Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Nov 20, 2024
2 parents 359ffeb + 1e2d042 commit efa9a6c
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#### Upcoming Changes

#### [2.0.0-rc1] - 2024-11-19
#### [2.0.0-rc1] - 2024-11-20

* feat: add `EvalCircuit` and `TestLessThanOrEqualAddress` hints [#1843](https://github.com/lambdaclass/cairo-vm/pull/1843)

* fix: [#1873](https://github.com/lambdaclass/cairo-vm/pull/1873)
* Fix broken num-prime `is_prime` call
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cairo1-run/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ num-bigint.workspace = true
[features]
default = ["with_mimalloc"]
with_mimalloc = ["dep:mimalloc"]
mod_builtin = ["cairo-vm/mod_builtin"]
4 changes: 2 additions & 2 deletions cairo1-run/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
CAIRO_1_FOLDER=../cairo_programs/cairo-1-programs

$(CAIRO_1_FOLDER)/%.trace: $(CAIRO_1_FOLDER)/%.cairo
cargo run --release $< --trace_file $@ --layout all_cairo
cargo run --release -F mod_builtin $< --trace_file $@ --layout all_cairo

$(CAIRO_1_FOLDER)/%.memory: $(CAIRO_1_FOLDER)/%.cairo
cargo run --release $< --memory_file $@ --layout all_cairo
cargo run --release -F mod_builtin $< --memory_file $@ --layout all_cairo

CAIRO_1_PROGRAMS=$(wildcard ../cairo_programs/cairo-1-programs/*.cairo)
TRACES:=$(patsubst $(CAIRO_1_FOLDER)/%.cairo, $(CAIRO_1_FOLDER)/%.trace, $(CAIRO_1_PROGRAMS))
Expand Down
21 changes: 19 additions & 2 deletions cairo1-run/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ use cairo_lang_casm::{
use cairo_lang_sierra::{
extensions::{
bitwise::BitwiseType,
circuit::{AddModType, MulModType},
core::{CoreLibfunc, CoreType},
ec::EcOpType,
gas::GasBuiltinType,
pedersen::PedersenType,
poseidon::PoseidonType,
range_check::RangeCheckType,
range_check::{RangeCheck96Type, RangeCheckType},
segment_arena::SegmentArenaType,
starknet::syscalls::SystemType,
ConcreteType, NamedType,
Expand Down Expand Up @@ -670,6 +671,9 @@ fn create_entry_code(
BuiltinName::ec_op => builtin_vars[&EcOpType::ID],
BuiltinName::poseidon => builtin_vars[&PoseidonType::ID],
BuiltinName::segment_arena => builtin_vars[&SegmentArenaType::ID],
BuiltinName::add_mod => builtin_vars[&AddModType::ID],
BuiltinName::mul_mod => builtin_vars[&MulModType::ID],
BuiltinName::range_check96 => builtin_vars[&RangeCheck96Type::ID],
_ => unreachable!(),
};
if copy_to_output_builtin {
Expand Down Expand Up @@ -902,6 +906,13 @@ fn get_function_builtins(
let mut builtin_offset: HashMap<cairo_lang_sierra::ids::GenericTypeId, i16> = HashMap::new();
let mut current_offset = 3;
for (debug_name, builtin_name, sierra_id) in [
("MulMod", BuiltinName::mul_mod, MulModType::ID),
("AddMod", BuiltinName::add_mod, AddModType::ID),
(
"RangeCheck96",
BuiltinName::range_check96,
RangeCheck96Type::ID,
),
("Poseidon", BuiltinName::poseidon, PoseidonType::ID),
("EcOp", BuiltinName::ec_op, EcOpType::ID),
("Bitwise", BuiltinName::bitwise, BitwiseType::ID),
Expand Down Expand Up @@ -962,8 +973,11 @@ fn is_implicit_generic_id(generic_ty: &GenericTypeId) -> bool {
PedersenType::ID,
PoseidonType::ID,
RangeCheckType::ID,
RangeCheck96Type::ID,
SegmentArenaType::ID,
SystemType::ID,
MulModType::ID,
AddModType::ID,
]
.contains(generic_ty)
}
Expand Down Expand Up @@ -1158,6 +1172,9 @@ fn finalize_builtins(
"Pedersen" => BuiltinName::pedersen,
"Output" => BuiltinName::output,
"Ecdsa" => BuiltinName::ecdsa,
"AddMod" => BuiltinName::add_mod,
"MulMod" => BuiltinName::mul_mod,
"RangeCheck96" => BuiltinName::range_check96,
_ => {
stack_pointer.offset += size as usize;
continue;
Expand Down Expand Up @@ -1246,7 +1263,7 @@ fn serialize_output_inner<'a>(
.expect("Missing return value")
.get_relocatable()
.expect("Box Pointer is not Relocatable");
let type_size = type_sizes[&info.ty].try_into().expect("could not parse to usize");
let type_size = type_sizes[&info.ty].try_into().expect("could not parse to usize");
let data = vm
.get_continuous_range(ptr, type_size)
.expect("Failed to extract value from nullable ptr");
Expand Down
12 changes: 9 additions & 3 deletions cairo1-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct Args {
air_public_input: Option<PathBuf>,
#[clap(
long = "air_private_input",
requires_all = ["proof_mode", "trace_file", "memory_file"]
requires_all = ["proof_mode", "trace_file", "memory_file"]
)]
air_private_input: Option<PathBuf>,
#[clap(
Expand Down Expand Up @@ -436,8 +436,14 @@ mod tests {
Some("[17 18]"),
Some("[17 18]")
)]

fn test_run_progarm(
#[cfg_attr(feature = "mod_builtin", case(
"circuit.cairo",
"36699840570117848377038274035 72042528776886984408017100026 54251667697617050795983757117 7",
"[36699840570117848377038274035 72042528776886984408017100026 54251667697617050795983757117 7]",
None,
None
))]
fn test_run_program(
#[case] program: &str,
#[case] expected_output: &str,
#[case] expected_serialized_output: &str,
Expand Down
30 changes: 30 additions & 0 deletions cairo_programs/cairo-1-programs/circuit.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use core::circuit::{
RangeCheck96, AddMod, MulMod, u96, CircuitElement, CircuitInput, circuit_add,
circuit_sub, circuit_mul, circuit_inverse, EvalCircuitTrait, u384,
CircuitOutputsTrait, CircuitModulus, AddInputResultTrait, CircuitInputs,
};

fn main() -> u384 {
let in1 = CircuitElement::<CircuitInput<0>> {};
let in2 = CircuitElement::<CircuitInput<1>> {};
let add1 = circuit_add(in1, in2);
let mul1 = circuit_mul(add1, in1);
let mul2 = circuit_mul(mul1, add1);
let inv1 = circuit_inverse(mul2);
let sub1 = circuit_sub(inv1, in2);
let sub2 = circuit_sub(sub1, mul2);
let inv2 = circuit_inverse(sub2);
let add2 = circuit_add(inv2, inv2);

let modulus = TryInto::<_, CircuitModulus>::try_into([17, 14, 14, 14]).unwrap();

let outputs = (add2,)
.new_inputs()
.next([9, 2, 9, 3])
.next([5, 7, 0, 8])
.done()
.eval(modulus)
.unwrap();

outputs.get_output(add2)
}
40 changes: 40 additions & 0 deletions cairo_programs/cairo-1-programs/serialized_output/circuit.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use core::circuit::{
RangeCheck96, AddMod, MulMod, u96, CircuitElement, CircuitInput, circuit_add,
circuit_sub, circuit_mul, circuit_inverse, EvalCircuitTrait, u384,
CircuitOutputsTrait, CircuitModulus, AddInputResultTrait, CircuitInputs,
};
use array::ArrayTrait;

fn main() -> Array<felt252> {
let in1 = CircuitElement::<CircuitInput<0>> {};
let in2 = CircuitElement::<CircuitInput<1>> {};
let add1 = circuit_add(in1, in2);
let mul1 = circuit_mul(add1, in1);
let mul2 = circuit_mul(mul1, add1);
let inv1 = circuit_inverse(mul2);
let sub1 = circuit_sub(inv1, in2);
let sub2 = circuit_sub(sub1, mul2);
let inv2 = circuit_inverse(sub2);
let add2 = circuit_add(inv2, inv2);

let modulus = TryInto::<_, CircuitModulus>::try_into([17, 14, 14, 14]).unwrap();

let outputs = (add2,)
.new_inputs()
.next([9, 2, 9, 3])
.next([5, 7, 0, 8])
.done()
.eval(modulus)
.unwrap();

let circuit_output = outputs.get_output(add2);

let mut output: Array<felt252> = ArrayTrait::new();

circuit_output.limb0.serialize(ref output);
circuit_output.limb1.serialize(ref output);
circuit_output.limb2.serialize(ref output);
circuit_output.limb3.serialize(ref output);

output
}
Loading

0 comments on commit efa9a6c

Please sign in to comment.