diff --git a/stwo_cairo_prover/Cargo.lock b/stwo_cairo_prover/Cargo.lock index 1ce3e053..d77c0f5a 100644 --- a/stwo_cairo_prover/Cargo.lock +++ b/stwo_cairo_prover/Cargo.lock @@ -1210,7 +1210,9 @@ dependencies = [ "ruint", "serde", "starknet-ff", + "stwo-cairo-serialize", "stwo-prover", + "stwo_cairo_utils", ] [[package]] @@ -1630,6 +1632,24 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "stwo-cairo-serialize" +version = "0.1.0" +dependencies = [ + "starknet-ff", + "stwo-cairo-serialize-derive", + "stwo-prover", +] + +[[package]] +name = "stwo-cairo-serialize-derive" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.85", +] + [[package]] name = "stwo-prover" version = "0.1.1" @@ -1669,7 +1689,10 @@ dependencies = [ "rayon", "serde", "sonic-rs", + "starknet-ff", + "stwo-cairo-serialize", "stwo-prover", + "stwo_cairo_utils", "thiserror", "tracing", ] diff --git a/stwo_cairo_prover/Cargo.toml b/stwo_cairo_prover/Cargo.toml index 8ac04604..964715c4 100644 --- a/stwo_cairo_prover/Cargo.toml +++ b/stwo_cairo_prover/Cargo.toml @@ -2,6 +2,8 @@ members = [ "crates/adapted_prover", "crates/prover", + "crates/cairo-serialize", + "crates/cairo-serialize-derive", "crates/utils", "crates/vm_runner", "crates/prover_types", diff --git a/stwo_cairo_prover/crates/adapted_prover/src/main.rs b/stwo_cairo_prover/crates/adapted_prover/src/main.rs index 9051e565..b5ed0bfe 100644 --- a/stwo_cairo_prover/crates/adapted_prover/src/main.rs +++ b/stwo_cairo_prover/crates/adapted_prover/src/main.rs @@ -8,7 +8,7 @@ use stwo_cairo_prover::input::vm_import::{import_from_vm_output, VmImportError}; use stwo_cairo_prover::input::CairoInput; use stwo_cairo_utils::logging_utils::init_logging; use stwo_prover::core::prover::ProvingError; -use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleHasher; +use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use thiserror::Error; use tracing::{span, Level}; @@ -71,7 +71,9 @@ fn run(args: impl Iterator) -> Result(vm_output, args.debug_lookup, args.display_components)?; // TODO(yuval): This is just some serialization for the sake of serialization. Find the right // way to serialize the proof. diff --git a/stwo_cairo_prover/crates/cairo-serialize-derive/Cargo.toml b/stwo_cairo_prover/crates/cairo-serialize-derive/Cargo.toml new file mode 100644 index 00000000..2fe8cead --- /dev/null +++ b/stwo_cairo_prover/crates/cairo-serialize-derive/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "stwo-cairo-serialize-derive" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true + +[dependencies] +proc-macro2 = "1.0" +quote = "1.0" +syn = "2.0" diff --git a/stwo_cairo_prover/crates/cairo-serialize-derive/src/lib.rs b/stwo_cairo_prover/crates/cairo-serialize-derive/src/lib.rs new file mode 100644 index 00000000..2e1539cb --- /dev/null +++ b/stwo_cairo_prover/crates/cairo-serialize-derive/src/lib.rs @@ -0,0 +1,54 @@ +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, Data, DeriveInput, Fields}; + +#[proc_macro_derive(CairoSerialize)] +pub fn derive_cairo_serialize(input: TokenStream) -> TokenStream { + // Parse the input tokens into a syntax tree. + let input = parse_macro_input!(input as DeriveInput); + + let struct_name = input.ident; + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); + + // Extract the fields of the struct. + let fields = match input.data { + Data::Struct(ref data_struct) => match &data_struct.fields { + Fields::Named(ref fields_named) => &fields_named.named, + Fields::Unnamed(_) | Fields::Unit => { + return syn::Error::new_spanned( + struct_name, + "CairoSerialize can only be derived for structs with named fields.", + ) + .to_compile_error() + .into(); + } + }, + _ => { + return syn::Error::new_spanned( + struct_name, + "CairoSerialize can only be derived for structs.", + ) + .to_compile_error() + .into(); + } + }; + + // Generate code to serialize each field in the order they appear. + let serialize_body = fields.iter().map(|f| { + let field_name = &f.ident; + quote! { + CairoSerialize::serialize(&self.#field_name, output); + } + }); + + // Implement `CairoSerialize` for the type. + let expanded = quote! { + impl #impl_generics ::stwo_cairo_serialize::CairoSerialize for #struct_name #ty_generics #where_clause { + fn serialize(&self, output: &mut Vec<::starknet_ff::FieldElement>) { + #(#serialize_body)* + } + } + }; + + TokenStream::from(expanded) +} diff --git a/stwo_cairo_prover/crates/cairo-serialize/Cargo.toml b/stwo_cairo_prover/crates/cairo-serialize/Cargo.toml new file mode 100644 index 00000000..147b302e --- /dev/null +++ b/stwo_cairo_prover/crates/cairo-serialize/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "stwo-cairo-serialize" +version = "0.1.0" +edition = "2021" + +[dependencies] +starknet-ff.workspace = true +stwo-cairo-serialize-derive = { path = "../cairo-serialize-derive" } +stwo-prover.workspace = true diff --git a/stwo_cairo_prover/crates/cairo-serialize/src/lib.rs b/stwo_cairo_prover/crates/cairo-serialize/src/lib.rs new file mode 100644 index 00000000..5a01c982 --- /dev/null +++ b/stwo_cairo_prover/crates/cairo-serialize/src/lib.rs @@ -0,0 +1,185 @@ +use starknet_ff::FieldElement; +// Make derive macro available. +pub use stwo_cairo_serialize_derive::CairoSerialize; +use stwo_prover::core::fields::m31::BaseField; +use stwo_prover::core::fields::qm31::SecureField; +use stwo_prover::core::fri::{FriLayerProof, FriProof}; +use stwo_prover::core::pcs::CommitmentSchemeProof; +use stwo_prover::core::poly::line::LinePoly; +use stwo_prover::core::prover::StarkProof; +use stwo_prover::core::vcs::ops::MerkleHasher; +use stwo_prover::core::vcs::prover::MerkleDecommitment; + +/// Serializes types into a format for deserialization by corresponding types in a Cairo program. +pub trait CairoSerialize { + fn serialize(&self, output: &mut Vec); +} + +impl CairoSerialize for u32 { + fn serialize(&self, output: &mut Vec) { + output.push((*self).into()); + } +} + +impl CairoSerialize for u64 { + fn serialize(&self, output: &mut Vec) { + output.push((*self).into()); + } +} + +impl CairoSerialize for usize { + fn serialize(&self, output: &mut Vec) { + output.push((*self).into()); + } +} + +impl CairoSerialize for BaseField { + fn serialize(&self, output: &mut Vec) { + output.push(self.0.into()); + } +} + +impl CairoSerialize for SecureField { + fn serialize(&self, output: &mut Vec) { + output.extend(self.to_m31_array().map(|c| FieldElement::from(c.0))); + } +} + +impl CairoSerialize for MerkleDecommitment +where + H::Hash: CairoSerialize, +{ + fn serialize(&self, output: &mut Vec) { + let Self { + hash_witness, + column_witness, + } = self; + hash_witness.serialize(output); + column_witness.serialize(output); + } +} + +impl CairoSerialize for LinePoly { + fn serialize(&self, output: &mut Vec) { + (**self).serialize(output); + output.push((self.len().ilog2()).into()); + } +} + +impl CairoSerialize for FriLayerProof +where + H::Hash: CairoSerialize, +{ + fn serialize(&self, output: &mut Vec) { + let Self { + fri_witness, + decommitment, + commitment, + } = self; + fri_witness.serialize(output); + decommitment.serialize(output); + commitment.serialize(output); + } +} + +impl CairoSerialize for FriProof +where + H::Hash: CairoSerialize, +{ + fn serialize(&self, output: &mut Vec) { + let Self { + first_layer, + inner_layers, + last_layer_poly, + } = self; + first_layer.serialize(output); + inner_layers.serialize(output); + last_layer_poly.serialize(output); + } +} + +impl CairoSerialize for FieldElement { + fn serialize(&self, output: &mut Vec) { + output.push(*self); + } +} + +impl CairoSerialize for CommitmentSchemeProof +where + H::Hash: CairoSerialize, +{ + fn serialize(&self, output: &mut Vec) { + let Self { + commitments, + sampled_values, + decommitments, + queried_values, + proof_of_work, + fri_proof, + } = self; + commitments.serialize(output); + sampled_values.serialize(output); + decommitments.serialize(output); + queried_values.serialize(output); + output.push((*proof_of_work).into()); + fri_proof.serialize(output); + } +} + +impl CairoSerialize for StarkProof +where + H::Hash: CairoSerialize, +{ + fn serialize(&self, output: &mut Vec) { + let Self(commitment_scheme_proof) = self; + commitment_scheme_proof.serialize(output); + } +} + +impl CairoSerialize for Option { + fn serialize(&self, output: &mut Vec) { + match self { + Some(v) => { + output.push(FieldElement::ZERO); + v.serialize(output); + } + None => output.push(FieldElement::ONE), + } + } +} + +impl CairoSerialize for [T] { + fn serialize(&self, output: &mut Vec) { + output.push(self.len().into()); + self.iter().for_each(|v| v.serialize(output)); + } +} + +impl CairoSerialize for [T; N] { + fn serialize(&self, output: &mut Vec) { + self.iter().for_each(|v| v.serialize(output)); + } +} + +impl CairoSerialize for Vec { + fn serialize(&self, output: &mut Vec) { + (**self).serialize(output); + } +} + +impl CairoSerialize for (T0, T1) { + fn serialize(&self, output: &mut Vec) { + let (v0, v1) = self; + v0.serialize(output); + v1.serialize(output); + } +} + +impl CairoSerialize for (T0, T1, T2) { + fn serialize(&self, output: &mut Vec) { + let (v0, v1, v2) = self; + v0.serialize(output); + v1.serialize(output); + v2.serialize(output); + } +} diff --git a/stwo_cairo_prover/crates/prover/Cargo.toml b/stwo_cairo_prover/crates/prover/Cargo.toml index ea5300a9..343aead4 100644 --- a/stwo_cairo_prover/crates/prover/Cargo.toml +++ b/stwo_cairo_prover/crates/prover/Cargo.toml @@ -13,14 +13,17 @@ cairo-vm.workspace = true hex.workspace = true itertools.workspace = true num-traits.workspace = true +paste.workspace = true +prover_types = { path = "../prover_types" } +rayon = { version = "1.10.0", optional = true } serde.workspace = true sonic-rs.workspace = true +starknet-ff.workspace = true +stwo_cairo_utils = { path = "../utils" } +stwo-cairo-serialize = { path = "../cairo-serialize" } stwo-prover.workspace = true thiserror.workspace = true tracing.workspace = true -paste.workspace = true -prover_types = { path = "../prover_types" } -rayon = { version = "1.10.0", optional = true } [dev-dependencies] cairo-lang-casm.workspace = true diff --git a/stwo_cairo_prover/crates/prover/src/cairo_air/air.rs b/stwo_cairo_prover/crates/prover/src/cairo_air/air.rs index 87ff25d0..3668fefe 100644 --- a/stwo_cairo_prover/crates/prover/src/cairo_air/air.rs +++ b/stwo_cairo_prover/crates/prover/src/cairo_air/air.rs @@ -2,18 +2,19 @@ use itertools::{chain, Itertools}; use num_traits::Zero; use prover_types::cpu::CasmState; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::LogupSumsExt; use stwo_prover::constraint_framework::preprocessed_columns::PreprocessedColumn; use stwo_prover::constraint_framework::{Relation, TraceLocationAllocator, PREPROCESSED_TRACE_IDX}; use stwo_prover::core::air::{Component, ComponentProver}; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::channel::Channel; +use stwo_prover::core::backend::BackendForChannel; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::fields::qm31::{SecureField, QM31}; use stwo_prover::core::fields::FieldExpOps; use stwo_prover::core::pcs::{TreeBuilder, TreeVec}; use stwo_prover::core::prover::StarkProof; -use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel; use stwo_prover::core::vcs::ops::MerkleHasher; use tracing::{span, Level}; @@ -39,10 +40,26 @@ pub struct CairoProof { pub stark_proof: StarkProof, } +impl CairoSerialize for CairoProof +where + H::Hash: CairoSerialize, +{ + fn serialize(&self, output: &mut Vec) { + let Self { + claim, + interaction_claim, + stark_proof, + } = self; + CairoSerialize::serialize(claim, output); + CairoSerialize::serialize(interaction_claim, output); + CairoSerialize::serialize(stark_proof, output); + } +} + // (Address, Id, Value) pub type PublicMemory = Vec<(u32, u32, [u32; 8])>; -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, CairoSerialize)] pub struct CairoClaim { pub public_data: PublicData, pub opcodes: OpcodeClaim, @@ -85,7 +102,7 @@ impl CairoClaim { } } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, CairoSerialize)] pub struct PublicData { pub public_memory: PublicMemory, pub initial_state: CasmState, @@ -202,10 +219,13 @@ impl CairoClaimGenerator { } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, - ) -> (CairoClaim, CairoInteractionClaimGenerator) { + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, + ) -> (CairoClaim, CairoInteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let span = span!(Level::INFO, "write opcode trace").entered(); let (opcodes_claim, opcodes_interaction_gen) = self.opcodes.write_trace( tree_builder, @@ -282,11 +302,14 @@ pub struct CairoInteractionClaimGenerator { // ... } impl CairoInteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, interaction_elements: &CairoInteractionElements, - ) -> CairoInteractionClaim { + ) -> CairoInteractionClaim + where + SimdBackend: BackendForChannel, + { let opcodes_interaction_claims = self .opcodes_interaction_gen .write_interaction_trace(tree_builder, interaction_elements); @@ -362,7 +385,7 @@ impl CairoInteractionElements { } } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, CairoSerialize)] pub struct CairoInteractionClaim { pub opcodes: OpcodeInteractionClaim, pub verify_instruction: verify_instruction::InteractionClaim, diff --git a/stwo_cairo_prover/crates/prover/src/cairo_air/debug_tools.rs b/stwo_cairo_prover/crates/prover/src/cairo_air/debug_tools.rs index bb8d7c98..088c65a0 100644 --- a/stwo_cairo_prover/crates/prover/src/cairo_air/debug_tools.rs +++ b/stwo_cairo_prover/crates/prover/src/cairo_air/debug_tools.rs @@ -7,10 +7,11 @@ use stwo_prover::constraint_framework::{ FrameworkComponent, FrameworkEval, TraceLocationAllocator, }; use stwo_prover::core::backend::simd::SimdBackend; +use stwo_prover::core::backend::BackendForChannel; +use stwo_prover::core::channel::MerkleChannel; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::CommitmentSchemeProver; use stwo_prover::core::poly::circle::CanonicCoset; -use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel; use super::air::CairoClaim; use crate::components::{ @@ -32,10 +33,13 @@ use crate::components::{ use crate::felt::split_f252; use crate::relations; -pub fn track_cairo_relations( - commitment_scheme: &CommitmentSchemeProver<'_, SimdBackend, Blake2sMerkleChannel>, +pub fn track_cairo_relations( + commitment_scheme: &CommitmentSchemeProver<'_, SimdBackend, MC>, claim: &CairoClaim, -) -> Vec { +) -> Vec +where + SimdBackend: BackendForChannel, +{ // Cairo air aggregates interpolated polynomials. Evaluate to get the original trace. // NOTE: this process is slow, and should be only used for debugging. let evals = commitment_scheme.trace().polys.map(|interaction_tree| { diff --git a/stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs b/stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs index 267ce535..a875b15d 100644 --- a/stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs +++ b/stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs @@ -8,12 +8,13 @@ use num_traits::Zero; use stwo_prover::constraint_framework::preprocessed_columns::gen_is_first; use stwo_prover::constraint_framework::relation_tracker::RelationSummary; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::channel::Blake2sChannel; +use stwo_prover::core::backend::BackendForChannel; +use stwo_prover::core::channel::MerkleChannel; use stwo_prover::core::fields::qm31::SecureField; +use stwo_prover::core::fri::FriConfig; use stwo_prover::core::pcs::{CommitmentSchemeProver, CommitmentSchemeVerifier, PcsConfig}; use stwo_prover::core::poly::circle::{CanonicCoset, PolyOps}; use stwo_prover::core::prover::{prove, verify, ProvingError, VerificationError}; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use thiserror::Error; use tracing::{span, Level}; @@ -25,14 +26,25 @@ const IS_FIRST_LOG_SIZES: [u32; 19] = [ 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, ]; -pub fn prove_cairo( +pub fn prove_cairo( input: CairoInput, // TODO(Ohad): wrap these flags in a struct. track_relations: bool, display_components: bool, -) -> Result, ProvingError> { +) -> Result, ProvingError> +where + SimdBackend: BackendForChannel, +{ let _span = span!(Level::INFO, "prove_cairo").entered(); - let config = PcsConfig::default(); + // TODO(Ohad): Propogate config from CLI args. + let config = PcsConfig { + pow_bits: 0, + fri_config: FriConfig { + log_last_layer_degree_bound: 2, + log_blowup_factor: 1, + n_queries: 15, + }, + }; let twiddles = SimdBackend::precompute_twiddles( CanonicCoset::new(LOG_MAX_ROWS + config.fri_config.log_blowup_factor + 2) .circle_domain() @@ -40,8 +52,8 @@ pub fn prove_cairo( ); // Setup protocol. - let channel = &mut Blake2sChannel::default(); - let mut commitment_scheme = CommitmentSchemeProver::new(config, &twiddles); + let channel = &mut MC::C::default(); + let mut commitment_scheme = CommitmentSchemeProver::::new(config, &twiddles); // Preprocessed trace. let mut tree_builder = commitment_scheme.tree_builder(); @@ -108,18 +120,25 @@ pub fn prove_cairo( }) } -pub fn verify_cairo( +pub fn verify_cairo( CairoProof { claim, interaction_claim, stark_proof, - }: CairoProof, + }: CairoProof, ) -> Result<(), CairoVerificationError> { // Verify. - let config = PcsConfig::default(); - let channel = &mut Blake2sChannel::default(); - let commitment_scheme_verifier = - &mut CommitmentSchemeVerifier::::new(config); + // TODO(Ohad): Propogate config from CLI args. + let config = PcsConfig { + pow_bits: 0, + fri_config: FriConfig { + log_last_layer_degree_bound: 2, + log_blowup_factor: 1, + n_queries: 15, + }, + }; + let channel = &mut MC::C::default(); + let commitment_scheme_verifier = &mut CommitmentSchemeVerifier::::new(config); let log_sizes = claim.log_sizes(); @@ -158,7 +177,13 @@ pub enum CairoVerificationError { #[cfg(test)] mod tests { + use std::io::Write; + use cairo_lang_casm::casm; + use itertools::Itertools; + use stwo_cairo_serialize::CairoSerialize; + use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel; + use stwo_prover::core::vcs::poseidon252_merkle::Poseidon252MerkleChannel; use crate::cairo_air::{prove_cairo, verify_cairo, CairoInput}; use crate::input::plain::input_from_plain_casm; @@ -190,14 +215,28 @@ mod tests { #[test] fn test_basic_cairo_air() { - let cairo_proof = prove_cairo(test_input(), true, true).unwrap(); - verify_cairo(cairo_proof).unwrap(); + let cairo_proof = prove_cairo::(test_input(), true, true).unwrap(); + verify_cairo::(cairo_proof).unwrap(); + } + + #[ignore] + #[test] + fn generate_and_serialise_proof() { + let cairo_proof = + prove_cairo::(test_input(), true, true).unwrap(); + let mut output = Vec::new(); + CairoSerialize::serialize(&cairo_proof, &mut output); + let proof_str = output.iter().map(|v| v.to_string()).join(","); + let mut file = std::fs::File::create("proof.cairo").unwrap(); + file.write_all(proof_str.as_bytes()).unwrap(); + verify_cairo::(cairo_proof).unwrap(); } #[ignore] #[test] fn test_full_cairo_air() { - let cairo_proof = prove_cairo(small_cairo_input(), true, true).unwrap(); - verify_cairo(cairo_proof).unwrap(); + let cairo_proof = + prove_cairo::(small_cairo_input(), true, true).unwrap(); + verify_cairo::(cairo_proof).unwrap(); } } diff --git a/stwo_cairo_prover/crates/prover/src/cairo_air/opcodes_air.rs b/stwo_cairo_prover/crates/prover/src/cairo_air/opcodes_air.rs index 61fa733c..5f5805e9 100644 --- a/stwo_cairo_prover/crates/prover/src/cairo_air/opcodes_air.rs +++ b/stwo_cairo_prover/crates/prover/src/cairo_air/opcodes_air.rs @@ -1,13 +1,14 @@ use itertools::{chain, Itertools}; use num_traits::Zero; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::TraceLocationAllocator; use stwo_prover::core::air::ComponentProver; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::channel::Channel; +use stwo_prover::core::backend::BackendForChannel; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::qm31::{SecureField, QM31}; use stwo_prover::core::pcs::{TreeBuilder, TreeVec}; -use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel; use super::air::CairoInteractionElements; use super::debug_tools::display_components; @@ -29,7 +30,7 @@ use crate::components::{ }; use crate::input::state_transitions::StateTransitions; -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, CairoSerialize)] pub struct OpcodeClaim { pub add_f_f: Vec, pub add_f_t: Vec, @@ -468,15 +469,18 @@ impl OpcodesClaimGenerator { } } - pub fn write_trace( + pub fn write_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_trace_generator: &mut memory_address_to_id::ClaimGenerator, memory_id_to_value_trace_generator: &mut memory_id_to_big::ClaimGenerator, range_check_19_trace_generator: &mut range_check_19::ClaimGenerator, range_check_9_9_trace_generator: &mut range_check_9_9::ClaimGenerator, verify_instruction_trace_generator: &mut verify_instruction::ClaimGenerator, - ) -> (OpcodeClaim, OpcodesInteractionClaimGenerator) { + ) -> (OpcodeClaim, OpcodesInteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let (add_f_f_claims, add_f_f_interaction_gens) = self .add_f_f .into_iter() @@ -840,7 +844,7 @@ impl OpcodesClaimGenerator { } } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, CairoSerialize)] pub struct OpcodeInteractionClaim { add_f_f: Vec, add_f_t: Vec, @@ -1106,11 +1110,14 @@ pub struct OpcodesInteractionClaimGenerator { ret_interaction_gens: Vec, } impl OpcodesInteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, interaction_elements: &CairoInteractionElements, - ) -> OpcodeInteractionClaim { + ) -> OpcodeInteractionClaim + where + SimdBackend: BackendForChannel, + { let add_f_f_interaction_claims = self .add_f_f .into_iter() diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_f/component.rs index b6c6aff7..b710de9e 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_f/prover.rs index 8be1fa3a..ca83850d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -341,14 +344,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_t/component.rs index dfcb18d5..69e13033 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_t/prover.rs index 5145ebc6..0aae4b30 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op1_base_fp_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -341,14 +344,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op1_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op1_base_fp_f/component.rs index 2db9c28c..ec8316d9 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op1_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op1_base_fp_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op1_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op1_base_fp_f/prover.rs index 90c1344c..9db83a9c 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op1_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op1_base_fp_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -325,14 +328,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/component.rs index 0862d836..88768b24 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/prover.rs index 8c0088ef..e8159ad4 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -714,14 +717,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/component.rs index e4b744b8..da741d38 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/prover.rs index 2736df75..b2958b5b 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -676,14 +679,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/component.rs index d16cf209..a2f519bd 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/prover.rs index 7e4ac5d5..b2d92182 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -588,14 +591,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/component.rs index 3ba84710..d3ff887b 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/prover.rs index e7969bb8..6accdd43 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -550,14 +553,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/component.rs index 3aed8fc2..c74eabbe 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -22,7 +23,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -44,7 +45,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/prover.rs index 2988665e..e338d03d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -353,13 +356,16 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/component.rs index 688ff73e..e3298f1d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -22,7 +23,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -44,7 +45,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/prover.rs index caaff5da..45d50b11 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -316,13 +319,16 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/component.rs index ee102cc7..8718f99f 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/prover.rs index aea3f420..0ad7c47d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -441,14 +444,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_f/component.rs index 5887f535..a1eb9dea 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_f/prover.rs index 2d80d2f6..aa24652d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -445,14 +448,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_t/component.rs index a5b61b3b..2fa10e24 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_t/prover.rs index 42f84dc8..a5f72151 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op1_base_fp_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -445,14 +448,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op1_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op1_base_fp_f/component.rs index 8a4562c1..b00056e8 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op1_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op1_base_fp_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op1_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op1_base_fp_f/prover.rs index f310e8dd..d1ec5fb4 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op1_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op1_base_fp_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -448,14 +451,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/component.rs b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/component.rs index 8410c6a2..e79dfac0 100644 --- a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -25,7 +26,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -47,7 +48,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/mod.rs b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/mod.rs index 465c814b..3f7a8d74 100644 --- a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/mod.rs +++ b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/mod.rs @@ -1,4 +1,3 @@ -#![allow(clippy::too_many_arguments)] pub mod component; pub mod prover; diff --git a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/prover.rs b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/prover.rs index 0af2b2bb..2074032c 100644 --- a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/prover.rs @@ -7,18 +7,19 @@ use prover_types::simd::*; use stwo_prover::constraint_framework::logup::LogupTraceGenerator; use stwo_prover::constraint_framework::Relation; use stwo_prover::core::air::Component; +use stwo_prover::core::backend::BackendForChannel; use stwo_prover::core::backend::{Col, Column}; use stwo_prover::core::backend::simd::column::BaseColumn; use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::pack_values; @@ -38,11 +39,14 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator,memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator,range_check_19_state: &mut range_check_19::ClaimGenerator,range_check_9_9_state: &mut range_check_9_9::ClaimGenerator,verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -1290,9 +1294,9 @@ pub struct InteractionClaimGenerator { } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: @@ -1305,7 +1309,10 @@ impl InteractionClaimGenerator { &relations::RangeCheck_9_9, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/component.rs index 2140dab3..915a0d43 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/prover.rs index ad30b83a..f0e9e516 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -394,14 +397,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/component.rs index 6587a759..9740f74c 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/prover.rs index ea676002..64704552 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -394,14 +397,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/component.rs index cbb4d0ca..a279ad69 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/prover.rs index 7e59342a..a48176ca 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -536,14 +539,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/component.rs index a8fbe610..f1f2e44a 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/prover.rs index dfe83b06..6c32743c 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -536,14 +539,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/component.rs index 80baed1d..b4e4b0c8 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/prover.rs index 526b46af..c890f5ad 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -374,14 +377,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/component.rs index c1278167..fb771537 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/prover.rs index 74b02821..b9c86250 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -447,14 +450,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/component.rs index fad95fd4..a6314bf4 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/prover.rs index 7fd67fa2..e225d714 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -391,14 +394,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/component.rs index 66f20089..df40c7a3 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/prover.rs index 304207f7..8de7ed71 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; @@ -37,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -350,14 +353,17 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/component.rs b/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/component.rs index f342c1a5..7b01cf8a 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/component.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, }; @@ -55,7 +56,7 @@ impl FrameworkEval for Eval { } } -#[derive(Clone, Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub log_size: u32, } @@ -76,7 +77,7 @@ impl Claim { } } -#[derive(Clone, Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub claimed_sum: SecureField, } diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/prover.rs b/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/prover.rs index 8e3c714f..5ec8cce7 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/prover.rs @@ -5,12 +5,12 @@ use stwo_prover::core::backend::simd::column::BaseColumn; use stwo_prover::core::backend::simd::m31::{PackedBaseField, PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedSecureField; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::MerkleChannel; use stwo_prover::core::fields::m31::{BaseField, M31}; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; -use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel; use super::component::{Claim, InteractionClaim, N_ADDR_TO_ID_COLUMNS}; use crate::components::memory::MEMORY_ADDRESS_BOUND; @@ -68,10 +68,13 @@ impl ClaimGenerator { self.multiplicities[addr] += 1; } - pub fn write_trace( + pub fn write_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, - ) -> (Claim, InteractionClaimGenerator) { + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let size = self.ids.len(); let mut trace = (0..N_ADDR_TO_ID_COLUMNS) .map(|_| Col::::zeros(size)) @@ -115,7 +118,9 @@ impl ClaimGenerator { let domain = CanonicCoset::new(log_address_bound).circle_domain(); let trace = trace .into_iter() - .map(|eval| CircleEvaluation::::new(domain, eval)) + .map(|eval| { + CircleEvaluation::::new(domain, eval) + }) .collect_vec(); tree_builder.extend_evals(trace); @@ -146,11 +151,14 @@ impl InteractionClaimGenerator { } } - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, lookup_elements: &relations::MemoryAddressToId, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = self.addresses.len().ilog2() + LOG_N_LANES; let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/memory_id_to_big/component.rs b/stwo_cairo_prover/crates/prover/src/components/memory/memory_id_to_big/component.rs index 7520e10e..a5383e76 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/memory_id_to_big/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/memory_id_to_big/component.rs @@ -1,6 +1,8 @@ use itertools::{chain, Itertools}; use num_traits::One; use serde::{Deserialize, Serialize}; +use starknet_ff::FieldElement; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, }; @@ -143,7 +145,7 @@ impl FrameworkEval for SmallEval { } } -#[derive(Clone, Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub big_log_size: u32, pub small_log_size: u32, @@ -190,3 +192,14 @@ impl InteractionClaim { channel.mix_felts(&[self.small_claimed_sum]); } } + +impl CairoSerialize for InteractionClaim { + fn serialize(&self, output: &mut Vec) { + let Self { + big_claimed_sum, + small_claimed_sum, + } = self; + CairoSerialize::serialize(big_claimed_sum, output); + CairoSerialize::serialize(small_claimed_sum, output); + } +} diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/memory_id_to_big/prover.rs b/stwo_cairo_prover/crates/prover/src/components/memory/memory_id_to_big/prover.rs index 53087462..2608d616 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/memory_id_to_big/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/memory_id_to_big/prover.rs @@ -9,12 +9,12 @@ use stwo_prover::core::backend::simd::column::BaseColumn; use stwo_prover::core::backend::simd::m31::{PackedBaseField, PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::Column; +use stwo_prover::core::backend::{BackendForChannel, Column}; +use stwo_prover::core::channel::MerkleChannel; use stwo_prover::core::fields::m31::{BaseField, M31}; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; -use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel; use super::component::{ Claim, InteractionClaim, BIG_N_ID_AND_VALUE_COLUMNS, MEMORY_ID_SIZE, N_M31_IN_SMALL_FELT252, @@ -110,11 +110,14 @@ impl ClaimGenerator { } } - pub fn write_trace( + pub fn write_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, range_check_9_9_trace_generator: &mut range_check_9_9::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let big_table_trace = gen_big_memory_trace(self.big_values, self.big_mults); let small_table_trace = gem_small_memory_trace(self.small_values, self.small_mults); @@ -143,7 +146,7 @@ impl ClaimGenerator { let trace = big_table_trace .into_iter() .map(|eval| { - CircleEvaluation::::new( + CircleEvaluation::::new( CanonicCoset::new(big_log_size).circle_domain(), eval, ) @@ -154,7 +157,7 @@ impl ClaimGenerator { let trace = small_table_trace .into_iter() .map(|eval| { - CircleEvaluation::::new( + CircleEvaluation::::new( CanonicCoset::new(small_log_size).circle_domain(), eval, ) @@ -268,12 +271,15 @@ impl InteractionClaimGenerator { } } - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, lookup_elements: &relations::MemoryIdToBig, range9_9_lookup_elements: &relations::RangeCheck_9_9, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let big_table_log_size = self.big_ids_and_values[0].len().ilog2() + LOG_N_LANES; let mut big_values_logup_gen = LogupTraceGenerator::new(big_table_log_size); let mut col_gen = big_values_logup_gen.new_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/mod.rs b/stwo_cairo_prover/crates/prover/src/components/mod.rs index 997c00f5..ade1dba8 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mod.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mod.rs @@ -1,10 +1,5 @@ -use std::array; -use std::cell::UnsafeCell; - use prover_types::simd::N_LANES; -use stwo_prover::core::backend::simd::column::BaseColumn; use stwo_prover::core::backend::simd::conversion::Pack; -use stwo_prover::core::backend::Column; pub mod add_ap_opcode_is_imm_f_op1_base_fp_f; pub mod add_ap_opcode_is_imm_f_op1_base_fp_t; @@ -52,23 +47,3 @@ pub fn pack_values(values: &[T]) -> Vec { .map(|c| T::pack(*c)) .collect() } - -// TODO(Ohad): move to another file. -struct ThreadSafeTrace { - data: [UnsafeCell; N], -} - -unsafe impl Send for ThreadSafeTrace {} -unsafe impl Sync for ThreadSafeTrace {} - -impl ThreadSafeTrace { - fn new(rows: usize) -> Self { - Self { - data: array::from_fn(|_| UnsafeCell::new(unsafe { BaseColumn::uninitialized(rows) })), - } - } - - pub fn inner(self) -> [BaseColumn; N] { - self.data.map(|c| c.into_inner()) - } -} diff --git a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/component.rs index a583dc1e..ca8fdbd1 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -24,7 +25,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -46,7 +47,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/prover.rs index 99ee271b..85e209e6 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{ @@ -39,14 +39,17 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, range_check_19_state: &mut range_check_19::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -1959,15 +1962,18 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, rangecheck_19_lookup_elements: &relations::RangeCheck_19, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/component.rs index 71647af4..dcd85301 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -24,7 +25,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -46,7 +47,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/prover.rs index 7b4b494d..8a1f090a 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/prover.rs @@ -12,13 +12,13 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; use crate::components::{ @@ -39,14 +39,17 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, range_check_19_state: &mut range_check_19::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -1920,15 +1923,18 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, rangecheck_19_lookup_elements: &relations::RangeCheck_19, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); diff --git a/stwo_cairo_prover/crates/prover/src/components/range_check_vector/component.rs b/stwo_cairo_prover/crates/prover/src/components/range_check_vector/component.rs index 97c5943e..c2a00887 100644 --- a/stwo_cairo_prover/crates/prover/src/components/range_check_vector/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/range_check_vector/component.rs @@ -3,6 +3,7 @@ macro_rules! range_check_eval{ ($($log_range:expr),+) => { paste::paste! { use serde::{Deserialize, Serialize}; + use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::{EvalAtRow, FrameworkComponent}; use stwo_prover::constraint_framework::FrameworkEval; use stwo_prover::core::channel::Channel; @@ -18,7 +19,7 @@ macro_rules! range_check_eval{ const RANGES : [u32; N_RANGES] = [$($log_range),+]; pub type Component = FrameworkComponent<[]>; - #[derive(Clone, Deserialize, Serialize)] + #[derive(Clone, Deserialize, Serialize, CairoSerialize)] pub struct Claim { pub log_ranges: Vec, } @@ -42,7 +43,7 @@ macro_rules! range_check_eval{ } } - #[derive(Clone, Copy, Serialize, Deserialize)] + #[derive(Clone, Copy, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim{ pub claimed_sum: QM31, } diff --git a/stwo_cairo_prover/crates/prover/src/components/range_check_vector/component_prover.rs b/stwo_cairo_prover/crates/prover/src/components/range_check_vector/component_prover.rs index 997feedb..44a225e1 100644 --- a/stwo_cairo_prover/crates/prover/src/components/range_check_vector/component_prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/range_check_vector/component_prover.rs @@ -9,13 +9,15 @@ macro_rules! range_check_prover { use stwo_prover::constraint_framework::logup::LogupTraceGenerator; use stwo_prover::constraint_framework::Relation; use stwo_prover::core::backend::simd::column::BaseColumn; + use stwo_prover::core::fields::m31::BaseField; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::SimdBackend; + use stwo_prover::core::backend::BackendForChannel; + use stwo_prover::core::channel::MerkleChannel; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; - use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel; use $crate::components::range_check_vector::{generate_partitioned_enumeration, partition_into_bit_segments, SIMD_ENUMERATION_0}; @@ -77,10 +79,12 @@ macro_rules! range_check_prover { }) } - pub fn write_trace( + pub fn write_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, - ) -> (Claim, InteractionClaimGenerator) { + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, { let log_size = self.log_size(); let fixed_columns = self.write_fixed_columns(); @@ -97,7 +101,7 @@ macro_rules! range_check_prover { let domain = CanonicCoset::new(log_size).circle_domain(); let trace = chain!(fixed_columns, [multiplicity_column]) .map(|col| - CircleEvaluation::::new(domain, col) + CircleEvaluation::::new(domain, col) ); tree_builder.extend_evals(trace); @@ -120,11 +124,13 @@ macro_rules! range_check_prover { pub multiplicities: Vec, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( &self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, lookup_elements: &relations::[], - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, { let log_size = RANGES.iter().sum::(); let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); @@ -174,6 +180,7 @@ mod tests { use stwo_prover::core::channel::Blake2sChannel; use stwo_prover::core::pcs::{CommitmentSchemeProver, PcsConfig}; use stwo_prover::core::poly::circle::{CanonicCoset, PolyOps}; + use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel; use crate::components::range_check_vector::{partition_into_bit_segments, range_check_7_2_5}; use crate::relations; @@ -193,7 +200,10 @@ mod tests { let channel = &mut Blake2sChannel::default(); let config = PcsConfig::default(); - let commitment_scheme = &mut CommitmentSchemeProver::new(config, &twiddles); + let commitment_scheme = + &mut CommitmentSchemeProver::::new( + config, &twiddles, + ); // Preprocessed trace. let mut tree_builder = commitment_scheme.tree_builder(); diff --git a/stwo_cairo_prover/crates/prover/src/components/ret_opcode/component.rs b/stwo_cairo_prover/crates/prover/src/components/ret_opcode/component.rs index 85d53fd1..1bb00542 100644 --- a/stwo_cairo_prover/crates/prover/src/components/ret_opcode/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/ret_opcode/component.rs @@ -2,6 +2,7 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; +use stwo_cairo_serialize::CairoSerialize; use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, @@ -23,7 +24,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub n_calls: usize, } @@ -45,7 +46,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/ret_opcode/prover.rs b/stwo_cairo_prover/crates/prover/src/components/ret_opcode/prover.rs index a956ee65..d91e155e 100644 --- a/stwo_cairo_prover/crates/prover/src/components/ret_opcode/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/ret_opcode/prover.rs @@ -1,14 +1,9 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use std::cell::UnsafeCell; -use std::sync::Arc; - use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; use prover_types::cpu::*; use prover_types::simd::*; -#[cfg(feature = "parallel")] -use rayon::prelude::*; use stwo_prover::constraint_framework::logup::LogupTraceGenerator; use stwo_prover::constraint_framework::Relation; use stwo_prover::core::air::Component; @@ -17,18 +12,16 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::{Channel, MerkleChannel}; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use stwo_prover::core::utils::bit_reverse_coset_to_circle_domain_order; -use stwo_prover::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher}; use super::component::{Claim, InteractionClaim}; -use crate::components::{ - memory_address_to_id, memory_id_to_big, pack_values, verify_instruction, ThreadSafeTrace, -}; +use crate::components::{memory_address_to_id, memory_id_to_big, pack_values, verify_instruction}; use crate::relations; pub type InputType = CasmState; @@ -44,13 +37,16 @@ impl ClaimGenerator { Self { inputs } } - pub fn write_trace( + pub fn write_trace( mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, verify_instruction_state: &mut verify_instruction::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let n_calls = self.inputs.len(); assert_ne!(n_calls, 0); let size = std::cmp::max(n_calls.next_power_of_two(), N_LANES); @@ -73,21 +69,21 @@ impl ClaimGenerator { } sub_components_inputs .memory_address_to_id_inputs - .iter_mut() + .iter() .for_each(|inputs| { - memory_address_to_id_state.add_inputs(&inputs.get_mut()[..n_calls]); + memory_address_to_id_state.add_inputs(&inputs[..n_calls]); }); sub_components_inputs .memory_id_to_big_inputs - .iter_mut() + .iter() .for_each(|inputs| { - memory_id_to_big_state.add_inputs(&inputs.get_mut()[..n_calls]); + memory_id_to_big_state.add_inputs(&inputs[..n_calls]); }); sub_components_inputs .verify_instruction_inputs - .iter_mut() + .iter() .for_each(|inputs| { - verify_instruction_state.add_inputs(&inputs.get_mut()[..n_calls]); + verify_instruction_state.add_inputs(&inputs[..n_calls]); }); tree_builder.extend_evals( @@ -120,64 +116,36 @@ impl ClaimGenerator { } pub struct SubComponentInputs { - pub memory_address_to_id_inputs: [UnsafeCell>; 2], - pub memory_id_to_big_inputs: [UnsafeCell>; 2], - pub verify_instruction_inputs: [UnsafeCell>; 1], + pub memory_address_to_id_inputs: [Vec; 2], + pub memory_id_to_big_inputs: [Vec; 2], + pub verify_instruction_inputs: [Vec; 1], } - impl SubComponentInputs { #[allow(unused_variables)] - unsafe fn uninitialized(len: usize) -> Self { - let sub_component_inputs = Self { + fn with_capacity(capacity: usize) -> Self { + Self { memory_address_to_id_inputs: [ - Vec::with_capacity(len).into(), - Vec::with_capacity(len).into(), - ], - memory_id_to_big_inputs: [ - Vec::with_capacity(len).into(), - Vec::with_capacity(len).into(), + Vec::with_capacity(capacity), + Vec::with_capacity(capacity), ], - verify_instruction_inputs: [Vec::with_capacity(len).into()], - }; - unsafe { - sub_component_inputs - .memory_address_to_id_inputs - .iter() - .for_each(|vec| { - (*vec.get()).set_len(len); - }); - sub_component_inputs - .memory_id_to_big_inputs - .iter() - .for_each(|vec| { - (*vec.get()).set_len(len); - }); - sub_component_inputs - .verify_instruction_inputs - .iter() - .for_each(|vec| { - (*vec.get()).set_len(len); - }); + memory_id_to_big_inputs: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], + verify_instruction_inputs: [Vec::with_capacity(capacity)], } - sub_component_inputs } fn bit_reverse_coset_to_circle_domain_order(&mut self) { self.memory_address_to_id_inputs .iter_mut() - .for_each(|vec| bit_reverse_coset_to_circle_domain_order(vec.get_mut())); + .for_each(|vec| bit_reverse_coset_to_circle_domain_order(vec)); self.memory_id_to_big_inputs .iter_mut() - .for_each(|vec| bit_reverse_coset_to_circle_domain_order(vec.get_mut())); + .for_each(|vec| bit_reverse_coset_to_circle_domain_order(vec)); self.verify_instruction_inputs .iter_mut() - .for_each(|vec| bit_reverse_coset_to_circle_domain_order(vec.get_mut())); + .for_each(|vec| bit_reverse_coset_to_circle_domain_order(vec)); } } -unsafe impl Send for SubComponentInputs {} -unsafe impl Sync for SubComponentInputs {} - #[allow(clippy::useless_conversion)] #[allow(unused_variables)] #[allow(clippy::double_parens)] @@ -192,11 +160,12 @@ pub fn write_trace_simd( LookupData, ) { const N_TRACE_COLUMNS: usize = 11; - let len = inputs.len(); - let cpu_len = len * N_LANES; - let trace = Arc::new(ThreadSafeTrace::::new(cpu_len)); - let lookup_data = Arc::new(unsafe { LookupData::uninitialized(len) }); - let sub_components_inputs = Arc::new(unsafe { SubComponentInputs::uninitialized(cpu_len) }); + let mut trace: [_; N_TRACE_COLUMNS] = + std::array::from_fn(|_| Col::::zeros(inputs.len() * N_LANES)); + + let mut lookup_data = LookupData::with_capacity(inputs.len()); + #[allow(unused_mut)] + let mut sub_components_inputs = SubComponentInputs::with_capacity(inputs.len()); let M31_0 = PackedM31::broadcast(M31::from(0)); let M31_1 = PackedM31::broadcast(M31::from(1)); @@ -206,44 +175,38 @@ pub fn write_trace_simd( let M31_32767 = PackedM31::broadcast(M31::from(32767)); let M31_512 = PackedM31::broadcast(M31::from(512)); - #[cfg(not(feature = "parallel"))] - let iter = inputs.into_iter().enumerate(); - - #[cfg(feature = "parallel")] - let iter = inputs.into_par_iter().enumerate(); - - iter.for_each(|(row_index, ret_opcode_input)| { - unsafe { - let input_tmp_1655 = ret_opcode_input; - let input_pc_col0 = input_tmp_1655.pc; - (*trace.data[0].get()).data[row_index] = input_pc_col0; - let input_ap_col1 = input_tmp_1655.ap; - (*trace.data[1].get()).data[row_index] = input_ap_col1; - let input_fp_col2 = input_tmp_1655.fp; - (*trace.data[2].get()).data[row_index] = input_fp_col2; - - // decode_instruction_c94bba24192ecf68. - - let memory_address_to_id_value_tmp_1659 = + inputs + .into_iter() + .enumerate() + .for_each(|(row_index, ret_opcode_input)| { + let input_tmp_e23a_0 = ret_opcode_input; + let input_pc_col0 = input_tmp_e23a_0.pc; + trace[0].data[row_index] = input_pc_col0; + let input_ap_col1 = input_tmp_e23a_0.ap; + trace[1].data[row_index] = input_ap_col1; + let input_fp_col2 = input_tmp_e23a_0.fp; + trace[2].data[row_index] = input_fp_col2; + + // DecodeInstruction_c94bba24192ecf68. + + let memoryaddresstoid_value_tmp_e23a_1 = memory_address_to_id_state.deduce_output(input_pc_col0); - let memory_id_to_big_value_tmp_1660 = - memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_1659); - - (*sub_components_inputs.verify_instruction_inputs[0].get()) - [row_index * N_LANES..(row_index + 1) * N_LANES] - .copy_from_slice( - &( - input_pc_col0, - [M31_32766, M31_32767, M31_32767], - [ - M31_1, M31_1, M31_0, M31_1, M31_0, M31_0, M31_0, M31_1, M31_0, M31_0, - M31_0, M31_0, M31_0, M31_1, M31_0, - ], - ) - .unpack(), - ); - - (*lookup_data.verifyinstruction[0].get())[row_index] = ([ + let memoryidtobig_value_tmp_e23a_2 = + memory_id_to_big_state.deduce_output(memoryaddresstoid_value_tmp_e23a_1); + + sub_components_inputs.verify_instruction_inputs[0].extend( + ( + input_pc_col0, + [M31_32766, M31_32767, M31_32767], + [ + M31_1, M31_1, M31_0, M31_1, M31_0, M31_0, M31_0, M31_1, M31_0, M31_0, + M31_0, M31_0, M31_0, M31_1, M31_0, + ], + ) + .unpack(), + ); + + lookup_data.verifyinstruction[0].push([ input_pc_col0, M31_32766, M31_32767, @@ -265,31 +228,27 @@ pub fn write_trace_simd( M31_0, ]); - // read_positive_num_bits_27. + // ReadPositive_num_bits_27. - let memory_address_to_id_value_tmp_1662 = + let memoryaddresstoid_value_tmp_e23a_3 = memory_address_to_id_state.deduce_output(((input_fp_col2) - (M31_1))); - let memory_id_to_big_value_tmp_1663 = - memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_1662); - let next_pc_id_col3 = memory_address_to_id_value_tmp_1662; - (*trace.data[3].get()).data[row_index] = next_pc_id_col3; - (*sub_components_inputs.memory_address_to_id_inputs[0].get()) - [row_index * N_LANES..(row_index + 1) * N_LANES] - .copy_from_slice(&((input_fp_col2) - (M31_1)).unpack()); - - (*lookup_data.memoryaddresstoid[0].get())[row_index] = - ([((input_fp_col2) - (M31_1)), next_pc_id_col3]); - let next_pc_limb_0_col4 = memory_id_to_big_value_tmp_1663.get_m31(0); - (*trace.data[4].get()).data[row_index] = next_pc_limb_0_col4; - let next_pc_limb_1_col5 = memory_id_to_big_value_tmp_1663.get_m31(1); - (*trace.data[5].get()).data[row_index] = next_pc_limb_1_col5; - let next_pc_limb_2_col6 = memory_id_to_big_value_tmp_1663.get_m31(2); - (*trace.data[6].get()).data[row_index] = next_pc_limb_2_col6; - (*sub_components_inputs.memory_id_to_big_inputs[0].get()) - [row_index * N_LANES..(row_index + 1) * N_LANES] - .copy_from_slice(&next_pc_id_col3.unpack()); - - (*lookup_data.memoryidtobig[0].get())[row_index] = ([ + let memoryidtobig_value_tmp_e23a_4 = + memory_id_to_big_state.deduce_output(memoryaddresstoid_value_tmp_e23a_3); + let next_pc_id_col3 = memoryaddresstoid_value_tmp_e23a_3; + trace[3].data[row_index] = next_pc_id_col3; + sub_components_inputs.memory_address_to_id_inputs[0] + .extend(((input_fp_col2) - (M31_1)).unpack()); + + lookup_data.memoryaddresstoid[0].push([((input_fp_col2) - (M31_1)), next_pc_id_col3]); + let next_pc_limb_0_col4 = memoryidtobig_value_tmp_e23a_4.get_m31(0); + trace[4].data[row_index] = next_pc_limb_0_col4; + let next_pc_limb_1_col5 = memoryidtobig_value_tmp_e23a_4.get_m31(1); + trace[5].data[row_index] = next_pc_limb_1_col5; + let next_pc_limb_2_col6 = memoryidtobig_value_tmp_e23a_4.get_m31(2); + trace[6].data[row_index] = next_pc_limb_2_col6; + sub_components_inputs.memory_id_to_big_inputs[0].extend(next_pc_id_col3.unpack()); + + lookup_data.memoryidtobig[0].push([ next_pc_id_col3, next_pc_limb_0_col4, next_pc_limb_1_col5, @@ -321,31 +280,27 @@ pub fn write_trace_simd( M31_0, ]); - // read_positive_num_bits_27. + // ReadPositive_num_bits_27. - let memory_address_to_id_value_tmp_1664 = + let memoryaddresstoid_value_tmp_e23a_5 = memory_address_to_id_state.deduce_output(((input_fp_col2) - (M31_2))); - let memory_id_to_big_value_tmp_1665 = - memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_1664); - let next_fp_id_col7 = memory_address_to_id_value_tmp_1664; - (*trace.data[7].get()).data[row_index] = next_fp_id_col7; - (*sub_components_inputs.memory_address_to_id_inputs[1].get()) - [row_index * N_LANES..(row_index + 1) * N_LANES] - .copy_from_slice(&((input_fp_col2) - (M31_2)).unpack()); - - (*lookup_data.memoryaddresstoid[1].get())[row_index] = - ([((input_fp_col2) - (M31_2)), next_fp_id_col7]); - let next_fp_limb_0_col8 = memory_id_to_big_value_tmp_1665.get_m31(0); - (*trace.data[8].get()).data[row_index] = next_fp_limb_0_col8; - let next_fp_limb_1_col9 = memory_id_to_big_value_tmp_1665.get_m31(1); - (*trace.data[9].get()).data[row_index] = next_fp_limb_1_col9; - let next_fp_limb_2_col10 = memory_id_to_big_value_tmp_1665.get_m31(2); - (*trace.data[10].get()).data[row_index] = next_fp_limb_2_col10; - (*sub_components_inputs.memory_id_to_big_inputs[1].get()) - [row_index * N_LANES..(row_index + 1) * N_LANES] - .copy_from_slice(&next_fp_id_col7.unpack()); - - (*lookup_data.memoryidtobig[1].get())[row_index] = [ + let memoryidtobig_value_tmp_e23a_6 = + memory_id_to_big_state.deduce_output(memoryaddresstoid_value_tmp_e23a_5); + let next_fp_id_col7 = memoryaddresstoid_value_tmp_e23a_5; + trace[7].data[row_index] = next_fp_id_col7; + sub_components_inputs.memory_address_to_id_inputs[1] + .extend(((input_fp_col2) - (M31_2)).unpack()); + + lookup_data.memoryaddresstoid[1].push([((input_fp_col2) - (M31_2)), next_fp_id_col7]); + let next_fp_limb_0_col8 = memoryidtobig_value_tmp_e23a_6.get_m31(0); + trace[8].data[row_index] = next_fp_limb_0_col8; + let next_fp_limb_1_col9 = memoryidtobig_value_tmp_e23a_6.get_m31(1); + trace[9].data[row_index] = next_fp_limb_1_col9; + let next_fp_limb_2_col10 = memoryidtobig_value_tmp_e23a_6.get_m31(2); + trace[10].data[row_index] = next_fp_limb_2_col10; + sub_components_inputs.memory_id_to_big_inputs[1].extend(next_fp_id_col7.unpack()); + + lookup_data.memoryidtobig[1].push([ next_fp_id_col7, next_fp_limb_0_col8, next_fp_limb_1_col9, @@ -375,147 +330,109 @@ pub fn write_trace_simd( M31_0, M31_0, M31_0, - ]; + ]); - (*lookup_data.opcodes[0].get())[row_index] = - ([input_pc_col0, input_ap_col1, input_fp_col2]); - (*lookup_data.opcodes[1].get())[row_index] = ([ + lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes[1].push([ (((next_pc_limb_0_col4) + ((next_pc_limb_1_col5) * (M31_512))) + ((next_pc_limb_2_col6) * (M31_262144))), input_ap_col1, (((next_fp_limb_0_col8) + ((next_fp_limb_1_col9) * (M31_512))) + ((next_fp_limb_2_col10) * (M31_262144))), ]); - } - }); - - let trace = match Arc::try_unwrap(trace) { - Ok(trace) => trace.inner(), - Err(_) => panic!("could not unwrap trace"), - }; - let sub_components_inputs = match Arc::try_unwrap(sub_components_inputs) { - Ok(sub_components_inputs) => sub_components_inputs, - Err(_) => panic!("could not unwrap sub_components_inputs"), - }; - let lookup_data = match Arc::try_unwrap(lookup_data) { - Ok(lookup_data) => lookup_data, - Err(_) => panic!("could not unwrap lookup_data"), - }; + }); + (trace, sub_components_inputs, lookup_data) } pub struct LookupData { - pub memoryaddresstoid: [UnsafeCell>; 2], - pub memoryidtobig: [UnsafeCell>; 2], - pub opcodes: [UnsafeCell>; 2], - pub verifyinstruction: [UnsafeCell>; 1], + pub memoryaddresstoid: [Vec<[PackedM31; 2]>; 2], + pub memoryidtobig: [Vec<[PackedM31; 29]>; 2], + pub opcodes: [Vec<[PackedM31; 3]>; 2], + pub verifyinstruction: [Vec<[PackedM31; 19]>; 1], } impl LookupData { #[allow(unused_variables)] - unsafe fn uninitialized(len: usize) -> Self { - let lookup_data = Self { - memoryaddresstoid: [ - Vec::with_capacity(len).into(), - Vec::with_capacity(len).into(), - ], - memoryidtobig: [ - Vec::with_capacity(len).into(), - Vec::with_capacity(len).into(), - ], - opcodes: [ - Vec::with_capacity(len).into(), - Vec::with_capacity(len).into(), - ], - verifyinstruction: [Vec::with_capacity(len).into()], - }; - unsafe { - lookup_data.memoryaddresstoid.iter().for_each(|vec| { - (*vec.get()).set_len(len); - }); - lookup_data.memoryidtobig.iter().for_each(|vec| { - (*vec.get()).set_len(len); - }); - lookup_data.opcodes.iter().for_each(|vec| { - (*vec.get()).set_len(len); - }); - lookup_data.verifyinstruction.iter().for_each(|vec| { - (*vec.get()).set_len(len); - }); + fn with_capacity(capacity: usize) -> Self { + Self { + memoryaddresstoid: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], + memoryidtobig: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], + opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], + verifyinstruction: [Vec::with_capacity(capacity)], } - - lookup_data } } -unsafe impl Send for LookupData {} -unsafe impl Sync for LookupData {} pub struct InteractionClaimGenerator { pub n_calls: usize, pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( - mut self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + pub fn write_interaction_trace( + self, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, opcodes_lookup_elements: &relations::Opcodes, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &mut self.lookup_data.verifyinstruction[0]; - for (i, lookup_values) in lookup_row.get_mut().iter().enumerate() { + let lookup_row = &self.lookup_data.verifyinstruction[0]; + for (i, lookup_values) in lookup_row.iter().enumerate() { let denom = verifyinstruction_lookup_elements.combine(lookup_values); col_gen.write_frac(i, PackedQM31::one(), denom); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &mut self.lookup_data.memoryaddresstoid[0]; - for (i, lookup_values) in lookup_row.get_mut().iter().enumerate() { + let lookup_row = &self.lookup_data.memoryaddresstoid[0]; + for (i, lookup_values) in lookup_row.iter().enumerate() { let denom = memoryaddresstoid_lookup_elements.combine(lookup_values); col_gen.write_frac(i, PackedQM31::one(), denom); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &mut self.lookup_data.memoryidtobig[0]; - for (i, lookup_values) in lookup_row.get_mut().iter().enumerate() { + let lookup_row = &self.lookup_data.memoryidtobig[0]; + for (i, lookup_values) in lookup_row.iter().enumerate() { let denom = memoryidtobig_lookup_elements.combine(lookup_values); col_gen.write_frac(i, PackedQM31::one(), denom); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &mut self.lookup_data.memoryaddresstoid[1]; - for (i, lookup_values) in lookup_row.get_mut().iter().enumerate() { + let lookup_row = &self.lookup_data.memoryaddresstoid[1]; + for (i, lookup_values) in lookup_row.iter().enumerate() { let denom = memoryaddresstoid_lookup_elements.combine(lookup_values); col_gen.write_frac(i, PackedQM31::one(), denom); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &mut self.lookup_data.memoryidtobig[1]; - for (i, lookup_values) in lookup_row.get_mut().iter().enumerate() { + let lookup_row = &self.lookup_data.memoryidtobig[1]; + for (i, lookup_values) in lookup_row.iter().enumerate() { let denom = memoryidtobig_lookup_elements.combine(lookup_values); col_gen.write_frac(i, PackedQM31::one(), denom); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &mut self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.get_mut().iter().enumerate() { + let lookup_row = &self.lookup_data.opcodes[0]; + for (i, lookup_values) in lookup_row.iter().enumerate() { let denom = opcodes_lookup_elements.combine(lookup_values); col_gen.write_frac(i, PackedQM31::one(), denom); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &mut self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.get_mut().iter().enumerate() { + let lookup_row = &self.lookup_data.opcodes[1]; + for (i, lookup_values) in lookup_row.iter().enumerate() { let denom = opcodes_lookup_elements.combine(lookup_values); col_gen.write_frac(i, -PackedQM31::one(), denom); } diff --git a/stwo_cairo_prover/crates/prover/src/components/verify_instruction/component.rs b/stwo_cairo_prover/crates/prover/src/components/verify_instruction/component.rs index df9471f3..55837bce 100644 --- a/stwo_cairo_prover/crates/prover/src/components/verify_instruction/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/verify_instruction/component.rs @@ -2,7 +2,12 @@ #![allow(unused_imports)] use num_traits::{One, Zero}; use serde::{Deserialize, Serialize}; -use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements}; +use starknet_ff::FieldElement; +use stwo_cairo_serialize::CairoSerialize; +use stwo_prover::constraint_framework::logup::{ + ClaimedPrefixSum, LogupAtRow, LogupSums, LookupElements, +}; +use stwo_prover::constraint_framework::preprocessed_columns::PreprocessedColumn; use stwo_prover::constraint_framework::{ EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry, }; @@ -24,7 +29,7 @@ pub struct Eval { pub verifyinstruction_lookup_elements: relations::VerifyInstruction, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct Claim { pub log_size: u32, } @@ -45,7 +50,7 @@ impl Claim { } } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize)] pub struct InteractionClaim { pub logup_sums: LogupSums, } diff --git a/stwo_cairo_prover/crates/prover/src/components/verify_instruction/prover.rs b/stwo_cairo_prover/crates/prover/src/components/verify_instruction/prover.rs index 44c33f5b..758c3c87 100644 --- a/stwo_cairo_prover/crates/prover/src/components/verify_instruction/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/verify_instruction/prover.rs @@ -16,7 +16,8 @@ use stwo_prover::core::backend::simd::conversion::Unpack; use stwo_prover::core::backend::simd::m31::{PackedM31, LOG_N_LANES, N_LANES}; use stwo_prover::core::backend::simd::qm31::PackedQM31; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::{Col, Column}; +use stwo_prover::core::backend::{BackendForChannel, Col, Column}; +use stwo_prover::core::channel::MerkleChannel; use stwo_prover::core::fields::m31::M31; use stwo_prover::core::pcs::TreeBuilder; use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; @@ -40,14 +41,17 @@ pub struct ClaimGenerator { pub inputs: BTreeMap, } impl ClaimGenerator { - pub fn write_trace( + pub fn write_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memory_address_to_id_state: &mut memory_address_to_id::ClaimGenerator, memory_id_to_big_state: &mut memory_id_to_big::ClaimGenerator, range_check_4_3_state: &mut range_check_4_3::ClaimGenerator, range_check_7_2_5_state: &mut range_check_7_2_5::ClaimGenerator, - ) -> (Claim, InteractionClaimGenerator) { + ) -> (Claim, InteractionClaimGenerator) + where + SimdBackend: BackendForChannel, + { let (mut inputs, mut mults) = self.inputs.into_iter().unzip::<_, _, Vec<_>, Vec<_>>(); let n_calls = inputs.len(); assert_ne!(n_calls, 0); @@ -406,15 +410,18 @@ pub struct InteractionClaimGenerator { pub lookup_data: LookupData, } impl InteractionClaimGenerator { - pub fn write_interaction_trace( + pub fn write_interaction_trace( self, - tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, Blake2sMerkleChannel>, + tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, memoryaddresstoid_lookup_elements: &relations::MemoryAddressToId, memoryidtobig_lookup_elements: &relations::MemoryIdToBig, rangecheck_4_3_lookup_elements: &relations::RangeCheck_4_3, rangecheck_7_2_5_lookup_elements: &relations::RangeCheck_7_2_5, verifyinstruction_lookup_elements: &relations::VerifyInstruction, - ) -> InteractionClaim { + ) -> InteractionClaim + where + SimdBackend: BackendForChannel, + { let mut logup_gen = LogupTraceGenerator::new(self.log_size); let mut col_gen = logup_gen.new_col(); diff --git a/stwo_cairo_prover/crates/prover_types/Cargo.toml b/stwo_cairo_prover/crates/prover_types/Cargo.toml index 5caf0459..b68673bd 100644 --- a/stwo_cairo_prover/crates/prover_types/Cargo.toml +++ b/stwo_cairo_prover/crates/prover_types/Cargo.toml @@ -4,13 +4,15 @@ version = "0.1.0" edition = "2021" [dependencies] -stwo-prover.workspace = true -starknet-ff.workspace = true -ruint.workspace = true -serde.workspace = true -itertools.workspace = true bytemuck.workspace = true +itertools.workspace = true num-traits.workspace = true +ruint.workspace = true +serde.workspace = true +starknet-ff.workspace = true +stwo_cairo_utils = { path = "../utils" } +stwo-cairo-serialize = { path = "../cairo-serialize" } +stwo-prover.workspace = true [dev-dependencies] rand.workspace = true diff --git a/stwo_cairo_prover/crates/prover_types/src/cpu.rs b/stwo_cairo_prover/crates/prover_types/src/cpu.rs index 40e879fb..e29a40f0 100644 --- a/stwo_cairo_prover/crates/prover_types/src/cpu.rs +++ b/stwo_cairo_prover/crates/prover_types/src/cpu.rs @@ -4,6 +4,7 @@ use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Not, Rem, Shl, Shr, Sub}; use ruint::Uint; use serde::{Deserialize, Serialize}; use starknet_ff::FieldElement; +use stwo_cairo_serialize::CairoSerialize; pub type M31 = stwo_prover::core::fields::m31::M31; @@ -42,7 +43,9 @@ impl ProverType for M31 { } } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default, Eq, PartialEq, Hash)] +#[derive( + Copy, Clone, Debug, Serialize, Deserialize, Default, Eq, PartialEq, Hash, CairoSerialize, +)] pub struct CasmState { pub pc: M31, pub ap: M31,