From 4cf5973f26f5ca70162fa2ff8e41a2ab2eb21d4b Mon Sep 17 00:00:00 2001 From: jrigada Date: Fri, 10 Mar 2023 10:12:32 -0300 Subject: [PATCH] Revert "Wasm32 support (#828)" This reverts commit c326ba8c63dc36f16e99524e4489b76891b41c96. --- .github/workflows/rust.yml | 8 - Cargo.lock | 325 ++-- Cargo.toml | 102 +- Makefile | 22 +- bench/criterion_benchmark.rs | 3 +- bench/iai_benchmark.rs | 10 +- bench/run_benchmarks.sh | 2 +- cairo-vm-cli/Cargo.toml | 11 - deps/parse-hyperlinks/Cargo.toml | 10 +- deps/parse-hyperlinks/src/lib.rs | 5 - felt/Cargo.toml | 19 +- felt/src/bigint_felt.rs | 35 +- felt/src/lib.rs | 56 +- src/cairo_run.rs | 240 +-- .../builtin_hint_processor/blake2s_hash.rs | 12 +- .../builtin_hint_processor/blake2s_utils.rs | 19 +- .../builtin_hint_processor_definition.rs | 28 +- .../cairo_keccak/keccak_hints.rs | 16 +- .../builtin_hint_processor/dict_hint_utils.rs | 36 +- .../builtin_hint_processor/dict_manager.rs | 16 +- .../find_element_hint.rs | 35 +- .../builtin_hint_processor/hint_utils.rs | 17 +- .../builtin_hint_processor/keccak_utils.rs | 3 +- .../builtin_hint_processor/math_utils.rs | 85 +- .../memcpy_hint_utils.rs | 8 +- .../builtin_hint_processor/memset_utils.rs | 13 +- .../builtin_hint_processor/pow_utils.rs | 12 +- .../secp/bigint_utils.rs | 12 +- .../builtin_hint_processor/secp/ec_utils.rs | 22 +- .../secp/field_utils.rs | 21 +- .../builtin_hint_processor/secp/secp_utils.rs | 12 +- .../builtin_hint_processor/secp/signature.rs | 20 +- .../builtin_hint_processor/segments.rs | 9 +- .../builtin_hint_processor/set.rs | 12 +- .../builtin_hint_processor/sha256_utils.rs | 9 +- .../builtin_hint_processor/signature.rs | 8 +- .../squash_dict_utils.rs | 70 +- .../builtin_hint_processor/uint256_utils.rs | 26 +- .../builtin_hint_processor/usort.rs | 10 +- .../hint_processor_definition.rs | 4 +- src/hint_processor/hint_processor_utils.rs | 20 +- src/lib.rs | 49 - {cairo-vm-cli/src => src}/main.rs | 90 +- src/math_utils.rs | 27 +- src/serde/deserialize_program.rs | 99 +- src/serde/deserialize_utils.rs | 33 +- src/tests/cairo_run_test.rs | 1402 ----------------- src/tests/mod.rs | 7 - src/types/errors/math_errors.rs | 4 - src/types/errors/program_errors.rs | 16 +- src/types/exec_scope.rs | 18 +- .../bitwise_instance_def.rs | 7 - .../builtins_instance_def.rs | 10 - .../instance_definitions/cpu_instance_def.rs | 4 - .../diluted_pool_instance_def.rs | 5 - .../ec_op_instance_def.rs | 7 - .../ecdsa_instance_def.rs | 7 - .../keccak_instance_def.rs | 9 - .../pedersen_instance_def.rs | 7 - .../range_check_instance_def.rs | 7 - src/types/instruction.rs | 6 - src/types/layout.rs | 12 - src/types/program.rs | 60 +- src/types/relocatable.rs | 53 +- src/utils.rs | 81 +- src/vm/context/run_context.rs | 15 - src/vm/decoding/decoder.rs | 16 - src/vm/errors/cairo_run_errors.rs | 6 +- src/vm/errors/exec_scope_errors.rs | 3 - src/vm/errors/hint_errors.rs | 8 +- src/vm/errors/memory_errors.rs | 8 +- src/vm/errors/runner_errors.rs | 10 +- src/vm/errors/trace_errors.rs | 6 +- src/vm/errors/vm_errors.rs | 13 +- src/vm/errors/vm_exception.rs | 179 +-- src/vm/hooks.rs | 25 +- src/vm/runners/builtin_runner/bitwise.rs | 31 +- src/vm/runners/builtin_runner/ec_op.rs | 118 +- src/vm/runners/builtin_runner/hash.rs | 25 +- src/vm/runners/builtin_runner/keccak.rs | 39 +- src/vm/runners/builtin_runner/mod.rs | 79 - src/vm/runners/builtin_runner/output.rs | 26 +- src/vm/runners/builtin_runner/range_check.rs | 38 +- src/vm/runners/builtin_runner/signature.rs | 32 +- src/vm/runners/cairo_runner.rs | 269 ++-- src/vm/security.rs | 15 +- src/vm/trace/mod.rs | 8 +- src/vm/trace/trace_entry.rs | 8 - src/vm/vm_core.rs | 172 +- src/vm/vm_memory/memory.rs | 69 +- src/vm/vm_memory/memory_segments.rs | 53 +- src/with_alloc.rs | 15 - src/with_std.rs | 34 - src/without_std.rs | 24 - {src/tests => tests}/bitwise_test.rs | 18 +- tests/cairo_run_test.rs | 267 ++-- {src/tests => tests}/compare_vm_state.sh | 0 {src/tests => tests}/memory_comparator.py | 0 {src/tests => tests}/pedersen_test.rs | 20 +- {src/tests => tests}/skip_instruction_test.rs | 21 +- {src/tests => tests}/struct_test.rs | 24 +- 101 files changed, 898 insertions(+), 4219 deletions(-) delete mode 100644 cairo-vm-cli/Cargo.toml rename {cairo-vm-cli/src => src}/main.rs (54%) delete mode 100644 src/tests/cairo_run_test.rs delete mode 100644 src/tests/mod.rs delete mode 100644 src/with_alloc.rs delete mode 100644 src/with_std.rs delete mode 100644 src/without_std.rs rename {src/tests => tests}/bitwise_test.rs (94%) rename {src/tests => tests}/compare_vm_state.sh (100%) rename {src/tests => tests}/memory_comparator.py (100%) rename {src/tests => tests}/pedersen_test.rs (87%) rename {src/tests => tests}/skip_instruction_test.rs (61%) rename {src/tests => tests}/struct_test.rs (63%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 49d668e8c2..48e96fe5c8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -28,10 +28,6 @@ jobs: uses: taiki-e/install-action@nextest - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov - - name: Install wasm-bindgen-cli - uses: jetli/wasm-pack-action@v0.4.0 - with: - version: "v0.10.3" - name: Set up cargo cache uses: Swatinem/rust-cache@v2 @@ -66,10 +62,6 @@ jobs: run: pip install ecdsa fastecdsa sympy cairo-lang - name: Run tests run: make -j test - - name: Run tests no_std - run: make -j test-no_std - - name: Run wasm tests - run: make -j test-wasm - name: Compare trace and memory run: make -j compare_trace_memory - name: Compare trace and memory with proof mode diff --git a/Cargo.lock b/Cargo.lock index a28f8f71cc..dabc670b47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,23 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", -] - -[[package]] -name = "anyhow" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" - [[package]] name = "ark-ff" version = "0.3.0" @@ -103,20 +86,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "bincode" -version = "2.0.0-rc.2" -source = "git+https://github.com/bincode-org/bincode.git?tag=v2.0.0-rc.2#6c219e9214bda2bdce1327db6ed7f66d2fa4bf02" +name = "bigdecimal" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aaf33151a6429fe9211d1b276eafdf70cdff28b071e76c0b0e1503221ea3744" dependencies = [ - "bincode_derive", - "serde", + "num-bigint", + "num-integer", + "num-traits", ] [[package]] -name = "bincode_derive" -version = "2.0.0-rc.2" -source = "git+https://github.com/bincode-org/bincode.git?tag=v2.0.0-rc.2#6c219e9214bda2bdce1327db6ed7f66d2fa4bf02" +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" dependencies = [ - "virtue", + "serde", ] [[package]] @@ -140,6 +126,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "block-buffer" version = "0.10.3" @@ -149,6 +144,18 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", + "serde", +] + [[package]] name = "bumpalo" version = "3.12.0" @@ -163,7 +170,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cairo-felt" -version = "0.2.0" +version = "0.1.3" dependencies = [ "lazy_static", "num-bigint", @@ -175,15 +182,14 @@ dependencies = [ [[package]] name = "cairo-vm" -version = "0.2.0" +version = "0.1.3" dependencies = [ - "anyhow", "assert_matches", "bincode", "cairo-felt", + "clap 3.2.23", "criterion", "generic-array", - "hashbrown 0.13.2", "hex", "iai", "keccak", @@ -199,23 +205,10 @@ dependencies = [ "serde", "serde_bytes", "serde_json", - "sha2", + "sha2 0.10.6", "sha3", "starknet-crypto", "thiserror", - "thiserror-no-std", - "wasm-bindgen-test", -] - -[[package]] -name = "cairo-vm-cli" -version = "0.1.0" -dependencies = [ - "bincode", - "cairo-vm", - "clap 3.2.23", - "nom", - "thiserror", ] [[package]] @@ -295,16 +288,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "console_error_panic_hook" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" -dependencies = [ - "cfg-if", - "wasm-bindgen", -] - [[package]] name = "cpufeatures" version = "0.2.5" @@ -395,11 +378,12 @@ dependencies = [ [[package]] name = "crypto-bigint" -version = "0.4.9" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" +checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ "generic-array", + "rand_core", "subtle", "zeroize", ] @@ -414,14 +398,25 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "csv" -version = "1.2.0" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af91f40b7355f82b0a891f50e70399475945bb0b0da4f1700ce60761c9d3e359" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" dependencies = [ + "bstr", "csv-core", - "itoa", + "itoa 0.4.8", "ryu", "serde", ] @@ -461,16 +456,15 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "block-buffer", + "block-buffer 0.10.3", "crypto-common", - "subtle", ] [[package]] name = "either" -version = "1.8.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "envmnt" @@ -547,21 +541,11 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", - "serde", -] - [[package]] name = "heck" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -589,11 +573,12 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hmac" -version = "0.12.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" dependencies = [ - "digest 0.10.6", + "crypto-mac", + "digest 0.9.0", ] [[package]] @@ -609,7 +594,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown 0.12.3", + "hashbrown", ] [[package]] @@ -630,6 +615,12 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + [[package]] name = "itoa" version = "1.0.5" @@ -638,9 +629,9 @@ checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -659,9 +650,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] [[package]] name = "libc" @@ -669,12 +657,6 @@ version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" -[[package]] -name = "libm" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" - [[package]] name = "libmimalloc-sys" version = "0.1.30" @@ -769,7 +751,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -794,6 +775,12 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "os_str_bytes" version = "6.4.1" @@ -805,7 +792,6 @@ name = "parse-hyperlinks" version = "0.23.4" dependencies = [ "nom", - "wasm-bindgen-test", ] [[package]] @@ -893,9 +879,9 @@ dependencies = [ [[package]] name = "proptest" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70" +checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5" dependencies = [ "bit-set", "bitflags", @@ -909,7 +895,6 @@ dependencies = [ "regex-syntax", "rusty-fork", "tempfile", - "unarray", ] [[package]] @@ -1012,6 +997,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.28" @@ -1029,9 +1020,9 @@ dependencies = [ [[package]] name = "rfc6979" -version = "0.3.1" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +checksum = "96ef608575f6392792f9ecf7890c00086591d29a83910939d430753f7c050525" dependencies = [ "crypto-bigint", "hmac", @@ -1086,12 +1077,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "scopeguard" version = "1.1.0" @@ -1127,9 +1112,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.9" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +checksum = "718dc5fff5b36f99093fc49b280cfc96ce6fc824317783bff5a1fed0c7a64819" dependencies = [ "serde", ] @@ -1161,11 +1146,24 @@ version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ - "itoa", + "itoa 1.0.5", "ryu", "serde", ] +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + [[package]] name = "sha2" version = "0.10.6" @@ -1187,37 +1185,32 @@ dependencies = [ "keccak", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "starknet-crypto" version = "0.2.0" -source = "git+https://github.com/tdelabro/starknet-rs.git?branch=feature/manual-no-std-bigdecimal#13023c5bbd0426ce064bc31e21bc70b517818b85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be7d6b2c959fde2a10dbc31d54bdd0307eecb7ef6c05c23a0263e65b57b3e18a" dependencies = [ "crypto-bigint", - "hashbrown 0.13.2", "hex", "hmac", "num-bigint", "num-integer", "num-traits", "rfc6979", - "sha2", + "sha2 0.9.9", "starknet-crypto-codegen", "starknet-curve", "starknet-ff", - "thiserror-no-std", + "thiserror", "zeroize", ] [[package]] name = "starknet-crypto-codegen" version = "0.1.0" -source = "git+https://github.com/tdelabro/starknet-rs.git?branch=feature/manual-no-std-bigdecimal#13023c5bbd0426ce064bc31e21bc70b517818b85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6569d70430f0f6edc41f6820d00acf63356e6308046ca01e57eeac22ad258c47" dependencies = [ "starknet-curve", "starknet-ff", @@ -1227,7 +1220,8 @@ dependencies = [ [[package]] name = "starknet-curve" version = "0.1.0" -source = "git+https://github.com/tdelabro/starknet-rs.git?branch=feature/manual-no-std-bigdecimal#13023c5bbd0426ce064bc31e21bc70b517818b85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84be6079d3060fdbd8b5335574fef3d3783fa2f7ee6474d08ae0c1e4b0a29ba4" dependencies = [ "starknet-ff", ] @@ -1235,14 +1229,17 @@ dependencies = [ [[package]] name = "starknet-ff" version = "0.2.0" -source = "git+https://github.com/tdelabro/starknet-rs.git?branch=feature/manual-no-std-bigdecimal#13023c5bbd0426ce064bc31e21bc70b517818b85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5874510620214ebeac50915b01d67437d8ca10a6682b1de85b93cd01157b58eb" dependencies = [ "ark-ff", + "bigdecimal", "crypto-bigint", "getrandom", "hex", + "num-bigint", "serde", - "thiserror-no-std", + "thiserror", ] [[package]] @@ -1338,26 +1335,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thiserror-impl-no-std" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e6318948b519ba6dc2b442a6d0b904ebfb8d411a3ad3e07843615a72249758" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thiserror-no-std" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3ad459d94dd517257cc96add8a43190ee620011bb6e6cdc82dafd97dfafafea" -dependencies = [ - "thiserror-impl-no-std", -] - [[package]] name = "tinytemplate" version = "1.2.1" @@ -1389,12 +1366,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" -[[package]] -name = "unarray" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" - [[package]] name = "unicode-ident" version = "1.0.6" @@ -1419,12 +1390,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "virtue" -version = "0.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b60dcd6a64dd45abf9bd426970c9843726da7fc08f44cd6fcebf68c21220a63" - [[package]] name = "wait-timeout" version = "0.2.0" @@ -1453,9 +1418,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1463,9 +1428,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -1476,23 +1441,11 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1500,9 +1453,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -1513,33 +1466,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" - -[[package]] -name = "wasm-bindgen-test" -version = "0.3.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db36fc0f9fb209e88fb3642590ae0205bb5a56216dabd963ba15879fe53a30b" -dependencies = [ - "console_error_panic_hook", - "js-sys", - "scoped-tls", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-test-macro", -] - -[[package]] -name = "wasm-bindgen-test-macro" -version = "0.3.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0734759ae6b3b1717d661fe4f016efcfb9828f5edb4520c18eaee05af3b43be9" -dependencies = [ - "proc-macro2", - "quote", -] +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" diff --git a/Cargo.toml b/Cargo.toml index 7794e20ad5..29b7f9e967 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,88 +1,62 @@ [workspace] -members = [".", "felt", "cairo-vm-cli", "./deps/parse-hyperlinks"] +members = [".", "felt", "./deps/parse-hyperlinks"] [package] name = "cairo-vm" -version = "0.2.0" +version = "0.1.3" edition = "2021" license = "Apache-2.0" description = "Blazing fast Cairo interpreter" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + [features] -default = ["std", "with_mimalloc"] +default = ["with_mimalloc"] with_mimalloc = ["mimalloc"] -std = [ - "serde_json/std", - "serde_bytes/std", - "bincode/std", - "anyhow/std", - "starknet-crypto/std", - "parse-hyperlinks/std", - "felt/std", -] -alloc = [ - "serde_json/alloc", - "serde_bytes/alloc", - "starknet-crypto/alloc", - "parse-hyperlinks/alloc", - "felt/alloc", -] - - +# This feature will reference every test-oriented feature. # Note that these features are not retro-compatible with the cairo Python VM. -test_utils = [ - "skip_next_instruction_hint", - "hooks", -] # This feature will reference every test-oriented feature +test_utils = ["skip_next_instruction_hint", "hooks"] skip_next_instruction_hint = [] hooks = [] [dependencies] mimalloc = { version = "0.1.29", default-features = false, optional = true } -num-bigint = { version = "0.4", features = ["serde"], default-features = false } -num-traits = { version = "0.2", default-features = false } -num-integer = { version = "0.1.45", default-features = false } -serde = { version = "1.0", features = ["derive"], default-features = false } -serde_bytes = { version = "0.11.9", default-features = false } -serde_json = { version = "1.0", features = [ - "arbitrary_precision", -], default-features = false } -hex = { version = "0.4.3", default-features = false } -bincode = { tag = "v2.0.0-rc.2", git = "https://github.com/bincode-org/bincode.git", default-features = false, features = [ - "serde", -] } -starknet-crypto = { git = "https://github.com/tdelabro/starknet-rs.git", branch = "feature/manual-no-std-bigdecimal", default-features = false } -sha3 = { version = "0.10.1", default-features = false } -rand_core = { version = "0.6.4", default-features = false } -lazy_static = { version = "1.4.0", default-features = false, features = [ - "spin_no_std", -] } -nom = { version = "7", default-features = false } -sha2 = { version = "0.10.2", features = ["compress"], default-features = false } -generic-array = { version = "0.14.6", default-features = false } -keccak = { version = "0.1.2", default-features = false } -hashbrown = { version = "0.13.2", features = ["serde"] } -anyhow = { version = "1.0.69", default-features = false } -thiserror = { version = "1.0.32", default-features = false } -thiserror-no-std = "2.0.2" - +num-bigint = { version = "0.4", features = ["serde"] } +num-traits = "0.2" +num-integer = "0.1.45" +serde = { version = "1.0", features = ["derive"] } +serde_bytes = "0.11.1" +serde_json = { version = "1.0", features = ["arbitrary_precision"] } +hex = "0.4.3" +bincode = "1.2.1" +starknet-crypto = "0.2.0" +clap = { version = "3.2.5", features = ["derive"] } +sha3 = "0.10.1" +rand_core = "0.6.4" +lazy_static = "1.4.0" +nom = "7" +sha2 = { version = "0.10.2", features = ["compress"] } +thiserror = "1.0.32" +generic-array = "0.14.6" +keccak = "0.1.2" # This crate has only one function `take_until_unbalanced` that is # very useful for our parsing purposes: # https://stackoverflow.com/questions/70630556/parse-allowing-nested-parentheses-in-nom # There is a proposal for extending nom::delimited to use this function: # https://github.com/Geal/nom/issues/1253 -parse-hyperlinks = { path = "./deps/parse-hyperlinks", version = "0.23.4", default-features = false } -felt = { package = "cairo-felt", path = "./felt", default-features = false } +parse-hyperlinks = { path = "./deps/parse-hyperlinks", version = "0.23.4" } +felt = { package = "cairo-felt", path = "./felt", version = "0.1.0" } -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] -wasm-bindgen-test = "0.3.34" -assert_matches = "1.5.0" - -[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +[dev-dependencies] iai = "0.1" -rusty-hook = "0.11" assert_matches = "1.5.0" -criterion = { version = "0.3", features = ["html_reports"] } + +[dev-dependencies.rusty-hook] +version = "0.11" + +[dev-dependencies.criterion] +version = "0.3" +features = ["html_reports"] [[bench]] path = "bench/iai_benchmark.rs" @@ -94,5 +68,11 @@ path = "bench/criterion_benchmark.rs" name = "criterion_benchmark" harness = false +[[bin]] +name = "cairo-rs-run" +path = "src/main.rs" +bench = false +doc = false + [profile.release] lto = "fat" diff --git a/Makefile b/Makefile index 5173f74552..f87c6cb330 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ $(TEST_PROOF_DIR)/%.json: $(TEST_PROOF_DIR)/%.cairo cairo-compile --cairo_path="$(TEST_PROOF_DIR):$(PROOF_BENCH_DIR)" $< --output $@ --proof_mode $(TEST_PROOF_DIR)/%.rs.trace $(TEST_PROOF_DIR)/%.rs.memory: $(TEST_PROOF_DIR)/%.json $(RELBIN) - cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all --proof_mode $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory + cargo llvm-cov run --release --no-report -- --layout all --proof_mode $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory $(TEST_PROOF_DIR)/%.trace $(TEST_PROOF_DIR)/%.memory: $(TEST_PROOF_DIR)/%.json cairo-run --layout all --proof_mode --program $< --trace_file $@ --memory_file $(@D)/$(*F).memory @@ -68,7 +68,7 @@ $(TEST_DIR)/%.json: $(TEST_DIR)/%.cairo cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@ $(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory: $(TEST_DIR)/%.json $(RELBIN) - cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory + cargo llvm-cov run --release --no-report -- --layout all $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory $(TEST_DIR)/%.trace $(TEST_DIR)/%.memory: $(TEST_DIR)/%.json cairo-run --layout all --program $< --trace_file $@ --memory_file $(@D)/$(*F).memory @@ -107,7 +107,7 @@ $(RELBIN): build: $(RELBIN) run: - cargo run -p cairo-vm-cli + cargo run check: cargo check @@ -121,10 +121,6 @@ cairo-rs_trace: $(CAIRO_RS_TRACE) $(CAIRO_RS_MEM) test: $(COMPILED_PROOF_TESTS) $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) cargo llvm-cov nextest --no-report --workspace --features test_utils -test-no_std: $(COMPILED_PROOF_TESTS) $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) - cargo llvm-cov nextest --no-report --workspace --features test_utils --no-default-features --features alloc -test-wasm: $(COMPILED_PROOF_TESTS) $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) - wasm-pack test --node --no-default-features --features alloc clippy: cargo clippy --tests --examples --all-features -- -D warnings @@ -152,22 +148,22 @@ compare_benchmarks: $(COMPILED_BENCHES) cd bench && ./run_benchmarks.sh compare_trace_memory: $(CAIRO_RS_TRACE) $(CAIRO_TRACE) $(CAIRO_RS_MEM) $(CAIRO_MEM) - cd src/tests; ./compare_vm_state.sh trace memory + cd tests; ./compare_vm_state.sh trace memory compare_trace: $(CAIRO_RS_TRACE) $(CAIRO_TRACE) - cd src/tests; ./compare_vm_state.sh trace + cd tests; ./compare_vm_state.sh trace compare_memory: $(CAIRO_RS_MEM) $(CAIRO_MEM) - cd src/tests; ./compare_vm_state.sh memory + cd tests; ./compare_vm_state.sh memory compare_trace_memory_proof: $(COMPILED_PROOF_TESTS) $(CAIRO_RS_TRACE_PROOF) $(CAIRO_TRACE_PROOF) $(CAIRO_RS_MEM_PROOF) $(CAIRO_MEM_PROOF) - cd src/tests; ./compare_vm_state.sh trace memory proof_mode + cd tests; ./compare_vm_state.sh trace memory proof_mode compare_trace_proof: $(CAIRO_RS_TRACE_PROOF) $(CAIRO_TRACE_PROOF) - cd src/tests; ./compare_vm_state.sh trace proof_mode + cd tests; ./compare_vm_state.sh trace proof_mode compare_memory_proof: $(CAIRO_RS_MEM_PROOF) $(CAIRO_MEM_PROOF) - cd src/tests; ./compare_vm_state.sh memory proof_mode + cd tests; ./compare_vm_state.sh memory proof_mode # Run with nightly enable the `doc_cfg` feature wich let us provide clear explaination about which parts of the code are behind a feature flag docs: diff --git a/bench/criterion_benchmark.rs b/bench/criterion_benchmark.rs index 2ca326bbce..4df2f75bc1 100644 --- a/bench/criterion_benchmark.rs +++ b/bench/criterion_benchmark.rs @@ -32,11 +32,10 @@ pub fn criterion_benchmarks(c: &mut Criterion) { ..cairo_vm::cairo_run::CairoRunConfig::default() }; for benchmark_name in build_bench_strings() { - let file_content = std::fs::read(Path::new(&benchmark_name.1)).unwrap(); c.bench_function(&benchmark_name.0, |b| { b.iter(|| { cairo_run::cairo_run( - black_box(&file_content), + black_box(Path::new(&benchmark_name.1)), &cairo_run_config, &mut hint_executor, ) diff --git a/bench/iai_benchmark.rs b/bench/iai_benchmark.rs index 496118035e..9763e99983 100644 --- a/bench/iai_benchmark.rs +++ b/bench/iai_benchmark.rs @@ -4,13 +4,12 @@ use cairo_vm::{ cairo_run::cairo_run, hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, vm::errors::cairo_run_errors::CairoRunError, vm::runners::cairo_runner::CairoRunner, - vm::vm_core::VirtualMachine, }; use iai::{black_box, main}; macro_rules! iai_bench_expand_prog { ($val: ident) => { - fn $val() -> Result<(CairoRunner, VirtualMachine), CairoRunError> { + fn $val() -> Result { let cairo_run_config = cairo_vm::cairo_run::CairoRunConfig { layout: "all", ..cairo_vm::cairo_run::CairoRunConfig::default() @@ -21,12 +20,7 @@ macro_rules! iai_bench_expand_prog { stringify!($val), ".json" )); - let program_content = std::fs::read(path).unwrap(); - cairo_run( - black_box(&program_content), - &cairo_run_config, - &mut hint_executor, - ) + cairo_run(black_box(path), &cairo_run_config, &mut hint_executor) } }; } diff --git a/bench/run_benchmarks.sh b/bench/run_benchmarks.sh index e5506de4c9..624b2e01d0 100755 --- a/bench/run_benchmarks.sh +++ b/bench/run_benchmarks.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh -tests_path="cairo_programs/benchmarks" +tests_path="../cairo_programs/benchmarks" set -e diff --git a/cairo-vm-cli/Cargo.toml b/cairo-vm-cli/Cargo.toml deleted file mode 100644 index ee0a5fcc1d..0000000000 --- a/cairo-vm-cli/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "cairo-vm-cli" -version = "0.1.0" -edition = "2021" - -[dependencies] -cairo-vm = { path = ".." } -clap = { version = "3.2.5", features = ["derive"] } -nom = "7" -thiserror = { version = "1.0.32" } -bincode = { tag = "v2.0.0-rc.2", git = "https://github.com/bincode-org/bincode.git" } diff --git a/deps/parse-hyperlinks/Cargo.toml b/deps/parse-hyperlinks/Cargo.toml index 9752d93471..b80392e2c7 100644 --- a/deps/parse-hyperlinks/Cargo.toml +++ b/deps/parse-hyperlinks/Cargo.toml @@ -12,12 +12,4 @@ description = "A Nom parser library for hyperlinks with markup." categories = ["command-line-utilities", "parser-implementations"] [dependencies] -nom = { version = "7.1.1", default-features = false } - -[features] -default = ["std"] -std = ["nom/std"] -alloc = ["nom/alloc"] - -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] -wasm-bindgen-test = "0.3.34" +nom= "7.1.1" diff --git a/deps/parse-hyperlinks/src/lib.rs b/deps/parse-hyperlinks/src/lib.rs index 8da099d0c5..cc1aa7af4c 100644 --- a/deps/parse-hyperlinks/src/lib.rs +++ b/deps/parse-hyperlinks/src/lib.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -#![cfg_attr(not(feature = "std"), no_std)] use nom::error::Error; use nom::error::ErrorKind; @@ -88,11 +87,7 @@ mod tests { use super::*; use nom::error::ErrorKind; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_take_until_unmatched() { assert_eq!(take_until_unbalanced('(', ')')("abc"), Ok(("", "abc"))); assert_eq!( diff --git a/felt/Cargo.toml b/felt/Cargo.toml index e1a7c221ac..c21a8706fe 100644 --- a/felt/Cargo.toml +++ b/felt/Cargo.toml @@ -1,23 +1,18 @@ [package] name = "cairo-felt" -version = "0.2.0" +version = "0.1.3" edition = "2021" license = "Apache-2.0" description = "Field elements representation for the Cairo VM" -[features] -default = ["std"] -std = [] -alloc = [] +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -num-integer = { version = "0.1.45", default-features = false } -num-bigint = { version = "0.4", features = ["serde"], default-features = false } -num-traits = { version = "0.2.15", default-features = false } -lazy_static = { version = "1.4.0", default-features = false, features = [ - "spin_no_std", -] } -serde = { version = "1.0", features = ["derive"], default-features = false } +num-integer = "0.1.45" +num-bigint = { version = "0.4", features = ["serde"] } +num-traits = "0.2.15" +lazy_static = "1.4.0" +serde = { version = "1.0", features = ["derive"] } [dev-dependencies] proptest = "1.0.0" diff --git a/felt/src/bigint_felt.rs b/felt/src/bigint_felt.rs index e0e24acd64..8c2a9f8e4a 100644 --- a/felt/src/bigint_felt.rs +++ b/felt/src/bigint_felt.rs @@ -1,8 +1,9 @@ -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use alloc::{string::String, vec::Vec}; - -use core::{ - cmp, +use lazy_static::lazy_static; +use num_bigint::{BigInt, BigUint, ToBigInt, U64Digits}; +use num_integer::Integer; +use num_traits::{Bounded, FromPrimitive, Num, One, Pow, Signed, ToPrimitive, Zero}; +use serde::{Deserialize, Serialize}; +use std::{ convert::Into, fmt, iter::Sum, @@ -16,11 +17,6 @@ use crate::{FeltOps, ParseFeltError}; pub const FIELD_HIGH: u128 = (1 << 123) + (17 << 64); // this is equal to 10633823966279327296825105735305134080 pub const FIELD_LOW: u128 = 1; -use lazy_static::lazy_static; -use num_bigint::{BigInt, BigUint, ToBigInt, U64Digits}; -use num_integer::Integer; -use num_traits::{Bounded, FromPrimitive, Num, One, Pow, Signed, ToPrimitive, Zero}; -use serde::{Deserialize, Serialize}; lazy_static! { static ref CAIRO_PRIME_BIGUINT: BigUint = @@ -152,12 +148,10 @@ impl FeltOps for FeltBigInt { self.val.iter_u64_digits() } - #[cfg(any(feature = "std", feature = "alloc"))] fn to_signed_bytes_le(&self) -> Vec { self.val.to_bytes_le() } - #[cfg(any(feature = "std", feature = "alloc"))] fn to_bytes_be(&self) -> Vec { self.val.to_bytes_be() } @@ -177,7 +171,6 @@ impl FeltOps for FeltBigInt { Self::from(value) } - #[cfg(any(feature = "std", feature = "alloc"))] fn to_str_radix(&self, radix: u32) -> String { self.val.to_str_radix(radix) } @@ -634,7 +627,7 @@ impl Integer for FeltBigInt { } fn lcm(&self, other: &Self) -> Self { - Self::new(cmp::max(&self.val, &other.val)) + Self::new(std::cmp::max(&self.val, &other.val)) } fn mod_floor(&self, other: &Self) -> Self { @@ -836,15 +829,8 @@ mod tests { use super::*; use proptest::prelude::*; - #[cfg(all(not(feature = "std"), feature = "alloc"))] - use alloc::string::ToString; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] // Tests that the result of adding two zeros is zero. - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_zeros() { let a = FeltBigInt::::new(0); let b = FeltBigInt::new(0); @@ -854,7 +840,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Tests that the result of performing add assign with two zeros is zero. fn add_assign_zeros() { let mut a = FeltBigInt::::new(0); @@ -913,7 +898,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Tests that the result of multiplying two zeros is zero. fn mul_zeros() { let a = FeltBigInt::::new(0); @@ -924,7 +908,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Tests that the result of multiplying two zeros with assignment is zero. fn mul_assign_zeros() { let mut a = FeltBigInt::::new(0); @@ -936,7 +919,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Tests that the result of subtracting two zeros is zero. fn sub_zeros() { let a = FeltBigInt::::new(0); @@ -947,7 +929,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Tests that the result of subtracting two zeros with assignment is zero. fn sub_assign_zeros() { let mut a = FeltBigInt::::new(0); @@ -959,7 +940,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sub_usize_felt() { let a = FeltBigInt::::new(4u32); let b = FeltBigInt::new(2u32); @@ -969,7 +949,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Tests that the negative of zero is zero fn negate_zero() { let a = FeltBigInt::::new(0); diff --git a/felt/src/lib.rs b/felt/src/lib.rs index a94818c89b..8c13790d4a 100644 --- a/felt/src/lib.rs +++ b/felt/src/lib.rs @@ -1,9 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#[allow(unused_imports)] -#[macro_use] -#[cfg(all(not(feature = "std"), feature = "alloc"))] -pub extern crate alloc; - mod bigint_felt; use bigint_felt::{FeltBigInt, FIELD_HIGH, FIELD_LOW}; @@ -11,8 +5,7 @@ use num_bigint::{BigInt, BigUint, U64Digits}; use num_integer::Integer; use num_traits::{Bounded, FromPrimitive, Num, One, Pow, Signed, ToPrimitive, Zero}; use serde::{Deserialize, Serialize}; - -use core::{ +use std::{ convert::Into, fmt, iter::Sum, @@ -22,9 +15,6 @@ use core::{ }, }; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use alloc::{string::String, vec::Vec}; - pub const PRIME_STR: &str = "0x800000000000011000000000000000000000000000000000000000000000001"; // in decimal, this is equal to 3618502788666131213697322783095070105623107215331596699973092056135872020481 pub(crate) trait FeltOps { @@ -38,17 +28,14 @@ pub(crate) trait FeltOps { fn iter_u64_digits(&self) -> U64Digits; - #[cfg(any(feature = "std", feature = "alloc"))] fn to_signed_bytes_le(&self) -> Vec; - #[cfg(any(feature = "std", feature = "alloc"))] fn to_bytes_be(&self) -> Vec; fn parse_bytes(buf: &[u8], radix: u32) -> Option>; fn from_bytes_be(bytes: &[u8]) -> Self; - #[cfg(any(feature = "std", feature = "alloc"))] fn to_str_radix(&self, radix: u32) -> String; #[deprecated] @@ -151,11 +138,9 @@ impl Felt { pub fn iter_u64_digits(&self) -> U64Digits { self.value.iter_u64_digits() } - #[cfg(any(feature = "std", feature = "alloc"))] pub fn to_signed_bytes_le(&self) -> Vec { self.value.to_signed_bytes_le() } - #[cfg(any(feature = "std", feature = "alloc"))] pub fn to_bytes_be(&self) -> Vec { self.value.to_bytes_be() } @@ -169,7 +154,6 @@ impl Felt { value: FeltBigInt::from_bytes_be(bytes), } } - #[cfg(any(feature = "std", feature = "alloc"))] pub fn to_str_radix(&self, radix: u32) -> String { self.value.to_str_radix(radix) } @@ -840,7 +824,6 @@ assert_felt_impl!(Felt); #[cfg(test)] mod test { use super::*; - use core::cmp; use proptest::prelude::*; const FELT_PATTERN: &str = "(0|[1-9][0-9]*)"; @@ -849,7 +832,6 @@ mod test { proptest! { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 felt values that are randomly generated each time tests are run, that a new felt doesn't fall outside the range [0, p]. // In this and some of the following tests, The value of {x} can be either [0] or a very large number, in order to try to overflow the value of {p} and thus ensure the modular arithmetic is working correctly. fn new_in_range(ref x in "(0|[1-9][0-9]*)") { @@ -859,7 +841,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 felt values that are randomly generated each time tests are run, that a felt created using Felt::from_bytes_be doesn't fall outside the range [0, p]. // In this and some of the following tests, The value of {x} can be either [0] or a very large number, in order to try to overflow the value of {p} and thus ensure the modular arithmetic is working correctly. fn from_bytes_be_in_range(ref x in "(0|[1-9][0-9]*)") { @@ -870,7 +851,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 felt values that are randomly generated each time tests are run, that the negative of a felt doesn't fall outside the range [0, p]. fn neg_in_range(ref x in "(0|[1-9][0-9]*)") { let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -888,7 +868,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 {x} and {y} values that are randomly generated each time tests are run, that a subtraction between two felts {x} and {y} and doesn't fall outside the range [0, p]. The values of {x} and {y} can be either [0] or a very large number. fn sub_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") { let x = &Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -902,7 +881,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 {x} and {y} values that are randomly generated each time tests are run, that a subtraction with assignment between two felts {x} and {y} and doesn't fall outside the range [0, p]. The values of {x} and {y} can be either [0] or a very large number. fn sub_assign_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") { let mut x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -921,7 +899,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 {x} and {y} values that are randomly generated each time tests are run, that a multiplication between two felts {x} and {y} and doesn't fall outside the range [0, p]. The values of {x} and {y} can be either [0] or a very large number. fn mul_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") { let x = &Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -935,7 +912,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 pairs of {x} and {y} values that are randomly generated each time tests are run, that a multiplication with assignment between two felts {x} and {y} and doesn't fall outside the range [0, p]. The values of {x} and {y} can be either [0] or a very large number. fn mul_assign_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") { let mut x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -949,7 +925,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 pairs of {x} and {y} values that are randomly generated each time tests are run, that the result of the division of {x} by {y} is the inverse multiplicative of {x} --that is, multiplying the result by {y} returns the original number {x}. The values of {x} and {y} can be either [0] or a very large number. fn div_is_mul_inv(ref x in "(0|[1-9][0-9]*)", ref y in "[1-9][0-9]*") { let x = &Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -965,7 +940,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 {value}s that are randomly generated each time tests are run, that performing a bit shift to the left by {shift_amount} of bits (between 0 and 999) returns a result that is inside of the range [0, p]. fn shift_left_in_range(ref value in "(0|[1-9][0-9]*)", ref shift_amount in "[0-9]{1,3}"){ let value = Felt::parse_bytes(value.as_bytes(), 10).unwrap(); @@ -981,7 +955,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 {value}s that are randomly generated each time tests are run, that performing a bit shift to the right by {shift_amount} of bits (between 0 and 999) returns a result that is inside of the range [0, p]. fn shift_right_in_range(ref value in "(0|[1-9][0-9]*)", ref shift_amount in "[0-9]{1,3}"){ let value = Felt::parse_bytes(value.as_bytes(), 10).unwrap(); @@ -993,7 +966,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 {value}s that are randomly generated each time tests are run, that performing a bit shift to the right by {shift_amount} of bits (between 0 and 999), with assignment, returns a result that is inside of the range [0, p]. // "With assignment" means that the result of the operation is autommatically assigned to the variable value, replacing its previous content. fn shift_right_assign_in_range(ref value in "(0|[1-9][0-9]*)", ref shift_amount in "[0-9]{1,3}"){ @@ -1006,7 +978,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property based test that ensures, for 100 pairs of values {x} and {y} generated at random each time tests are run, that performing a BitAnd operation between them returns a result that is inside of the range [0, p]. fn bitand_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)"){ let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -1019,7 +990,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property based test that ensures, for 100 pairs of values {x} and {y} generated at random each time tests are run, that performing a BitOr operation between them returns a result that is inside of the range [0, p]. fn bitor_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)"){ let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -1031,7 +1001,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property based test that ensures, for 100 pairs of values {x} and {y} generated at random each time tests are run, that performing a BitXor operation between them returns a result that is inside of the range [0, p]. fn bitxor_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)"){ let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -1043,7 +1012,6 @@ mod test { #[test] #[allow(deprecated)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property-based test that ensures, for 100 values {x} that are randomly generated each time tests are run, that raising {x} to the {y}th power returns a result that is inside of the range [0, p]. fn pow_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "[0-9]{1,2}"){ let base = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -1061,7 +1029,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property based test that ensures, for 100 pairs of values {x} and {y} generated at random each time tests are run, that performing a Sum operation between them returns a result that is inside of the range [0, p]. fn sum_in_range(ref x in "[1-9][0-9]*", ref y in "[0-9][0-9]*"){ let x = &Felt::parse_bytes(x.as_bytes(), 10).unwrap(); @@ -1074,7 +1041,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property test to check that the remainder of a division between 100 pairs of values {x} and {y},generated at random each time tests are run, falls in the range [0, p]. x and y can either take the value of 0 or a large integer. // In Cairo, the result of x / y is defined to always satisfy the equation (x / y) * y == x, so the remainder is 0 most of the time. fn rem_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") { @@ -1093,17 +1059,15 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property based test that ensures, for 100 Felts {x} generated at random each time tests are run, that converting them into the u64 type returns a result that is inside of the range [0, p]. fn from_u64_and_to_u64_primitive(x in any::()) { let x_felt:Felt = Felt::from_u64(x).unwrap(); let x_u64:u64 = Felt::to_u64(&x_felt).unwrap(); - prop_assert_eq!(x, x_u64); + prop_assert_eq!(x, x_u64); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn from_i64_and_to_i64_primitive(x in any::()) { let x: i64 = x as i64; let x_felt:Felt = Felt::from_i64(x).unwrap(); @@ -1118,17 +1082,16 @@ mod test { let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); let y = Felt::parse_bytes(y.as_bytes(), 10).unwrap(); let lcm = x.lcm(&y); - prop_assert!(lcm == cmp::max(x, y)); + prop_assert!(lcm == std::cmp::max(x, y)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Property test to check that is_multiple_of(x, y) works. Since we're operating in a prime field, is_multiple_of // will always be true fn is_multiple_of_doesnt_panic(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") { - let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); - let y = Felt::parse_bytes(y.as_bytes(), 10).unwrap(); - prop_assert!(x.is_multiple_of(&y)); + let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); + let y = Felt::parse_bytes(y.as_bytes(), 10).unwrap(); + prop_assert!(x.is_multiple_of(&y)); } #[test] @@ -1330,7 +1293,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Checks that the result of adding two zeroes is zero fn sum_zeros_in_range() { let x = Felt::new(0); @@ -1340,7 +1302,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Checks that the result of multiplying two zeroes is zero fn mul_zeros_in_range() { let x = Felt::new(0); @@ -1350,7 +1311,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Checks that the result of performing a bit and operation between zeroes is zero fn bit_and_zeros_in_range() { let x = Felt::new(0); @@ -1360,7 +1320,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Checks that the result of perfforming a bit or operation between zeroes is zero fn bit_or_zeros_in_range() { let x = Felt::new(0); @@ -1370,7 +1329,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Checks that the result of perfforming a bit xor operation between zeroes is zero fn bit_xor_zeros_in_range() { let x = Felt::new(0); @@ -1380,7 +1338,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Tests that the maximum value a Felt can take is equal to (prime - 1) fn upper_bound() { let prime = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); @@ -1390,7 +1347,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] // Tests that the minimum value a Felt can take is equal to zero. fn lower_bound() { let zero = BigUint::zero(); diff --git a/src/cairo_run.rs b/src/cairo_run.rs index 7c6784cdc0..cb50860a0e 100644 --- a/src/cairo_run.rs +++ b/src/cairo_run.rs @@ -2,24 +2,26 @@ use crate::{ hint_processor::hint_processor_definition::HintProcessor, types::program::Program, vm::{ - errors::{cairo_run_errors::CairoRunError, vm_exception::VmException}, + errors::{ + cairo_run_errors::CairoRunError, runner_errors::RunnerError, vm_exception::VmException, + }, runners::cairo_runner::CairoRunner, security::verify_secure_runner, + trace::trace_entry::RelocatedTraceEntry, vm_core::VirtualMachine, }, }; - -use bincode::enc::write::Writer; use felt::Felt; - -#[cfg(feature = "std")] -use thiserror::Error; -#[cfg(not(feature = "std"))] -use thiserror_no_std::Error; +use std::{ + fs::File, + io::{self, BufWriter, Error, ErrorKind, Write}, + path::Path, +}; pub struct CairoRunConfig<'a> { pub entrypoint: &'a str, pub trace_enabled: bool, + pub print_output: bool, pub layout: &'a str, pub proof_mode: bool, pub secure_run: Option, @@ -30,6 +32,7 @@ impl<'a> Default for CairoRunConfig<'a> { CairoRunConfig { entrypoint: "main", trace_enabled: false, + print_output: false, layout: "plain", proof_mode: false, secure_run: None, @@ -38,11 +41,14 @@ impl<'a> Default for CairoRunConfig<'a> { } pub fn cairo_run( - program_content: &[u8], + path: &Path, cairo_run_config: &CairoRunConfig, hint_executor: &mut dyn HintProcessor, -) -> Result<(CairoRunner, VirtualMachine), CairoRunError> { - let program = Program::from_bytes(program_content, Some(cairo_run_config.entrypoint))?; +) -> Result { + let program = match Program::from_file(path, Some(cairo_run_config.entrypoint)) { + Ok(program) => program, + Err(error) => return Err(CairoRunError::Program(error)), + }; let secure_run = cairo_run_config .secure_run @@ -71,81 +77,93 @@ pub fn cairo_run( } cairo_runner.relocate(&mut vm)?; - Ok((cairo_runner, vm)) + if cairo_run_config.print_output { + write_output(&mut cairo_runner, &mut vm)?; + } + + Ok(cairo_runner) } -#[derive(Debug, Error)] -#[error("Failed to encode trace at position {0}, serialize error: {1}")] -pub struct EncodeTraceError(usize, bincode::error::EncodeError); - -/// Writes the trace binary representation. -/// -/// Bincode encodes to little endian by default and each trace entry is composed of -/// 3 usize values that are padded to always reach 64 bit size. -pub fn write_encoded_trace( - relocated_trace: &[crate::vm::trace::trace_entry::RelocatedTraceEntry], - dest: &mut impl Writer, -) -> Result<(), EncodeTraceError> { +pub fn write_output( + cairo_runner: &mut CairoRunner, + vm: &mut VirtualMachine, +) -> Result<(), CairoRunError> { + let mut buffer = BufWriter::new(io::stdout()); + writeln!(&mut buffer, "Program Output: ") + .map_err(|_| CairoRunError::Runner(RunnerError::WriteFail))?; + cairo_runner.write_output(vm, &mut buffer)?; + buffer + .flush() + .map_err(|_| CairoRunError::Runner(RunnerError::WriteFail)) +} + +/// Writes a trace as a binary file. Bincode encodes to little endian by default and each trace +/// entry is composed of 3 usize values that are padded to always reach 64 bit size. +pub fn write_binary_trace( + relocated_trace: &[RelocatedTraceEntry], + trace_file: &Path, +) -> io::Result<()> { + let file = File::create(trace_file)?; + let mut buffer = BufWriter::new(file); + for (i, entry) in relocated_trace.iter().enumerate() { - bincode::serde::encode_into_writer(entry, &mut *dest, bincode::config::legacy()) - .map_err(|e| EncodeTraceError(i, e))?; + bincode::serialize_into(&mut buffer, entry).map_err(|e| { + Error::new( + ErrorKind::Other, + format!("Failed to dump trace at position {i}, serialize error: {e}"), + ) + })?; } - Ok(()) + buffer.flush() } -/// Writes a binary representation of the relocated memory. -/// -/// The memory pairs (address, value) are encoded and concatenated: -/// * address -> 8-byte encoded -/// * value -> 32-byte encoded -pub fn write_encoded_memory( +/* + Writes a binary memory file with the relocated memory as input. + The memory pairs (address, value) are encoded and concatenated in the file + given by the path `memory_file`. + + * address -> 8-byte encoded + * value -> 32-byte encoded +*/ +pub fn write_binary_memory( relocated_memory: &[Option], - dest: &mut impl Writer, -) -> Result<(), EncodeTraceError> { + memory_file: &Path, +) -> io::Result<()> { + let file = File::create(memory_file)?; + let mut buffer = BufWriter::new(file); + // initialize bytes vector that will be dumped to file + let mut memory_bytes: Vec = Vec::new(); for (i, memory_cell) in relocated_memory.iter().enumerate() { match memory_cell { None => continue, Some(unwrapped_memory_cell) => { - encode_relocated_memory(dest, i, unwrapped_memory_cell) - .map_err(|e| EncodeTraceError(i, e))?; + encode_relocated_memory(&mut memory_bytes, i, unwrapped_memory_cell); } } } - Ok(()) + buffer.write_all(&memory_bytes)?; + buffer.flush() } // encodes a given memory cell. -fn encode_relocated_memory( - dest: &mut impl Writer, - addr: usize, - memory_cell: &Felt, -) -> Result<(), bincode::error::EncodeError> { - let config = bincode::config::standard() - .with_little_endian() - .with_fixed_int_encoding() - .skip_fixed_array_length(); - +fn encode_relocated_memory(memory_bytes: &mut Vec, addr: usize, memory_cell: &Felt) { // append memory address to bytes vector using a 8 bytes representation - let addr_bytes: [u8; 8] = (addr as u64).to_le_bytes(); - bincode::encode_into_writer(addr_bytes, &mut *dest, config)?; + let mut addr_bytes = (addr as u64).to_le_bytes().to_vec(); + memory_bytes.append(&mut addr_bytes); // append memory value at address using a 32 bytes representation - let value_bytes = memory_cell.to_signed_bytes_le(); - let mut x = [0; 32]; - x[..value_bytes.len()].copy_from_slice(&value_bytes); - bincode::encode_into_writer(x, &mut *dest, config)?; - - Ok(()) + let mut value_bytes = memory_cell.to_signed_bytes_le(); + value_bytes.resize(32, 0); + memory_bytes.append(&mut value_bytes); } #[cfg(test)] mod tests { use super::*; - use crate::stdlib::prelude::*; use crate::{ hint_processor::{ builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, @@ -153,17 +171,15 @@ mod tests { }, utils::test_utils::*, }; - use bincode::enc::write::SliceWriter; - use felt::Felt; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::io::Read; fn run_test_program( - program_content: &[u8], + program_path: &Path, hint_processor: &mut dyn HintProcessor, ) -> Result<(CairoRunner, VirtualMachine), CairoRunError> { - let program = Program::from_bytes(program_content, Some("main")).unwrap(); + let program = + Program::from_file(program_path, Some("main")).map_err(CairoRunError::Program)?; + let mut cairo_runner = cairo_runner!(program); let mut vm = vm!(true); let end = cairo_runner @@ -178,13 +194,9 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_custom_entry_point() { - let program = Program::from_bytes( - include_bytes!("../cairo_programs/not_main.json"), - Some("not_main"), - ) - .unwrap(); + let program_path = Path::new("cairo_programs/not_main.json"); + let program = Program::from_file(program_path, Some("not_main")).unwrap(); let mut vm = vm!(); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program); @@ -199,65 +211,72 @@ mod tests { assert_eq!(cairo_runner.relocated_memory[2], Some(Felt::new(123))); } + fn compare_files(file_path_1: &Path, file_path_2: &Path) -> io::Result<()> { + let mut file_1 = File::open(file_path_1)?; + let mut file_2 = File::open(file_path_2)?; + + let mut buffer_1 = Vec::new(); + let mut buffer_2 = Vec::new(); + + file_1.read_to_end(&mut buffer_1)?; + file_2.read_to_end(&mut buffer_2)?; + + assert_eq!(&buffer_1.len(), &buffer_2.len()); + + for (buf_byte_1, buf_byte_2) in buffer_1.iter().zip(buffer_2.iter()) { + assert_eq!(buf_byte_1, buf_byte_2); + } + Ok(()) + } + #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_with_no_data_program() { // a compiled program with no `data` key. // it should fail when the program is loaded. let mut hint_processor = BuiltinHintProcessor::new_empty(); - let no_data_program_path = - include_bytes!("../cairo_programs/manually_compiled/no_data_program.json"); + let no_data_program_path = Path::new("cairo_programs/no_data_program.json"); let cairo_run_config = CairoRunConfig::default(); - assert!(cairo_run(no_data_program_path, &cairo_run_config, &mut hint_processor,).is_err()); + assert!(cairo_run(no_data_program_path, &cairo_run_config, &mut hint_processor).is_err()); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_with_no_main_program() { // a compiled program with no main scope // it should fail when trying to run initialize_main_entrypoint. let mut hint_processor = BuiltinHintProcessor::new_empty(); - let no_main_program = - include_bytes!("../cairo_programs/manually_compiled/no_main_program.json"); + let no_main_program_path = Path::new("cairo_programs/no_main_program.json"); let cairo_run_config = CairoRunConfig::default(); - assert!(cairo_run(no_main_program, &cairo_run_config, &mut hint_processor,).is_err()); + assert!(cairo_run(no_main_program_path, &cairo_run_config, &mut hint_processor).is_err()); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_with_invalid_memory() { // the program invalid_memory.json has an invalid memory cell and errors when trying to // decode the instruction. let mut hint_processor = BuiltinHintProcessor::new_empty(); - let invalid_memory = - include_bytes!("../cairo_programs/manually_compiled/invalid_memory.json"); + let invalid_memory = Path::new("cairo_programs/invalid_memory.json"); let cairo_run_config = CairoRunConfig::default(); - assert!(cairo_run(invalid_memory, &cairo_run_config, &mut hint_processor,).is_err()); + assert!(cairo_run(invalid_memory, &cairo_run_config, &mut hint_processor).is_err()); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn write_output_program() { - let program_content = include_bytes!("../cairo_programs/bitwise_output.json"); + let program_path = Path::new("cairo_programs/bitwise_output.json"); let mut hint_processor = BuiltinHintProcessor::new_empty(); - let (_, mut vm) = run_test_program(program_content, &mut hint_processor) + let (mut cairo_runner, mut vm) = run_test_program(program_path, &mut hint_processor) .expect("Couldn't initialize cairo runner"); - - let mut output_buffer = String::new(); - vm.write_output(&mut output_buffer).unwrap(); - assert_eq!(&output_buffer, "0\n"); + assert!(write_output(&mut cairo_runner, &mut vm).is_ok()); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn write_binary_trace_file() { - let program_content = include_bytes!("../cairo_programs/struct.json"); - let expected_encoded_trace = - include_bytes!("../cairo_programs/trace_memory/cairo_trace_struct"); + let program_path = Path::new("cairo_programs/struct.json"); + let expected_trace_path = Path::new("cairo_programs/trace_memory/cairo_trace_struct"); + let cairo_rs_trace_path = Path::new("cairo_programs/trace_memory/struct_cairo_rs.trace"); // run test program until the end let mut hint_processor = BuiltinHintProcessor::new_empty(); - let cairo_runner_result = run_test_program(program_content, &mut hint_processor); + let cairo_runner_result = run_test_program(program_path, &mut hint_processor); let (mut cairo_runner, mut vm) = cairo_runner_result.unwrap(); // relocate memory so we can dump it to file @@ -265,49 +284,40 @@ mod tests { assert!(vm.trace.is_some()); assert!(cairo_runner.relocated_trace.is_some()); - let trace_entries = cairo_runner.relocated_trace.unwrap(); - let mut buffer = [0; 24]; - let mut buff_writer = SliceWriter::new(&mut buffer); // write cairo_rs vm trace file - write_encoded_trace(&trace_entries, &mut buff_writer).unwrap(); + assert!( + write_binary_trace(&cairo_runner.relocated_trace.unwrap(), cairo_rs_trace_path).is_ok() + ); // compare that the original cairo vm trace file and cairo_rs vm trace files are equal - assert_eq!(buffer, *expected_encoded_trace); + assert!(compare_files(cairo_rs_trace_path, expected_trace_path).is_ok()); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn write_binary_memory_file() { - let program_content = include_bytes!("../cairo_programs/struct.json"); - let expected_encoded_memory = - include_bytes!("../cairo_programs/trace_memory/cairo_memory_struct"); + let program_path = Path::new("cairo_programs/struct.json"); + let expected_memory_path = Path::new("cairo_programs/trace_memory/cairo_memory_struct"); + let cairo_rs_memory_path = Path::new("cairo_programs/trace_memory/struct_cairo_rs.memory"); // run test program until the end let mut hint_processor = BuiltinHintProcessor::new_empty(); - let cairo_runner_result = run_test_program(program_content, &mut hint_processor); + let cairo_runner_result = run_test_program(program_path, &mut hint_processor); let (mut cairo_runner, mut vm) = cairo_runner_result.unwrap(); // relocate memory so we can dump it to file assert!(cairo_runner.relocate(&mut vm).is_ok()); - let mut buffer = [0; 120]; - let mut buff_writer = SliceWriter::new(&mut buffer); // write cairo_rs vm memory file - write_encoded_memory(&cairo_runner.relocated_memory, &mut buff_writer).unwrap(); + assert!(write_binary_memory(&cairo_runner.relocated_memory, cairo_rs_memory_path).is_ok()); // compare that the original cairo vm memory file and cairo_rs vm memory files are equal - assert_eq!(*expected_encoded_memory, buffer); + assert!(compare_files(cairo_rs_memory_path, expected_memory_path).is_ok()); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_with_no_trace() { - let program = Program::from_bytes( - include_bytes!("../cairo_programs/struct.json"), - Some("main"), - ) - .unwrap(); - + let program_path = Path::new("cairo_programs/struct.json"); + let program = Program::from_file(program_path, Some("main")).unwrap(); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program); let mut vm = vm!(); diff --git a/src/hint_processor/builtin_hint_processor/blake2s_hash.rs b/src/hint_processor/builtin_hint_processor/blake2s_hash.rs index 53515fd969..808d50f5c8 100644 --- a/src/hint_processor/builtin_hint_processor/blake2s_hash.rs +++ b/src/hint_processor/builtin_hint_processor/blake2s_hash.rs @@ -1,4 +1,4 @@ -use crate::stdlib::{ops::Shl, prelude::*}; +use std::ops::Shl; pub const IV: [u32; 8] = [ 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19, @@ -131,11 +131,7 @@ pub fn blake2s_compress( mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_compress_test_a() { let h: [u32; 8] = [ 1795745351, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, @@ -155,7 +151,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_compress_test_b() { let h: [u32; 8] = [ 1795745351, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, @@ -175,7 +170,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_compress_test_c() { //Hashing "Hello World" let h: [u32; 8] = [ @@ -198,7 +192,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_compress_test_d() { let h: [u32; 8] = [ 1795745351, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, @@ -221,7 +214,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_compress_test_e() { let h: [u32; 8] = [ 1795745351, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, @@ -244,7 +236,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_compress_test_f() { let h: [u32; 8] = [ 1795745351, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, @@ -267,7 +258,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_compress_test_g() { let h: [u32; 8] = [ 1795745351, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, diff --git a/src/hint_processor/builtin_hint_processor/blake2s_utils.rs b/src/hint_processor/builtin_hint_processor/blake2s_utils.rs index 62a6528e85..7723b41d05 100644 --- a/src/hint_processor/builtin_hint_processor/blake2s_utils.rs +++ b/src/hint_processor/builtin_hint_processor/blake2s_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{borrow::Cow, collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::{ @@ -15,6 +13,7 @@ use crate::{ }; use felt::Felt; use num_traits::ToPrimitive; +use std::{borrow::Cow, collections::HashMap}; fn get_fixed_size_u32_array( h_range: &Vec>, @@ -222,12 +221,9 @@ mod tests { vm::{errors::memory_errors::MemoryError, vm_memory::memory::Memory}, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_blake2s_output_offset_zero() { let hint_code = "from starkware.cairo.common.cairo_blake2s.blake2s_utils import compute_blake2s_func\ncompute_blake2s_func(segments=segments, output_ptr=ids.output)"; //Create vm @@ -249,7 +245,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_blake2s_output_empty_segment() { let hint_code = "from starkware.cairo.common.cairo_blake2s.blake2s_utils import compute_blake2s_func\ncompute_blake2s_func(segments=segments, output_ptr=ids.output)"; //Create vm @@ -271,7 +266,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_blake2s_output_not_relocatable() { let hint_code = "from starkware.cairo.common.cairo_blake2s.blake2s_utils import compute_blake2s_func\ncompute_blake2s_func(segments=segments, output_ptr=ids.output)"; //Create vm @@ -291,7 +285,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_blake2s_output_input_bigger_than_u32() { let hint_code = "from starkware.cairo.common.cairo_blake2s.blake2s_utils import compute_blake2s_func\ncompute_blake2s_func(segments=segments, output_ptr=ids.output)"; //Create vm @@ -320,7 +313,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_blake2s_output_input_relocatable() { let hint_code = "from starkware.cairo.common.cairo_blake2s.blake2s_utils import compute_blake2s_func\ncompute_blake2s_func(segments=segments, output_ptr=ids.output)"; //Create vm @@ -341,7 +333,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_blake2s_valid() { let hint_code = "# Add dummy pairs of input and output.\nfrom starkware.cairo.common.cairo_blake2s.blake2s_utils import IV, blake2s_compress\n\n_n_packed_instances = int(ids.N_PACKED_INSTANCES)\nassert 0 <= _n_packed_instances < 20\n_blake2s_input_chunk_size_felts = int(ids.INPUT_BLOCK_FELTS)\nassert 0 <= _blake2s_input_chunk_size_felts < 100\n\nmessage = [0] * _blake2s_input_chunk_size_felts\nmodified_iv = [IV[0] ^ 0x01010020] + IV[1:]\noutput = blake2s_compress(\n message=message,\n h=modified_iv,\n t0=0,\n t1=0,\n f0=0xffffffff,\n f1=0,\n)\npadding = (modified_iv + message + [0, 0xffffffff] + output) * (_n_packed_instances - 1)\nsegments.write_arg(ids.blake2s_ptr_end, padding)"; //Create vm @@ -388,7 +379,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_blake2s_invalid_segment_taken() { let hint_code = "# Add dummy pairs of input and output.\nfrom starkware.cairo.common.cairo_blake2s.blake2s_utils import IV, blake2s_compress\n\n_n_packed_instances = int(ids.N_PACKED_INSTANCES)\nassert 0 <= _n_packed_instances < 20\n_blake2s_input_chunk_size_felts = int(ids.INPUT_BLOCK_FELTS)\nassert 0 <= _blake2s_input_chunk_size_felts < 100\n\nmessage = [0] * _blake2s_input_chunk_size_felts\nmodified_iv = [IV[0] ^ 0x01010020] + IV[1:]\noutput = blake2s_compress(\n message=message,\n h=modified_iv,\n t0=0,\n t1=0,\n f0=0xffffffff,\n f1=0,\n)\npadding = (modified_iv + message + [0, 0xffffffff] + output) * (_n_packed_instances - 1)\nsegments.write_arg(ids.blake2s_ptr_end, padding)"; //Create vm @@ -414,7 +404,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_blake2s_invalid_no_ids() { let hint_code = "# Add dummy pairs of input and output.\nfrom starkware.cairo.common.cairo_blake2s.blake2s_utils import IV, blake2s_compress\n\n_n_packed_instances = int(ids.N_PACKED_INSTANCES)\nassert 0 <= _n_packed_instances < 20\n_blake2s_input_chunk_size_felts = int(ids.INPUT_BLOCK_FELTS)\nassert 0 <= _blake2s_input_chunk_size_felts < 100\n\nmessage = [0] * _blake2s_input_chunk_size_felts\nmodified_iv = [IV[0] ^ 0x01010020] + IV[1:]\noutput = blake2s_compress(\n message=message,\n h=modified_iv,\n t0=0,\n t1=0,\n f0=0xffffffff,\n f1=0,\n)\npadding = (modified_iv + message + [0, 0xffffffff] + output) * (_n_packed_instances - 1)\nsegments.write_arg(ids.blake2s_ptr_end, padding)"; //Create vm @@ -429,7 +418,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_add_uint256_valid_zero() { let hint_code = "B = 32\nMASK = 2 ** 32 - 1\nsegments.write_arg(ids.data, [(ids.low >> (B * i)) & MASK for i in range(4)])\nsegments.write_arg(ids.data + 4, [(ids.high >> (B * i)) & MASK for i in range(4)]"; //Create vm @@ -462,7 +450,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_add_uint256_valid_non_zero() { let hint_code = "B = 32\nMASK = 2 ** 32 - 1\nsegments.write_arg(ids.data, [(ids.low >> (B * i)) & MASK for i in range(4)])\nsegments.write_arg(ids.data + 4, [(ids.high >> (B * i)) & MASK for i in range(4)]"; //Create vm @@ -495,7 +482,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_add_uint256_bigend_valid_zero() { let hint_code = "B = 32\nMASK = 2 ** 32 - 1\nsegments.write_arg(ids.data, [(ids.high >> (B * (3 - i))) & MASK for i in range(4)])\nsegments.write_arg(ids.data + 4, [(ids.low >> (B * (3 - i))) & MASK for i in range(4)])"; //Create vm @@ -528,7 +514,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_add_uint256_bigend_valid_non_zero() { let hint_code = "B = 32\nMASK = 2 ** 32 - 1\nsegments.write_arg(ids.data, [(ids.high >> (B * (3 - i))) & MASK for i in range(4)])\nsegments.write_arg(ids.data + 4, [(ids.low >> (B * (3 - i))) & MASK for i in range(4)])"; //Create vm diff --git a/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index 6f94342a24..db4dd67767 100644 --- a/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{any::Any, collections::HashMap, prelude::*, rc::Rc}; - use crate::{ hint_processor::{ builtin_hint_processor::{ @@ -62,6 +60,7 @@ use crate::{ vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; use felt::Felt; +use std::{any::Any, collections::HashMap, rc::Rc}; #[cfg(feature = "skip_next_instruction_hint")] use crate::hint_processor::builtin_hint_processor::skip_next_instruction::skip_next_instruction; @@ -448,7 +447,6 @@ impl HintProcessor for BuiltinHintProcessor { #[cfg(test)] mod tests { use super::*; - use crate::stdlib::any::Any; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ any_box, @@ -463,12 +461,9 @@ mod tests { }; use assert_matches::assert_matches; use num_traits::{One, Zero}; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_alloc_hint_empty_memory() { let hint_code = "memory[ap] = segments.add()"; let mut vm = vm!(); @@ -482,7 +477,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_alloc_hint_preset_memory() { let hint_code = "memory[ap] = segments.add()"; let mut vm = vm!(); @@ -498,7 +492,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_alloc_hint_ap_is_not_empty() { let hint_code = "memory[ap] = segments.add()"; let mut vm = vm!(); @@ -523,7 +516,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_unknown_hint() { let hint_code = "random_invalid_code"; let mut vm = vm!(); @@ -534,7 +526,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memcpy_enter_scope_valid() { let hint_code = "vm_enter_scope({'n': ids.len})"; let mut vm = vm!(); @@ -549,7 +540,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memcpy_enter_scope_invalid() { let hint_code = "vm_enter_scope({'n': ids.len})"; let mut vm = vm!(); @@ -570,7 +560,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memcpy_continue_copying_valid() { let hint_code = "n -= 1\nids.continue_copying = 1 if n > 0 else 0"; let mut vm = vm!(); @@ -588,7 +577,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memcpy_continue_copying_variable_not_in_scope_error() { let hint_code = "n -= 1\nids.continue_copying = 1 if n > 0 else 0"; let mut vm = vm!(); @@ -607,7 +595,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memcpy_continue_copying_insert_error() { let hint_code = "n -= 1\nids.continue_copying = 1 if n > 0 else 0"; let mut vm = vm!(); @@ -637,7 +624,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn exit_scope_valid() { let hint_code = "vm_exit_scope()"; let mut vm = vm!(); @@ -651,7 +637,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn exit_scope_invalid() { let hint_code = "vm_exit_scope()"; let mut vm = vm!(); @@ -667,7 +652,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_enter_scope() { let hint_code = "vm_enter_scope()"; //Create vm @@ -685,7 +669,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak_valid() { let hint_code = "from eth_hash.auto import keccak\n\ndata, length = ids.data, ids.length\n\nif '__keccak_max_size' in globals():\n assert length <= __keccak_max_size, \\\n f'unsafe_keccak() can only be used with length<={__keccak_max_size}. ' \\\n f'Got: length={length}.'\n\nkeccak_input = bytearray()\nfor word_i, byte_i in enumerate(range(0, length, 16)):\n word = memory[data + word_i]\n n_bytes = min(16, length - byte_i)\n assert 0 <= word < 2 ** (8 * n_bytes)\n keccak_input += word.to_bytes(n_bytes, 'big')\n\nhashed = keccak(keccak_input)\nids.high = int.from_bytes(hashed[:16], 'big')\nids.low = int.from_bytes(hashed[16:32], 'big')"; let mut vm = vm!(); @@ -708,7 +691,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak_max_size() { let hint_code = "from eth_hash.auto import keccak\n\ndata, length = ids.data, ids.length\n\nif '__keccak_max_size' in globals():\n assert length <= __keccak_max_size, \\\n f'unsafe_keccak() can only be used with length<={__keccak_max_size}. ' \\\n f'Got: length={length}.'\n\nkeccak_input = bytearray()\nfor word_i, byte_i in enumerate(range(0, length, 16)):\n word = memory[data + word_i]\n n_bytes = min(16, length - byte_i)\n assert 0 <= word < 2 ** (8 * n_bytes)\n keccak_input += word.to_bytes(n_bytes, 'big')\n\nhashed = keccak(keccak_input)\nids.high = int.from_bytes(hashed[:16], 'big')\nids.low = int.from_bytes(hashed[16:32], 'big')"; let mut vm = vm!(); @@ -733,7 +715,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak_invalid_input_length() { let hint_code = "from eth_hash.auto import keccak\n\ndata, length = ids.data, ids.length\n\nif '__keccak_max_size' in globals():\n assert length <= __keccak_max_size, \\\n f'unsafe_keccak() can only be used with length<={__keccak_max_size}. ' \\\n f'Got: length={length}.'\n\nkeccak_input = bytearray()\nfor word_i, byte_i in enumerate(range(0, length, 16)):\n word = memory[data + word_i]\n n_bytes = min(16, length - byte_i)\n assert 0 <= word < 2 ** (8 * n_bytes)\n keccak_input += word.to_bytes(n_bytes, 'big')\n\nhashed = keccak(keccak_input)\nids.high = int.from_bytes(hashed[:16], 'big')\nids.low = int.from_bytes(hashed[16:32], 'big')"; let mut vm = vm!(); @@ -755,7 +736,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak_invalid_word_size() { let hint_code = "from eth_hash.auto import keccak\n\ndata, length = ids.data, ids.length\n\nif '__keccak_max_size' in globals():\n assert length <= __keccak_max_size, \\\n f'unsafe_keccak() can only be used with length<={__keccak_max_size}. ' \\\n f'Got: length={length}.'\n\nkeccak_input = bytearray()\nfor word_i, byte_i in enumerate(range(0, length, 16)):\n word = memory[data + word_i]\n n_bytes = min(16, length - byte_i)\n assert 0 <= word < 2 ** (8 * n_bytes)\n keccak_input += word.to_bytes(n_bytes, 'big')\n\nhashed = keccak(keccak_input)\nids.high = int.from_bytes(hashed[:16], 'big')\nids.low = int.from_bytes(hashed[16:32], 'big')"; let mut vm = vm!(); @@ -781,7 +761,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak_finalize_valid() { let hint_code = "from eth_hash.auto import keccak\nkeccak_input = bytearray()\nn_elms = ids.keccak_state.end_ptr - ids.keccak_state.start_ptr\nfor word in memory.get_range(ids.keccak_state.start_ptr, n_elms):\n keccak_input += word.to_bytes(16, 'big')\nhashed = keccak(keccak_input)\nids.high = int.from_bytes(hashed[:16], 'big')\nids.low = int.from_bytes(hashed[16:32], 'big')"; let mut vm = vm!(); @@ -802,7 +781,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak_finalize_nones_in_range() { let hint_code = "from eth_hash.auto import keccak\nkeccak_input = bytearray()\nn_elms = ids.keccak_state.end_ptr - ids.keccak_state.start_ptr\nfor word in memory.get_range(ids.keccak_state.start_ptr, n_elms):\n keccak_input += word.to_bytes(16, 'big')\nhashed = keccak(keccak_input)\nids.high = int.from_bytes(hashed[:16], 'big')\nids.low = int.from_bytes(hashed[16:32], 'big')"; let mut vm = vm!(); @@ -825,7 +803,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak_finalize_expected_integer_at_range() { let hint_code = "from eth_hash.auto import keccak\nkeccak_input = bytearray()\nn_elms = ids.keccak_state.end_ptr - ids.keccak_state.start_ptr\nfor word in memory.get_range(ids.keccak_state.start_ptr, n_elms):\n keccak_input += word.to_bytes(16, 'big')\nhashed = keccak(keccak_input)\nids.high = int.from_bytes(hashed[:16], 'big')\nids.low = int.from_bytes(hashed[16:32], 'big')"; let mut vm = vm!(); @@ -857,7 +834,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_hint_add_same_hint_twice() { let mut hint_processor = BuiltinHintProcessor::new_empty(); let hint_func = Rc::new(HintFunc(Box::new(enter_scope))); diff --git a/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs b/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs index b9cd8c0142..a6a0646f7e 100644 --- a/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs +++ b/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs @@ -1,8 +1,3 @@ -use crate::stdlib::{ - borrow::{Cow, ToOwned}, - collections::HashMap, - prelude::*, -}; use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -19,6 +14,7 @@ use crate::{ }; use felt::Felt; use num_traits::{ToPrimitive, Zero}; +use std::{borrow::Cow, collections::HashMap}; // Constants in package "starkware.cairo.common.cairo_keccak.keccak". const BYTES_IN_WORD: &str = "starkware.cairo.common.cairo_keccak.keccak.BYTES_IN_WORD"; @@ -256,7 +252,6 @@ pub fn u64_array_to_mayberelocatable_vec(array: &[u64]) -> Vec #[cfg(test)] mod tests { use super::*; - use crate::stdlib::string::ToString; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ any_box, @@ -274,12 +269,9 @@ mod tests { }, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn keccak_write_args_valid_test() { let hint_code = "segments.write_arg(ids.inputs, [ids.low % 2 ** 64, ids.low // 2 ** 64])\nsegments.write_arg(ids.inputs + 2, [ids.high % 2 ** 64, ids.high // 2 ** 64])"; let mut vm = vm_with_range_check!(); @@ -297,7 +289,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn keccak_write_args_write_error() { let hint_code = "segments.write_arg(ids.inputs, [ids.low % 2 ** 64, ids.low // 2 ** 64])\nsegments.write_arg(ids.inputs + 2, [ids.high % 2 ** 64, ids.high // 2 ** 64])"; let mut vm = vm_with_range_check!(); @@ -311,7 +302,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compare_bytes_in_word_nondet_valid() { let hint_code = "memory[ap] = to_felt_or_relocatable(ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES)"; @@ -338,7 +328,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compare_keccak_full_rate_in_bytes_nondet_valid() { let hint_code = "memory[ap] = to_felt_or_relocatable(ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES)"; @@ -367,7 +356,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn block_permutation_valid_test() { let hint_code = "memory[ap] = to_felt_or_relocatable(ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES)"; diff --git a/src/hint_processor/builtin_hint_processor/dict_hint_utils.rs b/src/hint_processor/builtin_hint_processor/dict_hint_utils.rs index 3767fce2ff..ab222d1ecf 100644 --- a/src/hint_processor/builtin_hint_processor/dict_hint_utils.rs +++ b/src/hint_processor/builtin_hint_processor/dict_hint_utils.rs @@ -1,9 +1,8 @@ -use crate::stdlib::{any::Any, cell::RefCell, collections::HashMap, prelude::*, rc::Rc}; - use crate::{ types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable}, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; +use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc}; use crate::{ any_box, @@ -258,7 +257,6 @@ mod tests { use crate::hint_processor::builtin_hint_processor::dict_manager::Dictionary; use crate::hint_processor::builtin_hint_processor::hint_code; use crate::hint_processor::hint_processor_definition::HintProcessor; - use crate::stdlib::collections::HashMap; use crate::types::exec_scope::ExecutionScopes; use crate::vm::vm_memory::memory::Memory; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; @@ -270,12 +268,9 @@ mod tests { vm::{errors::memory_errors::MemoryError, vm_core::VirtualMachine}, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::collections::HashMap; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_new_with_initial_dict_empty() { let hint_code = "if '__dict_manager' not in globals():\n from starkware.cairo.common.dict import DictManager\n __dict_manager = DictManager()\n\nmemory[ap] = __dict_manager.new_dict(segments, initial_dict)\ndel initial_dict"; let mut vm = vm!(); @@ -307,7 +302,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_new_with_no_initial_dict() { let hint_code = "if '__dict_manager' not in globals():\n from starkware.cairo.common.dict import DictManager\n __dict_manager = DictManager()\n\nmemory[ap] = __dict_manager.new_dict(segments, initial_dict)\ndel initial_dict"; let mut vm = vm!(); @@ -319,7 +313,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_new_ap_is_taken() { let hint_code = "if '__dict_manager' not in globals():\n from starkware.cairo.common.dict import DictManager\n __dict_manager = DictManager()\n\nmemory[ap] = __dict_manager.new_dict(segments, initial_dict)\ndel initial_dict"; let mut vm = vm!(); @@ -344,7 +337,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_read_valid() { let hint_code = "dict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ndict_tracker.current_ptr += ids.DictAccess.SIZE\nids.value = dict_tracker.data[ids.key]"; let mut vm = vm!(); @@ -372,7 +364,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_read_invalid_key() { let hint_code = "dict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ndict_tracker.current_ptr += ids.DictAccess.SIZE\nids.value = dict_tracker.data[ids.key]"; let mut vm = vm!(); @@ -390,7 +381,6 @@ mod tests { ); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_read_no_tracker() { let hint_code = "dict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ndict_tracker.current_ptr += ids.DictAccess.SIZE\nids.value = dict_tracker.data[ids.key]"; let mut vm = vm!(); @@ -411,7 +401,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_default_dict_new_valid() { let hint_code = "if '__dict_manager' not in globals():\n from starkware.cairo.common.dict import DictManager\n __dict_manager = DictManager()\n\nmemory[ap] = __dict_manager.new_default_dict(segments, ids.default_value)"; let mut vm = vm!(); @@ -443,7 +432,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_default_dict_new_no_default_value() { let hint_code = "if '__dict_manager' not in globals():\n from starkware.cairo.common.dict import DictManager\n __dict_manager = DictManager()\n\nmemory[ap] = __dict_manager.new_default_dict(segments, ids.default_value)"; let mut vm = vm!(); @@ -457,7 +445,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_write_default_valid_empty_dict() { let hint_code = "dict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ndict_tracker.current_ptr += ids.DictAccess.SIZE\nids.dict_ptr.prev_value = dict_tracker.data[ids.key]\ndict_tracker.data[ids.key] = ids.new_value"; let mut vm = vm!(); @@ -485,7 +472,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_write_default_valid_overwrite_value() { let hint_code = "dict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ndict_tracker.current_ptr += ids.DictAccess.SIZE\nids.dict_ptr.prev_value = dict_tracker.data[ids.key]\ndict_tracker.data[ids.key] = ids.new_value"; let mut vm = vm!(); @@ -513,7 +499,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_write_simple_valid_overwrite_value() { let hint_code = "dict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ndict_tracker.current_ptr += ids.DictAccess.SIZE\nids.dict_ptr.prev_value = dict_tracker.data[ids.key]\ndict_tracker.data[ids.key] = ids.new_value"; let mut vm = vm!(); @@ -542,7 +527,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_write_simple_valid_cant_write_new_key() { let hint_code = "dict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ndict_tracker.current_ptr += ids.DictAccess.SIZE\nids.dict_ptr.prev_value = dict_tracker.data[ids.key]\ndict_tracker.data[ids.key] = ids.new_value"; let mut vm = vm!(); @@ -567,7 +551,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_simple_valid() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -592,7 +575,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_simple_valid_no_change() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -617,7 +599,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_simple_invalid_wrong_prev_key() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -647,7 +628,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_simple_invalid_wrong_key() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -671,7 +651,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_default_valid() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -696,7 +675,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_default_valid_no_change() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -721,7 +699,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_default_invalid_wrong_prev_key() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -751,7 +728,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_default_invalid_wrong_key() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -781,7 +757,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_update_default_valid_no_key_prev_value_equals_default() { let hint_code = "# Verify dict pointer and prev value.\ndict_tracker = __dict_manager.get_tracker(ids.dict_ptr)\ncurrent_value = dict_tracker.data[ids.key]\nassert current_value == ids.prev_value, \\\n f'Wrong previous value in dict. Got {ids.prev_value}, expected {current_value}.'\n\n# Update value.\ndict_tracker.data[ids.key] = ids.new_value\ndict_tracker.current_ptr += ids.DictAccess.SIZE"; let mut vm = vm!(); @@ -806,7 +781,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_squash_copy_dict_valid_empty_dict() { let hint_code = "# Prepare arguments for dict_new. In particular, the same dictionary values should be copied\n# to the new (squashed) dictionary.\nvm_enter_scope({\n # Make __dict_manager accessible.\n '__dict_manager': __dict_manager,\n # Create a copy of the dict, in case it changes in the future.\n 'initial_dict': dict(__dict_manager.get_dict(ids.dict_accesses_end)),\n})"; let mut vm = vm!(); @@ -835,7 +809,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_squash_copy_dict_valid_non_empty_dict() { let hint_code = "# Prepare arguments for dict_new. In particular, the same dictionary values should be copied\n# to the new (squashed) dictionary.\nvm_enter_scope({\n # Make __dict_manager accessible.\n '__dict_manager': __dict_manager,\n # Create a copy of the dict, in case it changes in the future.\n 'initial_dict': dict(__dict_manager.get_dict(ids.dict_accesses_end)),\n})"; let mut vm = vm!(); @@ -867,7 +840,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_squash_copy_dict_invalid_no_dict() { let hint_code = "# Prepare arguments for dict_new. In particular, the same dictionary values should be copied\n# to the new (squashed) dictionary.\nvm_enter_scope({\n # Make __dict_manager accessible.\n '__dict_manager': __dict_manager,\n # Create a copy of the dict, in case it changes in the future.\n 'initial_dict': dict(__dict_manager.get_dict(ids.dict_accesses_end)),\n})"; let mut vm = vm!(); @@ -888,7 +860,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_squash_update_ptr_no_tracker() { let hint_code = "# Update the DictTracker's current_ptr to point to the end of the squashed dict.\n__dict_manager.get_tracker(ids.squashed_dict_start).current_ptr = \\\n ids.squashed_dict_end.address_"; let mut vm = vm!(); @@ -909,7 +880,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_squash_update_ptr_valid() { let hint_code = "# Update the DictTracker's current_ptr to point to the end of the squashed dict.\n__dict_manager.get_tracker(ids.squashed_dict_start).current_ptr = \\\n ids.squashed_dict_end.address_"; let mut vm = vm!(); @@ -929,7 +899,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_squash_update_ptr_mismatched_dict_ptr() { let hint_code = "# Update the DictTracker's current_ptr to point to the end of the squashed dict.\n__dict_manager.get_tracker(ids.squashed_dict_start).current_ptr = \\\n ids.squashed_dict_end.address_"; let mut vm = vm!(); @@ -952,7 +921,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_dict_write_valid_relocatable_new_value() { let mut vm = vm!(); //Initialize fp diff --git a/src/hint_processor/builtin_hint_processor/dict_manager.rs b/src/hint_processor/builtin_hint_processor/dict_manager.rs index 28102ac887..5d1b1ff5a9 100644 --- a/src/hint_processor/builtin_hint_processor/dict_manager.rs +++ b/src/hint_processor/builtin_hint_processor/dict_manager.rs @@ -1,4 +1,4 @@ -use crate::stdlib::collections::HashMap; +use std::collections::HashMap; use crate::{ types::relocatable::{MaybeRelocatable, Relocatable}, @@ -202,18 +202,13 @@ mod tests { use crate::{relocatable, utils::test_utils::*, vm::vm_core::VirtualMachine}; use assert_matches::assert_matches; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn create_dict_manager() { let dict_manager = DictManager::new(); assert_eq!(dict_manager.trackers, HashMap::new()); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn create_dict_tracker_empty() { let dict_tracker = DictTracker::new_empty(relocatable!(1, 0)); assert_eq!( @@ -224,7 +219,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn create_dict_tracker_default() { let dict_tracker = DictTracker::new_default_dict(relocatable!(1, 0), &MaybeRelocatable::from(5), None); @@ -239,7 +233,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_manager_new_dict_empty() { let mut vm = vm!(); let mut dict_manager = DictManager::new(); @@ -254,7 +247,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_manager_new_dict_default() { let mut dict_manager = DictManager::new(); let mut vm = vm!(); @@ -273,7 +265,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_manager_new_dict_with_initial_dict() { let mut dict_manager = DictManager::new(); let mut vm = vm!(); @@ -293,7 +284,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_manager_new_default_dict_with_initial_dict() { let mut dict_manager = DictManager::new(); let mut initial_dict = HashMap::::new(); @@ -318,7 +308,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_manager_new_dict_empty_same_segment() { let mut dict_manager = DictManager::new(); dict_manager @@ -332,7 +321,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_manager_new_default_dict_empty_same_segment() { let mut dict_manager = DictManager::new(); dict_manager.trackers.insert( @@ -347,7 +335,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dictionary_get_insert_simple() { let mut dictionary = Dictionary::SimpleDictionary(HashMap::new()); dictionary.insert(&MaybeRelocatable::from(1), &MaybeRelocatable::from(2)); @@ -359,7 +346,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dictionary_get_insert_default() { let mut dictionary = Dictionary::DefaultDictionary { dict: HashMap::new(), diff --git a/src/hint_processor/builtin_hint_processor/find_element_hint.rs b/src/hint_processor/builtin_hint_processor/find_element_hint.rs index cd0b013b3a..1e559fa252 100644 --- a/src/hint_processor/builtin_hint_processor/find_element_hint.rs +++ b/src/hint_processor/builtin_hint_processor/find_element_hint.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -15,6 +13,7 @@ use crate::{ }; use felt::Felt; use num_traits::{Signed, ToPrimitive}; +use std::collections::HashMap; pub fn find_element( vm: &mut VirtualMachine, @@ -133,7 +132,6 @@ pub fn search_sorted_lower( #[cfg(test)] mod tests { use super::*; - use crate::stdlib::string::ToString; use crate::{ any_box, hint_processor::{ @@ -149,9 +147,7 @@ mod tests { }; use assert_matches::assert_matches; use num_traits::{One, Zero}; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; fn init_vm_ids_data( values_to_override: HashMap, @@ -221,15 +217,16 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn element_found_by_search() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::new()); - assert_matches!(run_hint!(vm, ids_data, hint_code::FIND_ELEMENT), Ok(())); + assert_matches!( + run_hint!(vm, ids_data, hint_code::FIND_ELEMENT.to_string()), + Ok(()) + ); check_memory![vm.segments.memory, ((1, 3), 1)]; } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn element_found_by_oracle() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::new()); let mut exec_scopes = scope![("find_element_index", Felt::one())]; @@ -241,7 +238,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn element_not_found_search() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "key".to_string(), @@ -254,7 +250,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn element_not_found_oracle() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::new()); let mut exec_scopes = scope![("find_element_index", Felt::new(2))]; @@ -265,7 +260,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_failed_ids_get_from_mem() { let mut vm = vm!(); vm.run_context.fp = 5; @@ -278,7 +272,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_not_int_elm_size() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "elm_size".to_string(), @@ -292,7 +285,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_zero_elm_size() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "elm_size".to_string(), @@ -305,7 +297,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_negative_elm_size() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "elm_size".to_string(), @@ -318,7 +309,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_not_int_n_elms() { let relocatable = MaybeRelocatable::from((1, 2)); let (mut vm, ids_data) = @@ -331,7 +321,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_negative_n_elms() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "n_elms".to_string(), @@ -344,14 +333,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_empty_scope() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::new()); assert_matches!(run_hint!(vm, ids_data, hint_code::FIND_ELEMENT), Ok(())); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_n_elms_gt_max_size() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::new()); let mut exec_scopes = scope![("find_element_max_size", Felt::one())]; @@ -362,7 +349,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_elm_key_not_int() { let relocatable = MaybeRelocatable::from((1, 4)); let (mut vm, ids_data) = @@ -374,7 +360,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::new()); assert_matches!( @@ -386,7 +371,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower_no_matches() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "key".to_string(), @@ -400,7 +384,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower_not_int_elm_size() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "elm_size".to_string(), @@ -414,7 +397,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower_zero_elm_size() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "elm_size".to_string(), @@ -427,7 +409,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower_negative_elm_size() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "elm_size".to_string(), @@ -440,7 +421,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower_not_int_n_elms() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "n_elms".to_string(), @@ -454,7 +434,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower_negative_n_elms() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::from([( "n_elms".to_string(), @@ -467,7 +446,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower_empty_scope() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::new()); assert_matches!( @@ -477,7 +455,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower_n_elms_gt_max_size() { let (mut vm, ids_data) = init_vm_ids_data(HashMap::new()); let mut exec_scopes = scope![("find_element_max_size", Felt::one())]; diff --git a/src/hint_processor/builtin_hint_processor/hint_utils.rs b/src/hint_processor/builtin_hint_processor/hint_utils.rs index 796ebe2911..eb31045b2a 100644 --- a/src/hint_processor/builtin_hint_processor/hint_utils.rs +++ b/src/hint_processor/builtin_hint_processor/hint_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{borrow::Cow, collections::HashMap, prelude::*}; - use felt::Felt; use crate::hint_processor::hint_processor_definition::HintReference; @@ -14,6 +12,8 @@ use crate::types::relocatable::MaybeRelocatable; use crate::types::relocatable::Relocatable; use crate::vm::errors::hint_errors::HintError; use crate::vm::vm_core::VirtualMachine; +use std::borrow::Cow; +use std::collections::HashMap; //Inserts value into the address of the given ids variable pub fn insert_value_from_var_name( @@ -122,7 +122,6 @@ pub fn get_reference_from_var_name<'a>( #[cfg(test)] mod tests { use super::*; - use crate::stdlib::string::ToString; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ hint_processor::hint_processor_definition::HintReference, @@ -135,11 +134,7 @@ mod tests { }; use assert_matches::assert_matches; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_ptr_from_var_name_immediate_value() { let mut vm = vm!(); vm.segments = segments![((1, 0), (0, 0))]; @@ -154,7 +149,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_maybe_relocatable_from_var_name_valid() { let mut vm = vm!(); vm.segments = segments![((1, 0), (0, 0))]; @@ -168,7 +162,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_maybe_relocatable_from_var_name_invalid() { let mut vm = vm!(); vm.segments.memory = Memory::new(); @@ -182,7 +175,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_ptr_from_var_name_valid() { let mut vm = vm!(); vm.segments = segments![((1, 0), (0, 0))]; @@ -196,7 +188,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_ptr_from_var_name_invalid() { let mut vm = vm!(); vm.segments = segments![((1, 0), 0)]; @@ -211,7 +202,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_relocatable_from_var_name_valid() { let mut vm = vm!(); vm.segments = segments![((1, 0), (0, 0))]; @@ -225,7 +215,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_relocatable_from_var_name_invalid() { let mut vm = vm!(); vm.segments.memory = Memory::new(); @@ -239,7 +228,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_integer_from_var_name_valid() { let mut vm = vm!(); vm.segments = segments![((1, 0), 1)]; @@ -253,7 +241,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_integer_from_var_name_invalid() { let mut vm = vm!(); vm.segments = segments![((1, 0), (0, 0))]; diff --git a/src/hint_processor/builtin_hint_processor/keccak_utils.rs b/src/hint_processor/builtin_hint_processor/keccak_utils.rs index af2c259fdf..38a5bb348c 100644 --- a/src/hint_processor/builtin_hint_processor/keccak_utils.rs +++ b/src/hint_processor/builtin_hint_processor/keccak_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{cmp, collections::HashMap, ops::Shl, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -14,6 +12,7 @@ use crate::{ use felt::Felt; use num_traits::{One, Signed, ToPrimitive}; use sha3::{Digest, Keccak256}; +use std::{cmp, collections::HashMap, ops::Shl}; /* Implements hint: %{ diff --git a/src/hint_processor/builtin_hint_processor/math_utils.rs b/src/hint_processor/builtin_hint_processor/math_utils.rs index 8a12232418..f99246b10e 100644 --- a/src/hint_processor/builtin_hint_processor/math_utils.rs +++ b/src/hint_processor/builtin_hint_processor/math_utils.rs @@ -1,11 +1,4 @@ -use crate::stdlib::{ - collections::HashMap, - ops::{Shl, Shr}, - prelude::*, -}; - use crate::utils::CAIRO_PRIME; - use crate::{ any_box, hint_processor::{ @@ -28,6 +21,11 @@ use num_bigint::BigUint; use num_integer::Integer; use num_traits::One; use num_traits::{Signed, Zero}; +use std::{ + any::Any, + collections::HashMap, + ops::{Shl, Shr}, +}; use super::hint_utils::get_maybe_relocatable_from_var_name; @@ -538,7 +536,6 @@ fn div_prime_by_bound(bound: Felt) -> Result { #[cfg(test)] mod tests { use super::*; - use crate::stdlib::ops::Shl; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ any_box, @@ -559,12 +556,9 @@ mod tests { use assert_matches::assert_matches; use felt::felt_str; use num_traits::Zero; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::{any::Any, ops::Shl}; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_nn_hint_false() { let hint_code = "memory[ap] = 0 if 0 <= (ids.a % PRIME) < range_check_builtin.bound else 1"; let mut vm = vm_with_range_check!(); @@ -582,7 +576,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_nn_hint_true() { let hint_code = "memory[ap] = 0 if 0 <= (ids.a % PRIME) < range_check_builtin.bound else 1"; let mut vm = vm_with_range_check!(); @@ -600,7 +593,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] //This test contemplates the case when the number itself is negative, but it is within the range (-prime, -range_check_bound) //Making the comparison return 1 (true) fn run_is_nn_hint_true_border_case() { @@ -625,7 +617,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_nn_hint_no_range_check_builtin() { let hint_code = "memory[ap] = 0 if 0 <= (ids.a % PRIME) < range_check_builtin.bound else 1"; let mut vm = vm!(); @@ -645,7 +636,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_nn_hint_incorrect_ids() { let hint_code = "memory[ap] = 0 if 0 <= (ids.a % PRIME) < range_check_builtin.bound else 1"; let mut vm = vm_with_range_check!(); @@ -661,7 +651,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_nn_hint_cant_get_ids_from_memory() { let hint_code = "memory[ap] = 0 if 0 <= (ids.a % PRIME) < range_check_builtin.bound else 1"; let mut vm = vm_with_range_check!(); @@ -680,7 +669,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_nn_hint_ids_are_relocatable_values() { let hint_code = "memory[ap] = 0 if 0 <= (ids.a % PRIME) < range_check_builtin.bound else 1"; let mut vm = vm_with_range_check!(); @@ -699,7 +687,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_le_felt_valid() { let hint_code = ASSERT_LE_FELT; let mut constants = HashMap::new(); @@ -729,7 +716,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_le_felt_hint_true() { let hint_code = "memory[ap] = 0 if (ids.a % PRIME) <= (ids.b % PRIME) else 1"; let mut vm = vm_with_range_check!(); @@ -746,7 +732,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_le_felt_hint_inconsistent_memory() { let hint_code = "memory[ap] = 0 if (ids.a % PRIME) <= (ids.b % PRIME) else 1"; let mut vm = vm_with_range_check!(); @@ -771,7 +756,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_le_felt_hint_incorrect_ids() { let hint_code = "memory[ap] = 0 if (ids.a % PRIME) <= (ids.b % PRIME) else 1"; let mut vm = vm!(); @@ -786,7 +770,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_nn_valid() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert 0 <= ids.a % PRIME < range_check_builtin.bound, f'a = {ids.a} is out of range.'"; let mut vm = vm_with_range_check!(); @@ -802,7 +785,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_nn_invalid() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert 0 <= ids.a % PRIME < range_check_builtin.bound, f'a = {ids.a} is out of range.'"; let mut vm = vm_with_range_check!(); @@ -820,7 +802,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_nn_incorrect_ids() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert 0 <= ids.a % PRIME < range_check_builtin.bound, f'a = {ids.a} is out of range.'"; let mut vm = vm_with_range_check!(); @@ -837,7 +818,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_nn_a_is_not_integer() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert 0 <= ids.a % PRIME < range_check_builtin.bound, f'a = {ids.a} is out of range.'"; let mut vm = vm_with_range_check!(); @@ -855,7 +835,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_nn_no_range_check_builtin() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert 0 <= ids.a % PRIME < range_check_builtin.bound, f'a = {ids.a} is out of range.'"; let mut vm = vm!(); @@ -874,7 +853,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_nn_reference_is_not_in_memory() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert 0 <= ids.a % PRIME < range_check_builtin.bound, f'a = {ids.a} is out of range.'"; let mut vm = vm_with_range_check!(); @@ -891,7 +869,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_assert_le_felt_invalid() { let hint_code = ASSERT_LE_FELT; let mut vm = vm_with_range_check!(); @@ -919,7 +896,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_assert_le_felt_a_is_not_integer() { let hint_code = ASSERT_LE_FELT; let mut vm = vm_with_range_check!(); @@ -947,7 +923,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_assert_le_felt_b_is_not_integer() { let hint_code = ASSERT_LE_FELT; let mut vm = vm_with_range_check!(); @@ -975,7 +950,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_nn_hint_out_of_range_false() { let hint_code = "memory[ap] = 0 if 0 <= ((-ids.a - 1) % PRIME) < range_check_builtin.bound else 1"; @@ -993,7 +967,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_nn_hint_out_of_range_true() { let hint_code = "memory[ap] = 0 if 0 <= ((-ids.a - 1) % PRIME) < range_check_builtin.bound else 1"; @@ -1010,7 +983,6 @@ mod tests { check_memory![vm.segments.memory, ((1, 0), 0)]; } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_equal_int_false() { let hint_code = "from starkware.cairo.lang.vm.relocatable import RelocatableValue\nboth_ints = isinstance(ids.a, int) and isinstance(ids.b, int)\nboth_relocatable = (\n isinstance(ids.a, RelocatableValue) and isinstance(ids.b, RelocatableValue) and\n ids.a.segment_index == ids.b.segment_index)\nassert both_ints or both_relocatable, \\\n f'assert_not_equal failed: non-comparable values: {ids.a}, {ids.b}.'\nassert (ids.a - ids.b) % PRIME != 0, f'assert_not_equal failed: {ids.a} = {ids.b}.'"; let mut vm = vm!(); @@ -1031,7 +1003,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_equal_int_true() { let hint_code = "from starkware.cairo.lang.vm.relocatable import RelocatableValue\nboth_ints = isinstance(ids.a, int) and isinstance(ids.b, int)\nboth_relocatable = (\n isinstance(ids.a, RelocatableValue) and isinstance(ids.b, RelocatableValue) and\n ids.a.segment_index == ids.b.segment_index)\nassert both_ints or both_relocatable, \\\n f'assert_not_equal failed: non-comparable values: {ids.a}, {ids.b}.'\nassert (ids.a - ids.b) % PRIME != 0, f'assert_not_equal failed: {ids.a} = {ids.b}.'"; let mut vm = vm!(); @@ -1045,7 +1016,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_equal_int_bignum_true() { let hint_code = "from starkware.cairo.lang.vm.relocatable import RelocatableValue\nboth_ints = isinstance(ids.a, int) and isinstance(ids.b, int)\nboth_relocatable = (\n isinstance(ids.a, RelocatableValue) and isinstance(ids.b, RelocatableValue) and\n ids.a.segment_index == ids.b.segment_index)\nassert both_ints or both_relocatable, \\\n f'assert_not_equal failed: non-comparable values: {ids.a}, {ids.b}.'\nassert (ids.a - ids.b) % PRIME != 0, f'assert_not_equal failed: {ids.a} = {ids.b}.'"; let mut vm = vm!(); @@ -1069,7 +1039,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_equal_relocatable_false() { let hint_code = "from starkware.cairo.lang.vm.relocatable import RelocatableValue\nboth_ints = isinstance(ids.a, int) and isinstance(ids.b, int)\nboth_relocatable = (\n isinstance(ids.a, RelocatableValue) and isinstance(ids.b, RelocatableValue) and\n ids.a.segment_index == ids.b.segment_index)\nassert both_ints or both_relocatable, \\\n f'assert_not_equal failed: non-comparable values: {ids.a}, {ids.b}.'\nassert (ids.a - ids.b) % PRIME != 0, f'assert_not_equal failed: {ids.a} = {ids.b}.'"; let mut vm = vm!(); @@ -1090,7 +1059,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_equal_relocatable_true() { let hint_code = "from starkware.cairo.lang.vm.relocatable import RelocatableValue\nboth_ints = isinstance(ids.a, int) and isinstance(ids.b, int)\nboth_relocatable = (\n isinstance(ids.a, RelocatableValue) and isinstance(ids.b, RelocatableValue) and\n ids.a.segment_index == ids.b.segment_index)\nassert both_ints or both_relocatable, \\\n f'assert_not_equal failed: non-comparable values: {ids.a}, {ids.b}.'\nassert (ids.a - ids.b) % PRIME != 0, f'assert_not_equal failed: {ids.a} = {ids.b}.'"; let mut vm = vm!(); @@ -1104,7 +1072,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_non_equal_relocatable_diff_index() { let hint_code = "from starkware.cairo.lang.vm.relocatable import RelocatableValue\nboth_ints = isinstance(ids.a, int) and isinstance(ids.b, int)\nboth_relocatable = (\n isinstance(ids.a, RelocatableValue) and isinstance(ids.b, RelocatableValue) and\n ids.a.segment_index == ids.b.segment_index)\nassert both_ints or both_relocatable, \\\n f'assert_not_equal failed: non-comparable values: {ids.a}, {ids.b}.'\nassert (ids.a - ids.b) % PRIME != 0, f'assert_not_equal failed: {ids.a} = {ids.b}.'"; let mut vm = vm!(); @@ -1124,7 +1091,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_equal_relocatable_and_integer() { let hint_code = "from starkware.cairo.lang.vm.relocatable import RelocatableValue\nboth_ints = isinstance(ids.a, int) and isinstance(ids.b, int)\nboth_relocatable = (\n isinstance(ids.a, RelocatableValue) and isinstance(ids.b, RelocatableValue) and\n ids.a.segment_index == ids.b.segment_index)\nassert both_ints or both_relocatable, \\\n f'assert_not_equal failed: non-comparable values: {ids.a}, {ids.b}.'\nassert (ids.a - ids.b) % PRIME != 0, f'assert_not_equal failed: {ids.a} = {ids.b}.'"; let mut vm = vm!(); @@ -1146,7 +1112,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_zero_true() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.value)\nassert ids.value % PRIME != 0, f'assert_not_zero failed: {ids.value} = 0.'"; @@ -1162,7 +1127,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_zero_false() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.value)\nassert ids.value % PRIME != 0, f'assert_not_zero failed: {ids.value} = 0.'"; @@ -1183,7 +1147,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_zero_incorrect_id() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.value)\nassert ids.value % PRIME != 0, f'assert_not_zero failed: {ids.value} = 0.'"; @@ -1201,7 +1164,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_not_zero_expected_integer_error() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.value)\nassert ids.value % PRIME != 0, f'assert_not_zero failed: {ids.value} = 0.'"; @@ -1220,7 +1182,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_int_assertion_invalid() { let hint_code = "assert ids.value == 0, 'split_int(): value is out of range.'"; let mut vm = vm!(); @@ -1237,7 +1198,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_int_assertion_valid() { let hint_code = "assert ids.value == 0, 'split_int(): value is out of range.'"; let mut vm = vm!(); @@ -1251,7 +1211,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_int_valid() { let hint_code = "memory[ids.output] = res = (int(ids.value) % PRIME) % ids.base\nassert res < ids.bound, f'split_int(): Limb {res} is out of range.'"; let mut vm = vm!(); @@ -1267,7 +1226,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_int_invalid() { let hint_code = "memory[ids.output] = res = (int(ids.value) % PRIME) % ids.base\nassert res < ids.bound, f'split_int(): Limb {res} is out of range.'"; let mut vm = vm!(); @@ -1290,7 +1248,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_positive_hint_true() { let hint_code = "from starkware.cairo.common.math_utils import is_positive\nids.is_positive = 1 if is_positive(\n value=ids.value, prime=PRIME, rc_bound=range_check_builtin.bound) else 0"; @@ -1309,7 +1266,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_positive_hint_false() { let hint_code = "from starkware.cairo.common.math_utils import is_positive\nids.is_positive = 1 if is_positive(\n value=ids.value, prime=PRIME, rc_bound=range_check_builtin.bound) else 0"; @@ -1327,7 +1283,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_positive_hint_outside_valid_range() { let hint_code = "from starkware.cairo.common.math_utils import is_positive\nids.is_positive = 1 if is_positive(\n value=ids.value, prime=PRIME, rc_bound=range_check_builtin.bound) else 0"; @@ -1354,7 +1309,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_positive_hint_is_positive_not_empty() { let hint_code ="from starkware.cairo.common.math_utils import is_positive\nids.is_positive = 1 if is_positive(\n value=ids.value, prime=PRIME, rc_bound=range_check_builtin.bound) else 0"; let mut vm = vm_with_range_check!(); @@ -1380,7 +1334,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_sqrt_valid() { let hint_code = "from starkware.python.math_utils import isqrt\nvalue = ids.value % PRIME\nassert value < 2 ** 250, f\"value={value} is outside of the range [0, 2**250).\"\nassert 2 ** 250 < PRIME\nids.root = isqrt(value)"; let mut vm = vm!(); @@ -1397,7 +1350,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_sqrt_invalid_negative_number() { let hint_code = "from starkware.python.math_utils import isqrt\nvalue = ids.value % PRIME\nassert value < 2 ** 250, f\"value={value} is outside of the range [0, 2**250).\"\nassert 2 ** 250 < PRIME\nids.root = isqrt(value)"; let mut vm = vm!(); @@ -1417,7 +1369,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_sqrt_invalid_mismatched_root() { let hint_code = "from starkware.python.math_utils import isqrt\nvalue = ids.value % PRIME\nassert value < 2 ** 250, f\"value={value} is outside of the range [0, 2**250).\"\nassert 2 ** 250 < PRIME\nids.root = isqrt(value)"; let mut vm = vm!(); @@ -1443,7 +1394,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsigned_div_rem_success() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\nids.q, ids.r = divmod(ids.value, ids.div)"; let mut vm = vm_with_range_check!(); @@ -1459,7 +1409,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsigned_div_rem_out_of_range() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\nids.q, ids.r = divmod(ids.value, ids.div)"; let mut vm = vm_with_range_check!(); @@ -1480,7 +1429,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsigned_div_rem_no_range_check_builtin() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\nids.q, ids.r = divmod(ids.value, ids.div)"; let mut vm = vm!(); @@ -1499,7 +1447,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsigned_div_rem_inconsitent_memory() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\nids.q, ids.r = divmod(ids.value, ids.div)"; let mut vm = vm_with_range_check!(); @@ -1525,7 +1472,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsigned_div_rem_incorrect_ids() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\nids.q, ids.r = divmod(ids.value, ids.div)"; let mut vm = vm_with_range_check!(); @@ -1543,7 +1489,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn signed_div_rem_success() { let hint_code = "from starkware.cairo.common.math_utils import as_int, assert_integer\n\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\n\nassert_integer(ids.bound)\nassert ids.bound <= range_check_builtin.bound // 2, \\\n f'bound={hex(ids.bound)} is out of the valid range.'\n\nint_value = as_int(ids.value, PRIME)\nq, ids.r = divmod(int_value, ids.div)\n\nassert -ids.bound <= q < ids.bound, \\\n f'{int_value} / {ids.div} = {q} is out of the range [{-ids.bound}, {ids.bound}).'\n\nids.biased_q = q + ids.bound"; let mut vm = vm_with_range_check!(); @@ -1559,7 +1504,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn signed_div_rem_negative_quotient() { let hint_code = "from starkware.cairo.common.math_utils import as_int, assert_integer\n\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\n\nassert_integer(ids.bound)\nassert ids.bound <= range_check_builtin.bound // 2, \\\n f'bound={hex(ids.bound)} is out of the valid range.'\n\nint_value = as_int(ids.value, PRIME)\nq, ids.r = divmod(int_value, ids.div)\n\nassert -ids.bound <= q < ids.bound, \\\n f'{int_value} / {ids.div} = {q} is out of the range [{-ids.bound}, {ids.bound}).'\n\nids.biased_q = q + ids.bound"; let mut vm = vm_with_range_check!(); @@ -1575,7 +1519,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn signed_div_rem_out_of_range() { let hint_code = "from starkware.cairo.common.math_utils import as_int, assert_integer\n\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\n\nassert_integer(ids.bound)\nassert ids.bound <= range_check_builtin.bound // 2, \\\n f'bound={hex(ids.bound)} is out of the valid range.'\n\nint_value = as_int(ids.value, PRIME)\nq, ids.r = divmod(int_value, ids.div)\n\nassert -ids.bound <= q < ids.bound, \\\n f'{int_value} / {ids.div} = {q} is out of the range [{-ids.bound}, {ids.bound}).'\n\nids.biased_q = q + ids.bound"; let mut vm = vm_with_range_check!(); @@ -1596,7 +1539,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn signed_div_rem_no_range_check_builtin() { let hint_code = "from starkware.cairo.common.math_utils import as_int, assert_integer\n\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\n\nassert_integer(ids.bound)\nassert ids.bound <= range_check_builtin.bound // 2, \\\n f'bound={hex(ids.bound)} is out of the valid range.'\n\nint_value = as_int(ids.value, PRIME)\nq, ids.r = divmod(int_value, ids.div)\n\nassert -ids.bound <= q < ids.bound, \\\n f'{int_value} / {ids.div} = {q} is out of the range [{-ids.bound}, {ids.bound}).'\n\nids.biased_q = q + ids.bound"; let mut vm = vm!(); @@ -1615,7 +1557,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn signed_div_rem_inconsitent_memory() { let hint_code = "from starkware.cairo.common.math_utils import as_int, assert_integer\n\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\n\nassert_integer(ids.bound)\nassert ids.bound <= range_check_builtin.bound // 2, \\\n f'bound={hex(ids.bound)} is out of the valid range.'\n\nint_value = as_int(ids.value, PRIME)\nq, ids.r = divmod(int_value, ids.div)\n\nassert -ids.bound <= q < ids.bound, \\\n f'{int_value} / {ids.div} = {q} is out of the range [{-ids.bound}, {ids.bound}).'\n\nids.biased_q = q + ids.bound"; let mut vm = vm_with_range_check!(); @@ -1641,7 +1582,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn signed_div_rem_incorrect_ids() { let hint_code = "from starkware.cairo.common.math_utils import as_int, assert_integer\n\nassert_integer(ids.div)\nassert 0 < ids.div <= PRIME // range_check_builtin.bound, \\\n f'div={hex(ids.div)} is out of the valid range.'\n\nassert_integer(ids.bound)\nassert ids.bound <= range_check_builtin.bound // 2, \\\n f'bound={hex(ids.bound)} is out of the valid range.'\n\nint_value = as_int(ids.value, PRIME)\nq, ids.r = divmod(int_value, ids.div)\n\nassert -ids.bound <= q < ids.bound, \\\n f'{int_value} / {ids.div} = {q} is out of the range [{-ids.bound}, {ids.bound}).'\n\nids.biased_q = q + ids.bound"; let mut vm = vm_with_range_check!(); @@ -1659,7 +1599,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_250_bit_valid() { let hint_code = "from starkware.cairo.common.math_utils import as_int\n\n# Correctness check.\nvalue = as_int(ids.value, PRIME) % PRIME\nassert value < ids.UPPER_BOUND, f'{value} is outside of the range [0, 2**250).'\n\n# Calculation for the assertion.\nids.high, ids.low = divmod(ids.value, ids.SHIFT)"; let mut vm = vm!(); @@ -1677,7 +1616,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_250_bit_invalid() { let hint_code = "from starkware.cairo.common.math_utils import as_int\n\n# Correctness check.\nvalue = as_int(ids.value, PRIME) % PRIME\nassert value < ids.UPPER_BOUND, f'{value} is outside of the range [0, 2**250).'\n\n# Calculation for the assertion.\nids.high, ids.low = divmod(ids.value, ids.SHIFT)"; let mut vm = vm!(); @@ -1702,7 +1640,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_felt_ok() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert ids.MAX_HIGH < 2**128 and ids.MAX_LOW < 2**128\nassert PRIME - 1 == ids.MAX_HIGH * 2**128 + ids.MAX_LOW\nassert_integer(ids.value)\nids.low = ids.value & ((1 << 128) - 1)\nids.high = ids.value >> 128"; @@ -1731,7 +1668,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_felt_incorrect_ids() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert ids.MAX_HIGH < 2**128 and ids.MAX_LOW < 2**128\nassert PRIME - 1 == ids.MAX_HIGH * 2**128 + ids.MAX_LOW\nassert_integer(ids.value)\nids.low = ids.value & ((1 << 128) - 1)\nids.high = ids.value >> 128"; @@ -1753,7 +1689,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_felt_fails_first_insert() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert ids.MAX_HIGH < 2**128 and ids.MAX_LOW < 2**128\nassert PRIME - 1 == ids.MAX_HIGH * 2**128 + ids.MAX_LOW\nassert_integer(ids.value)\nids.low = ids.value & ((1 << 128) - 1)\nids.high = ids.value >> 128"; @@ -1788,7 +1723,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_felt_fails_second_insert() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert ids.MAX_HIGH < 2**128 and ids.MAX_LOW < 2**128\nassert PRIME - 1 == ids.MAX_HIGH * 2**128 + ids.MAX_LOW\nassert_integer(ids.value)\nids.low = ids.value & ((1 << 128) - 1)\nids.high = ids.value >> 128"; @@ -1823,7 +1757,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_felt_value_is_not_integer() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert ids.MAX_HIGH < 2**128 and ids.MAX_LOW < 2**128\nassert PRIME - 1 == ids.MAX_HIGH * 2**128 + ids.MAX_LOW\nassert_integer(ids.value)\nids.low = ids.value & ((1 << 128) - 1)\nids.high = ids.value >> 128"; @@ -1846,7 +1779,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_lt_felt_ok() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert_integer(ids.b)\nassert (ids.a % PRIME) < (ids.b % PRIME), \\\n f'a = {ids.a % PRIME} is not less than b = {ids.b % PRIME}.'"; @@ -1862,7 +1794,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_lt_felt_assert_fails() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert_integer(ids.b)\nassert (ids.a % PRIME) < (ids.b % PRIME), \\\n f'a = {ids.a % PRIME} is not less than b = {ids.b % PRIME}.'"; @@ -1879,7 +1810,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_lt_felt_incorrect_ids() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert_integer(ids.b)\nassert (ids.a % PRIME) < (ids.b % PRIME), \\\n f'a = {ids.a % PRIME} is not less than b = {ids.b % PRIME}.'"; @@ -1897,7 +1827,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_lt_felt_a_is_not_integer() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert_integer(ids.b)\nassert (ids.a % PRIME) < (ids.b % PRIME), \\\n f'a = {ids.a % PRIME} is not less than b = {ids.b % PRIME}.'"; @@ -1915,7 +1844,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_lt_felt_b_is_not_integer() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert_integer(ids.b)\nassert (ids.a % PRIME) < (ids.b % PRIME), \\\n f'a = {ids.a % PRIME} is not less than b = {ids.b % PRIME}.'"; @@ -1933,7 +1861,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_assert_lt_felt_ok_failed_to_get_ids() { let hint_code = "from starkware.cairo.common.math_utils import assert_integer\nassert_integer(ids.a)\nassert_integer(ids.b)\nassert (ids.a % PRIME) < (ids.b % PRIME), \\\n f'a = {ids.a % PRIME} is not less than b = {ids.b % PRIME}.'"; diff --git a/src/hint_processor/builtin_hint_processor/memcpy_hint_utils.rs b/src/hint_processor/builtin_hint_processor/memcpy_hint_utils.rs index 4ac912179b..a7e8d36ad6 100644 --- a/src/hint_processor/builtin_hint_processor/memcpy_hint_utils.rs +++ b/src/hint_processor/builtin_hint_processor/memcpy_hint_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{any::Any, collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -13,6 +11,7 @@ use crate::{ }; use felt::Felt; use num_traits::{One, Zero}; +use std::{any::Any, collections::HashMap}; //Implements hint: memory[ap] = segments.add() pub fn add_segment(vm: &mut VirtualMachine) -> Result<(), HintError> { @@ -83,11 +82,7 @@ mod tests { }; use assert_matches::assert_matches; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_integer_from_var_name_valid() { let mut vm = vm!(); // initialize memory segments @@ -113,7 +108,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_integer_from_var_name_invalid_expected_integer() { let mut vm = vm!(); diff --git a/src/hint_processor/builtin_hint_processor/memset_utils.rs b/src/hint_processor/builtin_hint_processor/memset_utils.rs index f915c544f2..8d13dd38da 100644 --- a/src/hint_processor/builtin_hint_processor/memset_utils.rs +++ b/src/hint_processor/builtin_hint_processor/memset_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{any::Any, collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -13,6 +11,7 @@ use crate::{ }; use felt::Felt; use num_traits::Signed; +use std::{any::Any, collections::HashMap}; // Implements hint: // %{ vm_enter_scope({'n': ids.n}) %} @@ -57,7 +56,6 @@ pub fn memset_continue_loop( #[cfg(test)] mod tests { use super::*; - use crate::stdlib::string::ToString; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ any_box, @@ -74,11 +72,7 @@ mod tests { use assert_matches::assert_matches; use num_traits::{One, Zero}; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memset_enter_scope_valid() { let hint_code = "vm_enter_scope({'n': ids.n})"; let mut vm = vm!(); @@ -91,7 +85,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memset_enter_scope_invalid() { let hint_code = "vm_enter_scope({'n': ids.n})"; let mut vm = vm!(); @@ -109,7 +102,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memset_continue_loop_valid_continue_loop_equal_1() { let hint_code = "n -= 1\nids.continue_loop = 1 if n > 0 else 0"; let mut vm = vm!(); @@ -127,7 +119,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memset_continue_loop_valid_continue_loop_equal_5() { let hint_code = "n -= 1\nids.continue_loop = 1 if n > 0 else 0"; let mut vm = vm!(); @@ -146,7 +137,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memset_continue_loop_variable_not_in_scope_error() { let hint_code = "n -= 1\nids.continue_loop = 1 if n > 0 else 0"; let mut vm = vm!(); @@ -168,7 +158,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memset_continue_loop_insert_error() { let hint_code = "n -= 1\nids.continue_loop = 1 if n > 0 else 0"; let mut vm = vm!(); diff --git a/src/hint_processor/builtin_hint_processor/pow_utils.rs b/src/hint_processor/builtin_hint_processor/pow_utils.rs index 7986ac277b..6de8b9e877 100644 --- a/src/hint_processor/builtin_hint_processor/pow_utils.rs +++ b/src/hint_processor/builtin_hint_processor/pow_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -12,6 +10,7 @@ use crate::{ }; use felt::Felt; use num_integer::Integer; +use std::collections::HashMap; /* Implements hint: @@ -54,12 +53,9 @@ mod tests { }; use assert_matches::assert_matches; use num_traits::One; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_pow_ok() { let hint_code = "ids.locs.bit = (ids.prev_locs.exp % PRIME) & 1"; let mut vm = vm_with_range_check!(); @@ -73,7 +69,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_pow_incorrect_ids() { let hint_code = "ids.locs.bit = (ids.prev_locs.exp % PRIME) & 1"; let mut vm = vm_with_range_check!(); @@ -90,7 +85,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_pow_incorrect_references() { let hint_code = "ids.locs.bit = (ids.prev_locs.exp % PRIME) & 1"; let mut vm = vm_with_range_check!(); @@ -107,7 +101,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_pow_prev_locs_exp_is_not_integer() { let hint_code = "ids.locs.bit = (ids.prev_locs.exp % PRIME) & 1"; let mut vm = vm_with_range_check!(); @@ -126,7 +119,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_pow_invalid_memory_insert() { let hint_code = "ids.locs.bit = (ids.prev_locs.exp % PRIME) & 1"; let mut vm = vm_with_range_check!(); diff --git a/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs b/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs index 4c8d59772e..68670332bd 100644 --- a/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs +++ b/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs @@ -1,4 +1,3 @@ -use crate::stdlib::{borrow::Cow, collections::HashMap, prelude::*}; use crate::{ hint_processor::{ builtin_hint_processor::{ @@ -15,6 +14,7 @@ use crate::{ vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; use felt::Felt; +use std::{borrow::Cow, collections::HashMap}; #[derive(Debug, PartialEq)] pub(crate) struct BigInt3<'a> { @@ -109,8 +109,6 @@ mod tests { BuiltinHintProcessor, HintProcessorData, }; use crate::hint_processor::hint_processor_definition::HintProcessor; - use crate::stdlib::ops::Shl; - use crate::stdlib::string::ToString; use crate::types::exec_scope::ExecutionScopes; use crate::types::relocatable::MaybeRelocatable; use crate::types::relocatable::Relocatable; @@ -122,12 +120,10 @@ mod tests { use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use assert_matches::assert_matches; use num_traits::One; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; + use std::ops::Shl; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_nondet_bigint3_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import split\n\nsegments.write_arg(ids.res.address_, split(value))"; let mut vm = vm_with_range_check!(); @@ -164,7 +160,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_nondet_bigint3_value_not_in_scope() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import split\n\nsegments.write_arg(ids.res.address_, split(value))"; let mut vm = vm_with_range_check!(); @@ -180,7 +175,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_nondet_bigint3_split_error() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import split\n\nsegments.write_arg(ids.res.address_, split(value))"; let mut vm = vm_with_range_check!(); diff --git a/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs b/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs index 5e2cabf9e5..cad7bd38a1 100644 --- a/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs +++ b/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs @@ -1,8 +1,3 @@ -use crate::stdlib::{ - collections::HashMap, - ops::{BitAnd, Shl}, - prelude::*, -}; use crate::{ hint_processor::{ builtin_hint_processor::{ @@ -22,6 +17,10 @@ use felt::Felt; use num_bigint::BigInt; use num_integer::Integer; use num_traits::{One, Zero}; +use std::{ + collections::HashMap, + ops::{BitAnd, Shl}, +}; use super::bigint_utils::BigInt3; @@ -331,7 +330,6 @@ pub fn ec_mul_inner( #[cfg(test)] mod tests { use super::*; - use crate::stdlib::string::ToString; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ any_box, @@ -352,12 +350,9 @@ mod tests { }, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_ec_negate_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\ny = pack(ids.point.y, PRIME) % SECP_P\n# The modulo operation in python always returns a nonnegative number.\nvalue = (-y) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -401,7 +396,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_compute_doubling_slope_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\nfrom starkware.python.math_utils import ec_double_slope\n\n# Compute the slope.\nx = pack(ids.point.x, PRIME)\ny = pack(ids.point.y, PRIME)\nvalue = slope = ec_double_slope(point=(x, y), alpha=0, p=SECP_P)"; let mut vm = vm_with_range_check!(); @@ -463,7 +457,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_compute_slope_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\nfrom starkware.python.math_utils import line_slope\n\n# Compute the slope.\nx0 = pack(ids.point0.x, PRIME)\ny0 = pack(ids.point0.y, PRIME)\nx1 = pack(ids.point1.x, PRIME)\ny1 = pack(ids.point1.y, PRIME)\nvalue = slope = line_slope(point1=(x0, y0), point2=(x1, y1), p=SECP_P)"; let mut vm = vm_with_range_check!(); @@ -535,7 +528,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_ec_double_assign_new_x_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nslope = pack(ids.slope, PRIME)\nx = pack(ids.point.x, PRIME)\ny = pack(ids.point.y, PRIME)\n\nvalue = new_x = (pow(slope, 2, SECP_P) - 2 * x) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -619,7 +611,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_ec_double_assign_new_y_ok() { let hint_code = "value = new_y = (slope * (x - new_x) - y) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -689,7 +680,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_fast_ec_add_assign_new_x_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nslope = pack(ids.slope, PRIME)\nx0 = pack(ids.point0.x, PRIME)\nx1 = pack(ids.point1.x, PRIME)\ny0 = pack(ids.point0.y, PRIME)\n\nvalue = new_x = (pow(slope, 2, SECP_P) - x0 - x1) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -767,7 +757,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_fast_ec_add_assign_new_y_ok() { let hint_code = "value = new_y = (slope * (x0 - new_x) - y0) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -839,7 +828,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_ec_mul_inner_ok() { let hint_code = "memory[ap] = (ids.scalar % PRIME) % 2"; let mut vm = vm_with_range_check!(); diff --git a/src/hint_processor/builtin_hint_processor/secp/field_utils.rs b/src/hint_processor/builtin_hint_processor/secp/field_utils.rs index fea37db3ea..3fb1a80068 100644 --- a/src/hint_processor/builtin_hint_processor/secp/field_utils.rs +++ b/src/hint_processor/builtin_hint_processor/secp/field_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, ops::Shl, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::{ @@ -17,6 +15,7 @@ use felt::Felt; use num_bigint::BigInt; use num_integer::Integer; use num_traits::{One, Zero}; +use std::{collections::HashMap, ops::Shl}; use super::{bigint_utils::BigInt3, secp_utils::pack}; @@ -162,7 +161,6 @@ pub fn is_zero_assign_scope_variables( #[cfg(test)] mod tests { use super::*; - use crate::stdlib::string::ToString; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ any_box, @@ -183,12 +181,9 @@ mod tests { }, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_verify_zero_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nq, r = divmod(pack(ids.val, PRIME), SECP_P)\nassert r == 0, f\"verify_zero: Invalid input {ids.val.d0, ids.val.d1, ids.val.d2}.\"\nids.q = q % PRIME"; let mut vm = vm_with_range_check!(); @@ -226,7 +221,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_verify_zero_error() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nq, r = divmod(pack(ids.val, PRIME), SECP_P)\nassert r == 0, f\"verify_zero: Invalid input {ids.val.d0, ids.val.d1, ids.val.d2}.\"\nids.q = q % PRIME"; let mut vm = vm_with_range_check!(); @@ -264,7 +258,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_verify_zero_invalid_memory_insert() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nq, r = divmod(pack(ids.val, PRIME), SECP_P)\nassert r == 0, f\"verify_zero: Invalid input {ids.val.d0, ids.val.d1, ids.val.d2}.\"\nids.q = q % PRIME"; let mut vm = vm_with_range_check!(); @@ -310,7 +303,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_reduce_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nvalue = pack(ids.x, PRIME) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -363,7 +355,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_reduce_error() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nvalue = pack(ids.x, PRIME) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -402,7 +393,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_zero_pack_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nx = pack(ids.x, PRIME) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -458,7 +448,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_zero_pack_error() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nx = pack(ids.x, PRIME) % SECP_P"; let mut vm = vm_with_range_check!(); @@ -498,7 +487,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_zero_nondet_ok_true() { let hint_code = "memory[ap] = to_felt_or_relocatable(x == 0)"; let mut vm = vm_with_range_check!(); @@ -525,7 +513,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_zero_nondet_ok_false() { let hint_code = "memory[ap] = to_felt_or_relocatable(x == 0)"; let mut vm = vm_with_range_check!(); @@ -552,7 +539,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_zero_nondet_scope_error() { let hint_code = "memory[ap] = to_felt_or_relocatable(x == 0)"; let mut vm = vm_with_range_check!(); @@ -573,7 +559,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_is_zero_nondet_invalid_memory_insert() { let hint_code = "memory[ap] = to_felt_or_relocatable(x == 0)"; let mut vm = vm_with_range_check!(); @@ -603,7 +588,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_zero_assign_scope_variables_ok() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P\nfrom starkware.python.math_utils import div_mod\n\nvalue = x_inv = div_mod(1, x, SECP_P)"; let mut vm = vm_with_range_check!(); @@ -658,7 +642,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_zero_assign_scope_variables_scope_error() { let hint_code = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P\nfrom starkware.python.math_utils import div_mod\n\nvalue = x_inv = div_mod(1, x, SECP_P)"; let mut vm = vm_with_range_check!(); diff --git a/src/hint_processor/builtin_hint_processor/secp/secp_utils.rs b/src/hint_processor/builtin_hint_processor/secp/secp_utils.rs index 60b0232daf..7952efd40b 100644 --- a/src/hint_processor/builtin_hint_processor/secp/secp_utils.rs +++ b/src/hint_processor/builtin_hint_processor/secp/secp_utils.rs @@ -1,9 +1,9 @@ -use crate::stdlib::{collections::HashMap, ops::Shl, prelude::*}; - use crate::vm::errors::hint_errors::HintError; use felt::Felt; use num_traits::Zero; +use std::collections::HashMap; +use std::ops::Shl; use super::bigint_utils::BigInt3; @@ -64,19 +64,16 @@ pub(crate) fn pack(num: BigInt3) -> num_bigint::BigInt { #[cfg(test)] mod tests { + use std::borrow::Cow; + use super::*; - use crate::stdlib::{borrow::Cow, string::ToString}; use crate::utils::test_utils::*; use assert_matches::assert_matches; use felt::felt_str; use num_bigint::BigUint; use num_traits::One; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn secp_split() { let mut constants = HashMap::new(); constants.insert(BASE_86.to_string(), Felt::one() << 86_usize); @@ -147,7 +144,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn secp_pack() { let pack_1 = pack(BigInt3 { d0: Cow::Borrowed(&Felt::new(10_i32)), diff --git a/src/hint_processor/builtin_hint_processor/secp/signature.rs b/src/hint_processor/builtin_hint_processor/secp/signature.rs index 8364e94c6a..25d3375c70 100644 --- a/src/hint_processor/builtin_hint_processor/secp/signature.rs +++ b/src/hint_processor/builtin_hint_processor/secp/signature.rs @@ -1,9 +1,3 @@ -use crate::stdlib::{ - collections::HashMap, - ops::{Shl, Shr}, - prelude::*, -}; - use crate::{ hint_processor::{ builtin_hint_processor::{ @@ -22,6 +16,10 @@ use felt::Felt; use num_bigint::BigInt; use num_integer::Integer; use num_traits::One; +use std::{ + collections::HashMap, + ops::{Shl, Shr}, +}; use super::bigint_utils::BigInt3; @@ -150,8 +148,6 @@ pub fn get_point_from_x( #[cfg(test)] mod tests { use super::*; - use crate::stdlib::ops::Shl; - use crate::stdlib::string::ToString; use crate::types::errors::math_errors::MathError; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ @@ -169,12 +165,9 @@ mod tests { }; use assert_matches::assert_matches; use num_traits::Zero; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::{any::Any, ops::Shl}; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn safe_div_ok() { let hint_code = hint_code::DIV_MOD_N_PACKED_DIVMOD; let mut vm = vm!(); @@ -207,7 +200,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn safe_div_fail() { let mut exec_scopes = scope![ ("a", BigInt::zero()), @@ -237,7 +229,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_point_from_x_ok() { let hint_code = hint_code::GET_POINT_FROM_X; let mut vm = vm!(); @@ -277,7 +268,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_point_from_x_negative_y() { let hint_code = hint_code::GET_POINT_FROM_X; let mut vm = vm!(); diff --git a/src/hint_processor/builtin_hint_processor/segments.rs b/src/hint_processor/builtin_hint_processor/segments.rs index 6ca1e525ff..45a779ca26 100644 --- a/src/hint_processor/builtin_hint_processor/segments.rs +++ b/src/hint_processor/builtin_hint_processor/segments.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, prelude::*}; - use crate::hint_processor::builtin_hint_processor::hint_utils::get_ptr_from_var_name; use crate::hint_processor::{ builtin_hint_processor::hint_utils::insert_value_from_var_name, @@ -8,6 +6,7 @@ use crate::hint_processor::{ use crate::serde::deserialize_program::ApTracking; use crate::vm::errors::hint_errors::HintError; use crate::vm::vm_core::VirtualMachine; +use std::collections::HashMap; /* Implements hint: @@ -64,12 +63,9 @@ mod tests { }, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_relocate_segment() { let hint_code = hint_code::RELOCATE_SEGMENT; //Initialize vm @@ -92,7 +88,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_temporary_array() { let hint_code = hint_code::TEMPORARY_ARRAY; //Initialize vm diff --git a/src/hint_processor/builtin_hint_processor/set.rs b/src/hint_processor/builtin_hint_processor/set.rs index 79ae9984ad..330f1435d3 100644 --- a/src/hint_processor/builtin_hint_processor/set.rs +++ b/src/hint_processor/builtin_hint_processor/set.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -13,6 +11,7 @@ use crate::{ }; use felt::Felt; use num_traits::{One, ToPrimitive, Zero}; +use std::collections::HashMap; pub fn set_add( vm: &mut VirtualMachine, @@ -87,9 +86,7 @@ mod tests { }, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; const HINT_CODE: &str = "assert ids.elm_size > 0\nassert ids.set_ptr <= ids.set_end_ptr\nelm_list = memory.get_range(ids.elm_ptr, ids.elm_size)\nfor i in range(0, ids.set_end_ptr - ids.set_ptr, ids.elm_size):\n if memory.get_range(ids.set_ptr + i, ids.elm_size) == elm_list:\n ids.index = i // ids.elm_size\n ids.is_elm_in_set = 1\n break\nelse:\n ids.is_elm_in_set = 0"; @@ -133,7 +130,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn set_add_new_elem() { let (mut vm, ids_data) = init_vm_ids_data(None, None, None, None); assert_matches!(run_hint!(vm, ids_data, HINT_CODE), Ok(())); @@ -148,7 +144,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn set_add_already_exists() { let (mut vm, ids_data) = init_vm_ids_data(None, None, Some(1), Some(3)); assert_matches!(run_hint!(vm, ids_data, HINT_CODE), Ok(())); @@ -156,7 +151,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn elm_size_negative() { let (mut vm, ids_data) = init_vm_ids_data(None, Some(-2), None, None); assert_matches!( @@ -166,7 +160,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn elm_size_zero() { let (mut vm, ids_data) = init_vm_ids_data(None, Some(0), None, None); assert_matches!( @@ -177,7 +170,6 @@ mod tests { ); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn set_ptr_gt_set_end_ptr() { let (mut vm, ids_data) = init_vm_ids_data(Some((2, 3)), None, None, None); assert_matches!( diff --git a/src/hint_processor/builtin_hint_processor/sha256_utils.rs b/src/hint_processor/builtin_hint_processor/sha256_utils.rs index 096ba782d2..ee7f92a31f 100644 --- a/src/hint_processor/builtin_hint_processor/sha256_utils.rs +++ b/src/hint_processor/builtin_hint_processor/sha256_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -16,6 +14,7 @@ use felt::Felt; use generic_array::GenericArray; use num_traits::{One, Zero}; use sha2::compress256; +use std::collections::HashMap; use crate::hint_processor::hint_processor_definition::HintReference; @@ -130,11 +129,7 @@ mod tests { }; use assert_matches::assert_matches; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sha256_input_one() { let mut vm = vm_with_range_check!(); vm.segments = segments![((1, 1), 7)]; @@ -146,7 +141,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sha256_input_zero() { let mut vm = vm_with_range_check!(); vm.segments = segments![((1, 1), 3)]; @@ -158,7 +152,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sha256_ok() { let mut vm = vm_with_range_check!(); diff --git a/src/hint_processor/builtin_hint_processor/signature.rs b/src/hint_processor/builtin_hint_processor/signature.rs index 9aa273bba7..b02011b406 100644 --- a/src/hint_processor/builtin_hint_processor/signature.rs +++ b/src/hint_processor/builtin_hint_processor/signature.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, prelude::*}; - use num_integer::Integer; use crate::{ @@ -14,6 +12,7 @@ use crate::{ vm_core::VirtualMachine, }, }; +use std::collections::HashMap; pub fn verify_ecdsa_signature( vm: &mut VirtualMachine, @@ -67,12 +66,9 @@ mod tests { }, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_ecdsa_signature_valid() { let mut vm = vm!(); vm.builtin_runners = vec![( diff --git a/src/hint_processor/builtin_hint_processor/squash_dict_utils.rs b/src/hint_processor/builtin_hint_processor/squash_dict_utils.rs index c4bb1a0ebf..d12193e669 100644 --- a/src/hint_processor/builtin_hint_processor/squash_dict_utils.rs +++ b/src/hint_processor/builtin_hint_processor/squash_dict_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::{ @@ -21,6 +19,7 @@ use crate::{ use felt::Felt; use num_integer::Integer; use num_traits::{One, ToPrimitive, Zero}; +use std::collections::HashMap; fn get_access_indices( exec_scopes: &mut ExecutionScopes, @@ -317,9 +316,7 @@ mod tests { }; use assert_matches::assert_matches; use felt::felt_str; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; //Hint code as consts const SQUASH_DICT_INNER_FIRST_ITERATION : &str = "current_access_indices = sorted(access_indices[key])[::-1]\ncurrent_access_index = current_access_indices.pop()\nmemory[ids.range_check_ptr] = current_access_index"; @@ -335,7 +332,6 @@ mod tests { const SQUASH_DICT_INNER_NEXT_KEY: &str = "assert len(keys) > 0, 'No keys left but remaining_accesses > 0.'\nids.next_key = key = keys.pop()"; const SQUASH_DICT: &str ="dict_access_size = ids.DictAccess.SIZE\naddress = ids.dict_accesses.address_\nassert ids.ptr_diff % dict_access_size == 0, \\\n 'Accesses array size must be divisible by DictAccess.SIZE'\nn_accesses = ids.n_accesses\nif '__squash_dict_max_size' in globals():\n assert n_accesses <= __squash_dict_max_size, \\\n f'squash_dict() can only be used with n_accesses<={__squash_dict_max_size}. ' \\\n f'Got: n_accesses={n_accesses}.'\n# A map from key to the list of indices accessing it.\naccess_indices = {}\nfor i in range(n_accesses):\n key = memory[address + dict_access_size * i]\n access_indices.setdefault(key, []).append(i)\n# Descending list of keys.\nkeys = sorted(access_indices.keys(), reverse=True)\n# Are the keys used bigger than range_check bound.\nids.big_keys = 1 if keys[0] >= range_check_builtin.bound else 0\nids.first_key = key = keys.pop()"; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_first_iteration_valid() { let hint_code = SQUASH_DICT_INNER_FIRST_ITERATION; //Prepare scope variables @@ -372,7 +368,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_first_iteration_empty_accessed_indices() { let hint_code = SQUASH_DICT_INNER_FIRST_ITERATION; //Prepare scope variables @@ -398,7 +393,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_first_iteration_no_local_variables() { let hint_code = SQUASH_DICT_INNER_FIRST_ITERATION; //No scope variables @@ -418,7 +412,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn should_skip_loop_valid_empty_current_access_indices() { let hint_code = SQUASH_DICT_INNER_SKIP_LOOP; //Create vm @@ -437,7 +430,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn should_skip_loop_valid_non_empty_current_access_indices() { let hint_code = SQUASH_DICT_INNER_SKIP_LOOP; //Create vm @@ -456,7 +448,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_check_access_index_valid() { let hint_code = SQUASH_DICT_INNER_CHECK_ACCESS_INDEX; //Create vm @@ -495,7 +486,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_check_access_current_access_addr_empty() { let hint_code = SQUASH_DICT_INNER_CHECK_ACCESS_INDEX; //Create vm @@ -519,7 +509,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn should_continue_loop_valid_non_empty_current_access_indices() { let hint_code = SQUASH_DICT_INNER_CONTINUE_LOOP; //Create vm @@ -538,7 +527,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn should_continue_loop_valid_empty_current_access_indices() { let hint_code = SQUASH_DICT_INNER_CONTINUE_LOOP; //Create vm @@ -557,7 +545,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assert_current_indices_len_is_empty() { let hint_code = SQUASH_DICT_INNER_ASSERT_LEN; //Create vm @@ -573,7 +560,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assert_current_indices_len_is_empty_not() { let hint_code = SQUASH_DICT_INNER_ASSERT_LEN; //Create vm @@ -589,7 +575,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_uses_accesses_assert_valid() { let hint_code = SQUASH_DICT_INNER_USED_ACCESSES_ASSERT; //Prepare scope variables @@ -613,7 +598,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_uses_accesses_assert_wrong_used_access_number() { let hint_code = SQUASH_DICT_INNER_USED_ACCESSES_ASSERT; //Prepare scope variables @@ -643,7 +627,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_uses_accesses_assert_used_access_number_relocatable() { let hint_code = SQUASH_DICT_INNER_USED_ACCESSES_ASSERT; //Prepare scope variables @@ -669,7 +652,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_assert_len_keys_empty() { let hint_code = SQUASH_DICT_INNER_LEN_KEYS; //Create vm @@ -684,7 +666,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_assert_len_keys_not_empty() { let hint_code = SQUASH_DICT_INNER_LEN_KEYS; //Create vm @@ -699,7 +680,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_assert_len_keys_no_keys() { let hint_code = SQUASH_DICT_INNER_LEN_KEYS; //Create vm @@ -712,7 +692,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_next_key_keys_non_empty() { let hint_code = SQUASH_DICT_INNER_NEXT_KEY; //Create vm @@ -736,7 +715,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_inner_next_key_keys_empty() { let hint_code = SQUASH_DICT_INNER_NEXT_KEY; //Create vm @@ -755,7 +733,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_valid_one_key_dict_no_max_size() { //Dict = {1: (1,1), 1: (1,2)} let hint_code = SQUASH_DICT; @@ -787,12 +764,13 @@ mod tests { //Execute the hint assert_matches!(run_hint!(vm, ids_data, hint_code, &mut exec_scopes), Ok(())); //Check scope variables - let access_indices_scope_value: HashMap> = - HashMap::from([(Felt::one(), vec![Felt::zero(), Felt::one()])]); check_scope!( &exec_scopes, [ - ("access_indices", access_indices_scope_value), + ( + "access_indices", + HashMap::from([(Felt::one(), vec![Felt::zero(), Felt::one()])]) + ), ("keys", Vec::::new()), ("key", Felt::one()) ] @@ -802,7 +780,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_valid_two_key_dict_no_max_size() { //Dict = {1: (1,1), 1: (1,2), 2: (10,10), 2: (10,20)} let hint_code = SQUASH_DICT; @@ -840,14 +817,16 @@ mod tests { //Execute the hint assert_matches!(run_hint!(vm, ids_data, hint_code, &mut exec_scopes), Ok(())); //Check scope variables - let access_indices_scope_value: HashMap> = HashMap::from([ - (Felt::one(), vec![Felt::zero(), Felt::one()]), - (Felt::new(2), vec![Felt::new(2), Felt::new(3)]), - ]); check_scope!( &exec_scopes, [ - ("access_indices", access_indices_scope_value), + ( + "access_indices", + HashMap::from([ + (Felt::one(), vec![Felt::zero(), Felt::one()]), + (Felt::new(2), vec![Felt::new(2), Felt::new(3)]) + ]) + ), ("keys", vec![Felt::new(2)]), ("key", Felt::one()) ] @@ -859,7 +838,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_valid_one_key_dict_with_max_size() { //Dict = {1: (1,1), 1: (1,2)} let hint_code = SQUASH_DICT; @@ -892,12 +870,13 @@ mod tests { //Execute the hint assert_matches!(run_hint!(vm, ids_data, hint_code, &mut exec_scopes), Ok(())); //Check scope variables - let access_indices_scope_value: HashMap> = - HashMap::from([(Felt::one(), vec![Felt::zero(), Felt::one()])]); check_scope!( &exec_scopes, [ - ("access_indices", access_indices_scope_value), + ( + "access_indices", + HashMap::from([(Felt::one(), vec![Felt::zero(), Felt::one()])]) + ), ("keys", Vec::::new()), ("key", Felt::one()) ] @@ -907,7 +886,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_invalid_one_key_dict_with_max_size_exceeded() { //Dict = {1: (1,1), 1: (1,2)} let hint_code = SQUASH_DICT; @@ -948,7 +926,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_invalid_one_key_dict_bad_ptr_diff() { //Dict = {1: (1,1), 1: (1,2)} let hint_code = SQUASH_DICT; @@ -983,7 +960,6 @@ mod tests { ); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_invalid_one_key_dict_with_n_access_too_big() { //Dict = {1: (1,1), 1: (1,2)} let hint_code = SQUASH_DICT; @@ -1027,7 +1003,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict_valid_one_key_dict_no_max_size_big_keys() { //Dict = {(prime - 1): (1,1), (prime - 1): (1,2)} let hint_code = SQUASH_DICT; @@ -1071,13 +1046,10 @@ mod tests { //Execute the hint assert_matches!(run_hint!(vm, ids_data, hint_code, &mut exec_scopes), Ok(())); //Check scope variables - let access_indices_scope_value: HashMap> = HashMap::from([( - felt_str!( - "3618502761706184546546682988428055018603476541694452277432519575032261771265" - ), - vec![Felt::zero(), Felt::one()], - )]); - check_scope!(&exec_scopes, [("access_indices", access_indices_scope_value), ("keys", Vec::::new()), ("key", felt_str!("3618502761706184546546682988428055018603476541694452277432519575032261771265"))]); + check_scope!(&exec_scopes, [("access_indices", HashMap::from([( + felt_str!("3618502761706184546546682988428055018603476541694452277432519575032261771265"), + vec![Felt::zero(), Felt::one()] + )])), ("keys", Vec::::new()), ("key", felt_str!("3618502761706184546546682988428055018603476541694452277432519575032261771265"))]); //Check ids variables check_memory![ vm.segments.memory, diff --git a/src/hint_processor/builtin_hint_processor/uint256_utils.rs b/src/hint_processor/builtin_hint_processor/uint256_utils.rs index 155a497ec9..f358b78713 100644 --- a/src/hint_processor/builtin_hint_processor/uint256_utils.rs +++ b/src/hint_processor/builtin_hint_processor/uint256_utils.rs @@ -1,8 +1,3 @@ -use crate::stdlib::{ - collections::HashMap, - ops::{Shl, Shr}, - prelude::*, -}; use crate::{ hint_processor::builtin_hint_processor::hint_utils::{ get_integer_from_var_name, get_relocatable_from_var_name, insert_value_from_var_name, @@ -16,6 +11,10 @@ use crate::{ use felt::Felt; use num_integer::div_rem; use num_traits::{One, Signed, Zero}; +use std::{ + collections::HashMap, + ops::{Shl, Shr}, +}; /* Implements hint: %{ @@ -241,12 +240,9 @@ mod tests { }; use assert_matches::assert_matches; use felt::felt_str; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::any::Any; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_uint256_add_ok() { let hint_code = "sum_low = ids.a.low + ids.b.low\nids.carry_low = 1 if sum_low >= ids.SHIFT else 0\nsum_high = ids.a.high + ids.b.high + ids.carry_low\nids.carry_high = 1 if sum_high >= ids.SHIFT else 0"; let mut vm = vm_with_range_check!(); @@ -268,7 +264,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_uint256_add_fail_inserts() { let hint_code = "sum_low = ids.a.low + ids.b.low\nids.carry_low = 1 if sum_low >= ids.SHIFT else 0\nsum_high = ids.a.high + ids.b.high + ids.carry_low\nids.carry_high = 1 if sum_high >= ids.SHIFT else 0"; let mut vm = vm_with_range_check!(); @@ -301,7 +296,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_64_ok() { let hint_code = "ids.low = ids.a & ((1<<64) - 1)\nids.high = ids.a >> 64"; let mut vm = vm_with_range_check!(); @@ -323,7 +317,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_64_with_big_a() { let hint_code = "ids.low = ids.a & ((1<<64) - 1)\nids.high = ids.a >> 64"; let mut vm = vm_with_range_check!(); @@ -346,7 +339,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_split_64_memory_error() { let hint_code = "ids.low = ids.a & ((1<<64) - 1)\nids.high = ids.a >> 64"; let mut vm = vm_with_range_check!(); @@ -375,7 +367,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_uint256_sqrt_ok() { let hint_code = "from starkware.python.math_utils import isqrt\nn = (ids.n.high << 128) + ids.n.low\nroot = isqrt(n)\nassert 0 <= root < 2 ** 128\nids.root.low = root\nids.root.high = 0"; let mut vm = vm_with_range_check!(); @@ -396,7 +387,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_uint256_sqrt_assert_error() { let hint_code = "from starkware.python.math_utils import isqrt\nn = (ids.n.high << 128) + ids.n.low\nroot = isqrt(n)\nassert 0 <= root < 2 ** 128\nids.root.low = root\nids.root.high = 0"; let mut vm = vm_with_range_check!(); @@ -418,7 +408,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_uint256_invalid_memory_insert() { let hint_code = "from starkware.python.math_utils import isqrt\nn = (ids.n.high << 128) + ids.n.low\nroot = isqrt(n)\nassert 0 <= root < 2 ** 128\nids.root.low = root\nids.root.high = 0"; let mut vm = vm_with_range_check!(); @@ -444,7 +433,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_signed_nn_ok_result_one() { let hint_code = "memory[ap] = 1 if 0 <= (ids.a.high % PRIME) < 2 ** 127 else 0"; let mut vm = vm_with_range_check!(); @@ -468,7 +456,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_signed_nn_ok_result_zero() { let hint_code = "memory[ap] = 1 if 0 <= (ids.a.high % PRIME) < 2 ** 127 else 0"; let mut vm = vm_with_range_check!(); @@ -492,7 +479,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_signed_nn_ok_invalid_memory_insert() { let hint_code = "memory[ap] = 1 if 0 <= (ids.a.high % PRIME) < 2 ** 127 else 0"; let mut vm = vm_with_range_check!(); @@ -517,7 +503,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_unsigned_div_rem_ok() { let hint_code = "a = (ids.a.high << 128) + ids.a.low\ndiv = (ids.div.high << 128) + ids.div.low\nquotient, remainder = divmod(a, div)\n\nids.quotient.low = quotient & ((1 << 128) - 1)\nids.quotient.high = quotient >> 128\nids.remainder.low = remainder & ((1 << 128) - 1)\nids.remainder.high = remainder >> 128"; let mut vm = vm_with_range_check!(); @@ -542,7 +527,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_unsigned_div_rem_invalid_memory_insert() { let hint_code = "a = (ids.a.high << 128) + ids.a.low\ndiv = (ids.div.high << 128) + ids.div.low\nquotient, remainder = divmod(a, div)\n\nids.quotient.low = quotient & ((1 << 128) - 1)\nids.quotient.high = quotient >> 128\nids.remainder.low = remainder & ((1 << 128) - 1)\nids.remainder.high = remainder >> 128"; let mut vm = vm_with_range_check!(); diff --git a/src/hint_processor/builtin_hint_processor/usort.rs b/src/hint_processor/builtin_hint_processor/usort.rs index f85cbfa3a0..72c8b8d6be 100644 --- a/src/hint_processor/builtin_hint_processor/usort.rs +++ b/src/hint_processor/builtin_hint_processor/usort.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{any::Any, collections::HashMap, prelude::*}; - use crate::{ hint_processor::{ builtin_hint_processor::hint_utils::{ @@ -13,6 +11,7 @@ use crate::{ }; use felt::Felt; use num_traits::{ToPrimitive, Zero}; +use std::{any::Any, collections::HashMap}; pub fn usort_enter_scope(exec_scopes: &mut ExecutionScopes) -> Result<(), HintError> { if let Ok(usort_max_size) = exec_scopes.get::("usort_max_size") { @@ -100,7 +99,7 @@ pub fn verify_usort( let value = get_integer_from_var_name("value", vm, ids_data, ap_tracking)?.clone(); let mut positions = exec_scopes .get_mut_dict_ref::>("positions_dict")? - .remove(value.as_ref()) + .remove(&value) .ok_or(HintError::UnexpectedPositionsDictFail)?; positions.reverse(); exec_scopes.insert_value("positions", positions); @@ -155,18 +154,13 @@ mod tests { }; use assert_matches::assert_matches; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn usort_with_max_size() { let mut exec_scopes = scope![("usort_max_size", 1_u64)]; assert_matches!(usort_enter_scope(&mut exec_scopes), Ok(())); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn usort_out_of_range() { let mut vm = vm_with_range_check!(); vm.run_context.fp = 2; diff --git a/src/hint_processor/hint_processor_definition.rs b/src/hint_processor/hint_processor_definition.rs index 5ba8335953..8e6bf56a47 100644 --- a/src/hint_processor/hint_processor_definition.rs +++ b/src/hint_processor/hint_processor_definition.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{any::Any, boxed::Box, collections::HashMap, prelude::*}; - use crate::any_box; use crate::serde::deserialize_program::ApTracking; use crate::serde::deserialize_program::OffsetValue; @@ -9,6 +7,8 @@ use crate::types::instruction::Register; use crate::vm::errors::hint_errors::HintError; use crate::vm::errors::vm_errors::VirtualMachineError; use crate::vm::vm_core::VirtualMachine; +use std::any::Any; +use std::collections::HashMap; use super::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData; use felt::Felt; diff --git a/src/hint_processor/hint_processor_utils.rs b/src/hint_processor/hint_processor_utils.rs index 894e72be5c..0a846e8b4a 100644 --- a/src/hint_processor/hint_processor_utils.rs +++ b/src/hint_processor/hint_processor_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::borrow::Cow; - use crate::{ serde::deserialize_program::{ApTracking, OffsetValue}, types::{ @@ -9,6 +7,7 @@ use crate::{ }, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; +use std::borrow::Cow; use super::hint_processor_definition::HintReference; use felt::Felt; @@ -178,7 +177,6 @@ fn get_offset_value_reference( #[cfg(test)] mod tests { use super::*; - use crate::stdlib::collections::HashMap; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ relocatable, @@ -188,12 +186,9 @@ mod tests { }, }; use assert_matches::assert_matches; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::collections::HashMap; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_integer_from_reference_with_immediate_value() { let mut vm = vm!(); vm.segments = segments![((1, 0), 0)]; @@ -209,7 +204,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_offset_value_reference_valid() { let mut vm = vm!(); vm.segments = segments![((1, 0), 0)]; @@ -223,7 +217,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_offset_value_reference_invalid() { let mut vm = vm!(); vm.segments = segments![((1, 0), 0)]; @@ -237,7 +230,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_ptr_from_reference_short_path() { let mut vm = vm!(); vm.segments = segments![((1, 0), (2, 0))]; @@ -253,7 +245,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_ptr_from_reference_with_dereference() { let mut vm = vm!(); vm.segments = segments![((1, 0), (3, 0))]; @@ -269,7 +260,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_ptr_from_reference_with_dereference_and_imm() { let mut vm = vm!(); vm.segments = segments![((1, 0), (4, 0))]; @@ -283,7 +273,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_addr_from_reference_no_regiter_in_reference() { let mut vm = vm!(); vm.segments = segments![((1, 0), (4, 0))]; @@ -294,7 +283,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_addr_from_reference_failed_to_get_ids() { let mut vm = vm!(); vm.segments = segments![((1, 0), 4)]; @@ -309,7 +297,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn tracking_correction_valid() { let mut ref_ap_tracking = ApTracking::new(); ref_ap_tracking.group = 1; @@ -323,7 +310,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn tracking_correction_invalid_group() { let mut ref_ap_tracking = ApTracking::new(); ref_ap_tracking.group = 1; @@ -339,7 +325,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_maybe_relocatable_from_reference_valid() { let mut vm = vm!(); vm.segments = segments![((1, 0), (0, 0))]; @@ -351,7 +336,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_maybe_relocatable_from_reference_invalid() { let mut vm = vm!(); vm.segments.memory = Memory::new(); diff --git a/src/lib.rs b/src/lib.rs index 021908a50a..6bfda22c3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,52 +7,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(warnings)] -#![cfg_attr(any(target_arch = "wasm32", not(feature = "std")), no_std)] - -#[cfg(feature = "std")] -include!("./with_std.rs"); -#[cfg(all(not(feature = "std"), feature = "alloc"))] -include!("./with_alloc.rs"); -#[cfg(not(feature = "std"))] -include!("./without_std.rs"); - -mod stdlib { - pub mod collections { - #[cfg(all(not(feature = "std"), feature = "alloc"))] - pub use crate::with_alloc::collections::*; - #[cfg(feature = "std")] - pub use crate::with_std::collections::*; - } - - pub mod borrow { - #[cfg(all(not(feature = "std"), feature = "alloc"))] - pub use crate::with_alloc::borrow::*; - #[cfg(feature = "std")] - pub use crate::with_std::borrow::*; - #[cfg(not(feature = "std"))] - pub use crate::without_std::borrow::*; - } - - pub mod prelude { - pub use crate::stdlib::{ - borrow::ToOwned, - boxed::Box, - clone::Clone, - cmp::{Eq, PartialEq, Reverse}, - iter::IntoIterator, - string::{String, ToString}, - vec::Vec, - }; - } - - #[cfg(all(not(feature = "std"), feature = "alloc"))] - pub use crate::with_alloc::*; - #[cfg(feature = "std")] - pub use crate::with_std::*; - #[cfg(not(feature = "std"))] - pub use crate::without_std::*; -} - pub mod cairo_run; pub mod hint_processor; pub mod math_utils; @@ -60,6 +14,3 @@ pub mod serde; pub mod types; pub mod utils; pub mod vm; - -#[cfg(test)] -mod tests; diff --git a/cairo-vm-cli/src/main.rs b/src/main.rs similarity index 54% rename from cairo-vm-cli/src/main.rs rename to src/main.rs index f9b05f96db..363dc933aa 100644 --- a/cairo-vm-cli/src/main.rs +++ b/src/main.rs @@ -1,14 +1,11 @@ #![deny(warnings)] -use bincode::enc::write::Writer; -use cairo_vm::cairo_run::{self, EncodeTraceError}; +use cairo_vm::cairo_run; use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; use cairo_vm::vm::errors::cairo_run_errors::CairoRunError; +use cairo_vm::vm::errors::runner_errors::RunnerError; use cairo_vm::vm::errors::trace_errors::TraceError; -use cairo_vm::vm::errors::vm_errors::VirtualMachineError; use clap::{Parser, ValueHint}; -use std::io::{self, Write}; use std::path::PathBuf; -use thiserror::Error; #[cfg(feature = "with_mimalloc")] use mimalloc::MiMalloc; @@ -46,98 +43,43 @@ fn validate_layout(value: &str) -> Result<(), String> { } } -#[derive(Debug, Error)] -enum Error { - #[error("Failed to interact with the file system")] - IO(#[from] std::io::Error), - #[error("The cairo program execution failed")] - Runner(#[from] CairoRunError), - #[error(transparent)] - EncodeTrace(#[from] EncodeTraceError), - #[error(transparent)] - VirtualMachine(#[from] VirtualMachineError), -} - -struct FileWriter { - buf_writer: io::BufWriter, - bytes_written: usize, -} - -impl Writer for FileWriter { - fn write(&mut self, bytes: &[u8]) -> Result<(), bincode::error::EncodeError> { - self.buf_writer - .write_all(bytes) - .map_err(|e| bincode::error::EncodeError::Io { - inner: e, - index: self.bytes_written, - })?; - - self.bytes_written += bytes.len(); - - Ok(()) - } -} - -impl FileWriter { - fn new(buf_writer: io::BufWriter) -> Self { - Self { - buf_writer, - bytes_written: 0, - } - } - - fn flush(&mut self) -> io::Result<()> { - self.buf_writer.flush() - } -} - -fn main() -> Result<(), Error> { +fn main() -> Result<(), CairoRunError> { let args = Args::parse(); let trace_enabled = args.trace_file.is_some(); let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { entrypoint: &args.entrypoint, trace_enabled, + print_output: args.print_output, layout: &args.layout, proof_mode: args.proof_mode, secure_run: args.secure_run, }; - - let program_content = std::fs::read(args.filename).map_err(|e| Error::IO(e))?; - - let (cairo_runner, mut vm) = - match cairo_run::cairo_run(&program_content, &cairo_run_config, &mut hint_executor) { + let cairo_runner = + match cairo_run::cairo_run(&args.filename, &cairo_run_config, &mut hint_executor) { Ok(runner) => runner, Err(error) => { println!("{error}"); - return Err(Error::Runner(error)); + return Err(error); } }; - if args.print_output { - let mut output_buffer = "Program Output:\n".to_string(); - vm.write_output(&mut output_buffer)?; - print!("{output_buffer}"); - } - if let Some(trace_path) = args.trace_file { let relocated_trace = cairo_runner .relocated_trace + .as_ref() .ok_or(CairoRunError::Trace(TraceError::TraceNotEnabled))?; - - let trace_file = std::fs::File::create(trace_path)?; - let mut trace_writer = FileWriter::new(io::BufWriter::new(trace_file)); - - cairo_run::write_encoded_trace(&relocated_trace, &mut trace_writer)?; - trace_writer.flush()?; + match cairo_run::write_binary_trace(relocated_trace, &trace_path) { + Ok(()) => (), + Err(_e) => return Err(CairoRunError::Runner(RunnerError::WriteFail)), + } } if let Some(memory_path) = args.memory_file { - let memory_file = std::fs::File::create(memory_path)?; - let mut memory_writer = FileWriter::new(io::BufWriter::new(memory_file)); - - cairo_run::write_encoded_memory(&cairo_runner.relocated_memory, &mut memory_writer)?; - memory_writer.flush()?; + match cairo_run::write_binary_memory(&cairo_runner.relocated_memory, &memory_path) { + Ok(()) => (), + Err(_e) => return Err(CairoRunError::Runner(RunnerError::WriteFail)), + } } Ok(()) diff --git a/src/math_utils.rs b/src/math_utils.rs index 0efd4293b5..70633c449a 100644 --- a/src/math_utils.rs +++ b/src/math_utils.rs @@ -1,9 +1,9 @@ -use crate::stdlib::ops::Shr; use crate::types::errors::math_errors::MathError; use felt::Felt; use num_bigint::{BigInt, BigUint}; use num_integer::Integer; use num_traits::{One, Signed, Zero}; +use std::ops::Shr; ///Returns the integer square root of the nonnegative integer n. ///This is the floor of the exact square root of n. @@ -165,11 +165,7 @@ mod tests { use assert_matches::assert_matches; use num_traits::Num; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_divmod_a() { let a = bigint_str!( "11260647941622813594563746375280766662237311019551239924981511729608487775604310196863705127454617186486639011517352066501847110680463498585797912894788" @@ -190,7 +186,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_divmod_b() { let a = bigint_str!( "29642372811668969595956851264770043260610851505766181624574941701711520154703788233010819515917136995474951116158286220089597404329949295479559895970988" @@ -211,7 +206,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_divmod_c() { let a = bigint_str!( "1208267356464811040667664150251401430616174694388968865551115897173431833224432165394286799069453655049199580362994484548890574931604445970825506916876" @@ -232,7 +226,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_safe_div() { let x = Felt::new(26); let y = Felt::new(13); @@ -240,7 +233,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_safe_div_non_divisor() { let x = Felt::new(25); let y = Felt::new(4); @@ -253,7 +245,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_safe_div_by_zero() { let x = Felt::new(25); let y = Felt::zero(); @@ -262,13 +253,11 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_safe_div_usize() { assert_matches!(safe_div_usize(26, 13), Ok(2)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_safe_div_usize_non_divisor() { assert_matches!( safe_div_usize(25, 4), @@ -277,13 +266,11 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_safe_div_usize_by_zero() { assert_matches!(safe_div_usize(25, 0), Err(MathError::DividedByZero)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_line_slope_for_valid_points() { let point_a = ( bigint_str!( @@ -311,7 +298,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_double_slope_for_valid_point_a() { let point = ( bigint_str!( @@ -332,7 +318,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_double_slope_for_valid_point_b() { let point = ( bigint_str!( @@ -353,7 +338,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_ec_double_for_valid_point_a() { let point = ( bigint_str!( @@ -379,7 +363,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_ec_double_for_valid_point_b() { let point = ( bigint_str!( @@ -405,7 +388,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_ec_double_for_valid_point_c() { let point = ( bigint_str!( @@ -431,7 +413,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_ec_add_for_valid_points_a() { let point_a = ( bigint_str!( @@ -464,7 +445,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_ec_add_for_valid_points_b() { let point_a = ( bigint_str!( @@ -497,7 +477,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_ec_add_for_valid_points_c() { let point_a = ( bigint_str!( @@ -530,21 +509,18 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_isqrt_a() { let n = biguint!(81); assert_matches!(isqrt(&n), Ok(x) if x == biguint!(9)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_isqrt_b() { let n = biguint_str!("4573659632505831259480"); assert_matches!(isqrt(&n.pow(2_u32)), Ok(num) if num == n); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_isqrt_c() { let n = biguint_str!( "3618502788666131213697322783095070105623107215331596699973092056135872020481" @@ -553,7 +529,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn calculate_isqrt_zero() { let n = BigUint::zero(); assert_matches!(isqrt(&n), Ok(inner) if inner.is_zero()); diff --git a/src/serde/deserialize_program.rs b/src/serde/deserialize_program.rs index 332964b5ec..bfe1f6deb6 100644 --- a/src/serde/deserialize_program.rs +++ b/src/serde/deserialize_program.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{collections::HashMap, fmt, prelude::*}; - use crate::{ serde::deserialize_utils, types::{ @@ -15,6 +13,7 @@ use felt::{Felt, PRIME_STR}; use num_traits::Num; use serde::{de, de::MapAccess, de::SeqAccess, Deserialize, Deserializer, Serialize}; use serde_json::Number; +use std::{collections::HashMap, fmt, io::Read}; // This enum is used to deserialize program builtins into &str and catch non-valid names #[derive(Deserialize, Debug, PartialEq)] @@ -330,22 +329,17 @@ pub fn deserialize_value_address<'de, D: Deserializer<'de>>( d.deserialize_str(ValueAddressVisitor) } -pub fn deserialize_program_json(reader: &[u8]) -> Result { - let program_json = serde_json::from_slice(reader)?; +pub fn deserialize_program_json(reader: impl Read) -> Result { + let program_json = serde_json::from_reader(reader)?; Ok(program_json) } -pub fn deserialize_and_parse_program( - reader: &[u8], + +pub fn deserialize_program( + reader: impl Read, entrypoint: Option<&str>, ) -> Result { let program_json: ProgramJson = deserialize_program_json(reader)?; - parse_program_json(program_json, entrypoint) -} -pub fn parse_program_json( - program_json: ProgramJson, - entrypoint: Option<&str>, -) -> Result { if PRIME_STR != program_json.prime { return Err(ProgramError::PrimeDiffers(program_json.prime)); } @@ -385,8 +379,8 @@ pub fn parse_program_json( let value = value .value .clone() - .ok_or_else(|| ProgramError::ConstWithoutValue(key.clone()))?; - constants.insert(key.clone(), value); + .ok_or_else(|| ProgramError::ConstWithoutValue(key.to_owned()))?; + constants.insert(key.to_owned(), value); } } @@ -415,12 +409,9 @@ mod tests { use assert_matches::assert_matches; use felt::felt_str; use num_traits::Zero; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::{fs::File, io::BufReader}; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_bigint_from_string_json_gives_error() { let invalid_even_length_hex_json = r#" { @@ -445,7 +436,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_bigint_invalid_char_error() { let invalid_char = r#" { @@ -458,7 +448,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_bigint_no_prefix_error() { let no_prefix = r#" { @@ -472,7 +461,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_from_string_json() { let valid_json = r#" { @@ -687,12 +675,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_json_from_json_file_a() { // Open json file with (valid) even length encoded hex - let reader = include_bytes!("../../cairo_programs/manually_compiled/valid_program_a.json"); + let file = File::open("cairo_programs/manually_compiled/valid_program_a.json").unwrap(); + let mut reader = BufReader::new(file); - let program_json: ProgramJson = serde_json::from_slice(reader).unwrap(); + let program_json: ProgramJson = serde_json::from_reader(&mut reader).unwrap(); assert_eq!( program_json.prime, @@ -704,12 +692,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_json_from_json_file_b() { // Open json file with (valid) odd length encoded hex - let reader = include_bytes!("../../cairo_programs/manually_compiled/valid_program_b.json"); + let file = File::open("cairo_programs/manually_compiled/valid_program_b.json").unwrap(); + let mut reader = BufReader::new(file); - let program_json: ProgramJson = serde_json::from_slice(reader).unwrap(); + let program_json: ProgramJson = serde_json::from_reader(&mut reader).unwrap(); let builtins: Vec = vec![BuiltinName::output, BuiltinName::range_check]; assert_eq!( @@ -722,32 +710,33 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_json_from_json_file_gives_error() { // Open json file with (invalid) even length encoded hex - let reader = - include_bytes!("../../cairo_programs/manually_compiled/invalid_even_length_hex.json"); + let even_length_file = + File::open("cairo_programs/manually_compiled/invalid_even_length_hex.json").unwrap(); + let mut reader = BufReader::new(even_length_file); - let even_result: Result = serde_json::from_slice(reader); + let even_result: Result = serde_json::from_reader(&mut reader); assert!(even_result.is_err()); // Open json file with (invalid) odd length encoded hex - let reader = - include_bytes!("../../cairo_programs/manually_compiled/invalid_odd_length_hex.json"); + let odd_length_file = + File::open("cairo_programs/manually_compiled/invalid_odd_length_hex.json").unwrap(); + let mut reader = BufReader::new(odd_length_file); - let odd_result: Result = serde_json::from_slice(reader); + let odd_result: Result = serde_json::from_reader(&mut reader); assert!(odd_result.is_err()); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_missing_entrypoint_gives_error() { - let reader = include_bytes!("../../cairo_programs/manually_compiled/valid_program_a.json"); + let even_length_file = + File::open("cairo_programs/manually_compiled/valid_program_a.json").unwrap(); + let reader = BufReader::new(even_length_file); - let deserialization_result = - deserialize_and_parse_program(reader, Some("missing_function")); + let deserialization_result = deserialize_program(reader, Some("missing_function")); assert!(deserialization_result.is_err()); assert_matches!( deserialization_result, @@ -756,12 +745,13 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_test() { - let reader = include_bytes!("../../cairo_programs/manually_compiled/valid_program_a.json"); + let even_length_file = + File::open("cairo_programs/manually_compiled/valid_program_a.json").unwrap(); + let reader = BufReader::new(even_length_file); - let program: Program = deserialize_and_parse_program(reader, Some("main")) - .expect("Failed to deserialize program"); + let program: Program = + deserialize_program(reader, Some("main")).expect("Failed to deserialize program"); let builtins: Vec = Vec::new(); let data: Vec = vec![ @@ -818,12 +808,13 @@ mod tests { /// Deserialize a program without an entrypoint. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_without_entrypoint_test() { - let reader = include_bytes!("../../cairo_programs/manually_compiled/valid_program_a.json"); + let even_length_file = + File::open("cairo_programs/manually_compiled/valid_program_a.json").unwrap(); + let reader = BufReader::new(even_length_file); let program: Program = - deserialize_and_parse_program(reader, None).expect("Failed to deserialize program"); + deserialize_program(reader, None).expect("Failed to deserialize program"); let builtins: Vec = Vec::new(); let data: Vec = vec![ @@ -879,12 +870,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_constant() { - let reader = - include_bytes!("../../cairo_programs/manually_compiled/deserialize_constant_test.json"); + let file = + File::open("cairo_programs/manually_compiled/deserialize_constant_test.json").unwrap(); + let mut reader = BufReader::new(file); - let program_json: ProgramJson = serde_json::from_slice(reader).unwrap(); + let program_json: ProgramJson = serde_json::from_reader(&mut reader).unwrap(); let mut identifiers: HashMap = HashMap::new(); identifiers.insert( @@ -973,7 +964,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn value_address_no_hint_reference_default_test() { let valid_json = r#" { @@ -1020,7 +1010,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_attributes_test() { let valid_json = r#" { @@ -1114,7 +1103,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_instruction_locations_test_no_parent() { let valid_json = r#" { @@ -1223,7 +1211,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_instruction_locations_test_with_parent() { let valid_json = r#" { @@ -1324,11 +1311,11 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_with_type_definition() { - let reader = include_bytes!("../../cairo_programs/uint256_integration_tests.json"); + let file = File::open("cairo_programs/uint256_integration_tests.json").unwrap(); + let reader = BufReader::new(file); - let program_json: ProgramJson = serde_json::from_slice(reader).unwrap(); + let program_json: ProgramJson = serde_json::from_reader(reader).unwrap(); assert_eq!( program_json.identifiers["starkware.cairo.common.alloc.alloc.Return"] diff --git a/src/serde/deserialize_utils.rs b/src/serde/deserialize_utils.rs index e4c659b901..22225dcdd3 100644 --- a/src/serde/deserialize_utils.rs +++ b/src/serde/deserialize_utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{fmt, num::ParseIntError, prelude::*, str::FromStr}; - use crate::{ serde::deserialize_program::{OffsetValue, ValueAddress}, types::instruction::Register, @@ -19,6 +17,7 @@ use nom::{ }; use num_integer::Integer; use parse_hyperlinks::take_until_unbalanced; +use std::{fmt, num::ParseIntError, str::FromStr}; #[derive(Debug, PartialEq, Eq)] pub enum ReferenceParseError { @@ -175,9 +174,9 @@ pub fn parse_value(input: &str) -> IResult<&str, ValueAddress> { tuple((tag(", "), take_till(|c: char| c == '*')))(second_arg)?; let type_: String = if let Some(indirections) = indirection_level.get(1..) { - struct_.to_string() + indirections + struct_.to_owned() + indirections } else { - struct_.to_string() + struct_.to_owned() }; let fst_offset = fst_offset.unwrap_or(OffsetValue::Value(0)); @@ -215,14 +214,9 @@ pub fn parse_value(input: &str) -> IResult<&str, ValueAddress> { #[cfg(test)] mod tests { use super::*; - use crate::stdlib::string::ToString; use num_traits::{One, Zero}; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn outer_brackets_test() { let deref_value = "[cast([fp])]"; let parsed_deref = outer_brackets(deref_value); @@ -234,7 +228,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn take_cast_test() { let value = "cast([fp + (-1)], felt*)"; let parsed = take_cast(value); @@ -242,7 +235,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn take_cast_first_arg_test() { let value = "cast([fp + (-1)] + (-1), felt*)"; let parsed = take_cast_first_arg(value); @@ -251,7 +243,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_register_test() { let value = "fp + (-1)"; let parsed = register(value); @@ -260,7 +251,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_offset_test() { let value_1 = " + (-1)"; let parsed_1 = offset(value_1); @@ -276,7 +266,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_register_and_offset_test() { let value_1 = "fp + 1"; let parsed_1 = register_and_offset(value_1); @@ -290,7 +279,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_inner_dereference_test() { let value = "[fp + (-1)] + 2"; let parsed = inner_dereference(value); @@ -302,7 +290,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_no_inner_dereference_test() { let value = "ap + 3"; let parsed = no_inner_dereference(value); @@ -314,7 +301,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_inner_dereference_test() { let value = "[cast([fp + (-1)] + 2, felt*)]"; let parsed = parse_value(value); @@ -334,7 +320,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_no_inner_dereference_test() { let value = "cast(ap + 2, felt*)"; let parsed = parse_value(value); @@ -354,7 +339,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_no_register_test() { let value = "cast(825323, felt*)"; let parsed = parse_value(value); @@ -373,7 +357,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_no_inner_deref_and_two_offsets() { let value = "[cast(ap - 0 + (-1), felt*)]"; let parsed = parse_value(value); @@ -393,7 +376,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_inner_deref_and_offset2() { let value = "[cast([ap] + 1, __main__.felt*)]"; let parsed = parse_value(value); @@ -413,7 +395,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_inner_deref_and_immediate() { let value = "[cast([ap] + 1, felt)]"; let parsed = parse_value(value); @@ -433,7 +414,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_inner_deref_to_pointer() { let value = "[cast([ap + 1] + 1, felt*)]"; let parsed = parse_value(value); @@ -453,7 +433,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_2_inner_deref() { let value = "[cast([ap] + [fp + 1], __main__.felt*)]"; let parsed = parse_value(value); @@ -473,7 +452,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_2_inner_dereferences() { let value = "[cast([ap + 1] + [fp + 1], __main__.felt*)]"; let parsed = parse_value(value); @@ -493,7 +471,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_no_reference() { let value = "cast(825323, felt)"; let parsed = parse_value(value); @@ -513,7 +490,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_one_reference() { let value = "[cast([ap] + 1, starkware.cairo.common.cairo_secp.ec.EcPoint*)]"; let parsed = parse_value(value); @@ -533,7 +509,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_doble_reference() { let value = "[cast([ap] + 1, starkware.cairo.common.cairo_secp.ec.EcPoint**)]"; let parsed = parse_value(value); @@ -553,7 +528,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_to_felt_with_doble_reference() { let value = "[cast([ap] + [ap], felt)]"; let parsed = parse_value(value); @@ -573,7 +547,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_to_felt_with_doble_reference_and_offsets() { let value = "[cast([ap + 1] + [ap + 2], felt)]"; let parsed = parse_value(value); diff --git a/src/tests/cairo_run_test.rs b/src/tests/cairo_run_test.rs deleted file mode 100644 index 8930d3c7aa..0000000000 --- a/src/tests/cairo_run_test.rs +++ /dev/null @@ -1,1402 +0,0 @@ -use crate::stdlib::prelude::*; - -use crate::cairo_run::{self, CairoRunConfig}; -use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen_test::*; - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn fibonacci() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/fibonacci.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn array_sum() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/array_sum.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn big_struct() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/big_struct.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn call_function_assign_param_by_name() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/call_function_assign_param_by_name.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn function_return() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/function_return.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn function_return_if_print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/function_return_if_print.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn function_return_to_variable() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/function_return_to_variable.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn if_and_prime() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/if_and_prime.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn if_in_function() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/if_in_function.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn if_list() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/if_list.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn jmp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/jmp.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn jmp_if_condition() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/jmp_if_condition.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn pointers() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/pointers.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/print.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn program_return() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/return.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn reversed_register_instructions() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/reversed_register_instructions.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn simple_print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/simple_print.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn test_addition_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/test_addition_if.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn test_reverse_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/test_reverse_if.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn test_subtraction_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/test_subtraction_if.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn use_imported_module() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/use_imported_module.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn bitwise_output() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bitwise_output.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn bitwise_recursion() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bitwise_recursion.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/integration.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn integration_with_alloc_locals() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/integration_with_alloc_locals.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn compare_arrays() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/compare_arrays.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn compare_greater_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/compare_greater_array.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn compare_lesser_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/compare_lesser_array.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn assert_le_felt_hint() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_le_felt_hint.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn assert_250_bit_element_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_250_bit_element_array.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn abs_value_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/abs_value_array.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn compare_different_arrays() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/compare_different_arrays.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn assert_nn() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_nn.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn sqrt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/sqrt.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn assert_not_zero() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_not_zero.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn split_int() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/split_int.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn split_int_big() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/split_int_big.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn split_felt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/split_felt.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn math_cmp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/math_cmp.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn unsigned_div_rem() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/unsigned_div_rem.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn signed_div_rem() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/signed_div_rem.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn assert_lt_felt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_lt_felt.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn memcpy_test() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/memcpy_test.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn memset() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/memset.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn pow() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/pow.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn dict() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn dict_update() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict_update.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn uint256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/uint256.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn find_element() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/find_element.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn search_sorted_lower() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/search_sorted_lower.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn usort() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/usort.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn squash_dict() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/squash_dict.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn dict_squash() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict_squash.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn set_add() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/set_add.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn secp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/secp.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn signature() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/signature.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn secp_ec() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/secp_ec.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn blake2s_hello_world_hash() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/blake2s_hello_world_hash.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn finalize_blake2s() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/finalize_blake2s.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn unsafe_keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/unsafe_keccak.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn blake2s_felts() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/blake2s_felts.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn unsafe_keccak_finalize() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/unsafe_keccak_finalize.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn keccak_add_uint256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/keccak_add_uint256.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/_keccak.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn keccak_copy_inputs() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/keccak_copy_inputs.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_finalize_keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/cairo_finalize_keccak.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn operations_with_data_structures() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/operations_with_data_structures.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn sha256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/sha256.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn math_cmp_and_pow_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/math_cmp_and_pow_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn uint256_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/uint256_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn set_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/set_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn memory_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/memory_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn dict_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn secp_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/secp_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn keccak_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/keccak_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn blake2s_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/blake2s_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn relocate_segments() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/relocate_segments.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn dict_store_cast_ptr() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict_store_cast_ptr.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn common_signature() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/common_signature.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn bad_usort() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/bad_usort.json"); - let expected_error_message = "unexpected verify multiplicity fail: positions length != 0"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn bad_dict_new() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/bad_dict_new.json"); - let expected_error_message = "Dict Error: Tried to create a dict whithout an initial dict"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn bad_dict_update() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/bad_dict_update.json"); - let expected_error_message = - "Dict Error: Got the wrong value for dict_update, expected value: 3, got: 5 for key: 2"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn error_msg_attr() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/error_msg_attr.json"); - let expected_error_message = "SafeUint256: addition overflow"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn error_msg_attr_tempvar() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/error_msg_attr_tempvar.json"); - - #[cfg(feature = "std")] - let expected_error_message = "Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n assert x = 2;\n ^***********^\n"; - #[cfg(all(not(feature = "std"), feature = "alloc"))] - let expected_error_message = "Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn error_msg_attr_struct() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/error_msg_attr_struct.json"); - let expected_error_message = "Error message: Cats cannot have more than nine lives: {cat} (Cannot evaluate ap-based or complex references: ['cat'])"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); -} diff --git a/src/tests/mod.rs b/src/tests/mod.rs deleted file mode 100644 index 47c3be4d51..0000000000 --- a/src/tests/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod bitwise_test; -mod cairo_run_test; -mod pedersen_test; -mod struct_test; - -#[cfg(feature = "skip_next_instruction_hint")] -mod skip_instruction_test; diff --git a/src/types/errors/math_errors.rs b/src/types/errors/math_errors.rs index 9350e0eb74..bb7accb49a 100644 --- a/src/types/errors/math_errors.rs +++ b/src/types/errors/math_errors.rs @@ -1,10 +1,6 @@ use felt::Felt; use num_bigint::{BigInt, BigUint}; - -#[cfg(feature = "std")] use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; use crate::types::relocatable::{MaybeRelocatable, Relocatable}; diff --git a/src/types/errors/program_errors.rs b/src/types/errors/program_errors.rs index 9a8437e7d5..c74d7456d3 100644 --- a/src/types/errors/program_errors.rs +++ b/src/types/errors/program_errors.rs @@ -1,17 +1,11 @@ -use crate::stdlib::prelude::*; - -#[cfg(feature = "std")] -use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; - use felt::PRIME_STR; +use std::io; +use thiserror::Error; #[derive(Debug, Error)] pub enum ProgramError { - #[cfg(feature = "std")] #[error(transparent)] - IO(#[from] std::io::Error), + IO(#[from] io::Error), #[error(transparent)] Parse(#[from] serde_json::Error), #[error("Entrypoint {0} not found")] @@ -26,11 +20,7 @@ pub enum ProgramError { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn format_entrypoint_not_found_error() { let error = ProgramError::EntrypointNotFound(String::from("my_function")); let formatted_error = format!("{error}"); diff --git a/src/types/exec_scope.rs b/src/types/exec_scope.rs index 941525e26b..1721d02f17 100644 --- a/src/types/exec_scope.rs +++ b/src/types/exec_scope.rs @@ -1,11 +1,10 @@ -use crate::stdlib::{any::Any, cell::RefCell, collections::HashMap, prelude::*, rc::Rc}; use crate::{ any_box, hint_processor::builtin_hint_processor::dict_manager::DictManager, vm::errors::{exec_scope_errors::ExecScopeError, hint_errors::HintError}, }; +use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc}; -#[derive(Debug)] pub struct ExecutionScopes { pub data: Vec>>, } @@ -191,18 +190,13 @@ mod tests { use felt::Felt; use num_traits::One; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_execution_scopes() { let scopes = ExecutionScopes::new(); assert_eq!(scopes.data.len(), 1); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_local_variables_test() { let var_name = String::from("a"); let var_value: Box = Box::new(Felt::new(2)); @@ -223,7 +217,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn enter_new_scope_test() { let var_name = String::from("a"); let var_value: Box = Box::new(Felt::new(2_i32)); @@ -266,7 +259,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn exit_scope_test() { let var_name = String::from("a"); let var_value: Box = Box::new(Felt::new(2)); @@ -303,7 +295,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assign_local_variable_test() { let var_value: Box = Box::new(Felt::new(2)); @@ -324,7 +315,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn re_assign_local_variable_test() { let var_name = String::from("a"); let var_value: Box = Box::new(Felt::new(2)); @@ -350,7 +340,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn delete_local_variable_test() { let var_name = String::from("a"); let var_value: Box = Box::new(Felt::new(2)); @@ -373,7 +362,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn exit_main_scope_gives_error_test() { let mut scopes = ExecutionScopes::new(); @@ -381,7 +369,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_listu64_test() { let list_u64: Box = Box::new(vec![20_u64, 18_u64]); @@ -403,7 +390,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_u64_test() { let u64: Box = Box::new(9_u64); @@ -429,7 +415,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_mut_int_ref_test() { let bigint: Box = Box::new(Felt::new(12)); @@ -443,7 +428,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_any_boxed_test() { let list_u64: Box = Box::new(vec![20_u64, 18_u64]); diff --git a/src/types/instance_definitions/bitwise_instance_def.rs b/src/types/instance_definitions/bitwise_instance_def.rs index 8cea97d21b..0f1a6c5b04 100644 --- a/src/types/instance_definitions/bitwise_instance_def.rs +++ b/src/types/instance_definitions/bitwise_instance_def.rs @@ -35,25 +35,19 @@ impl BitwiseInstanceDef { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_units_per_builtin() { let builtin_instance = BitwiseInstanceDef::default(); assert_eq!(builtin_instance._range_check_units_per_builtin(), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_builtin() { let builtin_instance = BitwiseInstanceDef::default(); assert_eq!(builtin_instance._cells_per_builtin(), 5); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_new() { let builtin_instance = BitwiseInstanceDef { ratio: 8, @@ -63,7 +57,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_default() { let builtin_instance = BitwiseInstanceDef { ratio: 256, diff --git a/src/types/instance_definitions/builtins_instance_def.rs b/src/types/instance_definitions/builtins_instance_def.rs index 95be8bb98f..c29ee400b2 100644 --- a/src/types/instance_definitions/builtins_instance_def.rs +++ b/src/types/instance_definitions/builtins_instance_def.rs @@ -105,11 +105,7 @@ impl BuiltinsInstanceDef { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_plain() { let builtins = BuiltinsInstanceDef::plain(); assert!(!builtins.output); @@ -121,7 +117,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_small() { let builtins = BuiltinsInstanceDef::small(); assert!(builtins.output); @@ -133,7 +128,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_dex() { let builtins = BuiltinsInstanceDef::dex(); assert!(builtins.output); @@ -145,7 +139,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_perpetual_with_bitwise() { let builtins = BuiltinsInstanceDef::perpetual_with_bitwise(); assert!(builtins.output); @@ -157,7 +150,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_bitwise() { let builtins = BuiltinsInstanceDef::bitwise(); assert!(builtins.output); @@ -169,7 +161,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_recursive() { let builtins = BuiltinsInstanceDef::recursive(); assert!(builtins.output); @@ -181,7 +172,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_all() { let builtins = BuiltinsInstanceDef::all(); assert!(builtins.output); diff --git a/src/types/instance_definitions/cpu_instance_def.rs b/src/types/instance_definitions/cpu_instance_def.rs index 0bee2496ea..7aa89b2e17 100644 --- a/src/types/instance_definitions/cpu_instance_def.rs +++ b/src/types/instance_definitions/cpu_instance_def.rs @@ -13,11 +13,7 @@ impl CpuInstanceDef { mod tests { use super::CpuInstanceDef; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_default() { let cpu_instance = CpuInstanceDef::default(); assert!(cpu_instance._safe_call) diff --git a/src/types/instance_definitions/diluted_pool_instance_def.rs b/src/types/instance_definitions/diluted_pool_instance_def.rs index 8138c573bd..7a7f756c45 100644 --- a/src/types/instance_definitions/diluted_pool_instance_def.rs +++ b/src/types/instance_definitions/diluted_pool_instance_def.rs @@ -27,11 +27,7 @@ impl DilutedPoolInstanceDef { mod tests { use super::DilutedPoolInstanceDef; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_default() { let diluted_pool = DilutedPoolInstanceDef::default(); assert_eq!(diluted_pool.units_per_step, 16); @@ -40,7 +36,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_new() { let diluted_pool = DilutedPoolInstanceDef::new(1, 1, 1); assert_eq!(diluted_pool.units_per_step, 1); diff --git a/src/types/instance_definitions/ec_op_instance_def.rs b/src/types/instance_definitions/ec_op_instance_def.rs index f777589842..03083c6866 100644 --- a/src/types/instance_definitions/ec_op_instance_def.rs +++ b/src/types/instance_definitions/ec_op_instance_def.rs @@ -38,25 +38,19 @@ impl EcOpInstanceDef { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_units_per_builtin() { let builtin_instance = EcOpInstanceDef::default(); assert_eq!(builtin_instance._range_check_units_per_builtin(), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_builtin() { let builtin_instance = EcOpInstanceDef::default(); assert_eq!(builtin_instance._cells_per_builtin(), 7); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_new() { let builtin_instance = EcOpInstanceDef { ratio: 8, @@ -67,7 +61,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_default() { let builtin_instance = EcOpInstanceDef { ratio: 256, diff --git a/src/types/instance_definitions/ecdsa_instance_def.rs b/src/types/instance_definitions/ecdsa_instance_def.rs index 689443f682..fdd48c1d3f 100644 --- a/src/types/instance_definitions/ecdsa_instance_def.rs +++ b/src/types/instance_definitions/ecdsa_instance_def.rs @@ -41,25 +41,19 @@ impl EcdsaInstanceDef { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_units_per_builtin() { let builtin_instance = EcdsaInstanceDef::default(); assert_eq!(builtin_instance._range_check_units_per_builtin(), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_builtin() { let builtin_instance = EcdsaInstanceDef::default(); assert_eq!(builtin_instance._cells_per_builtin(), 2); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_new() { let builtin_instance = EcdsaInstanceDef { ratio: 8, @@ -71,7 +65,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_default() { let builtin_instance = EcdsaInstanceDef { ratio: 512, diff --git a/src/types/instance_definitions/keccak_instance_def.rs b/src/types/instance_definitions/keccak_instance_def.rs index d01c666622..d1bf77195e 100644 --- a/src/types/instance_definitions/keccak_instance_def.rs +++ b/src/types/instance_definitions/keccak_instance_def.rs @@ -1,5 +1,3 @@ -use crate::stdlib::prelude::*; - #[derive(Clone, Debug, PartialEq)] pub(crate) struct KeccakInstanceDef { pub(crate) _ratio: u32, @@ -40,25 +38,19 @@ impl KeccakInstanceDef { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_units_per_builtin() { let builtin_instance = KeccakInstanceDef::default(); assert_eq!(builtin_instance._range_check_units_per_builtin(), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_builtin() { let builtin_instance = KeccakInstanceDef::default(); assert_eq!(builtin_instance.cells_per_builtin(), 16); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_new() { let builtin_instance = KeccakInstanceDef { _ratio: 2048, @@ -69,7 +61,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_default() { let builtin_instance = KeccakInstanceDef { _ratio: 2048, diff --git a/src/types/instance_definitions/pedersen_instance_def.rs b/src/types/instance_definitions/pedersen_instance_def.rs index dad14cdebb..bd225d059c 100644 --- a/src/types/instance_definitions/pedersen_instance_def.rs +++ b/src/types/instance_definitions/pedersen_instance_def.rs @@ -49,25 +49,19 @@ impl PedersenInstanceDef { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_units_per_builtin() { let builtin_instance = PedersenInstanceDef::default(); assert_eq!(builtin_instance._range_check_units_per_builtin(), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_builtin() { let builtin_instance = PedersenInstanceDef::default(); assert_eq!(builtin_instance._cells_per_builtin(), 3); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_new() { let builtin_instance = PedersenInstanceDef { ratio: 10, @@ -81,7 +75,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_default() { let builtin_instance = PedersenInstanceDef { ratio: 8, diff --git a/src/types/instance_definitions/range_check_instance_def.rs b/src/types/instance_definitions/range_check_instance_def.rs index bc67866e8a..24057a7888 100644 --- a/src/types/instance_definitions/range_check_instance_def.rs +++ b/src/types/instance_definitions/range_check_instance_def.rs @@ -31,25 +31,19 @@ impl RangeCheckInstanceDef { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_units_per_builtin() { let builtin_instance = RangeCheckInstanceDef::default(); assert_eq!(builtin_instance._range_check_units_per_builtin(), 8); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_builtin() { let builtin_instance = RangeCheckInstanceDef::default(); assert_eq!(builtin_instance._cells_per_builtin(), 1); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_new() { let builtin_instance = RangeCheckInstanceDef { ratio: 10, @@ -59,7 +53,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_default() { let builtin_instance = RangeCheckInstanceDef { ratio: 8, diff --git a/src/types/instruction.rs b/src/types/instruction.rs index d3d43866e9..f6f7590d23 100644 --- a/src/types/instruction.rs +++ b/src/types/instruction.rs @@ -103,11 +103,7 @@ pub(crate) fn is_call_instruction(encoded_instruction: &Felt, imm: Option<&Felt> mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_call_instruction_true() { let encoded_instruction = Felt::new(1226245742482522112_i64); assert!(is_call_instruction( @@ -116,14 +112,12 @@ mod tests { )); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_call_instruction_false() { let encoded_instruction = Felt::new(4612671187288031229_i64); assert!(!is_call_instruction(&encoded_instruction, None)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn instruction_size() { let encoded_instruction = Felt::new(1226245742482522112_i64); let instruction = diff --git a/src/types/layout.rs b/src/types/layout.rs index 3d9e7cebab..1e37c654a5 100644 --- a/src/types/layout.rs +++ b/src/types/layout.rs @@ -1,5 +1,3 @@ -use crate::stdlib::prelude::*; - use super::instance_definitions::{ builtins_instance_def::BuiltinsInstanceDef, cpu_instance_def::CpuInstanceDef, diluted_pool_instance_def::DilutedPoolInstanceDef, @@ -122,11 +120,7 @@ impl CairoLayout { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_plain_instance() { let layout = CairoLayout::plain_instance(); let builtins = BuiltinsInstanceDef::plain(); @@ -142,7 +136,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_small_instance() { let layout = CairoLayout::small_instance(); let builtins = BuiltinsInstanceDef::small(); @@ -158,7 +151,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_dex_instance() { let layout = CairoLayout::dex_instance(); let builtins = BuiltinsInstanceDef::dex(); @@ -174,7 +166,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_perpetual_with_bitwise_instance() { let layout = CairoLayout::perpetual_with_bitwise_instance(); let builtins = BuiltinsInstanceDef::perpetual_with_bitwise(); @@ -193,7 +184,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_bitwise_instance() { let layout = CairoLayout::bitwise_instance(); let builtins = BuiltinsInstanceDef::bitwise(); @@ -212,7 +202,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_recursive_instance() { let layout = CairoLayout::recursive_instance(); let builtins = BuiltinsInstanceDef::recursive(); @@ -231,7 +220,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_all_instance() { let layout = CairoLayout::all_instance(); let builtins = BuiltinsInstanceDef::all(); diff --git a/src/types/program.rs b/src/types/program.rs index d27fc3b31e..36cbc9ad8a 100644 --- a/src/types/program.rs +++ b/src/types/program.rs @@ -1,17 +1,17 @@ -use crate::stdlib::{collections::HashMap, prelude::*}; - use crate::{ serde::deserialize_program::{ - deserialize_and_parse_program, Attribute, HintParams, Identifier, InstructionLocation, + deserialize_program, Attribute, HintParams, Identifier, InstructionLocation, ReferenceManager, }, types::{errors::program_errors::ProgramError, relocatable::MaybeRelocatable}, }; use felt::{Felt, PRIME_STR}; use serde::Serialize; - -#[cfg(feature = "std")] -use std::path::Path; +use std::{ + fs::File, + io::{BufReader, Read}, + {collections::HashMap, path::Path}, +}; #[derive(Clone, Debug, PartialEq, Eq, Serialize)] pub struct Program { @@ -54,8 +54,8 @@ impl Program { let value = value .value .clone() - .ok_or_else(|| ProgramError::ConstWithoutValue(key.clone()))?; - constants.insert(key.clone(), value); + .ok_or_else(|| ProgramError::ConstWithoutValue(key.to_owned()))?; + constants.insert(key.to_owned(), value); } } @@ -72,14 +72,18 @@ impl Program { }) } - #[cfg(feature = "std")] pub fn from_file(path: &Path, entrypoint: Option<&str>) -> Result { - let file_content = std::fs::read(path)?; - deserialize_and_parse_program(&file_content, entrypoint) + let file = File::open(path)?; + let reader = BufReader::new(file); + + deserialize_program(reader, entrypoint) } - pub fn from_bytes(bytes: &[u8], entrypoint: Option<&str>) -> Result { - deserialize_and_parse_program(bytes, entrypoint) + pub fn from_reader( + reader: impl Read, + entrypoint: Option<&str>, + ) -> Result { + deserialize_program(reader, entrypoint) } } @@ -107,15 +111,11 @@ impl Default for Program { mod tests { use super::*; use crate::serde::deserialize_program::{ApTracking, FlowTrackingData}; - use crate::utils::test_utils::*; + use crate::utils::test_utils::mayberelocatable; use felt::felt_str; use num_traits::Zero; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn new() { let reference_manager = ReferenceManager { references: Vec::new(), @@ -151,7 +151,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn new_program_with_identifiers() { let reference_manager = ReferenceManager { references: Vec::new(), @@ -221,7 +220,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn new_program_with_invalid_identifiers() { let reference_manager = ReferenceManager { references: Vec::new(), @@ -280,13 +278,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/manually_compiled/valid_program_a.json"), + let program: Program = Program::from_file( + Path::new("cairo_programs/manually_compiled/valid_program_a.json"), Some("main"), ) - .unwrap(); + .expect("Failed to deserialize program"); let builtins: Vec<&'static str> = Vec::new(); let data: Vec = vec![ @@ -365,13 +362,12 @@ mod tests { /// Deserialize a program without an entrypoint. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_without_entrypoint_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/manually_compiled/valid_program_a.json"), + let program: Program = Program::from_file( + Path::new("cairo_programs/manually_compiled/valid_program_a.json"), None, ) - .unwrap(); + .expect("Failed to deserialize program"); let builtins: Vec<&'static str> = Vec::new(); @@ -465,13 +461,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deserialize_program_constants_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/manually_compiled/deserialize_constant_test.json"), + let program = Program::from_file( + Path::new("cairo_programs/manually_compiled/deserialize_constant_test.json"), Some("main"), ) - .unwrap(); + .expect("Failed to deserialize program"); let constants = [ ("__main__.compare_abs_arrays.SIZEOF_LOCALS", Felt::zero()), @@ -504,7 +499,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn default_program() { let program = Program { builtins: Vec::new(), diff --git a/src/types/relocatable.rs b/src/types/relocatable.rs index 36719ab182..2b3bae84fc 100644 --- a/src/types/relocatable.rs +++ b/src/types/relocatable.rs @@ -1,15 +1,13 @@ -use crate::stdlib::{ - fmt::{self, Display}, - ops::{Add, AddAssign, Sub}, - prelude::*, -}; - use crate::{ relocatable, types::errors::math_errors::MathError, vm::errors::memory_errors::MemoryError, }; use felt::Felt; use num_traits::{ToPrimitive, Zero}; use serde::{Deserialize, Serialize}; +use std::{ + fmt::{self, Display}, + ops::{Add, AddAssign, Sub}, +}; #[derive(Eq, Hash, PartialEq, PartialOrd, Clone, Copy, Debug, Serialize, Deserialize)] pub struct Relocatable { @@ -356,11 +354,7 @@ mod tests { use felt::felt_str; use num_traits::{One, Zero}; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_bigint_to_int() { let addr = MaybeRelocatable::from(Felt::new(7i32)); let added_addr = addr.add_int(&Felt::new(2i32)); @@ -368,7 +362,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_usize_to_int() { let addr = MaybeRelocatable::from(Felt::new(7_i32)); let added_addr = addr.add_usize(2).unwrap(); @@ -376,7 +369,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_bigint_to_relocatable() { let addr = MaybeRelocatable::RelocatableValue(relocatable!(7, 65)); let added_addr = addr.add_int(&Felt::new(2)); @@ -390,7 +382,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_int_mod_offset_exceeded() { let addr = MaybeRelocatable::from((0, 0)); let error = addr.add_int(&felt_str!("18446744073709551616")); @@ -404,7 +395,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_usize_to_relocatable() { let addr = MaybeRelocatable::RelocatableValue(relocatable!(7, 65)); let added_addr = addr.add_usize(2); @@ -418,7 +408,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_bigint_to_int_prime_mod() { let addr = MaybeRelocatable::Int(felt_str!( "800000000000011000000000000000000000000000000000000000000000004", @@ -429,7 +418,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_bigint_to_relocatable_prime() { let addr = MaybeRelocatable::from((1, 9)); let added_addr = addr.add_int(&felt_str!( @@ -445,7 +433,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_int_to_int() { let addr_a = &MaybeRelocatable::from(felt_str!( "3618502788666131213697322783095070105623107215331596699973092056135872020488" @@ -456,7 +443,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_relocatable_to_relocatable_should_fail() { let addr_a = &MaybeRelocatable::from((7, 5)); let addr_b = &MaybeRelocatable::RelocatableValue(relocatable!(7, 10)); @@ -471,7 +457,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_int_to_relocatable() { let addr_a = &MaybeRelocatable::from((7, 7)); let addr_b = &MaybeRelocatable::from(Felt::new(10)); @@ -486,7 +471,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_relocatable_to_int() { let addr_a = &MaybeRelocatable::from(Felt::new(10_i32)); let addr_b = &MaybeRelocatable::RelocatableValue(relocatable!(7, 7)); @@ -501,7 +485,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_int_to_relocatable_prime() { let addr_a = &MaybeRelocatable::from((7, 14)); let addr_b = &MaybeRelocatable::Int(felt_str!( @@ -519,7 +502,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_int_rel_int_offset_exceeded() { let addr = MaybeRelocatable::from((0, 0)); let error = addr.add(&MaybeRelocatable::from(felt_str!("18446744073709551616"))); @@ -533,7 +515,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_int_int_rel_offset_exceeded() { let addr = MaybeRelocatable::Int(felt_str!("18446744073709551616")); let relocatable = Relocatable { @@ -551,7 +532,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sub_int_from_int() { let addr_a = &MaybeRelocatable::from(Felt::new(7)); let addr_b = &MaybeRelocatable::from(Felt::new(5)); @@ -560,7 +540,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sub_relocatable_from_relocatable_same_offset() { let addr_a = &MaybeRelocatable::from((7, 17)); let addr_b = &MaybeRelocatable::from((7, 7)); @@ -569,7 +548,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sub_relocatable_from_relocatable_diff_offset() { let addr_a = &MaybeRelocatable::from((7, 17)); let addr_b = &MaybeRelocatable::from((8, 7)); @@ -584,7 +562,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sub_int_addr_ref_from_relocatable_addr_ref() { let addr_a = &MaybeRelocatable::from((7, 17)); let addr_b = &MaybeRelocatable::from(Felt::new(5_i32)); @@ -593,7 +570,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sub_rel_to_int_error() { assert_eq!( MaybeRelocatable::from(Felt::new(7_i32)).sub(&MaybeRelocatable::from((7, 10))), @@ -605,7 +581,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn divmod_working() { let value = &MaybeRelocatable::from(Felt::new(10)); let div = &MaybeRelocatable::from(Felt::new(3)); @@ -615,7 +590,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn divmod_bad_type() { let value = &MaybeRelocatable::from(Felt::new(10)); let div = &MaybeRelocatable::from((2, 7)); @@ -629,7 +603,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_relocatable_value() { let value = MaybeRelocatable::from((2, 7)); let relocation_table = vec![1, 2, 5]; @@ -637,7 +610,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_relocatable_in_temp_segment_value() { let value = MaybeRelocatable::from((-1, 7)); let relocation_table = vec![1, 2, 5]; @@ -648,7 +620,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_relocatable_in_temp_segment_value_with_offset() { let value = MaybeRelocatable::from((-1, 7)); let relocation_table = vec![1, 2, 5]; @@ -659,7 +630,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_relocatable_in_temp_segment_value_error() { let value = MaybeRelocatable::from((-1, 7)); let relocation_table = vec![1, 2, 5]; @@ -670,7 +640,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_int_value() { let value = MaybeRelocatable::from(Felt::new(7)); let relocation_table = vec![1, 2, 5]; @@ -678,7 +647,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_relocatable_value_no_relocation() { let value = MaybeRelocatable::from((2, 7)); let relocation_table = vec![1, 2]; @@ -689,14 +657,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocatable_add_int() { assert_eq!(relocatable!(1, 2) + &Felt::new(4), Ok(relocatable!(1, 6))); assert_eq!(relocatable!(3, 2) + &Felt::zero(), Ok(relocatable!(3, 2))); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocatable_add_int_mod_offset_exceeded_error() { assert_eq!( relocatable!(0, 0) + &(Felt::new(usize::MAX) + 1_usize), @@ -708,7 +674,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocatable_add_i32() { let reloc = relocatable!(1, 5); @@ -727,7 +692,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn mayberelocatable_try_into_reloctable() { let address = mayberelocatable!(1, 2); assert_eq!(Ok(relocatable!(1, 2)), address.try_into()); @@ -738,7 +702,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocatable_sub_rel_test() { let reloc = relocatable!(7, 6); assert_eq!(reloc - relocatable!(7, 5), Ok(1)); @@ -749,7 +712,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sub_rel_different_indexes() { let a = relocatable!(7, 6); let b = relocatable!(8, 6); @@ -757,7 +719,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_maybe_mod_ok() { assert_eq!( relocatable!(1, 0) + &mayberelocatable!(2), @@ -782,7 +743,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_maybe_mod_add_two_relocatable_error() { assert_eq!( relocatable!(1, 0) + &mayberelocatable!(1, 2), @@ -794,7 +754,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_maybe_mod_offset_exceeded_error() { assert_eq!( relocatable!(1, 0) + &mayberelocatable!(usize::MAX as i128 + 1), @@ -806,7 +765,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_relocatable_test() { assert_eq!( mayberelocatable!(1, 2).get_relocatable(), @@ -816,7 +774,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocatable_display() { assert_eq!( format!("{}", Relocatable::from((1, 0))), @@ -825,7 +782,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn maybe_relocatable_relocatable_display() { assert_eq!( format!("{}", MaybeRelocatable::from((1, 0))), @@ -834,7 +790,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn maybe_relocatable_int_display() { assert_eq!( format!("{}", MaybeRelocatable::from(Felt::new(6))), diff --git a/src/utils.rs b/src/utils.rs index 82721de83f..8e9db41827 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,3 @@ -use crate::stdlib::prelude::*; - use crate::types::relocatable::Relocatable; use felt::Felt; use lazy_static::lazy_static; @@ -22,7 +20,7 @@ lazy_static! { #[macro_export] macro_rules! any_box { ($val : expr) => { - $crate::stdlib::boxed::Box::new($val) as $crate::stdlib::boxed::Box + Box::new($val) as Box }; } @@ -146,9 +144,9 @@ pub mod test_utils { let mut res = $mem.insert(k, v); while matches!(res, Err(MemoryError::UnallocatedSegment(_, _))) { if $si < 0 { - $mem.temp_data.push($crate::stdlib::vec::Vec::new()) + $mem.temp_data.push(Vec::new()) } else { - $mem.data.push($crate::stdlib::vec::Vec::new()); + $mem.data.push(Vec::new()); } res = $mem.insert(k, v); } @@ -158,9 +156,9 @@ pub mod test_utils { let mut res = $mem.insert(k, v); while matches!(res, Err(MemoryError::UnallocatedSegment(_, _))) { if $si < 0 { - $mem.temp_data.push($crate::stdlib::vec::Vec::new()) + $mem.temp_data.push(Vec::new()) } else { - $mem.data.push($crate::stdlib::vec::Vec::new()); + $mem.data.push(Vec::new()); } res = $mem.insert(k, v); } @@ -205,7 +203,7 @@ pub mod test_utils { macro_rules! references { ($num: expr) => {{ - let mut references = crate::stdlib::collections::HashMap::::new(); + let mut references = HashMap::::new(); for i in 0..$num { references.insert(i as usize, HintReference::new_simple((i as i32 - $num))); } @@ -252,17 +250,17 @@ pub mod test_utils { Program { builtins: vec![$( $builtin_name ),*], prime: "0x800000000000011000000000000000000000000000000000000000000000001".to_string(), - data: crate::stdlib::vec::Vec::new(), - constants: crate::stdlib::collections::HashMap::new(), + data: Vec::new(), + constants: HashMap::new(), main: None, start: None, end: None, - hints: crate::stdlib::collections::HashMap::new(), + hints: HashMap::new(), reference_manager: ReferenceManager { - references: crate::stdlib::vec::Vec::new(), + references: Vec::new(), }, - identifiers: crate::stdlib::collections::HashMap::new(), - error_message_attributes: crate::stdlib::vec::Vec::new(), + identifiers: HashMap::new(), + error_message_attributes: Vec::new(), instruction_locations: None, } }; @@ -303,9 +301,9 @@ pub mod test_utils { { let ids_names = vec![$( $name ),*]; let references = references!(ids_names.len() as i32); - let mut ids_data = crate::stdlib::collections::HashMap::::new(); + let mut ids_data = HashMap::::new(); for (i, name) in ids_names.iter().enumerate() { - ids_data.insert(crate::stdlib::string::ToString::to_string(name), references.get(&i).unwrap().clone()); + ids_data.insert(name.to_string(), references.get(&i).unwrap().clone()); } ids_data } @@ -316,9 +314,9 @@ pub mod test_utils { macro_rules! non_continuous_ids_data { ( $( ($name: expr, $offset:expr) ),* ) => { { - let mut ids_data = crate::stdlib::collections::HashMap::::new(); + let mut ids_data = HashMap::::new(); $( - ids_data.insert(crate::stdlib::string::String::from($name), HintReference::new_simple($offset)); + ids_data.insert(String::from($name), HintReference::new_simple($offset)); )* ids_data } @@ -367,29 +365,23 @@ pub mod test_utils { hint_processor.execute_hint(&mut $vm, $exec_scopes, &any_box!(hint_data), $constants) }}; ($vm:expr, $ids_data:expr, $hint_code:expr, $exec_scopes:expr) => {{ - let hint_data = HintProcessorData::new_default( - crate::stdlib::string::ToString::to_string($hint_code), - $ids_data, - ); + let hint_data = HintProcessorData::new_default($hint_code.to_string(), $ids_data); let mut hint_processor = BuiltinHintProcessor::new_empty(); hint_processor.execute_hint( &mut $vm, $exec_scopes, &any_box!(hint_data), - &crate::stdlib::collections::HashMap::new(), + &HashMap::new(), ) }}; ($vm:expr, $ids_data:expr, $hint_code:expr) => {{ - let hint_data = HintProcessorData::new_default( - crate::stdlib::string::ToString::to_string($hint_code), - $ids_data, - ); + let hint_data = HintProcessorData::new_default($hint_code.to_string(), $ids_data); let mut hint_processor = BuiltinHintProcessor::new_empty(); hint_processor.execute_hint( &mut $vm, exec_scopes_ref!(), &any_box!(hint_data), - &crate::stdlib::collections::HashMap::new(), + &HashMap::new(), ) }}; } @@ -473,13 +465,13 @@ pub mod test_utils { )* let mut dict_manager = DictManager::new(); dict_manager.trackers.insert(2, tracker); - $exec_scopes.insert_value("dict_manager", crate::stdlib::rc::Rc::new(core::cell::RefCell::new(dict_manager))) + $exec_scopes.insert_value("dict_manager", Rc::new(RefCell::new(dict_manager))) }; ($exec_scopes:expr, $tracker_num:expr) => { let tracker = DictTracker::new_empty(relocatable!($tracker_num, 0)); let mut dict_manager = DictManager::new(); dict_manager.trackers.insert(2, tracker); - $exec_scopes.insert_value("dict_manager", crate::stdlib::rc::Rc::new(core::cell::RefCell::new(dict_manager))) + $exec_scopes.insert_value("dict_manager", Rc::new(RefCell::new(dict_manager))) }; } @@ -493,13 +485,13 @@ pub mod test_utils { )* let mut dict_manager = DictManager::new(); dict_manager.trackers.insert(2, tracker); - $exec_scopes.insert_value("dict_manager", crate::stdlib::rc::Rc::new(core::cell::RefCell::new(dict_manager))) + $exec_scopes.insert_value("dict_manager", Rc::new(RefCell::new(dict_manager))) }; ($exec_scopes:expr, $tracker_num:expr,$default:expr) => { let tracker = DictTracker::new_default_dict(relocatable!($tracker_num, 0), &MaybeRelocatable::from($default), None); let mut dict_manager = DictManager::new(); dict_manager.trackers.insert(2, tracker); - $exec_scopes.insert_value("dict_manager", crate::stdlib::rc::Rc::new(core::cell::RefCell::new(dict_manager))) + $exec_scopes.insert_value("dict_manager", Rc::new(RefCell::new(dict_manager))) }; } pub(crate) use dict_manager_default; @@ -521,7 +513,7 @@ pub mod test_utils { } pub(crate) use vec_data_inner; - pub fn check_scope_value( + pub fn check_scope_value( scopes: &ExecutionScopes, name: &str, value: T, @@ -533,7 +525,6 @@ pub mod test_utils { #[cfg(test)] mod test { - use crate::stdlib::{cell::RefCell, collections::HashMap, rc::Rc, string::String, vec::Vec}; use crate::{ hint_processor::{ builtin_hint_processor::{ @@ -552,14 +543,11 @@ mod test { }; use felt::Felt; use num_traits::One; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc}; use super::*; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memory_macro_test() { let mut memory = Memory::new(); for _ in 0..2 { @@ -582,7 +570,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_memory_macro_test() { let mut memory = Memory::new(); for _ in 0..2 { @@ -606,7 +593,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_memory_address_macro_test() { let mut memory = Memory::new(); for _ in 0..2 { @@ -631,7 +617,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn create_run_context() { let mut vm = vm!(); run_context!(vm, 2, 6, 10); @@ -642,7 +627,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assert_trace() { let trace = vec![ TraceEntry { @@ -699,7 +683,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_non_continuous_ids_data() { let ids_data_macro = non_continuous_ids_data![("a", -2), ("", -6)]; let ids_data_verbose = HashMap::from([ @@ -710,7 +693,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_hint_alloc() { let hint_code = "memory[ap] = segments.add()"; let mut vm = vm!(); @@ -721,7 +703,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_scope_test_pass() { let mut exec_scopes = ExecutionScopes::new(); exec_scopes.assign_or_update_variable("a", any_box!(String::from("Hello"))); @@ -767,7 +748,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn scope_macro_test() { let scope_from_macro = scope![("a", Felt::one())]; let mut scope_verbose = ExecutionScopes::new(); @@ -781,7 +761,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_dictionary_pass() { let mut tracker = DictTracker::new_empty(relocatable!(2, 0)); tracker.insert_value( @@ -817,7 +796,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_dict_ptr_pass() { let tracker = DictTracker::new_empty(relocatable!(2, 0)); let mut dict_manager = DictManager::new(); @@ -845,7 +823,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_manager_macro() { let tracker = DictTracker::new_empty(relocatable!(2, 0)); let mut dict_manager = DictManager::new(); @@ -859,7 +836,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_manager_default_macro() { let tracker = DictTracker::new_default_dict( relocatable!(2, 0), @@ -877,7 +853,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn data_vec_test() { let data = vec_data!((1), ((2, 2)), (("49128305", 10)), (("3b6f00a9", 16))); assert_eq!(data[0], mayberelocatable!(1)); @@ -886,7 +861,6 @@ mod test { assert_eq!(data[3], mayberelocatable!(997130409)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn from_relocatable_to_indexes_test() { let reloc_1 = relocatable!(1, 5); let reloc_2 = relocatable!(0, 5); @@ -897,7 +871,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn program_macro() { let program = Program { builtins: Vec::new(), @@ -920,7 +893,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn program_macro_with_builtin() { let program = Program { builtins: vec![RANGE_CHECK_BUILTIN_NAME], @@ -943,7 +915,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn program_macro_custom_definition() { let program = Program { builtins: vec![RANGE_CHECK_BUILTIN_NAME], diff --git a/src/vm/context/run_context.rs b/src/vm/context/run_context.rs index 5a49f2a2ea..7a5839d634 100644 --- a/src/vm/context/run_context.rs +++ b/src/vm/context/run_context.rs @@ -101,18 +101,13 @@ impl RunContext { mod tests { use super::*; use crate::relocatable; - use crate::stdlib::string::ToString; use crate::types::instruction::{ApUpdate, FpUpdate, Opcode, PcUpdate, Res}; use crate::utils::test_utils::mayberelocatable; use crate::vm::errors::memory_errors::MemoryError; use assert_matches::assert_matches; use felt::Felt; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_dst_addr_for_ap_register() { let instruction = Instruction { off0: 1, @@ -141,7 +136,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_dst_addr_for_fp_register() { let instruction = Instruction { off0: 1, @@ -171,7 +165,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op0_addr_for_ap_register() { let instruction = Instruction { off0: 1, @@ -200,7 +193,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op0_addr_for_fp_register() { let instruction = Instruction { off0: 1, @@ -229,7 +221,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op1_addr_for_fp_op1_addr() { let instruction = Instruction { off0: 1, @@ -258,7 +249,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op1_addr_for_ap_op1_addr() { let instruction = Instruction { off0: 1, @@ -287,7 +277,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op1_addr_for_imm_op1_addr_correct_off2() { let instruction = Instruction { off0: 1, @@ -316,7 +305,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op1_addr_for_imm_op1_addr_incorrect_off2() { let instruction = Instruction { off0: 1, @@ -348,7 +336,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op1_addr_for_op0_op1_addr_with_op0() { let instruction = Instruction { off0: 1, @@ -379,7 +366,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op1_addr_with_no_relocatable_address() { let instruction = Instruction { off0: 1, @@ -412,7 +398,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_op1_addr_for_op0_op1_addr_without_op0() { let instruction = Instruction { off0: 1, diff --git a/src/vm/decoding/decoder.rs b/src/vm/decoding/decoder.rs index 880b478996..106e7e7a0f 100644 --- a/src/vm/decoding/decoder.rs +++ b/src/vm/decoding/decoder.rs @@ -146,14 +146,9 @@ fn decode_offset(offset: i64) -> isize { #[cfg(test)] mod decoder_test { use super::*; - use crate::stdlib::string::ToString; use assert_matches::assert_matches; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn invalid_op1_reg() { let error = decode_instruction(0x294F800080008000, None); assert_matches!(error, Err(VirtualMachineError::InvalidOp1Reg(3))); @@ -164,7 +159,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn invalid_pc_update() { let error = decode_instruction(0x29A8800080008000, None); assert_matches!(error, Err(VirtualMachineError::InvalidPcUpdate(3))); @@ -172,7 +166,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn invalid_res_logic() { let error = decode_instruction(0x2968800080008000, None); assert_matches!(error, Err(VirtualMachineError::InvalidRes(3))); @@ -180,7 +173,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn invalid_opcode() { let error = decode_instruction(0x3948800080008000, None); assert_matches!(error, Err(VirtualMachineError::InvalidOpcode(3))); @@ -188,7 +180,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn invalid_ap_update() { let error = decode_instruction(0x2D48800080008000, None); assert_matches!(error, Err(VirtualMachineError::InvalidApUpdate(3))); @@ -196,7 +187,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn decode_no_immediate_given() { assert_matches!( decode_instruction(0x14A7800080008000, None), @@ -205,7 +195,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn decode_flags_call_add_jmp_add_imm_fp_fp() { // 0| opcode|ap_update|pc_update|res_logic|op1_src|op0_reg|dst_reg // 15|14 13 12| 11 10| 9 8 7| 6 5|4 3 2| 1| 0 @@ -224,7 +213,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn decode_flags_ret_add1_jmp_rel_mul_fp_ap_ap() { // 0| opcode|ap_update|pc_update|res_logic|op1_src|op0_reg|dst_reg // 15|14 13 12| 11 10| 9 8 7| 6 5|4 3 2| 1| 0 @@ -243,7 +231,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn decode_flags_assrt_add_jnz_mul_ap_ap_ap() { // 0| opcode|ap_update|pc_update|res_logic|op1_src|op0_reg|dst_reg // 15|14 13 12| 11 10| 9 8 7| 6 5|4 3 2| 1| 0 @@ -262,7 +249,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn decode_flags_assrt_add2_jnz_uncon_op0_ap_ap() { // 0| opcode|ap_update|pc_update|res_logic|op1_src|op0_reg|dst_reg // 15|14 13 12| 11 10| 9 8 7| 6 5|4 3 2| 1| 0 @@ -281,7 +267,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn decode_flags_nop_regu_regu_op1_op0_ap_ap() { // 0| opcode|ap_update|pc_update|res_logic|op1_src|op0_reg|dst_reg // 15|14 13 12| 11 10| 9 8 7| 6 5|4 3 2| 1| 0 @@ -300,7 +285,6 @@ mod decoder_test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn decode_offset_negative() { // 0| opcode|ap_update|pc_update|res_logic|op1_src|op0_reg|dst_reg // 15|14 13 12| 11 10| 9 8 7| 6 5|4 3 2| 1| 0 diff --git a/src/vm/errors/cairo_run_errors.rs b/src/vm/errors/cairo_run_errors.rs index 7684b29f2f..3810343411 100644 --- a/src/vm/errors/cairo_run_errors.rs +++ b/src/vm/errors/cairo_run_errors.rs @@ -1,14 +1,10 @@ -#[cfg(feature = "std")] -use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; - use super::memory_errors::MemoryError; use super::vm_exception::VmException; use crate::types::errors::program_errors::ProgramError; use crate::vm::errors::{ runner_errors::RunnerError, trace_errors::TraceError, vm_errors::VirtualMachineError, }; +use thiserror::Error; #[derive(Debug, Error)] pub enum CairoRunError { diff --git a/src/vm/errors/exec_scope_errors.rs b/src/vm/errors/exec_scope_errors.rs index 92e794a022..ec422dd32d 100644 --- a/src/vm/errors/exec_scope_errors.rs +++ b/src/vm/errors/exec_scope_errors.rs @@ -1,7 +1,4 @@ -#[cfg(feature = "std")] use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; #[derive(Eq, Hash, PartialEq, Debug, Error)] pub enum ExecScopeError { diff --git a/src/vm/errors/hint_errors.rs b/src/vm/errors/hint_errors.rs index e2ce4ec78d..5479a8944f 100644 --- a/src/vm/errors/hint_errors.rs +++ b/src/vm/errors/hint_errors.rs @@ -1,12 +1,6 @@ -use crate::stdlib::prelude::*; - -#[cfg(feature = "std")] -use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; - use felt::Felt; use num_bigint::{BigInt, BigUint}; +use thiserror::Error; use crate::types::{ errors::math_errors::MathError, diff --git a/src/vm/errors/memory_errors.rs b/src/vm/errors/memory_errors.rs index a6cf4eeb4f..afe99d6867 100644 --- a/src/vm/errors/memory_errors.rs +++ b/src/vm/errors/memory_errors.rs @@ -1,11 +1,5 @@ -use crate::stdlib::prelude::*; - -#[cfg(feature = "std")] -use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; - use felt::Felt; +use thiserror::Error; use crate::types::{ errors::math_errors::MathError, diff --git a/src/vm/errors/runner_errors.rs b/src/vm/errors/runner_errors.rs index 518fe75f14..2fe4bc0558 100644 --- a/src/vm/errors/runner_errors.rs +++ b/src/vm/errors/runner_errors.rs @@ -1,9 +1,4 @@ -use crate::stdlib::{collections::HashSet, prelude::*}; - -#[cfg(feature = "std")] -use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; +use std::collections::HashSet; use super::memory_errors::MemoryError; use crate::types::{ @@ -11,6 +6,7 @@ use crate::types::{ relocatable::{MaybeRelocatable, Relocatable}, }; use felt::Felt; +use thiserror::Error; #[derive(Debug, PartialEq, Error)] pub enum RunnerError { @@ -20,6 +16,8 @@ pub enum RunnerError { NoProgBase, #[error("Missing main()")] MissingMain, + #[error("Failed to write program output")] + WriteFail, #[error("Found None PC during VM initialization")] NoPC, #[error("Found None AP during VM initialization")] diff --git a/src/vm/errors/trace_errors.rs b/src/vm/errors/trace_errors.rs index dce825e20d..2f63144512 100644 --- a/src/vm/errors/trace_errors.rs +++ b/src/vm/errors/trace_errors.rs @@ -1,9 +1,5 @@ -#[cfg(feature = "std")] -use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; - use crate::vm::errors::memory_errors::MemoryError; +use thiserror::Error; #[derive(Debug, PartialEq, Error)] pub enum TraceError { diff --git a/src/vm/errors/vm_errors.rs b/src/vm/errors/vm_errors.rs index 2ee743d006..1f099b4f93 100644 --- a/src/vm/errors/vm_errors.rs +++ b/src/vm/errors/vm_errors.rs @@ -1,10 +1,3 @@ -use crate::stdlib::prelude::*; - -#[cfg(feature = "std")] -use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; - use crate::{ types::{ errors::math_errors::MathError, @@ -16,6 +9,8 @@ use crate::{ }, }; use felt::Felt; +use std::error::Error; +use thiserror::Error; #[derive(Debug, Error)] pub enum VirtualMachineError { @@ -115,8 +110,6 @@ pub enum VirtualMachineError { MissingAccessedAddresses, #[error(transparent)] Math(#[from] MathError), - #[error("Failed to write the output builtin content")] - FailedToWriteOutput, #[error(transparent)] - Other(anyhow::Error), + Other(Box), } diff --git a/src/vm/errors/vm_exception.rs b/src/vm/errors/vm_exception.rs index 35145deab0..070214f72f 100644 --- a/src/vm/errors/vm_exception.rs +++ b/src/vm/errors/vm_exception.rs @@ -1,13 +1,11 @@ -use crate::stdlib::{ +use std::{ fmt::{self, Display}, - prelude::*, - str, + fs::File, + io::{BufReader, Read}, + path::Path, }; -#[cfg(feature = "std")] use thiserror::Error; -#[cfg(all(not(feature = "std"), feature = "alloc"))] -use thiserror_no_std::Error; use crate::{ hint_processor::{ @@ -231,7 +229,7 @@ impl Display for VmException { impl Location { /// Prints the location with the passed message. - pub fn to_string(&self, message: &str) -> String { + pub fn to_string(&self, message: &String) -> String { let msg_prefix = if message.is_empty() { "" } else { ": " }; format!( "{}:{}:{}{}{}", @@ -239,26 +237,20 @@ impl Location { ) } - #[cfg(all(not(feature = "std"), feature = "alloc"))] - pub fn to_string_with_content(&self, message: &str) -> String { - self.to_string(message) - } - - #[cfg(feature = "std")] - pub fn to_string_with_content(&self, message: &str) -> String { + pub fn to_string_with_content(&self, message: &String) -> String { let mut string = self.to_string(message); - let input_file_path = std::path::Path::new(&self.input_file.filename); - if let Ok(file_content) = std::fs::read(input_file_path) { - string.push_str(&format!("\n{}", self.get_location_marks(&file_content))); + let input_file_path = Path::new(&self.input_file.filename); + if let Ok(file) = File::open(input_file_path) { + let mut reader = BufReader::new(file); + string.push_str(&format!("\n{}", self.get_location_marks(&mut reader))); } string } - pub fn get_location_marks(&self, file_contents: &[u8]) -> String { + pub fn get_location_marks(&self, file_contents: &mut impl Read) -> String { let mut contents = String::new(); - if let Ok(content) = str::from_utf8(file_contents) { - contents.push_str(content); - } + // If this read fails, the string will be left empty, so we can ignore the result + let _ = file_contents.read_to_string(&mut contents); let split_lines: Vec<&str> = contents.split('\n').collect(); if !(0 < self.start_line && ((self.start_line - 1) as usize) < split_lines.len()) { return String::new(); @@ -283,9 +275,8 @@ impl Location { } #[cfg(test)] mod test { - use crate::stdlib::{boxed::Box, collections::HashMap}; use assert_matches::assert_matches; - #[cfg(feature = "std")] + use std::collections::HashMap; use std::path::Path; use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; @@ -296,12 +287,8 @@ mod test { use crate::types::relocatable::Relocatable; use crate::utils::test_utils::*; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - use super::*; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_vm_exception_from_vm_error() { let pc = 0; let location = Location { @@ -334,7 +321,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn location_to_string_no_message() { let location = Location { end_line: 2, @@ -354,7 +340,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn location_to_string_with_message() { let location = Location { end_line: 2, @@ -374,7 +359,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn vm_exception_display_instruction_no_location_no_attributes() { let vm_excep = VmException { pc: 2, @@ -399,7 +383,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn vm_exception_display_instruction_no_location_with_attributes() { let vm_excep = VmException { pc: 2, @@ -424,7 +407,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn vm_exception_display_instruction_no_attributes_no_parent() { let location = Location { end_line: 2, @@ -459,7 +441,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn vm_exception_display_instruction_no_attributes_with_parent() { let location = Location { end_line: 2, @@ -503,7 +484,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_error_attr_value_some() { let attributes = vec![Attribute { name: String::from("Error message"), @@ -522,7 +502,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_error_attr_value_none() { let attributes = vec![Attribute { name: String::from("Error message"), @@ -538,7 +517,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_location_some() { let location = Location { end_line: 2, @@ -561,7 +539,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_location_none() { let location = Location { end_line: 2, @@ -584,7 +561,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_location_some_hint_index() { let location_a = Location { end_line: 2, @@ -621,17 +597,12 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_traceback_bad_dict_update() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/bad_dict_update.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/bad_dict_update.json"), Some("main"), ) - .unwrap(); - #[cfg(feature = "std")] - let expected_traceback = String::from("Cairo traceback (most recent call last):\ncairo_programs/bad_programs/bad_dict_update.cairo:10:5: (pc=0:34)\n dict_update{dict_ptr=my_dict}(key=2, prev_value=3, new_value=4);\n ^*************************************************************^\n"); - #[cfg(all(not(feature = "std"), feature = "alloc"))] - let expected_traceback = String::from("Cairo traceback (most recent call last):\ncairo_programs/bad_programs/bad_dict_update.cairo:10:5: (pc=0:34)\n"); + .expect("Call to `Program::from_file()` failed."); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program, "all", false); @@ -641,35 +612,17 @@ mod test { assert!(cairo_runner .run_until_pc(end, &mut vm, &mut hint_processor) .is_err()); + let expected_traceback = String::from("Cairo traceback (most recent call last):\ncairo_programs/bad_programs/bad_dict_update.cairo:10:5: (pc=0:34)\n dict_update{dict_ptr=my_dict}(key=2, prev_value=3, new_value=4);\n ^*************************************************************^\n"); assert_eq!(get_traceback(&vm, &cairo_runner), Some(expected_traceback)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_traceback_bad_usort() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/bad_usort.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/bad_usort.json"), Some("main"), ) - .unwrap(); - #[cfg(feature = "std")] - let expected_traceback = r"Cairo traceback (most recent call last): -cairo_programs/bad_programs/bad_usort.cairo:91:48: (pc=0:97) - let (output_len, output, multiplicities) = usort(input_len=3, input=input_array); - ^***********************************^ -cairo_programs/bad_programs/bad_usort.cairo:36:5: (pc=0:30) - verify_usort{output=output}( - ^**************************^ -cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) - verify_multiplicity(multiplicity=multiplicity, input_len=input_len, input=input, value=value); - ^*******************************************************************************************^ -"; - #[cfg(all(not(feature = "std"), feature = "alloc"))] - let expected_traceback = r"Cairo traceback (most recent call last): -cairo_programs/bad_programs/bad_usort.cairo:91:48: (pc=0:97) -cairo_programs/bad_programs/bad_usort.cairo:36:5: (pc=0:30) -cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) -"; + .expect("Call to `Program::from_file()` failed."); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program, "all", false); @@ -679,14 +632,11 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) assert!(cairo_runner .run_until_pc(end, &mut vm, &mut hint_processor) .is_err()); - assert_eq!( - get_traceback(&vm, &cairo_runner), - Some(expected_traceback.to_string()) - ); + let expected_traceback = String::from("Cairo traceback (most recent call last):\ncairo_programs/bad_programs/bad_usort.cairo:91:48: (pc=0:97)\n let (output_len, output, multiplicities) = usort(input_len=3, input=input_array);\n ^***********************************^\ncairo_programs/bad_programs/bad_usort.cairo:36:5: (pc=0:30)\n verify_usort{output=output}(\n ^**************************^\ncairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60)\n verify_multiplicity(multiplicity=multiplicity, input_len=input_len, input=input, value=value);\n ^*******************************************************************************************^\n"); + assert_eq!(get_traceback(&vm, &cairo_runner), Some(expected_traceback)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn location_to_string_with_contents_no_contents() { let location = Location { end_line: 2, @@ -706,7 +656,6 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn location_to_string_with_contents() { let location = Location { end_line: 5, @@ -719,20 +668,13 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) start_col: 1, }; let message = String::from("Error at pc=0:75:"); - - #[cfg(feature = "std")] - let expected_message = "cairo_programs/bad_programs/bad_usort.cairo:5:1: Error at pc=0:75:\nfunc usort{range_check_ptr}(input_len: felt, input: felt*) -> (\n^"; - #[cfg(all(not(feature = "std"), feature = "alloc"))] - let expected_message = "cairo_programs/bad_programs/bad_usort.cairo:5:1: Error at pc=0:75:"; - assert_eq!( location.to_string_with_content(&message), - expected_message.to_string() + String::from("cairo_programs/bad_programs/bad_usort.cairo:5:1: Error at pc=0:75:\nfunc usort{range_check_ptr}(input_len: felt, input: felt*) -> (\n^") ) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn location_to_string_with_contents_no_file() { let location = Location { end_line: 5, @@ -754,7 +696,6 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) } #[test] - #[cfg(feature = "std")] fn location_get_location_marks() { let location = Location { end_line: 5, @@ -767,15 +708,15 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) start_col: 1, }; let input_file_path = Path::new(&location.input_file.filename); - let file_content = std::fs::read(input_file_path).expect("Failed to open file"); + let file = File::open(input_file_path).expect("Failed to open file"); + let mut reader = BufReader::new(file); assert_eq!( - location.get_location_marks(&file_content), + location.get_location_marks(&mut reader), String::from("func usort{range_check_ptr}(input_len: felt, input: felt*) -> (\n^") ) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn location_get_location_marks_empty_file() { let location = Location { end_line: 5, @@ -787,14 +728,12 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) start_line: 5, start_col: 1, }; - let reader: &[u8] = &[]; - assert_eq!(location.get_location_marks(reader), String::from("")) + let mut reader: &[u8] = &[]; + assert_eq!(location.get_location_marks(&mut reader), String::from("")) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_bad_range_check_and_check_error_displayed() { - #[cfg(feature = "std")] let expected_error_string = r#"Error message: Failed range-check cairo_programs/bad_programs/bad_range_check.cairo:5:9: Error at pc=0:0: An ASSERT_EQ instruction failed: 4 != 5. @@ -814,21 +753,11 @@ cairo_programs/bad_programs/bad_range_check.cairo:11:5: (pc=0:6) check_range(num - 1); ^******************^ "#; - #[cfg(all(not(feature = "std"), feature = "alloc"))] - let expected_error_string = r#"Error message: Failed range-check -cairo_programs/bad_programs/bad_range_check.cairo:5:9: Error at pc=0:0: -An ASSERT_EQ instruction failed: 4 != 5. -Cairo traceback (most recent call last): -cairo_programs/bad_programs/bad_range_check.cairo:23:5: (pc=0:29) -cairo_programs/bad_programs/bad_range_check.cairo:19:12: (pc=0:21) -cairo_programs/bad_programs/bad_range_check.cairo:19:33: (pc=0:17) -cairo_programs/bad_programs/bad_range_check.cairo:11:5: (pc=0:6) -"#; - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/bad_range_check.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/bad_range_check.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program, "all", false); @@ -843,9 +772,7 @@ cairo_programs/bad_programs/bad_range_check.cairo:11:5: (pc=0:6) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_bad_usort_and_check_error_displayed() { - #[cfg(feature = "std")] let expected_error_string = r#"cairo_programs/bad_programs/bad_usort.cairo:79:5: Error at pc=0:75: Got an exception while executing a hint: unexpected verify multiplicity fail: positions length != 0 %{ assert len(positions) == 0 %} @@ -861,19 +788,11 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) verify_multiplicity(multiplicity=multiplicity, input_len=input_len, input=input, value=value); ^*******************************************************************************************^ "#; - #[cfg(all(not(feature = "std"), feature = "alloc"))] - let expected_error_string = r#"cairo_programs/bad_programs/bad_usort.cairo:79:5: Error at pc=0:75: -Got an exception while executing a hint: unexpected verify multiplicity fail: positions length != 0 -Cairo traceback (most recent call last): -cairo_programs/bad_programs/bad_usort.cairo:91:48: (pc=0:97) -cairo_programs/bad_programs/bad_usort.cairo:36:5: (pc=0:30) -cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) -"#; - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/bad_usort.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/bad_usort.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program, "all", false); @@ -888,13 +807,12 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_value_from_simple_reference_ap_based() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/error_msg_attr_tempvar.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/error_msg_attr_tempvar.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); // This program uses a tempvar inside an error attribute // This reference should be rejected when substituting the error attribute references let runner = cairo_runner!(program); @@ -907,13 +825,12 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn substitute_error_message_references_ap_based() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/error_msg_attr_tempvar.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/error_msg_attr_tempvar.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); // This program uses a tempvar inside an error attribute // This reference should be rejected when substituting the error attribute references let runner = cairo_runner!(program); @@ -929,13 +846,12 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_value_from_simple_reference_complex() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/error_msg_attr_struct.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/error_msg_attr_struct.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); // This program uses a struct inside an error attribute // This reference should be rejected when substituting the error attribute references let runner = cairo_runner!(program); @@ -948,13 +864,12 @@ cairo_programs/bad_programs/bad_usort.cairo:64:5: (pc=0:60) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn substitute_error_message_references_complex() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/error_msg_attr_struct.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/error_msg_attr_struct.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); // This program uses a struct inside an error attribute // This reference should be rejected when substituting the error attribute references let runner = cairo_runner!(program); diff --git a/src/vm/hooks.rs b/src/vm/hooks.rs index 883e1241ff..dab0c4db39 100644 --- a/src/vm/hooks.rs +++ b/src/vm/hooks.rs @@ -9,7 +9,7 @@ //! - pre_step_instruction, executed before each instruction_step in [step](VirtualMachine::step) //! - post_step_instruction, executed after each instruction_step in [step](VirtualMachine::step) -use crate::stdlib::{any::Any, collections::HashMap, prelude::*, sync::Arc}; +use std::{any::Any, collections::HashMap, sync::Arc}; use felt::Felt; @@ -124,6 +124,8 @@ impl VirtualMachine { #[cfg(test)] mod tests { + use std::path::Path; + use super::*; use crate::{ hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, @@ -133,11 +135,8 @@ mod tests { #[test] fn empty_hooks() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/sqrt.json"), - Some("main"), - ) - .expect("Call to `Program::from_file()` failed."); + let program = Program::from_file(Path::new("cairo_programs/sqrt.json"), Some("main")) + .expect("Call to `Program::from_file()` failed."); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program); @@ -152,11 +151,8 @@ mod tests { #[test] fn hook_failure() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/sqrt.json"), - Some("main"), - ) - .expect("Call to `Program::from_file()` failed."); + let program = Program::from_file(Path::new("cairo_programs/sqrt.json"), Some("main")) + .expect("Call to `Program::from_file()` failed."); fn before_first_step_hook( _vm: &mut VirtualMachine, @@ -222,11 +218,8 @@ mod tests { #[test] fn hook_success() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/sqrt.json"), - Some("main"), - ) - .expect("Call to `Program::from_file()` failed."); + let program = Program::from_file(Path::new("cairo_programs/sqrt.json"), Some("main")) + .expect("Call to `Program::from_file()` failed."); fn before_first_step_hook( _vm: &mut VirtualMachine, diff --git a/src/vm/runners/builtin_runner/bitwise.rs b/src/vm/runners/builtin_runner/bitwise.rs index d5d5681785..d4f5bc33ff 100644 --- a/src/vm/runners/builtin_runner/bitwise.rs +++ b/src/vm/runners/builtin_runner/bitwise.rs @@ -1,4 +1,3 @@ -use crate::stdlib::vec::Vec; use crate::{ math_utils::safe_div_usize, types::{ @@ -229,23 +228,18 @@ impl BitwiseBuiltinRunner { mod tests { use super::*; use crate::relocatable; - use crate::stdlib::collections::HashMap; use crate::vm::errors::memory_errors::MemoryError; - use crate::vm::runners::builtin_runner::BuiltinRunner; use crate::vm::runners::builtin_runner::HASH_BUILTIN_NAME; - use crate::vm::vm_core::VirtualMachine; use crate::vm::vm_memory::memory::Memory; + use crate::vm::{runners::builtin_runner::BuiltinRunner, vm_core::VirtualMachine}; use crate::{ hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, types::program::Program, utils::test_utils::*, vm::runners::cairo_runner::CairoRunner, }; use felt::Felt; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::collections::HashMap; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_instances() { let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true); @@ -264,7 +258,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack() { let mut builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true); @@ -288,7 +281,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_stop_pointer() { let mut builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true); @@ -316,7 +308,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_when_notincluded() { let mut builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), false); @@ -340,7 +331,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_non_relocatable() { let mut builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true); @@ -364,7 +354,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_test() { let builtin: BuiltinRunner = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true).into(); @@ -411,7 +400,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units() { let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true); @@ -455,7 +443,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_bitwise_for_preset_memory_valid_and() { let memory = memory![((0, 5), 10), ((0, 6), 12), ((0, 7), 0)]; let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true); @@ -464,7 +451,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_bitwise_for_preset_memory_valid_xor() { let memory = memory![((0, 5), 10), ((0, 6), 12), ((0, 8), 0)]; let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true); @@ -473,7 +459,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_bitwise_for_preset_memory_valid_or() { let memory = memory![((0, 5), 10), ((0, 6), 12), ((0, 9), 0)]; let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true); @@ -482,7 +467,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_bitwise_for_preset_memory_incorrect_offset() { let memory = memory![((0, 3), 10), ((0, 4), 12), ((0, 5), 0)]; let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true); @@ -491,7 +475,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_bitwise_for_preset_memory_no_values_to_operate() { let memory = memory![((0, 5), 12), ((0, 7), 0)]; let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true); @@ -500,7 +483,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_segment_addresses() { let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true); @@ -508,7 +490,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_missing_segment_used_sizes() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -523,7 +504,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_empty() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -536,7 +516,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -557,7 +536,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_missing_segment_used_sizes() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -572,7 +550,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_empty() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -585,7 +562,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -598,7 +574,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_a() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -608,7 +583,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_b() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -618,7 +592,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_c() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), diff --git a/src/vm/runners/builtin_runner/ec_op.rs b/src/vm/runners/builtin_runner/ec_op.rs index 2b0f5973ad..152df6dd8c 100644 --- a/src/vm/runners/builtin_runner/ec_op.rs +++ b/src/vm/runners/builtin_runner/ec_op.rs @@ -1,4 +1,4 @@ -use crate::stdlib::{borrow::Cow, prelude::*}; +use std::borrow::Cow; use crate::math_utils::{ec_add, ec_double, safe_div_usize}; use crate::types::instance_definitions::ec_op_instance_def::{ @@ -325,13 +325,12 @@ mod tests { use super::*; use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; use crate::relocatable; - use crate::stdlib::collections::HashMap; use crate::types::program::Program; use crate::utils::{test_utils::*, CAIRO_PRIME}; + use crate::vm::errors::cairo_run_errors::CairoRunError; use crate::vm::errors::vm_errors::VirtualMachineError; use crate::vm::runners::builtin_runner::HASH_BUILTIN_NAME; use crate::vm::runners::cairo_runner::CairoRunner; - use crate::vm::security::verify_secure_runner; use crate::vm::vm_memory::memory::Memory; use crate::vm::{ errors::{memory_errors::MemoryError, runner_errors::RunnerError}, @@ -339,13 +338,11 @@ mod tests { vm_core::VirtualMachine, }; use felt::felt_str; + use std::collections::HashMap; + use std::path::Path; use EcOpBuiltinRunner; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_instances() { let builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), true); @@ -356,7 +353,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack() { let mut builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), true); @@ -380,7 +376,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_stop_pointer() { let mut builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), true); @@ -408,7 +403,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_when_notincluded() { let mut builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), false); @@ -432,7 +426,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_non_relocatable() { let mut builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), true); @@ -456,7 +449,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_test() { let builtin: BuiltinRunner = EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), true).into(); @@ -501,7 +493,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units() { let builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), true); @@ -545,7 +536,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn point_is_on_curve_a() { let x = felt_str!( "874739451078007766457464989774322083649278607533249481151382481072868806602" @@ -561,7 +551,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn point_is_on_curve_b() { let x = felt_str!( "3139037544796708144595053687182055617920475701120786241351436619796497072089" @@ -577,7 +566,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn point_is_not_on_curve_a() { let x = felt_str!( "874739454078007766457464989774322083649278607533249481151382481072868806602" @@ -593,7 +581,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn point_is_not_on_curve_b() { let x = felt_str!( "3139037544756708144595053687182055617927475701120786241351436619796497072089" @@ -609,7 +596,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_ec_op_impl_valid_a() { let partial_sum = ( felt_str!( @@ -647,7 +633,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_ec_op_impl_valid_b() { let partial_sum = ( felt_str!( @@ -685,7 +670,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] #[allow(deprecated)] fn compute_ec_op_invalid_same_x_coordinate() { let partial_sum = (Felt::one(), Felt::new(9)); @@ -715,7 +699,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Data taken from this program execution: %builtins output ec_op from starkware.cairo.common.cairo_builtins import EcOpBuiltin @@ -783,7 +766,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_ec_op_for_preset_memory_unfilled_input_cells() { let memory = memory![ ( @@ -823,7 +805,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_ec_op_for_preset_memory_addr_not_an_output_cell() { let memory = memory![ ( @@ -870,7 +851,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_ec_op_for_preset_memory_non_integer_input() { let memory = memory![ ( @@ -915,7 +895,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_segment_addresses() { let builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); @@ -923,7 +902,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_missing_segment_used_sizes() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true)); @@ -936,7 +914,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_empty() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true)); @@ -947,7 +924,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true)); @@ -966,7 +942,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_missing_segment_used_sizes() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true)); @@ -979,7 +954,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_empty() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true)); @@ -990,7 +964,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true)); @@ -1001,7 +974,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initial_stackincluded_test() { let ec_op_builtin: BuiltinRunner = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true).into(); @@ -1009,82 +981,52 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initial_stack_notincluded_test() { let ec_op_builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), false); assert_eq!(ec_op_builtin.initial_stack(), Vec::new()) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn catch_point_same_x() { - let program = include_bytes!("../../../../cairo_programs/bad_programs/ec_op_same_x.json"); - let mut cairo_runner = CairoRunner::new( - &Program::from_bytes(program, Some("main")).unwrap(), - "all", - false, - ) - .unwrap(); - let mut vm = VirtualMachine::new(false); - let end = cairo_runner.initialize(&mut vm).unwrap(); - - let hint_executor = &mut BuiltinHintProcessor::new_empty(); - - cairo_runner - .run_until_pc(end, &mut vm, hint_executor) - .unwrap(); - cairo_runner - .end_run(false, false, &mut vm, hint_executor) - .unwrap(); - - vm.verify_auto_deductions().unwrap(); - cairo_runner.read_return_values(&mut vm).unwrap(); - let result = verify_secure_runner(&cairo_runner, true, &mut vm); - + let program = Path::new("cairo_programs/bad_programs/ec_op_same_x.json"); + let cairo_run_config = crate::cairo_run::CairoRunConfig { + layout: "all", + ..crate::cairo_run::CairoRunConfig::default() + }; + let result = crate::cairo_run::cairo_run( + program, + &cairo_run_config, + &mut BuiltinHintProcessor::new_empty(), + ); assert!(result.is_err()); // We need to check this way because CairoRunError doens't implement PartialEq match result { - Err(VirtualMachineError::RunnerError(RunnerError::EcOpSameXCoordinate(_))) => {} + Err(CairoRunError::VirtualMachine(VirtualMachineError::RunnerError( + RunnerError::EcOpSameXCoordinate(_), + ))) => {} Err(_) => panic!("Wrong error returned, expected RunnerError::EcOpSameXCoordinate"), Ok(_) => panic!("Expected run to fail"), } } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn catch_point_not_in_curve() { - let program = - include_bytes!("../../../../cairo_programs/bad_programs/ec_op_not_in_curve.json"); - - let mut cairo_runner = CairoRunner::new( - &Program::from_bytes(program, Some("main")).unwrap(), - "all", - false, - ) - .unwrap(); - let mut vm = VirtualMachine::new(false); - let end = cairo_runner.initialize(&mut vm).unwrap(); - - let hint_proccesor = &mut BuiltinHintProcessor::new_empty(); - cairo_runner - .run_until_pc(end, &mut vm, hint_proccesor) - .unwrap(); - - cairo_runner - .end_run(false, false, &mut vm, hint_proccesor) - .unwrap(); - - vm.verify_auto_deductions().unwrap(); - - cairo_runner.read_return_values(&mut vm).unwrap(); - - let result = verify_secure_runner(&cairo_runner, true, &mut vm); - + let program = Path::new("cairo_programs/bad_programs/ec_op_not_in_curve.json"); + let cairo_run_config = crate::cairo_run::CairoRunConfig { + layout: "all", + ..crate::cairo_run::CairoRunConfig::default() + }; + let result = crate::cairo_run::cairo_run( + program, + &cairo_run_config, + &mut BuiltinHintProcessor::new_empty(), + ); assert!(result.is_err()); - // We need to check this way because CairoRunError doens't implement PartialEq match result { - Err(VirtualMachineError::RunnerError(RunnerError::PointNotOnCurve(_))) => {} + Err(CairoRunError::VirtualMachine(VirtualMachineError::RunnerError( + RunnerError::PointNotOnCurve(_), + ))) => {} Err(_) => panic!("Wrong error returned, expected RunnerError::EcOpSameXCoordinate"), Ok(_) => panic!("Expected run to fail"), } diff --git a/src/vm/runners/builtin_runner/hash.rs b/src/vm/runners/builtin_runner/hash.rs index 226c035607..599f21363c 100644 --- a/src/vm/runners/builtin_runner/hash.rs +++ b/src/vm/runners/builtin_runner/hash.rs @@ -1,4 +1,4 @@ -use crate::stdlib::{cell::RefCell, prelude::*}; +use std::cell::RefCell; use crate::math_utils::safe_div_usize; use crate::types::instance_definitions::pedersen_instance_def::{ @@ -215,7 +215,6 @@ mod tests { use super::*; use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; use crate::relocatable; - use crate::stdlib::collections::HashMap; use crate::types::program::Program; use crate::utils::test_utils::*; use crate::vm::runners::cairo_runner::CairoRunner; @@ -225,12 +224,9 @@ mod tests { vm_core::VirtualMachine, }; use felt::felt_str; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::collections::HashMap; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_instances() { let builtin = HashBuiltinRunner::new(10, true); @@ -241,7 +237,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack() { let mut builtin = HashBuiltinRunner::new(10, true); @@ -265,7 +260,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_stop_pointer() { let mut builtin = HashBuiltinRunner::new(10, true); @@ -293,7 +287,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_when_not_included() { let mut builtin = HashBuiltinRunner::new(10, false); @@ -317,7 +310,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_non_relocatable() { let mut builtin = HashBuiltinRunner::new(10, true); @@ -341,7 +333,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_test() { let builtin: BuiltinRunner = HashBuiltinRunner::new(10, true).into(); @@ -387,7 +378,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units() { let builtin = HashBuiltinRunner::new(10, true); @@ -431,7 +421,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_pedersen_for_preset_memory_valid() { let memory = memory![((0, 3), 32), ((0, 4), 72), ((0, 5), 0)]; let builtin = HashBuiltinRunner::new(8, true); @@ -450,7 +439,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_pedersen_for_preset_memory_incorrect_offset() { let memory = memory![((0, 4), 32), ((0, 5), 72), ((0, 6), 0)]; let builtin = HashBuiltinRunner::new(8, true); @@ -459,7 +447,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_pedersen_for_preset_memory_no_values_to_hash() { let memory = memory![((0, 4), 72), ((0, 5), 0)]; let builtin = HashBuiltinRunner::new(8, true); @@ -468,7 +455,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_pedersen_for_preset_memory_already_computed() { let memory = memory![((0, 3), 32), ((0, 4), 72), ((0, 5), 0)]; let mut builtin = HashBuiltinRunner::new(8, true); @@ -478,7 +464,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_segment_addresses() { let builtin = HashBuiltinRunner::new(256, true); @@ -486,7 +471,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_missing_segment_used_sizes() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(256, true)); let vm = vm!(); @@ -498,7 +482,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_empty() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(256, true)); let mut vm = vm!(); @@ -508,7 +491,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(256, true)); let mut vm = vm!(); @@ -526,7 +508,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_missing_segment_used_sizes() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(256, true)); let vm = vm!(); @@ -538,7 +519,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_empty() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(256, true)); let mut vm = vm!(); @@ -548,7 +528,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(256, true)); let mut vm = vm!(); diff --git a/src/vm/runners/builtin_runner/keccak.rs b/src/vm/runners/builtin_runner/keccak.rs index 4fd7939132..39ee2ee19a 100644 --- a/src/vm/runners/builtin_runner/keccak.rs +++ b/src/vm/runners/builtin_runner/keccak.rs @@ -1,5 +1,3 @@ -use crate::stdlib::prelude::*; - use crate::hint_processor::builtin_hint_processor::keccak_utils::left_pad_u64; use crate::math_utils::safe_div_usize; use crate::types::instance_definitions::keccak_instance_def::KeccakInstanceDef; @@ -250,7 +248,6 @@ mod tests { use super::*; use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; use crate::relocatable; - use crate::stdlib::collections::HashMap; use crate::types::program::Program; use crate::utils::test_utils::*; use crate::vm::runners::cairo_runner::CairoRunner; @@ -260,12 +257,10 @@ mod tests { runners::builtin_runner::BuiltinRunner, vm_core::VirtualMachine, }; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::collections::HashMap; + use std::path::Path; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_instances() { let builtin: BuiltinRunner = KeccakBuiltinRunner::new(&KeccakInstanceDef::new(10, vec![200; 8]), true).into(); @@ -277,7 +272,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack() { let mut builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::new(10, vec![200; 8]), true); @@ -301,7 +295,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_stop_pointer() { let mut builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::new(10, vec![200; 8]), true); @@ -328,7 +321,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_when_not_included() { let mut builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::new(10, vec![200; 8]), false); @@ -353,7 +345,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_non_relocatable() { let mut builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::new(10, vec![200; 8]), true); @@ -377,7 +368,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_test() { let builtin: BuiltinRunner = KeccakBuiltinRunner::new(&KeccakInstanceDef::new(10, vec![200; 8]), true).into(); @@ -385,11 +375,8 @@ mod tests { let mut vm = vm!(); vm.segments.segment_used_sizes = Some(vec![0]); - let program = Program::from_bytes( - include_bytes!("../../../../cairo_programs/_keccak.json"), - Some("main"), - ) - .unwrap(); + let program = + Program::from_file(Path::new("cairo_programs/_keccak.json"), Some("main")).unwrap(); let mut cairo_runner = cairo_runner!(program, "all"); @@ -408,7 +395,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units() { let builtin: BuiltinRunner = KeccakBuiltinRunner::new(&KeccakInstanceDef::new(10, vec![200; 8]), true).into(); @@ -420,7 +406,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_segment_addresses() { let builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true); @@ -428,7 +413,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_missing_segment_used_sizes() { let builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true); let vm = vm!(); @@ -440,7 +424,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_empty() { let builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true); let mut vm = vm!(); @@ -450,7 +433,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses() { let builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true); let mut vm = vm!(); @@ -468,7 +450,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_missing_segment_used_sizes() { let builtin: BuiltinRunner = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true).into(); @@ -481,7 +462,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_empty() { let builtin: BuiltinRunner = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true).into(); @@ -492,7 +472,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells() { let builtin: BuiltinRunner = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true).into(); @@ -503,7 +482,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initial_stackincluded_test() { let keccak_builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true); assert_eq!( @@ -513,14 +491,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initial_stack_notincluded_test() { let keccak_builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), false); assert_eq!(keccak_builtin.initial_stack(), Vec::new()) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_memory_valid() { let memory = memory![ ((0, 16), 43), @@ -556,7 +532,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_non_reloc_address_err() { let memory = memory![ ((0, 4), 32), @@ -571,7 +546,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_offset_lt_input_cell_length_none() { let memory = memory![((0, 4), 32)]; let builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true); @@ -580,7 +554,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_offset_first_addr_error() { let memory = memory![ ((0, 16), 43), @@ -614,7 +587,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_expected_integer() { let memory = memory![((0, 0), (1, 2))]; @@ -634,7 +606,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_get_memory_err() { let memory = memory![((0, 35), 0)]; @@ -646,7 +617,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_memory_int_larger_than_bits() { let memory = memory![ ((0, 16), 43), @@ -687,7 +657,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_result() { let builtin = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true); diff --git a/src/vm/runners/builtin_runner/mod.rs b/src/vm/runners/builtin_runner/mod.rs index c377529948..78e1b95677 100644 --- a/src/vm/runners/builtin_runner/mod.rs +++ b/src/vm/runners/builtin_runner/mod.rs @@ -1,4 +1,3 @@ -use crate::stdlib::prelude::*; use crate::types::relocatable::{MaybeRelocatable, Relocatable}; use crate::vm::errors::memory_errors::{self, MemoryError}; use crate::vm::errors::runner_errors::RunnerError; @@ -452,11 +451,7 @@ mod tests { }; use assert_matches::assert_matches; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_missing_segment_used_sizes() { let builtin: BuiltinRunner = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true).into(); @@ -469,7 +464,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_empty() { let builtin: BuiltinRunner = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true).into(); @@ -480,7 +474,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses() { let builtin: BuiltinRunner = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true).into(); @@ -499,7 +492,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_n_input_cells_bitwise() { let bitwise = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true); let builtin: BuiltinRunner = bitwise.clone().into(); @@ -507,7 +499,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_n_input_cells_hash() { let hash = HashBuiltinRunner::new(10, true); let builtin: BuiltinRunner = hash.clone().into(); @@ -515,7 +506,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_n_input_cells_range_check() { let range_check = RangeCheckBuiltinRunner::new(10, 10, true); let builtin: BuiltinRunner = range_check.clone().into(); @@ -523,7 +513,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_n_input_cells_ec_op() { let ec_op = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); let builtin: BuiltinRunner = ec_op.clone().into(); @@ -531,7 +520,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_n_input_cells_ecdsa() { let signature = SignatureBuiltinRunner::new(&EcdsaInstanceDef::new(10), true); let builtin: BuiltinRunner = signature.clone().into(); @@ -539,7 +527,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_n_input_cells_output() { let output = OutputBuiltinRunner::new(true); let builtin: BuiltinRunner = output.into(); @@ -547,7 +534,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_instance_bitwise() { let bitwise = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true); let builtin: BuiltinRunner = bitwise.clone().into(); @@ -555,7 +541,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_instance_hash() { let hash = HashBuiltinRunner::new(10, true); let builtin: BuiltinRunner = hash.clone().into(); @@ -563,7 +548,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_instance_range_check() { let range_check = RangeCheckBuiltinRunner::new(10, 10, true); let builtin: BuiltinRunner = range_check.clone().into(); @@ -571,7 +555,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_instance_ec_op() { let ec_op = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); let builtin: BuiltinRunner = ec_op.clone().into(); @@ -579,7 +562,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_instance_ecdsa() { let signature = SignatureBuiltinRunner::new(&EcdsaInstanceDef::new(10), true); let builtin: BuiltinRunner = signature.clone().into(); @@ -587,7 +569,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_instance_output() { let output = OutputBuiltinRunner::new(true); let builtin: BuiltinRunner = output.into(); @@ -595,7 +576,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_cells_per_instance_keccak() { let keccak = KeccakBuiltinRunner::new(&KeccakInstanceDef::default(), true); let builtin: BuiltinRunner = keccak.clone().into(); @@ -603,7 +583,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_name_bitwise() { let bitwise = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::new(10), true); let builtin: BuiltinRunner = bitwise.into(); @@ -611,7 +590,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_name_hash() { let hash = HashBuiltinRunner::new(10, true); let builtin: BuiltinRunner = hash.into(); @@ -619,7 +597,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_name_range_check() { let range_check = RangeCheckBuiltinRunner::new(10, 10, true); let builtin: BuiltinRunner = range_check.into(); @@ -627,7 +604,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_name_ec_op() { let ec_op = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); let builtin: BuiltinRunner = ec_op.into(); @@ -635,7 +611,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_name_ecdsa() { let signature = SignatureBuiltinRunner::new(&EcdsaInstanceDef::new(10), true); let builtin: BuiltinRunner = signature.into(); @@ -643,7 +618,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_name_output() { let output = OutputBuiltinRunner::new(true); let builtin: BuiltinRunner = output.into(); @@ -651,7 +625,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_bitwise_with_items() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::new(10), @@ -698,7 +671,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_ec_op_with_items() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), true)); @@ -742,7 +714,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_hash_with_items() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(10, true)); @@ -786,7 +757,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_range_check_with_items() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(10, 12, true)); @@ -830,7 +800,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_keccak_with_items() { let builtin = BuiltinRunner::Keccak(KeccakBuiltinRunner::new( &KeccakInstanceDef::new(10, vec![200; 8]), @@ -843,7 +812,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_output() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let vm = vm!(); @@ -853,7 +821,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_range_check() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(8, 8, true)); let vm = vm!(); @@ -861,7 +828,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_hash() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(1, true)); let vm = vm!(); @@ -869,7 +835,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_bitwise() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -880,7 +845,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_ec_op() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true)); @@ -889,7 +853,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_keccak() { let builtin = BuiltinRunner::Keccak(KeccakBuiltinRunner::new( &KeccakInstanceDef::default(), @@ -900,7 +863,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_usage_range_check() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(8, 8, true)); let memory = memory![((0, 0), 1), ((0, 1), 2), ((0, 2), 3), ((0, 3), 4)]; @@ -908,7 +870,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_usage_output() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let memory = memory![((0, 0), 1), ((0, 1), 2), ((0, 2), 3), ((0, 3), 4)]; @@ -916,7 +877,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_usage_hash() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(256, true)); let memory = memory![((0, 0), 1), ((0, 1), 2), ((0, 2), 3), ((0, 3), 4)]; @@ -924,7 +884,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_usage_ec_op() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true)); @@ -933,7 +892,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_usage_bitwise() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -944,7 +902,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_bitwise() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -954,7 +911,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_keccak_zero_case() { let builtin = BuiltinRunner::Keccak(KeccakBuiltinRunner::new( &KeccakInstanceDef::default(), @@ -964,7 +920,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_keccak_non_zero_case() { let builtin = BuiltinRunner::Keccak(KeccakBuiltinRunner::new( &KeccakInstanceDef::default(), @@ -974,35 +929,30 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_ec_op() { let builtin = BuiltinRunner::EcOp(EcOpBuiltinRunner::new(&EcOpInstanceDef::new(10), true)); assert_eq!(builtin.get_used_diluted_check_units(270, 7), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_hash() { let builtin = BuiltinRunner::Hash(HashBuiltinRunner::new(16, true)); assert_eq!(builtin.get_used_diluted_check_units(270, 7), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_range_check() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(8, 8, true)); assert_eq!(builtin.get_used_diluted_check_units(270, 7), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_diluted_check_units_output() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); assert_eq!(builtin.get_used_diluted_check_units(270, 7), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_segment_addresses_test() { let bitwise_builtin: BuiltinRunner = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true).into(); @@ -1023,7 +973,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_for_output() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let vm = vm!(); @@ -1032,7 +981,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_empty_memory() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -1044,7 +992,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_empty_offsets() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -1058,7 +1005,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_bitwise_missing_memory_cells_with_offsets() { let builtin = BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( &BitwiseInstanceDef::default(), @@ -1081,7 +1027,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_bitwise_missing_memory_cells() { let mut bitwise_builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true); @@ -1109,7 +1054,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_hash_missing_memory_cells_with_offsets() { let builtin: BuiltinRunner = HashBuiltinRunner::new(8, true).into(); let mut vm = vm!(); @@ -1130,7 +1074,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_hash_missing_memory_cells() { let hash_builtin = HashBuiltinRunner::new(8, true); @@ -1149,7 +1092,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_range_check_missing_memory_cells_with_offsets() { let range_check_builtin = RangeCheckBuiltinRunner::new(8, 8, true); let builtin: BuiltinRunner = range_check_builtin.into(); @@ -1173,7 +1115,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_range_check_missing_memory_cells() { let builtin: BuiltinRunner = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(8, 8, true)); @@ -1190,7 +1131,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_range_check_empty() { let range_check_builtin = RangeCheckBuiltinRunner::new(8, 8, true); @@ -1204,7 +1144,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_checks_validate_auto_deductions() { let builtin: BuiltinRunner = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true).into(); @@ -1227,7 +1166,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_ec_op_check_memory_empty() { let ec_op_builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); @@ -1241,7 +1179,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_ec_op_check_memory_1_element() { let ec_op_builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); @@ -1259,7 +1196,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_ec_op_check_memory_3_elements() { let ec_op_builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); @@ -1278,7 +1214,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_ec_op_missing_memory_cells_with_offsets() { let builtin: BuiltinRunner = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true).into(); @@ -1301,7 +1236,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_security_ec_op_check_memory_gap() { let ec_op_builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); @@ -1334,7 +1268,6 @@ mod tests { /// Test that get_used_perm_range_check_units() returns zero when the /// builtin is a BitwiseBuiltinRunner. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_perm_range_check_units_bitwise() { let builtin_runner: BuiltinRunner = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true).into(); @@ -1348,7 +1281,6 @@ mod tests { /// Test that get_used_perm_range_check_units() returns zero when the /// builtin is an EcOpBuiltinRunner. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_perm_range_check_units_ec_op() { let builtin_runner: BuiltinRunner = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true).into(); @@ -1362,7 +1294,6 @@ mod tests { /// Test that get_used_perm_range_check_units() returns zero when the /// builtin is a HashBuiltinRunner. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_perm_range_check_units_hash() { let builtin_runner: BuiltinRunner = HashBuiltinRunner::new(8, true).into(); let mut vm = vm!(); @@ -1375,7 +1306,6 @@ mod tests { /// Test that get_used_perm_range_check_units() returns zero when the /// builtin is an OutputBuiltinRunner. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_perm_range_check_units_output() { let builtin_runner: BuiltinRunner = OutputBuiltinRunner::new(true).into(); let mut vm = vm!(); @@ -1388,7 +1318,6 @@ mod tests { /// Test that get_used_perm_range_check_units() calls the corresponding /// method when the builtin is a RangeCheckBuiltinRunner. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_perm_range_check_units_range_check() { let builtin_runner: BuiltinRunner = RangeCheckBuiltinRunner::new(8, 8, true).into(); let mut vm = vm!(); @@ -1399,7 +1328,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_ratio_tests() { let bitwise_builtin: BuiltinRunner = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true).into(); @@ -1420,7 +1348,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn bitwise_get_used_instances_test() { let mut vm = vm!(); vm.segments.segment_used_sizes = Some(vec![4]); @@ -1431,7 +1358,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn ec_op_get_used_instances_test() { let mut vm = vm!(); vm.segments.segment_used_sizes = Some(vec![4]); @@ -1442,7 +1368,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn hash_get_used_instances_test() { let mut vm = vm!(); vm.segments.segment_used_sizes = Some(vec![4]); @@ -1452,7 +1377,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn output_get_used_instances_test() { let mut vm = vm!(); vm.segments.segment_used_sizes = Some(vec![4]); @@ -1461,7 +1385,6 @@ mod tests { assert_eq!(output_builtin.get_used_instances(&vm.segments), Ok(4)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn range_check_get_used_instances_test() { let mut vm = vm!(); vm.segments.segment_used_sizes = Some(vec![4]); @@ -1472,7 +1395,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn runners_final_stack() { let mut builtins = vec![ BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( @@ -1500,7 +1422,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn runners_set_stop_ptr() { let builtins = vec![ BuiltinRunner::Bitwise(BitwiseBuiltinRunner::new( diff --git a/src/vm/runners/builtin_runner/output.rs b/src/vm/runners/builtin_runner/output.rs index 131d23c4ee..618faa0f1a 100644 --- a/src/vm/runners/builtin_runner/output.rs +++ b/src/vm/runners/builtin_runner/output.rs @@ -1,4 +1,3 @@ -use crate::stdlib::prelude::*; use crate::types::relocatable::{MaybeRelocatable, Relocatable}; use crate::vm::errors::memory_errors::MemoryError; use crate::vm::errors::runner_errors::RunnerError; @@ -127,7 +126,6 @@ impl Default for OutputBuiltinRunner { mod tests { use super::*; use crate::relocatable; - use crate::stdlib::collections::HashMap; use crate::vm::vm_memory::memory::Memory; use crate::{ utils::test_utils::*, @@ -136,12 +134,9 @@ mod tests { vm_core::VirtualMachine, }, }; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::collections::HashMap; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_instances() { let builtin = OutputBuiltinRunner::new(true); @@ -152,7 +147,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack() { let mut builtin = OutputBuiltinRunner::new(true); @@ -176,7 +170,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_stop_pointer() { let mut builtin = OutputBuiltinRunner::new(true); @@ -204,7 +197,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_when_notincluded() { let mut builtin = OutputBuiltinRunner::new(false); @@ -228,7 +220,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_non_relocatable() { let mut builtin = OutputBuiltinRunner::new(true); @@ -252,7 +243,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_test() { let builtin: BuiltinRunner = OutputBuiltinRunner::new(true).into(); @@ -267,7 +257,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units() { let builtin = OutputBuiltinRunner::new(true); @@ -277,7 +266,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_segments_for_output() { let mut builtin = OutputBuiltinRunner::new(true); let mut segments = MemorySegmentManager::new(); @@ -286,7 +274,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_initial_stack_for_output_with_base() { let mut builtin = OutputBuiltinRunner::new(true); builtin.base = 1; @@ -299,7 +286,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_segment_addresses() { let builtin = OutputBuiltinRunner::new(true); @@ -307,7 +293,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_missing_segment_used_sizes() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let vm = vm!(); @@ -319,7 +304,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_empty() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let mut vm = vm!(); @@ -329,7 +313,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let mut vm = vm!(); @@ -347,7 +330,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_missing_segment_used_sizes() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let vm = vm!(); @@ -359,7 +341,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_empty() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let mut vm = vm!(); @@ -369,7 +350,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let mut vm = vm!(); @@ -379,7 +359,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_used_instances_missing_segments() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let memory_segment_manager = MemorySegmentManager::new(); @@ -391,7 +370,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_used_instances_valid() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let mut memory_segment_manager = MemorySegmentManager::new(); @@ -401,7 +379,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_deduce_memory_cell_output_builtin() { let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); let mut vm = vm!(); @@ -424,7 +401,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_add_validation_rule() { let builtin = OutputBuiltinRunner::new(true); let mut vm = vm!(); diff --git a/src/vm/runners/builtin_runner/range_check.rs b/src/vm/runners/builtin_runner/range_check.rs index 7eb286a570..edb5e34f46 100644 --- a/src/vm/runners/builtin_runner/range_check.rs +++ b/src/vm/runners/builtin_runner/range_check.rs @@ -1,9 +1,3 @@ -use crate::stdlib::{ - cmp::{max, min}, - ops::Shl, - prelude::*, -}; - use crate::{ math_utils::safe_div_usize, types::{ @@ -25,6 +19,10 @@ use crate::{ use felt::Felt; use num_integer::Integer; use num_traits::{One, ToPrimitive, Zero}; +use std::{ + cmp::{max, min}, + ops::Shl, +}; use super::RANGE_CHECK_BUILTIN_NAME; @@ -250,7 +248,6 @@ impl RangeCheckBuiltinRunner { mod tests { use super::*; use crate::relocatable; - use crate::stdlib::collections::HashMap; use crate::vm::vm_memory::memory::Memory; use crate::{ hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, @@ -261,12 +258,9 @@ mod tests { vm_core::VirtualMachine, }, }; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::collections::HashMap; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_instances() { let builtin = RangeCheckBuiltinRunner::new(10, 12, true); @@ -277,7 +271,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack() { let mut builtin = RangeCheckBuiltinRunner::new(10, 12, true); @@ -301,7 +294,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_stop_pointer() { let mut builtin = RangeCheckBuiltinRunner::new(10, 12, true); @@ -329,7 +321,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_when_notincluded() { let mut builtin = RangeCheckBuiltinRunner::new(10, 12, false); @@ -353,7 +344,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_non_relocatable() { let mut builtin = RangeCheckBuiltinRunner::new(10, 12, true); @@ -377,7 +367,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_test() { let builtin: BuiltinRunner = RangeCheckBuiltinRunner::new(10, 12, true).into(); @@ -423,7 +412,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units() { let builtin = RangeCheckBuiltinRunner::new(10, 12, true); @@ -467,7 +455,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_segments_for_range_check() { let mut builtin = RangeCheckBuiltinRunner::new(8, 8, true); let mut segments = MemorySegmentManager::new(); @@ -476,7 +463,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_initial_stack_for_range_check_with_base() { let mut builtin = RangeCheckBuiltinRunner::new(8, 8, true); builtin.base = 1; @@ -489,7 +475,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_segment_addresses() { let builtin = RangeCheckBuiltinRunner::new(8, 8, true); @@ -497,7 +482,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_missing_segment_used_sizes() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(256, 8, true)); let vm = vm!(); @@ -509,7 +493,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_empty() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(256, 8, true)); let mut vm = vm!(); @@ -519,7 +502,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(256, 8, true)); let mut vm = vm!(); @@ -537,21 +519,18 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_base() { let builtin = RangeCheckBuiltinRunner::new(8, 8, true); assert_eq!(builtin.base(), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_ratio() { let builtin = RangeCheckBuiltinRunner::new(8, 8, true); assert_eq!(builtin.ratio(), 8); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_missing_segment_used_sizes() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(256, 8, true)); let vm = vm!(); @@ -563,7 +542,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_empty() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(256, 8, true)); let mut vm = vm!(); @@ -573,7 +551,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(256, 8, true)); let mut vm = vm!(); @@ -583,7 +560,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_usage_succesful_a() { let builtin = RangeCheckBuiltinRunner::new(8, 8, true); let memory = memory![((0, 0), 1), ((0, 1), 2), ((0, 2), 3), ((0, 3), 4)]; @@ -591,7 +567,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_usage_succesful_b() { let builtin = RangeCheckBuiltinRunner::new(8, 8, true); let memory = memory![ @@ -604,7 +579,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_usage_succesful_c() { let builtin = RangeCheckBuiltinRunner::new(8, 8, true); let memory = memory![ @@ -619,7 +593,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_check_empty_memory() { let builtin = RangeCheckBuiltinRunner::new(8, 8, true); let memory = Memory::new(); @@ -628,7 +601,6 @@ mod tests { /// Test that the method get_used_perm_range_check_units works as intended. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_perm_range_check_units() { let builtin_runner = RangeCheckBuiltinRunner::new(8, 8, true); let mut vm = vm!(); diff --git a/src/vm/runners/builtin_runner/signature.rs b/src/vm/runners/builtin_runner/signature.rs index b9c29f7c33..1095de4a93 100644 --- a/src/vm/runners/builtin_runner/signature.rs +++ b/src/vm/runners/builtin_runner/signature.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{cell::RefCell, collections::HashMap, prelude::*, rc::Rc}; - use crate::{ math_utils::safe_div_usize, types::{ @@ -21,6 +19,7 @@ use crate::{ use felt::Felt; use num_integer::div_ceil; use starknet_crypto::{verify, FieldElement, Signature}; +use std::{cell::RefCell, collections::HashMap, rc::Rc}; use super::SIGNATURE_BUILTIN_NAME; @@ -271,11 +270,7 @@ mod tests { }, }; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_min_step_not_reached() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); let mut vm = vm!(); @@ -290,7 +285,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_valid() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::new(10), true); let mut vm = vm!(); @@ -300,7 +294,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_segments_for_ecdsa() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); let mut segments = MemorySegmentManager::new(); @@ -309,7 +302,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_instances() { let builtin: BuiltinRunner = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true).into(); @@ -321,7 +313,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -345,7 +336,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_stop_pointer() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -373,7 +363,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_error_non_relocatable() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -397,7 +386,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_segment_addresses() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -405,7 +393,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_missing_segment_used_sizes() { let builtin = BuiltinRunner::Signature(SignatureBuiltinRunner::new( &EcdsaInstanceDef::default(), @@ -420,7 +407,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses_empty() { let builtin = BuiltinRunner::Signature(SignatureBuiltinRunner::new( &EcdsaInstanceDef::default(), @@ -433,7 +419,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_accesses() { let builtin = BuiltinRunner::Signature(SignatureBuiltinRunner::new( &EcdsaInstanceDef::default(), @@ -454,7 +439,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_missing_segment_used_sizes() { let builtin = BuiltinRunner::Signature(SignatureBuiltinRunner::new( &EcdsaInstanceDef::default(), @@ -469,7 +453,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_empty() { let builtin = BuiltinRunner::Signature(SignatureBuiltinRunner::new( &EcdsaInstanceDef::default(), @@ -482,7 +465,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells() { let builtin = BuiltinRunner::Signature(SignatureBuiltinRunner::new( &EcdsaInstanceDef::default(), @@ -495,7 +477,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_initial_stack_for_range_check_with_base() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); builtin.base = 1; @@ -508,14 +489,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initial_stack_not_included_test() { let ecdsa_builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), false); assert_eq!(ecdsa_builtin.initial_stack(), Vec::new()) } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_test() { let memory = Memory::new(); let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -524,21 +503,18 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_ratio() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); assert_eq!(builtin.ratio(), 512); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_base() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); assert_eq!(builtin.base(), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_memory_segment_addresses() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -546,7 +522,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell() { let memory = Memory::new(); let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -555,7 +530,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_allocated_memory_units_safe_div_fail() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); let mut vm = vm!(); @@ -567,7 +541,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_safe_div_fail() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); let mut vm = vm!(); @@ -586,7 +559,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_used_cells_and_allocated_size_insufficient_allocated() { let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); let mut vm = vm!(); @@ -601,7 +573,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_invalid_stop_pointer() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); let mut vm = vm!(); @@ -617,7 +588,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn final_stack_no_used_instances() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); let mut vm = vm!(); diff --git a/src/vm/runners/cairo_runner.rs b/src/vm/runners/cairo_runner.rs index 4eeac14a8e..8f210c33dd 100644 --- a/src/vm/runners/cairo_runner.rs +++ b/src/vm/runners/cairo_runner.rs @@ -1,10 +1,3 @@ -use crate::stdlib::{ - any::Any, - collections::{HashMap, HashSet}, - ops::{Add, Sub}, - prelude::*, -}; - use crate::{ hint_processor::hint_processor_definition::{HintProcessor, HintReference}, math_utils::safe_div_usize, @@ -46,6 +39,12 @@ use crate::{ use felt::Felt; use num_integer::div_rem; use num_traits::Zero; +use std::{ + any::Any, + collections::{HashMap, HashSet}, + io, + ops::{Add, Sub}, +}; use super::builtin_runner::{ KeccakBuiltinRunner, BITWISE_BUILTIN_NAME, EC_OP_BUILTIN_NAME, HASH_BUILTIN_NAME, @@ -71,7 +70,6 @@ impl From> for CairoArg { } } -#[derive(Debug)] pub struct CairoRunner { pub(crate) program: Program, layout: CairoLayout, @@ -240,7 +238,6 @@ impl CairoRunner { self.layout._name.clone(), )); } - drop(inserted_builtins); vm.builtin_runners = builtin_runners; Ok(()) @@ -838,6 +835,50 @@ impl CairoRunner { }) } + pub fn get_output(&mut self, vm: &mut VirtualMachine) -> Result { + let mut output = Vec::::new(); + self.write_output(vm, &mut output)?; + let output = String::from_utf8(output).map_err(|_| RunnerError::FailedStringConversion)?; + Ok(output) + } + + /// Writes the values hosted in the output builtin's segment. + /// Does nothing if the output builtin is not present in the program. + pub fn write_output( + &mut self, + vm: &mut VirtualMachine, + stdout: &mut dyn io::Write, + ) -> Result<(), RunnerError> { + let (_, builtin) = match vm + .builtin_runners + .iter() + .find(|(k, _)| k == &OUTPUT_BUILTIN_NAME) + { + Some(x) => x, + _ => return Ok(()), + }; + + let segment_used_sizes = vm.segments.compute_effective_sizes(); + let segment_index = builtin.base(); + #[allow(deprecated)] + for i in 0..segment_used_sizes[segment_index] { + let formatted_value = match vm + .segments + .memory + .get(&Relocatable::from((segment_index as isize, i))) + { + Some(val) => match val.as_ref() { + MaybeRelocatable::Int(num) => format!("{}", num.to_bigint()), + MaybeRelocatable::RelocatableValue(rel) => format!("{}", rel), + }, + _ => "".to_string(), + }; + writeln!(stdout, "{formatted_value}").map_err(|_| RunnerError::WriteFail)?; + } + + Ok(()) + } + // Finalizes the segments. // Note: // 1. end_run() must precede a call to this method. @@ -1161,7 +1202,6 @@ impl Sub for ExecutionResources { #[cfg(test)] mod tests { use super::*; - use crate::stdlib::collections::{HashMap, HashSet}; use crate::vm::vm_memory::memory::MemoryCell; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::{ @@ -1175,12 +1215,12 @@ mod tests { use assert_matches::assert_matches; use felt::felt_str; use num_traits::One; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::{ + collections::{HashMap, HashSet}, + path::Path, + }; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_memory_usage_ok_case() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![RANGE_CHECK_BUILTIN_NAME, OUTPUT_BUILTIN_NAME]; @@ -1192,7 +1232,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_memory_usage_err_case() { let program = program!(); @@ -1216,7 +1255,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_builtins_with_disordered_builtins() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![RANGE_CHECK_BUILTIN_NAME, OUTPUT_BUILTIN_NAME]; @@ -1226,7 +1264,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn create_cairo_runner_with_ordered_but_missing_builtins() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME, SIGNATURE_BUILTIN_NAME]; @@ -1235,7 +1272,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_segments_with_base() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME]; @@ -1269,7 +1305,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_segments_no_base() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME]; @@ -1298,7 +1333,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_state_empty_data_and_stack() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME]; @@ -1319,7 +1353,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_state_some_data_empty_stack() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program!( @@ -1342,7 +1375,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_state_empty_data_some_stack() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME]; @@ -1359,7 +1391,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_state_no_program_base() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME]; @@ -1398,7 +1429,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_function_entrypoint_empty_stack() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME]; @@ -1420,7 +1450,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_function_entrypoint_some_stack() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME]; @@ -1471,7 +1500,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_main_entrypoint() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program!(main = Some(1),); @@ -1484,16 +1512,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_state_program_segment_accessed_addrs() { // This test checks that all addresses from the program segment are marked as accessed at VM state initialization. // The fibonacci program has 24 instructions, so there should be 24 accessed addresses, // from (0, 0) to (0, 23). - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/fibonacci.json"), - Some("main"), - ) - .unwrap(); + let program = Program::from_file(Path::new("cairo_programs/fibonacci.json"), Some("main")) + .expect("Call to `Program::from_file()` failed."); let mut cairo_runner = cairo_runner!(program); let mut vm = vm!(); @@ -1508,7 +1532,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_vm_no_builtins() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program!(main = Some(1),); @@ -1525,7 +1548,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_vm_with_range_check_valid() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program!(builtins = vec![RANGE_CHECK_BUILTIN_NAME], main = Some(1),); @@ -1554,7 +1576,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_vm_with_range_check_invalid() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program!(builtins = vec![RANGE_CHECK_BUILTIN_NAME], main = Some(1),); @@ -1578,7 +1599,6 @@ mod tests { //Integration tests for initialization phase #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Program used: func myfunc(a: felt) -> (r: felt): let b = a * 2 @@ -1649,7 +1669,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins output @@ -1727,7 +1746,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins range_check @@ -1822,7 +1840,6 @@ mod tests { //Integration tests for initialization + execution phase #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: func myfunc(a: felt) -> (r: felt): let b = a * 2 @@ -1892,7 +1909,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins range_check @@ -1993,7 +2009,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins output @@ -2106,7 +2121,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins output range_check @@ -2266,7 +2280,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Memory from this test is taken from a cairo program execution Program used: func main(): @@ -2366,7 +2379,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Program used: %builtins output @@ -2522,7 +2534,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Program used: %builtins output @@ -2690,8 +2701,7 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] - fn get_output_from_preset_memory() { + fn write_output_from_preset_memory() { let program = program![OUTPUT_BUILTIN_NAME]; let mut cairo_runner = cairo_runner!(program); let mut vm = vm!(); @@ -2702,14 +2712,12 @@ mod tests { vm.segments = segments![((2, 0), 1), ((2, 1), 2)]; vm.segments.segment_used_sizes = Some(vec![0, 0, 2]); - - let mut output_buffer = String::new(); - vm.write_output(&mut output_buffer).unwrap(); - assert_eq!(&output_buffer, "1\n2\n"); + let mut stdout = Vec::::new(); + cairo_runner.write_output(&mut vm, &mut stdout).unwrap(); + assert_eq!(String::from_utf8(stdout), Ok(String::from("1\n2\n"))); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins output @@ -2720,7 +2728,7 @@ mod tests { serialize_word(a) return() end */ - fn get_output_from_program() { + fn write_output_from_program() { //Initialization Phase let program = program!( builtins = vec![OUTPUT_BUILTIN_NAME], @@ -2761,13 +2769,12 @@ mod tests { Ok(()) ); - let mut output_buffer = String::new(); - vm.write_output(&mut output_buffer).unwrap(); - assert_eq!(&output_buffer, "1\n17\n"); + let mut stdout = Vec::::new(); + cairo_runner.write_output(&mut vm, &mut stdout).unwrap(); + assert_eq!(String::from_utf8(stdout), Ok(String::from("1\n17\n"))); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins output @@ -2802,14 +2809,16 @@ mod tests { Ok(()) ); - let mut output_buffer = String::new(); - vm.write_output(&mut output_buffer).unwrap(); - assert_eq!(&output_buffer, "\n2:0\n"); + let mut stdout = Vec::::new(); + cairo_runner.write_output(&mut vm, &mut stdout).unwrap(); + assert_eq!( + String::from_utf8(stdout), + Ok(String::from("\n2:0\n")) + ); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] - fn get_output_from_preset_memory_neg_output() { + fn write_output_from_preset_memory_neg_output() { let program = program![OUTPUT_BUILTIN_NAME]; let mut cairo_runner = cairo_runner!(program); let mut vm = vm!(); @@ -2825,16 +2834,14 @@ mod tests { ) )]; vm.segments.segment_used_sizes = Some(vec![0, 0, 1]); - - let mut output_buffer = String::new(); - vm.write_output(&mut output_buffer).unwrap(); - assert_eq!(&output_buffer, "-1\n"); + let mut stdout = Vec::::new(); + cairo_runner.write_output(&mut vm, &mut stdout).unwrap(); + assert_eq!(String::from_utf8(stdout), Ok(String::from("-1\n"))); } - /// Test that `get_output()` works when the `output` builtin is not the first one. + /// Test that `write_output()` works when the `output` builtin is not the first one. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] - fn get_output_unordered_builtins() { + fn write_output_unordered_builtins() { //Initialization Phase let program = program!( builtins = vec![OUTPUT_BUILTIN_NAME, BITWISE_BUILTIN_NAME], @@ -2888,13 +2895,14 @@ mod tests { Ok(()) ); - let mut output_buffer = String::new(); - vm.write_output(&mut output_buffer).unwrap(); - assert_eq!(&output_buffer, "1\n17\n"); + let mut stdout = Vec::::new(); + cairo_runner + .write_output(&mut vm, &mut stdout) + .expect("Call to `write_output()` failed."); + assert_eq!(String::from_utf8(stdout), Ok(String::from("1\n17\n"))); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_all_builtins_in_order() { let program = program![ OUTPUT_BUILTIN_NAME, @@ -2914,7 +2922,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins range_check @@ -2981,7 +2988,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins range_check @@ -3052,7 +3058,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: %builtins range_check @@ -3162,7 +3167,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_constants() { let program_constants = HashMap::from([ ("MAX".to_string(), Felt::new(300)), @@ -3174,7 +3178,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes_missing_segment_used_sizes() { let program = program!(); @@ -3192,7 +3195,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes_empty() { let program = program!(); @@ -3205,7 +3207,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes_empty_builtins() { let program = program!(); @@ -3220,7 +3221,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes_empty_accesses() { let program = program!(); @@ -3238,7 +3238,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes() { let program = program!(); @@ -3260,7 +3259,6 @@ mod tests { /// Test that check_diluted_check_usage() works without a diluted pool /// instance. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_diluted_check_usage_without_pool_instance() { let program = program!(); @@ -3273,7 +3271,6 @@ mod tests { /// Test that check_diluted_check_usage() works without builtin runners. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_diluted_check_usage_without_builtin_runners() { let program = program!(); @@ -3288,7 +3285,6 @@ mod tests { /// Test that check_diluted_check_usage() fails when there aren't enough /// allocated units. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_diluted_check_usage_insufficient_allocated_cells() { let program = program!(); @@ -3308,7 +3304,6 @@ mod tests { /// Test that check_diluted_check_usage() succeeds when all the conditions /// are met. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_diluted_check_usage() { let program = program!(); @@ -3324,7 +3319,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn end_run_run_already_finished() { let program = program!(); @@ -3342,7 +3336,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn end_run() { let program = program!(); @@ -3365,13 +3358,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn end_run_proof_mode_insufficient_allocated_cells() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/proof_programs/fibonacci.json"), + let program = Program::from_file( + Path::new("cairo_programs/proof_programs/fibonacci.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program, "all", true); @@ -3388,7 +3380,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtin_segments_info_empty() { let program = program!(); @@ -3399,7 +3390,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtin_segments_info_base_not_finished() { let program = program!(); @@ -3417,7 +3407,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_execution_resources_trace_not_enabled() { let program = program!(); @@ -3436,7 +3425,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_execution_resources_empty_builtins() { let program = program!(); @@ -3456,7 +3444,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_execution_resources() { let program = program!(); @@ -3482,7 +3469,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_segments_run_not_ended() { let program = program!(); let mut cairo_runner = cairo_runner!(program); @@ -3494,7 +3480,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_segments_run_ended_empty_no_prog_base() { let program = program!(); let mut cairo_runner = cairo_runner!(program); @@ -3508,7 +3493,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_segments_run_ended_empty_no_exec_base() { let program = program!(); let mut cairo_runner = cairo_runner!(program); @@ -3523,7 +3507,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_segments_run_ended_empty_noproof_mode() { let program = program!(); let mut cairo_runner = cairo_runner!(program); @@ -3538,7 +3521,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_segments_run_ended_emptyproof_mode() { let program = program!(); let mut cairo_runner = cairo_runner!(program, "plain", true); @@ -3552,7 +3534,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_segments_run_ended_not_emptyproof_mode_empty_execution_public_memory() { let mut program = program!(); program.data = vec_data![(1), (2), (3), (4), (5), (6), (7), (8)]; @@ -3585,7 +3566,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_segments_run_ended_not_emptyproof_mode_with_execution_public_memory() { let mut program = program!(); program.data = vec_data![(1), (2), (3), (4)]; @@ -3625,7 +3605,6 @@ mod tests { /// Test that ensures get_perm_range_check_limits() returns an error when /// trace is not enabled. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_perm_range_check_limits_trace_not_enabled() { let program = program!(); @@ -3643,7 +3622,6 @@ mod tests { /// Test that ensures get_perm_range_check_limits() returns None when the /// trace is empty (get_perm_range_check_limits returns None). #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_perm_range_check_limits_empty() { let program = program!(); @@ -3657,7 +3635,6 @@ mod tests { /// Test that get_perm_range_check_limits() works correctly when there are /// no builtins. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_perm_range_check_limits_no_builtins() { let program = program!(); @@ -3696,7 +3673,6 @@ mod tests { /// Test that get_perm_range_check_limits() works correctly when there are /// builtins. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_perm_range_check_limits() { let program = program!(); @@ -3725,7 +3701,6 @@ mod tests { /// Test that check_range_check_usage() returns successfully when trace is /// not enabled. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_range_check_usage_perm_range_limits_none() { let program = program!(); @@ -3739,7 +3714,6 @@ mod tests { /// Test that check_range_check_usage() returns successfully when all the /// conditions are met. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_range_check_usage_without_builtins() { let program = program!(); @@ -3762,7 +3736,6 @@ mod tests { /// Test that check_range_check_usage() returns an error if there are /// insufficient allocated cells. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_range_check_usage_insufficient_allocated_cells() { let program = program!(); @@ -3790,7 +3763,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_initial_fp_is_none_without_initialization() { let program = program!(); @@ -3800,7 +3772,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_initial_fp_can_be_obtained() { //This test works with basic Program definition, will later be updated to use Program::new() when fully defined let program = program![OUTPUT_BUILTIN_NAME]; @@ -3819,7 +3790,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_used_cells_valid_case() { let program = program![RANGE_CHECK_BUILTIN_NAME, OUTPUT_BUILTIN_NAME]; let mut cairo_runner = cairo_runner!(program); @@ -3832,7 +3802,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_used_cells_get_used_cells_and_allocated_size_error() { let program = program!(); @@ -3860,7 +3829,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_used_cells_check_memory_usage_error() { let program = program!(); @@ -3886,7 +3854,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn check_used_cells_check_diluted_check_usage_error() { let program = program![RANGE_CHECK_BUILTIN_NAME, OUTPUT_BUILTIN_NAME]; let cairo_runner = cairo_runner!(program); @@ -3903,7 +3870,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_all_builtins() { let program = program!(); @@ -3926,7 +3892,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_all_builtins_maintain_program_order() { let program = program![ HASH_BUILTIN_NAME, @@ -3953,7 +3918,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_function_runner() { let program = program!(); @@ -3992,7 +3956,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_segments_incorrect_layout_plain_one_builtin() { let program = program![OUTPUT_BUILTIN_NAME]; let mut vm = vm!(); @@ -4007,7 +3970,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_segments_incorrect_layout_plain_two_builtins() { let program = program![OUTPUT_BUILTIN_NAME, HASH_BUILTIN_NAME]; let mut vm = vm!(); @@ -4022,7 +3984,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_segments_incorrect_layout_small_two_builtins() { let program = program![OUTPUT_BUILTIN_NAME, BITWISE_BUILTIN_NAME]; let mut vm = vm!(); @@ -4036,7 +3997,6 @@ mod tests { ); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_main_entrypoint_proof_mode_empty_program() { let program = program!(start = Some(0), end = Some(0), main = Some(8),); let mut runner = cairo_runner!(program); @@ -4055,7 +4015,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn initialize_main_entrypoint_proof_mode_empty_program_two_builtins() { let program = program!( start = Some(0), @@ -4080,7 +4039,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn can_get_the_runner_program_builtins() { let program = program!( start = Some(0), @@ -4094,7 +4052,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn set_entrypoint_main_default() { let program = program!(); let mut cairo_runner = cairo_runner!(program); @@ -4121,7 +4078,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn set_entrypoint_main() { let program = program!(); let mut cairo_runner = cairo_runner!(program); @@ -4162,7 +4118,6 @@ mod tests { /// Test that set_entrypoint() fails when the entrypoint doesn't exist. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn set_entrypoint_main_non_existent() { let program = program!(); let mut cairo_runner = cairo_runner!(program); @@ -4189,7 +4144,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn read_return_values_test() { let mut program = program!(); program.data = vec_data![(1), (2), (3), (4), (5), (6), (7), (8)]; @@ -4212,7 +4166,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn read_return_values_test_with_run_not_ended() { let mut program = program!(); program.data = vec_data![(1), (2), (3), (4), (5), (6), (7), (8)]; @@ -4229,7 +4182,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn read_return_values_test_with_segments_finalized() { let mut program = program!(); program.data = vec_data![(1), (2), (3), (4), (5), (6), (7), (8)]; @@ -4247,7 +4199,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn read_return_values_updates_builtin_stop_ptr_one_builtin_empty() { let mut program = program![OUTPUT_BUILTIN_NAME]; program.data = vec_data![(1), (2), (3), (4), (5), (6), (7), (8)]; @@ -4278,7 +4229,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn read_return_values_updates_builtin_stop_ptr_one_builtin_one_element() { let mut program = program![OUTPUT_BUILTIN_NAME]; program.data = vec_data![(1), (2), (3), (4), (5), (6), (7), (8)]; @@ -4309,7 +4259,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn read_return_values_updates_builtin_stop_ptr_two_builtins() { let mut program = program![OUTPUT_BUILTIN_NAME, BITWISE_BUILTIN_NAME]; program.data = vec_data![(1), (2), (3), (4), (5), (6), (7), (8)]; @@ -4355,7 +4304,6 @@ mod tests { /// Test that add_additional_hash_builtin() creates an additional builtin. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_additional_hash_builtin() { let program = program!(); let cairo_runner = cairo_runner!(program); @@ -4383,7 +4331,6 @@ mod tests { /// Test that add_additional_hash_builtin() replaces the created runner if called multiple /// times. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_additional_hash_builtin_replace() { let program = program!(); let cairo_runner = cairo_runner!(program); @@ -4410,13 +4357,9 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_from_entrypoint_custom_program_test() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/example_program.json"), - None, - ) - .unwrap(); + let program = + Program::from_file(Path::new("cairo_programs/example_program.json"), None).unwrap(); let mut cairo_runner = cairo_runner!(program); let mut vm = vm!(true); //this true expression dictates that the trace is enabled let mut hint_processor = BuiltinHintProcessor::new_empty(); @@ -4475,7 +4418,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_arg_from_single() { let expected = CairoArg::Single(MaybeRelocatable::from((0, 0))); let value = MaybeRelocatable::from((0, 0)); @@ -4483,7 +4425,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_arg_from_array() { let expected = CairoArg::Array(vec![MaybeRelocatable::from((0, 0))]); let value = vec![MaybeRelocatable::from((0, 0))]; @@ -4491,7 +4432,7 @@ mod tests { } fn setup_execution_resources() -> (ExecutionResources, ExecutionResources) { - let mut builtin_instance_counter: HashMap = HashMap::new(); + let mut builtin_instance_counter: HashMap = HashMap::new(); builtin_instance_counter.insert(OUTPUT_BUILTIN_NAME.to_string(), 8); let execution_resources_1 = ExecutionResources { @@ -4513,7 +4454,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn execution_resources_add() { let (execution_resources_1, execution_resources_2) = setup_execution_resources(); let combined_resources = execution_resources_1 + execution_resources_2; @@ -4533,7 +4473,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn execution_resources_sub() { let (execution_resources_1, execution_resources_2) = setup_execution_resources(); @@ -4554,10 +4493,9 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn run_from_entrypoint_substitute_error_message_test() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/bad_programs/error_msg_function.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/error_msg_function.json"), None, ) .unwrap(); @@ -4596,10 +4534,9 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_final_stack_range_check_builtin() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/assert_le_felt_hint.json"), + let program = Program::from_file( + Path::new("cairo_programs/assert_le_felt_hint.json"), Some("main"), ) .unwrap(); @@ -4619,13 +4556,9 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_final_stack_4_builtins() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/integration.json"), - Some("main"), - ) - .unwrap(); + let program = + Program::from_file(Path::new("cairo_programs/integration.json"), Some("main")).unwrap(); let mut runner = cairo_runner!(program); let mut vm = vm!(); let end = runner.initialize(&mut vm).unwrap(); @@ -4642,13 +4575,9 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_builtins_final_stack_no_builtins() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/fibonacci.json"), - Some("main"), - ) - .unwrap(); + let program = + Program::from_file(Path::new("cairo_programs/fibonacci.json"), Some("main")).unwrap(); let mut runner = cairo_runner!(program); let mut vm = vm!(); let end = runner.initialize(&mut vm).unwrap(); @@ -4665,14 +4594,10 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn filter_unused_builtins_test() { - let program = Program::from_bytes( - include_bytes!("../../../cairo_programs/integration.json"), - Some("main"), - ) - .unwrap(); + let program = + Program::from_file(Path::new("cairo_programs/integration.json"), Some("main")).unwrap(); let mut runner = cairo_runner!(program); let mut vm = vm!(); let end = runner.initialize(&mut vm).unwrap(); diff --git a/src/vm/security.rs b/src/vm/security.rs index 12cb2689e7..0ad3d994ed 100644 --- a/src/vm/security.rs +++ b/src/vm/security.rs @@ -1,5 +1,3 @@ -use crate::stdlib::prelude::*; - use num_traits::ToPrimitive; use super::{ @@ -83,7 +81,6 @@ pub fn verify_secure_runner( mod test { use super::*; use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; - use crate::stdlib::collections::HashMap; use crate::types::relocatable::MaybeRelocatable; use crate::types::relocatable::Relocatable; use crate::vm::errors::memory_errors::MemoryError; @@ -94,12 +91,9 @@ mod test { use assert_matches::assert_matches; use felt::Felt; use num_traits::Zero; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::collections::HashMap; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_secure_runner_without_program_base() { let program = program!(); @@ -113,7 +107,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_secure_runner_empty_memory() { let program = program!(main = Some(0),); @@ -126,7 +119,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_secure_runner_program_access_out_of_bounds() { let program = program!(main = Some(0),); @@ -145,7 +137,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_secure_runner_builtin_access_out_of_bounds() { let program = program!(main = Some(0), builtins = vec![RANGE_CHECK_BUILTIN_NAME],); @@ -163,7 +154,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_secure_runner_builtin_access_correct() { let program = program!(main = Some(0), builtins = vec![RANGE_CHECK_BUILTIN_NAME],); @@ -183,7 +173,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_secure_runner_success() { let program = program!( data = vec![ @@ -211,7 +200,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_secure_runner_temporary_memory_properly_relocated() { let program = program!( data = vec![ @@ -239,7 +227,6 @@ mod test { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_secure_runner_temporary_memory_not_fully_relocated() { let program = program!( data = vec![ diff --git a/src/vm/trace/mod.rs b/src/vm/trace/mod.rs index a0e3794ffb..6f699c403a 100644 --- a/src/vm/trace/mod.rs +++ b/src/vm/trace/mod.rs @@ -4,9 +4,9 @@ use super::{ errors::{memory_errors::MemoryError, vm_errors::VirtualMachineError}, vm_memory::memory::Memory, }; -use crate::stdlib::borrow::Cow; use crate::types::relocatable::{MaybeRelocatable, Relocatable}; use num_traits::ToPrimitive; +use std::borrow::Cow; pub mod trace_entry; @@ -56,13 +56,9 @@ mod test { use crate::{utils::test_utils::*, vm::errors::memory_errors::MemoryError}; use assert_matches::assert_matches; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - /// Test that get_perm_range_check_limits() works as intended with an empty /// trace. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_perm_range_check_limits_empty_trace() { let trace = &[]; let memory = Memory::new(); @@ -73,7 +69,6 @@ mod test { /// Test that get_perm_range_check_limits() works as intended with a single /// trace element. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_perm_range_check_limits_single_element() { let trace = &[TraceEntry { pc: (0, 0).into(), @@ -91,7 +86,6 @@ mod test { /// Test that get_perm_range_check_limits() works as intended with multiple /// trace elements. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_perm_range_check_limits_multiple_elements() { let trace = &[ TraceEntry { diff --git a/src/vm/trace/trace_entry.rs b/src/vm/trace/trace_entry.rs index b9221a7d2d..ce27abb48e 100644 --- a/src/vm/trace/trace_entry.rs +++ b/src/vm/trace/trace_entry.rs @@ -1,5 +1,3 @@ -use crate::stdlib::prelude::*; - use crate::vm::errors::trace_errors::TraceError; use crate::{types::relocatable::Relocatable, vm::errors::memory_errors::MemoryError}; use serde::{Deserialize, Serialize}; @@ -39,7 +37,6 @@ mod tests { use super::*; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_relocatable_value() { let value = Relocatable { segment_index: 2, @@ -52,11 +49,7 @@ mod tests { ); } - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_relocatable_value_no_relocation() { let value = Relocatable { segment_index: 2, @@ -72,7 +65,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_temp_segment_address() { let value = Relocatable { segment_index: -2, diff --git a/src/vm/vm_core.rs b/src/vm/vm_core.rs index 72daf227bd..bd469ae037 100644 --- a/src/vm/vm_core.rs +++ b/src/vm/vm_core.rs @@ -1,5 +1,3 @@ -use crate::stdlib::{any::Any, borrow::Cow, collections::HashMap, prelude::*}; - use crate::{ hint_processor::hint_processor_definition::HintProcessor, serde::deserialize_program::ApTracking, @@ -23,13 +21,11 @@ use crate::{ vm_memory::memory_segments::MemorySegmentManager, }, }; - use felt::Felt; use num_traits::{ToPrimitive, Zero}; +use std::{any::Any, borrow::Cow, collections::HashMap}; -use super::runners::builtin_runner::{ - OUTPUT_BUILTIN_NAME, RANGE_CHECK_BUILTIN_NAME, SIGNATURE_BUILTIN_NAME, -}; +use super::runners::builtin_runner::{RANGE_CHECK_BUILTIN_NAME, SIGNATURE_BUILTIN_NAME}; const MAX_TRACEBACK_ENTRIES: u32 = 20; @@ -948,41 +944,9 @@ impl VirtualMachine { self.segments.gen_arg(arg) } - /// Write the values hosted in the output builtin's segment. - /// Does nothing if the output builtin is not present in the program. - pub fn write_output( - &mut self, - writer: &mut impl core::fmt::Write, - ) -> Result<(), VirtualMachineError> { - let (_, builtin) = match self - .builtin_runners - .iter() - .find(|(k, _)| k == &OUTPUT_BUILTIN_NAME) - { - Some(x) => x, - _ => return Ok(()), - }; - - let segment_used_sizes = self.segments.compute_effective_sizes(); - let segment_index = builtin.base(); - #[allow(deprecated)] - for i in 0..segment_used_sizes[segment_index] { - let formatted_value = match self - .segments - .memory - .get(&Relocatable::from((segment_index as isize, i))) - { - Some(val) => match val.as_ref() { - MaybeRelocatable::Int(num) => format!("{}", num.to_bigint()), - MaybeRelocatable::RelocatableValue(rel) => format!("{}", rel), - }, - _ => "".to_string(), - }; - writeln!(writer, "{formatted_value}") - .map_err(|_| VirtualMachineError::FailedToWriteOutput)?; - } - - Ok(()) + /// Calls MemorySegmentManager::compute_effective_sizes() + pub fn compute_effective_sizes(&mut self) -> &Vec { + self.segments.compute_effective_sizes() } } @@ -1086,8 +1050,6 @@ impl VirtualMachineBuilder { #[cfg(test)] mod tests { use super::*; - use crate::stdlib::collections::HashMap; - use crate::types::program::Program; use crate::vm::runners::builtin_runner::{ BITWISE_BUILTIN_NAME, EC_OP_BUILTIN_NAME, HASH_BUILTIN_NAME, }; @@ -1103,6 +1065,7 @@ mod tests { bitwise_instance_def::BitwiseInstanceDef, ec_op_instance_def::EcOpInstanceDef, }, instruction::{Op1Addr, Register}, + program::Program, relocatable::Relocatable, }, utils::test_utils::*, @@ -1115,14 +1078,12 @@ mod tests { }, }; use assert_matches::assert_matches; + use std::collections::HashMap; use felt::felt_str; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::path::Path; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_instruction_encoding_successful_without_imm() { let mut vm = vm!(); vm.segments = segments![((0, 0), 5)]; @@ -1133,7 +1094,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_instruction_encoding_successful_with_imm() { let mut vm = vm!(); @@ -1150,7 +1110,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_instruction_encoding_unsuccesful() { let vm = vm!(); assert_matches!( @@ -1160,7 +1119,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_fp_ap_plus2() { let instruction = Instruction { off0: 1, @@ -1194,7 +1152,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_fp_dst() { let instruction = Instruction { off0: 1, @@ -1228,7 +1185,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_fp_regular() { let instruction = Instruction { off0: 1, @@ -1262,7 +1218,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_fp_dst_num() { let instruction = Instruction { off0: 1, @@ -1297,7 +1252,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_ap_add_with_res() { let instruction = Instruction { off0: 1, @@ -1334,7 +1288,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_ap_add_without_res() { let instruction = Instruction { off0: 1, @@ -1370,7 +1323,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_ap_add1() { let instruction = Instruction { off0: 1, @@ -1407,7 +1359,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_ap_add2() { let instruction = Instruction { off0: 1, @@ -1444,7 +1395,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_ap_regular() { let instruction = Instruction { off0: 1, @@ -1481,7 +1431,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_regular_instruction_no_imm() { let instruction = Instruction { off0: 1, @@ -1515,7 +1464,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_regular_instruction_has_imm() { let instruction = Instruction { off0: 1, @@ -1549,7 +1497,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_jump_with_res() { let instruction = Instruction { off0: 1, @@ -1583,7 +1530,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_jump_without_res() { let instruction = Instruction { off0: 1, @@ -1619,7 +1565,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_jump_rel_with_int_res() { let instruction = Instruction { off0: 1, @@ -1654,7 +1599,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_jump_rel_without_res() { let instruction = Instruction { off0: 1, @@ -1687,7 +1631,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_jump_rel_with_non_int_res() { let instruction = Instruction { off0: 1, @@ -1719,7 +1662,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_jnz_dst_is_zero() { let instruction = Instruction { off0: 1, @@ -1753,7 +1695,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_pc_jnz_dst_is_not_zero() { let instruction = Instruction { off0: 1, @@ -1787,7 +1728,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_registers_all_regular() { let instruction = Instruction { off0: 1, @@ -1826,7 +1766,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn update_registers_mixed_types() { let instruction = Instruction { off0: 1, @@ -1863,21 +1802,18 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_zero_int_value() { let value = MaybeRelocatable::Int(Felt::new(1)); assert!(!VirtualMachine::is_zero(&value)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_zero_relocatable_value() { let value = MaybeRelocatable::from((1, 2)); assert!(!VirtualMachine::is_zero(&value)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op0_opcode_call() { let instruction = Instruction { off0: 1, @@ -1906,7 +1842,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op0_opcode_assert_eq_res_add_with_optionals() { let instruction = Instruction { off0: 1, @@ -1939,7 +1874,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op0_opcode_assert_eq_res_add_without_optionals() { let instruction = Instruction { off0: 1, @@ -1967,7 +1901,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op0_opcode_assert_eq_res_mul_non_zero_op1() { let instruction = Instruction { off0: 1, @@ -2000,7 +1933,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op0_opcode_assert_eq_res_mul_zero_op1() { let instruction = Instruction { off0: 1, @@ -2030,7 +1962,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op0_opcode_assert_eq_res_op1() { let instruction = Instruction { off0: 1, @@ -2060,7 +1991,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op0_opcode_ret() { let instruction = Instruction { off0: 1, @@ -2091,7 +2021,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op1_opcode_call() { let instruction = Instruction { off0: 1, @@ -2119,7 +2048,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op1_opcode_assert_eq_res_add_with_optionals() { let instruction = Instruction { off0: 1, @@ -2151,7 +2079,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op1_opcode_assert_eq_res_add_without_optionals() { let instruction = Instruction { off0: 1, @@ -2178,7 +2105,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op1_opcode_assert_eq_res_mul_non_zero_op0() { let instruction = Instruction { off0: 1, @@ -2210,7 +2136,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op1_opcode_assert_eq_res_mul_zero_op0() { let instruction = Instruction { off0: 1, @@ -2240,7 +2165,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op1_opcode_assert_eq_res_op1_without_dst() { let instruction = Instruction { off0: 1, @@ -2269,7 +2193,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_op1_opcode_assert_eq_res_op1_with_dst() { let instruction = Instruction { off0: 1, @@ -2300,7 +2223,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_res_op1() { let instruction = Instruction { off0: 1, @@ -2330,7 +2252,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_res_add() { let instruction = Instruction { off0: 1, @@ -2360,7 +2281,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_res_mul_int_operands() { let instruction = Instruction { off0: 1, @@ -2390,7 +2310,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_res_mul_relocatable_values() { let instruction = Instruction { off0: 1, @@ -2418,7 +2337,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_res_unconstrained() { let instruction = Instruction { off0: 1, @@ -2446,7 +2364,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_dst_opcode_assert_eq_with_res() { let instruction = Instruction { off0: 1, @@ -2473,7 +2390,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_dst_opcode_assert_eq_without_res() { let instruction = Instruction { off0: 1, @@ -2496,7 +2412,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_dst_opcode_call() { let instruction = Instruction { off0: 1, @@ -2522,7 +2437,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_dst_opcode_ret() { let instruction = Instruction { off0: 1, @@ -2545,7 +2459,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_operands_add_ap() { let inst = Instruction { off0: 0, @@ -2606,7 +2519,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_operands_mul_fp() { let inst = Instruction { off0: 0, @@ -2666,7 +2578,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_jnz() { let instruction = Instruction { off0: 1, @@ -2720,7 +2631,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_operands_deduce_dst_none() { let instruction = Instruction { off0: 2, @@ -2746,7 +2656,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn opcode_assertions_res_unconstrained() { let instruction = Instruction { off0: 1, @@ -2777,7 +2686,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn opcode_assertions_instruction_failed() { let instruction = Instruction { off0: 1, @@ -2814,7 +2722,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn opcode_assertions_instruction_failed_relocatables() { let instruction = Instruction { off0: 1, @@ -2850,7 +2757,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn opcode_assertions_inconsistent_op0() { let instruction = Instruction { off0: 1, @@ -2887,7 +2793,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn opcode_assertions_inconsistent_dst() { let instruction = Instruction { off0: 1, @@ -2923,7 +2828,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /// Test for a simple program execution /// Used program code: /// func main(): @@ -2977,7 +2881,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Test for a simple program execution Used program code: @@ -3092,7 +2995,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /// Test the following program: /// ... /// [ap] = 4 @@ -3203,14 +3105,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_no_pedersen_builtin() { let vm = vm!(); assert_matches!(vm.deduce_memory_cell(Relocatable::from((0, 0))), Ok(None)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_pedersen_builtin_valid() { let mut vm = vm!(); let builtin = HashBuiltinRunner::new(8, true); @@ -3225,7 +3125,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Program used: %builtins output pedersen from starkware.cairo.common.cairo_builtins import HashBuiltin @@ -3312,7 +3211,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_bitwise_builtin_valid_and() { let mut vm = vm!(); let builtin = BitwiseBuiltinRunner::new(&BitwiseInstanceDef::default(), true); @@ -3326,7 +3224,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Program used: %builtins bitwise from starkware.cairo.common.bitwise import bitwise_and @@ -3394,7 +3291,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn deduce_memory_cell_ec_op_builtin_valid() { let mut vm = vm!(); let builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); @@ -3449,7 +3345,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Data taken from this program execution: %builtins output ec_op from starkware.cairo.common.cairo_builtins import EcOpBuiltin @@ -3514,7 +3409,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn verify_auto_deductions_for_ec_op_builtin_valid_points_invalid_result() { let mut builtin = EcOpBuiltinRunner::new(&EcOpInstanceDef::default(), true); builtin.base = 3; @@ -3578,7 +3472,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Program used: %builtins bitwise from starkware.cairo.common.bitwise import bitwise_and @@ -3602,7 +3495,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Program used: %builtins bitwise from starkware.cairo.common.bitwise import bitwise_and @@ -3632,7 +3524,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /* Program used: %builtins output pedersen from starkware.cairo.common.cairo_builtins import HashBuiltin @@ -3666,7 +3557,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn can_get_return_values() { let mut vm = vm!(); vm.set_ap(4); @@ -3681,7 +3571,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_return_values_fails_when_ap_is_0() { let mut vm = vm!(); vm.segments = segments![((1, 0), 1), ((1, 1), 2), ((1, 2), 3), ((1, 3), 4)]; @@ -3710,7 +3599,6 @@ mod tests { */ #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_step_for_preset_memory_with_alloc_hint() { let mut vm = vm!(true); let hint_data_dictionary = HashMap::from([( @@ -3789,7 +3677,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_builtin_runners() { let mut vm = vm!(); let hash_builtin = HashBuiltinRunner::new(8, true); @@ -3806,7 +3693,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn disable_trace() { let mut vm = VirtualMachine::new(true); assert!(vm.trace.is_some()); @@ -3815,7 +3701,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_for_continuous_memory() { let mut vm = vm!(); vm.segments = segments![((1, 0), 2), ((1, 1), 3), ((1, 2), 4)]; @@ -3833,7 +3718,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_for_non_continuous_memory() { let mut vm = vm!(); vm.segments = segments![((1, 0), 2), ((1, 1), 3), ((1, 3), 4)]; @@ -3852,7 +3736,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_continuous_range_for_continuous_memory() { let mut vm = vm!(); vm.segments = segments![((1, 0), 2), ((1, 1), 3), ((1, 2), 4)]; @@ -3869,7 +3752,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_continuous_range_for_non_continuous_memory() { let mut vm = vm!(); vm.segments = segments![((1, 0), 2), ((1, 1), 3), ((1, 3), 4)]; @@ -3881,7 +3763,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_segment_used_size_after_computing_used() { let mut vm = vm!(); vm.segments = segments![ @@ -3898,14 +3779,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_segment_used_size_before_computing_used() { let vm = vm!(); assert_eq!(None, vm.get_segment_used_size(2)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_and_set_pc() { let mut vm = vm!(); vm.set_pc(Relocatable { @@ -3922,7 +3801,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_and_set_fp() { let mut vm = vm!(); vm.set_fp(3); @@ -3936,7 +3814,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_maybe_key_not_in_memory() { let vm = vm!(); assert_eq!( @@ -3949,14 +3826,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_maybe_error() { let vm = vm!(); assert_eq!(vm.get_maybe(&MaybeRelocatable::Int(Felt::new(0_i32))), None,); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn end_run_error() { let mut vm = vm!(); let scopes = exec_scopes_ref!(); @@ -3971,7 +3846,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_temporary_segments() { let mut vm = vm!(); let mut _base = vm.add_temporary_segment(); @@ -3993,7 +3867,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn decode_current_instruction_invalid_encoding() { let mut vm = vm!(); vm.segments = segments![((0, 0), ("112233445566778899", 16))]; @@ -4004,7 +3877,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_relocation_rule_test() { let mut vm = vm!(); @@ -4031,7 +3903,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_relocatable() { let mut vm = vm!(); @@ -4044,7 +3915,6 @@ mod tests { /// Test that the call to .gen_arg() with a bigint and no prime number just /// passes the value through. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_bigint() { let mut vm = vm!(); @@ -4057,7 +3927,6 @@ mod tests { /// Test that the call to .gen_arg() with a bigint and a prime number passes /// the value through after applying the modulo. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_bigint_prime() { let mut vm = vm!(); let prime = felt_str!(felt::PRIME_STR[2..], 16); @@ -4069,7 +3938,6 @@ mod tests { /// Test that the call to .gen_arg() with a Vec writes its /// contents into a new segment and returns a pointer to it. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_vec() { let mut vm = vm!(); @@ -4090,7 +3958,6 @@ mod tests { /// Test that compute_effective_sizes() works as intended. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_effective_sizes() { let mut vm = vm!(); @@ -4106,7 +3973,7 @@ mod tests { ) .expect("Could not load data into memory."); - assert_eq!(vm.segments.compute_effective_sizes(), &vec![4]); + assert_eq!(vm.compute_effective_sizes(), &vec![4]); } /// Test that compute_segment_effective_sizes() works as intended. @@ -4131,7 +3998,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn mark_as_accessed() { let mut vm = vm!(); vm.run_finished = true; @@ -4169,7 +4035,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn mark_as_accessed_run_not_finished() { let mut vm = vm!(); assert_matches!( @@ -4179,7 +4044,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn mark_as_accessed_missing_accessed_addresses() { let mut vm = vm!(); assert_matches!( @@ -4189,13 +4053,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_traceback_entries_bad_usort() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/bad_programs/bad_usort.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/bad_usort.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program, "all", false); @@ -4214,13 +4077,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_traceback_entries_bad_dict_update() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/bad_programs/bad_dict_update.json"), + let program = Program::from_file( + Path::new("cairo_programs/bad_programs/bad_dict_update.json"), Some("main"), ) - .unwrap(); + .expect("Call to `Program::from_file()` failed."); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = cairo_runner!(program, "all", false); @@ -4305,8 +4167,8 @@ mod tests { ); #[cfg(feature = "hooks")] { - let program = crate::types::program::Program::from_bytes( - include_bytes!("../../cairo_programs/sqrt.json"), + let program = crate::types::program::Program::from_file( + Path::new("cairo_programs/sqrt.json"), Some("main"), ) .expect("Call to `Program::from_file()` failed."); diff --git a/src/vm/vm_memory/memory.rs b/src/vm/vm_memory/memory.rs index da80a04cc2..6f6afe4892 100644 --- a/src/vm/vm_memory/memory.rs +++ b/src/vm/vm_memory/memory.rs @@ -1,10 +1,3 @@ -use crate::stdlib::{ - borrow::Cow, - collections::{HashMap, HashSet}, - fmt, - prelude::*, -}; - use crate::{ types::relocatable::{MaybeRelocatable, Relocatable}, utils::from_relocatable_to_indexes, @@ -12,7 +5,11 @@ use crate::{ }; use felt::Felt; use num_traits::ToPrimitive; - +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, + fmt::{Display, Formatter}, +}; pub struct ValidationRule( #[allow(clippy::type_complexity)] pub Box Result, MemoryError>>, @@ -358,8 +355,8 @@ impl Memory { } } -impl fmt::Display for Memory { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl Display for Memory { + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { for (i, segment) in self.temp_data.iter().enumerate() { for (j, cell) in segment.iter().enumerate() { if let Some(cell) = cell { @@ -427,7 +424,7 @@ impl Default for Memory { #[cfg(test)] mod memory_tests { - use core::ops::Shl; + use std::ops::Shl; use super::*; use crate::{ @@ -448,9 +445,6 @@ mod memory_tests { use crate::utils::test_utils::memory_from_memory; use crate::utils::test_utils::memory_inner; - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; - pub fn memory_from( key_val_list: Vec<(MaybeRelocatable, MaybeRelocatable)>, num_segements: usize, @@ -466,7 +460,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_and_get_succesful() { let key = MaybeRelocatable::from((0, 0)); let val = MaybeRelocatable::from(Felt::new(5)); @@ -480,7 +473,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_valuef_from_temp_segment() { let mut memory = Memory::new(); memory.temp_data = vec![vec![ @@ -495,7 +487,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_value_in_temp_segment() { let key = MaybeRelocatable::from((-1, 3)); let val = MaybeRelocatable::from(Felt::new(8)); @@ -509,7 +500,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_and_get_from_temp_segment_succesful() { let key = MaybeRelocatable::from((-1, 0)); let val = MaybeRelocatable::from(Felt::new(5)); @@ -523,7 +513,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_and_get_from_temp_segment_failed() { let key = mayberelocatable!(-1, 1); let mut memory = Memory::new(); @@ -539,7 +528,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_non_allocated_memory() { let key = MaybeRelocatable::from((0, 0)); let memory = Memory::new(); @@ -547,7 +535,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_non_existant_element() { let key = MaybeRelocatable::from((0, 0)); let memory = Memory::new(); @@ -555,7 +542,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_non_relocatable_key() { let key = MaybeRelocatable::from(Felt::new(0)); let memory = Memory::new(); @@ -563,7 +549,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_non_allocated_memory() { let key = MaybeRelocatable::from((0, 0)); let val = MaybeRelocatable::from(Felt::new(5)); @@ -573,7 +558,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_inconsistent_memory() { let key = MaybeRelocatable::from((0, 0)); let val_a = MaybeRelocatable::from(Felt::new(5)); @@ -591,7 +575,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_address_not_relocatable() { let key = MaybeRelocatable::from(Felt::new(5)); let val = MaybeRelocatable::from(Felt::new(5)); @@ -605,7 +588,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_non_contiguous_element() { let key_a = MaybeRelocatable::from((0, 0)); let key_b = MaybeRelocatable::from((0, 2)); @@ -618,7 +600,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_non_contiguous_element_memory_gaps_none() { let key_a = MaybeRelocatable::from((0, 0)); let key_b = MaybeRelocatable::from((0, 5)); @@ -635,7 +616,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn from_array_test() { let mem = memory_from( vec![( @@ -649,7 +629,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn validate_existing_memory_for_range_check_within_bounds() { let mut builtin = RangeCheckBuiltinRunner::new(8, 8, true); let mut segments = MemorySegmentManager::new(); @@ -674,7 +653,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn validate_existing_memory_for_range_check_outside_bounds() { let mut builtin = RangeCheckBuiltinRunner::new(8, 8, true); let mut segments = MemorySegmentManager::new(); @@ -699,7 +677,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn validate_existing_memory_for_invalid_signature() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); let mut segments = MemorySegmentManager::new(); @@ -726,7 +703,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn validate_existing_memory_for_valid_signature() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -764,7 +740,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn validate_existing_memory_for_range_check_relocatable_value() { let mut builtin = RangeCheckBuiltinRunner::new(8, 8, true); let mut segments = MemorySegmentManager::new(); @@ -779,7 +754,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn validate_existing_memory_for_range_check_out_of_bounds_diff_segment() { let mut builtin = RangeCheckBuiltinRunner::new(8, 8, true); let mut segments = MemorySegmentManager::new(); @@ -798,7 +772,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_integer_valid() { let memory = memory![((0, 0), 10)]; assert_eq!( @@ -811,7 +784,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_integer_invalid_expected_integer() { let mut segments = MemorySegmentManager::new(); segments.add(); @@ -831,14 +803,12 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn default_memory() { let mem: Memory = Default::default(); assert_eq!(mem.data.len(), 0); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn insert_and_get_temporary_succesful() { let mut memory = Memory::new(); memory.temp_data.push(Vec::new()); @@ -851,7 +821,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_relocation_rule() { let mut memory = Memory::new(); @@ -878,7 +847,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_value_bigint() { let mut memory = Memory::new(); memory @@ -896,7 +864,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_value_mayberelocatable() { let mut memory = Memory::new(); memory @@ -918,7 +885,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_value_mayberelocatable_temporary_segment_no_rules() { let mut memory = Memory::new(); memory @@ -937,7 +903,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_value_mayberelocatable_temporary_segment_rules() { let mut memory = Memory::new(); memory @@ -966,9 +931,7 @@ mod memory_tests { Cow::Owned(MaybeRelocatable::RelocatableValue((2, 7).into())), ); } - #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_for_continuous_memory() { let memory = memory![((1, 0), 2), ((1, 1), 3), ((1, 2), 4)]; @@ -985,7 +948,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_range_for_non_continuous_memory() { let memory = memory![((1, 0), 2), ((1, 1), 3), ((1, 3), 4)]; @@ -1003,7 +965,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_continuous_range_for_continuous_memory() { let memory = memory![((1, 0), 2), ((1, 1), 3), ((1, 2), 4)]; @@ -1019,7 +980,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_continuous_range_for_non_continuous_memory() { let memory = memory![((1, 0), 2), ((1, 1), 3), ((1, 3), 4)]; @@ -1031,7 +991,6 @@ mod memory_tests { /// Test that relocate_memory() works when there are no relocation rules. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_empty_relocation_rules() { let mut memory = memory![((0, 0), 1), ((0, 1), 2), ((0, 2), 3)]; @@ -1040,7 +999,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_new_segment_with_gap() { let mut memory = memory![ ((0, 0), 1), @@ -1075,7 +1033,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_new_segment() { let mut memory = memory![ ((0, 0), 1), @@ -1111,7 +1068,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_new_segment_unallocated() { let mut memory = memory![ ((0, 0), 1), @@ -1135,7 +1091,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_into_existing_segment() { let mut memory = memory![ ((0, 0), 1), @@ -1170,7 +1125,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_into_existing_segment_inconsistent_memory() { let mut memory = memory![ ((0, 0), 1), @@ -1198,7 +1152,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_new_segment_2_temporary_segments_one_relocated() { let mut memory = memory![ ((0, 0), 1), @@ -1236,7 +1189,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_new_segment_2_temporary_segments_relocated() { let mut memory = memory![ ((0, 0), 1), @@ -1280,7 +1232,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_memory_display() { let memory = memory![ ((0, 0), 1), @@ -1300,7 +1251,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_memory_into_existing_segment_temporary_values_in_temporary_memory() { let mut memory = memory![ ((0, 0), 1), @@ -1334,7 +1284,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_address_with_rules() { let mut memory = Memory::new(); memory @@ -1355,7 +1304,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_address_no_rules() { let memory = Memory::new(); assert_eq!( @@ -1369,7 +1317,6 @@ mod memory_tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_address_real_addr() { let memory = Memory::new(); assert_eq!( diff --git a/src/vm/vm_memory/memory_segments.rs b/src/vm/vm_memory/memory_segments.rs index 6bef9c4673..1e59bbfcd6 100644 --- a/src/vm/vm_memory/memory_segments.rs +++ b/src/vm/vm_memory/memory_segments.rs @@ -1,7 +1,4 @@ -use crate::stdlib::prelude::*; -use crate::stdlib::{any::Any, collections::HashMap}; use crate::vm::runners::cairo_runner::CairoArg; - use crate::{ types::relocatable::{MaybeRelocatable, Relocatable}, vm::{ @@ -9,6 +6,7 @@ use crate::{ vm_memory::memory::Memory, }, }; +use std::{any::Any, collections::HashMap}; pub struct MemorySegmentManager { pub segment_sizes: HashMap, @@ -240,12 +238,9 @@ mod tests { use assert_matches::assert_matches; use felt::Felt; use num_traits::Num; - - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::*; + use std::vec; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_segment_no_size() { let mut segments = MemorySegmentManager::new(); let base = segments.add(); @@ -254,7 +249,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_segment_no_size_test_two_segments() { let mut segments = MemorySegmentManager::new(); let mut _base = segments.add(); @@ -270,7 +264,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_one_temporary_segment() { let mut segments = MemorySegmentManager::new(); let base = segments.add_temporary_segment(); @@ -279,7 +272,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn add_two_temporary_segments() { let mut segments = MemorySegmentManager::new(); segments.add_temporary_segment(); @@ -295,7 +287,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn load_data_empty() { let data = Vec::new(); let ptr = Relocatable::from((0, 3)); @@ -305,7 +296,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn load_data_one_element() { let data = vec![MaybeRelocatable::from(Felt::new(4))]; let ptr = Relocatable::from((0, 0)); @@ -320,7 +310,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn load_data_three_elements() { let data = vec![ MaybeRelocatable::from(Felt::new(4)), @@ -355,7 +344,6 @@ mod tests { ); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_effective_sizes_for_one_segment_memory() { let mut segments = segments![((0, 0), 1), ((0, 1), 1), ((0, 2), 1)]; segments.compute_effective_sizes(); @@ -363,7 +351,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_effective_sizes_for_one_segment_memory_with_gap() { let mut segments = MemorySegmentManager::new(); segments.add(); @@ -379,7 +366,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_effective_sizes_for_one_segment_memory_with_gaps() { let mut segments = segments![((0, 3), 1), ((0, 4), 1), ((0, 7), 1), ((0, 9), 1)]; segments.compute_effective_sizes(); @@ -387,7 +373,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_effective_sizes_for_three_segment_memory() { let mut segments = segments![ ((0, 0), 1), @@ -405,7 +390,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compute_effective_sizes_for_three_segment_memory_with_gaps() { let mut segments = segments![ ((0, 2), 1), @@ -421,7 +405,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_segment_used_size_after_computing_used() { let mut segments = segments![ ((0, 2), 1), @@ -437,14 +420,12 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_segment_used_size_before_computing_used() { let segments = MemorySegmentManager::new(); assert_eq!(None, segments.get_segment_used_size(2)); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_segments_one_segment() { let mut segments = MemorySegmentManager::new(); segments.segment_used_sizes = Some(vec![3]); @@ -457,7 +438,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_segments_five_segment() { let mut segments = MemorySegmentManager::new(); segments.segment_used_sizes = Some(vec![3, 3, 56, 78, 8]); @@ -470,7 +450,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn write_arg_with_apply_modulo() { let mut big_num = num_bigint::BigInt::from_str_radix(&felt::PRIME_STR[2..], 16) .expect("Couldn't parse prime"); @@ -497,7 +476,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn write_arg_relocatable() { let data = vec![ Relocatable::from((0, 1)), @@ -524,7 +502,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn segment_default() { let segment_mng_new = MemorySegmentManager::new(); let segment_mng_def: MemorySegmentManager = Default::default(); @@ -539,7 +516,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_valid_memory_value_missing_effective_sizes() { let segment_manager = MemorySegmentManager::new(); @@ -550,7 +526,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_valid_memory_value_temporary_segment() { let mut segment_manager = MemorySegmentManager::new(); @@ -562,7 +537,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_valid_memory_value_invalid_segment() { let mut segment_manager = MemorySegmentManager::new(); @@ -574,7 +548,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn is_valid_memory_value() { let mut segment_manager = MemorySegmentManager::new(); @@ -586,7 +559,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes_missing_segment_used_sizes() { let mut memory_segment_manager = MemorySegmentManager::new(); memory_segment_manager.memory = memory![((0, 0), 0)]; @@ -600,7 +572,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes_out_of_address_offset_bigger_than_size() { let mut memory_segment_manager = MemorySegmentManager::new(); memory_segment_manager.segment_used_sizes = Some(vec![2]); @@ -619,7 +590,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes_empty() { let mut memory_segment_manager = MemorySegmentManager::new(); memory_segment_manager.segment_used_sizes = Some(Vec::new()); @@ -627,7 +597,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes_empty2() { let mut memory_segment_manager = MemorySegmentManager::new(); memory_segment_manager.segment_used_sizes = Some(vec![4]); @@ -635,7 +604,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes() { let mut memory_segment_manager = MemorySegmentManager::new(); memory_segment_manager.segment_used_sizes = Some(vec![10]); @@ -658,7 +626,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_holes2() { let mut memory_segment_manager = MemorySegmentManager::new(); @@ -683,7 +650,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_size_missing_segment() { let memory_segment_manager = MemorySegmentManager::new(); @@ -691,7 +657,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_size_used() { let mut memory_segment_manager = MemorySegmentManager::new(); memory_segment_manager.segment_used_sizes = Some(vec![5]); @@ -700,7 +665,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_size() { let mut memory_segment_manager = MemorySegmentManager::new(); memory_segment_manager.segment_sizes = HashMap::from([(0, 5)]); @@ -709,7 +673,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn get_memory_size2() { let mut memory_segment_manager = MemorySegmentManager::new(); memory_segment_manager.segment_sizes = HashMap::from([(0, 5)]); @@ -721,7 +684,6 @@ mod tests { /// Test that the call to .gen_arg() with a relocatable just passes the /// value through. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_relocatable() { let mut memory_segment_manager = MemorySegmentManager::new(); @@ -734,7 +696,6 @@ mod tests { /// Test that the call to .gen_arg() with a bigint and no prime number just /// passes the value through. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_bigint() { let mut memory_segment_manager = MemorySegmentManager::new(); @@ -747,7 +708,6 @@ mod tests { /// Test that the call to .gen_arg() with a Vec writes its /// contents into a new segment and returns a pointer to it. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_vec() { let mut memory_segment_manager = MemorySegmentManager::new(); @@ -771,7 +731,6 @@ mod tests { /// Test that the call to .gen_arg() with a Vec writes its /// contents into a new segment and returns a pointer to it. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_vec_relocatable() { let mut memory_segment_manager = MemorySegmentManager::new(); @@ -791,7 +750,6 @@ mod tests { /// Test that the call to .gen_arg() with any other argument returns a not /// implemented error. #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_arg_invalid_type() { let mut memory_segment_manager = MemorySegmentManager::new(); @@ -802,7 +760,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_no_size_nor_memory_no_change() { let mut segments = MemorySegmentManager::new(); segments.finalize(None, 0, None); @@ -814,7 +771,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_no_memory() { let mut segments = MemorySegmentManager::new(); segments.finalize(Some(42), 0, None); @@ -823,7 +779,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_no_size() { let mut segments = MemorySegmentManager::new(); segments.finalize(None, 0, Some(&vec![(1_usize, 2_usize)])); @@ -835,7 +790,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_all_args() { let mut segments = MemorySegmentManager::new(); segments.finalize(Some(42), 0, Some(&vec![(1_usize, 2_usize)])); @@ -847,7 +801,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_cairo_arg_single() { let mut memory_segment_manager = MemorySegmentManager::new(); @@ -858,7 +811,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_cairo_arg_array() { let mut memory_segment_manager = MemorySegmentManager::new(); @@ -881,7 +833,6 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn gen_cairo_arg_composed() { let mut memory_segment_manager = MemorySegmentManager::new(); let cairo_args = CairoArg::Composed(vec![ diff --git a/src/with_alloc.rs b/src/with_alloc.rs deleted file mode 100644 index 450af26178..0000000000 --- a/src/with_alloc.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[macro_use] -pub extern crate alloc; - -pub mod with_alloc { - pub use alloc::borrow; - pub use alloc::boxed; - pub use alloc::rc; - pub use alloc::string; - pub use alloc::sync; - pub use alloc::vec; - - pub mod collections { - pub use hashbrown::{HashMap, HashSet}; - } -} diff --git a/src/with_std.rs b/src/with_std.rs deleted file mode 100644 index 2b30649c4e..0000000000 --- a/src/with_std.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Inspired by Substrate sp-std crate -// see https://github.com/paritytech/substrate/blob/master/primitives/std/with_std.rs - -pub mod with_std { - pub use core::time; - pub use std::alloc; - pub use std::any; - pub use std::borrow; - pub use std::boxed; - pub use std::cell; - pub use std::clone; - pub use std::cmp; - pub use std::convert; - pub use std::default; - pub use std::fmt; - pub use std::hash; - pub use std::iter; - pub use std::marker; - pub use std::mem; - pub use std::num; - pub use std::ops; - pub use std::ptr; - pub use std::rc; - pub use std::result; - pub use std::slice; - pub use std::str; - pub use std::string; - pub use std::sync; - pub use std::vec; - - pub mod collections { - pub use std::collections::{HashMap, HashSet}; - } -} diff --git a/src/without_std.rs b/src/without_std.rs deleted file mode 100644 index 1fb0b9746c..0000000000 --- a/src/without_std.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Inspired by Substrate sp-std crate -// see https://github.com/paritytech/substrate/blob/master/primitives/std/without_std.rs - -pub mod without_std { - pub use core::any; - pub use core::borrow; - pub use core::cell; - pub use core::clone; - pub use core::cmp; - pub use core::convert; - pub use core::default; - pub use core::fmt; - pub use core::hash; - pub use core::iter; - pub use core::marker; - pub use core::mem; - pub use core::num; - pub use core::ops; - pub use core::ptr; - pub use core::result; - pub use core::slice; - pub use core::str; - pub use core::time; -} diff --git a/src/tests/bitwise_test.rs b/tests/bitwise_test.rs similarity index 94% rename from src/tests/bitwise_test.rs rename to tests/bitwise_test.rs index 7fc819b4fe..c2b5cf14d6 100644 --- a/src/tests/bitwise_test.rs +++ b/tests/bitwise_test.rs @@ -1,6 +1,4 @@ -use crate::stdlib::prelude::*; - -use crate::{ +use cairo_vm::{ hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, types::program::Program, vm::{ @@ -9,19 +7,17 @@ use crate::{ }, }; -use assert_matches::assert_matches; - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen_test::*; +#[macro_use] +extern crate assert_matches; +use std::path::Path; #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn bitwise_integration_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/bitwise_builtin_test.json"), + let program = Program::from_file( + Path::new("cairo_programs/bitwise_builtin_test.json"), Some("main"), ) - .unwrap(); + .expect("Failed to deserialize program"); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = CairoRunner::new(&program, "all", false).unwrap(); let mut vm = VirtualMachine::new(true); diff --git a/tests/cairo_run_test.rs b/tests/cairo_run_test.rs index c1bbb9f0a7..d4b7bd88aa 100644 --- a/tests/cairo_run_test.rs +++ b/tests/cairo_run_test.rs @@ -1,11 +1,8 @@ use cairo_vm::cairo_run; use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen_test::*; +use std::path::Path; #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_test() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -13,7 +10,7 @@ fn cairo_run_test() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/fibonacci.json"), + Path::new("cairo_programs/fibonacci.json"), &cairo_run_config, &mut hint_executor, ) @@ -21,7 +18,6 @@ fn cairo_run_test() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_array_sum() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -29,7 +25,7 @@ fn cairo_run_array_sum() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/array_sum.json"), + Path::new("cairo_programs/array_sum.json"), &cairo_run_config, &mut hint_executor, ) @@ -37,7 +33,6 @@ fn cairo_run_array_sum() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_big_struct() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -45,7 +40,7 @@ fn cairo_run_big_struct() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/big_struct.json"), + Path::new("cairo_programs/big_struct.json"), &cairo_run_config, &mut hint_executor, ) @@ -53,7 +48,6 @@ fn cairo_run_big_struct() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_call_function_assign_param_by_name() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -61,7 +55,7 @@ fn cairo_run_call_function_assign_param_by_name() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/call_function_assign_param_by_name.json"), + Path::new("cairo_programs/call_function_assign_param_by_name.json"), &cairo_run_config, &mut hint_executor, ) @@ -69,7 +63,6 @@ fn cairo_run_call_function_assign_param_by_name() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_function_return() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -77,7 +70,7 @@ fn cairo_run_function_return() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/function_return.json"), + Path::new("cairo_programs/function_return.json"), &cairo_run_config, &mut hint_executor, ) @@ -85,7 +78,6 @@ fn cairo_run_function_return() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_function_return_if_print() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -93,7 +85,7 @@ fn cairo_run_function_return_if_print() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/function_return_if_print.json"), + Path::new("cairo_programs/function_return_if_print.json"), &cairo_run_config, &mut hint_executor, ) @@ -101,7 +93,6 @@ fn cairo_run_function_return_if_print() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_function_return_to_variable() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -109,7 +100,7 @@ fn cairo_run_function_return_to_variable() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/function_return_to_variable.json"), + Path::new("cairo_programs/function_return_to_variable.json"), &cairo_run_config, &mut hint_executor, ) @@ -117,7 +108,6 @@ fn cairo_run_function_return_to_variable() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_if_and_prime() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -125,7 +115,7 @@ fn cairo_run_if_and_prime() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/if_and_prime.json"), + Path::new("cairo_programs/if_and_prime.json"), &cairo_run_config, &mut hint_executor, ) @@ -133,7 +123,6 @@ fn cairo_run_if_and_prime() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_if_in_function() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -141,7 +130,7 @@ fn cairo_run_if_in_function() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/if_in_function.json"), + Path::new("cairo_programs/if_in_function.json"), &cairo_run_config, &mut hint_executor, ) @@ -149,7 +138,6 @@ fn cairo_run_if_in_function() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_if_list() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -157,7 +145,7 @@ fn cairo_run_if_list() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/if_list.json"), + Path::new("cairo_programs/if_list.json"), &cairo_run_config, &mut hint_executor, ) @@ -165,7 +153,6 @@ fn cairo_run_if_list() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_jmp() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -173,7 +160,7 @@ fn cairo_run_jmp() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/jmp.json"), + Path::new("cairo_programs/jmp.json"), &cairo_run_config, &mut hint_executor, ) @@ -181,7 +168,6 @@ fn cairo_run_jmp() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_jmp_if_condition() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -189,7 +175,7 @@ fn cairo_run_jmp_if_condition() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/jmp_if_condition.json"), + Path::new("cairo_programs/jmp_if_condition.json"), &cairo_run_config, &mut hint_executor, ) @@ -197,7 +183,6 @@ fn cairo_run_jmp_if_condition() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_pointers() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -205,7 +190,7 @@ fn cairo_run_pointers() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/pointers.json"), + Path::new("cairo_programs/pointers.json"), &cairo_run_config, &mut hint_executor, ) @@ -213,7 +198,6 @@ fn cairo_run_pointers() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_print() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -221,7 +205,7 @@ fn cairo_run_print() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/print.json"), + Path::new("cairo_programs/print.json"), &cairo_run_config, &mut hint_executor, ) @@ -229,7 +213,6 @@ fn cairo_run_print() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_return() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -237,7 +220,7 @@ fn cairo_run_return() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/return.json"), + Path::new("cairo_programs/return.json"), &cairo_run_config, &mut hint_executor, ) @@ -245,7 +228,6 @@ fn cairo_run_return() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_reversed_register_instructions() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -253,7 +235,7 @@ fn cairo_run_reversed_register_instructions() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/reversed_register_instructions.json"), + Path::new("cairo_programs/reversed_register_instructions.json"), &cairo_run_config, &mut hint_executor, ) @@ -261,7 +243,6 @@ fn cairo_run_reversed_register_instructions() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_simple_print() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -269,7 +250,7 @@ fn cairo_run_simple_print() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/simple_print.json"), + Path::new("cairo_programs/simple_print.json"), &cairo_run_config, &mut hint_executor, ) @@ -277,7 +258,6 @@ fn cairo_run_simple_print() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_test_addition_if() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -285,7 +265,7 @@ fn cairo_run_test_addition_if() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/test_addition_if.json"), + Path::new("cairo_programs/test_addition_if.json"), &cairo_run_config, &mut hint_executor, ) @@ -293,7 +273,6 @@ fn cairo_run_test_addition_if() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_test_reverse_if() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -301,7 +280,7 @@ fn cairo_run_test_reverse_if() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/test_reverse_if.json"), + Path::new("cairo_programs/test_reverse_if.json"), &cairo_run_config, &mut hint_executor, ) @@ -309,7 +288,6 @@ fn cairo_run_test_reverse_if() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_test_subtraction_if() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -317,7 +295,7 @@ fn cairo_run_test_subtraction_if() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/test_subtraction_if.json"), + Path::new("cairo_programs/test_subtraction_if.json"), &cairo_run_config, &mut hint_executor, ) @@ -325,7 +303,6 @@ fn cairo_run_test_subtraction_if() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_use_imported_module() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -333,7 +310,7 @@ fn cairo_run_use_imported_module() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/use_imported_module.json"), + Path::new("cairo_programs/use_imported_module.json"), &cairo_run_config, &mut hint_executor, ) @@ -341,7 +318,6 @@ fn cairo_run_use_imported_module() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_bitwise_output() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -349,7 +325,7 @@ fn cairo_run_bitwise_output() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/bitwise_output.json"), + Path::new("cairo_programs/bitwise_output.json"), &cairo_run_config, &mut hint_executor, ) @@ -357,7 +333,6 @@ fn cairo_run_bitwise_output() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_bitwise_recursion() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -365,7 +340,7 @@ fn cairo_run_bitwise_recursion() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/bitwise_recursion.json"), + Path::new("cairo_programs/bitwise_recursion.json"), &cairo_run_config, &mut hint_executor, ) @@ -373,7 +348,6 @@ fn cairo_run_bitwise_recursion() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -381,7 +355,7 @@ fn cairo_run_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/integration.json"), + Path::new("cairo_programs/integration.json"), &cairo_run_config, &mut hint_executor, ) @@ -389,7 +363,6 @@ fn cairo_run_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_integration_with_alloc_locals() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -397,7 +370,7 @@ fn cairo_run_integration_with_alloc_locals() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/integration_with_alloc_locals.json"), + Path::new("cairo_programs/integration_with_alloc_locals.json"), &cairo_run_config, &mut hint_executor, ) @@ -405,7 +378,6 @@ fn cairo_run_integration_with_alloc_locals() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_compare_arrays() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -413,7 +385,7 @@ fn cairo_run_compare_arrays() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/compare_arrays.json"), + Path::new("cairo_programs/compare_arrays.json"), &cairo_run_config, &mut hint_executor, ) @@ -421,7 +393,6 @@ fn cairo_run_compare_arrays() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_compare_greater_array() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -429,7 +400,7 @@ fn cairo_run_compare_greater_array() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/compare_greater_array.json"), + Path::new("cairo_programs/compare_greater_array.json"), &cairo_run_config, &mut hint_executor, ) @@ -437,7 +408,6 @@ fn cairo_run_compare_greater_array() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_compare_lesser_array() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -445,7 +415,7 @@ fn cairo_run_compare_lesser_array() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/compare_lesser_array.json"), + Path::new("cairo_programs/compare_lesser_array.json"), &cairo_run_config, &mut hint_executor, ) @@ -453,7 +423,6 @@ fn cairo_run_compare_lesser_array() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_assert_le_felt_hint() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -461,7 +430,7 @@ fn cairo_run_assert_le_felt_hint() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_le_felt_hint.json"), + Path::new("cairo_programs/assert_le_felt_hint.json"), &cairo_run_config, &mut hint_executor, ) @@ -469,7 +438,6 @@ fn cairo_run_assert_le_felt_hint() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_assert_250_bit_element_array() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -477,7 +445,7 @@ fn cairo_run_assert_250_bit_element_array() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_250_bit_element_array.json"), + Path::new("cairo_programs/assert_250_bit_element_array.json"), &cairo_run_config, &mut hint_executor, ) @@ -485,7 +453,6 @@ fn cairo_run_assert_250_bit_element_array() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_abs_value() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -493,7 +460,7 @@ fn cairo_abs_value() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/abs_value_array.json"), + Path::new("cairo_programs/abs_value_array.json"), &cairo_run_config, &mut hint_executor, ) @@ -501,7 +468,6 @@ fn cairo_abs_value() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_compare_different_arrays() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -509,7 +475,7 @@ fn cairo_run_compare_different_arrays() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/compare_different_arrays.json"), + Path::new("cairo_programs/compare_different_arrays.json"), &cairo_run_config, &mut hint_executor, ) @@ -517,7 +483,6 @@ fn cairo_run_compare_different_arrays() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_assert_nn() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -525,7 +490,7 @@ fn cairo_run_assert_nn() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_nn.json"), + Path::new("cairo_programs/assert_nn.json"), &cairo_run_config, &mut hint_executor, ) @@ -533,7 +498,6 @@ fn cairo_run_assert_nn() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_sqrt() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -541,7 +505,7 @@ fn cairo_run_sqrt() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/sqrt.json"), + Path::new("cairo_programs/sqrt.json"), &cairo_run_config, &mut hint_executor, ) @@ -549,7 +513,6 @@ fn cairo_run_sqrt() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_assert_not_zero() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -557,7 +520,7 @@ fn cairo_run_assert_not_zero() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_not_zero.json"), + Path::new("cairo_programs/assert_not_zero.json"), &cairo_run_config, &mut hint_executor, ) @@ -565,7 +528,6 @@ fn cairo_run_assert_not_zero() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_split_int() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -573,7 +535,7 @@ fn cairo_run_split_int() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/split_int.json"), + Path::new("cairo_programs/split_int.json"), &cairo_run_config, &mut hint_executor, ) @@ -581,7 +543,6 @@ fn cairo_run_split_int() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_split_int_big() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -589,7 +550,7 @@ fn cairo_run_split_int_big() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/split_int_big.json"), + Path::new("cairo_programs/split_int_big.json"), &cairo_run_config, &mut hint_executor, ) @@ -597,7 +558,6 @@ fn cairo_run_split_int_big() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_split_felt() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -605,7 +565,7 @@ fn cairo_run_split_felt() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/split_felt.json"), + Path::new("cairo_programs/split_felt.json"), &cairo_run_config, &mut hint_executor, ) @@ -613,7 +573,6 @@ fn cairo_run_split_felt() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_math_cmp() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -621,7 +580,7 @@ fn cairo_run_math_cmp() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/math_cmp.json"), + Path::new("cairo_programs/math_cmp.json"), &cairo_run_config, &mut hint_executor, ) @@ -629,7 +588,6 @@ fn cairo_run_math_cmp() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_unsigned_div_rem() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -637,7 +595,7 @@ fn cairo_run_unsigned_div_rem() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/unsigned_div_rem.json"), + Path::new("cairo_programs/unsigned_div_rem.json"), &cairo_run_config, &mut hint_executor, ) @@ -645,7 +603,6 @@ fn cairo_run_unsigned_div_rem() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_signed_div_rem() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -653,7 +610,7 @@ fn cairo_run_signed_div_rem() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/signed_div_rem.json"), + Path::new("cairo_programs/signed_div_rem.json"), &cairo_run_config, &mut hint_executor, ) @@ -661,7 +618,6 @@ fn cairo_run_signed_div_rem() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_assert_lt_felt() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -669,7 +625,7 @@ fn cairo_run_assert_lt_felt() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_lt_felt.json"), + Path::new("cairo_programs/assert_lt_felt.json"), &cairo_run_config, &mut hint_executor, ) @@ -677,7 +633,6 @@ fn cairo_run_assert_lt_felt() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_memcpy() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -685,7 +640,7 @@ fn cairo_run_memcpy() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/memcpy_test.json"), + Path::new("cairo_programs/memcpy_test.json"), &cairo_run_config, &mut hint_executor, ) @@ -693,7 +648,6 @@ fn cairo_run_memcpy() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_memset() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -701,7 +655,7 @@ fn cairo_run_memset() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/memset.json"), + Path::new("cairo_programs/memset.json"), &cairo_run_config, &mut hint_executor, ) @@ -709,7 +663,6 @@ fn cairo_run_memset() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_pow() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -717,7 +670,7 @@ fn cairo_run_pow() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/pow.json"), + Path::new("cairo_programs/pow.json"), &cairo_run_config, &mut hint_executor, ) @@ -725,7 +678,6 @@ fn cairo_run_pow() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_dict() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -733,7 +685,7 @@ fn cairo_run_dict() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict.json"), + Path::new("cairo_programs/dict.json"), &cairo_run_config, &mut hint_executor, ) @@ -741,7 +693,6 @@ fn cairo_run_dict() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_dict_update() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -749,7 +700,7 @@ fn cairo_run_dict_update() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict_update.json"), + Path::new("cairo_programs/dict_update.json"), &cairo_run_config, &mut hint_executor, ) @@ -757,7 +708,6 @@ fn cairo_run_dict_update() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_uint256() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -765,7 +715,7 @@ fn cairo_run_uint256() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/uint256.json"), + Path::new("cairo_programs/uint256.json"), &cairo_run_config, &mut hint_executor, ) @@ -773,7 +723,6 @@ fn cairo_run_uint256() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_find_element() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -781,7 +730,7 @@ fn cairo_run_find_element() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/find_element.json"), + Path::new("cairo_programs/find_element.json"), &cairo_run_config, &mut hint_executor, ) @@ -789,7 +738,6 @@ fn cairo_run_find_element() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_search_sorted_lower() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -797,7 +745,7 @@ fn cairo_run_search_sorted_lower() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/search_sorted_lower.json"), + Path::new("cairo_programs/search_sorted_lower.json"), &cairo_run_config, &mut hint_executor, ) @@ -805,7 +753,6 @@ fn cairo_run_search_sorted_lower() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_usort() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -813,7 +760,7 @@ fn cairo_run_usort() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/usort.json"), + Path::new("cairo_programs/usort.json"), &cairo_run_config, &mut hint_executor, ) @@ -821,7 +768,6 @@ fn cairo_run_usort() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_usort_bad() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -829,7 +775,7 @@ fn cairo_run_usort_bad() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_usort.json"), + Path::new("cairo_programs/bad_programs/bad_usort.json"), &cairo_run_config, &mut hint_executor, ); @@ -842,7 +788,6 @@ fn cairo_run_usort_bad() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_dict_write_bad() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -850,7 +795,7 @@ fn cairo_run_dict_write_bad() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; assert!(cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_dict_new.json"), + Path::new("cairo_programs/bad_programs/bad_dict_new.json"), &cairo_run_config, &mut hint_executor, ) @@ -861,7 +806,7 @@ fn cairo_run_dict_write_bad() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_dict_new.json"), + Path::new("cairo_programs/bad_programs/bad_dict_new.json"), &cairo_run_config, &mut hint_executor, ) @@ -873,7 +818,6 @@ fn cairo_run_dict_write_bad() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_dict_update_bad() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -881,7 +825,7 @@ fn cairo_run_dict_update_bad() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; assert!(cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_dict_update.json"), + Path::new("cairo_programs/bad_programs/bad_dict_update.json"), &cairo_run_config, &mut hint_executor, ) @@ -892,7 +836,7 @@ fn cairo_run_dict_update_bad() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_dict_update.json"), + Path::new("cairo_programs/bad_programs/bad_dict_update.json"), &cairo_run_config, &mut hint_executor, ) @@ -903,7 +847,6 @@ fn cairo_run_dict_update_bad() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_squash_dict() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -911,7 +854,7 @@ fn cairo_run_squash_dict() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/squash_dict.json"), + Path::new("cairo_programs/squash_dict.json"), &cairo_run_config, &mut hint_executor, ) @@ -919,7 +862,6 @@ fn cairo_run_squash_dict() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_dict_squash() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -927,7 +869,7 @@ fn cairo_run_dict_squash() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict_squash.json"), + Path::new("cairo_programs/dict_squash.json"), &cairo_run_config, &mut hint_executor, ) @@ -935,7 +877,6 @@ fn cairo_run_dict_squash() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_set_add() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -943,7 +884,7 @@ fn cairo_run_set_add() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/set_add.json"), + Path::new("cairo_programs/set_add.json"), &cairo_run_config, &mut hint_executor, ) @@ -951,7 +892,6 @@ fn cairo_run_set_add() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_secp() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -959,7 +899,7 @@ fn cairo_run_secp() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/secp.json"), + Path::new("cairo_programs/secp.json"), &cairo_run_config, &mut hint_executor, ) @@ -967,7 +907,6 @@ fn cairo_run_secp() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_signature() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -975,7 +914,7 @@ fn cairo_run_signature() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/signature.json"), + Path::new("cairo_programs/signature.json"), &cairo_run_config, &mut hint_executor, ) @@ -983,7 +922,6 @@ fn cairo_run_signature() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_secp_ec() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -991,7 +929,7 @@ fn cairo_run_secp_ec() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/secp_ec.json"), + Path::new("cairo_programs/secp_ec.json"), &cairo_run_config, &mut hint_executor, ) @@ -999,7 +937,6 @@ fn cairo_run_secp_ec() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_blake2s_hello_world_hash() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1007,7 +944,7 @@ fn cairo_run_blake2s_hello_world_hash() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/blake2s_hello_world_hash.json"), + Path::new("cairo_programs/blake2s_hello_world_hash.json"), &cairo_run_config, &mut hint_executor, ) @@ -1015,7 +952,6 @@ fn cairo_run_blake2s_hello_world_hash() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_finalize_blake2s() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1023,14 +959,13 @@ fn cairo_run_finalize_blake2s() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/finalize_blake2s.json"), + Path::new("cairo_programs/finalize_blake2s.json"), &cairo_run_config, &mut hint_executor, ) .expect("Couldn't run program"); } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_unsafe_keccak() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1038,7 +973,7 @@ fn cairo_run_unsafe_keccak() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/unsafe_keccak.json"), + Path::new("cairo_programs/unsafe_keccak.json"), &cairo_run_config, &mut hint_executor, ) @@ -1046,7 +981,6 @@ fn cairo_run_unsafe_keccak() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_blake2s_felts() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1054,7 +988,7 @@ fn cairo_run_blake2s_felts() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/blake2s_felts.json"), + Path::new("cairo_programs/blake2s_felts.json"), &cairo_run_config, &mut hint_executor, ) @@ -1062,7 +996,6 @@ fn cairo_run_blake2s_felts() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_unsafe_keccak_finalize() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1070,7 +1003,7 @@ fn cairo_run_unsafe_keccak_finalize() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/unsafe_keccak_finalize.json"), + Path::new("cairo_programs/unsafe_keccak_finalize.json"), &cairo_run_config, &mut hint_executor, ) @@ -1078,7 +1011,6 @@ fn cairo_run_unsafe_keccak_finalize() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_keccak_add_uint256() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1086,7 +1018,7 @@ fn cairo_run_keccak_add_uint256() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/keccak_add_uint256.json"), + Path::new("cairo_programs/keccak_add_uint256.json"), &cairo_run_config, &mut hint_executor, ) @@ -1094,7 +1026,6 @@ fn cairo_run_keccak_add_uint256() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_private_keccak() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1102,7 +1033,7 @@ fn cairo_run_private_keccak() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/_keccak.json"), + Path::new("cairo_programs/_keccak.json"), &cairo_run_config, &mut hint_executor, ) @@ -1110,7 +1041,6 @@ fn cairo_run_private_keccak() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_keccak_copy_inputs() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1118,7 +1048,7 @@ fn cairo_run_keccak_copy_inputs() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/keccak_copy_inputs.json"), + Path::new("cairo_programs/keccak_copy_inputs.json"), &cairo_run_config, &mut hint_executor, ) @@ -1126,7 +1056,6 @@ fn cairo_run_keccak_copy_inputs() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_finalize_keccak() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1134,7 +1063,7 @@ fn cairo_run_finalize_keccak() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/cairo_finalize_keccak.json"), + Path::new("cairo_programs/cairo_finalize_keccak.json"), &cairo_run_config, &mut hint_executor, ) @@ -1142,7 +1071,6 @@ fn cairo_run_finalize_keccak() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_operations_with_data() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1150,7 +1078,7 @@ fn cairo_run_operations_with_data() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/operations_with_data_structures.json"), + Path::new("cairo_programs/operations_with_data_structures.json"), &cairo_run_config, &mut hint_executor, ) @@ -1158,7 +1086,6 @@ fn cairo_run_operations_with_data() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_sha256() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1166,7 +1093,7 @@ fn cairo_run_sha256() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/sha256.json"), + Path::new("cairo_programs/sha256.json"), &cairo_run_config, &mut hint_executor, ) @@ -1174,7 +1101,6 @@ fn cairo_run_sha256() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_math_cmp_and_pow_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1182,7 +1108,7 @@ fn cairo_run_math_cmp_and_pow_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/math_cmp_and_pow_integration_tests.json"), + Path::new("cairo_programs/math_cmp_and_pow_integration_tests.json"), &cairo_run_config, &mut hint_executor, ) @@ -1190,7 +1116,6 @@ fn cairo_run_math_cmp_and_pow_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_uint256_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1198,7 +1123,7 @@ fn cairo_run_uint256_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/uint256_integration_tests.json"), + Path::new("cairo_programs/uint256_integration_tests.json"), &cairo_run_config, &mut hint_executor, ) @@ -1206,7 +1131,6 @@ fn cairo_run_uint256_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_set_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1214,7 +1138,7 @@ fn cairo_run_set_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/set_integration_tests.json"), + Path::new("cairo_programs/set_integration_tests.json"), &cairo_run_config, &mut hint_executor, ) @@ -1222,7 +1146,6 @@ fn cairo_run_set_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_memory_module_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1230,7 +1153,7 @@ fn cairo_run_memory_module_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/memory_integration_tests.json"), + Path::new("cairo_programs/memory_integration_tests.json"), &cairo_run_config, &mut hint_executor, ) @@ -1238,7 +1161,6 @@ fn cairo_run_memory_module_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_dict_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1246,7 +1168,7 @@ fn cairo_run_dict_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict_integration_tests.json"), + Path::new("cairo_programs/dict_integration_tests.json"), &cairo_run_config, &mut hint_executor, ) @@ -1254,7 +1176,6 @@ fn cairo_run_dict_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_secp_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1262,7 +1183,7 @@ fn cairo_run_secp_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/secp_integration_tests.json"), + Path::new("cairo_programs/secp_integration_tests.json"), &cairo_run_config, &mut hint_executor, ) @@ -1270,7 +1191,6 @@ fn cairo_run_secp_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_keccak_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1278,7 +1198,7 @@ fn cairo_run_keccak_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/keccak_integration_tests.json"), + Path::new("cairo_programs/keccak_integration_tests.json"), &cairo_run_config, &mut hint_executor, ) @@ -1286,7 +1206,6 @@ fn cairo_run_keccak_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_blake2s_integration() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1294,7 +1213,7 @@ fn cairo_run_blake2s_integration() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/blake2s_integration_tests.json"), + Path::new("cairo_programs/blake2s_integration_tests.json"), &cairo_run_config, &mut hint_executor, ) @@ -1302,7 +1221,6 @@ fn cairo_run_blake2s_integration() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_relocate_segments() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1310,7 +1228,7 @@ fn cairo_run_relocate_segments() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/relocate_segments.json"), + Path::new("cairo_programs/relocate_segments.json"), &cairo_run_config, &mut hint_executor, ) @@ -1318,7 +1236,6 @@ fn cairo_run_relocate_segments() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_error_msg_attr() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1326,7 +1243,7 @@ fn cairo_run_error_msg_attr() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/error_msg_attr.json"), + Path::new("cairo_programs/bad_programs/error_msg_attr.json"), &cairo_run_config, &mut hint_executor, ) @@ -1337,7 +1254,6 @@ fn cairo_run_error_msg_attr() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_error_msg_attr_ap_based_reference() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1345,22 +1261,17 @@ fn cairo_run_error_msg_attr_ap_based_reference() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/error_msg_attr_tempvar.json"), + Path::new("cairo_programs/bad_programs/error_msg_attr_tempvar.json"), &cairo_run_config, &mut hint_executor, ) .err() .unwrap(); - #[cfg(feature = "std")] assert_eq!(err.to_string(), String::from("Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n assert x = 2;\n ^***********^\n")); - - #[cfg(not(feature = "std"))] - assert_eq!(err.to_string(), String::from("Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n")); } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_error_msg_attr_complex_reference() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1368,7 +1279,7 @@ fn cairo_run_error_msg_attr_complex_reference() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/error_msg_attr_struct.json"), + Path::new("cairo_programs/bad_programs/error_msg_attr_struct.json"), &cairo_run_config, &mut hint_executor, ) @@ -1378,7 +1289,6 @@ fn cairo_run_error_msg_attr_complex_reference() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_dict_store_cast_pointer() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1386,7 +1296,7 @@ fn cairo_run_dict_store_cast_pointer() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict_store_cast_ptr.json"), + Path::new("cairo_programs/dict_store_cast_ptr.json"), &cairo_run_config, &mut hint_executor, ) @@ -1394,7 +1304,6 @@ fn cairo_run_dict_store_cast_pointer() { } #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_run_verify_signature_hint() { let mut hint_executor = BuiltinHintProcessor::new_empty(); let cairo_run_config = cairo_run::CairoRunConfig { @@ -1402,7 +1311,7 @@ fn cairo_run_verify_signature_hint() { ..cairo_vm::cairo_run::CairoRunConfig::default() }; cairo_run::cairo_run( - include_bytes!("../cairo_programs/common_signature.json"), + Path::new("cairo_programs/common_signature.json"), &cairo_run_config, &mut hint_executor, ) diff --git a/src/tests/compare_vm_state.sh b/tests/compare_vm_state.sh similarity index 100% rename from src/tests/compare_vm_state.sh rename to tests/compare_vm_state.sh diff --git a/src/tests/memory_comparator.py b/tests/memory_comparator.py similarity index 100% rename from src/tests/memory_comparator.py rename to tests/memory_comparator.py diff --git a/src/tests/pedersen_test.rs b/tests/pedersen_test.rs similarity index 87% rename from src/tests/pedersen_test.rs rename to tests/pedersen_test.rs index bc21549338..0392243d69 100644 --- a/src/tests/pedersen_test.rs +++ b/tests/pedersen_test.rs @@ -1,25 +1,17 @@ -use crate::stdlib::prelude::*; - -use crate::{ +use std::path::Path; +#[macro_use] +extern crate assert_matches; +use cairo_vm::{ hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, types::program::Program, vm::trace::trace_entry::RelocatedTraceEntry, vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine}, }; -use assert_matches::assert_matches; - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen_test::*; - #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn pedersen_integration_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/pedersen_test.json"), - Some("main"), - ) - .unwrap(); + let program = Program::from_file(Path::new("cairo_programs/pedersen_test.json"), Some("main")) + .expect("Failed to deserialize program"); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = CairoRunner::new(&program, "all", false).unwrap(); let mut vm = VirtualMachine::new(true); diff --git a/src/tests/skip_instruction_test.rs b/tests/skip_instruction_test.rs similarity index 61% rename from src/tests/skip_instruction_test.rs rename to tests/skip_instruction_test.rs index d781c8faac..c8675e58a5 100644 --- a/src/tests/skip_instruction_test.rs +++ b/tests/skip_instruction_test.rs @@ -1,24 +1,23 @@ -use crate::{ +#[cfg(feature = "skip_next_instruction_hint")] +use cairo_vm::{ hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, types::program::Program, vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine}, }; +#[macro_use] +extern crate assert_matches; -use assert_matches::assert_matches; - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen_test::*; +#[cfg(feature = "skip_next_instruction_hint")] +use std::path::Path; +#[cfg(feature = "skip_next_instruction_hint")] #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn skip_next_instruction_test() { - let program = Program::from_bytes( - include_bytes!( - "../../cairo_programs/noretrocompat/test_skip_next_instruction.noretrocompat.json" - ), + let program = Program::from_file( + Path::new("cairo_programs/noretrocompat/test_skip_next_instruction.noretrocompat.json"), Some("main"), ) - .unwrap(); + .expect("Failed to deserialize program"); let mut hint_processor = BuiltinHintProcessor::new_empty(); diff --git a/src/tests/struct_test.rs b/tests/struct_test.rs similarity index 63% rename from src/tests/struct_test.rs rename to tests/struct_test.rs index 72b7f65d86..cd443c051f 100644 --- a/src/tests/struct_test.rs +++ b/tests/struct_test.rs @@ -1,23 +1,21 @@ -use crate::{ +use cairo_vm::{ hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, - types::program::Program, vm::vm_core::VirtualMachine, + vm::vm_core::VirtualMachine, }; +use std::path::Path; -use crate::vm::{runners::cairo_runner::CairoRunner, trace::trace_entry::RelocatedTraceEntry}; - -use assert_matches::assert_matches; +use cairo_vm::{ + types::program::Program, + vm::{runners::cairo_runner::CairoRunner, trace::trace_entry::RelocatedTraceEntry}, +}; -#[cfg(target_arch = "wasm32")] -use wasm_bindgen_test::*; +#[macro_use] +extern crate assert_matches; #[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn struct_integration_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/struct.json"), - Some("main"), - ) - .unwrap(); + let program = Program::from_file(Path::new("cairo_programs/struct.json"), Some("main")) + .expect("Failed to deserialize program"); let mut hint_processor = BuiltinHintProcessor::new_empty(); let mut cairo_runner = CairoRunner::new(&program, "all", false).unwrap(); let mut vm = VirtualMachine::new(true);