diff --git a/zkevm-circuits/src/evm_circuit/execution/add_sub.rs b/zkevm-circuits/src/evm_circuit/execution/add_sub.rs index 90246abe36b..3f58266d58a 100644 --- a/zkevm-circuits/src/evm_circuit/execution/add_sub.rs +++ b/zkevm-circuits/src/evm_circuit/execution/add_sub.rs @@ -54,9 +54,9 @@ impl ExecutionGadget for AddSubGadget { // ADD: Pop a and b from the stack, push c on the stack // SUB: Pop c and b from the stack, push a on the stack - cb.stack_pop_word(Word::select(is_sub.expr().0, c.to_word(), a.to_word())); - cb.stack_pop_word(b.to_word()); - cb.stack_push_word(Word::select(is_sub.expr().0, a.to_word(), c.to_word())); + cb.stack_pop(Word::select(is_sub.expr().0, c.to_word(), a.to_word())); + cb.stack_pop(b.to_word()); + cb.stack_push(Word::select(is_sub.expr().0, a.to_word(), c.to_word())); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/addmod.rs b/zkevm-circuits/src/evm_circuit/execution/addmod.rs index 03a65af9956..cdac3a2a7a6 100644 --- a/zkevm-circuits/src/evm_circuit/execution/addmod.rs +++ b/zkevm-circuits/src/evm_circuit/execution/addmod.rs @@ -109,10 +109,10 @@ impl ExecutionGadget for AddModGadget { // pop/push values // take care that if n==0 pushed value for r should be zero also - cb.stack_pop_word(a.to_word()); - cb.stack_pop_word(b.to_word()); - cb.stack_pop_word(n.clone().to_word()); - cb.stack_push_word( + cb.stack_pop(a.to_word()); + cb.stack_pop(b.to_word()); + cb.stack_pop(n.clone().to_word()); + cb.stack_push( r.clone() .to_word() .mul_selector(not::expr(n_is_zero.expr())), diff --git a/zkevm-circuits/src/evm_circuit/execution/address.rs b/zkevm-circuits/src/evm_circuit/execution/address.rs index 896f0d291b5..95e9ecf8fc4 100644 --- a/zkevm-circuits/src/evm_circuit/execution/address.rs +++ b/zkevm-circuits/src/evm_circuit/execution/address.rs @@ -36,7 +36,7 @@ impl ExecutionGadget for AddressGadget { // Lookup callee address in call context. cb.call_context_lookup_read(None, CallContextFieldTag::CalleeAddress, address.to_word()); - cb.stack_push_word(address.to_word()); + cb.stack_push(address.to_word()); let step_state_transition = StepStateTransition { rw_counter: Delta(2.expr()), diff --git a/zkevm-circuits/src/evm_circuit/execution/balance.rs b/zkevm-circuits/src/evm_circuit/execution/balance.rs index f82678e869c..faed4d5097b 100644 --- a/zkevm-circuits/src/evm_circuit/execution/balance.rs +++ b/zkevm-circuits/src/evm_circuit/execution/balance.rs @@ -41,7 +41,7 @@ impl ExecutionGadget for BalanceGadget { fn configure(cb: &mut EVMConstraintBuilder) -> Self { let address = cb.query_account_address(); - cb.stack_pop_word(address.to_word()); + cb.stack_pop(address.to_word()); let tx_id = cb.call_context(None, CallContextFieldTag::TxId); let mut reversion_info = cb.reversion_info_read(None); @@ -55,7 +55,7 @@ impl ExecutionGadget for BalanceGadget { ); let code_hash = cb.query_word_unchecked(); // For non-existing accounts the code_hash must be 0 in the rw_table. - cb.account_read_word( + cb.account_read( address.to_word(), AccountFieldTag::CodeHash, code_hash.to_word(), @@ -64,7 +64,7 @@ impl ExecutionGadget for BalanceGadget { let exists = not::expr(not_exists.expr()); let balance = cb.query_word32(); cb.condition(exists.expr(), |cb| { - cb.account_read_word( + cb.account_read( address.to_word(), AccountFieldTag::Balance, balance.to_word(), @@ -74,7 +74,7 @@ impl ExecutionGadget for BalanceGadget { cb.require_zero_word("balance is zero when non_exists", balance.to_word()); }); - cb.stack_push_word(balance.to_word()); + cb.stack_push(balance.to_word()); let gas_cost = select::expr( is_warm.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs index 45232e43be8..ec4190dab14 100644 --- a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs @@ -131,7 +131,7 @@ impl ExecutionGadget for BeginTxGadget { // Increase caller's nonce. // (tx caller's nonce always increases even tx ends with error) - cb.account_write_word( + cb.account_write( tx_caller_address.to_word(), AccountFieldTag::Nonce, Word::from_lo_unchecked(tx_nonce.expr() + 1.expr()), @@ -191,7 +191,7 @@ impl ExecutionGadget for BeginTxGadget { // Query coinbase address. let coinbase = cb.query_word_unchecked(); let is_coinbase_warm = cb.query_bool(); - cb.block_lookup_word( + cb.block_lookup( BlockContextFieldTag::Coinbase.expr(), None, coinbase.to_word(), @@ -207,7 +207,7 @@ impl ExecutionGadget for BeginTxGadget { // Read code_hash of callee let code_hash = cb.query_word_unchecked(); let is_empty_code_hash = - IsEqualWordGadget::construct(cb, &code_hash.to_word(), &cb.empty_code_hash_word()); + IsEqualWordGadget::construct(cb, &code_hash.to_word(), &cb.empty_code_hash()); let callee_not_exists = IsZeroWordGadget::construct(cb, &code_hash); // no_callee_code is true when the account exists and has empty // code hash, or when the account doesn't exist (which we encode with @@ -216,7 +216,7 @@ impl ExecutionGadget for BeginTxGadget { // TODO: And not precompile cb.condition(not::expr(tx_is_create.expr()), |cb| { - cb.account_read_word( + cb.account_read( tx_callee_address.to_word(), AccountFieldTag::CodeHash, code_hash.to_word(), @@ -240,7 +240,7 @@ impl ExecutionGadget for BeginTxGadget { cb.require_equal_word( "tx caller address equivalence", tx_caller_address.to_word(), - create.caller_address_word(), + create.caller_address(), ); cb.condition(tx_is_create.expr(), |cb| { cb.require_equal_word( @@ -263,13 +263,13 @@ impl ExecutionGadget for BeginTxGadget { // 1. Handle contract creation transaction. cb.condition(tx_is_create.expr(), |cb| { - cb.keccak_table_lookup_word( + cb.keccak_table_lookup( create.input_rlc(cb), create.input_length(), caller_nonce_hash_bytes.to_word(), ); - cb.account_write_word( + cb.account_write( call_callee_address.to_word(), AccountFieldTag::Nonce, Word::one(), diff --git a/zkevm-circuits/src/evm_circuit/execution/bitwise.rs b/zkevm-circuits/src/evm_circuit/execution/bitwise.rs index 9c4fb7d4a36..947ee2a7dda 100644 --- a/zkevm-circuits/src/evm_circuit/execution/bitwise.rs +++ b/zkevm-circuits/src/evm_circuit/execution/bitwise.rs @@ -38,9 +38,9 @@ impl ExecutionGadget for BitwiseGadget { let b = cb.query_word32(); let c = cb.query_word32(); - cb.stack_pop_word(a.to_word()); - cb.stack_pop_word(b.to_word()); - cb.stack_push_word(c.to_word()); + cb.stack_pop(a.to_word()); + cb.stack_pop(b.to_word()); + cb.stack_push(c.to_word()); // Because opcode AND, OR, and XOR are continuous, so we can make the // FixedTableTag of them also continuous, and use the opcode delta from diff --git a/zkevm-circuits/src/evm_circuit/execution/block_ctx.rs b/zkevm-circuits/src/evm_circuit/execution/block_ctx.rs index 10e5bbc24d4..f3026c52024 100644 --- a/zkevm-circuits/src/evm_circuit/execution/block_ctx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/block_ctx.rs @@ -34,7 +34,7 @@ impl ExecutionGadget for BlockCtxGadget { fn configure(cb: &mut EVMConstraintBuilder) -> Self { let value = cb.query_word_unchecked(); // block table lookup below - cb.stack_push_word(value.to_word()); + cb.stack_push(value.to_word()); // Get op's FieldTag let opcode = cb.query_cell(); @@ -43,7 +43,7 @@ impl ExecutionGadget for BlockCtxGadget { // Lookup block table with block context ops // TIMESTAMP/NUMBER/GASLIMIT, COINBASE and DIFFICULTY/BASEFEE - cb.block_lookup_word(blockctx_tag, None, value.to_word()); + cb.block_lookup(blockctx_tag, None, value.to_word()); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/blockhash.rs b/zkevm-circuits/src/evm_circuit/execution/blockhash.rs index 6b8df8f4536..80971696469 100644 --- a/zkevm-circuits/src/evm_circuit/execution/blockhash.rs +++ b/zkevm-circuits/src/evm_circuit/execution/blockhash.rs @@ -39,14 +39,14 @@ impl ExecutionGadget for BlockHashGadget { fn configure(cb: &mut EVMConstraintBuilder) -> Self { let current_block_number = cb.query_cell(); - cb.block_lookup_word( + cb.block_lookup( BlockContextFieldTag::Number.expr(), None, Word::from_lo_unchecked(current_block_number.expr()), ); let block_number = WordByteCapGadget::construct(cb, current_block_number.expr()); - cb.stack_pop_word(block_number.original_word_new().to_word()); + cb.stack_pop(block_number.original_word().to_word()); let block_hash = cb.query_word_unchecked(); @@ -59,7 +59,7 @@ impl ExecutionGadget for BlockHashGadget { let is_valid = and::expr([block_number.lt_cap(), diff_lt.expr()]); cb.condition(is_valid.expr(), |cb| { - cb.block_lookup_word( + cb.block_lookup( BlockContextFieldTag::BlockHash.expr(), Some(block_number.valid_value()), block_hash.to_word(), @@ -73,7 +73,7 @@ impl ExecutionGadget for BlockHashGadget { ); }); - cb.stack_push_word(block_hash.to_word()); + cb.stack_push(block_hash.to_word()); let step_state_transition = StepStateTransition { rw_counter: Delta(2.expr()), diff --git a/zkevm-circuits/src/evm_circuit/execution/byte.rs b/zkevm-circuits/src/evm_circuit/execution/byte.rs index 65719416e96..532c7c61da2 100644 --- a/zkevm-circuits/src/evm_circuit/execution/byte.rs +++ b/zkevm-circuits/src/evm_circuit/execution/byte.rs @@ -68,9 +68,9 @@ impl ExecutionGadget for ByteGadget { // push the selected byte on the stack // We can push the selected byte here directly because // it only uses the LSB of a word. - cb.stack_pop_word(index.to_word()); - cb.stack_pop_word(value.to_word()); - cb.stack_push_word(Word::from_lo_unchecked(selected_byte)); + cb.stack_pop(index.to_word()); + cb.stack_pop(value.to_word()); + cb.stack_push(Word::from_lo_unchecked(selected_byte)); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs b/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs index 38cea8758c7..6a2cfdd9657 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs @@ -56,9 +56,9 @@ impl ExecutionGadget for CallDataCopyGadget { let data_offset = WordByteCapGadget::construct(cb, call_data_length.expr()); // Pop memory_offset, data_offset, length from stack - cb.stack_pop_word(memory_offset.to_word()); - cb.stack_pop_word(data_offset.original_word_new().to_word()); - cb.stack_pop_word(length.to_word()); + cb.stack_pop(memory_offset.to_word()); + cb.stack_pop(data_offset.original_word().to_word()); + cb.stack_pop(length.to_word()); // Lookup the calldata_length and caller_address in Tx context table or // Call context table diff --git a/zkevm-circuits/src/evm_circuit/execution/calldataload.rs b/zkevm-circuits/src/evm_circuit/execution/calldataload.rs index 3252b97adb1..68205165268 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldataload.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldataload.rs @@ -68,7 +68,7 @@ impl ExecutionGadget for CallDataLoadGadget { let call_data_offset = cb.query_cell(); let data_offset = WordByteCapGadget::construct(cb, call_data_length.expr()); - cb.stack_pop_word(data_offset.original_word_new().to_word()); + cb.stack_pop(data_offset.original_word().to_word()); cb.condition( and::expr([data_offset.not_overflow(), cb.curr.state.is_root.expr()]), @@ -137,7 +137,7 @@ impl ExecutionGadget for CallDataLoadGadget { cb.curr.state.is_root.expr(), ]), |cb| { - cb.tx_context_lookup_word( + cb.tx_context_lookup( src_id.expr(), TxContextFieldTag::CallData, Some(src_addr.expr() + idx.expr()), @@ -178,7 +178,7 @@ impl ExecutionGadget for CallDataLoadGadget { calldata_word.to_word().mul_selector(data_offset.overflow()), ); - cb.stack_push_word(calldata_word.to_word()); + cb.stack_push(calldata_word.to_word()); let step_state_transition = StepStateTransition { rw_counter: Delta(cb.rw_counter_offset()), diff --git a/zkevm-circuits/src/evm_circuit/execution/calldatasize.rs b/zkevm-circuits/src/evm_circuit/execution/calldatasize.rs index 1864d337d5b..070097ca992 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldatasize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldatasize.rs @@ -42,7 +42,7 @@ impl ExecutionGadget for CallDataSizeGadget { ); // The calldatasize should be pushed to the top of the stack. - cb.stack_push_word(call_data_size.to_word()); + cb.stack_push(call_data_size.to_word()); let step_state_transition = StepStateTransition { rw_counter: Delta(2.expr()), diff --git a/zkevm-circuits/src/evm_circuit/execution/caller.rs b/zkevm-circuits/src/evm_circuit/execution/caller.rs index 5dcedd8ab09..d1c6819e5e7 100644 --- a/zkevm-circuits/src/evm_circuit/execution/caller.rs +++ b/zkevm-circuits/src/evm_circuit/execution/caller.rs @@ -41,7 +41,7 @@ impl ExecutionGadget for CallerGadget { ); // Push the value to the stack - cb.stack_push_word(caller_address.to_word()); + cb.stack_push(caller_address.to_word()); // State transition let opcode = cb.query_cell(); diff --git a/zkevm-circuits/src/evm_circuit/execution/callop.rs b/zkevm-circuits/src/evm_circuit/execution/callop.rs index 81eabdc388a..1000d7a93e8 100644 --- a/zkevm-circuits/src/evm_circuit/execution/callop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/callop.rs @@ -114,7 +114,7 @@ impl ExecutionGadget for CallOpGadget { let callee_address = Word::select( is_callcode.expr() + is_delegatecall.expr(), current_callee_address.to_word(), - call_gadget.callee_address_word(), + call_gadget.callee_address(), ); // Add callee to access list @@ -122,7 +122,7 @@ impl ExecutionGadget for CallOpGadget { let is_warm_prev = cb.query_bool(); cb.account_access_list_write_unchecked( tx_id.expr(), - call_gadget.callee_address_word(), + call_gadget.callee_address(), is_warm.expr(), is_warm_prev.expr(), Some(&mut reversion_info), @@ -152,7 +152,7 @@ impl ExecutionGadget for CallOpGadget { }); let caller_balance_word = cb.query_word_unchecked(); - cb.account_read_word( + cb.account_read( caller_address.to_word(), AccountFieldTag::Balance, caller_balance_word.to_word(), diff --git a/zkevm-circuits/src/evm_circuit/execution/callvalue.rs b/zkevm-circuits/src/evm_circuit/execution/callvalue.rs index 6486e01418c..978452a58db 100644 --- a/zkevm-circuits/src/evm_circuit/execution/callvalue.rs +++ b/zkevm-circuits/src/evm_circuit/execution/callvalue.rs @@ -43,7 +43,7 @@ impl ExecutionGadget for CallValueGadget { ); // Push the value to the stack - cb.stack_push_word(call_value.to_word()); + cb.stack_push(call_value.to_word()); // State transition let opcode = cb.query_cell(); diff --git a/zkevm-circuits/src/evm_circuit/execution/chainid.rs b/zkevm-circuits/src/evm_circuit/execution/chainid.rs index 5a27fdc1881..920877f017f 100644 --- a/zkevm-circuits/src/evm_circuit/execution/chainid.rs +++ b/zkevm-circuits/src/evm_circuit/execution/chainid.rs @@ -34,10 +34,10 @@ impl ExecutionGadget for ChainIdGadget { let chain_id = cb.query_word_unchecked(); // Push the value to the stack - cb.stack_push_word(chain_id.to_word()); + cb.stack_push(chain_id.to_word()); // Lookup block table with chain_id - cb.block_lookup_word( + cb.block_lookup( BlockContextFieldTag::ChainId.expr(), None, chain_id.to_word(), diff --git a/zkevm-circuits/src/evm_circuit/execution/codecopy.rs b/zkevm-circuits/src/evm_circuit/execution/codecopy.rs index 6f1c65dbeb6..c95902b885d 100644 --- a/zkevm-circuits/src/evm_circuit/execution/codecopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/codecopy.rs @@ -61,9 +61,9 @@ impl ExecutionGadget for CodeCopyGadget { let code_offset = WordByteCapGadget::construct(cb, code_size.expr()); // Pop items from stack. - cb.stack_pop_word(dst_memory_offset.to_word()); - cb.stack_pop_word(code_offset.original_word_new().to_word()); - cb.stack_pop_word(Word::from_lo_unchecked(length.expr())); + cb.stack_pop(dst_memory_offset.to_word()); + cb.stack_pop(code_offset.original_word().to_word()); + cb.stack_pop(Word::from_lo_unchecked(length.expr())); // Construct memory address in the destionation (memory) to which we copy code. let dst_memory_addr = MemoryAddressGadget::construct(cb, dst_memory_offset, length); @@ -72,7 +72,7 @@ impl ExecutionGadget for CodeCopyGadget { let code_hash = cb.curr.state.code_hash.clone(); // Fetch the bytecode length from the bytecode table. - cb.bytecode_length_word(code_hash.to_word(), code_size.expr()); + cb.bytecode_length(code_hash.to_word(), code_size.expr()); // Calculate the next memory size and the gas cost for this memory // access. This also accounts for the dynamic gas required to copy bytes to diff --git a/zkevm-circuits/src/evm_circuit/execution/codesize.rs b/zkevm-circuits/src/evm_circuit/execution/codesize.rs index 383c3ba4c3b..cab8f2253ca 100644 --- a/zkevm-circuits/src/evm_circuit/execution/codesize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/codesize.rs @@ -38,7 +38,7 @@ impl ExecutionGadget for CodesizeGadget { let code_hash = cb.curr.state.code_hash.clone(); let codesize = cb.query_cell(); - cb.bytecode_length_word(code_hash.to_word(), codesize.expr()); + cb.bytecode_length(code_hash.to_word(), codesize.expr()); cb.require_equal( "Constraint: bytecode length lookup == codesize", @@ -46,7 +46,7 @@ impl ExecutionGadget for CodesizeGadget { codesize.expr(), ); - cb.stack_push_word(codesize_bytes.to_word()); + cb.stack_push(codesize_bytes.to_word()); let step_state_transition = StepStateTransition { gas_left: Transition::Delta(-OpcodeId::CODESIZE.constant_gas_cost().expr()), diff --git a/zkevm-circuits/src/evm_circuit/execution/comparator.rs b/zkevm-circuits/src/evm_circuit/execution/comparator.rs index 2df90a1be53..efcb8779924 100644 --- a/zkevm-circuits/src/evm_circuit/execution/comparator.rs +++ b/zkevm-circuits/src/evm_circuit/execution/comparator.rs @@ -62,9 +62,9 @@ impl ExecutionGadget for ComparatorGadget { // When swap is enabled we swap stack places between a and b. // We can push result here directly because // it only uses the LSB of a word. - cb.stack_pop_word(Word::select(is_gt.expr(), b.to_word(), a.to_word())); - cb.stack_pop_word(Word::select(is_gt.expr(), a.to_word(), b.to_word())); - cb.stack_push_word(Word::from_lo_unchecked(result.expr())); + cb.stack_pop(Word::select(is_gt.expr(), b.to_word(), a.to_word())); + cb.stack_pop(Word::select(is_gt.expr(), a.to_word(), b.to_word())); + cb.stack_push(Word::from_lo_unchecked(result.expr())); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/create.rs b/zkevm-circuits/src/evm_circuit/execution/create.rs index 1292618ef4d..deae88fe8b8 100644 --- a/zkevm-circuits/src/evm_circuit/execution/create.rs +++ b/zkevm-circuits/src/evm_circuit/execution/create.rs @@ -115,24 +115,24 @@ impl ExecutionGadget< let value = cb.query_word32(); let length = cb.query_memory_address(); let offset = cb.query_word_unchecked(); - cb.stack_pop_word(value.to_word()); - cb.stack_pop_word(offset.to_word()); - cb.stack_pop_word(length.to_word()); + cb.stack_pop(value.to_word()); + cb.stack_pop(offset.to_word()); + cb.stack_pop(length.to_word()); cb.condition(is_create2.expr(), |cb| { - cb.stack_pop_word(create.salt_word()); + cb.stack_pop(create.salt()); }); - cb.stack_push_word(contract_addr.to_word().mul_selector(is_success.expr())); + cb.stack_push(contract_addr.to_word().mul_selector(is_success.expr())); // read caller's balance and nonce let caller_nonce = create.caller_nonce(); let caller_balance = cb.query_word_unchecked(); - cb.account_read_word( - create.caller_address_word(), + cb.account_read( + create.caller_address(), AccountFieldTag::Balance, caller_balance.to_word(), ); - cb.account_read_word( - create.caller_address_word(), + cb.account_read( + create.caller_address(), AccountFieldTag::Nonce, Word::from_lo_unchecked(caller_nonce.expr()), ); @@ -173,8 +173,8 @@ impl ExecutionGadget< let callee_nonce = cb.query_cell(); let not_address_collision = cb.condition(is_precheck_ok.expr(), |cb| { // increase caller's nonce - cb.account_write_word( - create.caller_address_word(), + cb.account_write( + create.caller_address(), AccountFieldTag::Nonce, Word::from_lo_unchecked(caller_nonce.expr() + 1.expr()), Word::from_lo_unchecked(caller_nonce.expr()), @@ -191,7 +191,7 @@ impl ExecutionGadget< ); // read contract's previous hash - cb.account_read_word( + cb.account_read( contract_addr.to_word(), AccountFieldTag::CodeHash, prev_code_hash.to_word(), @@ -206,9 +206,9 @@ impl ExecutionGadget< IsZeroWordGadget::construct( cb, &Word::from_lo_unchecked(callee_nonce.expr()).add_unchecked( - prev_code_hash_word.clone().mul_unchecked( - prev_code_hash_word.sub_unchecked(cb.empty_code_hash_word()), - ), + prev_code_hash_word + .clone() + .mul_unchecked(prev_code_hash_word.sub_unchecked(cb.empty_code_hash())), ), ) }); @@ -251,7 +251,7 @@ impl ExecutionGadget< cb.copy_table_lookup( Word::from_lo_unchecked(current_call_id.expr()), CopyDataType::Memory.expr(), - create.code_hash_word(), + create.code_hash(), CopyDataType::Bytecode.expr(), init_code.offset(), init_code.address(), @@ -263,7 +263,7 @@ impl ExecutionGadget< }); // keccak table lookup to verify contract address. - cb.keccak_table_lookup_word( + cb.keccak_table_lookup( create.input_rlc(cb), create.input_length(), keccak_output.to_word(), @@ -279,7 +279,7 @@ impl ExecutionGadget< // transfer let transfer = TransferGadget::construct( cb, - create.caller_address_word(), + create.caller_address(), contract_addr.to_word(), 0.expr(), 1.expr(), @@ -288,7 +288,7 @@ impl ExecutionGadget< ); // EIP 161, the nonce of a newly created contract is 1 - cb.account_write_word( + cb.account_write( contract_addr.to_word(), AccountFieldTag::Nonce, Word::one(), @@ -314,10 +314,7 @@ impl ExecutionGadget< CallContextFieldTag::TxId, Word::from_lo_unchecked(tx_id.expr()), ), - ( - CallContextFieldTag::CallerAddress, - create.caller_address_word(), - ), + (CallContextFieldTag::CallerAddress, create.caller_address()), (CallContextFieldTag::CalleeAddress, contract_addr.to_word()), ( CallContextFieldTag::RwCounterEndOfReversion, @@ -341,7 +338,7 @@ impl ExecutionGadget< CallContextFieldTag::IsCreate, Word::from_lo_unchecked(true.expr()), ), - (CallContextFieldTag::CodeHash, create.code_hash_word()), + (CallContextFieldTag::CodeHash, create.code_hash()), ] { cb.call_context_lookup_write(Some(callee_call_id.expr()), field_tag, value); } @@ -352,7 +349,7 @@ impl ExecutionGadget< call_id: To(callee_call_id.expr()), is_root: To(false.expr()), is_create: To(true.expr()), - code_hash: To(create.code_hash_word()), + code_hash: To(create.code_hash()), gas_left: To(callee_gas_left), reversible_write_counter: To( 1.expr() + transfer.reversible_w_delta().expr() diff --git a/zkevm-circuits/src/evm_circuit/execution/dummy.rs b/zkevm-circuits/src/evm_circuit/execution/dummy.rs index 1388a023e29..425aa1a4435 100644 --- a/zkevm-circuits/src/evm_circuit/execution/dummy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/dummy.rs @@ -30,10 +30,10 @@ impl let pops: [WordCell; N_POP] = [(); N_POP].map(|_| cb.query_word_unchecked()); let pushes: [WordCell; N_PUSH] = [(); N_PUSH].map(|_| cb.query_word_unchecked()); for pop in pops.iter() { - cb.stack_pop_word(pop.to_word()); + cb.stack_pop(pop.to_word()); } for push in pushes.iter() { - cb.stack_push_word(push.to_word()); + cb.stack_push(push.to_word()); } Self { pops, diff --git a/zkevm-circuits/src/evm_circuit/execution/dup.rs b/zkevm-circuits/src/evm_circuit/execution/dup.rs index c3ebe5827b0..49c2a58a0a3 100644 --- a/zkevm-circuits/src/evm_circuit/execution/dup.rs +++ b/zkevm-circuits/src/evm_circuit/execution/dup.rs @@ -38,8 +38,8 @@ impl ExecutionGadget for DupGadget { let dup_offset = opcode.expr() - OpcodeId::DUP1.expr(); // Peek the value at `dup_offset` and push the value on the stack - cb.stack_lookup_word(false.expr(), dup_offset, value.to_word()); - cb.stack_push_word(value.to_word()); + cb.stack_lookup(false.expr(), dup_offset, value.to_word()); + cb.stack_push(value.to_word()); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/end_block.rs b/zkevm-circuits/src/evm_circuit/execution/end_block.rs index 1f1d39c9a66..30b743417cc 100644 --- a/zkevm-circuits/src/evm_circuit/execution/end_block.rs +++ b/zkevm-circuits/src/evm_circuit/execution/end_block.rs @@ -68,7 +68,7 @@ impl ExecutionGadget for EndBlockGadget { // Verify that there are at most total_txs meaningful txs in the tx_table, by // showing that the Tx following the last processed one has // CallerAddress = 0x0 (which means padding tx). - cb.tx_context_lookup_word( + cb.tx_context_lookup( total_txs.expr() + 1.expr(), TxContextFieldTag::CallerAddress, None, diff --git a/zkevm-circuits/src/evm_circuit/execution/end_tx.rs b/zkevm-circuits/src/evm_circuit/execution/end_tx.rs index 504af8cfb14..97e16927bd9 100644 --- a/zkevm-circuits/src/evm_circuit/execution/end_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/end_tx.rs @@ -93,7 +93,7 @@ impl ExecutionGadget for EndTxGadget { (BlockContextFieldTag::Coinbase, coinbase.to_word()), (BlockContextFieldTag::BaseFee, base_fee.to_word()), ] { - cb.block_lookup_word(tag.expr(), None, value); + cb.block_lookup(tag.expr(), None, value); } let effective_tip = cb.query_word32(); let sub_gas_price_by_base_fee = 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 4e9e9e805c9..3007f030339 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs @@ -64,20 +64,20 @@ impl ExecutionGadget for ErrorInvalidJumpGadget { let is_condition_zero = IsZeroWordGadget::construct(cb, &condition); // Pop the value from the stack - cb.stack_pop_word(dest.original_word_new().to_word()); + cb.stack_pop(dest.original_word().to_word()); cb.condition(is_jumpi.expr(), |cb| { - cb.stack_pop_word(condition.to_word()); + cb.stack_pop(condition.to_word()); // if condition is zero, jump will not happen, so constrain condition not zero cb.require_zero("condition is not zero", is_condition_zero.expr()); }); // Look up bytecode length - cb.bytecode_length_word(cb.curr.state.code_hash.to_word(), code_len.expr()); + cb.bytecode_length(cb.curr.state.code_hash.to_word(), code_len.expr()); // If destination is in valid range, lookup for the value. cb.condition(dest.lt_cap(), |cb| { - cb.bytecode_lookup_word( + cb.bytecode_lookup( cb.curr.state.code_hash.to_word(), dest.valid_value(), is_code.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs index 47fde088ac2..41dad3a55fc 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs @@ -64,11 +64,7 @@ impl ExecutionGadget for ErrorOOGCallGadget { // Add callee to access list let is_warm = cb.query_bool(); - cb.account_access_list_read( - tx_id.expr(), - call_gadget.callee_address_word(), - is_warm.expr(), - ); + cb.account_access_list_read(tx_id.expr(), call_gadget.callee_address(), is_warm.expr()); cb.condition(call_gadget.has_value.expr(), |cb| { cb.require_zero( diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_exp.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_exp.rs index c261faa6a2d..aa158548927 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_exp.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_exp.rs @@ -50,8 +50,8 @@ impl ExecutionGadget for ErrorOOGExpGadget { let base = cb.query_word32(); let exponent = cb.query_word32(); - cb.stack_pop_word(base.to_word()); - cb.stack_pop_word(exponent.to_word()); + cb.stack_pop(base.to_word()); + cb.stack_pop(exponent.to_word()); let exponent_byte_size = ByteSizeGadget::construct( cb, diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_log.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_log.rs index 8fae3291aa9..8d3db429604 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_log.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_log.rs @@ -45,8 +45,8 @@ impl ExecutionGadget for ErrorOOGLogGadget { let msize = cb.query_memory_address(); // Pop mstart_address, msize from stack - cb.stack_pop_word(mstart.to_word()); - cb.stack_pop_word(msize.to_word()); + cb.stack_pop(mstart.to_word()); + cb.stack_pop(msize.to_word()); // constrain not in static call let is_static_call = cb.call_context(None, CallContextFieldTag::IsStatic); diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_memory_copy.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_memory_copy.rs index 49fd53e2922..8abefb45333 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_memory_copy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_memory_copy.rs @@ -85,12 +85,12 @@ impl ExecutionGadget for ErrorOOGMemoryCopyGadget { cb.account_access_list_read(tx_id.expr(), external_address.to_word(), is_warm.expr()); // EXTCODECOPY has an extra stack pop for external address. - cb.stack_pop_word(external_address.to_word()); + cb.stack_pop(external_address.to_word()); }); - cb.stack_pop_word(dst_offset.to_word()); - cb.stack_pop_word(src_offset.to_word()); - cb.stack_pop_word(copy_size.to_word()); + cb.stack_pop(dst_offset.to_word()); + cb.stack_pop(src_offset.to_word()); + cb.stack_pop(copy_size.to_word()); let dst_memory_addr = MemoryAddressGadget::construct(cb, dst_offset, copy_size); let memory_expansion = MemoryExpansionGadget::construct(cb, [dst_memory_addr.address()]); diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs index b3d3f1953e8..d35f24d9b73 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs @@ -76,8 +76,8 @@ impl ExecutionGadget for ErrorOOGSloadSstoreGadget { let original_value = cb.query_word_unchecked(); let is_warm = cb.query_bool(); - cb.stack_pop_word(key.to_word()); - cb.account_storage_access_list_read_word( + cb.stack_pop(key.to_word()); + cb.account_storage_access_list_read( tx_id.expr(), callee_address.to_word(), key.to_word(), @@ -86,9 +86,9 @@ impl ExecutionGadget for ErrorOOGSloadSstoreGadget { let sload_gas_cost = SloadGasGadget::construct(cb, is_warm.expr()); let sstore_gas_cost = cb.condition(is_sstore.expr().0, |cb| { - cb.stack_pop_word(value.to_word()); + cb.stack_pop(value.to_word()); - cb.account_storage_read_word( + cb.account_storage_read( callee_address.to_word(), key.to_word(), value_prev.to_word(), diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs index 03c60d422e2..50ca74e6051 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs @@ -57,11 +57,11 @@ impl ExecutionGadget for ErrorOOGStaticMemoryGadget { // Get the next memory size and the gas cost for this memory access let memory_expansion = MemoryExpansionGadget::construct( cb, - [address_low::expr_word(&address) + 1.expr() + (is_not_mstore8 * 31.expr())], + [address_low::expr(&address) + 1.expr() + (is_not_mstore8 * 31.expr())], ); // Check if the memory address is too large - let address_in_range = IsZeroGadget::construct(cb, address_high::expr_word(&address)); + let address_in_range = IsZeroGadget::construct(cb, address_high::expr(&address)); // Check if the amount of gas available is less than the amount of gas // required let insufficient_gas = cb.condition(address_in_range.expr(), |cb| { @@ -74,7 +74,7 @@ impl ExecutionGadget for ErrorOOGStaticMemoryGadget { // Pop the address from the stack // We still have to do this to verify the correctness of `address` - cb.stack_pop_word(address.to_word()); + cb.stack_pop(address.to_word()); // TODO: Use ContextSwitchGadget to switch call context to caller's and // consume all gas_left. diff --git a/zkevm-circuits/src/evm_circuit/execution/error_return_data_oo_bound.rs b/zkevm-circuits/src/evm_circuit/execution/error_return_data_oo_bound.rs index 1d1d35bd9a9..0b045465376 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_return_data_oo_bound.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_return_data_oo_bound.rs @@ -56,9 +56,9 @@ impl ExecutionGadget for ErrorReturnDataOutOfBoundGadget { ); // Pop memory_offset, offset, size from stack - cb.stack_pop_word(memory_offset.to_word()); - cb.stack_pop_word(data_offset.to_word()); - cb.stack_pop_word(size.to_word()); + cb.stack_pop(memory_offset.to_word()); + cb.stack_pop(data_offset.to_word()); + cb.stack_pop(size.to_word()); // Read last callee return data length cb.call_context_lookup_read( diff --git a/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs b/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs index f10f3b89021..445fd45daf0 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs @@ -66,9 +66,9 @@ impl ExecutionGadget for ErrorWriteProtectionGadget { // Lookup values from stack if opcode is call // Precondition: If there's a StackUnderflow CALL, is handled before this error cb.condition(is_call.expr(), |cb| { - cb.stack_pop_word(gas_word.to_word()); - cb.stack_pop_word(code_address.to_word()); - cb.stack_pop_word(value.to_word()); + cb.stack_pop(gas_word.to_word()); + cb.stack_pop(code_address.to_word()); + cb.stack_pop(value.to_word()); cb.require_zero("value of call is not zero", is_value_zero.expr()); }); diff --git a/zkevm-circuits/src/evm_circuit/execution/exp.rs b/zkevm-circuits/src/evm_circuit/execution/exp.rs index 2e8b3eac363..0945e2819eb 100644 --- a/zkevm-circuits/src/evm_circuit/execution/exp.rs +++ b/zkevm-circuits/src/evm_circuit/execution/exp.rs @@ -63,11 +63,11 @@ impl ExecutionGadget for ExponentiationGadget { let exponentiation = cb.query_word32(); // Pop RLC-encoded base and exponent from the stack. - cb.stack_pop_word(base.to_word()); - cb.stack_pop_word(exponent.to_word()); + cb.stack_pop(base.to_word()); + cb.stack_pop(exponent.to_word()); // Push RLC-encoded exponentiation to the stack. - cb.stack_push_word(exponentiation.to_word()); + cb.stack_push(exponentiation.to_word()); // Extract low and high bytes of the base. let (base_lo, base_hi) = base.to_word().to_lo_hi(); diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs b/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs index 2b80d9dcf65..3187fc78076 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs @@ -66,10 +66,10 @@ impl ExecutionGadget for ExtcodecopyGadget { let memory_offset = cb.query_word_unchecked(); let code_offset = WordByteCapGadget::construct(cb, code_size.expr()); - cb.stack_pop_word(external_address_word.to_word()); - cb.stack_pop_word(memory_offset.to_word()); - cb.stack_pop_word(code_offset.original_word_new().to_word()); - cb.stack_pop_word(memory_length.to_word()); + cb.stack_pop(external_address_word.to_word()); + cb.stack_pop(memory_offset.to_word()); + cb.stack_pop(code_offset.original_word().to_word()); + cb.stack_pop(memory_length.to_word()); let tx_id = cb.call_context(None, CallContextFieldTag::TxId); let mut reversion_info = cb.reversion_info_read(None); @@ -83,7 +83,7 @@ impl ExecutionGadget for ExtcodecopyGadget { ); let code_hash = cb.query_word32(); - cb.account_read_word( + cb.account_read( external_address.to_word(), AccountFieldTag::CodeHash, code_hash.to_word(), @@ -91,7 +91,7 @@ impl ExecutionGadget for ExtcodecopyGadget { let not_exists = IsZeroWordGadget::construct(cb, &code_hash.to_word()); let exists = not::expr(not_exists.expr()); cb.condition(exists.expr(), |cb| { - cb.bytecode_length_word(code_hash.to_word(), code_size.expr()); + cb.bytecode_length(code_hash.to_word(), code_size.expr()); }); cb.condition(not_exists.expr(), |cb| { cb.require_zero("code_size is zero when non_exists", code_size.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs b/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs index caca0f704f0..73318ba5d29 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs @@ -44,7 +44,7 @@ impl ExecutionGadget for ExtcodehashGadget { .try_into() .unwrap(), ); - cb.stack_pop_word(address_word.to_word()); + cb.stack_pop(address_word.to_word()); let tx_id = cb.call_context(None, CallContextFieldTag::TxId); let mut reversion_info = cb.reversion_info_read(None); @@ -61,12 +61,12 @@ impl ExecutionGadget for ExtcodehashGadget { // range check will be cover by account code_hash lookup let code_hash = cb.query_word_unchecked(); // For non-existing accounts the code_hash must be 0 in the rw_table. - cb.account_read_word( + cb.account_read( address.to_word(), AccountFieldTag::CodeHash, code_hash.to_word(), ); - cb.stack_push_word(code_hash.to_word()); + cb.stack_push(code_hash.to_word()); let gas_cost = select::expr( is_warm.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs b/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs index 273bec425f5..702b2ce2943 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs @@ -48,7 +48,7 @@ impl ExecutionGadget for ExtcodesizeGadget { .try_into() .unwrap(), ); - cb.stack_pop_word(address_word.to_word()); + cb.stack_pop(address_word.to_word()); let tx_id = cb.call_context(None, CallContextFieldTag::TxId); let mut reversion_info = cb.reversion_info_read(None); @@ -64,7 +64,7 @@ impl ExecutionGadget for ExtcodesizeGadget { // range check will be cover by account code_hash lookup let code_hash = cb.query_word_unchecked(); // For non-existing accounts the code_hash must be 0 in the rw_table. - cb.account_read_word( + cb.account_read( address.to_word(), AccountFieldTag::CodeHash, code_hash.to_word(), @@ -74,13 +74,13 @@ impl ExecutionGadget for ExtcodesizeGadget { let code_size = cb.query_u64(); cb.condition(exists.expr(), |cb| { - cb.bytecode_length_word(code_hash.to_word(), code_size.expr()); + cb.bytecode_length(code_hash.to_word(), code_size.expr()); }); cb.condition(not_exists.expr(), |cb| { cb.require_zero("code_size is zero when non_exists", code_size.expr()); }); - cb.stack_push_word(code_size.to_word()); + cb.stack_push(code_size.to_word()); let gas_cost = select::expr( is_warm.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/gas.rs b/zkevm-circuits/src/evm_circuit/execution/gas.rs index d2e992199e3..e5486ad1db3 100644 --- a/zkevm-circuits/src/evm_circuit/execution/gas.rs +++ b/zkevm-circuits/src/evm_circuit/execution/gas.rs @@ -41,7 +41,7 @@ impl ExecutionGadget for GasGadget { ); // Construct the value and push it to stack. - cb.stack_push_word(gas_left.to_word()); + cb.stack_push(gas_left.to_word()); let step_state_transition = StepStateTransition { rw_counter: Delta(1.expr()), diff --git a/zkevm-circuits/src/evm_circuit/execution/gasprice.rs b/zkevm-circuits/src/evm_circuit/execution/gasprice.rs index 3fcd9e8acad..943372af722 100644 --- a/zkevm-circuits/src/evm_circuit/execution/gasprice.rs +++ b/zkevm-circuits/src/evm_circuit/execution/gasprice.rs @@ -38,7 +38,7 @@ impl ExecutionGadget for GasPriceGadget { // Lookup in call_ctx the TxId let tx_id = cb.call_context(None, CallContextFieldTag::TxId); // Lookup the gas_price in tx table - cb.tx_context_lookup_word( + cb.tx_context_lookup( tx_id.expr(), TxContextFieldTag::GasPrice, None, @@ -46,7 +46,7 @@ impl ExecutionGadget for GasPriceGadget { ); // Push the value to the stack - cb.stack_push_word(gas_price.to_word()); + cb.stack_push(gas_price.to_word()); // State transition let opcode = cb.query_cell(); diff --git a/zkevm-circuits/src/evm_circuit/execution/is_zero.rs b/zkevm-circuits/src/evm_circuit/execution/is_zero.rs index f0b4fc237a3..ec8b7334e6e 100644 --- a/zkevm-circuits/src/evm_circuit/execution/is_zero.rs +++ b/zkevm-circuits/src/evm_circuit/execution/is_zero.rs @@ -36,8 +36,8 @@ impl ExecutionGadget for IsZeroGadget { let value = cb.query_word_unchecked(); let is_zero_word = math_gadget::IsZeroWordGadget::construct(cb, &value); - cb.stack_pop_word(value.to_word()); - cb.stack_push_word(Word::from_lo_unchecked(is_zero_word.expr())); + cb.stack_pop(value.to_word()); + cb.stack_push(Word::from_lo_unchecked(is_zero_word.expr())); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/jump.rs b/zkevm-circuits/src/evm_circuit/execution/jump.rs index af644d01ab7..f99a4669933 100644 --- a/zkevm-circuits/src/evm_circuit/execution/jump.rs +++ b/zkevm-circuits/src/evm_circuit/execution/jump.rs @@ -32,7 +32,7 @@ impl ExecutionGadget for JumpGadget { let destination = cb.query_u64(); // Pop the value from the stack - cb.stack_pop_word(destination.to_word()); + cb.stack_pop(destination.to_word()); // Lookup opcode at destination cb.opcode_lookup_at(destination.expr(), OpcodeId::JUMPDEST.expr(), 1.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/jumpi.rs b/zkevm-circuits/src/evm_circuit/execution/jumpi.rs index a8bdb36e853..5697e8f0e22 100644 --- a/zkevm-circuits/src/evm_circuit/execution/jumpi.rs +++ b/zkevm-circuits/src/evm_circuit/execution/jumpi.rs @@ -40,8 +40,8 @@ impl ExecutionGadget for JumpiGadget { let condition = cb.query_word_unchecked(); // Pop the value from the stack - cb.stack_pop_word(dest.original()); - cb.stack_pop_word(condition.to_word()); + cb.stack_pop(dest.original()); + cb.stack_pop(condition.to_word()); // Determine if the jump condition is met let is_condition_zero = IsZeroWordGadget::construct(cb, &condition); diff --git a/zkevm-circuits/src/evm_circuit/execution/logs.rs b/zkevm-circuits/src/evm_circuit/execution/logs.rs index 0c4f8fe6f6c..14c5485b7df 100644 --- a/zkevm-circuits/src/evm_circuit/execution/logs.rs +++ b/zkevm-circuits/src/evm_circuit/execution/logs.rs @@ -55,8 +55,8 @@ impl ExecutionGadget for LogGadget { let msize = cb.query_memory_address(); // Pop mstart_address, msize from stack - cb.stack_pop_word(mstart.to_word()); - cb.stack_pop_word(msize.to_word()); + cb.stack_pop(mstart.to_word()); + cb.stack_pop(msize.to_word()); // read tx id let tx_id = cb.call_context(None, CallContextFieldTag::TxId); // constrain not in static call @@ -71,7 +71,7 @@ impl ExecutionGadget for LogGadget { cb.require_boolean("is_persistent is bool", is_persistent.expr()); cb.condition(is_persistent.expr(), |cb| { - cb.tx_log_lookup_word( + cb.tx_log_lookup( tx_id.expr(), cb.curr.state.log_id.expr() + 1.expr(), TxLogFieldTag::Address, @@ -85,10 +85,10 @@ impl ExecutionGadget for LogGadget { let topic_selectors: [Cell; 4] = array_init(|_| cb.query_cell()); for (idx, topic) in topics.iter().enumerate() { cb.condition(topic_selectors[idx].expr(), |cb| { - cb.stack_pop_word(topic.to_word()); + cb.stack_pop(topic.to_word()); }); cb.condition(topic_selectors[idx].expr() * is_persistent.expr(), |cb| { - cb.tx_log_lookup_word( + cb.tx_log_lookup( tx_id.expr(), cb.curr.state.log_id.expr() + 1.expr(), TxLogFieldTag::Topic, diff --git a/zkevm-circuits/src/evm_circuit/execution/memory.rs b/zkevm-circuits/src/evm_circuit/execution/memory.rs index e120e4be065..9138397b130 100644 --- a/zkevm-circuits/src/evm_circuit/execution/memory.rs +++ b/zkevm-circuits/src/evm_circuit/execution/memory.rs @@ -63,10 +63,10 @@ impl ExecutionGadget for MemoryGadget { // Stack operations // Pop the address from the stack - cb.stack_pop_word(address.to_word()); + cb.stack_pop(address.to_word()); // For MLOAD push the value to the stack // FOR MSTORE pop the value from the stack - cb.stack_lookup_word( + cb.stack_lookup( is_mload.expr(), cb.stack_pointer_offset().expr() - is_mload.expr(), value.to_word(), diff --git a/zkevm-circuits/src/evm_circuit/execution/msize.rs b/zkevm-circuits/src/evm_circuit/execution/msize.rs index 8e76cb8aa9c..2c34f0d9588 100644 --- a/zkevm-circuits/src/evm_circuit/execution/msize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/msize.rs @@ -42,7 +42,7 @@ impl ExecutionGadget for MsizeGadget { ); // Push the value on the stack - cb.stack_push_word(Word::from_lo_unchecked(value.expr())); + cb.stack_push(Word::from_lo_unchecked(value.expr())); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs b/zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs index 2f11516200e..bef4c22c266 100644 --- a/zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs +++ b/zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs @@ -71,9 +71,9 @@ impl ExecutionGadget for MulDivModGadget { // The second pop is multiplicand for MUL and divisor for DIV/MOD // The push is product for MUL, quotient for DIV, and residue for MOD // Note that for DIV/MOD, when divisor == 0, the push value is also 0. - cb.stack_pop_word(Word::select(is_mul.clone(), a.to_word(), d.to_word())); - cb.stack_pop_word(b.to_word()); - cb.stack_push_word( + cb.stack_pop(Word::select(is_mul.clone(), a.to_word(), d.to_word())); + cb.stack_pop(b.to_word()); + cb.stack_push( d.to_word() .mul_selector(is_mul.clone()) .add_unchecked( diff --git a/zkevm-circuits/src/evm_circuit/execution/mulmod.rs b/zkevm-circuits/src/evm_circuit/execution/mulmod.rs index 5a091aac49f..c4b140b18e3 100644 --- a/zkevm-circuits/src/evm_circuit/execution/mulmod.rs +++ b/zkevm-circuits/src/evm_circuit/execution/mulmod.rs @@ -77,10 +77,10 @@ impl ExecutionGadget for MulModGadget { 1.expr() - lt.expr() - n_is_zero.expr(), ); - cb.stack_pop_word(a.to_word()); - cb.stack_pop_word(b.to_word()); - cb.stack_pop_word(n.to_word()); - cb.stack_push_word(r.to_word()); + cb.stack_pop(a.to_word()); + cb.stack_pop(b.to_word()); + cb.stack_pop(n.to_word()); + cb.stack_push(r.to_word()); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/not.rs b/zkevm-circuits/src/evm_circuit/execution/not.rs index 398272d83d9..d60e4dbbd8d 100644 --- a/zkevm-circuits/src/evm_circuit/execution/not.rs +++ b/zkevm-circuits/src/evm_circuit/execution/not.rs @@ -36,8 +36,8 @@ impl ExecutionGadget for NotGadget { let input = cb.query_word32(); let output = cb.query_word32(); - cb.stack_pop_word(input.to_word()); - cb.stack_push_word(output.to_word()); + cb.stack_pop(input.to_word()); + cb.stack_push(output.to_word()); for (i, o) in input.limbs.iter().zip(output.limbs.iter()) { cb.add_lookup( diff --git a/zkevm-circuits/src/evm_circuit/execution/origin.rs b/zkevm-circuits/src/evm_circuit/execution/origin.rs index 27f201fabf3..bc0003c81b6 100644 --- a/zkevm-circuits/src/evm_circuit/execution/origin.rs +++ b/zkevm-circuits/src/evm_circuit/execution/origin.rs @@ -34,7 +34,7 @@ impl ExecutionGadget for OriginGadget { // Lookup in call_ctx the TxId let tx_id = cb.call_context(None, CallContextFieldTag::TxId); // Lookup rw_table -> call_context with tx origin address - cb.tx_context_lookup_word( + cb.tx_context_lookup( tx_id.expr(), TxContextFieldTag::CallerAddress, None, // None because unrelated to calldata @@ -42,7 +42,7 @@ impl ExecutionGadget for OriginGadget { ); // Push the value to the stack - cb.stack_push_word(origin.to_word()); + cb.stack_push(origin.to_word()); // State transition let opcode = cb.query_cell(); diff --git a/zkevm-circuits/src/evm_circuit/execution/pc.rs b/zkevm-circuits/src/evm_circuit/execution/pc.rs index 927aadd7458..b89f28e789e 100644 --- a/zkevm-circuits/src/evm_circuit/execution/pc.rs +++ b/zkevm-circuits/src/evm_circuit/execution/pc.rs @@ -40,7 +40,7 @@ impl ExecutionGadget for PcGadget { ); // Push the value on the stack - cb.stack_push_word(value.to_word()); + cb.stack_push(value.to_word()); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/pop.rs b/zkevm-circuits/src/evm_circuit/execution/pop.rs index 0914c107ebd..bb69d8f13b8 100644 --- a/zkevm-circuits/src/evm_circuit/execution/pop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/pop.rs @@ -33,7 +33,7 @@ impl ExecutionGadget for PopGadget { let value = cb.query_word_unchecked(); // Pop the value from the stack - cb.stack_pop_word(value.to_word()); + cb.stack_pop(value.to_word()); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/push.rs b/zkevm-circuits/src/evm_circuit/execution/push.rs index c6b88713c0b..2165347fc1b 100644 --- a/zkevm-circuits/src/evm_circuit/execution/push.rs +++ b/zkevm-circuits/src/evm_circuit/execution/push.rs @@ -98,7 +98,7 @@ impl ExecutionGadget for PushGadget { ); // Push the value on the stack - cb.stack_push_word(value.to_word()); + cb.stack_push(value.to_word()); // State transition // `program_counter` needs to be increased by number of bytes pushed + 1 diff --git a/zkevm-circuits/src/evm_circuit/execution/return_revert.rs b/zkevm-circuits/src/evm_circuit/execution/return_revert.rs index 48af306e0d7..985c815e5e1 100644 --- a/zkevm-circuits/src/evm_circuit/execution/return_revert.rs +++ b/zkevm-circuits/src/evm_circuit/execution/return_revert.rs @@ -61,8 +61,8 @@ impl ExecutionGadget for ReturnRevertGadget { let offset = cb.query_word_unchecked(); let length = cb.query_memory_address(); - cb.stack_pop_word(offset.to_word()); - cb.stack_pop_word(length.to_word()); + cb.stack_pop(offset.to_word()); + cb.stack_pop(length.to_word()); let range = MemoryAddressGadget::construct(cb, offset, length); let is_success = cb.call_context(None, CallContextFieldTag::IsSuccess); @@ -126,11 +126,11 @@ impl ExecutionGadget for ReturnRevertGadget { let mut reversion_info = cb.reversion_info_read(None); - cb.account_write_word( + cb.account_write( address.to_word(), AccountFieldTag::CodeHash, code_hash.to_word(), - cb.empty_code_hash_word(), + cb.empty_code_hash(), Some(&mut reversion_info), ); diff --git a/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs b/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs index 6bda0ef5708..462e3632db9 100644 --- a/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs @@ -67,9 +67,9 @@ impl ExecutionGadget for ReturnDataCopyGadget { let size = cb.query_memory_address(); // 1. Pop dest_offset, offset, length from stack - cb.stack_pop_word(dest_offset.to_word()); - cb.stack_pop_word(Word::from_lo_unchecked(data_offset.expr())); - cb.stack_pop_word(Word::from_lo_unchecked(size.expr())); + cb.stack_pop(dest_offset.to_word()); + cb.stack_pop(Word::from_lo_unchecked(data_offset.expr())); + cb.stack_pop(Word::from_lo_unchecked(size.expr())); // 2. Add lookup constraint in the call context for the returndatacopy field. let last_callee_id = cb.query_cell(); diff --git a/zkevm-circuits/src/evm_circuit/execution/returndatasize.rs b/zkevm-circuits/src/evm_circuit/execution/returndatasize.rs index 96bba3753b7..14144d3aecd 100644 --- a/zkevm-circuits/src/evm_circuit/execution/returndatasize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/returndatasize.rs @@ -42,7 +42,7 @@ impl ExecutionGadget for ReturnDataSizeGadget { ); // The returndatasize should be pushed to the top of the stack. - cb.stack_push_word(return_data_size.to_word()); + cb.stack_push(return_data_size.to_word()); let step_state_transition = StepStateTransition { rw_counter: Delta(2.expr()), diff --git a/zkevm-circuits/src/evm_circuit/execution/sar.rs b/zkevm-circuits/src/evm_circuit/execution/sar.rs index bf68e4d0efe..9cfb4ac939e 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sar.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sar.rs @@ -85,9 +85,9 @@ impl ExecutionGadget for SarGadget { let a = cb.query_word32(); let b = cb.query_word32(); - cb.stack_pop_word(shift.to_word()); - cb.stack_pop_word(a.to_word()); - cb.stack_push_word(b.to_word()); + cb.stack_pop(shift.to_word()); + cb.stack_pop(a.to_word()); + cb.stack_push(b.to_word()); let a64s: Word4> = a.to_word_n(); let b64s: Word4> = b.to_word_n(); diff --git a/zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs b/zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs index 84bf7d47561..8bea99c940b 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs @@ -52,20 +52,20 @@ impl ExecutionGadget for SignedDivModGadget { let divisor_abs_word = AbsWordGadget::construct(cb); let remainder_abs_word = AbsWordGadget::construct(cb); let dividend_abs_word = AbsWordGadget::construct(cb); - let quotient_is_zero = IsZeroWordGadget::construct(cb, quotient_abs_word.x_word()); - let divisor_is_zero = IsZeroWordGadget::construct(cb, divisor_abs_word.x_word()); - let remainder_is_zero = IsZeroWordGadget::construct(cb, remainder_abs_word.x_word()); + let quotient_is_zero = IsZeroWordGadget::construct(cb, quotient_abs_word.x()); + let divisor_is_zero = IsZeroWordGadget::construct(cb, divisor_abs_word.x()); + let remainder_is_zero = IsZeroWordGadget::construct(cb, remainder_abs_word.x()); - cb.stack_pop_word(dividend_abs_word.x_word().to_word()); - cb.stack_pop_word(divisor_abs_word.x_word().to_word()); - cb.stack_push_word(Word::select( + cb.stack_pop(dividend_abs_word.x().to_word()); + cb.stack_pop(divisor_abs_word.x().to_word()); + cb.stack_push(Word::select( is_sdiv, quotient_abs_word - .x_word() + .x() .to_word() .mul_selector(1.expr() - divisor_is_zero.expr()), remainder_abs_word - .x_word() + .x() .to_word() .mul_selector(1.expr() - divisor_is_zero.expr()), )); @@ -74,18 +74,18 @@ impl ExecutionGadget for SignedDivModGadget { let mul_add_words = MulAddWordsGadget::construct( cb, [ - quotient_abs_word.x_abs_word(), - divisor_abs_word.x_abs_word(), - remainder_abs_word.x_abs_word(), - dividend_abs_word.x_abs_word(), + quotient_abs_word.x_abs(), + divisor_abs_word.x_abs(), + remainder_abs_word.x_abs(), + dividend_abs_word.x_abs(), ], ); cb.add_constraint("overflow == 0", mul_add_words.overflow()); let remainder_abs_lt_divisor_abs = LtWordGadget::construct( cb, - &remainder_abs_word.x_abs_word().to_word(), - &divisor_abs_word.x_abs_word().to_word(), + &remainder_abs_word.x_abs().to_word(), + &divisor_abs_word.x_abs().to_word(), ); cb.add_constraint( "abs(remainder) < abs(divisor) when divisor != 0", @@ -108,11 +108,8 @@ impl ExecutionGadget for SignedDivModGadget { // `(1 << 255) - 1`. So constraint // `sign(dividend) == sign(divisor) ^ sign(quotient)` cannot be applied // for this case. - let dividend_is_signed_overflow = LtGadget::construct( - cb, - 127.expr(), - dividend_abs_word.x_abs_word().limbs[31].expr(), - ); + let dividend_is_signed_overflow = + LtGadget::construct(cb, 127.expr(), dividend_abs_word.x_abs().limbs[31].expr()); // Constrain sign(dividend) == sign(divisor) ^ sign(quotient) when both // quotient and divisor are non-zero and dividend is not signed overflow. diff --git a/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs b/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs index ab47f904489..a222299ca03 100644 --- a/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs +++ b/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs @@ -35,13 +35,13 @@ impl ExecutionGadget for SelfbalanceGadget { let callee_address = cb.call_context_read_as_word(None, CallContextFieldTag::CalleeAddress); let self_balance = cb.query_word_unchecked(); - cb.account_read_word( + cb.account_read( callee_address.to_word(), AccountFieldTag::Balance, self_balance.to_word(), ); - cb.stack_push_word(self_balance.to_word()); + cb.stack_push(self_balance.to_word()); let opcode = cb.query_cell(); let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/sha3.rs b/zkevm-circuits/src/evm_circuit/execution/sha3.rs index 79a21175ce0..9ee37025306 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sha3.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sha3.rs @@ -45,9 +45,9 @@ impl ExecutionGadget for Sha3Gadget { let size = cb.query_memory_address(); let sha3_digest = cb.query_word_unchecked(); - cb.stack_pop_word(offset.to_word()); - cb.stack_pop_word(size.to_word()); - cb.stack_push_word(sha3_digest.to_word()); + cb.stack_pop(offset.to_word()); + cb.stack_pop(size.to_word()); + cb.stack_push(sha3_digest.to_word()); let memory_address = MemoryAddressGadget::construct(cb, offset, size); @@ -73,7 +73,7 @@ impl ExecutionGadget for Sha3Gadget { cb.require_zero("copy_rwc_inc == 0 for size = 0", copy_rwc_inc.expr()); cb.require_zero("rlc_acc == 0 for size = 0", rlc_acc.expr()); }); - cb.keccak_table_lookup_word( + cb.keccak_table_lookup( rlc_acc.expr(), memory_address.length(), sha3_digest.to_word(), diff --git a/zkevm-circuits/src/evm_circuit/execution/shl_shr.rs b/zkevm-circuits/src/evm_circuit/execution/shl_shr.rs index f5512daf610..a95a633101b 100644 --- a/zkevm-circuits/src/evm_circuit/execution/shl_shr.rs +++ b/zkevm-circuits/src/evm_circuit/execution/shl_shr.rs @@ -78,14 +78,14 @@ impl ExecutionGadget for ShlShrGadget { // Constrain stack pops and pushes as: // - for SHL, two pops are shift and quotient, and push is dividend. // - for SHR, two pops are shift and dividend, and push is quotient. - cb.stack_pop_word(shift.to_word()); - cb.stack_pop_word( + cb.stack_pop(shift.to_word()); + cb.stack_pop( quotient .to_word() .mul_selector(is_shl.expr()) .add_unchecked(dividend.to_word().mul_selector(is_shr.expr())), ); - cb.stack_push_word( + cb.stack_push( (dividend .to_word() .mul_selector(is_shl.expr()) diff --git a/zkevm-circuits/src/evm_circuit/execution/signed_comparator.rs b/zkevm-circuits/src/evm_circuit/execution/signed_comparator.rs index 207f721f73c..3f910d10fac 100644 --- a/zkevm-circuits/src/evm_circuit/execution/signed_comparator.rs +++ b/zkevm-circuits/src/evm_circuit/execution/signed_comparator.rs @@ -109,9 +109,9 @@ impl ExecutionGadget for SignedComparatorGadget { let result = a_neg_b_pos.clone() + (1.expr() - a_neg_b_pos - b_neg_a_pos) * a_lt_b.expr(); // Pop a and b from the stack, push the result on the stack. - cb.stack_pop_word(Word::select(is_sgt.expr(), b.to_word(), a.to_word())); - cb.stack_pop_word(Word::select(is_sgt.expr(), a.to_word(), b.to_word())); - cb.stack_push_word(Word::from_lo_unchecked(result)); + cb.stack_pop(Word::select(is_sgt.expr(), b.to_word(), a.to_word())); + cb.stack_pop(Word::select(is_sgt.expr(), a.to_word(), b.to_word())); + cb.stack_push(Word::from_lo_unchecked(result)); // The read-write counter changes by three since we're reading two words // from stack and writing one. The program counter shifts only by one diff --git a/zkevm-circuits/src/evm_circuit/execution/signextend.rs b/zkevm-circuits/src/evm_circuit/execution/signextend.rs index 2abaa64aed8..fbf48b3d2ce 100644 --- a/zkevm-circuits/src/evm_circuit/execution/signextend.rs +++ b/zkevm-circuits/src/evm_circuit/execution/signextend.rs @@ -128,9 +128,9 @@ impl ExecutionGadget for SignextendGadget { // Pop the byte index and the value from the stack, push the result on // the stack - cb.stack_pop_word(index.to_word()); - cb.stack_pop_word(value.to_word()); - cb.stack_push_word(result.to_word()); + cb.stack_pop(index.to_word()); + cb.stack_pop(value.to_word()); + cb.stack_push(result.to_word()); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/sload.rs b/zkevm-circuits/src/evm_circuit/execution/sload.rs index 795f015fd2c..750abbf7d81 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sload.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sload.rs @@ -46,11 +46,11 @@ impl ExecutionGadget for SloadGadget { let key = cb.query_word_unchecked(); // Pop the key from the stack - cb.stack_pop_word(key.to_word()); + cb.stack_pop(key.to_word()); let value = cb.query_word_unchecked(); let committed_value = cb.query_word_unchecked(); - cb.account_storage_read_word( + cb.account_storage_read( callee_address.to_word(), key.to_word(), value.to_word(), @@ -58,10 +58,10 @@ impl ExecutionGadget for SloadGadget { committed_value.to_word(), ); - cb.stack_push_word(value.to_word()); + cb.stack_push(value.to_word()); let is_warm = cb.query_bool(); - cb.account_storage_access_list_write_word( + cb.account_storage_access_list_write( tx_id.expr(), callee_address.to_word(), key.to_word(), diff --git a/zkevm-circuits/src/evm_circuit/execution/sstore.rs b/zkevm-circuits/src/evm_circuit/execution/sstore.rs index b172b963aa5..5c1927a4c8d 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sstore.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sstore.rs @@ -65,15 +65,15 @@ impl ExecutionGadget for SstoreGadget { let key = cb.query_word32(); // Pop the key from the stack - cb.stack_pop_word(key.to_word()); + cb.stack_pop(key.to_word()); let value = cb.query_word32(); // Pop the value from the stack - cb.stack_pop_word(value.to_word()); + cb.stack_pop(value.to_word()); let value_prev = cb.query_word32(); let original_value = cb.query_word32(); - cb.account_storage_write_word( + cb.account_storage_write( callee_address.to_word(), key.to_word(), value.to_word(), @@ -84,7 +84,7 @@ impl ExecutionGadget for SstoreGadget { ); let is_warm = cb.query_bool(); - cb.account_storage_access_list_write_word( + cb.account_storage_access_list_write( tx_id.expr(), callee_address.to_word(), key.to_word(), @@ -121,7 +121,7 @@ impl ExecutionGadget for SstoreGadget { value_prev.clone(), original_value.clone(), ); - cb.tx_refund_write_word( + cb.tx_refund_write( tx_id.expr(), Word::from_lo_unchecked(tx_refund.expr()), tx_refund_prev.to_word(), diff --git a/zkevm-circuits/src/evm_circuit/execution/stop.rs b/zkevm-circuits/src/evm_circuit/execution/stop.rs index fca4b8b194f..464b936f747 100644 --- a/zkevm-circuits/src/evm_circuit/execution/stop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/stop.rs @@ -38,7 +38,7 @@ impl ExecutionGadget for StopGadget { fn configure(cb: &mut EVMConstraintBuilder) -> Self { let code_length = cb.query_cell(); - cb.bytecode_length_word(cb.curr.state.code_hash.to_word(), code_length.expr()); + cb.bytecode_length(cb.curr.state.code_hash.to_word(), code_length.expr()); let is_out_of_range = IsZeroGadget::construct( cb, code_length.expr() - cb.curr.state.program_counter.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/swap.rs b/zkevm-circuits/src/evm_circuit/execution/swap.rs index 17e893a03b5..b9722f6e45c 100644 --- a/zkevm-circuits/src/evm_circuit/execution/swap.rs +++ b/zkevm-circuits/src/evm_circuit/execution/swap.rs @@ -38,13 +38,13 @@ impl ExecutionGadget for SwapGadget { let swap_offset = opcode.expr() - (OpcodeId::SWAP1.as_u64() - 1).expr(); // Peek the value at `swap_offset` - cb.stack_lookup_word(false.expr(), swap_offset.clone(), values[0].to_word()); + cb.stack_lookup(false.expr(), swap_offset.clone(), values[0].to_word()); // Peek the value at the top of the stack - cb.stack_lookup_word(false.expr(), 0.expr(), values[1].to_word()); + cb.stack_lookup(false.expr(), 0.expr(), values[1].to_word()); // Write the value previously at the top of the stack to `swap_offset` - cb.stack_lookup_word(true.expr(), swap_offset, values[1].to_word()); + cb.stack_lookup(true.expr(), swap_offset, values[1].to_word()); // Write the value previously at `swap_offset` to the top of the stack - cb.stack_lookup_word(true.expr(), 0.expr(), values[0].to_word()); + cb.stack_lookup(true.expr(), 0.expr(), values[0].to_word()); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/util.rs b/zkevm-circuits/src/evm_circuit/util.rs index 7975e0a636b..b70ffa7d807 100644 --- a/zkevm-circuits/src/evm_circuit/util.rs +++ b/zkevm-circuits/src/evm_circuit/util.rs @@ -13,8 +13,7 @@ use crate::{ util::int_decomposition::IntDecomposition, witness::{Block, ExecStep, Rw, RwMap}, }; -use bus_mapping::state_db::CodeDB; -use eth_types::{Address, Field, ToLittleEndian, ToWord, U256}; +use eth_types::{Address, Field, ToLittleEndian, U256}; use halo2_proofs::{ circuit::{AssignedCell, Region, Value}, plonk::{Advice, Assigned, Column, ConstraintSystem, Error, Expression, VirtualCells}, @@ -207,11 +206,7 @@ impl<'r, 'b, F: Field> CachedRegion<'r, 'b, F> { .map(|r| rlc::value(le_bytes, r)) } - pub fn empty_code_hash_rlc(&self) -> Value { - self.word_rlc(CodeDB::empty_code_hash().to_word()) - } - - pub fn code_hash_word(&self, n: U256) -> Word> { + pub fn code_hash(&self, n: U256) -> Word> { Word::from(n).into_value() } diff --git a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs index 08755cb16ab..be2485bdd79 100644 --- a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs @@ -304,7 +304,7 @@ impl balance_sum, ); - cb.account_write_word( + cb.account_write( address, AccountFieldTag::Balance, value.to_word(), @@ -392,10 +392,10 @@ impl TransferWithGasFeeGadget { must_create.clone(), ]), |cb| { - cb.account_write_word( + cb.account_write( receiver_address.clone(), AccountFieldTag::CodeHash, - cb.empty_code_hash_word(), + cb.empty_code_hash(), Word::zero(), Some(reversion_info), ); @@ -522,10 +522,10 @@ impl TransferGadget { must_create.clone(), ]), |cb| { - cb.account_write_word( + cb.account_write( receiver_address.clone(), AccountFieldTag::CodeHash, - cb.empty_code_hash_word(), + cb.empty_code_hash(), Word::zero(), Some(reversion_info), ); @@ -610,7 +610,7 @@ pub(crate) struct CommonCallGadget { pub gas: Word32Cell, pub gas_is_u64: IsZeroGadget, - pub callee_address_word: AccountAddress, + pub callee_address: AccountAddress, pub value: Word32Cell, pub cd_address: MemoryAddressGadget, pub rd_address: MemoryAddressGadget, @@ -640,7 +640,7 @@ impl CommonCallGadget ); let gas_word = cb.query_word32(); - let callee_address_word = cb.query_account_address(); + let callee_address = cb.query_account_address(); let value = cb.query_word32(); let cd_offset = cb.query_word_unchecked(); let cd_length = cb.query_memory_address(); @@ -656,18 +656,16 @@ impl CommonCallGadget // callee address is `current_callee_address`. // For both CALL and STATICCALL, caller address is // `current_callee_address` and callee address is `callee_address`. - cb.stack_pop_word(gas_word.to_word()); - cb.stack_pop_word(callee_address_word.to_word()); + cb.stack_pop(gas_word.to_word()); + cb.stack_pop(callee_address.to_word()); // `CALL` and `CALLCODE` opcodes have an additional stack pop `value`. - cb.condition(is_call + is_callcode, |cb| { - cb.stack_pop_word(value.to_word()) - }); - cb.stack_pop_word(cd_offset.to_word()); - cb.stack_pop_word(cd_length.to_word()); - cb.stack_pop_word(rd_offset.to_word()); - cb.stack_pop_word(rd_length.to_word()); - cb.stack_push_word(if IS_SUCCESS_CALL { + cb.condition(is_call + is_callcode, |cb| cb.stack_pop(value.to_word())); + cb.stack_pop(cd_offset.to_word()); + cb.stack_pop(cd_length.to_word()); + cb.stack_pop(rd_offset.to_word()); + cb.stack_pop(rd_length.to_word()); + cb.stack_push(if IS_SUCCESS_CALL { Word::from_lo_unchecked(is_success.expr()) // is_success is bool } else { Word::zero() @@ -689,18 +687,18 @@ impl CommonCallGadget ); let callee_code_hash = cb.query_word_unchecked(); - cb.account_read_word( - callee_address_word.to_word(), + cb.account_read( + callee_address.to_word(), AccountFieldTag::CodeHash, callee_code_hash.to_word(), ); let is_empty_code_hash = - IsEqualWordGadget::construct(cb, &callee_code_hash, &cb.empty_code_hash_word()); + IsEqualWordGadget::construct(cb, &callee_code_hash, &cb.empty_code_hash()); let callee_not_exists = IsZeroWordGadget::construct(cb, &callee_code_hash); Self { is_success, - callee_address_word, + callee_address, gas: gas_word, gas_is_u64, value, @@ -715,8 +713,8 @@ impl CommonCallGadget } } - pub fn callee_address_word(&self) -> Word> { - self.callee_address_word.to_word() + pub fn callee_address(&self) -> Word> { + self.callee_address.to_word() } pub fn gas_expr(&self) -> Expression { @@ -756,7 +754,7 @@ impl CommonCallGadget callee_code_hash: U256, ) -> Result { self.gas.assign_u256(region, offset, gas)?; - self.callee_address_word + self.callee_address .assign_h160(region, offset, callee_address.to_address())?; self.value.assign_u256(region, offset, value)?; if IS_SUCCESS_CALL { @@ -1106,7 +1104,7 @@ impl WordByteCapGadget { self.lt_cap.expr() } - pub(crate) fn original_word_new(&self) -> Word32Cell { + pub(crate) fn original_word(&self) -> Word32Cell { self.word.original.clone() } diff --git a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs index 65ce6106ca7..71258e7dd57 100644 --- a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs +++ b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs @@ -536,11 +536,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { rlc::expr(&bytes, self.challenges.keccak_input()) } - pub(crate) fn empty_code_hash_rlc(&self) -> Expression { - self.word_rlc((*EMPTY_CODE_HASH_LE).map(|byte| byte.expr())) - } - - pub(crate) fn empty_code_hash_word(&self) -> Word> { + pub(crate) fn empty_code_hash(&self) -> Word> { Word32::new(EMPTY_CODE_HASH_LE.map(|byte| byte.expr())).to_word() } @@ -680,7 +676,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ); } - pub(crate) fn bytecode_lookup_word( + pub(crate) fn bytecode_lookup( &mut self, code_hash: Word>, index: Expression, @@ -699,11 +695,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ) } - pub(crate) fn bytecode_length_word( - &mut self, - code_hash: Word>, - value: Expression, - ) { + pub(crate) fn bytecode_length(&mut self, code_hash: Word>, value: Expression) { self.add_lookup( "Bytecode (length)", Lookup::Bytecode { @@ -726,7 +718,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ) -> Cell { let cell = self.query_cell(); // lookup read, unchecked is safe - self.tx_context_lookup_word(id, field_tag, index, Word::from_lo_unchecked(cell.expr())); + self.tx_context_lookup(id, field_tag, index, Word::from_lo_unchecked(cell.expr())); cell } pub(crate) fn tx_context_as_word32( @@ -736,7 +728,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { index: Option>, ) -> Word32Cell { let word = self.query_word32(); - self.tx_context_lookup_word(id, field_tag, index, word.to_word()); + self.tx_context_lookup(id, field_tag, index, word.to_word()); word } @@ -747,11 +739,11 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { index: Option>, ) -> WordCell { let word = self.query_word_unchecked(); - self.tx_context_lookup_word(id, field_tag, index, word.to_word()); + self.tx_context_lookup(id, field_tag, index, word.to_word()); word } - pub(crate) fn tx_context_lookup_word( + pub(crate) fn tx_context_lookup( &mut self, id: Expression, field_tag: TxContextFieldTag, @@ -770,7 +762,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { } // block - pub(crate) fn block_lookup_word( + pub(crate) fn block_lookup( &mut self, tag: Expression, number: Option>, @@ -921,7 +913,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ), ); } - pub(crate) fn account_storage_access_list_write_word( + pub(crate) fn account_storage_access_list_write( &mut self, tx_id: Expression, account_address: Word>, @@ -946,7 +938,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ); } - pub(crate) fn account_storage_access_list_read_word( + pub(crate) fn account_storage_access_list_read( &mut self, tx_id: Expression, account_address: Word>, @@ -988,7 +980,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ); } - pub(crate) fn tx_refund_write_word( + pub(crate) fn tx_refund_write( &mut self, tx_id: Expression, value: Word>, @@ -1012,7 +1004,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { } // Account - pub(crate) fn account_read_word( + pub(crate) fn account_read( &mut self, account_address: Word>, field_tag: AccountFieldTag, @@ -1034,7 +1026,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ); } - pub(crate) fn account_write_word( + pub(crate) fn account_write( &mut self, account_address: Word>, field_tag: AccountFieldTag, @@ -1059,7 +1051,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { } // Account Storage - pub(crate) fn account_storage_read_word( + pub(crate) fn account_storage_read( &mut self, account_address: Word>, key: Word>, @@ -1084,7 +1076,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { } #[allow(clippy::too_many_arguments)] - pub(crate) fn account_storage_write_word( + pub(crate) fn account_storage_write( &mut self, account_address: Word>, key: Word>, @@ -1238,17 +1230,17 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { } // Stack - pub(crate) fn stack_pop_word(&mut self, value: Word>) { - self.stack_lookup_word(false.expr(), self.stack_pointer_offset.clone(), value); + pub(crate) fn stack_pop(&mut self, value: Word>) { + self.stack_lookup(false.expr(), self.stack_pointer_offset.clone(), value); self.stack_pointer_offset = self.stack_pointer_offset.clone() + self.condition_expr(); } - pub(crate) fn stack_push_word(&mut self, value: Word>) { + pub(crate) fn stack_push(&mut self, value: Word>) { self.stack_pointer_offset = self.stack_pointer_offset.clone() - self.condition_expr(); - self.stack_lookup_word(true.expr(), self.stack_pointer_offset.expr(), value); + self.stack_lookup(true.expr(), self.stack_pointer_offset.expr(), value); } - pub(crate) fn stack_lookup_word( + pub(crate) fn stack_lookup( &mut self, is_write: Expression, stack_pointer_offset: Expression, @@ -1296,7 +1288,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ); } - pub(crate) fn tx_log_lookup_word( + pub(crate) fn tx_log_lookup( &mut self, tx_id: Expression, log_id: Expression, @@ -1425,7 +1417,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { } // Keccak Table - pub(crate) fn keccak_table_lookup_word( + pub(crate) fn keccak_table_lookup( &mut self, input_rlc: Expression, input_len: Expression, diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/abs_word.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/abs_word.rs index 8bc22cc43f1..119e7d77a2b 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/abs_word.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/abs_word.rs @@ -94,10 +94,10 @@ impl AbsWordGadget { &self.is_neg } - pub(crate) fn x_word(&self) -> &Word32Cell { + pub(crate) fn x(&self) -> &Word32Cell { &self.x } - pub(crate) fn x_abs_word(&self) -> &Word32Cell { + pub(crate) fn x_abs(&self) -> &Word32Cell { &self.x_abs } } diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs index 848a0018488..e097a7cbd2f 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs @@ -260,7 +260,7 @@ impl ContractCreateGadget { } /// Caller address' value. - pub(crate) fn caller_address_word(&self) -> word::Word> { + pub(crate) fn caller_address(&self) -> word::Word> { self.caller_address.to_word() } @@ -270,7 +270,7 @@ impl ContractCreateGadget { } /// Code hash word RLC. - pub(crate) fn code_hash_word(&self) -> word::Word> { + pub(crate) fn code_hash(&self) -> word::Word> { self.code_hash.to_word() } @@ -287,7 +287,7 @@ impl ContractCreateGadget { ) } - pub(crate) fn salt_word(&self) -> word::Word> { + pub(crate) fn salt(&self) -> word::Word> { self.salt.to_word() } diff --git a/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs b/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs index 0fb7c958a5d..6a0bdadbe54 100644 --- a/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs @@ -29,7 +29,7 @@ pub(crate) mod address_low { use eth_types::Field; use halo2_proofs::plonk::Expression; - pub(crate) fn expr_word(address: &Word32Cell) -> Expression { + pub(crate) fn expr(address: &Word32Cell) -> Expression { from_bytes::expr(&address.limbs[..N_BYTES_MEMORY_ADDRESS]) } @@ -50,7 +50,7 @@ pub(crate) mod address_high { use eth_types::Field; use halo2_proofs::plonk::Expression; - pub(crate) fn expr_word(address: &Word32Cell) -> Expression { + pub(crate) fn expr(address: &Word32Cell) -> Expression { sum::expr(&address.limbs[N_BYTES_MEMORY_ADDRESS..]) } diff --git a/zkevm-circuits/src/util/word.rs b/zkevm-circuits/src/util/word.rs index d2e1c42e93d..20ed0658709 100644 --- a/zkevm-circuits/src/util/word.rs +++ b/zkevm-circuits/src/util/word.rs @@ -54,22 +54,6 @@ impl Default for WordLimbs { } } -impl Expr for WordCell { - fn expr(&self) -> Expression { - unreachable!( - "This function is meat to fix the build. Remove once we fixed the word lo-hi refactor" - ) - } -} - -impl Expr for Word32Cell { - fn expr(&self) -> Expression { - unreachable!( - "This function is meat to fix the build. Remove once we fixed the word lo-hi refactor" - ) - } -} - /// Get the word expression pub trait WordExpr { /// Get the word expression