Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
fix: update rws steps due to broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Mar 17, 2024
1 parent 6defa55 commit 4a6de58
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 26 deletions.
25 changes: 14 additions & 11 deletions zkevm-circuits/src/evm_circuit/execution/end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
MulWordByU64Gadget,
},
tx::EndTxHelperGadget,
CachedRegion, Cell, StepRws,
CachedRegion, Cell,
},
witness::{Block, Call, ExecStep, Transaction},
},
Expand Down Expand Up @@ -152,12 +152,9 @@ impl<F: Field> ExecutionGadget<F> for EndTxGadget<F> {
step: &ExecStep,
) -> Result<(), Error> {
let gas_used = tx.gas() - step.gas_left;
let mut rws = StepRws::new(block, step);
rws.offset_add(2);

let (refund, _) = rws.next().tx_refund_value_pair();
let (caller_balance, caller_balance_prev) = rws.next().account_balance_pair();
let (coinbase_code_hash_prev, _) = rws.next().account_codehash_pair();
let (refund, _) = block.get_rws(step, 2).tx_refund_value_pair();
let (caller_balance, caller_balance_prev) = block.get_rws(step, 3).account_balance_pair();
let (coinbase_code_hash_prev, _) = block.get_rws(step, 4).account_codehash_pair();

self.tx_id
.assign(region, offset, Value::known(F::from(tx.id)))?;
Expand Down Expand Up @@ -212,10 +209,16 @@ impl<F: Field> ExecutionGadget<F> for EndTxGadget<F> {
self.coinbase_code_hash_is_zero
.assign_u256(region, offset, coinbase_code_hash_prev)?;
if !coinbase_reward.is_zero() {
if coinbase_code_hash_prev.is_zero() {
rws.next();
}
let coinbase_balance_pair = rws.next().account_balance_pair();
let coinbase_balance_pair = block
.get_rws(
step,
if coinbase_code_hash_prev.is_zero() {
6
} else {
5
},
)
.account_balance_pair();
self.coinbase_reward.assign(
region,
offset,
Expand Down
9 changes: 8 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/error_oog_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,19 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGCallGadget<F> {
U256::zero()
};

if is_call_or_callcode == 1 {
rws.offset_sub(1);
}

rws.offset_add(is_call_or_callcode);

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 callee_code_hash = rws.next().account_codehash_pair().0;

let callee_exists = !callee_code_hash.is_zero();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGMemoryCopyGadget<F> {
);

let (is_warm, external_address) = if is_extcodecopy {
rws.next();
(
rws.next().tx_access_list_value_pair().0,
rws.next().stack_value(),
Expand All @@ -174,12 +175,14 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGMemoryCopyGadget<F> {
(false, U256::zero())
};

if is_extcodecopy {
rws.next(); // Skip external address
}
if !is_extcodecopy {
rws.offset_reset();
};

let dst_offset = rws.next().stack_value();

let src_offset = rws.next().stack_value();

let copy_size = rws.next().stack_value();

self.opcode
Expand Down
9 changes: 6 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ impl<F: Field> ExecutionGadget<F> for ExtcodecopyGadget<F> {

let mut rws = StepRws::new(block, step);

let [external_address, memory_offset, code_offset, memory_length] =
[0, 1, 2, 3].map(|_| rws.next().stack_value());
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 =
Expand All @@ -201,7 +204,7 @@ impl<F: Field> ExecutionGadget<F> for ExtcodecopyGadget<F> {
call.is_persistent,
)?;

rws.offset_add(3);
rws.offset_add(4);

let (_, is_warm) = rws.next().tx_access_list_value_pair();
self.is_warm
Expand Down
10 changes: 4 additions & 6 deletions zkevm-circuits/src/evm_circuit/execution/extcodehash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
constraint_builder::{
EVMConstraintBuilder, ReversionInfo, StepStateTransition, Transition::Delta,
},
select, AccountAddress, CachedRegion, Cell, StepRws,
select, AccountAddress, CachedRegion, Cell,
},
witness::{Block, Call, ExecStep, Transaction},
},
Expand Down Expand Up @@ -106,9 +106,7 @@ impl<F: Field> ExecutionGadget<F> for ExtcodehashGadget<F> {
) -> Result<(), Error> {
self.same_context.assign_exec_step(region, offset, step)?;

let mut rws = StepRws::new(block, step);

let address = rws.next().stack_value();
let address = block.get_rws(step, 0).stack_value();
self.address_word.assign_u256(region, offset, address)?;

self.tx_id
Expand All @@ -120,11 +118,11 @@ impl<F: Field> ExecutionGadget<F> for ExtcodehashGadget<F> {
call.is_persistent,
)?;

let (_, is_warm) = rws.next().tx_access_list_value_pair();
let (_, is_warm) = block.get_rws(step, 4).tx_access_list_value_pair();
self.is_warm
.assign(region, offset, Value::known(F::from(is_warm as u64)))?;

let code_hash = rws.next().account_codehash_pair().0;
let code_hash = block.get_rws(step, 5).account_codehash_pair().0;
self.code_hash.assign_u256(region, offset, code_hash)?;

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/return_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ impl<F: Field> ExecutionGadget<F> for ReturnRevertGadget<F> {

let mut rws = StepRws::new(block, step);

let [memory_offset, length] = [0, 1].map(|_| rws.next().stack_value());
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
Expand Down Expand Up @@ -324,7 +325,7 @@ impl<F: Field> ExecutionGadget<F> for ReturnRevertGadget<F> {

if call.is_create() && call.is_success {
let values: Vec<_> = (4..4 + length.as_usize())
.map(|_| rws.next().memory_value())
.map(|index| block.get_rws(step, index).memory_value())
.collect();
self.deployed_code_rlc.assign(
region,
Expand Down
8 changes: 8 additions & 0 deletions zkevm-circuits/src/evm_circuit/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,14 @@ impl<'a> StepRws<'a> {
pub(crate) fn offset_add(&mut self, inc: usize) {
self.offset += inc
}
/// Decrement the step rw operation offset by `dec`.
pub(crate) fn offset_sub(&mut self, dec: usize) {
self.offset -= dec
}
/// Reset the step rw operation offset to 0.
pub(crate) fn offset_reset(&mut self) {
self.offset = 0
}
/// Return the next rw operation from the step.
pub(crate) fn next(&mut self) -> Rw {
let rw = self.rws[self.step.rw_index(self.offset)];
Expand Down

0 comments on commit 4a6de58

Please sign in to comment.