Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 45 additions & 37 deletions Cargo.lock

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

49 changes: 49 additions & 0 deletions cairo_programs/mod_builtin_feature/mod_builtin_no_solution.cairo
Original file line number Diff line number Diff line change
@@ -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 ();
}
8 changes: 8 additions & 0 deletions vm/src/tests/cairo_run_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion vm/src/vm/runners/builtin_runner/modulo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Loading