Skip to content

Commit

Permalink
check rw_counter is unique (privacy-scaling-explorations#415)
Browse files Browse the repository at this point in the history
* check rw_counter is unique and increasing

* only check uniqueness

* fix clippy

* make calldatasize rwc start with 1

* rebase to main

* remove unused method

* remove blank line

* minor updates
  • Loading branch information
DreamWuGit authored Apr 12, 2022
1 parent 17829e3 commit 7ac8bfb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,18 @@ pub mod test {
.assign(&mut region, offset, &Default::default())?;
offset += 1;

for rw in rws.0.values().flat_map(|rws| rws.iter()) {
let mut rows = rws
.0
.values()
.flat_map(|rws| rws.iter())
.collect::<Vec<_>>();

rows.sort_by_key(|a| a.rw_counter());
let mut expected_rw_counter = 1;
for rw in rows {
assert!(rw.rw_counter() == expected_rw_counter);
expected_rw_counter += 1;

self.rw_table.assign(
&mut region,
offset,
Expand Down
14 changes: 14 additions & 0 deletions zkevm-circuits/src/evm_circuit/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,20 @@ impl<F: FieldExt> From<[F; 11]> for RwRow<F> {
}

impl Rw {
pub fn rw_counter(&self) -> usize {
match self {
Self::TxAccessListAccount { rw_counter, .. } => (*rw_counter),
Self::TxAccessListAccountStorage { rw_counter, .. } => (*rw_counter),
Self::Stack { rw_counter, .. } => (*rw_counter),
Self::Memory { rw_counter, .. } => (*rw_counter),
Self::Account { rw_counter, .. } => (*rw_counter),
Self::AccountDestructed { rw_counter, .. } => (*rw_counter),
Self::CallContext { rw_counter, .. } => (*rw_counter),
Self::AccountStorage { rw_counter, .. } => (*rw_counter),
Self::TxRefund { rw_counter, .. } => (*rw_counter),
}
}

pub fn tx_access_list_value_pair(&self) -> (bool, bool) {
match self {
Self::TxAccessListAccount {
Expand Down

0 comments on commit 7ac8bfb

Please sign in to comment.