diff --git a/evm_arithmetization/src/arithmetic/arithmetic_stark.rs b/evm_arithmetization/src/arithmetic/arithmetic_stark.rs index d0712a3bc..2b7eb2507 100644 --- a/evm_arithmetization/src/arithmetic/arithmetic_stark.rs +++ b/evm_arithmetization/src/arithmetic/arithmetic_stark.rs @@ -191,7 +191,8 @@ impl ArithmeticStark { } impl, const D: usize> Stark for ArithmeticStark { - type EvaluationFrame = EvmStarkFrame + type EvaluationFrame + = EvmStarkFrame where FE: FieldExtension, P: PackedField; diff --git a/evm_arithmetization/src/byte_packing/byte_packing_stark.rs b/evm_arithmetization/src/byte_packing/byte_packing_stark.rs index 018c23e14..af62a5079 100644 --- a/evm_arithmetization/src/byte_packing/byte_packing_stark.rs +++ b/evm_arithmetization/src/byte_packing/byte_packing_stark.rs @@ -285,7 +285,8 @@ impl, const D: usize> BytePackingStark { } impl, const D: usize> Stark for BytePackingStark { - type EvaluationFrame = EvmStarkFrame + type EvaluationFrame + = EvmStarkFrame where FE: FieldExtension, P: PackedField; diff --git a/evm_arithmetization/src/cpu/cpu_stark.rs b/evm_arithmetization/src/cpu/cpu_stark.rs index 386f89519..a0dd45e1e 100644 --- a/evm_arithmetization/src/cpu/cpu_stark.rs +++ b/evm_arithmetization/src/cpu/cpu_stark.rs @@ -581,7 +581,8 @@ pub(crate) struct CpuStark { } impl, const D: usize> Stark for CpuStark { - type EvaluationFrame = EvmStarkFrame + type EvaluationFrame + = EvmStarkFrame where FE: FieldExtension, P: PackedField; diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 7f3842826..cb3cec8a8 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -697,77 +697,30 @@ where // Sanity check on the provided config assert_eq!(DEFAULT_CAP_LEN, 1 << stark_config.fri_config.cap_height); - let arithmetic = RecursiveCircuitsForTable::new( - Table::Arithmetic, - &all_stark.arithmetic_stark, - degree_bits_ranges[*Table::Arithmetic].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); - let byte_packing = RecursiveCircuitsForTable::new( - Table::BytePacking, - &all_stark.byte_packing_stark, - degree_bits_ranges[*Table::BytePacking].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); - let cpu = RecursiveCircuitsForTable::new( - Table::Cpu, - &all_stark.cpu_stark, - degree_bits_ranges[*Table::Cpu].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); - let keccak = RecursiveCircuitsForTable::new( - Table::Keccak, - &all_stark.keccak_stark, - degree_bits_ranges[*Table::Keccak].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); - let keccak_sponge = RecursiveCircuitsForTable::new( - Table::KeccakSponge, - &all_stark.keccak_sponge_stark, - degree_bits_ranges[*Table::KeccakSponge].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); - let logic = RecursiveCircuitsForTable::new( - Table::Logic, - &all_stark.logic_stark, - degree_bits_ranges[*Table::Logic].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); - let memory = RecursiveCircuitsForTable::new( - Table::Memory, - &all_stark.memory_stark, - degree_bits_ranges[*Table::Memory].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); - let mem_before = RecursiveCircuitsForTable::new( - Table::MemBefore, - &all_stark.mem_before_stark, - degree_bits_ranges[*Table::MemBefore].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); - let mem_after = RecursiveCircuitsForTable::new( - Table::MemAfter, - &all_stark.mem_after_stark, - degree_bits_ranges[*Table::MemAfter].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); + macro_rules! create_recursive_circuit { + ($table_enum:expr, $stark_field:ident) => { + RecursiveCircuitsForTable::new( + $table_enum, + &all_stark.$stark_field, + degree_bits_ranges[*$table_enum].clone(), + &all_stark.cross_table_lookups, + stark_config, + ) + }; + } + + let arithmetic = create_recursive_circuit!(Table::Arithmetic, arithmetic_stark); + let byte_packing = create_recursive_circuit!(Table::BytePacking, byte_packing_stark); + let cpu = create_recursive_circuit!(Table::Cpu, cpu_stark); + let keccak = create_recursive_circuit!(Table::Keccak, keccak_stark); + let keccak_sponge = create_recursive_circuit!(Table::KeccakSponge, keccak_sponge_stark); + let logic = create_recursive_circuit!(Table::Logic, logic_stark); + let memory = create_recursive_circuit!(Table::Memory, memory_stark); + let mem_before = create_recursive_circuit!(Table::MemBefore, mem_before_stark); + let mem_after = create_recursive_circuit!(Table::MemAfter, mem_after_stark); + #[cfg(feature = "cdk_erigon")] - let poseidon = RecursiveCircuitsForTable::new( - Table::Poseidon, - &all_stark.poseidon_stark, - degree_bits_ranges[*Table::Poseidon].clone(), - &all_stark.cross_table_lookups, - stark_config, - ); + let poseidon = create_recursive_circuit!(Table::Poseidon, poseidon_stark); let by_table = [ arithmetic, @@ -782,6 +735,7 @@ where #[cfg(feature = "cdk_erigon")] poseidon, ]; + let root = Self::create_segment_circuit(&by_table, stark_config); let segment_aggregation = Self::create_segment_aggregation_circuit(&root); let txn_aggregation = @@ -789,6 +743,7 @@ where let block = Self::create_block_circuit(&txn_aggregation); let block_wrapper = Self::create_block_wrapper_circuit(&block); let two_to_one_block = Self::create_two_to_one_block_circuit(&block_wrapper); + Self { root, segment_aggregation, diff --git a/evm_arithmetization/src/keccak/keccak_stark.rs b/evm_arithmetization/src/keccak/keccak_stark.rs index 5f505cf06..0a086d03d 100644 --- a/evm_arithmetization/src/keccak/keccak_stark.rs +++ b/evm_arithmetization/src/keccak/keccak_stark.rs @@ -255,7 +255,8 @@ impl, const D: usize> KeccakStark { } impl, const D: usize> Stark for KeccakStark { - type EvaluationFrame = EvmStarkFrame + type EvaluationFrame + = EvmStarkFrame where FE: FieldExtension, P: PackedField; diff --git a/evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs b/evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs index b517117a3..26cc76431 100644 --- a/evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs +++ b/evm_arithmetization/src/keccak_sponge/keccak_sponge_stark.rs @@ -534,7 +534,8 @@ impl, const D: usize> KeccakSpongeStark { } impl, const D: usize> Stark for KeccakSpongeStark { - type EvaluationFrame = EvmStarkFrame + type EvaluationFrame + = EvmStarkFrame where FE: FieldExtension, P: PackedField; diff --git a/evm_arithmetization/src/logic.rs b/evm_arithmetization/src/logic.rs index eae7c972b..0ba378b52 100644 --- a/evm_arithmetization/src/logic.rs +++ b/evm_arithmetization/src/logic.rs @@ -237,7 +237,8 @@ impl LogicStark { } impl, const D: usize> Stark for LogicStark { - type EvaluationFrame = EvmStarkFrame + type EvaluationFrame + = EvmStarkFrame where FE: FieldExtension, P: PackedField; diff --git a/evm_arithmetization/src/memory/memory_stark.rs b/evm_arithmetization/src/memory/memory_stark.rs index e58a85a26..357e72095 100644 --- a/evm_arithmetization/src/memory/memory_stark.rs +++ b/evm_arithmetization/src/memory/memory_stark.rs @@ -463,7 +463,8 @@ impl, const D: usize> MemoryStark { } impl, const D: usize> Stark for MemoryStark { - type EvaluationFrame = EvmStarkFrame + type EvaluationFrame + = EvmStarkFrame where FE: FieldExtension, P: PackedField; diff --git a/evm_arithmetization/src/memory_continuation/memory_continuation_stark.rs b/evm_arithmetization/src/memory_continuation/memory_continuation_stark.rs index 72c869b61..107c8dd5d 100644 --- a/evm_arithmetization/src/memory_continuation/memory_continuation_stark.rs +++ b/evm_arithmetization/src/memory_continuation/memory_continuation_stark.rs @@ -99,7 +99,8 @@ impl, const D: usize> MemoryContinuationStark } impl, const D: usize> Stark for MemoryContinuationStark { - type EvaluationFrame = EvmStarkFrame + type EvaluationFrame + = EvmStarkFrame where FE: FieldExtension, P: PackedField; diff --git a/evm_arithmetization/src/poseidon/poseidon_stark.rs b/evm_arithmetization/src/poseidon/poseidon_stark.rs index 0aacbaa50..ae6f485fb 100644 --- a/evm_arithmetization/src/poseidon/poseidon_stark.rs +++ b/evm_arithmetization/src/poseidon/poseidon_stark.rs @@ -427,10 +427,11 @@ impl, const D: usize> PoseidonStark { } impl, const D: usize> Stark for PoseidonStark { - type EvaluationFrame = EvmStarkFrame - where - FE: FieldExtension, - P: PackedField; + type EvaluationFrame + = EvmStarkFrame + where + FE: FieldExtension, + P: PackedField; type EvaluationFrameTarget = EvmStarkFrame, ExtensionTarget, NUM_COLUMNS>; diff --git a/evm_arithmetization/src/prover.rs b/evm_arithmetization/src/prover.rs index 0cd825e87..079fe3469 100644 --- a/evm_arithmetization/src/prover.rs +++ b/evm_arithmetization/src/prover.rs @@ -239,157 +239,38 @@ where F: RichField + Extendable, C: GenericConfig, { - let (arithmetic_proof, _) = timed!( - timing, - "prove Arithmetic STARK", - prove_single_table( - &all_stark.arithmetic_stark, - config, - &trace_poly_values[*Table::Arithmetic], - &trace_commitments[*Table::Arithmetic], - &ctl_data_per_table[*Table::Arithmetic], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); - let (byte_packing_proof, _) = timed!( - timing, - "prove byte packing STARK", - prove_single_table( - &all_stark.byte_packing_stark, - config, - &trace_poly_values[*Table::BytePacking], - &trace_commitments[*Table::BytePacking], - &ctl_data_per_table[*Table::BytePacking], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); - let (cpu_proof, _) = timed!( - timing, - "prove CPU STARK", - prove_single_table( - &all_stark.cpu_stark, - config, - &trace_poly_values[*Table::Cpu], - &trace_commitments[*Table::Cpu], - &ctl_data_per_table[*Table::Cpu], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); - let (keccak_proof, _) = timed!( - timing, - "prove Keccak STARK", - prove_single_table( - &all_stark.keccak_stark, - config, - &trace_poly_values[*Table::Keccak], - &trace_commitments[*Table::Keccak], - &ctl_data_per_table[*Table::Keccak], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); - let (keccak_sponge_proof, _) = timed!( - timing, - "prove Keccak sponge STARK", - prove_single_table( - &all_stark.keccak_sponge_stark, - config, - &trace_poly_values[*Table::KeccakSponge], - &trace_commitments[*Table::KeccakSponge], - &ctl_data_per_table[*Table::KeccakSponge], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); - let (logic_proof, _) = timed!( - timing, - "prove logic STARK", - prove_single_table( - &all_stark.logic_stark, - config, - &trace_poly_values[*Table::Logic], - &trace_commitments[*Table::Logic], - &ctl_data_per_table[*Table::Logic], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); - let (memory_proof, _) = timed!( - timing, - "prove memory STARK", - prove_single_table( - &all_stark.memory_stark, - config, - &trace_poly_values[*Table::Memory], - &trace_commitments[*Table::Memory], - &ctl_data_per_table[*Table::Memory], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); - let (mem_before_proof, mem_before_cap) = timed!( - timing, - "prove mem_before STARK", - prove_single_table( - &all_stark.mem_before_stark, - config, - &trace_poly_values[*Table::MemBefore], - &trace_commitments[*Table::MemBefore], - &ctl_data_per_table[*Table::MemBefore], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); - let (mem_after_proof, mem_after_cap) = timed!( - timing, - "prove mem_after STARK", - prove_single_table( - &all_stark.mem_after_stark, - config, - &trace_poly_values[*Table::MemAfter], - &trace_commitments[*Table::MemAfter], - &ctl_data_per_table[*Table::MemAfter], - ctl_challenges, - challenger, - timing, - abort_signal.clone(), - )? - ); + macro_rules! prove_table { + ($stark:ident, $table:expr) => { + timed!( + timing, + &format!("prove {} STARK", stringify!($stark)), + prove_single_table( + &all_stark.$stark, + config, + &trace_poly_values[*$table], + &trace_commitments[*$table], + &ctl_data_per_table[*$table], + ctl_challenges, + challenger, + timing, + abort_signal.clone(), + )? + ) + }; + } + + let (arithmetic_proof, _) = prove_table!(arithmetic_stark, Table::Arithmetic); + let (byte_packing_proof, _) = prove_table!(byte_packing_stark, Table::BytePacking); + let (cpu_proof, _) = prove_table!(cpu_stark, Table::Cpu); + let (keccak_proof, _) = prove_table!(keccak_stark, Table::Keccak); + let (keccak_sponge_proof, _) = prove_table!(keccak_sponge_stark, Table::KeccakSponge); + let (logic_proof, _) = prove_table!(logic_stark, Table::Logic); + let (memory_proof, _) = prove_table!(memory_stark, Table::Memory); + let (mem_before_proof, mem_before_cap) = prove_table!(mem_before_stark, Table::MemBefore); + let (mem_after_proof, mem_after_cap) = prove_table!(mem_after_stark, Table::MemAfter); + #[cfg(feature = "cdk_erigon")] - let (poseidon_proof, _) = timed!( - timing, - "prove poseidon STARK", - prove_single_table( - &all_stark.poseidon_stark, - config, - &trace_poly_values[*Table::Poseidon], - &trace_commitments[*Table::Poseidon], - &ctl_data_per_table[*Table::Poseidon], - ctl_challenges, - challenger, - timing, - abort_signal, - )? - ); + let (poseidon_proof, _) = prove_table!(poseidon_stark, Table::Poseidon); Ok(( [ diff --git a/evm_arithmetization/src/verifier.rs b/evm_arithmetization/src/verifier.rs index 9ee5750f8..caa01859e 100644 --- a/evm_arithmetization/src/verifier.rs +++ b/evm_arithmetization/src/verifier.rs @@ -156,88 +156,31 @@ fn verify_proof, C: GenericConfig, const let stark_proofs = &all_proof.multi_proof.stark_proofs; - verify_stark_proof_with_challenges( - arithmetic_stark, - &stark_proofs[*Table::Arithmetic].proof, - &stark_challenges[*Table::Arithmetic], - Some(&ctl_vars_per_table[*Table::Arithmetic]), - &[], - config, - )?; + macro_rules! verify_table { + ($stark:ident, $table:expr) => { + verify_stark_proof_with_challenges( + $stark, + &stark_proofs[*$table].proof, + &stark_challenges[*$table], + Some(&ctl_vars_per_table[*$table]), + &[], + config, + )?; + }; + } + + verify_table!(arithmetic_stark, Table::Arithmetic); + verify_table!(byte_packing_stark, Table::BytePacking); + verify_table!(cpu_stark, Table::Cpu); + verify_table!(keccak_stark, Table::Keccak); + verify_table!(keccak_sponge_stark, Table::KeccakSponge); + verify_table!(logic_stark, Table::Logic); + verify_table!(memory_stark, Table::Memory); + verify_table!(mem_before_stark, Table::MemBefore); + verify_table!(mem_after_stark, Table::MemAfter); - verify_stark_proof_with_challenges( - byte_packing_stark, - &stark_proofs[*Table::BytePacking].proof, - &stark_challenges[*Table::BytePacking], - Some(&ctl_vars_per_table[*Table::BytePacking]), - &[], - config, - )?; - verify_stark_proof_with_challenges( - cpu_stark, - &stark_proofs[*Table::Cpu].proof, - &stark_challenges[*Table::Cpu], - Some(&ctl_vars_per_table[*Table::Cpu]), - &[], - config, - )?; - verify_stark_proof_with_challenges( - keccak_stark, - &stark_proofs[*Table::Keccak].proof, - &stark_challenges[*Table::Keccak], - Some(&ctl_vars_per_table[*Table::Keccak]), - &[], - config, - )?; - verify_stark_proof_with_challenges( - keccak_sponge_stark, - &stark_proofs[*Table::KeccakSponge].proof, - &stark_challenges[*Table::KeccakSponge], - Some(&ctl_vars_per_table[*Table::KeccakSponge]), - &[], - config, - )?; - verify_stark_proof_with_challenges( - logic_stark, - &stark_proofs[*Table::Logic].proof, - &stark_challenges[*Table::Logic], - Some(&ctl_vars_per_table[*Table::Logic]), - &[], - config, - )?; - verify_stark_proof_with_challenges( - memory_stark, - &stark_proofs[*Table::Memory].proof, - &stark_challenges[*Table::Memory], - Some(&ctl_vars_per_table[*Table::Memory]), - &[], - config, - )?; - verify_stark_proof_with_challenges( - mem_before_stark, - &stark_proofs[*Table::MemBefore].proof, - &stark_challenges[*Table::MemBefore], - Some(&ctl_vars_per_table[*Table::MemBefore]), - &[], - config, - )?; - verify_stark_proof_with_challenges( - mem_after_stark, - &stark_proofs[*Table::MemAfter].proof, - &stark_challenges[*Table::MemAfter], - Some(&ctl_vars_per_table[*Table::MemAfter]), - &[], - config, - )?; #[cfg(feature = "cdk_erigon")] - verify_stark_proof_with_challenges( - poseidon_stark, - &stark_proofs[*Table::Poseidon].proof, - &stark_challenges[*Table::Poseidon], - Some(&ctl_vars_per_table[*Table::Poseidon]), - &[], - config, - )?; + verify_table!(poseidon_stark, Table::Poseidon); let public_values = all_proof.public_values;