diff --git a/zkevm-circuits/src/evm_circuit/execution/create.rs b/zkevm-circuits/src/evm_circuit/execution/create.rs index 3bb5e06302..9236cbf16c 100644 --- a/zkevm-circuits/src/evm_circuit/execution/create.rs +++ b/zkevm-circuits/src/evm_circuit/execution/create.rs @@ -478,30 +478,30 @@ impl ExecutionGadget< Value::known(call.depth.to_scalar().unwrap()), )?; let mut rws = StepRws::new(block, step); - rws.next(); // 0 - TxId - rws.next(); // 1 - Depth - let rw_end_of_reversion = rws.next().call_context_value().as_usize(); // 2 - RwCounterEndOfReversion - let is_persistent = rws.next().call_context_value().as_usize() != 0; // 3 - IsPersistent + rws.next(); + rws.next(); + let rw_end_of_reversion = rws.next().call_context_value().as_usize(); + let is_persistent = rws.next().call_context_value().as_usize() != 0; self.reversion_info .assign(region, offset, rw_end_of_reversion, is_persistent)?; // stack value starts from 4 - let value = rws.next().stack_value(); // 4 - Value - let init_code_start = rws.next().stack_value(); // 5 - Offset - let init_code_length = rws.next().stack_value(); // 6 - Length + let value = rws.next().stack_value(); + let init_code_start = rws.next().stack_value(); + let init_code_length = rws.next().stack_value(); self.value.assign_u256(region, offset, value)?; let salt = if is_create2 { - rws.next().stack_value() // 7 - Salt + rws.next().stack_value() } else { U256::zero() }; - rws.next(); // rw_off = 7 + 1 or 8 + 1 depends on is_create2 + rws.next(); // Pre-check: call depth, user's nonce and user's balance - let (caller_balance, _) = rws.next().account_balance_pair(); // rw_off + 1 - CallerBalance - let (caller_nonce, _) = rws.next().account_nonce_pair(); // rw_off + 2 - CallerNonce + let (caller_balance, _) = rws.next().account_balance_pair(); + let (caller_nonce, _) = rws.next().account_nonce_pair(); let is_precheck_ok = if call.depth < 1025 && caller_balance >= value && caller_nonce.as_u64() < u64::MAX { 1 @@ -511,28 +511,17 @@ impl ExecutionGadget< self.caller_balance .assign_u256(region, offset, caller_balance)?; - rws.next(); // rw_off + 3 + rws.next(); let (callee_prev_code_hash, was_warm) = if is_precheck_ok == 1 { - let (_, was_warm) = rws.next().tx_access_list_value_pair(); // rw_off + 4 - TxAccessList - let (callee_prev_code_hash, _) = rws.next().account_codehash_pair(); // rw_off + 5 - CalleePrevCodeHash + let (_, was_warm) = rws.next().tx_access_list_value_pair(); + let (callee_prev_code_hash, _) = rws.next().account_codehash_pair(); (callee_prev_code_hash, was_warm) } else { (U256::from(0), false) }; - let (callee_rw_counter_end_of_reversion, callee_is_persistent) = if is_precheck_ok == 1 { - rws.offset_add(5); // rw_off + 6,7,8,9,10 - ( - rws.next().call_context_value(), // rw_off + 11 - CalleeRwCounterEndOfReversion - rws.next().call_context_value(), // rw_off + 12 - CalleeIsPersistent - ) - } else { - rws.offset_add(2); // rw_off + 6,7 - ( - rws.next().call_context_value(), // // rw_off + 8 - CalleeRwCounterEndOfReversion - rws.next().call_context_value(), // // rw_off + 9 - CalleeIsPersistent - ) - }; + let callee_rw_counter_end_of_reversion = rws.next().call_context_value(); + let callee_is_persistent = rws.next().call_context_value(); // retrieve code_hash for creating address let is_address_collision = !callee_prev_code_hash.is_zero(); @@ -589,11 +578,11 @@ impl ExecutionGadget< let code_hash = if is_precheck_ok == 1 { // transfer let (caller_balance_pair, callee_balance_pair) = if !value.is_zero() { - rws.offset_add(copy_rw_increase + 1); // rw_off + 13 + copy_rw_increase + rws.offset_add(copy_rw_increase + 1); ( rws.next().account_balance_pair(), rws.next().account_balance_pair(), - ) // rw_off + 14 + copy_rw_increase, rw_off + 15 + copy_rw_increase + ) } else { ((0.into(), 0.into()), (0.into(), 0.into())) }; @@ -606,8 +595,8 @@ impl ExecutionGadget< )?; // copy_table_lookup - rws.offset_sub(copy_rw_increase + 2); // rw_off + 13 - let values: Vec<_> = (0..copy_rw_increase) // (rw_off + 13..rw_off + 13 + copy_rw_increase) + rws.offset_sub(copy_rw_increase + 2); + let values: Vec<_> = (0..copy_rw_increase) .map(|_i| rws.next().memory_value()) .collect(); let code_hash = CodeDB::hash(&values); @@ -656,8 +645,6 @@ impl ExecutionGadget< Some(salt), )?; - // If transfer value is zero, there is no balance update - let transfer_offset = if value.is_zero() { 2 } else { 0 }; self.is_success.assign( region, offset, @@ -666,7 +653,6 @@ impl ExecutionGadget< } else if init_code_length.as_usize() == 0 { F::ONE } else { - rws.offset_add(5 - transfer_offset); // rw_off + 13 + 5 + copy_rw_increase - transfer_offset rws.next().call_context_value().to_scalar().unwrap() }), )?; diff --git a/zkevm-circuits/src/evm_circuit/execution/end_tx.rs b/zkevm-circuits/src/evm_circuit/execution/end_tx.rs index e29e08bd90..277a24a776 100644 --- a/zkevm-circuits/src/evm_circuit/execution/end_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/end_tx.rs @@ -281,16 +281,10 @@ impl ExecutionGadget for EndTxGadget { self.coinbase_code_hash_is_zero .assign_u256(region, offset, coinbase_code_hash_prev)?; if !coinbase_reward.is_zero() { - let coinbase_balance_pair = block - .get_rws( - step, - if coinbase_code_hash_prev.is_zero() { - 6 - } else { - 5 - }, - ) - .account_balance_pair(); + if coinbase_code_hash_prev.is_zero() { + rws.next(); + } + let coinbase_balance_pair = rws.next().account_balance_pair(); self.coinbase_reward.assign( region, offset, 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 92025e9244..92bb154f6e 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs @@ -141,15 +141,10 @@ impl ExecutionGadget for ErrorOOGCallGadget { let rd_offset = rws.next().stack_value(); let rd_length = rws.next().stack_value(); - let callee_code_hash = block - .get_rws(step, 9 + is_call_or_callcode) - .account_codehash_pair() - .0; + let callee_code_hash = rws.next().account_codehash_pair().0; let callee_exists = !callee_code_hash.is_zero(); - let (is_warm, is_warm_prev) = block - .get_rws(step, 10 + is_call_or_callcode) - .tx_access_list_value_pair(); + let (is_warm, is_warm_prev) = rws.next().tx_access_list_value_pair(); let memory_expansion_gas_cost = self.call.assign( region, 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 88f3ed5078..0ef0b824fb 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 @@ -156,7 +156,6 @@ impl ExecutionGadget for ErrorOOGMemoryCopyGadget { let opcode = step.opcode().unwrap(); let is_extcodecopy = opcode == OpcodeId::EXTCODECOPY; let mut rws = StepRws::new(block, step); - rws.next(); log::debug!( "ErrorOutOfGasMemoryCopy: opcode = {}, gas_left = {}, gas_cost = {}", @@ -166,6 +165,7 @@ impl ExecutionGadget for ErrorOOGMemoryCopyGadget { ); let (is_warm, external_address) = if is_extcodecopy { + rws.next(); ( rws.next().tx_access_list_value_pair().0, rws.next().stack_value(),