diff --git a/Cargo.lock b/Cargo.lock index 1da07e03a..c19d16c11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "array-macro" -version = "2.1.5" +version = "2.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "457661fa6716c30b73d7c41400a8a78780d20523b83a9441dabec28e93f27cf4" +checksum = "220a2c618ab466efe41d0eace94dfeff1c35e3aa47891bdb95e1c0fefffd3c99" [[package]] name = "arrayvec" @@ -883,7 +883,7 @@ dependencies = [ [[package]] name = "curta" version = "0.1.0" -source = "git+https://github.com/succinctlabs/curta.git#86723feac21731c3f7acd8827abafe16609d47c4" +source = "git+https://github.com/succinctlabs/curta.git#11f52ddc96a2433d1d983668c484a54afefc1f18" dependencies = [ "anyhow", "bincode", @@ -1208,9 +1208,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" dependencies = [ "humantime", "is-terminal", @@ -1610,9 +1610,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a481586acf778f1b1455424c343f71124b048ffa5f4fc3f8f6ae9dc432dcb3c7" +checksum = "f69037fe1b785e84986b4f2cbcf647381876a00671d25ceef715d7812dd7e1dd" [[package]] name = "fixed-hash" @@ -1828,9 +1828,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", "js-sys", @@ -1975,9 +1975,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "f95b9abcae896730d42b78e09c155ed4ddf82c07b4de772c64aee5b2d8b7c150" dependencies = [ "bytes", "fnv", @@ -2352,9 +2352,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" [[package]] name = "lock_api" @@ -2906,7 +2906,7 @@ checksum = "14e6ab3f592e6fb464fc9712d8d6e6912de6473954635fd76a589d832cffcbb0" [[package]] name = "plonky2" version = "0.1.4" -source = "git+https://github.com/mir-protocol/plonky2.git#605932d149eeba4558b404b52180e9ac20daca87" +source = "git+https://github.com/mir-protocol/plonky2.git#5c41dc4dacc899921951d852883bb9f2792b3c62" dependencies = [ "ahash", "anyhow", @@ -2930,7 +2930,7 @@ dependencies = [ [[package]] name = "plonky2_field" version = "0.1.1" -source = "git+https://github.com/mir-protocol/plonky2.git#605932d149eeba4558b404b52180e9ac20daca87" +source = "git+https://github.com/mir-protocol/plonky2.git#5c41dc4dacc899921951d852883bb9f2792b3c62" dependencies = [ "anyhow", "itertools 0.11.0", @@ -2954,7 +2954,7 @@ dependencies = [ [[package]] name = "plonky2_maybe_rayon" version = "0.1.1" -source = "git+https://github.com/mir-protocol/plonky2.git#605932d149eeba4558b404b52180e9ac20daca87" +source = "git+https://github.com/mir-protocol/plonky2.git#5c41dc4dacc899921951d852883bb9f2792b3c62" dependencies = [ "rayon", ] @@ -2962,7 +2962,7 @@ dependencies = [ [[package]] name = "plonky2_util" version = "0.1.1" -source = "git+https://github.com/mir-protocol/plonky2.git#605932d149eeba4558b404b52180e9ac20daca87" +source = "git+https://github.com/mir-protocol/plonky2.git#5c41dc4dacc899921951d852883bb9f2792b3c62" [[package]] name = "plonky2x" @@ -2980,7 +2980,7 @@ dependencies = [ "digest 0.10.7", "dotenv", "ed25519-dalek", - "env_logger 0.10.0", + "env_logger 0.10.1", "ethers", "ff", "futures", @@ -3120,9 +3120,9 @@ dependencies = [ [[package]] name = "proptest" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c003ac8c77cb07bb74f5f198bce836a689bcd5a42574612bf14d17bfd08c20e" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", "bit-vec", @@ -3132,7 +3132,7 @@ dependencies = [ "rand", "rand_chacha", "rand_xorshift", - "regex-syntax 0.7.5", + "regex-syntax 0.8.2", "rusty-fork", "tempfile", "unarray", @@ -3473,9 +3473,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ "base64 0.21.5", ] @@ -3504,7 +3504,7 @@ dependencies = [ "alloy-sol-types", "clap", "dotenv", - "env_logger 0.10.0", + "env_logger 0.10.1", "ethers", "hex", "log", @@ -3871,9 +3871,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "smol_str" @@ -4016,9 +4016,9 @@ dependencies = [ [[package]] name = "svm-rs" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0cc95be7cc2c384a2f57cac56548d2178650905ebe5725bc8970ccc25529060" +checksum = "20689c7d03b6461b502d0b95d6c24874c7d24dea2688af80486a130a06af3b07" dependencies = [ "dirs", "fs2", @@ -4203,9 +4203,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.33.0" +version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" +checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" dependencies = [ "backtrace", "bytes", @@ -4222,9 +4222,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", diff --git a/plonky2x/core/src/frontend/ecc/curve25519/curta/stark.rs b/plonky2x/core/src/frontend/ecc/curve25519/curta/stark.rs index a9dcc0bf0..773397456 100644 --- a/plonky2x/core/src/frontend/ecc/curve25519/curta/stark.rs +++ b/plonky2x/core/src/frontend/ecc/curve25519/curta/stark.rs @@ -1,18 +1,20 @@ use curta::chip::builder::AirBuilder; -use curta::chip::ec::edwards::ed25519::gadget::{CompressedPointGadget, CompressedPointWriter}; +use curta::chip::ec::edwards::ed25519::gadget::{CompressedPointAirWriter, CompressedPointGadget}; use curta::chip::ec::edwards::ed25519::instruction::Ed25519FpInstruction; use curta::chip::ec::edwards::ed25519::point::CompressedPointRegister; -use curta::chip::ec::gadget::EllipticCurveWriter; +use curta::chip::ec::gadget::EllipticCurveAirWriter; use curta::chip::ec::point::{AffinePoint, AffinePointRegister}; use curta::chip::ec::scalar::ECScalarRegister; use curta::chip::register::Register; -use curta::chip::trace::writer::{InnerWriterData, TraceWriter}; +use curta::chip::trace::writer::data::AirWriterData; +use curta::chip::trace::writer::AirWriter; use curta::chip::AirParameters; use curta::machine::builder::Builder; use curta::machine::ec::builder::EllipticCurveBuilder; use curta::machine::emulated::builder::EmulatedBuilder; use curta::machine::emulated::proof::EmulatedStarkProof; use curta::machine::emulated::stark::EmulatedStark; +use curta::maybe_rayon::*; use curve25519_dalek::edwards::CompressedEdwardsY; use itertools::Itertools; use log::debug; @@ -114,15 +116,19 @@ impl, const D: usize> Ed25519Stark { } } - pub fn write_input(&self, writer: &TraceWriter, input: &[Ed25519CurtaOpValue]) { + pub fn write_input( + &self, + writer: &mut impl AirWriter, + input: &[Ed25519CurtaOpValue], + ) { self.operations .iter() .zip(input.iter()) .for_each(|(op, op_value)| match &op { Ed25519CurtaOp::Add(a, b, _) => { if let Ed25519CurtaOpValue::Add(a_val, b_val, _) = &op_value { - writer.write_ec_point(a, a_val, 0); - writer.write_ec_point(b, b_val, 0); + writer.write_ec_point(a, a_val); + writer.write_ec_point(b, b_val); } else { panic!("invalid input"); } @@ -134,24 +140,24 @@ impl, const D: usize> Ed25519Stark { let mut limb_values = scalar_val.to_u32_digits(); limb_values.resize(8, 0); for (limb_reg, limb) in scalar.limbs.iter().zip_eq(limb_values) { - writer.write(&limb_reg, &L::Field::from_canonical_u32(limb), 0); + writer.write(&limb_reg, &L::Field::from_canonical_u32(limb)); } - writer.write_ec_point(point, point_val, 0); - writer.write_ec_point(result, result_val, 0); + writer.write_ec_point(point, point_val); + writer.write_ec_point(result, result_val); } else { panic!("invalid input"); } } Ed25519CurtaOp::Decompress(compressed_point, _) => { if let Ed25519CurtaOpValue::Decompress(compressed_point_val, _) = &op_value { - writer.write_ec_compressed_point(compressed_point, compressed_point_val, 0); + writer.write_ec_compressed_point(compressed_point, compressed_point_val); } else { panic!("invalid input"); } } Ed25519CurtaOp::IsValid(point) => { if let Ed25519CurtaOpValue::IsValid(point_val) = &op_value { - writer.write_ec_point(point, point_val, 0); + writer.write_ec_point(point, point_val); } else { panic!("invalid input"); } @@ -168,21 +174,24 @@ impl, const D: usize> Ed25519Stark { Vec, ) { let num_rows = self.degree; - let writer = TraceWriter::new(&self.stark.air_data, num_rows); + + let mut writer_data = AirWriterData::new(&self.stark.air_data, num_rows); debug!("Writing EC stark input"); - self.write_input(&writer, input); + let mut writer = writer_data.public_writer(); + self.write_input(&mut writer, input); debug!("Writing EC execusion trace"); - writer.write_global_instructions(&self.stark.air_data); - for i in 0..num_rows { - writer.write_row_instructions(&self.stark.air_data, i); - } - - let public_inputs: Vec = writer.public().unwrap().clone(); + self.stark.air_data.write_global_instructions(&mut writer); + writer_data.chunks_par(256).for_each(|mut chunk| { + for i in 0..256 { + let mut writer = chunk.window_writer(i); + self.stark.air_data.write_trace_instructions(&mut writer); + } + }); debug!("EC stark proof generation"); - let InnerWriterData { trace, public, .. } = writer.into_inner().unwrap(); + let (trace, public) = (writer_data.trace, writer_data.public); let proof = self .stark .prove(&trace, &public, &mut TimingTree::default()) @@ -193,7 +202,7 @@ impl, const D: usize> Ed25519Stark { debug!("EC stark proof verified"); - (proof, public_inputs) + (proof, public) } pub fn verify_proof(