From 7a5998b94e234c2d48c0f7c5859497c2fa97098a Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 19 Sep 2024 18:09:32 -0300 Subject: [PATCH 01/33] add TestLessThanOrEqual match case + start implementing EvalCircuit Hint --- cairo_programs/cairo-1-programs/circuit.cairo | 30 ++++++++ .../cairo_1_hint_processor/circuit.rs | 72 +++++++++++++++++++ .../cairo_1_hint_processor/hint_processor.rs | 58 ++++++++++++++- .../cairo_1_hint_processor/mod.rs | 1 + 4 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 cairo_programs/cairo-1-programs/circuit.cairo create mode 100644 vm/src/hint_processor/cairo_1_hint_processor/circuit.rs diff --git a/cairo_programs/cairo-1-programs/circuit.cairo b/cairo_programs/cairo-1-programs/circuit.cairo new file mode 100644 index 0000000000..5624c92ccc --- /dev/null +++ b/cairo_programs/cairo-1-programs/circuit.cairo @@ -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::> {}; + let in2 = CircuitElement::> {}; + 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) +} diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs new file mode 100644 index 0000000000..4e56073e8f --- /dev/null +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -0,0 +1,72 @@ +use ark_ff::Zero; +use num_bigint::BigUint; + +use crate::{types::relocatable::{MaybeRelocatable, Relocatable}, vm::vm_core::VirtualMachine}; + +// Represents the number of limbs use to represent a single value in a circuit +const LIMBS_COUNT: usize = 4; + +struct CircuitInstance<'a> { + vm: &'a mut VirtualMachine, + values_ptr: Relocatable, + add_mod_offsets: Relocatable, + mul_mod_offsets: Relocatable, + modulus: BigUint, +} + +impl CircuitInstance<'_> { + fn fill_add_gate(&mut self, index: usize) -> bool {todo!()} + fn fill_mul_gate(&mut self, index: usize) -> bool {todo!()} +} + +fn read_circuit_value(vm: &mut VirtualMachine, add: Relocatable) -> Option { + let mut res = BigUint::zero(); + + for l in (0..LIMBS_COUNT).rev() { + let add_l = (add + l).unwrap(); + match vm.get_maybe(&add_l) { + Some(MaybeRelocatable::Int(limb)) => res = (res << 96) + limb.to_biguint(), + _ => return None + } + } + + Some(res) +} + +pub fn fill_values( + vm: &mut VirtualMachine, + values_ptr: Relocatable, + add_mod_offsets: Relocatable, + n_add_mods: usize, + mul_mod_offsets: Relocatable, + n_mul_mods: usize, + modulus_ptr: Relocatable, +) -> usize { + let modulus = read_circuit_value(vm, modulus_ptr).unwrap(); + let circuit = CircuitInstance {vm, values_ptr, add_mod_offsets, mul_mod_offsets, modulus}; + + let mut addmod_idx = 0; + let mut mulmod_idx = 0; + + // A circuit evaluation can only fail through a mulmod operation + let mut first_failure_idx = n_mul_mods; + + loop { + while addmod_idx < n_add_mods { + if !circuit.fill_add_gate() { + break; + } + addmod_idx += 1; + } + + if mulmod_idx == n_mul_mods { + break; + } + + if !circuit.fill_mul_gate(3 * mulmod_idx) && first_failure_idx == n_mul_mods { + first_failure_idx = mulmod_idx; + } + mulmod_idx += 1; + } + 0 +} diff --git a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs index 98bb0a1547..b65ad2b566 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs @@ -1,3 +1,4 @@ +use super::circuit::fill_values; use super::dict_manager::DictManagerExecScope; use super::hint_processor_utils::*; use crate::any_box; @@ -85,9 +86,12 @@ impl Cairo1HintProcessor { Hint::Core(CoreHintBase::Core(CoreHint::TestLessThan { lhs, rhs, dst })) => { self.test_less_than(vm, lhs, rhs, dst) } - Hint::Core(CoreHintBase::Core(CoreHint::TestLessThanOrEqual { lhs, rhs, dst })) => { - self.test_less_than_or_equal(vm, lhs, rhs, dst) - } + Hint::Core(CoreHintBase::Core(CoreHint::TestLessThanOrEqual { lhs, rhs, dst })) + | Hint::Core(CoreHintBase::Core(CoreHint::TestLessThanOrEqualAddress { + lhs, + rhs, + dst, + })) => self.test_less_than_or_equal(vm, lhs, rhs, dst), Hint::Core(CoreHintBase::Deprecated(DeprecatedHint::Felt252DictRead { dict_ptr, key, @@ -274,6 +278,12 @@ impl Cairo1HintProcessor { t_or_k0, t_or_k1, ), + Hint::Core(CoreHintBase::Core(CoreHint::EvalCircuit { + n_add_mods, + add_mod_builtin, + n_mul_mods, + mul_mod_builtin, + })) => self.eval_circuit(vm, n_add_mods, add_mod_builtin, n_mul_mods, mul_mod_builtin), Hint::Starknet(StarknetHint::Cheatcode { selector, .. }) => { let selector = &selector.value.to_bytes_be().1; let selector = crate::stdlib::str::from_utf8(selector).map_err(|_| { @@ -1192,6 +1202,48 @@ impl Cairo1HintProcessor { } Ok(()) } + fn eval_circuit( + &self, + vm: &mut VirtualMachine, + n_add_mods: &ResOperand, + add_mod_builtin_ptr: &ResOperand, + n_mul_mods: &ResOperand, + mul_mod_builtin_ptr: &ResOperand, + ) -> Result<(), HintError> { + let n_add_mods = get_val(vm, n_add_mods)?.to_usize().unwrap(); + let n_mul_mods = get_val(vm, n_mul_mods)?.to_usize().unwrap(); + + let (add_mod_builtin_base, add_mod_builtin_offset) = extract_buffer(add_mod_builtin_ptr)?; + let (mul_mod_builtin_base, mul_mod_builtin_offset) = extract_buffer(mul_mod_builtin_ptr)?; + + let add_mod_builtin_address = get_ptr(vm, add_mod_builtin_base, &add_mod_builtin_offset)?; + let mul_mod_builtin_address = get_ptr(vm, mul_mod_builtin_base, &mul_mod_builtin_offset)?; + + let modulus_ptr = mul_mod_builtin_address; + // The offset of the values pointer inside the mul_mod_builtin + let values_offset = 4; + // The offset of the offsets pointer inside the mul_mod_builtin + let offsets_offset = 5; + + let values_ptr = vm.get_relocatable((mul_mod_builtin_address + values_offset)?)?; + let mul_mod_offsets = vm.get_relocatable((mul_mod_builtin_address + offsets_offset)?)?; + let add_mod_offsets = if n_add_mods == 0 { + mul_mod_offsets + } else { + vm.get_relocatable((add_mod_builtin_address + offsets_offset)?)? + }; + + let n_computed_gates = fill_values( + vm, + values_ptr, + add_mod_offsets, + n_add_mods, + mul_mod_offsets, + n_mul_mods, + modulus_ptr, + ); + Ok(()) + } } impl HintProcessorLogic for Cairo1HintProcessor { diff --git a/vm/src/hint_processor/cairo_1_hint_processor/mod.rs b/vm/src/hint_processor/cairo_1_hint_processor/mod.rs index 29d5f47bd3..d6d964081e 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/mod.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/mod.rs @@ -1,3 +1,4 @@ +pub mod circuit; pub mod dict_manager; pub mod hint_processor; pub mod hint_processor_utils; From d013f727a0712f70f251f17d0f011f6e129065fc Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 20 Sep 2024 14:45:36 -0300 Subject: [PATCH 02/33] add eval circuit functionallity --- cairo1-run/cairo | 1 + .../cairo_1_hint_processor/circuit.rs | 208 +++++++++++++++++- .../cairo_1_hint_processor/hint_processor.rs | 27 +-- 3 files changed, 206 insertions(+), 30 deletions(-) create mode 160000 cairo1-run/cairo diff --git a/cairo1-run/cairo b/cairo1-run/cairo new file mode 160000 index 0000000000..9322175308 --- /dev/null +++ b/cairo1-run/cairo @@ -0,0 +1 @@ +Subproject commit 93221753088d58f54f9a7f35a0bb338cf0bfb952 diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 4e56073e8f..c3e1909664 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -1,10 +1,24 @@ -use ark_ff::Zero; +use core::{ + array, + ops::{Deref, Shl}, +}; + +use ark_ff::{One, Zero}; use num_bigint::BigUint; +use num_integer::Integer; +use starknet_types_core::felt::Felt; -use crate::{types::relocatable::{MaybeRelocatable, Relocatable}, vm::vm_core::VirtualMachine}; +use crate::{ + types::relocatable::{MaybeRelocatable, Relocatable}, + vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, +}; +// A gate is defined by 3 offsets, the first two are the inputs and the third is the output. +const OFFSETS_PER_GATE: usize = 3; // Represents the number of limbs use to represent a single value in a circuit const LIMBS_COUNT: usize = 4; +// Representes the size of a MulMod and AddMod instance +const MOD_BUILTIN_INSTACE_SIZE: usize = 7; struct CircuitInstance<'a> { vm: &'a mut VirtualMachine, @@ -15,10 +29,97 @@ struct CircuitInstance<'a> { } impl CircuitInstance<'_> { - fn fill_add_gate(&mut self, index: usize) -> bool {todo!()} - fn fill_mul_gate(&mut self, index: usize) -> bool {todo!()} + fn read_add_mod_value(&mut self, offset: usize) -> Option { + self.read_circuit_value((self.add_mod_offsets + offset).unwrap()) + } + + fn read_mul_mod_value(&mut self, offset: usize) -> Option { + self.read_circuit_value((self.mul_mod_offsets + offset).unwrap()) + } + + fn read_circuit_value(&mut self, offset: Relocatable) -> Option { + let value_ptr = self.get_value_ptr(offset); + read_circuit_value(self.vm, value_ptr) + } + + fn write_add_mod_value(&mut self, offset: usize, value: BigUint) { + self.write_circuit_value((self.add_mod_offsets + offset).unwrap(), value); + } + + fn write_mul_mod_value(&mut self, offset: usize, value: BigUint) { + self.write_circuit_value((self.mul_mod_offsets + offset).unwrap(), value); + } + + fn write_circuit_value(&mut self, offset: Relocatable, value: BigUint) { + let value_ptr = self.get_value_ptr(offset); + write_circuit_value(self.vm, value_ptr, value); + } + + fn get_value_ptr(&self, address: Relocatable) -> Relocatable { + (self.values_ptr + self.vm.get_integer(address).unwrap().as_ref()).unwrap() + } + + /// Fills an `add_mod` gate + /// + /// Returns `true` if all the inputs of the gate are filled up and so the operation can be performed, + /// `false` otherwise. + fn fill_add_gate(&mut self, index: usize) -> bool { + let lhs = self.read_add_mod_value(index); + let rhs = self.read_add_mod_value(index + 1); + + match (lhs, rhs) { + (Some(l), Some(r)) => { + let res = (l + r) % &self.modulus; + self.write_add_mod_value(index + 2, res); + true + } + // sub gate: lhs + rhs = res => lhs = res - rhs + (None, Some(r)) => { + let Some(res) = self.read_add_mod_value(index + 2) else { + return false; + }; + let value = (res + &self.modulus - r) % &self.modulus; + self.write_add_mod_value(index, value); + true + } + _ => false, + } + } + + /// Fills the a `mul_mod` gate + /// + /// Returns `true` if all the inputs of the gates are filled up and so the operation can be performed, + /// false if it is an inverse opeartion with a non invertible input. + /// + /// This operation implies that all the gate's inputs are filled up, + /// and will panic if that is not the case. + fn fill_mul_gate(&mut self, index: usize) -> bool { + let lhs = self.read_mul_mod_value(index); + let rhs = self.read_mul_mod_value(index + 1); + + match (lhs, rhs) { + (Some(l), Some(r)) => { + let res = (l * r) % &self.modulus; + self.write_mul_mod_value(index + 2, res); + true + } + // inverse gate: lhs * rhs = 1 => lhs = 1 / rhs + (None, Some(r)) => { + let res = match r.modinv(&self.modulus) { + Some(inv) => inv, + None => { + return false; + } + }; + self.write_mul_mod_value(index, res); + true + } + _ => unreachable!("Unexpected None value while filling mul_mod gate"), + } + } } +/// Reads a circuit value from memory fn read_circuit_value(vm: &mut VirtualMachine, add: Relocatable) -> Option { let mut res = BigUint::zero(); @@ -26,14 +127,29 @@ fn read_circuit_value(vm: &mut VirtualMachine, add: Relocatable) -> Option res = (res << 96) + limb.to_biguint(), - _ => return None + _ => return None, } } Some(res) } -pub fn fill_values( +// Writes a circuit value in memory +fn write_circuit_value(vm: &mut VirtualMachine, add: Relocatable, mut value: BigUint) { + for l in 0..LIMBS_COUNT { + // get the nth limb from a circuit value + let (new_value, rem) = value.div_rem(&BigUint::one().shl(96)); + vm.insert_value((add + l).unwrap(), Felt::from(rem)) + .unwrap(); + value = new_value; + } +} + +/// Fills the values for a circuit +/// +/// Returns the first mul gate index that failed to fill its values or +/// `n_mul_mods` if all gates were filled successfully +fn fill_values( vm: &mut VirtualMachine, values_ptr: Relocatable, add_mod_offsets: Relocatable, @@ -43,7 +159,13 @@ pub fn fill_values( modulus_ptr: Relocatable, ) -> usize { let modulus = read_circuit_value(vm, modulus_ptr).unwrap(); - let circuit = CircuitInstance {vm, values_ptr, add_mod_offsets, mul_mod_offsets, modulus}; + let mut circuit = CircuitInstance { + vm, + values_ptr, + add_mod_offsets, + mul_mod_offsets, + modulus, + }; let mut addmod_idx = 0; let mut mulmod_idx = 0; @@ -53,7 +175,7 @@ pub fn fill_values( loop { while addmod_idx < n_add_mods { - if !circuit.fill_add_gate() { + if !circuit.fill_add_gate(3 * addmod_idx) { break; } addmod_idx += 1; @@ -68,5 +190,73 @@ pub fn fill_values( } mulmod_idx += 1; } - 0 + + first_failure_idx +} + +fn fill_instances( + vm: &mut VirtualMachine, + built_ptr: Relocatable, + n_instances: usize, + modulus: [Felt; LIMBS_COUNT], + values_ptr: Relocatable, + mut offsets_ptr: Relocatable, +) -> Result<(), HintError> { + for i in 0..n_instances { + let instance_ptr = (built_ptr + i * MOD_BUILTIN_INSTACE_SIZE).unwrap(); + + for (idx, value) in modulus.iter().enumerate() { + vm.insert_value((instance_ptr + idx)?, *value)?; + } + + vm.insert_value((instance_ptr + 4)?, values_ptr)?; + vm.insert_value((instance_ptr + 5)?, offsets_ptr)?; + offsets_ptr += OFFSETS_PER_GATE; + vm.insert_value((instance_ptr + 6)?, n_instances - i)?; + } + Ok(()) +} + +/// Evaluates a circuit and fills the builtin instances and the values buffer. +/// +/// Returns the first mul gate index that failed to fill its values +/// or `n_mul_mods` if all gates were filled successfully. +pub fn eval_circuit( + vm: &mut VirtualMachine, + n_add_mods: usize, + add_mod_builtin_address: Relocatable, + n_mul_mods: usize, + mul_mod_builtin_address: Relocatable, +) -> Result<(), HintError> { + let modulus_ptr = mul_mod_builtin_address; + // The offset of the values pointer inside the mul_mod_builtin + let values_offset = 4; + // The offset of the offsets pointer inside the mul_mod_builtin + let offsets_offset = 5; + + let values_ptr = vm.get_relocatable((mul_mod_builtin_address + values_offset)?)?; + let mul_mod_offsets = vm.get_relocatable((mul_mod_builtin_address + offsets_offset)?)?; + let add_mod_offsets = if n_add_mods == 0 { + mul_mod_offsets + } else { + vm.get_relocatable((add_mod_builtin_address + offsets_offset)?)? + }; + + let n_computed_gates = fill_values( + vm, + values_ptr, + add_mod_offsets, + n_add_mods, + mul_mod_offsets, + n_mul_mods, + modulus_ptr, + ); + + let modulus: [Felt; 4] = + array::from_fn(|l| *vm.get_integer((modulus_ptr + l).unwrap()).unwrap().deref()); + + fill_instances(vm, add_mod_builtin_address, n_add_mods, modulus, values_ptr, add_mod_offsets)?; + fill_instances(vm, mul_mod_builtin_address, n_computed_gates, modulus, values_ptr, mul_mod_offsets)?; + + Ok(()) } diff --git a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs index b65ad2b566..8fc40842e9 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs @@ -1,4 +1,4 @@ -use super::circuit::fill_values; +use super::circuit; use super::dict_manager::DictManagerExecScope; use super::hint_processor_utils::*; use crate::any_box; @@ -1219,29 +1219,14 @@ impl Cairo1HintProcessor { let add_mod_builtin_address = get_ptr(vm, add_mod_builtin_base, &add_mod_builtin_offset)?; let mul_mod_builtin_address = get_ptr(vm, mul_mod_builtin_base, &mul_mod_builtin_offset)?; - let modulus_ptr = mul_mod_builtin_address; - // The offset of the values pointer inside the mul_mod_builtin - let values_offset = 4; - // The offset of the offsets pointer inside the mul_mod_builtin - let offsets_offset = 5; - - let values_ptr = vm.get_relocatable((mul_mod_builtin_address + values_offset)?)?; - let mul_mod_offsets = vm.get_relocatable((mul_mod_builtin_address + offsets_offset)?)?; - let add_mod_offsets = if n_add_mods == 0 { - mul_mod_offsets - } else { - vm.get_relocatable((add_mod_builtin_address + offsets_offset)?)? - }; - - let n_computed_gates = fill_values( + circuit::eval_circuit( vm, - values_ptr, - add_mod_offsets, n_add_mods, - mul_mod_offsets, + add_mod_builtin_address, n_mul_mods, - modulus_ptr, - ); + mul_mod_builtin_address, + )?; + Ok(()) } } From 3456d3d0c38721dca922c589c2db8dab34f972d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Fri, 20 Sep 2024 16:12:21 -0300 Subject: [PATCH 03/33] Add support for circuit builtins in cairo-run --- cairo1-run/Cargo.toml | 1 + cairo1-run/src/cairo_run.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index 500d410d28..5390732e17 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -34,3 +34,4 @@ num-bigint.workspace = true [features] default = ["with_mimalloc"] with_mimalloc = ["dep:mimalloc"] +mod_builtin = ["cairo-vm/mod_builtin"] diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index 3f8095e160..e7a7535ea2 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -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, @@ -657,6 +658,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 { @@ -887,6 +891,13 @@ fn get_function_builtins( let mut builtin_offset: HashMap = 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), From de0ddb6f88e9421ac4a4ab1f876cbb08f47dbf5d Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 25 Sep 2024 12:18:57 -0300 Subject: [PATCH 04/33] possible fix to segment error in EvalCircuit Hint --- cairo1-run/src/cairo_run.rs | 15 +++++++++------ .../cairo_1_hint_processor/circuit.rs | 19 +++++++++++++++++-- vm/src/vm/runners/cairo_runner.rs | 1 + 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index e7a7535ea2..00303d0be0 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -188,7 +188,8 @@ pub fn cairo_run_program( let builtin_count: i16 = builtins.len().into_or_panic(); // This is the program we are actually running/proving - // With (embedded proof mode), cairo1 header and the libfunc footer + // With (embedded proof mode), cairo1 header and the libfunc foote + let instructions = chain!( entry_code.instructions.iter(), casm_program.instructions.iter(), @@ -196,15 +197,17 @@ pub fn cairo_run_program( ); let (processor_hints, program_hints) = build_hints_vec(instructions.clone()); - + // This is the instructions + the segment's value up to this point appended after the footr + let bytecode = casm_program + .assemble_ex(&entry_code.instructions, &libfunc_footer) + .bytecode; let mut hint_processor = Cairo1HintProcessor::new( &processor_hints, RunResources::default(), cairo_run_config.copy_to_output(), ); - - let data: Vec = instructions - .flat_map(|inst| inst.assemble().encode()) + let data: Vec = bytecode + .into_iter() .map(|x| Felt252::from(&x)) .map(MaybeRelocatable::from) .collect(); @@ -1242,7 +1245,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"); diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index c3e1909664..15ed256366 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -228,6 +228,7 @@ pub fn eval_circuit( n_mul_mods: usize, mul_mod_builtin_address: Relocatable, ) -> Result<(), HintError> { + println!("Memory: {}", &vm.segments); let modulus_ptr = mul_mod_builtin_address; // The offset of the values pointer inside the mul_mod_builtin let values_offset = 4; @@ -255,8 +256,22 @@ pub fn eval_circuit( let modulus: [Felt; 4] = array::from_fn(|l| *vm.get_integer((modulus_ptr + l).unwrap()).unwrap().deref()); - fill_instances(vm, add_mod_builtin_address, n_add_mods, modulus, values_ptr, add_mod_offsets)?; - fill_instances(vm, mul_mod_builtin_address, n_computed_gates, modulus, values_ptr, mul_mod_offsets)?; + fill_instances( + vm, + add_mod_builtin_address, + n_add_mods, + modulus, + values_ptr, + add_mod_offsets, + )?; + fill_instances( + vm, + mul_mod_builtin_address, + n_computed_gates, + modulus, + values_ptr, + mul_mod_offsets, + )?; Ok(()) } diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index ecf47892b0..1d1de0f004 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -656,6 +656,7 @@ impl CairoRunner { .clone(); #[cfg(feature = "test_utils")] self.vm.execute_before_first_step(&hint_data)?; + while self.vm.get_pc() != address && !hint_processor.consumed() { self.vm.step( hint_processor, From 3d55984924a70b2de74586e684e2cdcdaf6a4c13 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 25 Sep 2024 12:21:25 -0300 Subject: [PATCH 05/33] remove unwanted files --- cairo1-run/cairo | 1 - vm/src/vm/runners/cairo_runner.rs | 1 - 2 files changed, 2 deletions(-) delete mode 160000 cairo1-run/cairo diff --git a/cairo1-run/cairo b/cairo1-run/cairo deleted file mode 160000 index 9322175308..0000000000 --- a/cairo1-run/cairo +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 93221753088d58f54f9a7f35a0bb338cf0bfb952 diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index 1d1de0f004..ecf47892b0 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -656,7 +656,6 @@ impl CairoRunner { .clone(); #[cfg(feature = "test_utils")] self.vm.execute_before_first_step(&hint_data)?; - while self.vm.get_pc() != address && !hint_processor.consumed() { self.vm.step( hint_processor, From 5e2a723c197fce629c1076adb4f3720b33403f07 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 25 Sep 2024 12:24:30 -0300 Subject: [PATCH 06/33] format --- cairo1-run/src/cairo_run.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index 00303d0be0..df089a53fd 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -188,8 +188,7 @@ pub fn cairo_run_program( let builtin_count: i16 = builtins.len().into_or_panic(); // This is the program we are actually running/proving - // With (embedded proof mode), cairo1 header and the libfunc foote - + // With (embedded proof mode), cairo1 header and the libfunc footer let instructions = chain!( entry_code.instructions.iter(), casm_program.instructions.iter(), @@ -197,7 +196,7 @@ pub fn cairo_run_program( ); let (processor_hints, program_hints) = build_hints_vec(instructions.clone()); - // This is the instructions + the segment's value up to this point appended after the footr + // These the instructions' bytecode + the segment's value up to this point appended after the footer let bytecode = casm_program .assemble_ex(&entry_code.instructions, &libfunc_footer) .bytecode; From 32b62eac7c27bf75a7b2a0294836906f2510c2f1 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 26 Sep 2024 16:30:54 -0300 Subject: [PATCH 07/33] fix NoStopPointer issue --- cairo1-run/src/cairo_run.rs | 3 ++ .../serialized_output/circuit.cairo | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 cairo_programs/cairo-1-programs/serialized_output/circuit.cairo diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index df089a53fd..dd963cce41 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -1156,6 +1156,9 @@ fn finalize_builtins( "Pedersen" => BuiltinName::pedersen, "Output" => BuiltinName::output, "Ecdsa" => BuiltinName::ecdsa, + "RangeCheck96" => BuiltinName::range_check96, + "AddMod" => BuiltinName::add_mod, + "MulMod" => BuiltinName::mul_mod, _ => { stack_pointer.offset += size as usize; continue; diff --git a/cairo_programs/cairo-1-programs/serialized_output/circuit.cairo b/cairo_programs/cairo-1-programs/serialized_output/circuit.cairo new file mode 100644 index 0000000000..a638680e95 --- /dev/null +++ b/cairo_programs/cairo-1-programs/serialized_output/circuit.cairo @@ -0,0 +1,43 @@ +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 { + let in1 = CircuitElement::> {}; + let in2 = CircuitElement::> {}; + 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 limbs_output = ArrayTrait::new(); + + limbs_output.append(circuit_output.limb0); + limbs_output.append(circuit_output.limb1); + limbs_output.append(circuit_output.limb2); + limbs_output.append(circuit_output.limb3); + + let mut output: Array = ArrayTrait::new(); + + limbs_output.serialize(ref output); + + output +} From 2fc325869d7f573a707bf60adc0c32d03cf235e9 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 30 Sep 2024 10:33:03 -0300 Subject: [PATCH 08/33] tests passing --- cairo1-run/Cargo.toml | 6 +++--- cairo1-run/src/cairo_run.rs | 5 ++++- cairo1-run/src/main.rs | 19 ++++++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index 5390732e17..9d699de792 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -12,9 +12,9 @@ keywords.workspace = true cairo-vm = { workspace = true, features = ["std", "cairo-1-hints", "clap"] } serde_json = { workspace = true } -cairo-lang-sierra-type-size = { version = "2.8.0", default-features = false } -cairo-lang-sierra-ap-change = { version = "2.8.0", default-features = false } -cairo-lang-sierra-gas = { version = "2.8.0", default-features = false } +cairo-lang-sierra-type-size = { version = "2.8.2", default-features = false } +cairo-lang-sierra-ap-change = { version = "2.8.2", default-features = false } +cairo-lang-sierra-gas = { version = "2.8.2", default-features = false } cairo-lang-starknet-classes.workspace = true cairo-lang-sierra-to-casm.workspace = true cairo-lang-compiler.workspace = true diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index dd963cce41..a3e9e7140d 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -960,8 +960,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) } @@ -1156,9 +1159,9 @@ fn finalize_builtins( "Pedersen" => BuiltinName::pedersen, "Output" => BuiltinName::output, "Ecdsa" => BuiltinName::ecdsa, - "RangeCheck96" => BuiltinName::range_check96, "AddMod" => BuiltinName::add_mod, "MulMod" => BuiltinName::mul_mod, + "RangeCheck96" => BuiltinName::range_check96, _ => { stack_pointer.offset += size as usize; continue; diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index 47c9abfbca..980f19d786 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -32,7 +32,7 @@ struct Args { air_public_input: Option, #[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, #[clap( @@ -424,8 +424,21 @@ mod tests { Some("[17 18]"), Some("[17 18]") )] - - fn test_run_progarm( + #[case( + "circuit.cairo", + "36699840570117848377038274035 72042528776886984408017100026 54251667697617050795983757117 7", + "[36699840570117848377038274035 72042528776886984408017100026 54251667697617050795983757117 7]", + None, + None + )] + // #[case( + // "circuit_failure.cairo", + // "", + // "", + // None, + // None + // )] + fn test_run_program( #[case] program: &str, #[case] expected_output: &str, #[case] expected_serialized_output: &str, From 45b739f3de054432163c579ed22bdfd55330e6ca Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 30 Sep 2024 10:33:47 -0300 Subject: [PATCH 09/33] tests passing --- Cargo.lock | 358 +++++++++--------- Cargo.toml | 16 +- .../cairo-1-programs/circuit_failure.cairo | 24 ++ .../serialized_output/circuit.cairo | 11 +- .../cairo_1_hint_processor/circuit.rs | 1 - 5 files changed, 212 insertions(+), 198 deletions(-) create mode 100644 cairo_programs/cairo-1-programs/circuit_failure.cairo diff --git a/Cargo.lock b/Cargo.lock index 03c0cb9c47..7c8e3df555 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,19 +4,13 @@ version = 3 [[package]] name = "addr2line" -version = "0.22.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" dependencies = [ "gimli", ] -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "adler2" version = "2.0.0" @@ -122,9 +116,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "arbitrary" @@ -238,20 +232,20 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "axum" @@ -304,17 +298,17 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", - "miniz_oxide 0.7.4", + "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] [[package]] @@ -431,15 +425,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cairo-lang-casm" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad9e8fe95ee2add1537d00467b98bb8928334633eb01dcba7f33fb64769af259" +checksum = "60a4b4ca8473c25d1e760c83c2a49d953197556f82f6feb636004d3b6d6cc4a7" dependencies = [ "cairo-lang-utils", "indoc", @@ -451,9 +445,9 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0db1ae47b4918a894b60160fac42e6fbcb5a8c0023dd6c290ba03a1bcdf5a554" +checksum = "5852668d1c6966b34d6e4fe249732769ab9cb2012c201e3889d8119f206760a0" dependencies = [ "anyhow", "cairo-lang-defs", @@ -477,18 +471,18 @@ dependencies = [ [[package]] name = "cairo-lang-debug" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c87b905b74516c33fc7e6d61b5243363ce65133054c30bd9531f47e30ca201" +checksum = "b0644fab571f598547993936918c85f0e89b0bbc15140ca3ea723bff376be07d" dependencies = [ "cairo-lang-utils", ] [[package]] name = "cairo-lang-defs" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611996d85ec608bfec75d546a5c2ec44f664f4bd2514840a5b369d30a1a8bfdb" +checksum = "7f5f437d75ac25644880458effde562edcac45a888d27f2e497d30c6450fa97d" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -503,9 +497,9 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d015a0790b1f5de8b22b4b4b60d392c35bed07b7aa9dd22361af2793835cee51" +checksum = "6ec5b44d3eaf50e28e068d163e56b9effcea6afe3625c32dd96418d2d4ebc34c" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -515,9 +509,9 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c580e56e5857d51b6bf2ec5ed5fdd33fd3b74dad7e3cb6d7398396174a6c85" +checksum = "a0cd844e568f51e39729e8ac18bd27ada2e2b6dc9138f8c81adad48456480681" dependencies = [ "cairo-lang-utils", "good_lp", @@ -525,9 +519,9 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5368e66a742b8532d656171525bfea599490280ceee10bdac93ad60775fc4e59" +checksum = "323a2385e000589f7591f8a46599b4a462db6e36e5935bad3bceddcc1a1608e1" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -540,9 +534,9 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1200324728e7f4c4acedceee427d9b3ffce221af57e469a454f007cbc248255" +checksum = "1cf9cf637e12d41260dc59f3d988c76a6347424913ac8b6b8449ff3e79b59750" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -561,9 +555,9 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a7a3069c75e1aca7cf15f20d03baf71f5c86e5be26988f6c25656549aa8b54a" +checksum = "5d71bc5b1f19a00eb662c2cac33259b16b9cdbf9c005047aca0d538c13936407" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -585,9 +579,9 @@ dependencies = [ [[package]] name = "cairo-lang-parser" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c13b245ddc740ebfed8b05e1bdb7805a06d267cf89d46486c9609306f92d45ce" +checksum = "5d939d258e26ace0f3cb1e50338ae18981a7505e3c20eabd24a62d70ee862d6c" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -605,9 +599,9 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b656552d0ab4a69be223e42c4e1c4028e512f506a237d04bbe4ccab9a1e13c5" +checksum = "b67a553a6d2d2b54264e77e3c8cb5bc866b40b32d5e2144a58b74c559c7e289f" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -624,20 +618,20 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05cc6adb49faa42ea825e041dff0496c2e72e4ddaf50734062a62383c0c8adbf" +checksum = "c33b5f4502b7efde6ac07fd5468f6dae15d88760aeece3d57a7bc4c224ba693e" dependencies = [ "cairo-lang-debug", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "cairo-lang-project" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad123ba0e0dd5e1ea80977c0244ff4b0b6d8bf050d42ecb5ff0cf7f885e871f9" +checksum = "b63d6a3cc86a79a29978acaaf6f94738c5487e265247fe06c7bf359645d8c200" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -649,9 +643,9 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d528c79e4ff3e1364569c07e22660ddf60c0d1989705b8f0feed9949962b28a" +checksum = "00c284031fd14796dad91483c3039d7929f8440e1e9e334017744b1d22df5aa8" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -675,9 +669,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bdb0c2cc419f45ab7e413322502ca02c2a2c56aeabdd0885e3740f378d8b269" +checksum = "891488c1a3184ce91679f5bdb63015a1d24769a48bd07e5d51a1779d0031dfbe" dependencies = [ "anyhow", "cairo-lang-utils", @@ -702,9 +696,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7224cd827ccf69e742c90a60278876865a96b545a101248d9472d2e02f9190b3" +checksum = "ea7752cd48c86b2cde8603b753a6df4da086dacd16a73d288854d5f040b51171" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -718,9 +712,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e379e3010827fe983e66aa38a0d25fe24cfc11eaf8cadf4dc7bcb31fff031de" +checksum = "340892a09c9421414b2ac45b03c705f16e2bd737e4559dfd98ee1d20718dec9e" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -734,9 +728,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6b353930676c06bb885a16ec3b120109aa15539c49f41b3370a5a6314dc29dc" +checksum = "c5cc616e8df44c4d685fe3c5f81f35ebbda57225098b35cea8602457c45c9e96" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -758,9 +752,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83873751d489aae4674f3d755a4897429a664bdc4b0847283e13889f0b0c2a44" +checksum = "1c22ff7e8113a46a907f82f191096c96935cc48247e3079971ddf536ccc2f4f8" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -779,9 +773,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd84b445715326e44832836732b6bda76a119116b296ac9b6b87e2a4177634a" +checksum = "5bf41941776e7410a8853a8e2a116292fc24d219df1989a92ffe5ab0e98037eb" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -789,9 +783,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8df3086f909d27a49d6706be835725df4e21fb50efe699cd763d1f782a31dea" +checksum = "b5508fa5ee8d24adf7d2c65505d0ac35efc892eac16d1449c6f7e314a0288cb8" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -819,9 +813,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41bcab650779b3431389dc52f1e643a7c9690a1aa2b072c8f01955503d094007" +checksum = "482b8f9d7f8cc7140f1260ee71f3308a66d15bd228a06281067ca3f8f4410db2" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -842,9 +836,9 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e2dc876ec02a197b8d13dbfc0b2cf7a7e31dcfc6446761cbb85f5b42d589cdc" +checksum = "7db0776c3d06cea65d7afe7a3c7685f6867eb6d951cf505caf35abfd1746773b" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -858,9 +852,9 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8727fe3f24ec0834ec6656c70a59f85233439f0a09ca53cf5e27fbdb1b40193" +checksum = "8ce0f7fa01c26cc731bc1d6350ac02fae91a68b5fdf60e684f991e861715adc4" dependencies = [ "genco", "xshell", @@ -868,9 +862,9 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a7681562268173d74b1c8d2438a1d9ec3218c89a8e39a8be3f10e044fa46ebe" +checksum = "630a070a69c387eee9c0eda65e4f2508d129d4fbe081091077e661020ab95637" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -881,9 +875,9 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "2.8.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e6004780c42bf28ce5afd048cc628b3de34aaf24fd2c228ae73217c58999f9" +checksum = "73104609a7d865e4cd1de9cbf4e750683d076b6d0233bf81be511df274a26916" dependencies = [ "hashbrown 0.14.5", "indexmap 2.5.0", @@ -1006,9 +1000,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.15" +version = "1.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +checksum = "3bbb537bb4a30b90362caddba8f360c0a56bc13d3a5570028e7197204cb54a17" dependencies = [ "jobserver", "libc", @@ -1050,9 +1044,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.16" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" +checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" dependencies = [ "clap_builder", "clap_derive", @@ -1060,9 +1054,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.15" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" dependencies = [ "anstream", "anstyle", @@ -1072,14 +1066,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1122,18 +1116,18 @@ checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" [[package]] name = "const_format" -version = "0.2.32" +version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" +checksum = "50c655d81ff1114fb0dcdea9225ea9f0cc712a6f8d189378e82bdf62a473a64b" dependencies = [ "const_format_proc_macros", ] [[package]] name = "const_format_proc_macros" -version = "0.2.32" +version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" +checksum = "eff1a44b93f47b1bac19a27932f5c591e43d1ba357ee4f61526c8a25603f0eb1" dependencies = [ "proc-macro2", "quote", @@ -1151,9 +1145,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -1274,7 +1268,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1375,12 +1369,12 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" dependencies = [ "crc32fast", - "miniz_oxide 0.8.0", + "miniz_oxide", ] [[package]] @@ -1460,7 +1454,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1518,7 +1512,7 @@ checksum = "553630feadf7b76442b0849fd25fdf89b860d933623aec9693fed19af0400c78" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1546,15 +1540,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" [[package]] name = "globset" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19" dependencies = [ "aho-corasick", "bstr", @@ -1734,9 +1728,9 @@ checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" [[package]] name = "ignore" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b" dependencies = [ "crossbeam-deque", "globset", @@ -1814,9 +1808,9 @@ checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "iri-string" -version = "0.7.2" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f5f6c2df22c009ac44f6f1499308e7a3ac7ba42cd2378475cc691510e1eef1b" +checksum = "44bd7eced44cfe2cebc674adb2a7124a754a4b5269288d22e9f39f8fada3562d" dependencies = [ "memchr", "serde", @@ -1963,9 +1957,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libm" @@ -2086,15 +2080,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - [[package]] name = "miniz_oxide" version = "0.8.0" @@ -2243,9 +2228,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "oorandom" @@ -2368,7 +2356,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2385,15 +2373,15 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "plotters" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" dependencies = [ "num-traits 0.2.19", "plotters-backend", @@ -2404,19 +2392,25 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" [[package]] name = "plotters-svg" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" dependencies = [ "plotters-backend", ] +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -2434,9 +2428,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "pretty_assertions" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" dependencies = [ "diff", "yansi", @@ -2568,9 +2562,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -2588,9 +2582,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -2600,9 +2594,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -2611,9 +2605,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "relative-path" @@ -2683,7 +2677,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2719,9 +2713,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.35" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.6.0", "errno", @@ -2785,7 +2779,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2811,22 +2805,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2837,14 +2831,14 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "serde_json" -version = "1.0.127" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -2864,9 +2858,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -3010,7 +3004,7 @@ checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" dependencies = [ "starknet-curve", "starknet-ff", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3036,9 +3030,9 @@ dependencies = [ [[package]] name = "starknet-types-core" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6bacf0ba19bc721e518bc4bf389ff13daa8a7c5db5fd320600473b8aa9fcbd" +checksum = "9b889ee5734db8b3c8a6551135c16764bf4ce1ab4955fffbb2ac5b6706542b64" dependencies = [ "arbitrary", "lambdaworks-crypto", @@ -3088,9 +3082,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -3111,9 +3105,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -3135,22 +3129,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3226,14 +3220,14 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", @@ -3265,9 +3259,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap 2.5.0", "serde", @@ -3354,7 +3348,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3440,21 +3434,21 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-segmentation" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-xid" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "utf8parse" @@ -3538,7 +3532,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -3572,7 +3566,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3605,7 +3599,7 @@ checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3810,9 +3804,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] @@ -3843,9 +3837,9 @@ checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852" [[package]] name = "yansi" -version = "0.5.1" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" @@ -3865,7 +3859,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3885,7 +3879,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 64a4af3e09..37a87353b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,15 +62,15 @@ thiserror-no-std = { version = "2.0.2", default-features = false } bitvec = { version = "1", default-features = false, features = ["alloc"] } # Dependencies for cairo-1-hints feature -cairo-lang-starknet = { version = "2.8.0", default-features = false } -cairo-lang-casm = { version = "2.8.0", default-features = false } +cairo-lang-starknet = { version = "2.8.2", default-features = false } +cairo-lang-casm = { version = "2.8.2", default-features = false } -cairo-lang-starknet-classes = { version = "2.8.0", default-features = false } -cairo-lang-compiler = { version = "=2.8.0", default-features = false } -cairo-lang-sierra-to-casm = { version = "2.8.0", default-features = false } -cairo-lang-sierra = { version = "2.8.0", default-features = false } -cairo-lang-runner = { version = "2.8.0", default-features = false } -cairo-lang-utils = { version = "=2.8.0", default-features = false } +cairo-lang-starknet-classes = { version = "2.8.2", default-features = false } +cairo-lang-compiler = { version = "=2.8.2", default-features = false } +cairo-lang-sierra-to-casm = { version = "2.8.2", default-features = false } +cairo-lang-sierra = { version = "2.8.2", default-features = false } +cairo-lang-runner = { version = "2.8.2", default-features = false } +cairo-lang-utils = { version = "=2.8.2", default-features = false } # TODO: check these dependencies for wasm compatibility ark-ff = { version = "0.4.2", default-features = false } diff --git a/cairo_programs/cairo-1-programs/circuit_failure.cairo b/cairo_programs/cairo-1-programs/circuit_failure.cairo new file mode 100644 index 0000000000..66c59416f1 --- /dev/null +++ b/cairo_programs/cairo-1-programs/circuit_failure.cairo @@ -0,0 +1,24 @@ +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::> {}; + let in2 = CircuitElement::> {}; + let add1 = circuit_add(in1, in2); + let sub1 = circuit_sub(add1, add1); + let inv1 = circuit_inverse(sub1); + let modulus = TryInto::<_, CircuitModulus>::try_into([17, 14, 14, 14]).unwrap(); + + let outputs = (inv1,) + .new_inputs() + .next([9, 2, 9, 3]) + .next([5, 7, 0, 8]) + .done() + .eval(modulus) + .unwrap(); + + outputs.get_output(sub1) +} diff --git a/cairo_programs/cairo-1-programs/serialized_output/circuit.cairo b/cairo_programs/cairo-1-programs/serialized_output/circuit.cairo index a638680e95..85e9f7e9a6 100644 --- a/cairo_programs/cairo-1-programs/serialized_output/circuit.cairo +++ b/cairo_programs/cairo-1-programs/serialized_output/circuit.cairo @@ -28,16 +28,13 @@ fn main() -> Array { .unwrap(); let circuit_output = outputs.get_output(add2); - let mut limbs_output = ArrayTrait::new(); - - limbs_output.append(circuit_output.limb0); - limbs_output.append(circuit_output.limb1); - limbs_output.append(circuit_output.limb2); - limbs_output.append(circuit_output.limb3); let mut output: Array = ArrayTrait::new(); - limbs_output.serialize(ref output); + 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 } diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 15ed256366..ca73c49d8a 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -228,7 +228,6 @@ pub fn eval_circuit( n_mul_mods: usize, mul_mod_builtin_address: Relocatable, ) -> Result<(), HintError> { - println!("Memory: {}", &vm.segments); let modulus_ptr = mul_mod_builtin_address; // The offset of the values pointer inside the mul_mod_builtin let values_offset = 4; From fdd5341517f1ce8950f22be311183485e112ec00 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 30 Sep 2024 11:03:12 -0300 Subject: [PATCH 10/33] default mod_builtins feature --- cairo1-run/Cargo.toml | 2 +- .../cairo_1_hint_processor/circuit.rs | 33 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index 9d699de792..09adca0e88 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -32,6 +32,6 @@ num-traits = { version = "0.2", default-features = false } num-bigint.workspace = true [features] -default = ["with_mimalloc"] +default = ["with_mimalloc", "mod_builtin"] with_mimalloc = ["dep:mimalloc"] mod_builtin = ["cairo-vm/mod_builtin"] diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index ca73c49d8a..7145f2e159 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -4,8 +4,9 @@ use core::{ }; use ark_ff::{One, Zero}; -use num_bigint::BigUint; -use num_integer::Integer; +use num_bigint::{BigInt, BigUint, ToBigInt}; +use num_integer::{ExtendedGcd, Integer}; +use num_traits::Signed; use starknet_types_core::felt::Felt; use crate::{ @@ -105,14 +106,9 @@ impl CircuitInstance<'_> { } // inverse gate: lhs * rhs = 1 => lhs = 1 / rhs (None, Some(r)) => { - let res = match r.modinv(&self.modulus) { - Some(inv) => inv, - None => { - return false; - } - }; + let (success, res) = invert_or_nullify(r, &self.modulus); self.write_mul_mod_value(index, res); - true + success } _ => unreachable!("Unexpected None value while filling mul_mod gate"), } @@ -145,6 +141,25 @@ fn write_circuit_value(vm: &mut VirtualMachine, add: Relocatable, mut value: Big } } +fn invert_or_nullify(value: BigUint, modulus: &BigUint) -> (bool, BigUint) { + let ExtendedGcd::<_> { gcd, x, y: _ } = + value.to_bigint().unwrap().extended_gcd(&modulus.to_bigint().unwrap()); + + let gcd = gcd.to_biguint().unwrap(); + if gcd.is_one() { + return (true, positive_modulus(&x, modulus)); + } + let nullifier = modulus / gcd; + // Note that gcd divides the value, so value * nullifier = value * (modulus / gcd) = + // (value // gcd) * modulus = 0 (mod modulus) + (false, nullifier) +} + +fn positive_modulus(value: &BigInt, modulus: &BigUint) -> BigUint { + let value_magnitud = value.magnitude().mod_floor(modulus); + if value.is_negative() { modulus - value_magnitud } else { value_magnitud } +} + /// Fills the values for a circuit /// /// Returns the first mul gate index that failed to fill its values or From 8a349506998afab939d4449abe28dad8d95cc377 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 30 Sep 2024 13:00:41 -0300 Subject: [PATCH 11/33] format + update changelog --- CHANGELOG.md | 2 + Cargo.lock | 100 +++++++++--------- Cargo.toml | 16 +-- cairo1-run/Cargo.toml | 6 +- cairo1-run/src/cairo_run.rs | 2 +- cairo1-run/src/main.rs | 7 -- .../cairo_1_hint_processor/circuit.rs | 30 +++--- 7 files changed, 82 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03c22eb7fd..b74038c9d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* feat: add `EvalCircuit` and `TestLessThanOrEqualAddress` hints [#1843](https://github.com/lambdaclass/cairo-vm/pull/1843) + * chore: bump pip `cairo-lang` 0.13.2 [#1827](https://github.com/lambdaclass/cairo-vm/pull/1827) * chore: bump `cairo-lang-` dependencies to 2.8.0 [#1833](https://github.com/lambdaclass/cairo-vm/pull/1833/files) diff --git a/Cargo.lock b/Cargo.lock index 7c8e3df555..8e5af077a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -431,9 +431,9 @@ checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cairo-lang-casm" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a4b4ca8473c25d1e760c83c2a49d953197556f82f6feb636004d3b6d6cc4a7" +checksum = "ad9e8fe95ee2add1537d00467b98bb8928334633eb01dcba7f33fb64769af259" dependencies = [ "cairo-lang-utils", "indoc", @@ -445,9 +445,9 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5852668d1c6966b34d6e4fe249732769ab9cb2012c201e3889d8119f206760a0" +checksum = "0db1ae47b4918a894b60160fac42e6fbcb5a8c0023dd6c290ba03a1bcdf5a554" dependencies = [ "anyhow", "cairo-lang-defs", @@ -471,18 +471,18 @@ dependencies = [ [[package]] name = "cairo-lang-debug" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0644fab571f598547993936918c85f0e89b0bbc15140ca3ea723bff376be07d" +checksum = "b1c87b905b74516c33fc7e6d61b5243363ce65133054c30bd9531f47e30ca201" dependencies = [ "cairo-lang-utils", ] [[package]] name = "cairo-lang-defs" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f5f437d75ac25644880458effde562edcac45a888d27f2e497d30c6450fa97d" +checksum = "611996d85ec608bfec75d546a5c2ec44f664f4bd2514840a5b369d30a1a8bfdb" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -497,9 +497,9 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ec5b44d3eaf50e28e068d163e56b9effcea6afe3625c32dd96418d2d4ebc34c" +checksum = "d015a0790b1f5de8b22b4b4b60d392c35bed07b7aa9dd22361af2793835cee51" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -509,9 +509,9 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0cd844e568f51e39729e8ac18bd27ada2e2b6dc9138f8c81adad48456480681" +checksum = "54c580e56e5857d51b6bf2ec5ed5fdd33fd3b74dad7e3cb6d7398396174a6c85" dependencies = [ "cairo-lang-utils", "good_lp", @@ -519,9 +519,9 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "323a2385e000589f7591f8a46599b4a462db6e36e5935bad3bceddcc1a1608e1" +checksum = "5368e66a742b8532d656171525bfea599490280ceee10bdac93ad60775fc4e59" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -534,9 +534,9 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cf9cf637e12d41260dc59f3d988c76a6347424913ac8b6b8449ff3e79b59750" +checksum = "c1200324728e7f4c4acedceee427d9b3ffce221af57e469a454f007cbc248255" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -555,9 +555,9 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d71bc5b1f19a00eb662c2cac33259b16b9cdbf9c005047aca0d538c13936407" +checksum = "2a7a3069c75e1aca7cf15f20d03baf71f5c86e5be26988f6c25656549aa8b54a" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -579,9 +579,9 @@ dependencies = [ [[package]] name = "cairo-lang-parser" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d939d258e26ace0f3cb1e50338ae18981a7505e3c20eabd24a62d70ee862d6c" +checksum = "c13b245ddc740ebfed8b05e1bdb7805a06d267cf89d46486c9609306f92d45ce" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -599,9 +599,9 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67a553a6d2d2b54264e77e3c8cb5bc866b40b32d5e2144a58b74c559c7e289f" +checksum = "3b656552d0ab4a69be223e42c4e1c4028e512f506a237d04bbe4ccab9a1e13c5" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -618,9 +618,9 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c33b5f4502b7efde6ac07fd5468f6dae15d88760aeece3d57a7bc4c224ba693e" +checksum = "05cc6adb49faa42ea825e041dff0496c2e72e4ddaf50734062a62383c0c8adbf" dependencies = [ "cairo-lang-debug", "quote", @@ -629,9 +629,9 @@ dependencies = [ [[package]] name = "cairo-lang-project" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63d6a3cc86a79a29978acaaf6f94738c5487e265247fe06c7bf359645d8c200" +checksum = "ad123ba0e0dd5e1ea80977c0244ff4b0b6d8bf050d42ecb5ff0cf7f885e871f9" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -643,9 +643,9 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00c284031fd14796dad91483c3039d7929f8440e1e9e334017744b1d22df5aa8" +checksum = "0d528c79e4ff3e1364569c07e22660ddf60c0d1989705b8f0feed9949962b28a" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -669,9 +669,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891488c1a3184ce91679f5bdb63015a1d24769a48bd07e5d51a1779d0031dfbe" +checksum = "1bdb0c2cc419f45ab7e413322502ca02c2a2c56aeabdd0885e3740f378d8b269" dependencies = [ "anyhow", "cairo-lang-utils", @@ -696,9 +696,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea7752cd48c86b2cde8603b753a6df4da086dacd16a73d288854d5f040b51171" +checksum = "7224cd827ccf69e742c90a60278876865a96b545a101248d9472d2e02f9190b3" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -712,9 +712,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340892a09c9421414b2ac45b03c705f16e2bd737e4559dfd98ee1d20718dec9e" +checksum = "7e379e3010827fe983e66aa38a0d25fe24cfc11eaf8cadf4dc7bcb31fff031de" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -728,9 +728,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5cc616e8df44c4d685fe3c5f81f35ebbda57225098b35cea8602457c45c9e96" +checksum = "d6b353930676c06bb885a16ec3b120109aa15539c49f41b3370a5a6314dc29dc" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -752,9 +752,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c22ff7e8113a46a907f82f191096c96935cc48247e3079971ddf536ccc2f4f8" +checksum = "83873751d489aae4674f3d755a4897429a664bdc4b0847283e13889f0b0c2a44" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -773,9 +773,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf41941776e7410a8853a8e2a116292fc24d219df1989a92ffe5ab0e98037eb" +checksum = "5bd84b445715326e44832836732b6bda76a119116b296ac9b6b87e2a4177634a" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -783,9 +783,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5508fa5ee8d24adf7d2c65505d0ac35efc892eac16d1449c6f7e314a0288cb8" +checksum = "d8df3086f909d27a49d6706be835725df4e21fb50efe699cd763d1f782a31dea" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -813,9 +813,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "482b8f9d7f8cc7140f1260ee71f3308a66d15bd228a06281067ca3f8f4410db2" +checksum = "41bcab650779b3431389dc52f1e643a7c9690a1aa2b072c8f01955503d094007" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -836,9 +836,9 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7db0776c3d06cea65d7afe7a3c7685f6867eb6d951cf505caf35abfd1746773b" +checksum = "7e2dc876ec02a197b8d13dbfc0b2cf7a7e31dcfc6446761cbb85f5b42d589cdc" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -862,9 +862,9 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630a070a69c387eee9c0eda65e4f2508d129d4fbe081091077e661020ab95637" +checksum = "7a7681562268173d74b1c8d2438a1d9ec3218c89a8e39a8be3f10e044fa46ebe" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -875,9 +875,9 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "2.8.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73104609a7d865e4cd1de9cbf4e750683d076b6d0233bf81be511df274a26916" +checksum = "37e6004780c42bf28ce5afd048cc628b3de34aaf24fd2c228ae73217c58999f9" dependencies = [ "hashbrown 0.14.5", "indexmap 2.5.0", diff --git a/Cargo.toml b/Cargo.toml index 37a87353b2..64a4af3e09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,15 +62,15 @@ thiserror-no-std = { version = "2.0.2", default-features = false } bitvec = { version = "1", default-features = false, features = ["alloc"] } # Dependencies for cairo-1-hints feature -cairo-lang-starknet = { version = "2.8.2", default-features = false } -cairo-lang-casm = { version = "2.8.2", default-features = false } +cairo-lang-starknet = { version = "2.8.0", default-features = false } +cairo-lang-casm = { version = "2.8.0", default-features = false } -cairo-lang-starknet-classes = { version = "2.8.2", default-features = false } -cairo-lang-compiler = { version = "=2.8.2", default-features = false } -cairo-lang-sierra-to-casm = { version = "2.8.2", default-features = false } -cairo-lang-sierra = { version = "2.8.2", default-features = false } -cairo-lang-runner = { version = "2.8.2", default-features = false } -cairo-lang-utils = { version = "=2.8.2", default-features = false } +cairo-lang-starknet-classes = { version = "2.8.0", default-features = false } +cairo-lang-compiler = { version = "=2.8.0", default-features = false } +cairo-lang-sierra-to-casm = { version = "2.8.0", default-features = false } +cairo-lang-sierra = { version = "2.8.0", default-features = false } +cairo-lang-runner = { version = "2.8.0", default-features = false } +cairo-lang-utils = { version = "=2.8.0", default-features = false } # TODO: check these dependencies for wasm compatibility ark-ff = { version = "0.4.2", default-features = false } diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index 09adca0e88..6f4f432bfc 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -12,9 +12,9 @@ keywords.workspace = true cairo-vm = { workspace = true, features = ["std", "cairo-1-hints", "clap"] } serde_json = { workspace = true } -cairo-lang-sierra-type-size = { version = "2.8.2", default-features = false } -cairo-lang-sierra-ap-change = { version = "2.8.2", default-features = false } -cairo-lang-sierra-gas = { version = "2.8.2", default-features = false } +cairo-lang-sierra-type-size = { version = "2.8.0", default-features = false } +cairo-lang-sierra-ap-change = { version = "2.8.0", default-features = false } +cairo-lang-sierra-gas = { version = "2.8.0", default-features = false } cairo-lang-starknet-classes.workspace = true cairo-lang-sierra-to-casm.workspace = true cairo-lang-compiler.workspace = true diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index a3e9e7140d..edcbcd5a21 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -196,7 +196,7 @@ pub fn cairo_run_program( ); let (processor_hints, program_hints) = build_hints_vec(instructions.clone()); - // These the instructions' bytecode + the segment's value up to this point appended after the footer + // These the instructions' bytecode + the segment's values up to this point, appended after the footer let bytecode = casm_program .assemble_ex(&entry_code.instructions, &libfunc_footer) .bytecode; diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index 980f19d786..85bc34942d 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -431,13 +431,6 @@ mod tests { None, None )] - // #[case( - // "circuit_failure.cairo", - // "", - // "", - // None, - // None - // )] fn test_run_program( #[case] program: &str, #[case] expected_output: &str, diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 7145f2e159..96df706466 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -142,22 +142,28 @@ fn write_circuit_value(vm: &mut VirtualMachine, add: Relocatable, mut value: Big } fn invert_or_nullify(value: BigUint, modulus: &BigUint) -> (bool, BigUint) { - let ExtendedGcd::<_> { gcd, x, y: _ } = - value.to_bigint().unwrap().extended_gcd(&modulus.to_bigint().unwrap()); - - let gcd = gcd.to_biguint().unwrap(); - if gcd.is_one() { - return (true, positive_modulus(&x, modulus)); - } - let nullifier = modulus / gcd; - // Note that gcd divides the value, so value * nullifier = value * (modulus / gcd) = - // (value // gcd) * modulus = 0 (mod modulus) - (false, nullifier) + let ExtendedGcd::<_> { gcd, x, y: _ } = value + .to_bigint() + .unwrap() + .extended_gcd(&modulus.to_bigint().unwrap()); + + let gcd = gcd.to_biguint().unwrap(); + if gcd.is_one() { + return (true, positive_modulus(&x, modulus)); + } + let nullifier = modulus / gcd; + // Note that gcd divides the value, so value * nullifier = value * (modulus / gcd) = + // (value // gcd) * modulus = 0 (mod modulus) + (false, nullifier) } fn positive_modulus(value: &BigInt, modulus: &BigUint) -> BigUint { let value_magnitud = value.magnitude().mod_floor(modulus); - if value.is_negative() { modulus - value_magnitud } else { value_magnitud } + if value.is_negative() { + modulus - value_magnitud + } else { + value_magnitud + } } /// Fills the values for a circuit From b2eca485b2a65654a8db5e7efb9c5809b6b97cfb Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 30 Sep 2024 15:47:33 -0300 Subject: [PATCH 12/33] ignore circuit case if mod_builtin feature is not active --- cairo1-run/Cargo.toml | 2 +- cairo1-run/src/main.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index 6f4f432bfc..5390732e17 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -32,6 +32,6 @@ num-traits = { version = "0.2", default-features = false } num-bigint.workspace = true [features] -default = ["with_mimalloc", "mod_builtin"] +default = ["with_mimalloc"] with_mimalloc = ["dep:mimalloc"] mod_builtin = ["cairo-vm/mod_builtin"] diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index ead87bcb64..6ec7d6d32f 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -436,13 +436,13 @@ mod tests { Some("[17 18]"), Some("[17 18]") )] - #[case( + #[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, From ef1a132b32c6d0054d547729f40dd287b091fcac Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 30 Sep 2024 17:02:49 -0300 Subject: [PATCH 13/33] add mod_builtin feature to make run --- cairo1-run/Makefile | 4 ++-- cairo1-run/src/cairo_run.rs | 3 ++- cairo1-run/src/main.rs | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cairo1-run/Makefile b/cairo1-run/Makefile index a00f9dfe3f..0ea9c78f3d 100644 --- a/cairo1-run/Makefile +++ b/cairo1-run/Makefile @@ -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)) diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index 9ba9de6925..188f953c80 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -198,7 +198,8 @@ pub fn cairo_run_program( ); let (processor_hints, program_hints) = build_hints_vec(instructions.clone()); - // These the instructions' bytecode + the segment's values up to this point, appended after the footer + + // These are the instructions' bytecode + the segment's values up to this point let bytecode = casm_program .assemble_ex(&entry_code.instructions, &libfunc_footer) .bytecode; diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index 6ec7d6d32f..b380471585 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -443,6 +443,14 @@ mod tests { None, None ))] + #[should_panic] + #[cfg_attr(feature = "mod_builtin", case( + "circuit_failure.cairo", + "", + "", + None, + None + ))] fn test_run_program( #[case] program: &str, #[case] expected_output: &str, From 449e167c851b80cef2109ffa2f5286d106e7fcf1 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 30 Sep 2024 17:10:54 -0300 Subject: [PATCH 14/33] format --- cairo1-run/src/main.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index b380471585..722cb84511 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -444,13 +444,10 @@ mod tests { None ))] #[should_panic] - #[cfg_attr(feature = "mod_builtin", case( - "circuit_failure.cairo", - "", - "", - None, - None - ))] + #[cfg_attr( + feature = "mod_builtin", + case("circuit_failure.cairo", "", "", None, None) + )] fn test_run_program( #[case] program: &str, #[case] expected_output: &str, From cbbe4a4ce84560a32fbdf82d57b8139fe74cf77b Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 30 Sep 2024 17:46:04 -0300 Subject: [PATCH 15/33] fix tests --- cairo1-run/src/main.rs | 5 ---- .../cairo-1-programs/circuit_failure.cairo | 24 ------------------- 2 files changed, 29 deletions(-) delete mode 100644 cairo_programs/cairo-1-programs/circuit_failure.cairo diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index 722cb84511..6ec7d6d32f 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -443,11 +443,6 @@ mod tests { None, None ))] - #[should_panic] - #[cfg_attr( - feature = "mod_builtin", - case("circuit_failure.cairo", "", "", None, None) - )] fn test_run_program( #[case] program: &str, #[case] expected_output: &str, diff --git a/cairo_programs/cairo-1-programs/circuit_failure.cairo b/cairo_programs/cairo-1-programs/circuit_failure.cairo deleted file mode 100644 index 66c59416f1..0000000000 --- a/cairo_programs/cairo-1-programs/circuit_failure.cairo +++ /dev/null @@ -1,24 +0,0 @@ -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::> {}; - let in2 = CircuitElement::> {}; - let add1 = circuit_add(in1, in2); - let sub1 = circuit_sub(add1, add1); - let inv1 = circuit_inverse(sub1); - let modulus = TryInto::<_, CircuitModulus>::try_into([17, 14, 14, 14]).unwrap(); - - let outputs = (inv1,) - .new_inputs() - .next([9, 2, 9, 3]) - .next([5, 7, 0, 8]) - .done() - .eval(modulus) - .unwrap(); - - outputs.get_output(sub1) -} From e955a7474596259bf3f11549f3d5eb67fb5cb4ad Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 16 Oct 2024 10:12:54 -0300 Subject: [PATCH 16/33] rewrite a little --- .../cairo_1_hint_processor/circuit.rs | 126 ++++++++---------- 1 file changed, 53 insertions(+), 73 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 96df706466..52309a3ba9 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -21,7 +21,7 @@ const LIMBS_COUNT: usize = 4; // Representes the size of a MulMod and AddMod instance const MOD_BUILTIN_INSTACE_SIZE: usize = 7; -struct CircuitInstance<'a> { +struct Circuit<'a> { vm: &'a mut VirtualMachine, values_ptr: Relocatable, add_mod_offsets: Relocatable, @@ -29,7 +29,7 @@ struct CircuitInstance<'a> { modulus: BigUint, } -impl CircuitInstance<'_> { +impl Circuit<'_> { fn read_add_mod_value(&mut self, offset: usize) -> Option { self.read_circuit_value((self.add_mod_offsets + offset).unwrap()) } @@ -59,60 +59,6 @@ impl CircuitInstance<'_> { fn get_value_ptr(&self, address: Relocatable) -> Relocatable { (self.values_ptr + self.vm.get_integer(address).unwrap().as_ref()).unwrap() } - - /// Fills an `add_mod` gate - /// - /// Returns `true` if all the inputs of the gate are filled up and so the operation can be performed, - /// `false` otherwise. - fn fill_add_gate(&mut self, index: usize) -> bool { - let lhs = self.read_add_mod_value(index); - let rhs = self.read_add_mod_value(index + 1); - - match (lhs, rhs) { - (Some(l), Some(r)) => { - let res = (l + r) % &self.modulus; - self.write_add_mod_value(index + 2, res); - true - } - // sub gate: lhs + rhs = res => lhs = res - rhs - (None, Some(r)) => { - let Some(res) = self.read_add_mod_value(index + 2) else { - return false; - }; - let value = (res + &self.modulus - r) % &self.modulus; - self.write_add_mod_value(index, value); - true - } - _ => false, - } - } - - /// Fills the a `mul_mod` gate - /// - /// Returns `true` if all the inputs of the gates are filled up and so the operation can be performed, - /// false if it is an inverse opeartion with a non invertible input. - /// - /// This operation implies that all the gate's inputs are filled up, - /// and will panic if that is not the case. - fn fill_mul_gate(&mut self, index: usize) -> bool { - let lhs = self.read_mul_mod_value(index); - let rhs = self.read_mul_mod_value(index + 1); - - match (lhs, rhs) { - (Some(l), Some(r)) => { - let res = (l * r) % &self.modulus; - self.write_mul_mod_value(index + 2, res); - true - } - // inverse gate: lhs * rhs = 1 => lhs = 1 / rhs - (None, Some(r)) => { - let (success, res) = invert_or_nullify(r, &self.modulus); - self.write_mul_mod_value(index, res); - success - } - _ => unreachable!("Unexpected None value while filling mul_mod gate"), - } - } } /// Reads a circuit value from memory @@ -141,7 +87,7 @@ fn write_circuit_value(vm: &mut VirtualMachine, add: Relocatable, mut value: Big } } -fn invert_or_nullify(value: BigUint, modulus: &BigUint) -> (bool, BigUint) { +fn find_inverse(value: BigUint, modulus: &BigUint) -> (bool, BigUint) { let ExtendedGcd::<_> { gcd, x, y: _ } = value .to_bigint() .unwrap() @@ -149,15 +95,17 @@ fn invert_or_nullify(value: BigUint, modulus: &BigUint) -> (bool, BigUint) { let gcd = gcd.to_biguint().unwrap(); if gcd.is_one() { - return (true, positive_modulus(&x, modulus)); + return (true, get_modulus(&x, modulus)); } + + // if the value has no inverse, find a nullifier so that: + // value * nullifier = 0 (mod modulus) let nullifier = modulus / gcd; - // Note that gcd divides the value, so value * nullifier = value * (modulus / gcd) = - // (value // gcd) * modulus = 0 (mod modulus) + (false, nullifier) } -fn positive_modulus(value: &BigInt, modulus: &BigUint) -> BigUint { +fn get_modulus(value: &BigInt, modulus: &BigUint) -> BigUint { let value_magnitud = value.magnitude().mod_floor(modulus); if value.is_negative() { modulus - value_magnitud @@ -166,11 +114,7 @@ fn positive_modulus(value: &BigInt, modulus: &BigUint) -> BigUint { } } -/// Fills the values for a circuit -/// -/// Returns the first mul gate index that failed to fill its values or -/// `n_mul_mods` if all gates were filled successfully -fn fill_values( +fn compute_gates( vm: &mut VirtualMachine, values_ptr: Relocatable, add_mod_offsets: Relocatable, @@ -180,7 +124,7 @@ fn fill_values( modulus_ptr: Relocatable, ) -> usize { let modulus = read_circuit_value(vm, modulus_ptr).unwrap(); - let mut circuit = CircuitInstance { + let mut circuit = Circuit { vm, values_ptr, add_mod_offsets, @@ -191,14 +135,30 @@ fn fill_values( let mut addmod_idx = 0; let mut mulmod_idx = 0; - // A circuit evaluation can only fail through a mulmod operation + // Only mul gates can make the evaluation fail let mut first_failure_idx = n_mul_mods; loop { while addmod_idx < n_add_mods { - if !circuit.fill_add_gate(3 * addmod_idx) { - break; + let lhs = circuit.read_add_mod_value(3 * addmod_idx); + let rhs = circuit.read_add_mod_value(3 * addmod_idx + 1); + + match (lhs, rhs) { + (Some(l), Some(r)) => { + let res = (l + r) % &circuit.modulus; + circuit.write_add_mod_value(3 * addmod_idx + 2, res); + } + // sub gate: lhs = res - rhs + (None, Some(r)) => { + let Some(res) = circuit.read_add_mod_value(3 * addmod_idx + 2) else { + break; + }; + let value = (res + &circuit.modulus - r) % &circuit.modulus; + circuit.write_add_mod_value(3 * addmod_idx, value); + } + _ => break, } + addmod_idx += 1; } @@ -206,9 +166,29 @@ fn fill_values( break; } - if !circuit.fill_mul_gate(3 * mulmod_idx) && first_failure_idx == n_mul_mods { - first_failure_idx = mulmod_idx; + let lhs = circuit.read_mul_mod_value(3 * mulmod_idx); + let rhs = circuit.read_mul_mod_value(3 * mulmod_idx + 1); + + match (lhs, rhs) { + (Some(l), Some(r)) => { + let res = (l * r) % &circuit.modulus; + circuit.write_mul_mod_value(3 * mulmod_idx + 2, res); + } + // inverse gate: lhs = 1 / rhs + (None, Some(r)) => { + let (success, res) = find_inverse(r, &circuit.modulus); + circuit.write_mul_mod_value(3 * mulmod_idx, res); + + if !success { + first_failure_idx = mulmod_idx; + break; + } + } + _ => { + unreachable!("Unexpected None value while filling mul_mod gate") + }, } + mulmod_idx += 1; } @@ -263,7 +243,7 @@ pub fn eval_circuit( vm.get_relocatable((add_mod_builtin_address + offsets_offset)?)? }; - let n_computed_gates = fill_values( + let n_computed_gates = compute_gates( vm, values_ptr, add_mod_offsets, From b5479ab30af0787885630ecd3ac3701cc29f1e9e Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 16 Oct 2024 10:31:03 -0300 Subject: [PATCH 17/33] format --- vm/src/hint_processor/cairo_1_hint_processor/circuit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 52309a3ba9..8559745031 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -186,7 +186,7 @@ fn compute_gates( } _ => { unreachable!("Unexpected None value while filling mul_mod gate") - }, + } } mulmod_idx += 1; From a293bb5081f1c5e6a53d717f7c702042a981eebc Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 16 Oct 2024 15:43:47 -0300 Subject: [PATCH 18/33] stylling --- .../cairo_1_hint_processor/circuit.rs | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 8559745031..34d1ea94e5 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -1,6 +1,6 @@ use core::{ array, - ops::{Deref, Shl}, + ops::Deref, }; use ark_ff::{One, Zero}; @@ -61,7 +61,6 @@ impl Circuit<'_> { } } -/// Reads a circuit value from memory fn read_circuit_value(vm: &mut VirtualMachine, add: Relocatable) -> Option { let mut res = BigUint::zero(); @@ -76,30 +75,31 @@ fn read_circuit_value(vm: &mut VirtualMachine, add: Relocatable) -> Option (bool, BigUint) { - let ExtendedGcd::<_> { gcd, x, y: _ } = value + let ex_gcd = value .to_bigint() .unwrap() .extended_gcd(&modulus.to_bigint().unwrap()); - let gcd = gcd.to_biguint().unwrap(); + let gcd = ex_gcd.gcd.to_biguint().unwrap(); if gcd.is_one() { - return (true, get_modulus(&x, modulus)); + return (true, get_modulus(&ex_gcd.x, modulus)); } - // if the value has no inverse, find a nullifier so that: - // value * nullifier = 0 (mod modulus) let nullifier = modulus / gcd; (false, nullifier) @@ -218,10 +218,10 @@ fn fill_instances( Ok(()) } -/// Evaluates a circuit and fills the builtin instances and the values buffer. +/// Computes the circuit. /// -/// Returns the first mul gate index that failed to fill its values -/// or `n_mul_mods` if all gates were filled successfully. +/// If theres a failure, it returs the index of the gate in which the failure occurred, else +/// returns the total amount of mul gates. pub fn eval_circuit( vm: &mut VirtualMachine, n_add_mods: usize, @@ -230,17 +230,15 @@ pub fn eval_circuit( mul_mod_builtin_address: Relocatable, ) -> Result<(), HintError> { let modulus_ptr = mul_mod_builtin_address; - // The offset of the values pointer inside the mul_mod_builtin - let values_offset = 4; - // The offset of the offsets pointer inside the mul_mod_builtin - let offsets_offset = 5; + let mul_mod_values_offset = 4; + let mul_mod_offset = 5; - let values_ptr = vm.get_relocatable((mul_mod_builtin_address + values_offset)?)?; - let mul_mod_offsets = vm.get_relocatable((mul_mod_builtin_address + offsets_offset)?)?; + let values_ptr = vm.get_relocatable((mul_mod_builtin_address + mul_mod_values_offset)?)?; + let mul_mod_offsets = vm.get_relocatable((mul_mod_builtin_address + mul_mod_offset)?)?; let add_mod_offsets = if n_add_mods == 0 { mul_mod_offsets } else { - vm.get_relocatable((add_mod_builtin_address + offsets_offset)?)? + vm.get_relocatable((add_mod_builtin_address + mul_mod_offset)?)? }; let n_computed_gates = compute_gates( From aa4068f3a605b770bd06529dd83e0d1bbf5b6d97 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 16 Oct 2024 15:47:31 -0300 Subject: [PATCH 19/33] stylling --- vm/src/hint_processor/cairo_1_hint_processor/circuit.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 34d1ea94e5..f0fd6617f9 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -1,11 +1,8 @@ -use core::{ - array, - ops::Deref, -}; +use core::{array, ops::Deref}; use ark_ff::{One, Zero}; use num_bigint::{BigInt, BigUint, ToBigInt}; -use num_integer::{ExtendedGcd, Integer}; +use num_integer::Integer; use num_traits::Signed; use starknet_types_core::felt::Felt; From a3abf1f8545d2c8f2cf2659d9bdc58e60cec646a Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 16 Oct 2024 17:18:19 -0300 Subject: [PATCH 20/33] reference --- vm/src/hint_processor/cairo_1_hint_processor/circuit.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index f0fd6617f9..c107ab645e 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -1,3 +1,6 @@ +// Most of the `EvalCircuit` implementation is derived from the `cairo-lang-runner` crate. +// https://github.com/starkware-libs/cairo/blob/main/crates/cairo-lang-runner/src/casm_run/circuit.rs + use core::{array, ops::Deref}; use ark_ff::{One, Zero}; From fb5cd175cf0ad6872eeaa5c1c6e6ff1038fc30e9 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 14 Nov 2024 09:28:42 -0300 Subject: [PATCH 21/33] cargo lock --- Cargo.lock | 466 ++++++++++++++++++++------------------- cairo1-run/program.cairo | 9 + 2 files changed, 249 insertions(+), 226 deletions(-) create mode 100644 cairo1-run/program.cairo diff --git a/Cargo.lock b/Cargo.lock index 8e5af077a9..5ce3b28079 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] @@ -55,9 +55,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.18" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" [[package]] name = "anes" @@ -67,9 +67,9 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -82,49 +82,49 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "arbitrary" -version = "1.3.2" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223" dependencies = [ "derive_arbitrary", ] @@ -143,7 +143,7 @@ dependencies = [ "digest", "itertools 0.10.5", "num-bigint", - "num-traits 0.2.19", + "num-traits", "paste", "rustc_version", "zeroize", @@ -166,7 +166,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" dependencies = [ "num-bigint", - "num-traits 0.2.19", + "num-traits", "proc-macro2", "quote", "syn 1.0.109", @@ -189,7 +189,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" dependencies = [ - "num-traits 0.2.19", + "num-traits", "rand", ] @@ -216,9 +216,9 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "async-compression" -version = "0.4.12" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fec134f64e2bc57411226dfc4e52dec859ddfc7e711fc5e07b612584f000e4aa" +checksum = "0cb8f1d480b0ea3783ab015936d2a55c87e219676f0c0b7dec61494043f21857" dependencies = [ "brotli", "flate2", @@ -238,7 +238,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -376,9 +376,9 @@ dependencies = [ [[package]] name = "brotli" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" +checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -397,9 +397,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" +checksum = "1a68f1f47cdf0ec8ee4b941b2eee2a80cb796db73118c0dd09ac63fbe405be22" dependencies = [ "memchr", "serde", @@ -425,9 +425,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cairo-lang-casm" @@ -438,7 +438,7 @@ dependencies = [ "cairo-lang-utils", "indoc", "num-bigint", - "num-traits 0.2.19", + "num-traits", "parity-scale-codec", "serde", ] @@ -572,7 +572,7 @@ dependencies = [ "itertools 0.12.1", "log", "num-bigint", - "num-traits 0.2.19", + "num-traits", "rust-analyzer-salsa", "smol_str", ] @@ -591,7 +591,7 @@ dependencies = [ "colored", "itertools 0.12.1", "num-bigint", - "num-traits 0.2.19", + "num-traits", "rust-analyzer-salsa", "smol_str", "unescaper", @@ -624,7 +624,7 @@ checksum = "05cc6adb49faa42ea825e041dff0496c2e72e4ddaf50734062a62383c0c8adbf" dependencies = [ "cairo-lang-debug", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -661,7 +661,7 @@ dependencies = [ "indoc", "itertools 0.12.1", "num-bigint", - "num-traits 0.2.19", + "num-traits", "rust-analyzer-salsa", "smol_str", "toml", @@ -683,7 +683,7 @@ dependencies = [ "lalrpop-util", "num-bigint", "num-integer", - "num-traits 0.2.19", + "num-traits", "regex", "rust-analyzer-salsa", "serde", @@ -706,7 +706,7 @@ dependencies = [ "cairo-lang-utils", "itertools 0.12.1", "num-bigint", - "num-traits 0.2.19", + "num-traits", "thiserror", ] @@ -722,7 +722,7 @@ dependencies = [ "cairo-lang-utils", "itertools 0.12.1", "num-bigint", - "num-traits 0.2.19", + "num-traits", "thiserror", ] @@ -743,7 +743,7 @@ dependencies = [ "cairo-lang-syntax", "cairo-lang-utils", "itertools 0.12.1", - "num-traits 0.2.19", + "num-traits", "rust-analyzer-salsa", "serde", "serde_json", @@ -766,7 +766,7 @@ dependencies = [ "indoc", "itertools 0.12.1", "num-bigint", - "num-traits 0.2.19", + "num-traits", "starknet-types-core", "thiserror", ] @@ -825,7 +825,7 @@ dependencies = [ "itertools 0.12.1", "num-bigint", "num-integer", - "num-traits 0.2.19", + "num-traits", "serde", "serde_json", "sha3", @@ -844,7 +844,7 @@ dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", "num-bigint", - "num-traits 0.2.19", + "num-traits", "rust-analyzer-salsa", "smol_str", "unescaper", @@ -852,9 +852,9 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" -version = "2.8.2" +version = "2.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce0f7fa01c26cc731bc1d6350ac02fae91a68b5fdf60e684f991e861715adc4" +checksum = "31cef5b4347626e61bad8f070495cd35d637a5cb6744c34d20dd382c7431aff8" dependencies = [ "genco", "xshell", @@ -880,10 +880,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e6004780c42bf28ce5afd048cc628b3de34aaf24fd2c228ae73217c58999f9" dependencies = [ "hashbrown 0.14.5", - "indexmap 2.5.0", + "indexmap 2.6.0", "itertools 0.12.1", "num-bigint", - "num-traits 0.2.19", + "num-traits", "schemars", "serde", ] @@ -915,7 +915,7 @@ dependencies = [ "num-bigint", "num-integer", "num-prime", - "num-traits 0.2.19", + "num-traits", "proptest", "rand", "rstest", @@ -956,7 +956,7 @@ dependencies = [ "include_dir", "mime_guess", "num-bigint", - "num-traits 0.2.19", + "num-traits", "serde", "thiserror-no-std", "tokio", @@ -986,7 +986,7 @@ dependencies = [ "itertools 0.11.0", "mimalloc", "num-bigint", - "num-traits 0.2.19", + "num-traits", "rstest", "serde_json", "thiserror", @@ -1000,9 +1000,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.23" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbb537bb4a30b90362caddba8f360c0a56bc13d3a5570028e7197204cb54a17" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ "jobserver", "libc", @@ -1044,9 +1044,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.18" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", "clap_derive", @@ -1054,9 +1054,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.18" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstream", "anstyle", @@ -1073,20 +1073,20 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "colored" @@ -1145,9 +1145,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" dependencies = [ "libc", ] @@ -1174,7 +1174,7 @@ dependencies = [ "criterion-plot", "is-terminal", "itertools 0.10.5", - "num-traits 0.2.19", + "num-traits", "once_cell", "oorandom", "plotters", @@ -1262,13 +1262,13 @@ dependencies = [ [[package]] name = "derive_arbitrary" -version = "1.3.2" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +checksum = "30542c1ad912e0e3d22a1935c290e12e8a29d704a420177a31faad4a601a0800" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -1357,9 +1357,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "fixedbitset" @@ -1383,6 +1383,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1400,9 +1406,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -1415,9 +1421,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -1425,15 +1431,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -1442,32 +1448,32 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -1477,9 +1483,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -1495,9 +1501,9 @@ dependencies = [ [[package]] name = "genco" -version = "0.17.9" +version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afac3cbb14db69ac9fef9cdb60d8a87e39a7a527f85a81a923436efa40ad42c6" +checksum = "a35958104272e516c2a5f66a9d82fba4784d2b585fc1e2358b8f96e15d342995" dependencies = [ "genco-macros", "relative-path", @@ -1506,13 +1512,13 @@ dependencies = [ [[package]] name = "genco-macros" -version = "0.17.9" +version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "553630feadf7b76442b0849fd25fdf89b860d933623aec9693fed19af0400c78" +checksum = "43eaff6bbc0b3a878361aced5ec6a2818ee7c541c5b33b5880dfa9a86c23e9e7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -1540,9 +1546,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "globset" @@ -1559,12 +1565,12 @@ dependencies = [ [[package]] name = "good_lp" -version = "1.8.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3198bd13dea84c76a64621d6ee8ee26a4960a9a0d538eca95ca8f1320a469ac9" +checksum = "97630e1e456d7081c524488a87d8f8f7ed0fd3100ba10c55e3cfa7add5ce05c6" dependencies = [ "fnv", - "minilp", + "microlp", ] [[package]] @@ -1594,6 +1600,17 @@ dependencies = [ "serde", ] +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "heck" version = "0.4.1" @@ -1672,9 +1689,9 @@ checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" [[package]] name = "httparse" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "httpdate" @@ -1684,9 +1701,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.30" +version = "0.14.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" +checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" dependencies = [ "bytes", "futures-channel", @@ -1791,12 +1808,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.1", "serde", ] @@ -1808,9 +1825,9 @@ checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "iri-string" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bd7eced44cfe2cebc674adb2a7124a754a4b5269288d22e9f39f8fada3562d" +checksum = "dc0f0a572e8ffe56e2ff4f769f32ffe919282c3916799f8b68688b6030063bea" dependencies = [ "memchr", "serde", @@ -1926,9 +1943,9 @@ dependencies = [ [[package]] name = "lambdaworks-crypto" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb5d4f22241504f7c7b8d2c3a7d7835d7c07117f10bff2a7d96a9ef6ef217c3" +checksum = "bbc2a4da0d9e52ccfe6306801a112e81a8fc0c76aa3e4449fefeda7fef72bb34" dependencies = [ "lambdaworks-math", "serde", @@ -1938,9 +1955,9 @@ dependencies = [ [[package]] name = "lambdaworks-math" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358e172628e713b80a530a59654154bfc45783a6ed70ea284839800cebdf8f97" +checksum = "d1bd2632acbd9957afc5aeec07ad39f078ae38656654043bf16e046fa2730e23" dependencies = [ "serde", "serde_json", @@ -1957,15 +1974,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.159" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "libmimalloc-sys" @@ -2011,11 +2028,11 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lru" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.1", ] [[package]] @@ -2026,10 +2043,11 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "matrixmultiply" -version = "0.2.4" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "916806ba0031cd542105d916a97c8572e1fa6dd79c9c51e7eb43a09ec2dd84c1" +checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a" dependencies = [ + "autocfg", "rawpointer", ] @@ -2039,6 +2057,16 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "microlp" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4190b5ca62abfbc95a81d57f4a8e3e3872289d656f3eeea5820b3046a1f81d4b" +dependencies = [ + "log", + "sprs", +] + [[package]] name = "mimalloc" version = "0.1.43" @@ -2064,16 +2092,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "minilp" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a7750a9e5076c660b7bec5e6457b4dbff402b9863c8d112891434e18fd5385" -dependencies = [ - "log", - "sprs", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2103,14 +2121,16 @@ dependencies = [ [[package]] name = "ndarray" -version = "0.13.1" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac06db03ec2f46ee0ecdca1a1c34a99c0d188a0d83439b84bf0cb4b386e4ab09" +checksum = "882ed72dce9365842bf196bdeedf5055305f11fc8c03dee7bb0194a6cad34841" dependencies = [ "matrixmultiply", "num-complex", "num-integer", - "num-traits 0.2.19", + "num-traits", + "portable-atomic", + "portable-atomic-util", "rawpointer", ] @@ -2147,19 +2167,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", - "num-traits 0.2.19", + "num-traits", "rand", "serde", ] [[package]] name = "num-complex" -version = "0.2.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ - "autocfg", - "num-traits 0.2.19", + "num-traits", ] [[package]] @@ -2168,7 +2187,7 @@ version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "num-traits 0.2.19", + "num-traits", ] [[package]] @@ -2179,7 +2198,7 @@ checksum = "64a5fe11d4135c3bcdf3a95b18b194afa9608a5f6ff034f5d857bc9a27fb0119" dependencies = [ "num-bigint", "num-integer", - "num-traits 0.2.19", + "num-traits", ] [[package]] @@ -2194,19 +2213,10 @@ dependencies = [ "num-bigint", "num-integer", "num-modular", - "num-traits 0.2.19", + "num-traits", "rand", ] -[[package]] -name = "num-traits" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" -dependencies = [ - "num-traits 0.2.19", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -2219,21 +2229,18 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.20.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oorandom" @@ -2321,7 +2328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.5.0", + "indexmap 2.6.0", ] [[package]] @@ -2341,29 +2348,29 @@ checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" [[package]] name = "pin-project" -version = "1.1.5" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.5" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" @@ -2383,7 +2390,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" dependencies = [ - "num-traits 0.2.19", + "num-traits", "plotters-backend", "plotters-svg", "wasm-bindgen", @@ -2411,6 +2418,15 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" +[[package]] +name = "portable-atomic-util" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90a7d5beecc52a491b54d6dd05c7a45ba1801666a5baad9fdbfc6fef8d2d206c" +dependencies = [ + "portable-atomic", +] + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -2447,9 +2463,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -2464,7 +2480,7 @@ dependencies = [ "bit-vec", "bitflags 2.6.0", "lazy_static", - "num-traits 0.2.19", + "num-traits", "rand", "rand_chacha", "rand_xorshift", @@ -2582,9 +2598,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -2594,9 +2610,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -2657,7 +2673,7 @@ version = "0.17.0-pre.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719825638c59fd26a55412a24561c7c5bcf54364c88b9a7a04ba08a6eafaba8d" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "lock_api", "oorandom", "parking_lot", @@ -2677,7 +2693,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2687,7 +2703,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" dependencies = [ "arrayvec", - "num-traits 0.2.19", + "num-traits", ] [[package]] @@ -2713,9 +2729,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" dependencies = [ "bitflags 2.6.0", "errno", @@ -2726,9 +2742,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" [[package]] name = "rusty-fork" @@ -2779,7 +2795,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2805,22 +2821,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2831,14 +2847,14 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -2961,13 +2977,14 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "sprs" -version = "0.7.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec63571489873d4506683915840eeb1bb16b3198ee4894cc6f2fe3013d505e56" +checksum = "704ef26d974e8a452313ed629828cd9d4e4fa34667ca1ad9d6b1fffa43c6e166" dependencies = [ "ndarray", "num-complex", - "num-traits 0.1.43", + "num-traits", + "smallvec", ] [[package]] @@ -2987,7 +3004,7 @@ dependencies = [ "hmac", "num-bigint", "num-integer", - "num-traits 0.2.19", + "num-traits", "rfc6979", "sha2", "starknet-crypto-codegen", @@ -3004,7 +3021,7 @@ checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" dependencies = [ "starknet-curve", "starknet-ff", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3030,9 +3047,9 @@ dependencies = [ [[package]] name = "starknet-types-core" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b889ee5734db8b3c8a6551135c16764bf4ce1ab4955fffbb2ac5b6706542b64" +checksum = "fa1b9e01ccb217ab6d475c5cda05dbb22c30029f7bb52b192a010a00d77a3d74" dependencies = [ "arbitrary", "lambdaworks-crypto", @@ -3040,7 +3057,7 @@ dependencies = [ "lazy_static", "num-bigint", "num-integer", - "num-traits 0.2.19", + "num-traits", "serde", ] @@ -3082,9 +3099,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -3105,9 +3122,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", @@ -3129,22 +3146,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3198,9 +3215,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.40.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", @@ -3220,7 +3237,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3263,7 +3280,7 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "serde", "serde_spanned", "toml_datetime", @@ -3348,7 +3365,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3388,9 +3405,9 @@ dependencies = [ [[package]] name = "triomphe" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6631e42e10b40c0690bf92f404ebcfe6e1fdb480391d15f17cc8e96eeed5369" +checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85" dependencies = [ "serde", "stable_deref_trait", @@ -3425,12 +3442,9 @@ dependencies = [ [[package]] name = "unicase" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] +checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" [[package]] name = "unicode-ident" @@ -3458,9 +3472,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" dependencies = [ "getrandom", ] @@ -3532,7 +3546,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -3566,7 +3580,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3599,7 +3613,7 @@ checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3859,7 +3873,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -3879,7 +3893,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] diff --git a/cairo1-run/program.cairo b/cairo1-run/program.cairo new file mode 100644 index 0000000000..08526ea9c1 --- /dev/null +++ b/cairo1-run/program.cairo @@ -0,0 +1,9 @@ +use core::poseidon::PoseidonTrait; +use core::hash::{HashStateTrait, HashStateExTrait}; +use core::testing::get_available_gas; + +fn main() { + let a: u128 = get_available_gas(); + let b = PoseidonTrait::new().update_with(a).finalize(); + assert(b != 0, ''); +} From 1498ff09b1bce303d60c7ceffd9e136b9523b0b7 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 14 Nov 2024 17:16:38 -0300 Subject: [PATCH 22/33] remove unwanted files --- Cargo.lock | 4 ++-- cairo1-run/program.cairo | 9 --------- vm/src/serde/deserialize_program.rs | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 cairo1-run/program.cairo diff --git a/Cargo.lock b/Cargo.lock index 7f6eefe9bf..20b66dc5cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1370,9 +1370,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", "miniz_oxide", diff --git a/cairo1-run/program.cairo b/cairo1-run/program.cairo deleted file mode 100644 index 08526ea9c1..0000000000 --- a/cairo1-run/program.cairo +++ /dev/null @@ -1,9 +0,0 @@ -use core::poseidon::PoseidonTrait; -use core::hash::{HashStateTrait, HashStateExTrait}; -use core::testing::get_available_gas; - -fn main() { - let a: u128 = get_available_gas(); - let b = PoseidonTrait::new().update_with(a).finalize(); - assert(b != 0, ''); -} diff --git a/vm/src/serde/deserialize_program.rs b/vm/src/serde/deserialize_program.rs index 052d9ae09c..64d6e51f7b 100644 --- a/vm/src/serde/deserialize_program.rs +++ b/vm/src/serde/deserialize_program.rs @@ -1494,7 +1494,7 @@ mod tests { fn test_felt_from_number_with_scientific_notation() { let n = Number::deserialize(serde_json::Value::from(1000000000000000000000000000_u128)) .unwrap(); - assert_eq!(n.to_string(), "1e27".to_owned()); + assert_eq!(n.to_string(), "1000000000000000000000000000".to_owned()); assert_matches!( felt_from_number(n), From 6b385008bfa9ad98c50094fbff4f4b50f4fd6e24 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 14 Nov 2024 18:22:41 -0300 Subject: [PATCH 23/33] change test --- vm/src/serde/deserialize_program.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/src/serde/deserialize_program.rs b/vm/src/serde/deserialize_program.rs index 64d6e51f7b..dd614dbd68 100644 --- a/vm/src/serde/deserialize_program.rs +++ b/vm/src/serde/deserialize_program.rs @@ -1492,9 +1492,9 @@ mod tests { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_felt_from_number_with_scientific_notation() { - let n = Number::deserialize(serde_json::Value::from(1000000000000000000000000000_u128)) + let n = Number::deserialize(serde_json::Value::from(1e27)) .unwrap(); - assert_eq!(n.to_string(), "1000000000000000000000000000".to_owned()); + assert_eq!(n.to_string(), "1e27".to_owned()); assert_matches!( felt_from_number(n), From 397cd7419b4b1dc052d0c6eddbf8ccd6d529cb54 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 14 Nov 2024 18:30:31 -0300 Subject: [PATCH 24/33] format --- vm/src/serde/deserialize_program.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vm/src/serde/deserialize_program.rs b/vm/src/serde/deserialize_program.rs index dd614dbd68..82771f7552 100644 --- a/vm/src/serde/deserialize_program.rs +++ b/vm/src/serde/deserialize_program.rs @@ -1492,8 +1492,7 @@ mod tests { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_felt_from_number_with_scientific_notation() { - let n = Number::deserialize(serde_json::Value::from(1e27)) - .unwrap(); + let n = Number::deserialize(serde_json::Value::from(1e27)).unwrap(); assert_eq!(n.to_string(), "1e27".to_owned()); assert_matches!( From 862a5c043b7c188b41cfe675fb0176870b0b66eb Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 10:15:34 -0300 Subject: [PATCH 25/33] better error handling --- .../hint_processor/cairo_1_hint_processor/circuit.rs | 11 +++++++---- vm/src/vm/errors/hint_errors.rs | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index c107ab645e..58d189820e 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -7,6 +7,7 @@ use ark_ff::{One, Zero}; use num_bigint::{BigInt, BigUint, ToBigInt}; use num_integer::Integer; use num_traits::Signed; +use proptest::prelude::Strategy; use starknet_types_core::felt::Felt; use crate::{ @@ -122,7 +123,7 @@ fn compute_gates( mul_mod_offsets: Relocatable, n_mul_mods: usize, modulus_ptr: Relocatable, -) -> usize { +) -> Result { let modulus = read_circuit_value(vm, modulus_ptr).unwrap(); let mut circuit = Circuit { vm, @@ -185,14 +186,16 @@ fn compute_gates( } } _ => { - unreachable!("Unexpected None value while filling mul_mod gate") + return Err(HintError::CircuitEvaluationFailed(Box::from( + "Unexpected None value while filling mul_mod gate", + ))) } } mulmod_idx += 1; } - first_failure_idx + Ok(first_failure_idx) } fn fill_instances( @@ -249,7 +252,7 @@ pub fn eval_circuit( mul_mod_offsets, n_mul_mods, modulus_ptr, - ); + )?; let modulus: [Felt; 4] = array::from_fn(|l| *vm.get_integer((modulus_ptr + l).unwrap()).unwrap().deref()); diff --git a/vm/src/vm/errors/hint_errors.rs b/vm/src/vm/errors/hint_errors.rs index 0594a2f518..639ce9aaf2 100644 --- a/vm/src/vm/errors/hint_errors.rs +++ b/vm/src/vm/errors/hint_errors.rs @@ -190,6 +190,8 @@ pub enum HintError { ExcessBalanceKeyError(Box), #[error("excess_balance_func: Failed to calculate {0}")] ExcessBalanceCalculationFailed(Box), + #[error("circuit evalution: {0}")] + CircuitEvaluationFailed(Box), } #[cfg(test)] From f6a89a79868ebdc91d27f238d8b0c725dbd73881 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 10:15:56 -0300 Subject: [PATCH 26/33] better error handling --- vm/src/hint_processor/cairo_1_hint_processor/circuit.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 58d189820e..31077eca02 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -186,9 +186,11 @@ fn compute_gates( } } _ => { + // this should be unreachable as it would mean that the + //circuit being evaluated is not complete and therefore invalid return Err(HintError::CircuitEvaluationFailed(Box::from( "Unexpected None value while filling mul_mod gate", - ))) + ))); } } @@ -257,7 +259,7 @@ pub fn eval_circuit( let modulus: [Felt; 4] = array::from_fn(|l| *vm.get_integer((modulus_ptr + l).unwrap()).unwrap().deref()); - fill_instances( + fill_inst( vm, add_mod_builtin_address, n_add_mods, From 60d660241ee302cc122b76019ffead76ce2489bc Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 10:18:49 -0300 Subject: [PATCH 27/33] better error handling --- vm/src/hint_processor/cairo_1_hint_processor/circuit.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 31077eca02..fb10f2530e 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -7,7 +7,6 @@ use ark_ff::{One, Zero}; use num_bigint::{BigInt, BigUint, ToBigInt}; use num_integer::Integer; use num_traits::Signed; -use proptest::prelude::Strategy; use starknet_types_core::felt::Felt; use crate::{ @@ -259,7 +258,7 @@ pub fn eval_circuit( let modulus: [Felt; 4] = array::from_fn(|l| *vm.get_integer((modulus_ptr + l).unwrap()).unwrap().deref()); - fill_inst( + fill_instances( vm, add_mod_builtin_address, n_add_mods, From 1119398d7b25840a3ba4549ce48ced7e1ff39d70 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 10:25:52 -0300 Subject: [PATCH 28/33] fix --- vm/src/hint_processor/cairo_1_hint_processor/circuit.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index fb10f2530e..08a41d4bf4 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -10,6 +10,7 @@ use num_traits::Signed; use starknet_types_core::felt::Felt; use crate::{ + stdlib::boxed::Box, types::relocatable::{MaybeRelocatable, Relocatable}, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; From b7bfc6eb89e59200aaa79cad0c33cd18afea5a6b Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 14:25:51 -0300 Subject: [PATCH 29/33] fix CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb95d941f1..6516229b6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## Cairo-VM Changelog #### Upcoming Changes +* 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 * fix: [#1868](https://github.com/lambdaclass/cairo-vm/pull/1855): @@ -23,8 +25,6 @@ * fix: [#1851](https://github.com/lambdaclass/cairo-vm/pull/1851): * Fix unsorted signature and mod builtin outputs in air_private_input. -* feat: add `EvalCircuit` and `TestLessThanOrEqualAddress` hints [#1843](https://github.com/lambdaclass/cairo-vm/pull/1843) - * feat(BREAKING): [#1824](https://github.com/lambdaclass/cairo-vm/pull/1824)[#1838](https://github.com/lambdaclass/cairo-vm/pull/1838): * Add support for dynamic layout * CLI change(BREAKING): The flag `cairo_layout_params_file` must be specified when using dynamic layout. From 13e00fff64fd9fe470ecef64c95f923ed725379a Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 16:53:37 -0300 Subject: [PATCH 30/33] fix unwraps --- .../cairo_1_hint_processor/circuit.rs | 113 +++++++++++------- vm/src/vm/errors/hint_errors.rs | 2 + 2 files changed, 71 insertions(+), 44 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 08a41d4bf4..dff4e5a42a 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -1,7 +1,7 @@ // Most of the `EvalCircuit` implementation is derived from the `cairo-lang-runner` crate. // https://github.com/starkware-libs/cairo/blob/main/crates/cairo-lang-runner/src/casm_run/circuit.rs -use core::{array, ops::Deref}; +use core::ops::Deref; use ark_ff::{One, Zero}; use num_bigint::{BigInt, BigUint, ToBigInt}; @@ -12,7 +12,10 @@ use starknet_types_core::felt::Felt; use crate::{ stdlib::boxed::Box, types::relocatable::{MaybeRelocatable, Relocatable}, - vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, + vm::{ + errors::{hint_errors::HintError, memory_errors::MemoryError}, + vm_core::VirtualMachine, + }, }; // A gate is defined by 3 offsets, the first two are the inputs and the third is the output. @@ -31,79 +34,97 @@ struct Circuit<'a> { } impl Circuit<'_> { - fn read_add_mod_value(&mut self, offset: usize) -> Option { - self.read_circuit_value((self.add_mod_offsets + offset).unwrap()) + fn read_add_mod_value(&mut self, offset: usize) -> Result, MemoryError> { + self.read_circuit_value((self.add_mod_offsets + offset)?) } - fn read_mul_mod_value(&mut self, offset: usize) -> Option { - self.read_circuit_value((self.mul_mod_offsets + offset).unwrap()) + fn read_mul_mod_value(&mut self, offset: usize) -> Result, MemoryError> { + self.read_circuit_value((self.mul_mod_offsets + offset)?) } - fn read_circuit_value(&mut self, offset: Relocatable) -> Option { - let value_ptr = self.get_value_ptr(offset); - read_circuit_value(self.vm, value_ptr) + fn read_circuit_value(&mut self, offset: Relocatable) -> Result, MemoryError> { + let value_ptr = self.get_value_ptr(offset)?; + Ok(read_circuit_value(self.vm, value_ptr)?) } - fn write_add_mod_value(&mut self, offset: usize, value: BigUint) { - self.write_circuit_value((self.add_mod_offsets + offset).unwrap(), value); + fn write_add_mod_value(&mut self, offset: usize, value: BigUint) -> Result<(), MemoryError> { + self.write_circuit_value((self.add_mod_offsets + offset)?, value)?; + + Ok(()) } - fn write_mul_mod_value(&mut self, offset: usize, value: BigUint) { - self.write_circuit_value((self.mul_mod_offsets + offset).unwrap(), value); + fn write_mul_mod_value(&mut self, offset: usize, value: BigUint) -> Result<(), MemoryError> { + self.write_circuit_value((self.mul_mod_offsets + offset)?, value)?; + + Ok(()) } - fn write_circuit_value(&mut self, offset: Relocatable, value: BigUint) { - let value_ptr = self.get_value_ptr(offset); - write_circuit_value(self.vm, value_ptr, value); + fn write_circuit_value( + &mut self, + offset: Relocatable, + value: BigUint, + ) -> Result<(), MemoryError> { + let value_ptr = self.get_value_ptr(offset)?; + write_circuit_value(self.vm, value_ptr, value)?; + + Ok(()) } - fn get_value_ptr(&self, address: Relocatable) -> Relocatable { - (self.values_ptr + self.vm.get_integer(address).unwrap().as_ref()).unwrap() + fn get_value_ptr(&self, address: Relocatable) -> Result { + (self.values_ptr + self.vm.get_integer(address)?.as_ref()).map_err(|e| MemoryError::Math(e)) } } -fn read_circuit_value(vm: &mut VirtualMachine, add: Relocatable) -> Option { +fn read_circuit_value( + vm: &mut VirtualMachine, + add: Relocatable, +) -> Result, MemoryError> { let mut res = BigUint::zero(); for l in (0..LIMBS_COUNT).rev() { - let add_l = (add + l).unwrap(); + let add_l = (add + l)?; match vm.get_maybe(&add_l) { Some(MaybeRelocatable::Int(limb)) => res = (res << 96) + limb.to_biguint(), - _ => return None, + _ => return Ok(None), } } - Some(res) + Ok(Some(res)) } -fn write_circuit_value(vm: &mut VirtualMachine, add: Relocatable, mut value: BigUint) { +fn write_circuit_value( + vm: &mut VirtualMachine, + add: Relocatable, + mut value: BigUint, +) -> Result<(), MemoryError> { for l in 0..LIMBS_COUNT { // get the nth limb from a circuit value let (new_value, rem) = value.div_rem(&(BigUint::one() << 96u8)); - vm.insert_value((add + l).unwrap(), Felt::from(rem)) - .unwrap(); + vm.insert_value((add + l)?, Felt::from(rem))?; value = new_value; } + + Ok(()) } // Finds the inverse of a value. // // If the value has no inverse, find a nullifier so that: // value * nullifier = 0 (mod modulus) -fn find_inverse(value: BigUint, modulus: &BigUint) -> (bool, BigUint) { +fn find_inverse(value: BigUint, modulus: &BigUint) -> Result<(bool, BigUint), HintError> { let ex_gcd = value .to_bigint() - .unwrap() - .extended_gcd(&modulus.to_bigint().unwrap()); + .ok_or(HintError::BigUintToBigIntFail)? + .extended_gcd(&modulus.to_bigint().ok_or(HintError::BigUintToBigIntFail)?); let gcd = ex_gcd.gcd.to_biguint().unwrap(); if gcd.is_one() { - return (true, get_modulus(&ex_gcd.x, modulus)); + return Ok((true, get_modulus(&ex_gcd.x, modulus))); } let nullifier = modulus / gcd; - (false, nullifier) + Ok((false, nullifier)) } fn get_modulus(value: &BigInt, modulus: &BigUint) -> BigUint { @@ -124,7 +145,7 @@ fn compute_gates( n_mul_mods: usize, modulus_ptr: Relocatable, ) -> Result { - let modulus = read_circuit_value(vm, modulus_ptr).unwrap(); + let modulus = read_circuit_value(vm, modulus_ptr)?.unwrap(); let mut circuit = Circuit { vm, values_ptr, @@ -141,21 +162,21 @@ fn compute_gates( loop { while addmod_idx < n_add_mods { - let lhs = circuit.read_add_mod_value(3 * addmod_idx); - let rhs = circuit.read_add_mod_value(3 * addmod_idx + 1); + let lhs = circuit.read_add_mod_value(3 * addmod_idx)?; + let rhs = circuit.read_add_mod_value(3 * addmod_idx + 1)?; match (lhs, rhs) { (Some(l), Some(r)) => { let res = (l + r) % &circuit.modulus; - circuit.write_add_mod_value(3 * addmod_idx + 2, res); + circuit.write_add_mod_value(3 * addmod_idx + 2, res)?; } // sub gate: lhs = res - rhs (None, Some(r)) => { - let Some(res) = circuit.read_add_mod_value(3 * addmod_idx + 2) else { + let Some(res) = circuit.read_add_mod_value(3 * addmod_idx + 2)? else { break; }; let value = (res + &circuit.modulus - r) % &circuit.modulus; - circuit.write_add_mod_value(3 * addmod_idx, value); + circuit.write_add_mod_value(3 * addmod_idx, value)?; } _ => break, } @@ -167,18 +188,18 @@ fn compute_gates( break; } - let lhs = circuit.read_mul_mod_value(3 * mulmod_idx); - let rhs = circuit.read_mul_mod_value(3 * mulmod_idx + 1); + let lhs = circuit.read_mul_mod_value(3 * mulmod_idx)?; + let rhs = circuit.read_mul_mod_value(3 * mulmod_idx + 1)?; match (lhs, rhs) { (Some(l), Some(r)) => { let res = (l * r) % &circuit.modulus; - circuit.write_mul_mod_value(3 * mulmod_idx + 2, res); + circuit.write_mul_mod_value(3 * mulmod_idx + 2, res)?; } // inverse gate: lhs = 1 / rhs (None, Some(r)) => { - let (success, res) = find_inverse(r, &circuit.modulus); - circuit.write_mul_mod_value(3 * mulmod_idx, res); + let (success, res) = find_inverse(r, &circuit.modulus)?; + circuit.write_mul_mod_value(3 * mulmod_idx, res)?; if !success { first_failure_idx = mulmod_idx; @@ -209,7 +230,7 @@ fn fill_instances( mut offsets_ptr: Relocatable, ) -> Result<(), HintError> { for i in 0..n_instances { - let instance_ptr = (built_ptr + i * MOD_BUILTIN_INSTACE_SIZE).unwrap(); + let instance_ptr = (built_ptr + i * MOD_BUILTIN_INSTACE_SIZE)?; for (idx, value) in modulus.iter().enumerate() { vm.insert_value((instance_ptr + idx)?, *value)?; @@ -256,8 +277,12 @@ pub fn eval_circuit( modulus_ptr, )?; - let modulus: [Felt; 4] = - array::from_fn(|l| *vm.get_integer((modulus_ptr + l).unwrap()).unwrap().deref()); + let modulus: [Felt; 4] = [ + *vm.get_integer(modulus_ptr)?.deref(), + *vm.get_integer((modulus_ptr + 1)?)?.deref(), + *vm.get_integer((modulus_ptr + 2)?)?.deref(), + *vm.get_integer((modulus_ptr + 3)?)?.deref(), + ]; fill_instances( vm, diff --git a/vm/src/vm/errors/hint_errors.rs b/vm/src/vm/errors/hint_errors.rs index 639ce9aaf2..849d38288d 100644 --- a/vm/src/vm/errors/hint_errors.rs +++ b/vm/src/vm/errors/hint_errors.rs @@ -154,6 +154,8 @@ pub enum HintError { BigintToU32Fail, #[error("BigInt to BigUint failed, BigInt is negative")] BigIntToBigUintFail, + #[error("BigUint to BigInt failed")] + BigUintToBigIntFail, #[error("Assertion failed, 0 <= ids.a % PRIME < range_check_builtin.bound \n a = {0} is out of range")] ValueOutOfRange(Box), #[error("Assertion failed, 0 <= ids.a % PRIME < range_check_builtin.bound \n a = {0} is out of range")] From 18d061cbf1acc5f711f6071f71d316bfb4a1aa3f Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 17:09:09 -0300 Subject: [PATCH 31/33] fix unwraps --- .../hint_processor/cairo_1_hint_processor/circuit.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index dff4e5a42a..05d5b25aed 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -117,7 +117,10 @@ fn find_inverse(value: BigUint, modulus: &BigUint) -> Result<(bool, BigUint), Hi .ok_or(HintError::BigUintToBigIntFail)? .extended_gcd(&modulus.to_bigint().ok_or(HintError::BigUintToBigIntFail)?); - let gcd = ex_gcd.gcd.to_biguint().unwrap(); + let gcd = ex_gcd + .gcd + .to_biguint() + .ok_or(HintError::BigIntToBigUintFail)?; if gcd.is_one() { return Ok((true, get_modulus(&ex_gcd.x, modulus))); } @@ -145,7 +148,10 @@ fn compute_gates( n_mul_mods: usize, modulus_ptr: Relocatable, ) -> Result { - let modulus = read_circuit_value(vm, modulus_ptr)?.unwrap(); + let modulus = read_circuit_value(vm, modulus_ptr)?.ok_or(HintError::Memory( + MemoryError::ExpectedInteger(Box::from(modulus_ptr)), + ))?; + let mut circuit = Circuit { vm, values_ptr, From d70786f0b5c04a07091b2230a8e9bcdeee67f5be Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 17:23:47 -0300 Subject: [PATCH 32/33] fix unwraps --- .../cairo_1_hint_processor/hint_processor.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs index 40dad19bf0..9b6e4b8651 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs @@ -11,7 +11,7 @@ use crate::vm::runners::cairo_runner::RunResources; use crate::Felt252; use crate::{ hint_processor::hint_processor_definition::HintProcessorLogic, - types::exec_scope::ExecutionScopes, + types::{errors::math_errors::MathError, exec_scope::ExecutionScopes}, vm::errors::vm_errors::VirtualMachineError, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; @@ -1212,8 +1212,20 @@ impl Cairo1HintProcessor { n_mul_mods: &ResOperand, mul_mod_builtin_ptr: &ResOperand, ) -> Result<(), HintError> { - let n_add_mods = get_val(vm, n_add_mods)?.to_usize().unwrap(); - let n_mul_mods = get_val(vm, n_mul_mods)?.to_usize().unwrap(); + let n_add_mods = get_val(vm, n_add_mods)?; + let n_add_mods = + n_add_mods + .to_usize() + .ok_or(HintError::Math(MathError::Felt252ToUsizeConversion( + Box::from(n_add_mods), + )))?; + let n_mul_mods = get_val(vm, n_mul_mods)?; + let n_mul_mods = + n_mul_mods + .to_usize() + .ok_or(HintError::Math(MathError::Felt252ToUsizeConversion( + Box::from(n_mul_mods), + )))?; let (add_mod_builtin_base, add_mod_builtin_offset) = extract_buffer(add_mod_builtin_ptr)?; let (mul_mod_builtin_base, mul_mod_builtin_offset) = extract_buffer(mul_mod_builtin_ptr)?; From b367d969f61985455642c013a62cae149612428a Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 15 Nov 2024 17:33:51 -0300 Subject: [PATCH 33/33] clippy --- vm/src/hint_processor/cairo_1_hint_processor/circuit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs index 05d5b25aed..1b23a7f0e3 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/circuit.rs @@ -44,7 +44,7 @@ impl Circuit<'_> { fn read_circuit_value(&mut self, offset: Relocatable) -> Result, MemoryError> { let value_ptr = self.get_value_ptr(offset)?; - Ok(read_circuit_value(self.vm, value_ptr)?) + read_circuit_value(self.vm, value_ptr) } fn write_add_mod_value(&mut self, offset: usize, value: BigUint) -> Result<(), MemoryError> { @@ -71,7 +71,7 @@ impl Circuit<'_> { } fn get_value_ptr(&self, address: Relocatable) -> Result { - (self.values_ptr + self.vm.get_integer(address)?.as_ref()).map_err(|e| MemoryError::Math(e)) + (self.values_ptr + self.vm.get_integer(address)?.as_ref()).map_err(MemoryError::Math) } }