diff --git a/Cargo.toml b/Cargo.toml index 1ecfd3f1e..3c76a43be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,10 +21,10 @@ serde-big-array = "0.5.1" thiserror = "1.0.49" # plonky2-related dependencies -plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", branch = "zkevm_no_dummy_segment" } +plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" } plonky2_maybe_rayon = "0.2.0" -plonky2_util = { git = "https://github.com/0xPolygonZero/plonky2.git", branch = "zkevm_no_dummy_segment" } -starky = { git = "https://github.com/0xPolygonZero/plonky2.git", branch = "zkevm_no_dummy_segment" } +plonky2_util = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" } +starky = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" } [workspace.package] diff --git a/evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs b/evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs index 3f13ce1b0..ed8313c50 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs @@ -101,6 +101,8 @@ fn test_init_exc_stop() { interpreter.set_is_kernel(true); interpreter.clock = 0; + // Set the program counter and `is_kernel` at the end of the execution. They + // have offsets 6 and 7 resepectively in segment `RegistersStates`. let regs_to_set = [ ( MemoryAddress { diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 3c5a8800f..bdbd0d530 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -1977,44 +1977,7 @@ where proof, ); if is_dummy { - let mut dummy_pis = proof.public_inputs.clone(); - // We must change the registers before and memory before. - dummy_pis.copy_within( - TrieRootsTarget::SIZE * 2 - + BlockMetadataTarget::SIZE - + BlockHashesTarget::SIZE - + ExtraBlockDataTarget::SIZE - + RegistersDataTarget::SIZE - ..TrieRootsTarget::SIZE * 2 - + BlockMetadataTarget::SIZE - + BlockHashesTarget::SIZE - + ExtraBlockDataTarget::SIZE - + RegistersDataTarget::SIZE * 2, - TrieRootsTarget::SIZE * 2 - + BlockMetadataTarget::SIZE - + BlockHashesTarget::SIZE - + ExtraBlockDataTarget::SIZE, - ); - // Mem before := Mem after - dummy_pis.copy_within( - TrieRootsTarget::SIZE * 2 - + BlockMetadataTarget::SIZE - + BlockHashesTarget::SIZE - + ExtraBlockDataTarget::SIZE - + RegistersDataTarget::SIZE * 2 - + len_mem_cap * NUM_HASH_OUT_ELTS - ..TrieRootsTarget::SIZE * 2 - + BlockMetadataTarget::SIZE - + BlockHashesTarget::SIZE - + ExtraBlockDataTarget::SIZE - + RegistersDataTarget::SIZE * 2 - + 2 * len_mem_cap * NUM_HASH_OUT_ELTS, - TrieRootsTarget::SIZE * 2 - + BlockMetadataTarget::SIZE - + BlockHashesTarget::SIZE - + ExtraBlockDataTarget::SIZE - + RegistersDataTarget::SIZE * 2, - ); + let dummy_pis = Self::get_dummy_pis(&proof.public_inputs, len_mem_cap); let mut dummy_pis_map = HashMap::new(); for (idx, &pi) in dummy_pis.iter().enumerate() { @@ -2033,6 +1996,48 @@ where agg_inputs.set_proof_with_pis_target(&agg_child.real_proof, proof); } + fn get_dummy_pis(pis: &[F], len_mem_cap: usize) -> Vec { + let mut dummy_pis = pis.to_vec(); + // We must change the registers before and memory before. + dummy_pis.copy_within( + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + + ExtraBlockDataTarget::SIZE + + RegistersDataTarget::SIZE + ..TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + + ExtraBlockDataTarget::SIZE + + RegistersDataTarget::SIZE * 2, + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + + ExtraBlockDataTarget::SIZE, + ); + // Mem before := Mem after + dummy_pis.copy_within( + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + + ExtraBlockDataTarget::SIZE + + RegistersDataTarget::SIZE * 2 + + len_mem_cap * NUM_HASH_OUT_ELTS + ..TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + + ExtraBlockDataTarget::SIZE + + RegistersDataTarget::SIZE * 2 + + 2 * len_mem_cap * NUM_HASH_OUT_ELTS, + TrieRootsTarget::SIZE * 2 + + BlockMetadataTarget::SIZE + + BlockHashesTarget::SIZE + + ExtraBlockDataTarget::SIZE + + RegistersDataTarget::SIZE * 2, + ); + dummy_pis + } + /// Create a final block proof, once all transactions of a given block have /// been combined into a single aggregation proof. /// diff --git a/evm_arithmetization/src/proof.rs b/evm_arithmetization/src/proof.rs index e95018f18..53c10a41d 100644 --- a/evm_arithmetization/src/proof.rs +++ b/evm_arithmetization/src/proof.rs @@ -824,20 +824,24 @@ impl TrieRootsTarget { } /// If `condition`, asserts that `tr0 == tr1`. - pub(crate) fn assert_equal_if, const D: usize>( + pub(crate) fn conditionally_assert_eq, const D: usize>( builder: &mut CircuitBuilder, condition: BoolTarget, tr0: Self, tr1: Self, ) { for i in 0..8 { - builder.assert_equal_if(condition.target, tr0.state_root[i], tr1.state_root[i]); - builder.assert_equal_if( + builder.conditional_assert_eq(condition.target, tr0.state_root[i], tr1.state_root[i]); + builder.conditional_assert_eq( condition.target, tr0.transactions_root[i], tr1.transactions_root[i], ); - builder.assert_equal_if(condition.target, tr0.receipts_root[i], tr1.receipts_root[i]); + builder.conditional_assert_eq( + condition.target, + tr0.receipts_root[i], + tr1.receipts_root[i], + ); } } } @@ -1205,14 +1209,14 @@ impl RegistersDataTarget { rd0: Self, rd1: Self, ) { - builder.assert_equal_if(condition.target, rd0.program_counter, rd1.program_counter); - builder.assert_equal_if(condition.target, rd0.is_kernel, rd1.is_kernel); - builder.assert_equal_if(condition.target, rd0.stack_len, rd1.stack_len); + builder.conditional_assert_eq(condition.target, rd0.program_counter, rd1.program_counter); + builder.conditional_assert_eq(condition.target, rd0.is_kernel, rd1.is_kernel); + builder.conditional_assert_eq(condition.target, rd0.stack_len, rd1.stack_len); for i in 0..8 { - builder.assert_equal_if(condition.target, rd0.stack_top[i], rd1.stack_top[i]); + builder.conditional_assert_eq(condition.target, rd0.stack_top[i], rd1.stack_top[i]); } - builder.assert_equal_if(condition.target, rd0.context, rd1.context); - builder.assert_equal_if(condition.target, rd0.gas_used, rd1.gas_used); + builder.conditional_assert_eq(condition.target, rd0.context, rd1.context); + builder.conditional_assert_eq(condition.target, rd0.gas_used, rd1.gas_used); } } @@ -1291,7 +1295,7 @@ impl MemCapTarget { ) { for i in 0..mc0.mem_cap.0.len() { for j in 0..NUM_HASH_OUT_ELTS { - builder.assert_equal_if( + builder.conditional_assert_eq( condition.target, mc0.mem_cap.0[i].elements[j], mc1.mem_cap.0[i].elements[j],