diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc3fa40e4..217b02a41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -151,8 +151,6 @@ jobs: run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: Install deps run: make deps - - name: Build cairo-native-runtime library. - run: cargo build --profile=ci --package=cairo-native-runtime - name: test run: make test-ci - name: test-cairo @@ -180,11 +178,9 @@ jobs: - name: Install scarb uses: software-mansion/setup-scarb@v1 with: - scarb-version: "2.8.2" + scarb-version: "2.8.4" - name: Install deps run: make deps - - name: Build cairo-native-runtime library. - run: cargo build --profile=ci --package=cairo-native-runtime - name: Run tests run: make test-ci - name: test-cairo @@ -206,7 +202,6 @@ jobs: - partition: 4 output: lcov-4.info env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ @@ -251,13 +246,11 @@ jobs: - name: Install scarb uses: software-mansion/setup-scarb@v1 with: - scarb-version: "2.8.2" + scarb-version: "2.8.4" - name: Install deps run: make deps - name: Build runtime and alexandria - run: make runtime && make check-llvm && make needs-cairo2 && make build-alexandria - - name: Build cairo-native-runtime library. - run: export PATH=$HOME/.rustup/toolchains/stable-aarch64-apple-darwin/bin:$PATH && cargo build --profile=ci --package=cairo-native-runtime + run: make runtime-ci && make check-llvm && make needs-cairo2 && make build-alexandria - name: Run tests and generate coverage partition ${{ matrix.partition }} run: cargo llvm-cov nextest --verbose --features=scarb --workspace --lcov --output-path ${{ matrix.output }} --partition count:${{ matrix.partition }}/4 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 554118a8a..8dc69fb33 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,7 +19,7 @@ jobs: CRATES_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: free HDD space run: | # deleting space diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ec185740..cf8e81d31 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: free HDD space run: | # deleting space diff --git a/Cargo.lock b/Cargo.lock index 9adf7ed6e..a4e14a522 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -276,12 +276,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64ct" version = "1.6.0" @@ -433,9 +427,9 @@ dependencies = [ [[package]] name = "cairo-lang-casm" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a4b4ca8473c25d1e760c83c2a49d953197556f82f6feb636004d3b6d6cc4a7" +checksum = "fd4d6659539ace9649c8e8a7434e51b0c50a7a700111d0a2b967dde220ddff49" dependencies = [ "cairo-lang-utils", "indoc", @@ -447,9 +441,9 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5852668d1c6966b34d6e4fe249732769ab9cb2012c201e3889d8119f206760a0" +checksum = "e2016966ed29f3a44487fd1bbdb05320fb6ea8ec46201c04c6b222ccb5264e0a" dependencies = [ "anyhow", "cairo-lang-defs", @@ -473,18 +467,18 @@ dependencies = [ [[package]] name = "cairo-lang-debug" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0644fab571f598547993936918c85f0e89b0bbc15140ca3ea723bff376be07d" +checksum = "50c804649297ca417206435ee3e8041d2100cc31ebf4a95bc4b92ed02dc63469" dependencies = [ "cairo-lang-utils", ] [[package]] name = "cairo-lang-defs" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f5f437d75ac25644880458effde562edcac45a888d27f2e497d30c6450fa97d" +checksum = "e8fbda467ac36f73bb1879e1f741898fc719d6f9239a01cc422e6a023281319b" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -499,9 +493,9 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ec5b44d3eaf50e28e068d163e56b9effcea6afe3625c32dd96418d2d4ebc34c" +checksum = "c843ef4715e3d21de5388d02206db2506e2d2ec0e80e2629e0ae9900a08b8674" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -511,9 +505,9 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0cd844e568f51e39729e8ac18bd27ada2e2b6dc9138f8c81adad48456480681" +checksum = "33a416c5871960fb4823160ebef2abc51e0c1b86fef1e97a1ebb2e5f3c3795d3" dependencies = [ "cairo-lang-utils", "good_lp", @@ -521,9 +515,9 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "323a2385e000589f7591f8a46599b4a462db6e36e5935bad3bceddcc1a1608e1" +checksum = "47189e0cb84b21defd201af4cf24a94c6b0d09f48706cf659c9ffa0def8a7a43" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -536,9 +530,9 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cf9cf637e12d41260dc59f3d988c76a6347424913ac8b6b8449ff3e79b59750" +checksum = "6409ff1f4a93ce7c0968d9d857d2a8c03657617a827159d33f978110b718b31d" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -557,9 +551,9 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d71bc5b1f19a00eb662c2cac33259b16b9cdbf9c005047aca0d538c13936407" +checksum = "1e224e006c82ef21bd9e243390992de2be25ae6fbbdaa8544067b3f0c31977f1" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -581,9 +575,9 @@ dependencies = [ [[package]] name = "cairo-lang-parser" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d939d258e26ace0f3cb1e50338ae18981a7505e3c20eabd24a62d70ee862d6c" +checksum = "afb260ba349c2b699639e56f9b64deb969ff01179a0253087e2c8ceec7e32157" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -601,9 +595,9 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67a553a6d2d2b54264e77e3c8cb5bc866b40b32d5e2144a58b74c559c7e289f" +checksum = "05a2e500dc8ddea4d25a866d8a839158b0e4c41a6c023f21911e2da252bd91b3" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -620,9 +614,9 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c33b5f4502b7efde6ac07fd5468f6dae15d88760aeece3d57a7bc4c224ba693e" +checksum = "d72f17373740f242d6995e896b9195c2cedff7e8b14e496afdd16b405039d1fb" dependencies = [ "cairo-lang-debug", "quote", @@ -631,9 +625,9 @@ dependencies = [ [[package]] name = "cairo-lang-project" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63d6a3cc86a79a29978acaaf6f94738c5487e265247fe06c7bf359645d8c200" +checksum = "13294f08d2013fcd6e815e7235935680963dec3390e5baf454f33da866fc44b6" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -645,9 +639,9 @@ dependencies = [ [[package]] name = "cairo-lang-runner" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528a247ac59cb35b2f99d64605a81de815fa5fb0b0e7f7ece1d4e7fcf267d4ea" +checksum = "6c5b9e6a21d92255b92f64c60658b4224dd7d290cde8beea783fadc10fbfcd8c" dependencies = [ "ark-ff", "ark-secp256k1", @@ -676,9 +670,9 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00c284031fd14796dad91483c3039d7929f8440e1e9e334017744b1d22df5aa8" +checksum = "6936215bca75c23e71873998420a3d46c322507a09917ce676c8d39f8c1bd6fe" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -702,9 +696,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891488c1a3184ce91679f5bdb63015a1d24769a48bd07e5d51a1779d0031dfbe" +checksum = "424f55450494e959c1ae26c52a71075767a90f76e3ecca6e81056dd7517e8ba0" dependencies = [ "anyhow", "cairo-lang-utils", @@ -729,9 +723,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea7752cd48c86b2cde8603b753a6df4da086dacd16a73d288854d5f040b51171" +checksum = "053dd520e0b9d1c1078d93ea69045f6f334c3d41b4b75db183ab33e32cfd8570" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -745,9 +739,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340892a09c9421414b2ac45b03c705f16e2bd737e4559dfd98ee1d20718dec9e" +checksum = "9a73227867377efc62ebb893cddaa88df3940bf2be5dbdc2f0b00f9edf69288e" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -761,9 +755,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5cc616e8df44c4d685fe3c5f81f35ebbda57225098b35cea8602457c45c9e96" +checksum = "a3752cacd475ea089d9a536357804150e693a124e703fcc33a55566d568094b3" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -785,9 +779,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c22ff7e8113a46a907f82f191096c96935cc48247e3079971ddf536ccc2f4f8" +checksum = "7162fb3c93960dfc6d8005b65064e518e3f1ed6102e8981b42ea41879c331184" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -806,9 +800,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf41941776e7410a8853a8e2a116292fc24d219df1989a92ffe5ab0e98037eb" +checksum = "a51b80c117e2b05a6d300f2e2247892cc99e42e950e79f6085e6ed6cbcb44d12" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -816,9 +810,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5508fa5ee8d24adf7d2c65505d0ac35efc892eac16d1449c6f7e314a0288cb8" +checksum = "aafaabc43f78dfa2f45d935993ba21c05c164bbb3bf277d348847a51e5939a9f" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -846,9 +840,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "482b8f9d7f8cc7140f1260ee71f3308a66d15bd228a06281067ca3f8f4410db2" +checksum = "832fd9072ddf4204ca6d227c0238929349f10146bd066a98025d51ac15d27fad" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -869,9 +863,9 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7db0776c3d06cea65d7afe7a3c7685f6867eb6d951cf505caf35abfd1746773b" +checksum = "cebe67c0d68f9acf8709d170c1308ca57a778d22f70da38a57f74ae250eee28a" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -885,9 +879,9 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce0f7fa01c26cc731bc1d6350ac02fae91a68b5fdf60e684f991e861715adc4" +checksum = "31cef5b4347626e61bad8f070495cd35d637a5cb6744c34d20dd382c7431aff8" dependencies = [ "genco", "xshell", @@ -895,9 +889,9 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f1597b8229a3649183ff33b19f0aeca5d86505253ebbbce377b271d1732835" +checksum = "4d5f036132e07b7829cb1d61b1ecc02789a70c7d16b2733722a2aca992492bc3" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -922,9 +916,9 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630a070a69c387eee9c0eda65e4f2508d129d4fbe081091077e661020ab95637" +checksum = "060c61ac4a3ae0428771244ff8db903105f127392b7d725d919fe3fb1ec4132f" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -935,9 +929,9 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73104609a7d865e4cd1de9cbf4e750683d076b6d0233bf81be511df274a26916" +checksum = "8bfc6372538143afad658c853a35bdc9f5210c5cb54e0c8f04ab78e268139466" dependencies = [ "hashbrown 0.14.5", "indexmap 2.6.0", @@ -950,10 +944,14 @@ dependencies = [ [[package]] name = "cairo-native" -version = "0.2.0-alpha.2" +version = "0.2.0-alpha.3" dependencies = [ "anyhow", "aquamarine", + "ark-ec", + "ark-ff", + "ark-secp256k1", + "ark-secp256r1", "bumpalo", "cairo-lang-compiler", "cairo-lang-defs", @@ -977,9 +975,8 @@ dependencies = [ "criterion", "educe", "itertools 0.13.0", - "k256", "keccak", - "lambdaworks-math 0.10.0", + "lambdaworks-math", "lazy_static", "libc", "libloading", @@ -987,14 +984,13 @@ dependencies = [ "melior", "mlir-sys", "num-bigint", + "num-integer", "num-traits 0.2.19", - "p256", "pretty_assertions_sorted", "proptest", "rstest", "scarb-metadata", "scarb-ui", - "sec1", "serde", "serde_json", "sha2", @@ -1011,7 +1007,7 @@ dependencies = [ [[package]] name = "cairo-native-runtime" -version = "0.2.0-alpha.2" +version = "0.2.0-alpha.3" dependencies = [ "cairo-lang-sierra-gas", "itertools 0.13.0", @@ -1086,9 +1082,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.24" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "jobserver", "libc", @@ -1250,12 +1246,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "const_format" version = "0.2.33" @@ -1383,7 +1373,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array", - "rand_core", "subtle", "zeroize", ] @@ -1459,17 +1448,6 @@ dependencies = [ "parking_lot_core", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "pem-rfc7468", - "zeroize", -] - [[package]] name = "deranged" version = "0.3.11" @@ -1549,7 +1527,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", "subtle", ] @@ -1581,20 +1558,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - [[package]] name = "educe" version = "0.5.11" @@ -1613,26 +1576,6 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pem-rfc7468", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "zeroize", -] - [[package]] name = "ena" version = "0.14.3" @@ -1696,16 +1639,6 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "rand_core", - "subtle", -] - [[package]] name = "fixedbitset" version = "0.4.2" @@ -1728,6 +1661,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "funty" version = "2.0.0" @@ -1736,9 +1675,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -1751,9 +1690,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -1761,15 +1700,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -1778,15 +1717,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -1795,15 +1734,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -1813,9 +1752,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -1859,7 +1798,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -1904,17 +1842,6 @@ dependencies = [ "minilp", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "half" version = "2.4.1" @@ -1956,6 +1883,11 @@ name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] [[package]] name = "heck" @@ -2208,20 +2140,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "k256" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2", - "signature", -] - [[package]] name = "keccak" version = "0.1.5" @@ -2264,26 +2182,16 @@ dependencies = [ [[package]] name = "lambdaworks-crypto" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb5d4f22241504f7c7b8d2c3a7d7835d7c07117f10bff2a7d96a9ef6ef217c3" +checksum = "bbc2a4da0d9e52ccfe6306801a112e81a8fc0c76aa3e4449fefeda7fef72bb34" dependencies = [ - "lambdaworks-math 0.7.0", + "lambdaworks-math", "serde", "sha2", "sha3", ] -[[package]] -name = "lambdaworks-math" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358e172628e713b80a530a59654154bfc45783a6ed70ea284839800cebdf8f97" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "lambdaworks-math" version = "0.10.0" @@ -2380,11 +2288,11 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lru" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -2604,12 +2512,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" -version = "1.20.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oorandom" @@ -2632,18 +2537,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "p256" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" -dependencies = [ - "ecdsa", - "elliptic-curve", - "primeorder", - "sha2", -] - [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -2728,15 +2621,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "pem-rfc7468" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] - [[package]] name = "petgraph" version = "0.6.5" @@ -2774,16 +2658,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "pkg-config" version = "0.3.31" @@ -2875,15 +2749,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "primeorder" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" -dependencies = [ - "elliptic-curve", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -2919,9 +2784,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -3120,9 +2985,9 @@ dependencies = [ [[package]] name = "rstest" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b423f0e62bdd61734b67cd21ff50871dfaeb9cc74f869dcd6af974fbcb19936" +checksum = "0a2c585be59b6b5dd66a9d2084aa1d8bd52fbdb806eafdeffb52791147862035" dependencies = [ "futures", "futures-timer", @@ -3132,9 +2997,9 @@ dependencies = [ [[package]] name = "rstest_macros" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e1711e7d14f74b12a58411c542185ef7fb7f2e7f8ee6e2940a883628522b42" +checksum = "825ea780781b15345a146be27eaefb05085e337e869bff01b4306a4fd4a9ad5a" dependencies = [ "cfg-if", "glob", @@ -3309,20 +3174,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "semver" version = "1.0.23" @@ -3431,16 +3282,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "siphasher" version = "0.3.11" @@ -3487,16 +3328,6 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - [[package]] name = "sprs" version = "0.7.1" @@ -3577,12 +3408,12 @@ dependencies = [ [[package]] name = "starknet-types-core" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b889ee5734db8b3c8a6551135c16764bf4ce1ab4955fffbb2ac5b6706542b64" +checksum = "fa1b9e01ccb217ab6d475c5cda05dbb22c30029f7bb52b192a010a00d77a3d74" dependencies = [ "lambdaworks-crypto", - "lambdaworks-math 0.7.0", + "lambdaworks-math", "lazy_static", "num-bigint", "num-integer", @@ -3931,9 +3762,9 @@ dependencies = [ [[package]] name = "triomphe" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6631e42e10b40c0690bf92f404ebcfe6e1fdb480391d15f17cc8e96eeed5369" +checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85" dependencies = [ "serde", "stable_deref_trait", diff --git a/Cargo.toml b/Cargo.toml index d8b356d2d..c4b2e6a37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cairo-native" -version = "0.2.0-alpha.2" +version = "0.2.0-alpha.3" edition = "2021" license = "Apache-2.0" description = "A compiler to convert Cairo's intermediate representation Sierra code to MLIR." @@ -59,42 +59,42 @@ normal = ["aquamarine"] [dependencies] aquamarine = "0.5.0" bumpalo = "3.16.0" -cairo-lang-compiler = "2.8.2" -cairo-lang-defs = "2.8.2" -cairo-lang-filesystem = "2.8.2" -cairo-lang-semantic = "2.8.2" -cairo-lang-sierra = "2.8.2" -cairo-lang-sierra-generator = "2.8.2" -cairo-lang-diagnostics = "2.8.2" +cairo-lang-compiler = "2.8.4" +cairo-lang-defs = "2.8.4" +cairo-lang-filesystem = "2.8.4" +cairo-lang-semantic = "2.8.4" +cairo-lang-sierra = "2.8.4" +cairo-lang-sierra-generator = "2.8.4" +cairo-lang-diagnostics = "2.8.4" educe = "0.5.11" # can't update until https://github.com/magiclen/educe/issues/27 itertools = "0.13.0" -lazy_static = "1.4" +lazy_static = "1.5" libc = "0.2" llvm-sys = "191.0.0" melior = { version = "0.19.0", features = ["ods-dialects"] } mlir-sys = { version = "0.3.0" } -num-bigint = "0.4.4" +num-bigint = "0.4.6" num-traits = "0.2" -starknet-types-core = { version = "0.1.5", default-features = false, features = [ +starknet-types-core = { version = "0.1.7", default-features = false, features = [ "std", "serde", "num-traits", ] } -tempfile = "3.6" +tempfile = "3.13" thiserror = "1.0.64" tracing = "0.1" utf8_iter = "1.0.4" # CLI dependencies -cairo-lang-sierra-ap-change = "2.8.2" -cairo-lang-sierra-gas = "2.8.2" -cairo-lang-starknet = "2.8.2" -cairo-lang-utils = "2.8.2" -cairo-lang-starknet-classes = "2.8.2" -cairo-native-runtime = { version = "0.2.0-alpha.2", path = "runtime", optional = true } -clap = { version = "4.5.18", features = ["derive"], optional = true } -libloading = "0.8.3" +cairo-lang-sierra-ap-change = "2.8.4" +cairo-lang-sierra-gas = "2.8.4" +cairo-lang-starknet = "2.8.4" +cairo-lang-utils = "2.8.4" +cairo-lang-starknet-classes = "2.8.4" +cairo-native-runtime = { version = "0.2.0-alpha.3", path = "runtime", optional = true } +clap = { version = "4.5.19", features = ["derive"], optional = true } +libloading = "0.8.5" tracing-subscriber = { version = "0.3.18", features = [ "env-filter", "json", @@ -102,35 +102,39 @@ tracing-subscriber = { version = "0.3.18", features = [ ], optional = true } serde = { version = "1.0", features = ["derive"] } anyhow = { version = "1.0", optional = true } -cairo-lang-test-plugin = { version = "2.8.2", optional = true } -cairo-lang-runner = { version = "2.8.2", optional = true } +cairo-lang-test-plugin = { version = "2.8.4", optional = true } +cairo-lang-runner = { version = "2.8.4", optional = true } colored = { version = "2.1.0", optional = true } # needed to interface with cairo-lang-* keccak = "0.1.5" -k256 = "0.13.4" -p256 = "0.13.2" sha2 = "0.10.8" # needed for the syscall handler stub scarb-metadata = { version = "1.12.0", optional = true } scarb-ui = { version = "0.1.5", optional = true } -sec1 = "0.7.3" -serde_json = { version = "1.0.125" } +serde_json = { version = "1.0.128" } stats_alloc = "0.1.10" +# for the syscallhandler stub to match blockifier +ark-secp256k1 = "0.4.0" +ark-secp256r1 = "0.4.0" +ark-ec = "0.4.2" +ark-ff = "0.4.2" +num-integer = "0.1.46" + [dev-dependencies] cairo-vm = { version = "1.0.1", features = ["cairo-1-hints"] } -cairo-lang-runner = "2.8.2" -cairo-lang-semantic = { version = "2.8.2", features = ["testing"] } +cairo-lang-runner = "2.8.4" +cairo-lang-semantic = { version = "2.8.4", features = ["testing"] } criterion = { version = "0.5.1", features = ["html_reports"] } lambdaworks-math = "0.10.0" pretty_assertions_sorted = "1.2.3" -proptest = "1.4.0" -rstest = "0.22.0" +proptest = "1.5.0" +rstest = "0.23.0" test-case = "3.3" walkdir = "2.5.0" -serde_json = { version = "1.0.117" } +serde_json = { version = "1.0.128" } [build-dependencies] -cc = "1.1.21" +cc = "1.1.28" [profile.optimized-dev] inherits = "dev" diff --git a/Makefile b/Makefile index a0b34bbb5..5d018b1f4 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ # Environment detection. UNAME := $(shell uname) -CAIRO_2_VERSION = 2.8.2 -SCARB_VERSION = 2.8.3 +CAIRO_2_VERSION = 2.8.4 +SCARB_VERSION = 2.8.4 # Usage is the default target for newcomers running `make`. .PHONY: usage diff --git a/README.md b/README.md index 6fb737235..9a831e594 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ to machine code via MLIR and LLVM. [![codecov](https://img.shields.io/codecov/c/github/lambdaclass/cairo_native)](https://codecov.io/gh/lambdaclass/cairo_native) [![license](https://img.shields.io/github/license/lambdaclass/cairo_native)](/LICENSE) [![pr-welcome]](#-contributing) +[![Crates.io Version](https://img.shields.io/crates/v/cairo_native)](https://crates.io/crates/cairo-native) + [tg-badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Ftg.sumanjay.workers.dev%2FLambdaStarkNet%2F&logo=telegram&label=chat&color=neon [tg-url]: https://t.me/LambdaStarkNet diff --git a/docs/release.md b/docs/release.md new file mode 100644 index 000000000..68313274e --- /dev/null +++ b/docs/release.md @@ -0,0 +1,10 @@ +# Release Process + +- Update version on root Cargo.toml +- Update version on runtime Cargo.toml +- Update Cargo.toml runtime dependency version to match the new version +- Make a PR +- Wait for PR to be merged +- Pull changes once merged +- `git tag v` +- `git push --tags` # this will test, build and publish the version if successful. diff --git a/env.sh b/env.sh index df9e250f5..d20ca7fc8 100644 --- a/env.sh +++ b/env.sh @@ -11,24 +11,24 @@ case $(uname) in MLIR_SYS_190_PREFIX="$(brew --prefix llvm@19)" LLVM_SYS_191_PREFIX="$(brew --prefix llvm@19)" TABLEGEN_190_PREFIX="$(brew --prefix llvm@19)" - CAIRO_NATIVE_RUNTIME_LIBDIR="$(pwd)/target/debug" + CAIRO_NATIVE_RUNTIME_LIBRARY="$(pwd)/target/debug/libcairo_native_runtime.a" export LIBRARY_PATH export MLIR_SYS_190_PREFIX export LLVM_SYS_191_PREFIX export TABLEGEN_190_PREFIX - export CAIRO_NATIVE_RUNTIME_LIBDIR + export CAIRO_NATIVE_RUNTIME_LIBRARY ;; Linux) # If installed from Debian/Ubuntu repository: MLIR_SYS_190_PREFIX=/usr/lib/llvm-19 LLVM_SYS_191_PREFIX=/usr/lib/llvm-19 TABLEGEN_190_PREFIX=/usr/lib/llvm-19 - CAIRO_NATIVE_RUNTIME_LIBDIR="$(pwd)/target/debug" + CAIRO_NATIVE_RUNTIME_LIBRARY="$(pwd)/target/debug/libcairo_native_runtime.a" export MLIR_SYS_190_PREFIX export LLVM_SYS_191_PREFIX export TABLEGEN_190_PREFIX - export CAIRO_NATIVE_RUNTIME_LIBDIR + export CAIRO_NATIVE_RUNTIME_LIBRARY ;; esac diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 6f458f7d3..f06d62c67 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cairo-native-runtime" -version = "0.2.0-alpha.2" +version = "0.2.0-alpha.3" description = "A compiler to convert Cairo's intermediate representation Sierra code to MLIR." edition = "2021" license = "Apache-2.0" @@ -9,12 +9,12 @@ license = "Apache-2.0" crate-type = ["rlib", "cdylib", "staticlib"] [dependencies] -starknet-types-core = { version = "0.1.5", default-features = false, features = [ +starknet-types-core = { version = "0.1.7", default-features = false, features = [ "std", "serde", "hash" ] } -cairo-lang-sierra-gas = "2.8.2" +cairo-lang-sierra-gas = "2.8.4" libc = "0.2" -starknet-curve = "0.5.0" +starknet-curve = "0.5.1" lazy_static = "1.5.0" rand = "0.8.5" itertools = "0.13.0" diff --git a/src/arch.rs b/src/arch.rs index e6e963c2a..12d76b865 100644 --- a/src/arch.rs +++ b/src/arch.rs @@ -1,6 +1,6 @@ use crate::{ error, - starknet::{ArrayAbi, U256}, + starknet::{ArrayAbi, Secp256k1Point, Secp256r1Point}, types::TypeBuilder, utils::libc_malloc, values::Value, @@ -60,7 +60,7 @@ impl<'a> AbiArgument for JitValueWithInfoWrapper<'a> { fn to_bytes(&self, buffer: &mut Vec) -> Result<(), error::Error> { match (self.value, self.info) { (value, CoreTypeConcrete::Box(info)) => { - let ptr = value.to_jit(self.arena, self.registry, self.type_id)?; + let ptr = value.to_ptr(self.arena, self.registry, self.type_id)?; let layout = self.registry.get_type(&info.ty)?.layout(self.registry)?; let heap_ptr = unsafe { @@ -75,7 +75,7 @@ impl<'a> AbiArgument for JitValueWithInfoWrapper<'a> { if matches!(value, Value::Null) { null::<()>().to_bytes(buffer)?; } else { - let ptr = value.to_jit(self.arena, self.registry, self.type_id)?; + let ptr = value.to_ptr(self.arena, self.registry, self.type_id)?; let layout = self.registry.get_type(&info.ty)?.layout(self.registry)?; let heap_ptr = unsafe { @@ -94,7 +94,7 @@ impl<'a> AbiArgument for JitValueWithInfoWrapper<'a> { (Value::Array(_), CoreTypeConcrete::Array(_)) => { // TODO: Assert that `info.ty` matches all the values' types. - let abi_ptr = self.value.to_jit(self.arena, self.registry, self.type_id)?; + let abi_ptr = self.value.to_ptr(self.arena, self.registry, self.type_id)?; let abi = unsafe { abi_ptr.cast::>().as_ref() }; abi.ptr.to_bytes(buffer)?; @@ -116,7 +116,7 @@ impl<'a> AbiArgument for JitValueWithInfoWrapper<'a> { } (Value::Enum { tag, value, .. }, CoreTypeConcrete::Enum(info)) => { if self.info.is_memory_allocated(self.registry)? { - let abi_ptr = self.value.to_jit(self.arena, self.registry, self.type_id)?; + let abi_ptr = self.value.to_ptr(self.arena, self.registry, self.type_id)?; let abi_ptr = unsafe { *abi_ptr.cast::>().as_ref() }; abi_ptr.as_ptr().to_bytes(buffer)?; @@ -146,27 +146,25 @@ impl<'a> AbiArgument for JitValueWithInfoWrapper<'a> { // TODO: Assert that `info.ty` matches all the values' types. self.value - .to_jit(self.arena, self.registry, self.type_id)? + .to_ptr(self.arena, self.registry, self.type_id)? .as_ptr() .to_bytes(buffer)? } ( - Value::Secp256K1Point { x, y }, + Value::Secp256K1Point(Secp256k1Point { x, y, is_infinity }), CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::Secp256Point( Secp256PointTypeConcrete::K1(_), )), ) | ( - Value::Secp256R1Point { x, y }, + Value::Secp256R1Point(Secp256r1Point { x, y, is_infinity }), CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::Secp256Point( Secp256PointTypeConcrete::R1(_), )), ) => { - let x = U256 { lo: x.0, hi: x.1 }; - let y = U256 { lo: y.0, hi: y.1 }; - x.to_bytes(buffer)?; y.to_bytes(buffer)?; + is_infinity.to_bytes(buffer)?; } (Value::Sint128(value), CoreTypeConcrete::Sint128(_)) => value.to_bytes(buffer)?, (Value::Sint16(value), CoreTypeConcrete::Sint16(_)) => value.to_bytes(buffer)?, diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index a58925244..b99d878a7 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -18,6 +18,18 @@ fn align_to(buffer: &mut Vec, align: usize) { buffer.resize(buffer.len().next_multiple_of(align), 0); } +impl AbiArgument for bool { + fn to_bytes(&self, buffer: &mut Vec) -> Result<(), Error> { + if buffer.len() < 64 { + buffer.extend_from_slice(&(*self as u64).to_ne_bytes()); + } else { + align_to(buffer, get_integer_layout(1).align()); + buffer.push((*self) as u8); + } + Ok(()) + } +} + impl AbiArgument for u8 { fn to_bytes(&self, buffer: &mut Vec) -> Result<(), Error> { if buffer.len() < 64 { diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 59c525a9c..e00e12bcf 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -18,6 +18,18 @@ fn align_to(buffer: &mut Vec, align: usize) { buffer.resize(buffer.len().next_multiple_of(align), 0); } +impl AbiArgument for bool { + fn to_bytes(&self, buffer: &mut Vec) -> Result<(), Error> { + if buffer.len() < 48 { + buffer.extend_from_slice(&(*self as u64).to_ne_bytes()); + } else { + align_to(buffer, get_integer_layout(1).align()); + buffer.push((*self) as u8); + } + Ok(()) + } +} + impl AbiArgument for u8 { fn to_bytes(&self, buffer: &mut Vec) -> Result<(), Error> { if buffer.len() < 48 { diff --git a/src/bin/utils/mod.rs b/src/bin/utils/mod.rs index 0bbf59825..fc145c5b1 100644 --- a/src/bin/utils/mod.rs +++ b/src/bin/utils/mod.rs @@ -4,7 +4,11 @@ use anyhow::bail; use cairo_lang_runner::{casm_run::format_next_item, RunResultValue}; use cairo_lang_sierra::program::{Function, Program}; -use cairo_native::{execution_result::ExecutionResult, Value}; +use cairo_native::{ + execution_result::ExecutionResult, + starknet::{Secp256k1Point, Secp256r1Point}, + Value, +}; use clap::ValueEnum; use itertools::Itertools; use starknet_types_core::felt::Felt; @@ -159,11 +163,19 @@ fn jitvalue_to_felt(value: &Value) -> Vec { Value::EcState(a, b, c, d) => { vec![*a, *b, *c, *d] } - Value::Secp256K1Point { x, y } => { - vec![x.0.into(), x.1.into(), y.0.into(), y.1.into()] + Value::Secp256K1Point(Secp256k1Point { + x, + y, + is_infinity: _, + }) => { + vec![x.lo.into(), x.hi.into(), y.lo.into(), y.hi.into()] } - Value::Secp256R1Point { x, y } => { - vec![x.0.into(), x.1.into(), y.0.into(), y.1.into()] + Value::Secp256R1Point(Secp256r1Point { + x, + y, + is_infinity: _, + }) => { + vec![x.lo.into(), x.hi.into(), y.lo.into(), y.hi.into()] } Value::Null => vec![0.into()], } @@ -550,10 +562,9 @@ mod tests { #[test] fn test_jitvalue_to_felt_secp256_k1_point() { assert_eq!( - jitvalue_to_felt(&Value::Secp256K1Point { - x: (1, 2), - y: (3, 4) - }), + jitvalue_to_felt(&Value::Secp256K1Point(Secp256k1Point::new( + 1, 2, 3, 4, false + ))), vec![Felt::ONE, Felt::TWO, Felt::THREE, Felt::from(4)] ); } @@ -561,10 +572,9 @@ mod tests { #[test] fn test_jitvalue_to_felt_secp256_r1_point() { assert_eq!( - jitvalue_to_felt(&Value::Secp256R1Point { - x: (1, 2), - y: (3, 4) - }), + jitvalue_to_felt(&Value::Secp256R1Point(Secp256r1Point::new( + 1, 2, 3, 4, false + ))), vec![Felt::ONE, Felt::TWO, Felt::THREE, Felt::from(4)] ); } diff --git a/src/error.rs b/src/error.rs index bc0d65395..c58b2fa57 100644 --- a/src/error.rs +++ b/src/error.rs @@ -54,9 +54,12 @@ pub enum Error { #[error(transparent)] GasMetadataError(#[from] GasMetadataError), - #[error("llvm error")] + #[error("llvm compile error: {0}")] LLVMCompileError(String), + #[error("ld link error: {0}")] + LinkError(String), + #[error("cairo const data mismatch")] ConstDataMismatch, diff --git a/src/executor.rs b/src/executor.rs index cf94e5b37..8d5cdfabc 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -335,15 +335,15 @@ fn parse_result( } match type_info { - CoreTypeConcrete::Array(_) => Ok(Value::from_jit(return_ptr.unwrap(), type_id, registry)?), + CoreTypeConcrete::Array(_) => Ok(Value::from_ptr(return_ptr.unwrap(), type_id, registry)?), CoreTypeConcrete::Box(info) => unsafe { let ptr = return_ptr.unwrap_or(NonNull::new_unchecked(ret_registers[0] as *mut ())); - let value = Value::from_jit(ptr, &info.ty, registry)?; + let value = Value::from_ptr(ptr, &info.ty, registry)?; libc_free(ptr.cast().as_ptr()); Ok(value) }, CoreTypeConcrete::EcPoint(_) | CoreTypeConcrete::EcState(_) => { - Ok(Value::from_jit(return_ptr.unwrap(), type_id, registry)?) + Ok(Value::from_ptr(return_ptr.unwrap(), type_id, registry)?) } CoreTypeConcrete::Felt252(_) | CoreTypeConcrete::StarkNet( @@ -352,7 +352,7 @@ fn parse_result( | StarkNetTypeConcrete::StorageAddress(_) | StarkNetTypeConcrete::StorageBaseAddress(_), ) => match return_ptr { - Some(return_ptr) => Ok(Value::from_jit(return_ptr, type_id, registry)?), + Some(return_ptr) => Ok(Value::from_ptr(return_ptr, type_id, registry)?), None => { #[cfg(target_arch = "x86_64")] // Since x86_64's return values hold at most two different 64bit registers, @@ -369,7 +369,7 @@ fn parse_result( } }, CoreTypeConcrete::Bytes31(_) => match return_ptr { - Some(return_ptr) => Ok(Value::from_jit(return_ptr, type_id, registry)?), + Some(return_ptr) => Ok(Value::from_ptr(return_ptr, type_id, registry)?), None => { #[cfg(target_arch = "x86_64")] // Since x86_64's return values hold at most two different 64bit registers, @@ -384,7 +384,7 @@ fn parse_result( } }, CoreTypeConcrete::BoundedInt(info) => match return_ptr { - Some(return_ptr) => Ok(Value::from_jit(return_ptr, type_id, registry)?), + Some(return_ptr) => Ok(Value::from_ptr(return_ptr, type_id, registry)?), None => { let mut data = if info.range.offset_bit_width() <= 64 { BigInt::from(ret_registers[0]) @@ -456,7 +456,7 @@ fn parse_result( Ok(Value::Null) } else { let ptr = NonNull::new_unchecked(ptr); - let value = Value::from_jit(ptr, &info.ty, registry)?; + let value = Value::from_ptr(ptr, &info.ty, registry)?; libc_free(ptr.as_ptr().cast()); Ok(value) } @@ -506,7 +506,7 @@ fn parse_result( } }; let value = match ptr { - Ok(ptr) => Box::new(Value::from_jit(ptr, &info.variants[tag], registry)?), + Ok(ptr) => Box::new(Value::from_ptr(ptr, &info.variants[tag], registry)?), Err(offset) => { ret_registers.copy_within(offset.., 0); Box::new(parse_result( @@ -531,14 +531,14 @@ fn parse_result( debug_name: Some(debug_name), }) } else { - Ok(Value::from_jit(return_ptr.unwrap(), type_id, registry)?) + Ok(Value::from_ptr(return_ptr.unwrap(), type_id, registry)?) } } CoreTypeConcrete::Felt252Dict(_) | CoreTypeConcrete::SquashedFelt252Dict(_) => unsafe { let ptr = return_ptr.unwrap_or(NonNull::new_unchecked( addr_of_mut!(ret_registers[0]) as *mut () )); - Ok(Value::from_jit(ptr, type_id, registry)?) + Ok(Value::from_ptr(ptr, type_id, registry)?) }, CoreTypeConcrete::Snapshot(info) => { diff --git a/src/ffi.rs b/src/ffi.rs index a53a1343e..0e6b563ce 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -260,7 +260,6 @@ pub fn object_to_shared_lib(object: &[u8], output_filename: &Path) -> Result<()> "-o".into(), Cow::from(output_path), "-lc".into(), - //"-lcairo_native_runtime".into(), Cow::from(file_path), ]); @@ -284,7 +283,7 @@ pub fn object_to_shared_lib(object: &[u8], output_filename: &Path) -> Result<()> Ok(()) } else { let msg = String::from_utf8_lossy(&proc.stderr); - panic!("error linking:\n{}", msg); + Err(Error::LinkError(msg.to_string())) } } diff --git a/src/libfuncs/sint128.rs b/src/libfuncs/sint128.rs index ccee4c372..4ce06cbf8 100644 --- a/src/libfuncs/sint128.rs +++ b/src/libfuncs/sint128.rs @@ -22,6 +22,7 @@ use melior::{ dialect::{ arith::{self, CmpiPredicate}, cf, llvm, + ods::math, }, ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike}, Context, @@ -244,11 +245,33 @@ pub fn build_to_felt252<'ctx, 'this>( metadata, &info.branch_signatures()[0].vars[0].ty, )?; + let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?; + let value: Value = entry.argument(0)?.into(); + let value_type = value.r#type(); + + let is_negative = entry.append_op_result(arith::cmpi( + context, + arith::CmpiPredicate::Slt, + value, + entry.const_int_from_type(context, location, 0, value_type)?, + location, + ))?; + + let value_abs = entry.append_op_result(math::absi(context, value, location).into())?; - let result = entry.append_op_result(arith::extui(value, felt252_ty, location))?; + let result = entry.append_op_result(arith::extui(value_abs, felt252_ty, location))?; - entry.append_operation(helper.br(0, &[result], location)); + let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?; + + let final_result = entry.append_op_result(arith::select( + is_negative, + prime_minus_result, + result, + location, + ))?; + + entry.append_operation(helper.br(0, &[final_result], location)); Ok(()) } @@ -468,7 +491,7 @@ mod test { } #[test] - fn i128_to_felt252() { + fn pos_i128_to_felt252() { let program = load_cairo!( use traits::Into; @@ -476,8 +499,24 @@ mod test { 2_i128.into() } ); + run_program_assert_output(&program, "run_test", &[], Felt::from(2_i128).into()); + } - run_program_assert_output(&program, "run_test", &[], Felt::from(2).into()); + #[test] + fn neg_i128_to_felt252() { + let program = load_cairo!( + use traits::Into; + + fn run_test() -> felt252 { + -396372399979_i128.into() + } + ); + run_program_assert_output( + &program, + "run_test", + &[], + Felt::from(-396372399979_i128).into(), + ); } #[test] diff --git a/src/libfuncs/sint16.rs b/src/libfuncs/sint16.rs index 2d3821cf2..5211e0246 100644 --- a/src/libfuncs/sint16.rs +++ b/src/libfuncs/sint16.rs @@ -22,6 +22,7 @@ use melior::{ dialect::{ arith::{self, CmpiPredicate}, cf, llvm, + ods::math, }, ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike}, Context, @@ -274,11 +275,33 @@ pub fn build_to_felt252<'ctx, 'this>( metadata, &info.branch_signatures()[0].vars[0].ty, )?; + let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?; + let value: Value = entry.argument(0)?.into(); + let value_type = value.r#type(); - let result = entry.append_op_result(arith::extui(value, felt252_ty, location))?; + let is_negative = entry.append_op_result(arith::cmpi( + context, + arith::CmpiPredicate::Slt, + value, + entry.const_int_from_type(context, location, 0, value_type)?, + location, + ))?; - entry.append_operation(helper.br(0, &[result], location)); + let value_abs = entry.append_op_result(math::absi(context, value, location).into())?; + + let result = entry.append_op_result(arith::extui(value_abs, felt252_ty, location))?; + + let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?; + + let final_result = entry.append_op_result(arith::select( + is_negative, + prime_minus_result, + result, + location, + ))?; + + entry.append_operation(helper.br(0, &[final_result], location)); Ok(()) } @@ -504,7 +527,7 @@ mod test { } #[test] - fn i16_to_felt252() { + fn pos_i16_to_felt252() { let program = load_cairo!( use traits::Into; @@ -516,6 +539,18 @@ mod test { run_program_assert_output(&program, "run_test", &[], Felt::from(2).into()); } + #[test] + fn neg_i16_to_felt252() { + let program = load_cairo!( + use traits::Into; + + fn run_test() -> felt252 { + -3963_i16.into() + } + ); + run_program_assert_output(&program, "run_test", &[], Felt::from(-3963).into()); + } + #[test] fn i16_from_felt252() { let program = load_cairo!( diff --git a/src/libfuncs/sint32.rs b/src/libfuncs/sint32.rs index 0de6c839f..3e8bd9139 100644 --- a/src/libfuncs/sint32.rs +++ b/src/libfuncs/sint32.rs @@ -22,6 +22,7 @@ use melior::{ dialect::{ arith::{self, CmpiPredicate}, cf, llvm, + ods::math, }, ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike}, Context, @@ -273,11 +274,33 @@ pub fn build_to_felt252<'ctx, 'this>( metadata, &info.branch_signatures()[0].vars[0].ty, )?; + let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?; + let value: Value = entry.argument(0)?.into(); + let value_type = value.r#type(); - let result = entry.append_op_result(arith::extui(value, felt252_ty, location))?; + let is_negative = entry.append_op_result(arith::cmpi( + context, + arith::CmpiPredicate::Slt, + value, + entry.const_int_from_type(context, location, 0, value_type)?, + location, + ))?; - entry.append_operation(helper.br(0, &[result], location)); + let value_abs = entry.append_op_result(math::absi(context, value, location).into())?; + + let result = entry.append_op_result(arith::extui(value_abs, felt252_ty, location))?; + + let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?; + + let final_result = entry.append_op_result(arith::select( + is_negative, + prime_minus_result, + result, + location, + ))?; + + entry.append_operation(helper.br(0, &[final_result], location)); Ok(()) } @@ -504,7 +527,7 @@ mod test { } #[test] - fn i32_to_felt252() { + fn pos_i32_to_felt252() { let program = load_cairo!( use traits::Into; @@ -516,6 +539,18 @@ mod test { run_program_assert_output(&program, "run_test", &[], Felt::from(2).into()); } + #[test] + fn neg_i32_to_felt252() { + let program = load_cairo!( + use traits::Into; + + fn run_test() -> felt252 { + -396372_i32.into() + } + ); + run_program_assert_output(&program, "run_test", &[], Felt::from(-396372).into()); + } + #[test] fn i32_from_felt252() { let program = load_cairo!( diff --git a/src/libfuncs/sint64.rs b/src/libfuncs/sint64.rs index 745935da5..a7ec6bc6c 100644 --- a/src/libfuncs/sint64.rs +++ b/src/libfuncs/sint64.rs @@ -22,6 +22,7 @@ use melior::{ dialect::{ arith::{self, CmpiPredicate}, cf, llvm, + ods::math, }, ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike}, Context, @@ -274,11 +275,33 @@ pub fn build_to_felt252<'ctx, 'this>( metadata, &info.branch_signatures()[0].vars[0].ty, )?; + let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?; + let value: Value = entry.argument(0)?.into(); + let value_type = value.r#type(); - let result = entry.append_op_result(arith::extui(value, felt252_ty, location))?; + let is_negative = entry.append_op_result(arith::cmpi( + context, + arith::CmpiPredicate::Slt, + value, + entry.const_int_from_type(context, location, 0, value_type)?, + location, + ))?; - entry.append_operation(helper.br(0, &[result], location)); + let value_abs = entry.append_op_result(math::absi(context, value, location).into())?; + + let result = entry.append_op_result(arith::extui(value_abs, felt252_ty, location))?; + + let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?; + + let final_result = entry.append_op_result(arith::select( + is_negative, + prime_minus_result, + result, + location, + ))?; + + entry.append_operation(helper.br(0, &[final_result], location)); Ok(()) } @@ -504,7 +527,7 @@ mod test { } #[test] - fn i64_to_felt252() { + fn pos_i64_to_felt252() { let program = load_cairo!( use traits::Into; @@ -516,6 +539,18 @@ mod test { run_program_assert_output(&program, "run_test", &[], Felt::from(2).into()); } + #[test] + fn neg_i64_to_felt252() { + let program = load_cairo!( + use traits::Into; + + fn run_test() -> felt252 { + -396372_i64.into() + } + ); + run_program_assert_output(&program, "run_test", &[], Felt::from(-396372).into()); + } + #[test] fn i64_from_felt252() { let program = load_cairo!( diff --git a/src/libfuncs/sint8.rs b/src/libfuncs/sint8.rs index f87b30520..99c3705bc 100644 --- a/src/libfuncs/sint8.rs +++ b/src/libfuncs/sint8.rs @@ -22,6 +22,7 @@ use melior::{ dialect::{ arith::{self, CmpiPredicate}, cf, llvm, + ods::math, }, ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike}, Context, @@ -275,11 +276,33 @@ pub fn build_to_felt252<'ctx, 'this>( metadata, &info.branch_signatures()[0].vars[0].ty, )?; + let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?; + let value: Value = entry.argument(0)?.into(); + let value_type = value.r#type(); - let result = entry.append_op_result(arith::extui(value, felt252_ty, location))?; + let is_negative = entry.append_op_result(arith::cmpi( + context, + arith::CmpiPredicate::Slt, + value, + entry.const_int_from_type(context, location, 0, value_type)?, + location, + ))?; - entry.append_operation(helper.br(0, &[result], location)); + let value_abs = entry.append_op_result(math::absi(context, value, location).into())?; + + let result = entry.append_op_result(arith::extui(value_abs, felt252_ty, location))?; + + let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?; + + let final_result = entry.append_op_result(arith::select( + is_negative, + prime_minus_result, + result, + location, + ))?; + + entry.append_operation(helper.br(0, &[final_result], location)); Ok(()) } @@ -506,7 +529,7 @@ mod test { } #[test] - fn i8_to_felt252() { + fn pos_i8_to_felt252() { let program = load_cairo!( use traits::Into; @@ -518,6 +541,18 @@ mod test { run_program_assert_output(&program, "run_test", &[], Felt::from(2).into()); } + #[test] + fn neg_i8_to_felt252() { + let program = load_cairo!( + use traits::Into; + + fn run_test() -> felt252 { + -255_i128.into() + } + ); + run_program_assert_output(&program, "run_test", &[], Felt::from(-255).into()); + } + #[test] fn i8_from_felt252() { let program = load_cairo!( diff --git a/src/starknet.rs b/src/starknet.rs index f50cd4ede..d1a7c6ddf 100644 --- a/src/starknet.rs +++ b/src/starknet.rs @@ -1,5 +1,6 @@ //! Starknet related code for `cairo_native` +use serde::{Deserialize, Serialize}; use starknet_types_core::felt::Felt; pub type SyscallResult = std::result::Result>; @@ -20,7 +21,17 @@ pub struct Felt252Abi(pub [u8; 32]); /// Binary representation of a `u256` (in MLIR). // TODO: This shouldn't need to be public. #[derive( - Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize, + Debug, + Clone, + Copy, + PartialEq, + Eq, + PartialOrd, + Ord, + Hash, + serde::Serialize, + serde::Deserialize, + Default, )] #[repr(C, align(16))] pub struct U256 { @@ -100,16 +111,40 @@ pub struct TxInfo { pub nonce: Felt, } -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Deserialize, Serialize, Default)] +#[repr(C, align(16))] pub struct Secp256k1Point { pub x: U256, pub y: U256, + pub is_infinity: bool, +} + +impl Secp256k1Point { + pub fn new(x_lo: u128, x_hi: u128, y_lo: u128, y_hi: u128, is_infinity: bool) -> Self { + Self { + x: U256 { lo: x_lo, hi: x_hi }, + y: U256 { lo: y_lo, hi: y_hi }, + is_infinity, + } + } } -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Deserialize, Serialize, Default)] +#[repr(C, align(16))] pub struct Secp256r1Point { pub x: U256, pub y: U256, + pub is_infinity: bool, +} + +impl Secp256r1Point { + pub fn new(x_lo: u128, x_hi: u128, y_lo: u128, y_hi: u128, is_infinity: bool) -> Self { + Self { + x: U256 { lo: x_lo, hi: x_hi }, + y: U256 { lo: y_lo, hi: y_hi }, + is_infinity, + } + } } pub trait StarknetSyscallHandler { diff --git a/src/starknet_stub.rs b/src/starknet_stub.rs index 288bca68c..bf25d22c1 100644 --- a/src/starknet_stub.rs +++ b/src/starknet_stub.rs @@ -2,18 +2,18 @@ use std::{ collections::{HashMap, VecDeque}, - iter::once, + fmt, }; use crate::starknet::{ BlockInfo, ExecutionInfo, ExecutionInfoV2, Secp256k1Point, Secp256r1Point, StarknetSyscallHandler, SyscallResult, TxInfo, TxV2Info, U256, }; -use k256::elliptic_curve::{ - generic_array::GenericArray, - sec1::{FromEncodedPoint, ToEncodedPoint}, -}; -use sec1::point::Coordinates; +use ark_ec::short_weierstrass::{Affine, Projective, SWCurveConfig}; +use ark_ff::{BigInt, PrimeField}; +use itertools::Itertools; +use num_bigint::BigUint; +use num_traits::Zero; use starknet_types_core::felt::Felt; use tracing::instrument; @@ -78,6 +78,191 @@ pub struct ContractLogs { type L2ToL1Message = (Felt, Vec); +#[derive(PartialEq, Clone, Copy)] +struct Secp256Point(Affine); + +impl fmt::Debug for Secp256Point { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("Secp256Point").field(&self.0).finish() + } +} + +impl From> for Secp256k1Point { + fn from(Secp256Point(Affine { x, y, infinity }): Secp256Point) -> Self { + Secp256k1Point { + x: big4int_to_u256(x.into()), + y: big4int_to_u256(y.into()), + is_infinity: infinity, + } + } +} + +impl From> for Secp256r1Point { + fn from(Secp256Point(Affine { x, y, infinity }): Secp256Point) -> Self { + Secp256r1Point { + x: big4int_to_u256(x.into()), + y: big4int_to_u256(y.into()), + is_infinity: infinity, + } + } +} + +impl From for Secp256Point { + fn from(p: Secp256k1Point) -> Self { + Secp256Point(Affine { + x: u256_to_biguint(p.x).into(), + y: u256_to_biguint(p.y).into(), + infinity: p.is_infinity, + }) + } +} + +impl From for Secp256Point { + fn from(p: Secp256r1Point) -> Self { + Secp256Point(Affine { + x: u256_to_biguint(p.x).into(), + y: u256_to_biguint(p.y).into(), + infinity: p.is_infinity, + }) + } +} + +pub fn u256_to_biguint(u256: U256) -> BigUint { + let lo = BigUint::from(u256.lo); + let hi = BigUint::from(u256.hi); + + (hi << 128) + lo +} + +pub fn big4int_to_u256(b_int: BigInt<4>) -> U256 { + let [a, b, c, d] = b_int.0; + + let lo = u128::from(a) | (u128::from(b) << 64); + let hi = u128::from(c) | (u128::from(d) << 64); + + U256 { lo, hi } +} + +pub fn encode_str_as_felts(msg: &str) -> Vec { + const CHUNK_SIZE: usize = 32; + + let data = msg.as_bytes().chunks(CHUNK_SIZE - 1); + let mut encoding = vec![Felt::default(); data.len()]; + for (i, data_chunk) in data.enumerate() { + let mut chunk = [0_u8; CHUNK_SIZE]; + chunk[1..data_chunk.len() + 1].copy_from_slice(data_chunk); + encoding[i] = Felt::from_bytes_be(&chunk); + } + encoding +} + +pub fn decode_felts_as_str(encoding: &[Felt]) -> String { + let bytes_err: Vec<_> = encoding + .iter() + .flat_map(|felt| felt.to_bytes_be()[1..32].to_vec()) + .collect(); + + match String::from_utf8(bytes_err) { + Ok(s) => s.trim_matches('\0').to_owned(), + Err(_) => { + let err_msgs = encoding + .iter() + .map( + |felt| match String::from_utf8(felt.to_bytes_be()[1..32].to_vec()) { + Ok(s) => format!("{} ({})", s.trim_matches('\0'), felt), + Err(_) => felt.to_string(), + }, + ) + .join(", "); + format!("[{}]", err_msgs) + } + } +} + +impl Secp256Point +where + Curve::BaseField: PrimeField, // constraint for get_point_by_id +{ + // Given a (x,y) pair it will + // - return the point at infinity for (0,0) + // - Err if either x or y is outside of the modulus + // - Ok(None) if (x,y) are within the modules but not on the curve + // - Ok(Some(Point)) if (x,y) are on the curve + fn new(x: U256, y: U256) -> Result, Vec> { + let x = u256_to_biguint(x); + let y = u256_to_biguint(y); + let modulos = Curve::BaseField::MODULUS.into(); + + if x >= modulos || y >= modulos { + let error = Felt::from_hex( + "0x00000000000000000000000000000000496e76616c696420617267756d656e74", + ) // INVALID_ARGUMENT + .map_err(|err| encode_str_as_felts(&err.to_string()))?; + + return Err(vec![error]); + } + + Ok(maybe_affine(x.into(), y.into())) + } + + fn add(p0: Self, p1: Self) -> Self { + let result: Projective = p0.0 + p1.0; + Secp256Point(result.into()) + } + + fn mul(p: Self, m: U256) -> Self { + let result = p.0 * Curve::ScalarField::from(u256_to_biguint(m)); + Secp256Point(result.into()) + } + + fn get_point_from_x(x: U256, y_parity: bool) -> Result, Vec> { + let modulos = Curve::BaseField::MODULUS.into(); + let x = u256_to_biguint(x); + + if x >= modulos { + let error = Felt::from_hex( + "0x00000000000000000000000000000000496e76616c696420617267756d656e74", + ) // INVALID_ARGUMENT + .map_err(|err| encode_str_as_felts(&err.to_string()))?; + + return Err(vec![error]); + } + + let x = x.into(); + let maybe_ec_point = Affine::::get_ys_from_x_unchecked(x) + .map(|(smaller, greater)| { + // Return the correct y coordinate based on the parity. + if ark_ff::BigInteger::is_odd(&smaller.into_bigint()) == y_parity { + smaller + } else { + greater + } + }) + .map(|y| Affine::::new_unchecked(x, y)) + .filter(|p| p.is_in_correct_subgroup_assuming_on_curve()); + + Ok(maybe_ec_point.map(Secp256Point)) + } +} + +/// Variation on [`Affine::new`] that doesn't panic and maps (x,y) = (0,0) -> infinity +fn maybe_affine( + x: Curve::BaseField, + y: Curve::BaseField, +) -> Option> { + let ec_point = if x.is_zero() && y.is_zero() { + Affine::::identity() + } else { + Affine::::new_unchecked(x, y) + }; + + if ec_point.is_on_curve() && ec_point.is_in_correct_subgroup_assuming_on_curve() { + Some(Secp256Point(ec_point)) + } else { + None + } +} + impl StarknetSyscallHandler for &mut StubSyscallHandler { #[instrument(skip(self))] fn get_block_hash( @@ -228,38 +413,30 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { #[instrument(skip(self))] fn keccak(&mut self, input: &[u64], gas: &mut u128) -> SyscallResult { - tracing::debug!("called"); + const KECCAK_FULL_RATE_IN_WORDS: usize = 17; + let length = input.len(); + let (_n_rounds, remainder) = num_integer::div_rem(length, KECCAK_FULL_RATE_IN_WORDS); - if length % 17 != 0 { - let error_msg = b"Invalid keccak input size"; - let felt_error = Felt::from_bytes_be_slice(error_msg); - return Err(vec![felt_error]); + if remainder != 0 { + // In VM this error is wrapped into `SyscallExecutionError::SyscallError` + return Err(vec![Felt::from_hex( + "0x000000000000000000000000496e76616c696420696e707574206c656e677468", + ) + .unwrap()]); } - let n_chunks = length / 17; let mut state = [0u64; 25]; - - for i in 0..n_chunks { - if *gas < KECCAK_ROUND_COST { - let error_msg = b"Syscall out of gas"; - let felt_error = Felt::from_bytes_be_slice(error_msg); - return Err(vec![felt_error]); - } - const KECCAK_ROUND_COST: u128 = 180000; - *gas -= KECCAK_ROUND_COST; - let chunk = &input[i * 17..(i + 1) * 17]; //(request.input_start + i * 17)?; + for chunk in input.chunks(KECCAK_FULL_RATE_IN_WORDS) { for (i, val) in chunk.iter().enumerate() { state[i] ^= val; } keccak::f1600(&mut state) } - // state[0] and state[1] conform the hash_high (u128) - // state[2] and state[3] conform the hash_low (u128) - SyscallResult::Ok(U256 { - lo: state[0] as u128 | ((state[1] as u128) << 64), - hi: state[2] as u128 | ((state[3] as u128) << 64), + Ok(U256 { + hi: u128::from(state[2]) | (u128::from(state[3]) << 64), + lo: u128::from(state[0]) | (u128::from(state[1]) << 64), }) } @@ -270,28 +447,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { y: U256, _remaining_gas: &mut u128, ) -> SyscallResult> { - tracing::debug!("called"); - // The following unwraps should be unreachable because the iterator we provide has the - // expected number of bytes. - let point = k256::ProjectivePoint::from_encoded_point( - &k256::EncodedPoint::from_affine_coordinates( - &GenericArray::from_exact_iter( - x.hi.to_be_bytes().into_iter().chain(x.lo.to_be_bytes()), - ) - .unwrap(), - &GenericArray::from_exact_iter( - y.hi.to_be_bytes().into_iter().chain(y.lo.to_be_bytes()), - ) - .unwrap(), - false, - ), - ); - - if bool::from(point.is_some()) { - Ok(Some(Secp256k1Point { x, y })) - } else { - Ok(None) - } + Secp256Point::new(x, y).map(|op| op.map(|p| p.into())) } #[instrument(skip(self))] @@ -302,76 +458,8 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { _remaining_gas: &mut u128, ) -> SyscallResult { tracing::debug!("called"); - // The inner unwraps should be unreachable because the iterator we provide has the expected - // number of bytes. The outer unwraps depend on the felt values, which should be valid since - // they'll be provided by secp256 syscalls. - let p0 = k256::ProjectivePoint::from_encoded_point( - &k256::EncodedPoint::from_affine_coordinates( - &GenericArray::from_exact_iter( - p0.x.hi - .to_be_bytes() - .into_iter() - .chain(p0.x.lo.to_be_bytes()), - ) - .unwrap(), - &GenericArray::from_exact_iter( - p0.y.hi - .to_be_bytes() - .into_iter() - .chain(p0.y.lo.to_be_bytes()), - ) - .unwrap(), - false, - ), - ) - .unwrap(); - let p1 = k256::ProjectivePoint::from_encoded_point( - &k256::EncodedPoint::from_affine_coordinates( - &GenericArray::from_exact_iter( - p1.x.hi - .to_be_bytes() - .into_iter() - .chain(p1.x.lo.to_be_bytes()), - ) - .unwrap(), - &GenericArray::from_exact_iter( - p1.y.hi - .to_be_bytes() - .into_iter() - .chain(p1.y.lo.to_be_bytes()), - ) - .unwrap(), - false, - ), - ) - .unwrap(); - - let p = p0 + p1; - - let p = p.to_encoded_point(false); - let (x, y) = match p.coordinates() { - Coordinates::Uncompressed { x, y } => (x, y), - _ => { - // This should be unreachable because we explicitly asked for the uncompressed - // encoding. - unreachable!() - } - }; - // The following two unwraps should be safe because the array always has 32 bytes. The other - // four are definitely safe because the slicing guarantees its length to be the right one. - let x: [u8; 32] = x.as_slice().try_into().unwrap(); - let y: [u8; 32] = y.as_slice().try_into().unwrap(); - Ok(Secp256k1Point { - x: U256 { - hi: u128::from_be_bytes(x[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(x[16..32].try_into().unwrap()), - }, - y: U256 { - hi: u128::from_be_bytes(y[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(y[16..32].try_into().unwrap()), - }, - }) + Ok(Secp256Point::add(p0.into(), p1.into()).into()) } #[instrument(skip(self))] @@ -381,62 +469,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { m: U256, _remaining_gas: &mut u128, ) -> SyscallResult { - // The inner unwrap should be unreachable because the iterator we provide has the expected - // number of bytes. The outer unwrap depends on the felt values, which should be valid since - // they'll be provided by secp256 syscalls. - let p = k256::ProjectivePoint::from_encoded_point( - &k256::EncodedPoint::from_affine_coordinates( - &GenericArray::from_exact_iter( - p.x.hi.to_be_bytes().into_iter().chain(p.x.lo.to_be_bytes()), - ) - .unwrap(), - &GenericArray::from_exact_iter( - p.y.hi.to_be_bytes().into_iter().chain(p.y.lo.to_be_bytes()), - ) - .unwrap(), - false, - ), - ) - .unwrap(); - let m: k256::Scalar = k256::elliptic_curve::ScalarPrimitive::from_slice(&{ - let mut buf = [0u8; 32]; - buf[0..16].copy_from_slice(&m.hi.to_be_bytes()); - buf[16..32].copy_from_slice(&m.lo.to_be_bytes()); - buf - }) - .map_err(|_| { - vec![Felt::from_bytes_be( - b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0invalid scalar", - )] - })? - .into(); - - let p = p * m; - - let p = p.to_encoded_point(false); - let (x, y) = match p.coordinates() { - Coordinates::Uncompressed { x, y } => (x, y), - _ => { - // This should be unreachable because we explicitly asked for the uncompressed - // encoding. - unreachable!() - } - }; - - // The following two unwraps should be safe because the array always has 32 bytes. The other - // four are definitely safe because the slicing guarantees its length to be the right one. - let x: [u8; 32] = x.as_slice().try_into().unwrap(); - let y: [u8; 32] = y.as_slice().try_into().unwrap(); - Ok(Secp256k1Point { - x: U256 { - hi: u128::from_be_bytes(x[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(x[16..32].try_into().unwrap()), - }, - y: U256 { - hi: u128::from_be_bytes(y[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(y[16..32].try_into().unwrap()), - }, - }) + Ok(Secp256Point::mul(p.into(), m).into()) } #[instrument(skip(self))] @@ -446,50 +479,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { y_parity: bool, _remaining_gas: &mut u128, ) -> SyscallResult> { - tracing::debug!("called"); - // The inner unwrap should be unreachable because the iterator we provide has the expected - // number of bytes. The outer unwrap depends on the encoding format, which should be valid - // since it's hardcoded.. - let point = k256::ProjectivePoint::from_encoded_point( - &k256::EncodedPoint::from_bytes( - k256::CompressedPoint::from_exact_iter( - once(0x02 | y_parity as u8) - .chain(x.hi.to_be_bytes()) - .chain(x.lo.to_be_bytes()), - ) - .unwrap(), - ) - .unwrap(), - ); - - if bool::from(point.is_some()) { - // This unwrap has already been checked in the `if` expression's condition. - let p = point.unwrap(); - - let p = p.to_encoded_point(false); - let y = match p.coordinates() { - Coordinates::Uncompressed { y, .. } => y, - _ => { - // This should be unreachable because we explicitly asked for the uncompressed - // encoding. - unreachable!() - } - }; - - // The following unwrap should be safe because the array always has 32 bytes. The other - // two are definitely safe because the slicing guarantees its length to be the right - // one. - let y: [u8; 32] = y.as_slice().try_into().unwrap(); - Ok(Some(Secp256k1Point { - x, - y: U256 { - hi: u128::from_be_bytes(y[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(y[16..32].try_into().unwrap()), - }, - })) - } else { - Ok(None) - } + Secp256Point::get_point_from_x(x, y_parity).map(|op| op.map(|p| p.into())) } #[instrument(skip(self))] @@ -498,7 +488,6 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { p: Secp256k1Point, _remaining_gas: &mut u128, ) -> SyscallResult<(U256, U256)> { - tracing::debug!("called"); Ok((p.x, p.y)) } @@ -509,28 +498,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { y: U256, _remaining_gas: &mut u128, ) -> SyscallResult> { - tracing::debug!("called"); - // The following unwraps should be unreachable because the iterator we provide has the - // expected number of bytes. - let point = p256::ProjectivePoint::from_encoded_point( - &k256::EncodedPoint::from_affine_coordinates( - &GenericArray::from_exact_iter( - x.hi.to_be_bytes().into_iter().chain(x.lo.to_be_bytes()), - ) - .unwrap(), - &GenericArray::from_exact_iter( - y.hi.to_be_bytes().into_iter().chain(y.lo.to_be_bytes()), - ) - .unwrap(), - false, - ), - ); - - if bool::from(point.is_some()) { - Ok(Some(Secp256r1Point { x, y })) - } else { - Ok(None) - } + Secp256Point::new(x, y).map(|op| op.map(|p| p.into())) } #[instrument(skip(self))] @@ -540,77 +508,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { p1: Secp256r1Point, _remaining_gas: &mut u128, ) -> SyscallResult { - tracing::debug!("called"); - // The inner unwraps should be unreachable because the iterator we provide has the expected - // number of bytes. The outer unwraps depend on the felt values, which should be valid since - // they'll be provided by secp256 syscalls. - let p0 = p256::ProjectivePoint::from_encoded_point( - &p256::EncodedPoint::from_affine_coordinates( - &GenericArray::from_exact_iter( - p0.x.hi - .to_be_bytes() - .into_iter() - .chain(p0.x.lo.to_be_bytes()), - ) - .unwrap(), - &GenericArray::from_exact_iter( - p0.y.hi - .to_be_bytes() - .into_iter() - .chain(p0.y.lo.to_be_bytes()), - ) - .unwrap(), - false, - ), - ) - .unwrap(); - let p1 = p256::ProjectivePoint::from_encoded_point( - &p256::EncodedPoint::from_affine_coordinates( - &GenericArray::from_exact_iter( - p1.x.hi - .to_be_bytes() - .into_iter() - .chain(p1.x.lo.to_be_bytes()), - ) - .unwrap(), - &GenericArray::from_exact_iter( - p1.y.hi - .to_be_bytes() - .into_iter() - .chain(p1.y.lo.to_be_bytes()), - ) - .unwrap(), - false, - ), - ) - .unwrap(); - - let p = p0 + p1; - - let p = p.to_encoded_point(false); - let (x, y) = match p.coordinates() { - Coordinates::Uncompressed { x, y } => (x, y), - _ => { - // This should be unreachable because we explicitly asked for the uncompressed - // encoding. - unreachable!() - } - }; - - // The following two unwraps should be safe because the array always has 32 bytes. The other - // four are definitely safe because the slicing guarantees its length to be the right one. - let x: [u8; 32] = x.as_slice().try_into().unwrap(); - let y: [u8; 32] = y.as_slice().try_into().unwrap(); - Ok(Secp256r1Point { - x: U256 { - hi: u128::from_be_bytes(x[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(x[16..32].try_into().unwrap()), - }, - y: U256 { - hi: u128::from_be_bytes(y[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(y[16..32].try_into().unwrap()), - }, - }) + Ok(Secp256Point::add(p0.into(), p1.into()).into()) } #[instrument(skip(self))] @@ -620,61 +518,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { m: U256, _remaining_gas: &mut u128, ) -> SyscallResult { - // The inner unwrap should be unreachable because the iterator we provide has the expected - // number of bytes. The outer unwrap depends on the felt values, which should be valid since - // they'll be provided by secp256 syscalls. - let p = p256::ProjectivePoint::from_encoded_point( - &p256::EncodedPoint::from_affine_coordinates( - &GenericArray::from_exact_iter( - p.x.hi.to_be_bytes().into_iter().chain(p.x.lo.to_be_bytes()), - ) - .unwrap(), - &GenericArray::from_exact_iter( - p.y.hi.to_be_bytes().into_iter().chain(p.y.lo.to_be_bytes()), - ) - .unwrap(), - false, - ), - ) - .unwrap(); - let m: p256::Scalar = p256::elliptic_curve::ScalarPrimitive::from_slice(&{ - let mut buf = [0u8; 32]; - buf[0..16].copy_from_slice(&m.hi.to_be_bytes()); - buf[16..32].copy_from_slice(&m.lo.to_be_bytes()); - buf - }) - .map_err(|_| { - vec![Felt::from_bytes_be( - b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0invalid scalar", - )] - })? - .into(); - - let p = p * m; - let p = p.to_encoded_point(false); - let (x, y) = match p.coordinates() { - Coordinates::Uncompressed { x, y } => (x, y), - _ => { - // This should be unreachable because we explicitly asked for the uncompressed - // encoding. - unreachable!() - } - }; - - // The following two unwraps should be safe because the array always has 32 bytes. The other - // four are definitely safe because the slicing guarantees its length to be the right one. - let x: [u8; 32] = x.as_slice().try_into().unwrap(); - let y: [u8; 32] = y.as_slice().try_into().unwrap(); - Ok(Secp256r1Point { - x: U256 { - hi: u128::from_be_bytes(x[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(x[16..32].try_into().unwrap()), - }, - y: U256 { - hi: u128::from_be_bytes(y[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(y[16..32].try_into().unwrap()), - }, - }) + Ok(Secp256Point::mul(p.into(), m).into()) } #[instrument(skip(self))] @@ -684,38 +528,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { y_parity: bool, _remaining_gas: &mut u128, ) -> SyscallResult> { - let point = p256::ProjectivePoint::from_encoded_point( - &p256::EncodedPoint::from_bytes( - p256::CompressedPoint::from_exact_iter( - once(0x02 | y_parity as u8) - .chain(x.hi.to_be_bytes()) - .chain(x.lo.to_be_bytes()), - ) - .unwrap(), - ) - .unwrap(), - ); - - if bool::from(point.is_some()) { - let p = point.unwrap(); - - let p = p.to_encoded_point(false); - let y = match p.coordinates() { - Coordinates::Uncompressed { y, .. } => y, - _ => unreachable!(), - }; - - let y: [u8; 32] = y.as_slice().try_into().unwrap(); - Ok(Some(Secp256r1Point { - x, - y: U256 { - hi: u128::from_be_bytes(y[0..16].try_into().unwrap()), - lo: u128::from_be_bytes(y[16..32].try_into().unwrap()), - }, - })) - } else { - Ok(None) - } + Secp256Point::get_point_from_x(x, y_parity).map(|op| op.map(|p| p.into())) } #[instrument(skip(self))] @@ -724,7 +537,6 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { p: Secp256r1Point, _remaining_gas: &mut u128, ) -> SyscallResult<(U256, U256)> { - tracing::debug!("called"); Ok((p.x, p.y)) } @@ -852,6 +664,7 @@ mod tests { hi: 75181762170223969696219813306313470806, lo: 134255467439736302886468555755295925874, }, + is_infinity: false, }; let mut test_syscall_handler = StubSyscallHandler::default(); @@ -888,7 +701,11 @@ mod tests { assert_eq!( test_syscall_handler.secp256k1_new(x, y, &mut 10).unwrap(), - Some(Secp256k1Point { x, y }) + Some(Secp256k1Point { + x, + y, + is_infinity: false + }) ); } @@ -923,6 +740,7 @@ mod tests { lo: 336417762351022071123394393598455764152, hi: 96009999919712310848645357523629574312, }, + is_infinity: false, }; let p2 = p1; @@ -939,6 +757,7 @@ mod tests { lo: 329597642124196932058042157271922763050, hi: 35730324229579385338853513728577301230, }, + is_infinity: false, }; assert_eq!(p3, p1_double); assert_eq!( @@ -958,6 +777,7 @@ mod tests { lo: 134255467439736302886468555755295925874, hi: 75181762170223969696219813306313470806, }, + is_infinity: false, }; assert_eq!( test_syscall_handler.secp256k1_add(p1, p3, &mut 10).unwrap(), @@ -997,6 +817,7 @@ mod tests { lo: 68974579539311638391577168388077592842, hi: 26163136114030451075775058782541084873, }, + is_infinity: false } ); } @@ -1027,6 +848,7 @@ mod tests { lo: 271307787381626825071797439039395650341, hi: 314119230806908012387599548649227126582, }, + is_infinity: false } ); } @@ -1061,22 +883,29 @@ mod tests { .secp256r1_new(x, y, &mut 10) .unwrap() .unwrap(), - Secp256r1Point { x, y } + Secp256r1Point { + x, + y, + is_infinity: false + } ); } #[test] - fn test_secp256r1_new_none() { + fn test_secp256r1_new_infinity() { let mut test_syscall_handler = StubSyscallHandler::default(); let mut test_syscall_handler = &mut test_syscall_handler; let x = U256 { hi: 0, lo: 0 }; let y = U256 { hi: 0, lo: 0 }; - assert!(test_syscall_handler - .secp256r1_new(x, y, &mut 10) - .unwrap() - .is_none()); + assert!( + test_syscall_handler + .secp256r1_new(x, y, &mut 10) + .unwrap() + .unwrap() + .is_infinity + ); } #[test] @@ -1093,6 +922,7 @@ mod tests { lo: 111045440647474106186537215379882575585, hi: 118910939004298029402109603132816090461, }, + is_infinity: false, }; let p2 = p1; @@ -1109,6 +939,7 @@ mod tests { lo: 231570843221643745062297421862629788481, hi: 84249534056490759701994051847937833933, }, + is_infinity: false, }; assert_eq!(p3, p1_double); assert_eq!( @@ -1128,6 +959,7 @@ mod tests { lo: 282344931843342117515389970197013120959, hi: 178681203065513270100417145499857169664, }, + is_infinity: false, }; assert_eq!( test_syscall_handler.secp256r1_add(p1, p3, &mut 10).unwrap(), @@ -1161,7 +993,11 @@ mod tests { .secp256r1_get_point_from_x(x, true, &mut 10) .unwrap() .unwrap(), - Secp256r1Point { x, y } + Secp256r1Point { + x, + y, + is_infinity: false + } ); } @@ -1185,7 +1021,11 @@ mod tests { .secp256r1_get_point_from_x(x, false, &mut 10) .unwrap() .unwrap(), - Secp256r1Point { x, y } + Secp256r1Point { + x, + y, + is_infinity: false + } ); } @@ -1213,6 +1053,7 @@ mod tests { lo: 221371427837412271565447410779117722274, hi: 229236926352692519791101729645429586206, }, + is_infinity: false, }; let mut test_syscall_handler = StubSyscallHandler::default(); diff --git a/src/types.rs b/src/types.rs index 7711c0291..bf1dbb8bf 100644 --- a/src/types.rs +++ b/src/types.rs @@ -691,7 +691,11 @@ impl TypeBuilder for CoreTypeConcrete { StarkNetTypeConcrete::StorageAddress(_) => get_integer_layout(252), StarkNetTypeConcrete::System(_) => Layout::new::<*mut ()>(), StarkNetTypeConcrete::Secp256Point(_) => { - get_integer_layout(256).extend(get_integer_layout(256))?.0 + get_integer_layout(256) + .extend(get_integer_layout(256))? + .0 + .extend(get_integer_layout(1))? + .0 } StarkNetTypeConcrete::Sha256StateHandle(_) => Layout::new::<*mut ()>(), }, diff --git a/src/types/starknet.rs b/src/types/starknet.rs index a25b6e964..9299125c2 100644 --- a/src/types/starknet.rs +++ b/src/types/starknet.rs @@ -187,6 +187,7 @@ pub fn build_secp256_point<'ctx>( ], false, ), + IntegerType::new(context, 1).into(), ], false, )) diff --git a/src/values.rs b/src/values.rs index 7a9c14d99..873b00cbb 100644 --- a/src/values.rs +++ b/src/values.rs @@ -4,6 +4,7 @@ use crate::{ error::{CompilerError, Error}, + starknet::{Secp256k1Point, Secp256r1Point}, types::TypeBuilder, utils::{ felt252_bigint, get_integer_layout, layout_repeat, libc_free, libc_malloc, RangeExt, PRIME, @@ -26,11 +27,11 @@ use num_traits::{Euclid, One}; use starknet_types_core::felt::Felt; use std::{alloc::Layout, collections::HashMap, ptr::NonNull, slice}; -/// A JitValue is a value that can be passed to the JIT engine as an argument or received as a result. +/// A Value is a value that can be passed to either the JIT engine or a compiled program as an argument or received as a result. /// /// They map to the cairo/sierra types. /// -/// The debug_name field on some variants is `Some` when receiving a [`JitValue`] as a result. +/// The debug_name field on some variants is `Some` when receiving a [`Value`] as a result. /// /// A Boxed value or a non-null Nullable value is returned with it's inner value. #[derive(Clone, Educe, serde::Serialize, serde::Deserialize)] @@ -68,14 +69,8 @@ pub enum Value { Sint128(i128), EcPoint(Felt, Felt), EcState(Felt, Felt, Felt, Felt), - Secp256K1Point { - x: (u128, u128), - y: (u128, u128), - }, - Secp256R1Point { - x: (u128, u128), - y: (u128, u128), - }, + Secp256K1Point(Secp256k1Point), + Secp256R1Point(Secp256r1Point), BoundedInt { value: Felt, #[serde(with = "range_serde")] @@ -182,8 +177,8 @@ impl Value { }) } - /// Allocates the value in the given arena so it can be passed to the JIT engine. - pub(crate) fn to_jit( + /// Allocates the value in the given arena so it can be passed to the JIT engine or a compiled program. + pub(crate) fn to_ptr( &self, arena: &Bump, registry: &ProgramRegistry, @@ -251,7 +246,7 @@ impl Value { .map_err(|_| Error::IntegerConversion)?; for (idx, elem) in data.iter().enumerate() { - let elem = elem.to_jit(arena, registry, &info.ty)?; + let elem = elem.to_ptr(arena, registry, &info.ty)?; std::ptr::copy_nonoverlapping( elem.cast::().as_ptr(), @@ -310,7 +305,7 @@ impl Value { }; layout = Some(new_layout); - let member_ptr = member.to_jit(arena, registry, member_type_id)?; + let member_ptr = member.to_ptr(arena, registry, member_type_id)?; data.push(( member_layout, offset, @@ -356,7 +351,7 @@ impl Value { assert!(*tag < info.variants.len(), "Variant index out of range."); let payload_type_id = &info.variants[*tag]; - let payload = value.to_jit(arena, registry, payload_type_id)?; + let payload = value.to_ptr(arena, registry, payload_type_id)?; let (layout, tag_layout, variant_layouts) = crate::types::r#enum::get_layout_for_variants(registry, &info.variants) @@ -403,7 +398,7 @@ impl Value { for (key, value) in map.iter() { let key = key.to_bytes_le(); - let value = value.to_jit(arena, registry, &info.ty)?; + let value = value.to_ptr(arena, registry, &info.ty)?; let value_malloc_ptr = libc_malloc(elem_layout.size()); std::ptr::copy_nonoverlapping( @@ -520,8 +515,8 @@ impl Value { }) } - /// From the given pointer acquired from the JIT outputs, convert it to a [`Self`] - pub(crate) fn from_jit( + /// From the given pointer acquired from the either the JIT / compiled program outputs, convert it to a [`Self`] + pub(crate) fn from_ptr( ptr: NonNull<()>, type_id: &ConcreteTypeId, registry: &ProgramRegistry, @@ -564,7 +559,7 @@ impl Value { let cur_elem_ptr = NonNull::new(data_ptr.byte_add(elem_stride * i)).unwrap(); - array_value.push(Self::from_jit(cur_elem_ptr, &info.ty, registry)?); + array_value.push(Self::from_ptr(cur_elem_ptr, &info.ty, registry)?); } if !init_data_ptr.is_null() { @@ -575,7 +570,7 @@ impl Value { } CoreTypeConcrete::Box(info) => { let inner = *ptr.cast::>().as_ptr(); - let value = Self::from_jit(inner, &info.ty, registry)?; + let value = Self::from_ptr(inner, &info.ty, registry)?; libc_free(inner.as_ptr().cast()); value } @@ -610,13 +605,13 @@ impl Value { CoreTypeConcrete::Sint32(_) => Self::Sint32(*ptr.cast::().as_ref()), CoreTypeConcrete::Sint64(_) => Self::Sint64(*ptr.cast::().as_ref()), CoreTypeConcrete::Sint128(_) => Self::Sint128(*ptr.cast::().as_ref()), - CoreTypeConcrete::NonZero(info) => Self::from_jit(ptr, &info.ty, registry)?, + CoreTypeConcrete::NonZero(info) => Self::from_ptr(ptr, &info.ty, registry)?, CoreTypeConcrete::Nullable(info) => { let inner_ptr = *ptr.cast::<*mut ()>().as_ptr(); if inner_ptr.is_null() { Self::Null } else { - let value = Self::from_jit( + let value = Self::from_ptr( NonNull::new_unchecked(inner_ptr).cast(), &info.ty, registry, @@ -626,7 +621,7 @@ impl Value { } } CoreTypeConcrete::Uninitialized(_) => { - todo!("implement uninit from_jit or ignore the return value") + todo!("implement uninit from_ptr or ignore the return value") } CoreTypeConcrete::Enum(info) => { let tag_layout = crate::utils::get_integer_layout(match info.variants.len() { @@ -656,7 +651,7 @@ impl Value { let payload_ptr = NonNull::new(ptr.as_ptr().byte_add(tag_layout.extend(payload_layout)?.1)) .unwrap(); - let payload = Self::from_jit(payload_ptr, &info.variants[tag_value], registry)?; + let payload = Self::from_ptr(payload_ptr, &info.variants[tag_value], registry)?; Self::Enum { tag: tag_value, @@ -678,7 +673,7 @@ impl Value { }; layout = Some(new_layout); - members.push(Self::from_jit( + members.push(Self::from_ptr( NonNull::new(ptr.as_ptr().byte_add(offset)).unwrap(), member_ty, registry, @@ -708,7 +703,7 @@ impl Value { let key = Felt::from_bytes_le(key); output_map.insert( key, - Self::from_jit( + Self::from_ptr( NonNull::new(*val_ptr).unwrap().cast(), &info.ty, registry, @@ -733,7 +728,7 @@ impl Value { | CoreTypeConcrete::EcOp(_) | CoreTypeConcrete::GasBuiltin(_) | CoreTypeConcrete::SegmentArena(_) => { - unimplemented!("handled before: {:?}", type_id) + unreachable!("handled before: {:?}", type_id) } // Does it make sense for programs to return this? Should it be implemented CoreTypeConcrete::StarkNet(selector) => match selector { @@ -747,23 +742,22 @@ impl Value { Self::Felt252(data) } StarkNetTypeConcrete::System(_) => { - unimplemented!("should be handled before") + unreachable!("should be handled before") } - StarkNetTypeConcrete::Secp256Point(info) => { - let data = ptr.cast::<[[u128; 2]; 2]>().as_ref(); - - let x = (data[0][0], data[0][1]); - let y = (data[1][0], data[1][1]); - - match info { - Secp256PointTypeConcrete::K1(_) => Self::Secp256K1Point { x, y }, - Secp256PointTypeConcrete::R1(_) => Self::Secp256R1Point { x, y }, + StarkNetTypeConcrete::Secp256Point(info) => match info { + Secp256PointTypeConcrete::K1(_) => { + let data = ptr.cast::().as_ref(); + Self::Secp256K1Point(*data) } - } + Secp256PointTypeConcrete::R1(_) => { + let data = ptr.cast::().as_ref(); + Self::Secp256R1Point(*data) + } + }, StarkNetTypeConcrete::Sha256StateHandle(_) => todo!(), }, - CoreTypeConcrete::Span(_) => todo!("implement span from_jit"), - CoreTypeConcrete::Snapshot(info) => Self::from_jit(ptr, &info.ty, registry)?, + CoreTypeConcrete::Span(_) => todo!("implement span from_ptr"), + CoreTypeConcrete::Snapshot(info) => Self::from_ptr(ptr, &info.ty, registry)?, CoreTypeConcrete::Bytes31(_) => { let data = *ptr.cast::<[u8; 31]>().as_ref(); Self::Bytes31(data) @@ -967,7 +961,7 @@ mod test { assert_eq!( unsafe { *Value::Felt252(Felt::from(42)) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::<[u32; 8]>() .as_ptr() @@ -978,7 +972,7 @@ mod test { assert_eq!( unsafe { *Value::Felt252(Felt::MAX) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::<[u32; 8]>() .as_ptr() @@ -990,7 +984,7 @@ mod test { assert_eq!( unsafe { *Value::Felt252(Felt::MAX + Felt::ONE) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::<[u32; 8]>() .as_ptr() @@ -1008,7 +1002,7 @@ mod test { assert_eq!( unsafe { *Value::Uint8(9) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1026,7 +1020,7 @@ mod test { assert_eq!( unsafe { *Value::Uint16(17) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1044,7 +1038,7 @@ mod test { assert_eq!( unsafe { *Value::Uint32(33) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1062,7 +1056,7 @@ mod test { assert_eq!( unsafe { *Value::Uint64(65) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1080,7 +1074,7 @@ mod test { assert_eq!( unsafe { *Value::Uint128(129) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1098,7 +1092,7 @@ mod test { assert_eq!( unsafe { *Value::Sint8(-9) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1116,7 +1110,7 @@ mod test { assert_eq!( unsafe { *Value::Sint16(-17) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1134,7 +1128,7 @@ mod test { assert_eq!( unsafe { *Value::Sint32(-33) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1152,7 +1146,7 @@ mod test { assert_eq!( unsafe { *Value::Sint64(-65) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1170,7 +1164,7 @@ mod test { assert_eq!( unsafe { *Value::Sint128(-129) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::() .as_ptr() @@ -1190,7 +1184,7 @@ mod test { assert_eq!( unsafe { *Value::EcPoint(Felt::from(1234), Felt::from(4321)) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::<[[u32; 8]; 2]>() .as_ptr() @@ -1215,7 +1209,7 @@ mod test { Felt::from(3333), Felt::from(4444), ) - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap() .cast::<[[u32; 8]; 4]>() .as_ptr() @@ -1248,7 +1242,7 @@ mod test { value: Box::new(Value::Uint8(10)), debug_name: None, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[1].id); + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[1].id); // Assertion to verify that the value returned by to_jit is not NULL assert!(result.is_ok()); @@ -1277,7 +1271,7 @@ mod test { upper: BigInt::from(510), }, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[1].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[1].id) .unwrap() .cast::<[u32; 8]>() .as_ptr() @@ -1307,7 +1301,7 @@ mod test { upper: BigInt::from(10), }, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[1].id); + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[1].id); assert!(matches!( result, @@ -1336,7 +1330,7 @@ mod test { upper: BigInt::from(510), }, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[1].id); + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[1].id); assert!(matches!( result, @@ -1365,7 +1359,7 @@ mod test { upper: BigInt::from(510), }, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[1].id); + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[1].id); assert!(matches!( result, @@ -1394,7 +1388,7 @@ mod test { upper: BigInt::from(10), }, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[1].id); + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[1].id); assert!(matches!( result, @@ -1422,7 +1416,7 @@ mod test { value: Box::new(Value::Uint8(10)), debug_name: None, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[1].id); + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[1].id); } #[test] @@ -1442,7 +1436,7 @@ mod test { value: Box::new(Value::Uint8(10)), debug_name: None, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[1].id); + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[1].id); } #[test] @@ -1468,7 +1462,7 @@ mod test { }), debug_name: None, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap_err(); // Unwrapping the error // Matching the error result to verify the error type and message. @@ -1506,7 +1500,7 @@ mod test { fields: vec![Value::from(2u32)], debug_name: None, } - .to_jit(&Bump::new(), ®istry, &program.type_declarations[0].id) + .to_ptr(&Bump::new(), ®istry, &program.type_declarations[0].id) .unwrap_err(); // Unwrapping the error // Matching the error result to verify the error type and message. diff --git a/tests/tests/starknet/keccak.rs b/tests/tests/starknet/keccak.rs index 9c9830110..9422ef6fe 100644 --- a/tests/tests/starknet/keccak.rs +++ b/tests/tests/starknet/keccak.rs @@ -38,7 +38,7 @@ fn keccak_test() { assert!(!result.failure_flag); assert_eq!( result.remaining_gas, - 340282366920938463463374607431767963515 + 340282366920938463463374607431768143515 ); assert_eq!(result.return_values, vec![1.into()]); } diff --git a/tests/tests/starknet/secp256.rs b/tests/tests/starknet/secp256.rs index 107e666c7..28a8f9ce6 100644 --- a/tests/tests/starknet/secp256.rs +++ b/tests/tests/starknet/secp256.rs @@ -273,6 +273,7 @@ fn secp256k1_new() { Some(Secp256k1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }), Some(Secp256k1Point { x: U256 { @@ -283,6 +284,7 @@ fn secp256k1_new() { hi: u128::MAX, lo: u128::MAX, }, + is_infinity: false, }), ]), ), @@ -343,10 +345,7 @@ fn secp256k1_new() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (0, 0), - y: (0, 0), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::default())), debug_name: None, }), debug_name: None, @@ -375,10 +374,13 @@ fn secp256k1_new() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false + ))), debug_name: None, }), debug_name: None, @@ -423,6 +425,7 @@ fn secp256k1_add() { Secp256k1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }, Secp256k1Point { x: U256 { @@ -433,6 +436,7 @@ fn secp256k1_add() { lo: 0, hi: u128::MAX, }, + is_infinity: false, }, Secp256k1Point { x: U256 { @@ -443,6 +447,7 @@ fn secp256k1_add() { lo: u128::MAX, hi: u128::MAX, }, + is_infinity: false, }, ]), ), @@ -453,14 +458,8 @@ fn secp256k1_add() { &SECP256_PROGRAM, "secp256k1_add", &[ - Value::Secp256K1Point { - x: (0, 0), - y: (0, 0), - }, - Value::Secp256K1Point { - x: (0, 0), - y: (0, 0), - }, + Value::Secp256K1Point(Secp256k1Point::default()), + Value::Secp256K1Point(Secp256k1Point::default()), ], Some(u128::MAX), Some(&mut syscall_handler), @@ -469,10 +468,7 @@ fn secp256k1_add() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (0, 0), - y: (0, 0), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::default())), debug_name: None, }, ); @@ -481,14 +477,8 @@ fn secp256k1_add() { &SECP256_PROGRAM, "secp256k1_add", &[ - Value::Secp256K1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }, - Value::Secp256K1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }, + Value::Secp256K1Point(Secp256k1Point::new(0, u128::MAX, u128::MAX, 0, false)), + Value::Secp256K1Point(Secp256k1Point::new(u128::MAX, 0, 0, u128::MAX, false)), ], Some(u128::MAX), Some(&mut syscall_handler), @@ -497,10 +487,13 @@ fn secp256k1_add() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + 0, + 0, + u128::MAX, + false + ))), debug_name: None, }, ); @@ -509,14 +502,20 @@ fn secp256k1_add() { &SECP256_PROGRAM, "secp256k1_add", &[ - Value::Secp256K1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }, - Value::Secp256K1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }, + Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false, + )), + Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false, + )), ], Some(u128::MAX), Some(&mut syscall_handler), @@ -525,10 +524,13 @@ fn secp256k1_add() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false + ))), debug_name: None, }, ); @@ -540,10 +542,12 @@ fn secp256k1_add() { Secp256k1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }, Secp256k1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }, ), ( @@ -556,6 +560,7 @@ fn secp256k1_add() { hi: 0, lo: u128::MAX }, + is_infinity: false, }, Secp256k1Point { x: U256 { @@ -566,6 +571,7 @@ fn secp256k1_add() { hi: u128::MAX, lo: 0 }, + is_infinity: false, }, ), ( @@ -578,6 +584,7 @@ fn secp256k1_add() { lo: u128::MAX, hi: u128::MAX }, + is_infinity: false, }, Secp256k1Point { x: U256 { @@ -588,6 +595,7 @@ fn secp256k1_add() { lo: u128::MAX, hi: u128::MAX }, + is_infinity: false, }, ), ], @@ -604,6 +612,7 @@ fn secp256k1_mul() { Secp256k1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }, Secp256k1Point { x: U256 { @@ -614,6 +623,7 @@ fn secp256k1_mul() { hi: 0, lo: u128::MAX, }, + is_infinity: false, }, Secp256k1Point { x: U256 { @@ -624,6 +634,7 @@ fn secp256k1_mul() { hi: u128::MAX, lo: u128::MAX, }, + is_infinity: false, }, ]), ), @@ -634,10 +645,7 @@ fn secp256k1_mul() { &SECP256_PROGRAM, "secp256k1_mul", &[ - Value::Secp256K1Point { - x: (0, 0), - y: (0, 0), - }, + Value::Secp256K1Point(Secp256k1Point::default()), Value::Struct { fields: vec![Value::Uint128(0), Value::Uint128(0)], debug_name: None, @@ -650,10 +658,7 @@ fn secp256k1_mul() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (0, 0), - y: (0, 0), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::default())), debug_name: None, }, ); @@ -662,10 +667,7 @@ fn secp256k1_mul() { &SECP256_PROGRAM, "secp256k1_mul", &[ - Value::Secp256K1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }, + Value::Secp256K1Point(Secp256k1Point::new(u128::MAX, 0, 0, u128::MAX, false)), Value::Struct { fields: vec![Value::Uint128(u128::MAX), Value::Uint128(0)], debug_name: None, @@ -678,10 +680,13 @@ fn secp256k1_mul() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::new( + 0, + u128::MAX, + u128::MAX, + 0, + false + ))), debug_name: None, }, ); @@ -690,10 +695,7 @@ fn secp256k1_mul() { &SECP256_PROGRAM, "secp256k1_mul", &[ - Value::Secp256K1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }, + Value::Secp256K1Point(Secp256k1Point::new(u128::MAX, 0, 0, u128::MAX, false)), Value::Struct { fields: vec![Value::Uint128(u128::MAX), Value::Uint128(0)], debug_name: None, @@ -706,10 +708,13 @@ fn secp256k1_mul() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false + ))), debug_name: None, }, ); @@ -717,40 +722,16 @@ fn secp256k1_mul() { assert_eq!( syscall_handler.secp256k1_mul.0, [ + (Secp256k1Point::default(), U256 { hi: 0, lo: 0 },), ( - Secp256k1Point { - x: U256 { hi: 0, lo: 0 }, - y: U256 { hi: 0, lo: 0 }, - }, - U256 { hi: 0, lo: 0 }, - ), - ( - Secp256k1Point { - x: U256 { - lo: u128::MAX, - hi: 0 - }, - y: U256 { - lo: 0, - hi: u128::MAX, - }, - }, + Secp256k1Point::new(u128::MAX, 0, 0, u128::MAX, false), U256 { lo: u128::MAX, hi: 0, }, ), ( - Secp256k1Point { - x: U256 { - hi: 0, - lo: u128::MAX, - }, - y: U256 { - hi: u128::MAX, - lo: 0, - }, - }, + Secp256k1Point::new(u128::MAX, 0, 0, u128::MAX, false), U256 { hi: 0, lo: u128::MAX, @@ -771,6 +752,7 @@ fn secp256k1_get_point_from_x() { Some(Secp256k1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }), Some(Secp256k1Point { x: U256 { @@ -781,6 +763,7 @@ fn secp256k1_get_point_from_x() { hi: u128::MAX, lo: 0, }, + is_infinity: false, }), Some(Secp256k1Point { x: U256 { @@ -791,6 +774,7 @@ fn secp256k1_get_point_from_x() { hi: 0, lo: u128::MAX, }, + is_infinity: false, }), ]), ), @@ -859,10 +843,7 @@ fn secp256k1_get_point_from_x() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (0, 0), - y: (0, 0), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::default())), debug_name: None, }), debug_name: None, @@ -895,10 +876,13 @@ fn secp256k1_get_point_from_x() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + 0, + 0, + u128::MAX, + false + ))), debug_name: None, }), debug_name: None, @@ -931,10 +915,13 @@ fn secp256k1_get_point_from_x() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256K1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }), + value: Box::new(Value::Secp256K1Point(Secp256k1Point::new( + 0, + u128::MAX, + u128::MAX, + 0, + false + ))), debug_name: None, }), debug_name: None, @@ -1016,10 +1003,7 @@ fn secp256k1_get_xy() { let result = run_native_program( &SECP256_PROGRAM, "secp256k1_get_xy", - &[Value::Secp256K1Point { - x: (0, 0), - y: (0, 0), - }], + &[Value::Secp256K1Point(Secp256k1Point::default())], Some(u128::MAX), Some(&mut syscall_handler), ); @@ -1047,10 +1031,13 @@ fn secp256k1_get_xy() { let result = run_native_program( &SECP256_PROGRAM, "secp256k1_get_xy", - &[Value::Secp256K1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }], + &[Value::Secp256K1Point(Secp256k1Point::new( + 0, + u128::MAX, + u128::MAX, + 0, + false, + ))], Some(u128::MAX), Some(&mut syscall_handler), ); @@ -1078,10 +1065,13 @@ fn secp256k1_get_xy() { let result = run_native_program( &SECP256_PROGRAM, "secp256k1_get_xy", - &[Value::Secp256K1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }], + &[Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + 0, + 0, + u128::MAX, + false, + ))], Some(u128::MAX), Some(&mut syscall_handler), ); @@ -1109,10 +1099,13 @@ fn secp256k1_get_xy() { let result = run_native_program( &SECP256_PROGRAM, "secp256k1_get_xy", - &[Value::Secp256K1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }], + &[Value::Secp256K1Point(Secp256k1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false, + ))], Some(u128::MAX), Some(&mut syscall_handler), ); @@ -1143,6 +1136,7 @@ fn secp256k1_get_xy() { Secp256k1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false }, Secp256k1Point { x: U256 { @@ -1153,6 +1147,7 @@ fn secp256k1_get_xy() { lo: u128::MAX, hi: 0, }, + is_infinity: false }, Secp256k1Point { x: U256 { @@ -1163,6 +1158,7 @@ fn secp256k1_get_xy() { lo: 0, hi: u128::MAX, }, + is_infinity: false }, Secp256k1Point { x: U256 { @@ -1173,6 +1169,7 @@ fn secp256k1_get_xy() { hi: u128::MAX, lo: u128::MAX, }, + is_infinity: false }, ], ); @@ -1189,6 +1186,7 @@ fn secp256r1_new() { Some(Secp256r1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }), Some(Secp256r1Point { x: U256 { @@ -1199,6 +1197,7 @@ fn secp256r1_new() { hi: u128::MAX, lo: u128::MAX, }, + is_infinity: false, }), ]), ), @@ -1259,10 +1258,7 @@ fn secp256r1_new() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (0, 0), - y: (0, 0), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::default())), debug_name: None, }), debug_name: None, @@ -1291,10 +1287,13 @@ fn secp256r1_new() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false + ))), debug_name: None, }), debug_name: None, @@ -1339,6 +1338,7 @@ fn secp256r1_add() { Secp256r1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }, Secp256r1Point { x: U256 { @@ -1349,6 +1349,7 @@ fn secp256r1_add() { hi: 0, lo: u128::MAX, }, + is_infinity: false, }, Secp256r1Point { x: U256 { @@ -1359,6 +1360,7 @@ fn secp256r1_add() { hi: u128::MAX, lo: u128::MAX, }, + is_infinity: false, }, ]), ), @@ -1369,14 +1371,8 @@ fn secp256r1_add() { &SECP256_PROGRAM, "secp256r1_add", &[ - Value::Secp256R1Point { - x: (0, 0), - y: (0, 0), - }, - Value::Secp256R1Point { - x: (0, 0), - y: (0, 0), - }, + Value::Secp256R1Point(Secp256r1Point::default()), + Value::Secp256R1Point(Secp256r1Point::default()), ], Some(u128::MAX), Some(&mut syscall_handler), @@ -1385,10 +1381,7 @@ fn secp256r1_add() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (0, 0), - y: (0, 0), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::default())), debug_name: None, }, ); @@ -1397,14 +1390,8 @@ fn secp256r1_add() { &SECP256_PROGRAM, "secp256r1_add", &[ - Value::Secp256R1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }, - Value::Secp256R1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }, + Value::Secp256R1Point(Secp256r1Point::new(u128::MAX, 0, 0, u128::MAX, false)), + Value::Secp256R1Point(Secp256r1Point::new(0, u128::MAX, u128::MAX, 0, false)), ], Some(u128::MAX), Some(&mut syscall_handler), @@ -1413,10 +1400,13 @@ fn secp256r1_add() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::new( + 0, + u128::MAX, + u128::MAX, + 0, + false + ))), debug_name: None, }, ); @@ -1425,14 +1415,20 @@ fn secp256r1_add() { &SECP256_PROGRAM, "secp256r1_add", &[ - Value::Secp256R1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }, - Value::Secp256R1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }, + Value::Secp256R1Point(Secp256r1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false, + )), + Value::Secp256R1Point(Secp256r1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false, + )), ], Some(u128::MAX), Some(&mut syscall_handler), @@ -1441,10 +1437,13 @@ fn secp256r1_add() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false + )),), debug_name: None, }, ); @@ -1452,59 +1451,14 @@ fn secp256r1_add() { assert_eq!( syscall_handler.secp256r1_add.0, [ + (Secp256r1Point::default(), Secp256r1Point::default(),), ( - Secp256r1Point { - x: U256 { hi: 0, lo: 0 }, - y: U256 { hi: 0, lo: 0 }, - }, - Secp256r1Point { - x: U256 { hi: 0, lo: 0 }, - y: U256 { hi: 0, lo: 0 }, - }, - ), - ( - Secp256r1Point { - x: U256 { - lo: u128::MAX, - hi: 0 - }, - y: U256 { - lo: 0, - hi: u128::MAX - }, - }, - Secp256r1Point { - x: U256 { - lo: 0, - hi: u128::MAX - }, - y: U256 { - lo: u128::MAX, - hi: 0 - }, - }, + Secp256r1Point::new(u128::MAX, 0, 0, u128::MAX, false), + Secp256r1Point::new(0, u128::MAX, u128::MAX, 0, false), ), ( - Secp256r1Point { - x: U256 { - hi: u128::MAX, - lo: u128::MAX - }, - y: U256 { - hi: u128::MAX, - lo: u128::MAX - }, - }, - Secp256r1Point { - x: U256 { - hi: u128::MAX, - lo: u128::MAX - }, - y: U256 { - hi: u128::MAX, - lo: u128::MAX - }, - }, + Secp256r1Point::new(u128::MAX, u128::MAX, u128::MAX, u128::MAX, false), + Secp256r1Point::new(u128::MAX, u128::MAX, u128::MAX, u128::MAX, false), ), ], ); @@ -1520,6 +1474,7 @@ fn secp256r1_mul() { Secp256r1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }, Secp256r1Point { x: U256 { @@ -1530,6 +1485,7 @@ fn secp256r1_mul() { hi: 0, lo: u128::MAX, }, + is_infinity: false, }, Secp256r1Point { x: U256 { @@ -1540,6 +1496,7 @@ fn secp256r1_mul() { hi: u128::MAX, lo: u128::MAX, }, + is_infinity: false, }, ]), ), @@ -1550,10 +1507,7 @@ fn secp256r1_mul() { &SECP256_PROGRAM, "secp256r1_mul", &[ - Value::Secp256R1Point { - x: (0, 0), - y: (0, 0), - }, + Value::Secp256R1Point(Secp256r1Point::default()), Value::Struct { fields: vec![Value::Uint128(0), Value::Uint128(0)], debug_name: None, @@ -1566,10 +1520,7 @@ fn secp256r1_mul() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (0, 0), - y: (0, 0), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::default())), debug_name: None, }, ); @@ -1578,10 +1529,7 @@ fn secp256r1_mul() { &SECP256_PROGRAM, "secp256r1_mul", &[ - Value::Secp256R1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }, + Value::Secp256R1Point(Secp256r1Point::new(u128::MAX, 0, 0, u128::MAX, false)), Value::Struct { fields: vec![Value::Uint128(u128::MAX), Value::Uint128(0)], debug_name: None, @@ -1594,10 +1542,13 @@ fn secp256r1_mul() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::new( + 0, + u128::MAX, + u128::MAX, + 0, + false + ))), debug_name: None, }, ); @@ -1606,10 +1557,7 @@ fn secp256r1_mul() { &SECP256_PROGRAM, "secp256r1_mul", &[ - Value::Secp256R1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }, + Value::Secp256R1Point(Secp256r1Point::new(0, u128::MAX, u128::MAX, 0, false)), Value::Struct { fields: vec![Value::Uint128(0), Value::Uint128(u128::MAX)], debug_name: None, @@ -1622,10 +1570,13 @@ fn secp256r1_mul() { result.return_value, Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false + ))), debug_name: None, }, ); @@ -1633,40 +1584,16 @@ fn secp256r1_mul() { assert_eq!( syscall_handler.secp256r1_mul.0, [ + (Secp256r1Point::default(), U256 { hi: 0, lo: 0 },), ( - Secp256r1Point { - x: U256 { hi: 0, lo: 0 }, - y: U256 { hi: 0, lo: 0 }, - }, - U256 { hi: 0, lo: 0 }, - ), - ( - Secp256r1Point { - x: U256 { - lo: u128::MAX, - hi: 0 - }, - y: U256 { - lo: 0, - hi: u128::MAX, - }, - }, + Secp256r1Point::new(u128::MAX, 0, 0, u128::MAX, false), U256 { lo: u128::MAX, hi: 0, }, ), ( - Secp256r1Point { - x: U256 { - lo: 0, - hi: u128::MAX, - }, - y: U256 { - lo: u128::MAX, - hi: 0, - }, - }, + Secp256r1Point::new(0, u128::MAX, u128::MAX, 0, false), U256 { lo: 0, hi: u128::MAX, @@ -1687,6 +1614,7 @@ fn secp256r1_get_point_from_x() { Some(Secp256r1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false, }), Some(Secp256r1Point { x: U256 { @@ -1697,6 +1625,7 @@ fn secp256r1_get_point_from_x() { hi: u128::MAX, lo: 0, }, + is_infinity: false, }), Some(Secp256r1Point { x: U256 { @@ -1707,6 +1636,7 @@ fn secp256r1_get_point_from_x() { hi: 0, lo: u128::MAX, }, + is_infinity: false, }), ]), ), @@ -1775,10 +1705,7 @@ fn secp256r1_get_point_from_x() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (0, 0), - y: (0, 0), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::default())), debug_name: None, }), debug_name: None, @@ -1811,10 +1738,13 @@ fn secp256r1_get_point_from_x() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::new( + u128::MAX, + 0, + 0, + u128::MAX, + false + ))), debug_name: None, }), debug_name: None, @@ -1847,10 +1777,13 @@ fn secp256r1_get_point_from_x() { tag: 0, value: Box::new(Value::Enum { tag: 0, - value: Box::new(Value::Secp256R1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }), + value: Box::new(Value::Secp256R1Point(Secp256r1Point::new( + 0, + u128::MAX, + u128::MAX, + 0, + false + ))), debug_name: None, }), debug_name: None, @@ -1932,10 +1865,7 @@ fn secp256r1_get_xy() { let result = run_native_program( &SECP256_PROGRAM, "secp256r1_get_xy", - &[Value::Secp256R1Point { - x: (0, 0), - y: (0, 0), - }], + &[Value::Secp256R1Point(Secp256r1Point::default())], Some(u128::MAX), Some(&mut syscall_handler), ); @@ -1963,10 +1893,13 @@ fn secp256r1_get_xy() { let result = run_native_program( &SECP256_PROGRAM, "secp256r1_get_xy", - &[Value::Secp256R1Point { - x: (0, u128::MAX), - y: (u128::MAX, 0), - }], + &[Value::Secp256R1Point(Secp256r1Point::new( + 0, + u128::MAX, + u128::MAX, + 0, + false, + ))], Some(u128::MAX), Some(&mut syscall_handler), ); @@ -1994,10 +1927,13 @@ fn secp256r1_get_xy() { let result = run_native_program( &SECP256_PROGRAM, "secp256r1_get_xy", - &[Value::Secp256R1Point { - x: (u128::MAX, 0), - y: (0, u128::MAX), - }], + &[Value::Secp256R1Point(Secp256r1Point::new( + u128::MAX, + 0, + 0, + u128::MAX, + false, + ))], Some(u128::MAX), Some(&mut syscall_handler), ); @@ -2025,10 +1961,13 @@ fn secp256r1_get_xy() { let result = run_native_program( &SECP256_PROGRAM, "secp256r1_get_xy", - &[Value::Secp256R1Point { - x: (u128::MAX, u128::MAX), - y: (u128::MAX, u128::MAX), - }], + &[Value::Secp256R1Point(Secp256r1Point::new( + u128::MAX, + u128::MAX, + u128::MAX, + u128::MAX, + false, + ))], Some(u128::MAX), Some(&mut syscall_handler), ); @@ -2059,6 +1998,7 @@ fn secp256r1_get_xy() { Secp256r1Point { x: U256 { hi: 0, lo: 0 }, y: U256 { hi: 0, lo: 0 }, + is_infinity: false }, Secp256r1Point { x: U256 { @@ -2069,6 +2009,7 @@ fn secp256r1_get_xy() { lo: u128::MAX, hi: 0, }, + is_infinity: false }, Secp256r1Point { x: U256 { @@ -2079,6 +2020,7 @@ fn secp256r1_get_xy() { lo: 0, hi: u128::MAX, }, + is_infinity: false }, Secp256r1Point { x: U256 { @@ -2089,6 +2031,7 @@ fn secp256r1_get_xy() { hi: u128::MAX, lo: u128::MAX, }, + is_infinity: false }, ], ); diff --git a/tests/tests/starknet/u256.rs b/tests/tests/starknet/u256.rs index cdca1ea50..0557e000d 100644 --- a/tests/tests/starknet/u256.rs +++ b/tests/tests/starknet/u256.rs @@ -43,6 +43,6 @@ fn u256_test() { ); assert_eq!( result.remaining_gas, - 340282366920938463463374607431768012415 + 340282366920938463463374607431768192315 ); }