From 21185a0ce8da2233d161f9f22c789c79afaf6558 Mon Sep 17 00:00:00 2001 From: Alon Haramati Date: Wed, 3 Jul 2024 12:42:11 +0300 Subject: [PATCH] Update stwo and fix changes. --- Cargo.lock | 46 ++++++------- .../src/components/range_check_unit.rs | 65 +++++++++---------- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9894ba69..01161934 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,14 +150,14 @@ checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", ] [[package]] name = "cc" -version = "1.0.101" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" +checksum = "5208975e568d83b6b05cc0a063c8e7e9acc2b43bee6da15616a5b73e109d7437" [[package]] name = "cfg-if" @@ -238,7 +238,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", ] [[package]] @@ -264,7 +264,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", ] [[package]] @@ -340,15 +340,15 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "num-bigint" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", @@ -467,22 +467,22 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", ] [[package]] @@ -524,7 +524,7 @@ checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" dependencies = [ "starknet-curve", "starknet-ff", - "syn 2.0.68", + "syn 2.0.69", ] [[package]] @@ -553,7 +553,7 @@ dependencies = [ [[package]] name = "stwo-prover" version = "0.1.1" -source = "git+https://github.com/starkware-libs/stwo?branch=dev#1f38b04c6cea354774585eb27d6116c3e0a2eeba" +source = "git+https://github.com/starkware-libs/stwo?branch=dev#8866c2815a5107372bd78356f304f0570daf20aa" dependencies = [ "blake2", "blake3", @@ -599,9 +599,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "201fcda3845c23e8212cd466bfebf0bd20694490fc0356ae8e428e0824a915a6" dependencies = [ "proc-macro2", "quote", @@ -625,7 +625,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", ] [[package]] @@ -647,7 +647,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", ] [[package]] @@ -704,7 +704,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", "wasm-bindgen-shared", ] @@ -726,7 +726,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -754,5 +754,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.69", ] diff --git a/stwo_cairo_prover/src/components/range_check_unit.rs b/stwo_cairo_prover/src/components/range_check_unit.rs index 56e0bfda..101da046 100644 --- a/stwo_cairo_prover/src/components/range_check_unit.rs +++ b/stwo_cairo_prover/src/components/range_check_unit.rs @@ -2,19 +2,21 @@ use itertools::{zip_eq, Itertools}; use num_traits::Zero; use stwo_prover::core::air::accumulation::PointEvaluationAccumulator; -use stwo_prover::core::air::{Component, ComponentTraceWriter}; +use stwo_prover::core::air::Component; use stwo_prover::core::backend::CpuBackend; use stwo_prover::core::circle::CirclePoint; use stwo_prover::core::fields::m31::BaseField; use stwo_prover::core::fields::qm31::SecureField; +use stwo_prover::core::fields::secure_column::SecureColumn; use stwo_prover::core::fields::FieldExpOps; use stwo_prover::core::pcs::TreeVec; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; +use stwo_prover::core::LookupValues; use stwo_prover::core::{ColumnVec, InteractionElements}; - use stwo_prover::trace_generation::registry::ComponentGenerationRegistry; -use stwo_prover::trace_generation::{ComponentGen, TraceGenerator}; +use stwo_prover::trace_generation::ComponentGen; +use stwo_prover::trace_generation::ComponentTraceGenerator; pub const RC_Z: &str = "RangeCheckUnit_Z"; pub const RC_COMPONENT_ID: &str = "RC_UNIT"; @@ -55,16 +57,13 @@ impl Component for RangeCheckUnitComponent { fn evaluate_constraint_quotients_at_point( &self, _point: CirclePoint, - _mask: &ColumnVec>, + _mask: &TreeVec>>, _evaluation_accumulator: &mut PointEvaluationAccumulator, _interaction_elements: &InteractionElements, + _lookup_values: &LookupValues, ) { unimplemented!() } - - fn interaction_element_ids(&self) -> Vec { - unimplemented!() - } } impl RangeCheckUnitTraceGenerator { @@ -79,7 +78,7 @@ impl RangeCheckUnitTraceGenerator { impl ComponentGen for RangeCheckUnitTraceGenerator {} -impl TraceGenerator for RangeCheckUnitTraceGenerator { +impl ComponentTraceGenerator for RangeCheckUnitTraceGenerator { type Component = RangeCheckUnitComponent; type Inputs = Vec; @@ -113,14 +112,6 @@ impl TraceGenerator for RangeCheckUnitTraceGenerator { .collect_vec() } - fn component(&self) -> RangeCheckUnitComponent { - RangeCheckUnitComponent { - log_n_instances: self.max_value.checked_ilog2().unwrap() as usize, - } - } -} - -impl ComponentTraceWriter for RangeCheckUnitTraceGenerator { fn write_interaction_trace( &self, trace: &ColumnVec<&CircleEvaluation>, @@ -129,21 +120,28 @@ impl ComponentTraceWriter for RangeCheckUnitTraceGenerator { let interaction_trace_domain = trace[0].domain; let z = elements[RC_Z]; - let mut last = BaseField::zero(); + let mut last = SecureField::zero(); let interaction_values = zip_eq(&trace[0].values, &trace[1].values).fold( Vec::new(), |mut acc, (trace_value, multiplicity)| { - let interaction_value = last + (z - *trace_value).inverse() * *multiplicity; + let interaction_value = last + ((z - *trace_value).inverse() * *multiplicity); acc.push(interaction_value); last = interaction_value; acc }, ); + let secure_column: SecureColumn = interaction_values.into_iter().collect(); + secure_column + .columns + .into_iter() + .map(|eval| CircleEvaluation::new(interaction_trace_domain, eval)) + .collect_vec() + } - vec![CircleEvaluation::new( - interaction_trace_domain, - interaction_values, - )] + fn component(&self) -> RangeCheckUnitComponent { + RangeCheckUnitComponent { + log_n_instances: self.max_value.checked_ilog2().unwrap() as usize, + } } } @@ -154,7 +152,6 @@ mod tests { #[test] fn test_rc_unit_trace() { let mut registry = ComponentGenerationRegistry::default(); - let random_seed: usize = 117; registry.register(RC_COMPONENT_ID, RangeCheckUnitTraceGenerator::new(8)); let inputs = vec![ vec![BaseField::from_u32_unchecked(0); 3], @@ -174,25 +171,23 @@ mod tests { .add_inputs(&inputs); let trace = RangeCheckUnitTraceGenerator::write_trace(RC_COMPONENT_ID, &mut registry); - let interaction_elements = InteractionElements::new( - [( - RC_Z.to_string(), - BaseField::from_u32_unchecked(random_seed as u32), - )] - .into(), - ); + let random_value = SecureField::from_u32_unchecked(1, 2, 3, 117); + let interaction_elements = + InteractionElements::new([(RC_Z.to_string(), random_value)].into()); let interaction_trace = registry .get_generator::(RC_COMPONENT_ID) .write_interaction_trace(&trace.iter().collect(), &interaction_elements); - let mut trace_sum = BaseField::zero(); + let mut trace_sum = SecureField::zero(); for i in 0..8 { assert_eq!(trace[0].values[i], BaseField::from_u32_unchecked(i as u32)); trace_sum += trace.last().unwrap().values[i] - / BaseField::from_u32_unchecked((random_seed - i) as u32); + / (random_value - BaseField::from_u32_unchecked(i as u32)); } - let logup_sum = interaction_trace.first().unwrap().last().unwrap(); + let logup_sum = SecureField::from_m31_array(std::array::from_fn(|j| { + *interaction_trace[j].last().unwrap() + })); - assert_eq!(*logup_sum, trace_sum); + assert_eq!(logup_sum, trace_sum); } }