Skip to content

Commit

Permalink
Add pythonic run_circuit hint.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalesokhin-starkware committed Jun 13, 2024
1 parent ffe60ee commit 806b169
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
30 changes: 29 additions & 1 deletion crates/cairo-lang-casm/src/hints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,35 @@ impl PythonicHint for CoreHint {
memory{t_or_k1} = k >> 128
"}
}
CoreHint::EvalCircuit { .. } => "raise NotImplementedError".into(),
CoreHint::EvalCircuit {
values_ptr,
n_add_mods,
add_mod_builtin,
n_mul_mods,
mul_mod_builtin,
modulus,
computed_gates_out,
} => {
let n_add_mods = ResOperandAsIntegerFormatter(n_add_mods);
let n_mul_mods = ResOperandAsIntegerFormatter(n_mul_mods);
let modulus_str = format!("{}", modulus);
let modulus_ptr = &modulus_str[1..modulus_str.len() - 1];
formatdoc! {
"
from starkware.cairo.lang.builtins.modulo.mod_builtin_runner import run_circuit
memory{computed_gates_out} = run_circuit(
memory=memory,
values_ptr=memory{values_ptr},
add_mod_builtin=memory{add_mod_builtin},
n_add_mods=memory{n_add_mods},
mul_mod_builtin=memory{mul_mod_builtin},
n_mul_mods=memory{n_mul_mods},
modulus_ptr={modulus_ptr},
)
",
}
}
}
}
}
Expand Down
26 changes: 24 additions & 2 deletions tests/e2e_test_data/libfuncs/circuit
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,18 @@ fn foo(
[fp + -3] = [[fp + -12] + 3];
[ap + -1] = [[fp + -12] + 4];
[fp + -9] = [[fp + -12] + 5];
%{ raise NotImplementedError %}
%{ from starkware.cairo.lang.builtins.modulo.mod_builtin_runner import run_circuit

memory[ap + 0] = run_circuit(
memory=memory,
values_ptr=memory[ap + -1],
add_mod_builtin=memory[fp + -13],
n_add_mods=memorymemory[fp + -10],
mul_mod_builtin=memory[fp + -12],
n_mul_mods=memorymemory[fp + -8],
modulus_ptr=fp + -6,
)
%}
[ap + 0] = [[fp + -12] + 6], ap++;
[ap + 0] = [ap + -1] * 7, ap++;
[fp + -8] = [ap + 0] + [ap + -2], ap++;
Expand Down Expand Up @@ -427,7 +438,18 @@ fn foo(
[fp + -3] = [[fp + -12] + 3];
[ap + -1] = [[fp + -12] + 4];
[fp + -9] = [[fp + -12] + 5];
%{ raise NotImplementedError %}
%{ from starkware.cairo.lang.builtins.modulo.mod_builtin_runner import run_circuit

memory[ap + 0] = run_circuit(
memory=memory,
values_ptr=memory[ap + -1],
add_mod_builtin=memory[fp + -13],
n_add_mods=memorymemory[fp + -10],
mul_mod_builtin=memory[fp + -12],
n_mul_mods=memorymemory[fp + -8],
modulus_ptr=fp + -6,
)
%}
[ap + 0] = [[fp + -12] + 6], ap++;
[ap + 0] = [ap + -1] * 7, ap++;
[fp + -8] = [ap + 0] + [ap + -2], ap++;
Expand Down

0 comments on commit 806b169

Please sign in to comment.