From 55754a9d3e3bbd5f21ad9116a2b6ca93be666df0 Mon Sep 17 00:00:00 2001 From: Chad Nehemiah Date: Thu, 28 Mar 2024 01:47:46 -0500 Subject: [PATCH] Refactor: use StepRws in evm circuits to replace rw indices (#1786) ### Description Continuing the work originally started in https://github.com/privacy-scaling-explorations/zkevm-circuits/pull/1616 this PR seeks to introduce `StepRws` across the evm circuits to reduce the need for tracking rw indices through code. ### Issue Link Closes https://github.com/privacy-scaling-explorations/zkevm-circuits/issues/1586 ### Type of change Refactor (no updates to logic) ### Contents The change has been made to the following files - error_oog_call.rs - error_oog_memory_copy.rs - error_oog_sload_sstore.rs - error_return_data_oo_bound.rs - error_write_protection.rs - extcodecopy.rs - extcodehash.rs - extcodesize.rs - logs.rs - return_revert.rs - returndatacopy.rs - sha3.rs - sload.rs - sstore.rs --- .../evm_circuit/execution/error_oog_call.rs | 34 +++++++++++-------- .../execution/error_oog_memory_copy.rs | 15 ++++---- .../execution/error_oog_sload_sstore.rs | 15 +++++--- .../execution/error_return_data_oo_bound.rs | 12 ++++--- .../execution/error_write_protection.rs | 7 ++-- .../src/evm_circuit/execution/extcodecopy.rs | 17 +++++++--- .../src/evm_circuit/execution/extcodehash.rs | 12 ++++--- .../src/evm_circuit/execution/extcodesize.rs | 14 +++++--- .../src/evm_circuit/execution/logs.rs | 8 +++-- .../evm_circuit/execution/return_revert.rs | 12 +++++-- .../evm_circuit/execution/returndatacopy.rs | 21 +++++------- .../src/evm_circuit/execution/sha3.rs | 9 ++--- .../src/evm_circuit/execution/sload.rs | 17 +++++++--- .../src/evm_circuit/execution/sstore.rs | 16 ++++++--- 14 files changed, 130 insertions(+), 79 deletions(-) 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 4c2a851d27..dafd542d5a 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs @@ -8,7 +8,7 @@ use crate::{ constraint_builder::{ConstrainBuilderCommon, EVMConstraintBuilder}, math_gadget::{IsZeroGadget, LtGadget}, memory_gadget::MemoryExpandedAddressGadget, - or, CachedRegion, Cell, + or, CachedRegion, Cell, StepRws, }, }, table::CallContextFieldTag, @@ -127,26 +127,30 @@ impl ExecutionGadget for ErrorOOGCallGadget { let opcode = step.opcode().unwrap(); let is_call_or_callcode = usize::from([OpcodeId::CALL, OpcodeId::CALLCODE].contains(&opcode)); - let [tx_id, is_static] = - [0, 1].map(|index| block.get_rws(step, index).call_context_value()); - let [gas, callee_address] = [2, 3].map(|index| block.get_rws(step, index).stack_value()); + + let mut rws = StepRws::new(block, step); + + let tx_id = rws.next().call_context_value(); + let is_static = rws.next().call_context_value(); + let gas = rws.next().stack_value(); + let callee_address = rws.next().stack_value(); + let value = if is_call_or_callcode == 1 { - block.get_rws(step, 4).stack_value() + rws.next().stack_value() } else { U256::zero() }; - let [cd_offset, cd_length, rd_offset, rd_length] = - [4, 5, 6, 7].map(|i| block.get_rws(step, is_call_or_callcode + i).stack_value()); - let callee_code_hash = block - .get_rws(step, 9 + is_call_or_callcode) - .account_codehash_pair() - .0; - let callee_exists = !callee_code_hash.is_zero(); + let cd_offset = rws.next().stack_value(); + let cd_length = rws.next().stack_value(); + let rd_offset = rws.next().stack_value(); + let rd_length = rws.next().stack_value(); + + rws.offset_add(1); - let (is_warm, is_warm_prev) = block - .get_rws(step, 10 + is_call_or_callcode) - .tx_access_list_value_pair(); + let callee_code_hash = rws.next().account_codehash_pair().0; + let callee_exists = !callee_code_hash.is_zero(); + 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 e7b8087647..bdbf1f5115 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 @@ -11,7 +11,7 @@ use crate::{ CommonMemoryAddressGadget, MemoryCopierGasGadget, MemoryExpandedAddressGadget, MemoryExpansionGadget, }, - or, select, AccountAddress, CachedRegion, Cell, + or, select, AccountAddress, CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -157,6 +157,8 @@ impl ExecutionGadget for ErrorOOGMemoryCopyGadget { let opcode = step.opcode().unwrap(); let is_extcodecopy = opcode == OpcodeId::EXTCODECOPY; + let mut rws = StepRws::new(block, step); + log::debug!( "ErrorOutOfGasMemoryCopy: opcode = {}, gas_left = {}, gas_cost = {}", opcode, @@ -165,17 +167,18 @@ impl ExecutionGadget for ErrorOOGMemoryCopyGadget { ); let (is_warm, external_address) = if is_extcodecopy { + rws.next(); ( - block.get_rws(step, 1).tx_access_list_value_pair().0, - block.get_rws(step, 2).stack_value(), + rws.next().tx_access_list_value_pair().0, + rws.next().stack_value(), ) } else { (false, U256::zero()) }; - let rw_offset = if is_extcodecopy { 3 } else { 0 }; - let [dst_offset, src_offset, copy_size] = [rw_offset, rw_offset + 1, rw_offset + 2] - .map(|index| block.get_rws(step, index).stack_value()); + let dst_offset = rws.next().stack_value(); + let src_offset = rws.next().stack_value(); + let copy_size = rws.next().stack_value(); self.opcode .assign(region, offset, Value::known(F::from(opcode.as_u64())))?; 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 c6ed23f111..100f9572cd 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 @@ -11,7 +11,7 @@ use crate::{ }, constraint_builder::{ConstrainBuilderCommon, EVMConstraintBuilder}, math_gadget::{LtGadget, PairSelectGadget}, - or, select, CachedRegion, Cell, + or, select, CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -162,12 +162,17 @@ impl ExecutionGadget for ErrorOOGSloadSstoreGadget { ) -> Result<(), Error> { let opcode = step.opcode().unwrap(); let is_sstore = opcode == OpcodeId::SSTORE; - let key = block.get_rws(step, 3).stack_value(); - let (is_warm, _) = block.get_rws(step, 4).tx_access_list_value_pair(); + + let mut rws = StepRws::new(block, step); + + rws.offset_add(3); + + let key = rws.next().stack_value(); + let (is_warm, _) = rws.next().tx_access_list_value_pair(); let (value, value_prev, original_value, gas_cost) = if is_sstore { - let value = block.get_rws(step, 5).stack_value(); - let (_, value_prev, _, original_value) = block.get_rws(step, 6).storage_value_aux(); + let value = rws.next().stack_value(); + let (_, value_prev, _, original_value) = rws.next().storage_value_aux(); let gas_cost = cal_sstore_gas_cost_for_assignment(value, value_prev, original_value, is_warm); (value, value_prev, original_value, gas_cost) 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 42234d499a..0a61142342 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 @@ -8,7 +8,7 @@ use crate::{ constraint_builder::{ConstrainBuilderCommon, EVMConstraintBuilder}, from_bytes, math_gadget::{AddWordsGadget, IsZeroGadget, LtGadget}, - not, or, sum, CachedRegion, Cell, U64Cell, + not, or, sum, CachedRegion, Cell, StepRws, U64Cell, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -131,8 +131,11 @@ impl ExecutionGadget for ErrorReturnDataOutOfBoundGadget { self.opcode .assign(region, offset, Value::known(F::from(opcode.as_u64())))?; - let [dest_offset, data_offset, size] = - [0, 1, 2].map(|index| block.get_rws(step, index).stack_value()); + let mut rws = StepRws::new(block, step); + + let dest_offset = rws.next().stack_value(); + let data_offset = rws.next().stack_value(); + let size = rws.next().stack_value(); self.memory_offset .assign(region, offset, Some(dest_offset.as_u64().to_le_bytes()))?; @@ -141,7 +144,8 @@ impl ExecutionGadget for ErrorReturnDataOutOfBoundGadget { self.sum .assign(region, offset, [data_offset, size], remainder_end)?; - let return_data_length = block.get_rws(step, 3).call_context_value(); + let return_data_length = rws.next().call_context_value(); + self.return_data_length.assign( region, offset, 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 baf2b244de..0266354989 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs @@ -6,7 +6,7 @@ use crate::{ common_gadget::CommonErrorGadget, constraint_builder::{ConstrainBuilderCommon, EVMConstraintBuilder}, math_gadget::{IsEqualGadget, IsZeroWordGadget}, - AccountAddress, CachedRegion, Cell, + AccountAddress, CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -110,9 +110,10 @@ impl ExecutionGadget for ErrorWriteProtectionGadget { .assign(region, offset, Value::known(F::from(opcode.as_u64())))?; let [mut gas, mut code_address, mut value] = [U256::zero(), U256::zero(), U256::zero()]; + let mut rws = StepRws::new(block, step); + if is_call { - [gas, code_address, value] = - [0, 1, 2].map(|index| block.get_rws(step, index).stack_value()); + [gas, code_address, value] = [0, 1, 2].map(|_| rws.next().stack_value()); } self.gas.assign_u256(region, offset, gas)?; diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs b/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs index ef72eb0a9d..61db9a8df0 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs @@ -13,7 +13,7 @@ use crate::{ CommonMemoryAddressGadget, MemoryAddressGadget, MemoryCopierGasGadget, MemoryExpansionGadget, }, - not, select, AccountAddress, CachedRegion, Cell, + not, select, AccountAddress, CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -183,8 +183,13 @@ impl ExecutionGadget for ExtcodecopyGadget { ) -> Result<(), Error> { self.same_context.assign_exec_step(region, offset, step)?; - let [external_address, memory_offset, code_offset, memory_length] = - [0, 1, 2, 3].map(|idx| block.get_rws(step, idx).stack_value()); + let mut rws = StepRws::new(block, step); + + let external_address = rws.next().stack_value(); + let memory_offset = rws.next().stack_value(); + let code_offset = rws.next().stack_value(); + let memory_length = rws.next().stack_value(); + self.external_address_word .assign_u256(region, offset, external_address)?; let memory_address = @@ -200,11 +205,13 @@ impl ExecutionGadget for ExtcodecopyGadget { call.is_persistent, )?; - let (_, is_warm) = block.get_rws(step, 7).tx_access_list_value_pair(); + rws.offset_add(3); + + let (_, is_warm) = rws.next().tx_access_list_value_pair(); self.is_warm .assign(region, offset, Value::known(F::from(is_warm as u64)))?; - let code_hash = block.get_rws(step, 8).account_codehash_pair().0; + let code_hash = rws.next().account_codehash_pair().0; self.code_hash.assign_u256(region, offset, code_hash)?; self.not_exists.assign_u256(region, offset, code_hash)?; diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs b/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs index fd9fcf370d..e7c90402ce 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs @@ -8,7 +8,7 @@ use crate::{ constraint_builder::{ EVMConstraintBuilder, ReversionInfo, StepStateTransition, Transition::Delta, }, - select, AccountAddress, CachedRegion, Cell, + select, AccountAddress, CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -107,7 +107,9 @@ impl ExecutionGadget for ExtcodehashGadget { ) -> Result<(), Error> { self.same_context.assign_exec_step(region, offset, step)?; - let address = block.get_rws(step, 0).stack_value(); + let mut rws = StepRws::new(block, step); + + let address = rws.next().stack_value(); self.address_word.assign_u256(region, offset, address)?; self.tx_id @@ -119,11 +121,13 @@ impl ExecutionGadget for ExtcodehashGadget { call.is_persistent, )?; - let (_, is_warm) = block.get_rws(step, 4).tx_access_list_value_pair(); + rws.offset_add(3); + + let (_, is_warm) = rws.next().tx_access_list_value_pair(); self.is_warm .assign(region, offset, Value::known(F::from(is_warm as u64)))?; - let code_hash = block.get_rws(step, 5).account_codehash_pair().0; + let code_hash = rws.next().account_codehash_pair().0; self.code_hash.assign_u256(region, offset, code_hash)?; Ok(()) diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs b/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs index b80a2c3532..ca5affef12 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs @@ -10,7 +10,7 @@ use crate::{ Transition::Delta, }, math_gadget::IsZeroWordGadget, - not, select, AccountAddress, CachedRegion, Cell, U64Cell, + not, select, AccountAddress, CachedRegion, Cell, StepRws, U64Cell, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -124,7 +124,9 @@ impl ExecutionGadget for ExtcodesizeGadget { ) -> Result<(), Error> { self.same_context.assign_exec_step(region, offset, step)?; - let address = block.get_rws(step, 0).stack_value(); + let mut rws = StepRws::new(block, step); + + let address = rws.next().stack_value(); self.address_word.assign_u256(region, offset, address)?; self.tx_id @@ -137,16 +139,18 @@ impl ExecutionGadget for ExtcodesizeGadget { call.is_persistent, )?; - let (_, is_warm) = block.get_rws(step, 4).tx_access_list_value_pair(); + rws.offset_add(3); + + let (_, is_warm) = rws.next().tx_access_list_value_pair(); self.is_warm .assign(region, offset, Value::known(F::from(is_warm as u64)))?; - let code_hash = block.get_rws(step, 5).account_codehash_pair().0; + let code_hash = rws.next().account_codehash_pair().0; self.code_hash.assign_u256(region, offset, code_hash)?; self.not_exists .assign(region, offset, WordLoHi::from(code_hash))?; - let code_size = block.get_rws(step, 6).stack_value().as_u64(); + let code_size = rws.next().stack_value().as_u64(); self.code_size .assign(region, offset, Some(code_size.to_le_bytes()))?; diff --git a/zkevm-circuits/src/evm_circuit/execution/logs.rs b/zkevm-circuits/src/evm_circuit/execution/logs.rs index 12b472de3a..68ab4deede 100644 --- a/zkevm-circuits/src/evm_circuit/execution/logs.rs +++ b/zkevm-circuits/src/evm_circuit/execution/logs.rs @@ -12,7 +12,7 @@ use crate::{ memory_gadget::{ CommonMemoryAddressGadget, MemoryAddressGadget, MemoryExpansionGadget, }, - not, sum, CachedRegion, Cell, + not, sum, CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -202,7 +202,11 @@ impl ExecutionGadget for LogGadget { ) -> Result<(), Error> { self.same_context.assign_exec_step(region, offset, step)?; - let [memory_start, msize] = [0, 1].map(|index| block.get_rws(step, index).stack_value()); + let mut rws = StepRws::new(block, step); + + let memory_start = rws.next().stack_value(); + let msize = rws.next().stack_value(); + let memory_address = self .memory_address .assign(region, offset, memory_start, msize)?; diff --git a/zkevm-circuits/src/evm_circuit/execution/return_revert.rs b/zkevm-circuits/src/evm_circuit/execution/return_revert.rs index 48f9e352e1..66a363c311 100644 --- a/zkevm-circuits/src/evm_circuit/execution/return_revert.rs +++ b/zkevm-circuits/src/evm_circuit/execution/return_revert.rs @@ -13,7 +13,7 @@ use crate::{ memory_gadget::{ CommonMemoryAddressGadget, MemoryAddressGadget, MemoryExpansionGadget, }, - not, CachedRegion, Cell, + not, CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -293,7 +293,11 @@ impl ExecutionGadget for ReturnRevertGadget { Value::known(F::from(step.opcode().unwrap().as_u64())), )?; - let [memory_offset, length] = [0, 1].map(|index| block.get_rws(step, index).stack_value()); + let mut rws = StepRws::new(block, step); + + let memory_offset = rws.next().stack_value(); + let length = rws.next().stack_value(); + let range = self.range.assign(region, offset, memory_offset, length)?; self.memory_expansion .assign(region, offset, step.memory_word_size(), [range])?; @@ -349,8 +353,10 @@ impl ExecutionGadget for ReturnRevertGadget { let is_contract_deployment = call.is_create() && call.is_success && !length.is_zero(); + rws.next(); + let init_code_first_byte = if is_contract_deployment { - block.get_rws(step, 3).memory_value() + rws.next().memory_value() } else { 0 } diff --git a/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs b/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs index 1bf7334d4c..8fa7a5be1a 100644 --- a/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs @@ -14,7 +14,7 @@ use crate::{ CommonMemoryAddressGadget, MemoryAddressGadget, MemoryCopierGasGadget, MemoryExpansionGadget, }, - CachedRegion, Cell, MemoryAddress, + CachedRegion, Cell, MemoryAddress, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -177,21 +177,16 @@ impl ExecutionGadget for ReturnDataCopyGadget { ) -> Result<(), Error> { self.same_context.assign_exec_step(region, offset, step)?; - let [dest_offset, data_offset, size] = - [0, 1, 2].map(|index| block.get_rws(step, index).stack_value()); + let mut rws = StepRws::new(block, step); + + let [dest_offset, data_offset, size] = [0, 1, 2].map(|_| rws.next().stack_value()); self.data_offset.assign_u256(region, offset, data_offset)?; - let [last_callee_id, return_data_offset, return_data_size] = [ - (3, CallContextFieldTag::LastCalleeId), - (4, CallContextFieldTag::LastCalleeReturnDataOffset), - (5, CallContextFieldTag::LastCalleeReturnDataLength), - ] - .map(|(i, tag)| { - let rw = block.get_rws(step, i); - assert_eq!(rw.field_tag(), Some(tag as u64)); - rw.call_context_value() - }); + let last_callee_id = rws.next().call_context_value(); + let return_data_offset = rws.next().call_context_value(); + let return_data_size = rws.next().call_context_value(); + self.last_callee_id.assign( region, offset, diff --git a/zkevm-circuits/src/evm_circuit/execution/sha3.rs b/zkevm-circuits/src/evm_circuit/execution/sha3.rs index 9cff5746c4..a8ba4644bc 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sha3.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sha3.rs @@ -16,7 +16,7 @@ use crate::{ CommonMemoryAddressGadget, MemoryAddressGadget, MemoryCopierGasGadget, MemoryExpansionGadget, }, - rlc, CachedRegion, Cell, + rlc, CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -124,8 +124,9 @@ impl ExecutionGadget for Sha3Gadget { ) -> Result<(), Error> { self.same_context.assign_exec_step(region, offset, step)?; - let [memory_offset, size, sha3_output] = - [0, 1, 2].map(|idx| block.get_rws(step, idx).stack_value()); + let mut rws = StepRws::new(block, step); + + let [memory_offset, size, sha3_output] = [0, 1, 2].map(|_| rws.next().stack_value()); let memory_address = self .memory_address .assign(region, offset, memory_offset, size)?; @@ -141,7 +142,7 @@ impl ExecutionGadget for Sha3Gadget { )?; let values: Vec = (3..3 + (size.low_u64() as usize)) - .map(|i| block.get_rws(step, i).memory_value()) + .map(|_| rws.next().memory_value()) .collect(); let rlc_acc = region diff --git a/zkevm-circuits/src/evm_circuit/execution/sload.rs b/zkevm-circuits/src/evm_circuit/execution/sload.rs index 0065e00ad8..5b3c7ced0b 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::{ EVMConstraintBuilder, ReversionInfo, StepStateTransition, Transition::Delta, }, - CachedRegion, Cell, + CachedRegion, Cell, StepRws, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -121,16 +121,23 @@ impl ExecutionGadget for SloadGadget { self.callee_address .assign_h160(region, offset, call.address)?; - let key = block.get_rws(step, 4).stack_value(); - let value = block.get_rws(step, 6).stack_value(); + let mut rws = StepRws::new(block, step); + + rws.offset_add(4); + + let key = rws.next().stack_value(); + let (_, committed_value) = rws.next().aux_pair(); + let value = rws.next().stack_value(); + self.key.assign_u256(region, offset, key)?; self.value.assign_u256(region, offset, value)?; - let (_, committed_value) = block.get_rws(step, 5).aux_pair(); self.committed_value .assign_u256(region, offset, committed_value)?; - let (_, is_warm) = block.get_rws(step, 8).tx_access_list_value_pair(); + rws.next(); + + let (_, is_warm) = rws.next().tx_access_list_value_pair(); self.is_warm .assign(region, offset, Value::known(F::from(is_warm as u64)))?; diff --git a/zkevm-circuits/src/evm_circuit/execution/sstore.rs b/zkevm-circuits/src/evm_circuit/execution/sstore.rs index bcc946cf8b..8c6a57cf6e 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sstore.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sstore.rs @@ -10,7 +10,7 @@ use crate::{ Transition::Delta, }, math_gadget::{IsEqualWordGadget, IsZeroWordGadget, LtGadget}, - not, CachedRegion, Cell, U64Cell, + not, CachedRegion, Cell, StepRws, U64Cell, }, witness::{Block, Call, Chunk, ExecStep, Transaction}, }, @@ -187,17 +187,23 @@ impl ExecutionGadget for SstoreGadget { self.callee_address .assign_h160(region, offset, call.address)?; - let key = block.get_rws(step, 5).stack_value(); - let value = block.get_rws(step, 6).stack_value(); + let mut rws = StepRws::new(block, step); + + rws.offset_add(5); + + let key = rws.next().stack_value(); + let value = rws.next().stack_value(); self.key.assign_u256(region, offset, key)?; self.value.assign_u256(region, offset, value)?; - let (_, value_prev, _, original_value) = block.get_rws(step, 7).storage_value_aux(); + let (_, value_prev, _, original_value) = rws.next().storage_value_aux(); self.value_prev.assign_u256(region, offset, value_prev)?; self.original_value .assign_u256(region, offset, original_value)?; - let (_, is_warm) = block.get_rws(step, 9).tx_access_list_value_pair(); + rws.next(); // skip the storage write + + let (_, is_warm) = rws.next().tx_access_list_value_pair(); self.is_warm .assign(region, offset, Value::known(F::from(is_warm as u64)))?;