diff --git a/CHANGELOG.md b/CHANGELOG.md index 874f72ce08..6455ca9e0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* fix: `mod_builtin_fill_memory` could be stuck in an infinite loop [#1975](https://github.com/lambdaclass/cairo-vm/issues/1975) + * feat: replace `thiserror-no-std` with `thiserror 2` [#1919](https://github.com/lambdaclass/cairo-vm/pull/1919) #### [2.0.1] - 2025-03-17 diff --git a/Cargo.lock b/Cargo.lock index 6cb6b82d74..8f1cca0486 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -914,7 +914,7 @@ dependencies = [ [[package]] name = "cairo-vm" -version = "2.0.0" +version = "2.0.1" dependencies = [ "anyhow", "arbitrary", @@ -953,14 +953,13 @@ dependencies = [ "starknet-crypto", "starknet-types-core", "thiserror 2.0.12", - "wasm-bindgen", "wasm-bindgen-test", "zip", ] [[package]] name = "cairo-vm-cli" -version = "2.0.0" +version = "2.0.1" dependencies = [ "assert_matches", "bincode", @@ -975,7 +974,7 @@ dependencies = [ [[package]] name = "cairo-vm-tracer" -version = "2.0.0" +version = "2.0.1" dependencies = [ "axum", "cairo-vm", @@ -994,7 +993,7 @@ dependencies = [ [[package]] name = "cairo1-run" -version = "2.0.0" +version = "2.0.1" dependencies = [ "assert_matches", "bincode", @@ -1676,7 +1675,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hint_accountant" -version = "2.0.0" +version = "2.0.1" dependencies = [ "cairo-vm", "serde", @@ -1757,7 +1756,7 @@ dependencies = [ [[package]] name = "hyper_threading" -version = "2.0.0" +version = "2.0.1" dependencies = [ "cairo-vm", "rayon", @@ -1927,10 +1926,11 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -2119,6 +2119,16 @@ dependencies = [ "unicase", ] +[[package]] +name = "minicov" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27fe9f1cc3c22e1687f9446c2083c4c5fc7f0bcf1c7a86bdbded14985895b4b" +dependencies = [ + "cc", + "walkdir", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2825,12 +2835,6 @@ dependencies = [ "syn 2.0.98", ] -[[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.2.0" @@ -3539,23 +3543,24 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", + "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn 2.0.98", @@ -3564,21 +3569,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.42" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", "js-sys", + "once_cell", "wasm-bindgen", "web-sys", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3586,9 +3592,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", @@ -3599,19 +3605,21 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "wasm-bindgen-test" -version = "0.3.42" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bf62a58e0780af3e852044583deee40983e5886da43a271dd772379987667b" +checksum = "66c8d5e33ca3b6d9fa3b4676d774c5778031d27a578c2b007f905acf816152c3" dependencies = [ - "console_error_panic_hook", "js-sys", - "scoped-tls", + "minicov", "wasm-bindgen", "wasm-bindgen-futures", "wasm-bindgen-test-macro", @@ -3619,9 +3627,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.42" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" +checksum = "17d5042cc5fa009658f9a7333ef24291b1291a25b6382dd68862a7f3b969f69b" dependencies = [ "proc-macro2", "quote", @@ -3630,7 +3638,7 @@ dependencies = [ [[package]] name = "wasm-demo" -version = "2.0.0" +version = "2.0.1" dependencies = [ "cairo-vm", "console_error_panic_hook", @@ -3641,9 +3649,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/cairo_programs/mod_builtin_feature/mod_builtin_no_solution.cairo b/cairo_programs/mod_builtin_feature/mod_builtin_no_solution.cairo new file mode 100644 index 0000000000..e7a39c2d18 --- /dev/null +++ b/cairo_programs/mod_builtin_feature/mod_builtin_no_solution.cairo @@ -0,0 +1,49 @@ +%builtins range_check add_mod mul_mod + +from cairo_programs.mod_builtin_feature.common.modulo import ModBuiltin, UInt384, run_mod_p_circuit +from starkware.cairo.common.registers import get_label_location +from starkware.cairo.common.alloc import alloc + +func main{range_check_ptr, add_mod_ptr: ModBuiltin*, mul_mod_ptr: ModBuiltin*}() { + alloc_locals; + + + // The circuit definition can be described as: + // + // x1 (input) + // x2 (input) + // a1 = x1 + x2 + // a2 = ?? + // a3 = a1 * a2 + // + // As the first mul gate tries to compute a3 when a2 is unkown, it will fail. + + let p = UInt384(d0=1, d1=1, d2=0, d3=0); + let x1 = UInt384(d0=1, d1=0, d2=0, d3=0); + let x2 = UInt384(d0=2, d1=1, d2=0, d3=0); + + let (local values_arr: UInt384*) = alloc(); + assert values_arr[0] = x1; + assert values_arr[1] = x2; + + let (local add_mod_offsets_arr: felt*) = alloc(); + assert add_mod_offsets_arr[0] = 0; // x1 + assert add_mod_offsets_arr[1] = 4; // x2 + assert add_mod_offsets_arr[2] = 8; // a1 = x1 + x2 + + let (local mul_mod_offsets_arr: felt*) = alloc(); + assert mul_mod_offsets_arr[0] = 8; // a1 + assert mul_mod_offsets_arr[1] = 12; // a2 (unknown) + assert mul_mod_offsets_arr[2] = 16; // a1 * a2 (impossible) + + run_mod_p_circuit( + p=p, + values_ptr=values_arr, + add_mod_offsets_ptr=add_mod_offsets_arr, + add_mod_n=1, + mul_mod_offsets_ptr=mul_mod_offsets_arr, + mul_mod_n=1, + ); + + return (); +} diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index fee26e2879..12d0260790 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1153,6 +1153,14 @@ fn cairo_run_mod_builtin_failure() { run_program_with_custom_mod_builtin_params(program_data, false, 1, 3, Some(error_msg)); } +#[test] +#[cfg(feature = "mod_builtin")] +fn cairo_run_mod_builtin_no_solution() { + let program_data = + include_bytes!("../../../cairo_programs/mod_builtin_feature/mod_builtin_no_solution.json"); + run_program_with_error(program_data, "Could not fill the values table"); +} + #[test] #[cfg(feature = "mod_builtin")] fn cairo_run_mod_builtin_large_batch_size() { diff --git a/vm/src/vm/runners/builtin_runner/modulo.rs b/vm/src/vm/runners/builtin_runner/modulo.rs index 37575ddd07..85a8fe8070 100644 --- a/vm/src/vm/runners/builtin_runner/modulo.rs +++ b/vm/src/vm/runners/builtin_runner/modulo.rs @@ -566,8 +566,13 @@ impl ModBuiltinRunner { if let Some((_, mul_mod_runner, _)) = mul_mod { if mul_mod_runner.fill_value(memory, &mul_mod_inputs, mul_mod_index)? { mul_mod_index += 1; + continue; + } else { + return Err(RunnerError::FillMemoryCoudNotFillTable( + add_mod_index, + mul_mod_index, + )); } - continue; } }