diff --git a/zkevm-circuits/src/evm_circuit/execution/balance.rs b/zkevm-circuits/src/evm_circuit/execution/balance.rs index c910112ccd..929bf9a2be 100644 --- a/zkevm-circuits/src/evm_circuit/execution/balance.rs +++ b/zkevm-circuits/src/evm_circuit/execution/balance.rs @@ -49,12 +49,12 @@ impl ExecutionGadget for BalanceGadget { is_warm.expr(), Some(&mut reversion_info), ); - let code_hash = cb.query_cell(); + let code_hash = cb.query_cell_phase2(); // For non-existing accounts the code_hash must be 0 in the rw_table. cb.account_read(address.expr(), AccountFieldTag::CodeHash, code_hash.expr()); let not_exists = IsZeroGadget::construct(cb, code_hash.expr()); let exists = not::expr(not_exists.expr()); - let balance = cb.query_cell(); + let balance = cb.query_cell_phase2(); cb.condition(exists.expr(), |cb| { cb.account_read(address.expr(), AccountFieldTag::Balance, balance.expr()); }); diff --git a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs index cd438f197c..a0382a2977 100644 --- a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs @@ -10,7 +10,7 @@ use crate::{ Transition::{Delta, To}, }, math_gadget::{IsEqualGadget, IsZeroGadget, MulWordByU64Gadget, RangeCheckGadget}, - select, CachedRegion, Cell, CellType, Word, + select, CachedRegion, Cell, Word, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -149,7 +149,7 @@ impl ExecutionGadget for BeginTxGadget { // TODO: Handle precompiled // Read code_hash of callee - let phase2_code_hash = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_code_hash = cb.query_cell_phase2(); cb.account_read( tx_callee_address.expr(), AccountFieldTag::CodeHash, diff --git a/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs b/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs index 08b42ec188..29a74f8586 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs @@ -45,7 +45,7 @@ impl ExecutionGadget for CallDataCopyGadget { fn configure(cb: &mut ConstraintBuilder) -> Self { let opcode = cb.query_cell(); - let memory_offset = cb.query_cell(); + let memory_offset = cb.query_cell_phase2(); let data_offset = cb.query_word_rlc(); let length = cb.query_word_rlc(); diff --git a/zkevm-circuits/src/evm_circuit/execution/callvalue.rs b/zkevm-circuits/src/evm_circuit/execution/callvalue.rs index 25343998fa..98c822ea23 100644 --- a/zkevm-circuits/src/evm_circuit/execution/callvalue.rs +++ b/zkevm-circuits/src/evm_circuit/execution/callvalue.rs @@ -30,7 +30,7 @@ impl ExecutionGadget for CallValueGadget { const EXECUTION_STATE: ExecutionState = ExecutionState::CALLVALUE; fn configure(cb: &mut ConstraintBuilder) -> Self { - let call_value = cb.query_cell(); + let call_value = cb.query_cell_phase2(); // Lookup rw_table -> call_context with call value cb.call_context_lookup( diff --git a/zkevm-circuits/src/evm_circuit/execution/chainid.rs b/zkevm-circuits/src/evm_circuit/execution/chainid.rs index 6b48f31b3b..c3cefb9522 100644 --- a/zkevm-circuits/src/evm_circuit/execution/chainid.rs +++ b/zkevm-circuits/src/evm_circuit/execution/chainid.rs @@ -28,7 +28,7 @@ impl ExecutionGadget for ChainIdGadget { const EXECUTION_STATE: ExecutionState = ExecutionState::CHAINID; fn configure(cb: &mut ConstraintBuilder) -> Self { - let chain_id = cb.query_cell(); + let chain_id = cb.query_cell_phase2(); // Push the value to the stack cb.stack_push(chain_id.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/codecopy.rs b/zkevm-circuits/src/evm_circuit/execution/codecopy.rs index c6a57a655e..9a91c2905a 100644 --- a/zkevm-circuits/src/evm_circuit/execution/codecopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/codecopy.rs @@ -50,7 +50,7 @@ impl ExecutionGadget for CodeCopyGadget { let opcode = cb.query_cell(); // Query elements to be popped from the stack. - let dst_memory_offset = cb.query_cell(); + let dst_memory_offset = cb.query_cell_phase2(); let code_offset = cb.query_word_rlc(); let size = cb.query_word_rlc(); diff --git a/zkevm-circuits/src/evm_circuit/execution/dup.rs b/zkevm-circuits/src/evm_circuit/execution/dup.rs index 6ac47e2cb0..f8d30ea8af 100644 --- a/zkevm-circuits/src/evm_circuit/execution/dup.rs +++ b/zkevm-circuits/src/evm_circuit/execution/dup.rs @@ -5,7 +5,7 @@ use crate::{ util::{ common_gadget::SameContextGadget, constraint_builder::{ConstraintBuilder, StepStateTransition, Transition::Delta}, - CachedRegion, Cell, CellType, + CachedRegion, Cell, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -28,7 +28,7 @@ impl ExecutionGadget for DupGadget { fn configure(cb: &mut ConstraintBuilder) -> Self { let opcode = cb.query_cell(); - let value = cb.query_cell_with_type(CellType::StoragePhase2); + let value = cb.query_cell_phase2(); // The stack index we have to peek, deduced from the 'x' value of 'dupx' // The offset starts at 0 for DUP1 diff --git a/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs b/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs index fdb878dda3..0f9d2b149e 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs @@ -11,7 +11,7 @@ use crate::{ }, from_bytes, math_gadget::{IsEqualGadget, IsZeroGadget, LtGadget}, - CachedRegion, Cell, CellType, RandomLinearCombination, + CachedRegion, Cell, RandomLinearCombination, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -49,7 +49,7 @@ impl ExecutionGadget for ErrorInvalidJumpGadget { let value = cb.query_cell(); let is_code = cb.query_cell(); let rw_counter_end_of_reversion = cb.query_cell(); - let phase2_condition = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_condition = cb.query_cell_phase2(); cb.require_in_set( "ErrorInvalidJump only happend in JUMP or JUMPI", diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs b/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs index d9237c6645..fa77fafcea 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs @@ -47,7 +47,7 @@ impl ExecutionGadget for ExtcodecopyGadget { let opcode = cb.query_cell(); let external_address = cb.query_word_rlc(); - let memory_offset = cb.query_cell(); + let memory_offset = cb.query_cell_phase2(); let data_offset = cb.query_word_rlc(); let memory_length = cb.query_word_rlc(); @@ -69,7 +69,7 @@ impl ExecutionGadget for ExtcodecopyGadget { Some(&mut reversion_info), ); - let code_hash = cb.query_cell(); + let code_hash = cb.query_cell_phase2(); cb.account_read( from_bytes::expr(&external_address.cells), AccountFieldTag::CodeHash, diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs b/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs index 30a20d4f5d..d3d38358da 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs @@ -50,7 +50,7 @@ impl ExecutionGadget for ExtcodehashGadget { Some(&mut reversion_info), ); - let code_hash = cb.query_cell(); + let code_hash = cb.query_cell_phase2(); // For non-existing accounts the code_hash must be 0 in the rw_table. cb.account_read(address, AccountFieldTag::CodeHash, code_hash.expr()); cb.stack_push(code_hash.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs b/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs index 70f37fdb43..28f52c328b 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs @@ -51,7 +51,7 @@ impl ExecutionGadget for ExtcodesizeGadget { Some(&mut reversion_info), ); - let code_hash = cb.query_cell(); + let code_hash = cb.query_cell_phase2(); // For non-existing accounts the code_hash must be 0 in the rw_table. cb.account_read(address.expr(), AccountFieldTag::CodeHash, code_hash.expr()); let not_exists = IsZeroGadget::construct(cb, code_hash.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/gasprice.rs b/zkevm-circuits/src/evm_circuit/execution/gasprice.rs index 95f5e44dd8..fcd40d7616 100644 --- a/zkevm-circuits/src/evm_circuit/execution/gasprice.rs +++ b/zkevm-circuits/src/evm_circuit/execution/gasprice.rs @@ -30,7 +30,7 @@ impl ExecutionGadget for GasPriceGadget { fn configure(cb: &mut ConstraintBuilder) -> Self { // Query gasprice value - let gas_price = cb.query_cell(); + let gas_price = cb.query_cell_phase2(); // Lookup in call_ctx the TxId let tx_id = cb.call_context(None, CallContextFieldTag::TxId); diff --git a/zkevm-circuits/src/evm_circuit/execution/is_zero.rs b/zkevm-circuits/src/evm_circuit/execution/is_zero.rs index b07f02cb07..92e6914f17 100644 --- a/zkevm-circuits/src/evm_circuit/execution/is_zero.rs +++ b/zkevm-circuits/src/evm_circuit/execution/is_zero.rs @@ -30,7 +30,7 @@ impl ExecutionGadget for IsZeroGadget { fn configure(cb: &mut ConstraintBuilder) -> Self { let opcode = cb.query_cell(); - let value = cb.query_cell(); + let value = cb.query_cell_phase2(); let is_zero = math_gadget::IsZeroGadget::construct(cb, value.expr()); cb.stack_pop(value.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/jumpi.rs b/zkevm-circuits/src/evm_circuit/execution/jumpi.rs index 7e4a8cbb36..0a278eec21 100644 --- a/zkevm-circuits/src/evm_circuit/execution/jumpi.rs +++ b/zkevm-circuits/src/evm_circuit/execution/jumpi.rs @@ -11,7 +11,7 @@ use crate::{ }, from_bytes, math_gadget::IsZeroGadget, - select, CachedRegion, Cell, CellType, RandomLinearCombination, + select, CachedRegion, Cell, RandomLinearCombination, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -35,7 +35,7 @@ impl ExecutionGadget for JumpiGadget { fn configure(cb: &mut ConstraintBuilder) -> Self { let destination = cb.query_word_rlc(); - let phase2_condition = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_condition = cb.query_cell_phase2(); // Pop the value from the stack cb.stack_pop(destination.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/logs.rs b/zkevm-circuits/src/evm_circuit/execution/logs.rs index a4d7c79e10..19ff4da60a 100644 --- a/zkevm-circuits/src/evm_circuit/execution/logs.rs +++ b/zkevm-circuits/src/evm_circuit/execution/logs.rs @@ -10,7 +10,7 @@ use crate::{ Transition::{Delta, To}, }, memory_gadget::{MemoryAddressGadget, MemoryExpansionGadget}, - not, sum, CachedRegion, Cell, CellType, + not, sum, CachedRegion, Cell, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -45,7 +45,7 @@ impl ExecutionGadget for LogGadget { const EXECUTION_STATE: ExecutionState = ExecutionState::LOG; fn configure(cb: &mut ConstraintBuilder) -> Self { - let mstart = cb.query_cell(); + let mstart = cb.query_cell_phase2(); let msize = cb.query_word_rlc(); // Pop mstart_address, msize from stack @@ -74,7 +74,7 @@ impl ExecutionGadget for LogGadget { }); // constrain topics in logs - let phase2_topics = array_init(|_| cb.query_cell_with_type(CellType::StoragePhase2)); + let phase2_topics = array_init(|_| cb.query_cell_phase2()); let topic_selectors: [Cell; 4] = array_init(|_| cb.query_cell()); for (idx, topic) in phase2_topics.iter().enumerate() { cb.condition(topic_selectors[idx].expr(), |cb| { diff --git a/zkevm-circuits/src/evm_circuit/execution/pop.rs b/zkevm-circuits/src/evm_circuit/execution/pop.rs index 22f997f20e..112e0a9b98 100644 --- a/zkevm-circuits/src/evm_circuit/execution/pop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/pop.rs @@ -5,7 +5,7 @@ use crate::{ util::{ common_gadget::SameContextGadget, constraint_builder::{ConstraintBuilder, StepStateTransition, Transition::Delta}, - CachedRegion, Cell, CellType, + CachedRegion, Cell, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -27,7 +27,7 @@ impl ExecutionGadget for PopGadget { const EXECUTION_STATE: ExecutionState = ExecutionState::POP; fn configure(cb: &mut ConstraintBuilder) -> Self { - let phase2_value = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_value = cb.query_cell_phase2(); // Pop the value from the stack cb.stack_pop(phase2_value.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/return_revert.rs b/zkevm-circuits/src/evm_circuit/execution/return_revert.rs index 5aae53e5f2..7d71721624 100644 --- a/zkevm-circuits/src/evm_circuit/execution/return_revert.rs +++ b/zkevm-circuits/src/evm_circuit/execution/return_revert.rs @@ -56,7 +56,7 @@ impl ExecutionGadget for ReturnRevertGadget { let opcode = cb.query_cell(); cb.opcode_lookup(opcode.expr(), 1.expr()); - let offset = cb.query_cell(); + let offset = cb.query_cell_phase2(); let length = cb.query_word_rlc(); cb.stack_pop(offset.expr()); cb.stack_pop(length.expr()); @@ -99,7 +99,7 @@ impl ExecutionGadget for ReturnRevertGadget { cb.condition(is_contract_deployment.clone(), |cb| { // We don't need to place any additional constraints on code_hash because the // copy circuit enforces that it is the hash of the bytes in the copy lookup. - let code_hash = cb.query_cell(); + let code_hash = cb.query_cell_phase2(); cb.copy_table_lookup( cb.curr.state.call_id.expr(), CopyDataType::Memory.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs b/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs index e046796b39..d0928a2268 100644 --- a/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs @@ -60,7 +60,7 @@ impl ExecutionGadget for ReturnDataCopyGadget { fn configure(cb: &mut ConstraintBuilder) -> Self { let opcode = cb.query_cell(); - let dest_offset = cb.query_cell(); + let dest_offset = cb.query_cell_phase2(); let data_offset = cb.query_word_rlc(); let size = cb.query_word_rlc(); diff --git a/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs b/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs index 2d366afd27..94e8ccb8e4 100644 --- a/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs +++ b/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs @@ -5,7 +5,7 @@ use crate::{ util::{ common_gadget::SameContextGadget, constraint_builder::{ConstraintBuilder, StepStateTransition, Transition::Delta}, - CachedRegion, Cell, CellType, + CachedRegion, Cell, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -31,7 +31,7 @@ impl ExecutionGadget for SelfbalanceGadget { fn configure(cb: &mut ConstraintBuilder) -> Self { let callee_address = cb.call_context(None, CallContextFieldTag::CalleeAddress); - let phase2_self_balance = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_self_balance = cb.query_cell_phase2(); cb.account_read( callee_address.expr(), AccountFieldTag::Balance, diff --git a/zkevm-circuits/src/evm_circuit/execution/sha3.rs b/zkevm-circuits/src/evm_circuit/execution/sha3.rs index 581f559707..e476a65f23 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sha3.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sha3.rs @@ -36,7 +36,7 @@ impl ExecutionGadget for Sha3Gadget { fn configure(cb: &mut ConstraintBuilder) -> Self { let opcode = cb.query_cell(); - let offset = cb.query_cell(); + let offset = cb.query_cell_phase2(); let size = cb.query_word_rlc(); let sha3_rlc = cb.query_word_rlc(); @@ -47,7 +47,7 @@ impl ExecutionGadget for Sha3Gadget { let memory_address = MemoryAddressGadget::construct(cb, offset, size); let copy_rwc_inc = cb.query_cell(); - let rlc_acc = cb.query_cell(); + let rlc_acc = cb.query_cell_phase2(); cb.condition(memory_address.has_length(), |cb| { cb.copy_table_lookup( diff --git a/zkevm-circuits/src/evm_circuit/execution/sload.rs b/zkevm-circuits/src/evm_circuit/execution/sload.rs index b6cdb5d98f..05ecd0a4d7 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sload.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sload.rs @@ -7,7 +7,7 @@ use crate::{ constraint_builder::{ ConstraintBuilder, ReversionInfo, StepStateTransition, Transition::Delta, }, - select, CachedRegion, Cell, CellType, + select, CachedRegion, Cell, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -44,12 +44,12 @@ impl ExecutionGadget for SloadGadget { let mut reversion_info = cb.reversion_info_read(None); let callee_address = cb.call_context(None, CallContextFieldTag::CalleeAddress); - let phase2_key = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_key = cb.query_cell_phase2(); // Pop the key from the stack cb.stack_pop(phase2_key.expr()); - let phase2_value = cb.query_cell_with_type(CellType::StoragePhase2); - let phase2_committed_value = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_value = cb.query_cell_phase2(); + let phase2_committed_value = cb.query_cell_phase2(); cb.account_storage_read( callee_address.expr(), phase2_key.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/sstore.rs b/zkevm-circuits/src/evm_circuit/execution/sstore.rs index ef5889439a..7449250100 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sstore.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sstore.rs @@ -8,7 +8,7 @@ use crate::{ ConstraintBuilder, ReversionInfo, StepStateTransition, Transition::Delta, }, math_gadget::{IsEqualGadget, IsZeroGadget}, - not, select, CachedRegion, Cell, CellType, + not, select, CachedRegion, Cell, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -56,16 +56,16 @@ impl ExecutionGadget for SstoreGadget { let mut reversion_info = cb.reversion_info_read(None); let callee_address = cb.call_context(None, CallContextFieldTag::CalleeAddress); - let phase2_key = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_key = cb.query_cell_phase2(); // Pop the key from the stack cb.stack_pop(phase2_key.expr()); - let phase2_value = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_value = cb.query_cell_phase2(); // Pop the value from the stack cb.stack_pop(phase2_value.expr()); - let phase2_value_prev = cb.query_cell_with_type(CellType::StoragePhase2); - let phase2_original_value = cb.query_cell_with_type(CellType::StoragePhase2); + let phase2_value_prev = cb.query_cell_phase2(); + let phase2_original_value = cb.query_cell_phase2(); cb.account_storage_write( callee_address.expr(), phase2_key.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/swap.rs b/zkevm-circuits/src/evm_circuit/execution/swap.rs index 0808574def..f33008ffe5 100644 --- a/zkevm-circuits/src/evm_circuit/execution/swap.rs +++ b/zkevm-circuits/src/evm_circuit/execution/swap.rs @@ -5,7 +5,7 @@ use crate::{ util::{ common_gadget::SameContextGadget, constraint_builder::{ConstraintBuilder, StepStateTransition, Transition::Delta}, - CachedRegion, Cell, CellType, + CachedRegion, Cell, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -28,10 +28,7 @@ impl ExecutionGadget for SwapGadget { fn configure(cb: &mut ConstraintBuilder) -> Self { let opcode = cb.query_cell(); - let phase2_values = [ - cb.query_cell_with_type(CellType::StoragePhase2), - cb.query_cell_with_type(CellType::StoragePhase2), - ]; + let phase2_values = [cb.query_cell_phase2(), cb.query_cell_phase2()]; // The stack index we have to peek, deduced from the 'x' value of // 'swapx' The offset starts at 1 for SWAP1 diff --git a/zkevm-circuits/src/evm_circuit/util.rs b/zkevm-circuits/src/evm_circuit/util.rs index 575f3f86b2..42e271eff0 100644 --- a/zkevm-circuits/src/evm_circuit/util.rs +++ b/zkevm-circuits/src/evm_circuit/util.rs @@ -35,14 +35,21 @@ pub(crate) struct Cell { column: Column, // relative position to selector for synthesis rotation: usize, + cell_column_index: usize, } impl Cell { - pub(crate) fn new(meta: &mut VirtualCells, column: Column, rotation: usize) -> Self { + pub(crate) fn new( + meta: &mut VirtualCells, + column: Column, + rotation: usize, + cell_column_index: usize, + ) -> Self { Self { expression: meta.query_advice(column, Rotation(rotation as i32)), column, rotation, + cell_column_index, } } @@ -325,7 +332,7 @@ impl CellManager { query_expression(meta, |meta| { for c in 0..width { for r in 0..height { - cells.push(Cell::new(meta, advices[c], height_offset + r)); + cells.push(Cell::new(meta, advices[c], height_offset + r, c)); } columns.push(CellColumn { index: c, diff --git a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs index 6a487db80c..2ad69e003f 100644 --- a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs @@ -476,9 +476,9 @@ impl CommonCallGadget let gas_word = cb.query_word_rlc(); let callee_address_word = cb.query_word_rlc(); let value = cb.query_word_rlc(); - let cd_offset = cb.query_cell(); + let cd_offset = cb.query_cell_phase2(); let cd_length = cb.query_word_rlc(); - let rd_offset = cb.query_cell(); + let rd_offset = cb.query_cell_phase2(); let rd_length = cb.query_word_rlc(); let is_success = cb.query_bool(); diff --git a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs index 9dff3a664c..10e5c075c9 100644 --- a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs +++ b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs @@ -394,6 +394,10 @@ impl<'a, F: Field> ConstraintBuilder<'a, F> { self.query_cell_with_type(CellType::StoragePhase1) } + pub(crate) fn query_cell_phase2(&mut self) -> Cell { + self.query_cell_with_type(CellType::StoragePhase2) + } + pub(crate) fn query_copy_cell(&mut self) -> Cell { self.query_cell_with_type(CellType::StoragePermutation) } diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/test_util.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/test_util.rs index 8a5c0cf2a6..9f3258ba0c 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/test_util.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/test_util.rs @@ -5,12 +5,12 @@ use strum::IntoEnumIterator; use crate::table::LookupTable; use crate::{ evm_circuit::{ - param::{MAX_STEP_HEIGHT, STEP_WIDTH}, + param::{MAX_STEP_HEIGHT, N_PHASE2_COLUMNS, N_PHASE3_COLUMNS, STEP_WIDTH}, step::{ExecutionState, Step}, table::{FixedTableTag, Table}, util::{ constraint_builder::ConstraintBuilder, rlc, CachedRegion, CellType, Expr, - StoredExpression, + StoredExpression, LOOKUP_CONFIG, }, Advice, Column, Fixed, }, @@ -18,6 +18,7 @@ use crate::{ }; use eth_types::{Field, Word, U256}; pub(crate) use halo2_proofs::circuit::{Layouter, Value}; +use halo2_proofs::plonk::{FirstPhase, SecondPhase, ThirdPhase}; use halo2_proofs::{ circuit::SimpleFloorPlanner, dev::MockProver, @@ -98,13 +99,31 @@ impl> Circuit for UnitTestMathGadgetBaseC } fn configure(meta: &mut ConstraintSystem) -> Self::Config { + let challenges = Challenges::construct(meta); + let challenges_exprs = challenges.exprs(meta); + let q_usable = meta.selector(); let fixed_table = [(); 4].map(|_| meta.fixed_column()); - let advices = [(); STEP_WIDTH].map(|_| meta.advice_column()); + + let lookup_column_count: usize = LOOKUP_CONFIG.iter().map(|(_, count)| *count).sum(); + let advices = [(); STEP_WIDTH] + .iter() + .enumerate() + .map(|(n, _)| { + if n < N_PHASE3_COLUMNS + lookup_column_count { + meta.advice_column_in(ThirdPhase) + } else if n < N_PHASE3_COLUMNS + lookup_column_count + N_PHASE2_COLUMNS { + meta.advice_column_in(SecondPhase) + } else { + meta.advice_column_in(FirstPhase) + } + }) + .collect::>() + .try_into() + .unwrap(); + let step_curr = Step::new(meta, advices, 0, false); let step_next = Step::new(meta, advices, MAX_STEP_HEIGHT, true); - let challenges = Challenges::construct(meta); - let challenges_exprs = challenges.exprs(meta); let evm_word_powers_of_randomness = challenges_exprs.evm_word_powers_of_randomness(); let lookup_input_powers_of_randomness = challenges_exprs.lookup_input_powers_of_randomness(); diff --git a/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs b/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs index a06f97b63e..cd080cb2fa 100644 --- a/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs @@ -6,7 +6,7 @@ use crate::{ constraint_builder::ConstraintBuilder, from_bytes, math_gadget::{ConstantDivisionGadget, IsZeroGadget, MinMaxGadget, RangeCheckGadget}, - select, sum, Cell, MemoryAddress, + select, sum, Cell, CellType, MemoryAddress, }, }, util::Expr, @@ -75,6 +75,10 @@ impl MemoryAddressGadget { memory_offset: Cell, memory_length: MemoryAddress, ) -> Self { + debug_assert_eq!( + CellType::StoragePhase2, + cb.curr.cell_manager.columns()[memory_offset.cell_column_index].cell_type + ); let memory_length_is_zero = IsZeroGadget::construct(cb, sum::expr(&memory_length.cells)); let memory_offset_bytes = cb.query_word_rlc();