Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support 256bits integer #22

Merged
merged 1 commit into from Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/smartir_test.yml
Expand Up @@ -17,12 +17,12 @@ jobs:
- name: Code format check
working-directory: ./ir_cli
run: |
rustup default 1.67
rustup default 1.70
make fmt-check
shell: bash
- name: e2e tests
working-directory: ./ir_cli
shell: bash
run: |
rustup default 1.67
rustup default 1.70
make test
2 changes: 2 additions & 0 deletions docker/ir-cli-builder/Dockerfile
Expand Up @@ -50,6 +50,8 @@ RUN yum install -y bison
#RUN source /opt/rh/devtoolset-11/enable
RUN yum install -y gcc-c++
RUN yum install -y gcc-toolset-11 gcc-toolset-11-gcc-c++ gcc-toolset-11-make gcc-toolset-11-libasan-devel gcc-toolset-11-gdb gcc-toolset-11-binutils
RUN echo "source /opt/rh/gcc-toolset-11/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN mkdir -p /opt
WORKDIR /opt
# COPY linux-x64/clang+llvm-14.0.6-x86_64-linux-gnu-rhel-8.4.tar.xz /opt/
Expand Down
10 changes: 5 additions & 5 deletions ir_cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions ir_cli/Cargo.toml
Expand Up @@ -18,8 +18,8 @@ num-traits = "0.2.17"
num-derive = "0.4.1"
rustc-serialize = "0.3.24"
bstr = "1.7.0"
lalrpop ="0.19.9"
lalrpop-util ="0.19.9"
lalrpop = "0.19.9"
lalrpop-util = "0.19.9"
rust-crypto = "^0.2"
rsa = "0.3.0"
keccak-hash = "0.10.0"
Expand All @@ -30,7 +30,10 @@ hex = "0.4.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_derive = { version = "1.0" }
inkwell = { git = "https://github.com/TheDan64/inkwell", rev = "bbe1f3d76c45fc137a125665861fc6382ab352d6", features = ["target-webassembly", "llvm14-0-force-static"] }
inkwell = { git = "https://github.com/TheDan64/inkwell", features = [
"target-webassembly",
"llvm15-0-force-static",
] }
smart_ir_macro = { path = "../smart_ir_macro", version = "0.3.0" }
smart_ir = { path = "../smart_ir" }
compiler_base_span = "0.0.1"
Expand Down
10 changes: 5 additions & 5 deletions smart_ir/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions smart_ir/Cargo.toml
Expand Up @@ -17,9 +17,9 @@ indexmap = "1.0"
lalrpop-util = { version = "0.20.0", features = ["lexer"] }
downcast-rs = "1.2.0"
smart_ir_macro = { path = "../smart_ir_macro", version = "0.3.0" }
inkwell = { git = "https://github.com/TheDan64/inkwell", rev = "bbe1f3d76c45fc137a125665861fc6382ab352d6", features = [
inkwell = { git = "https://github.com/TheDan64/inkwell", features = [
"target-webassembly",
"llvm14-0-force-static",
"llvm15-0-force-static",
] }
num-bigint = "0.4"
num-integer = "0.1.45"
Expand Down
38 changes: 38 additions & 0 deletions smart_ir/src/abi/params.rs
Expand Up @@ -5,6 +5,7 @@
#[allow(unused_imports)]
use anyhow::{anyhow, Result};
use nano_leb128::ULEB128;
use num_bigint::BigInt;
#[allow(unused_imports)]
use num_traits::FromPrimitive;
use std::collections::HashMap;
Expand All @@ -30,6 +31,8 @@ pub enum ABIParam {
I64(i64),
U128(u128),
I128(i128),
U256(BigInt),
I256(BigInt),
Bool(bool),
Str(String),
Parampack(Vec<u8>),
Expand All @@ -45,6 +48,8 @@ pub enum ABIParam {
I64Array(Vec<i64>),
U128Array(Vec<u128>),
I128Array(Vec<i128>),
U256Array(Vec<BigInt>),
I256Array(Vec<BigInt>),
BoolArray(Vec<bool>),
StrArray(Vec<String>),

Expand All @@ -59,6 +64,8 @@ pub enum ABIParam {
StrI64Map(HashMap<String, i64>),
StrU128Map(HashMap<String, u128>),
StrI128Map(HashMap<String, i128>),
StrU256Map(HashMap<String, BigInt>),
StrI256Map(HashMap<String, BigInt>),
StrBoolMap(HashMap<String, bool>),
StrStrMap(HashMap<String, String>),
}
Expand Down Expand Up @@ -157,6 +164,8 @@ impl ABIParam {
ABIParam::I64(v) => (*v).to_le_bytes().to_vec(),
ABIParam::U128(v) => (*v).to_le_bytes().to_vec(),
ABIParam::I128(v) => (*v).to_le_bytes().to_vec(),
ABIParam::U256(v) => (*v).to_bytes_le().1.to_vec(),
ABIParam::I256(v) => (*v).to_bytes_le().1.to_vec(),
ABIParam::Bool(v) => vec![(*v) as u8],
ABIParam::Str(v) => {
let mut buf = buffer_starts_with_uleb128_len(v.len());
Expand All @@ -173,6 +182,8 @@ impl ABIParam {
ABIParam::I64Array(v) => encode_vec!(v, I64),
ABIParam::U128Array(v) => encode_vec!(v, U128),
ABIParam::I128Array(v) => encode_vec!(v, I128),
ABIParam::U256Array(v) => encode_vec!(v, U256),
ABIParam::I256Array(v) => encode_vec!(v, I256),
ABIParam::BoolArray(v) => encode_vec!(v, Bool),
ABIParam::StrArray(v) => encode_vec!(v, Str),
ABIParam::StrU8Map(v) => encode_map!(v, Str, U8),
Expand All @@ -185,6 +196,8 @@ impl ABIParam {
ABIParam::StrI64Map(v) => encode_map!(v, Str, I64),
ABIParam::StrU128Map(v) => encode_map!(v, Str, U128),
ABIParam::StrI128Map(v) => encode_map!(v, Str, I128),
ABIParam::StrU256Map(v) => encode_map!(v, Str, U256),
ABIParam::StrI256Map(v) => encode_map!(v, Str, I256),
ABIParam::StrBoolMap(v) => encode_map!(v, Str, Bool),
ABIParam::StrStrMap(v) => encode_map!(v, Str, Str),
ABIParam::Parampack(v) => {
Expand All @@ -207,6 +220,8 @@ impl ABIParam {
ABIParam::I64(_) => ParamType::I64,
ABIParam::U128(_) => ParamType::U128,
ABIParam::I128(_) => ParamType::I128,
ABIParam::U256(_) => ParamType::U256,
ABIParam::I256(_) => ParamType::I256,
ABIParam::Bool(_) => ParamType::Bool,
ABIParam::Str(_) => ParamType::Str,
ABIParam::Parampack(_) => ParamType::Parampack,
Expand All @@ -220,6 +235,8 @@ impl ABIParam {
ABIParam::I64Array(_) => ParamType::I64Array,
ABIParam::U128Array(_) => ParamType::U128Array,
ABIParam::I128Array(_) => ParamType::I128Array,
ABIParam::U256Array(_) => ParamType::U256Array,
ABIParam::I256Array(_) => ParamType::I256Array,
ABIParam::BoolArray(_) => ParamType::BoolArray,
ABIParam::StrArray(_) => ParamType::StrArray,
ABIParam::StrU8Map(_) => ParamType::StrU8Map,
Expand All @@ -232,6 +249,8 @@ impl ABIParam {
ABIParam::StrI64Map(_) => ParamType::StrI64Map,
ABIParam::StrU128Map(_) => ParamType::StrU128Map,
ABIParam::StrI128Map(_) => ParamType::StrI128Map,
ABIParam::StrU256Map(_) => ParamType::StrU256Map,
ABIParam::StrI256Map(_) => ParamType::StrI256Map,
ABIParam::StrBoolMap(_) => ParamType::StrBoolMap,
ABIParam::StrStrMap(_) => ParamType::StrStrMap,
}
Expand Down Expand Up @@ -280,6 +299,21 @@ pub fn decode_param(
ParamType::I64 => decode_int!(data, offset, I64, i64, 8),
ParamType::U128 => decode_int!(data, offset, U128, u128, 16),
ParamType::I128 => decode_int!(data, offset, I128, i128, 16),
ParamType::U256 => {
const SIZE: usize = 32;
let bytes = get_bytes::<SIZE>(data, offset);
let param = ABIParam::U256(BigInt::from_bytes_be(num_bigint::Sign::NoSign, &bytes));
*offset += SIZE;
Ok(param)
}
ParamType::I256 => {
const SIZE: usize = 32;
let bytes = get_bytes::<SIZE>(data, offset);
let param = ABIParam::I256(BigInt::from_bytes_be(num_bigint::Sign::NoSign, &bytes));
*offset += SIZE;
Ok(param)
}

ParamType::Bool => {
let param = ABIParam::Bool(data[*offset] != 0);
*offset += 1;
Expand All @@ -301,6 +335,8 @@ pub fn decode_param(
ParamType::I64Array => decode_vec!(data, offset, I64, I64Array),
ParamType::U128Array => decode_vec!(data, offset, U128, U128Array),
ParamType::I128Array => decode_vec!(data, offset, I128, I128Array),
ParamType::U256Array => decode_vec!(data, offset, U256, U256Array),
ParamType::I256Array => decode_vec!(data, offset, I256, I256Array),
ParamType::BoolArray => decode_vec!(data, offset, Bool, BoolArray),
ParamType::StrArray => decode_vec!(data, offset, Str, StrArray),
ParamType::StrU8Map => decode_map!(data, offset, Str, U8, StrU8Map),
Expand All @@ -313,6 +349,8 @@ pub fn decode_param(
ParamType::StrI64Map => decode_map!(data, offset, Str, I64, StrI64Map),
ParamType::StrU128Map => decode_map!(data, offset, Str, U128, StrU128Map),
ParamType::StrI128Map => decode_map!(data, offset, Str, I128, StrI128Map),
ParamType::StrU256Map => decode_map!(data, offset, Str, U256, StrU256Map),
ParamType::StrI256Map => decode_map!(data, offset, Str, I256, StrI256Map),
ParamType::StrBoolMap => decode_map!(data, offset, Str, Bool, StrBoolMap),
ParamType::StrStrMap => decode_map!(data, offset, Str, Str, StrStrMap),
ParamType::Parampack => unimplemented!(),
Expand Down
26 changes: 19 additions & 7 deletions smart_ir/src/encoding/datastream/mod.rs
Expand Up @@ -22,9 +22,11 @@ pub enum ParamType {
I64 = 7,
U128 = 8,
I128 = 9,
Bool = 10,
Str = 11,
Parampack = 12,
U256 = 10,
I256 = 11,
Bool = 12,
Str = 13,
Parampack = 14,

// Array params
U8Array = 32,
Expand All @@ -37,8 +39,10 @@ pub enum ParamType {
I64Array = 39,
U128Array = 40,
I128Array = 41,
BoolArray = 42,
StrArray = 43,
U256Array = 42,
I256Array = 43,
BoolArray = 44,
StrArray = 45,

// Map params
StrU8Map = 64,
Expand All @@ -51,8 +55,10 @@ pub enum ParamType {
StrI64Map = 71,
StrU128Map = 72,
StrI128Map = 73,
StrBoolMap = 74,
StrStrMap = 75,
StrU256Map = 74,
StrI256Map = 75,
StrBoolMap = 76,
StrStrMap = 77,
}

impl ParamType {
Expand Down Expand Up @@ -96,11 +102,13 @@ impl TryInto<ParamType> for cfg::Type {
cfg::IntType::I32 => Ok(ParamType::I32),
cfg::IntType::I64 => Ok(ParamType::I64),
cfg::IntType::I128 => Ok(ParamType::I128),
cfg::IntType::I256 => Ok(ParamType::I256),
cfg::IntType::U8 => Ok(ParamType::U8),
cfg::IntType::U16 => Ok(ParamType::U16),
cfg::IntType::U32 => Ok(ParamType::U32),
cfg::IntType::U64 => Ok(ParamType::U64),
cfg::IntType::U128 => Ok(ParamType::U128),
cfg::IntType::U256 => Ok(ParamType::U256),
},
},
cfg::Type::Map { key, value } => {
Expand All @@ -116,11 +124,13 @@ impl TryInto<ParamType> for cfg::Type {
cfg::IntType::I32 => Ok(ParamType::StrI32Map),
cfg::IntType::I64 => Ok(ParamType::StrI64Map),
cfg::IntType::I128 => Ok(ParamType::StrI128Map),
cfg::IntType::I256 => Ok(ParamType::StrI256Map),
cfg::IntType::U8 => Ok(ParamType::StrU8Map),
cfg::IntType::U16 => Ok(ParamType::StrU16Map),
cfg::IntType::U32 => Ok(ParamType::StrU32Map),
cfg::IntType::U64 => Ok(ParamType::StrU64Map),
cfg::IntType::U128 => Ok(ParamType::StrU128Map),
cfg::IntType::U256 => Ok(ParamType::StrU256Map),
},
},
_ => err,
Expand All @@ -140,11 +150,13 @@ impl TryInto<ParamType> for cfg::Type {
cfg::IntType::I32 => Ok(ParamType::I32Array),
cfg::IntType::I64 => Ok(ParamType::I64Array),
cfg::IntType::I128 => Ok(ParamType::I128Array),
cfg::IntType::I256 => Ok(ParamType::I256Array),
cfg::IntType::U8 => Ok(ParamType::U8Array),
cfg::IntType::U16 => Ok(ParamType::U16Array),
cfg::IntType::U32 => Ok(ParamType::U32Array),
cfg::IntType::U64 => Ok(ParamType::U64Array),
cfg::IntType::U128 => Ok(ParamType::U128Array),
cfg::IntType::U256 => Ok(ParamType::U256Array),
},
},
_ => err,
Expand Down