Skip to content

Commit

Permalink
change: Update sdb/storage-related ops warm check fields (privacy-sca…
Browse files Browse the repository at this point in the history
…ling-explorations#452)

* change: Update sdb/storage-related ops warm check fields

`TxAccessListAccountOp`, `TxAccessListAccountStorageOp` and
`AccountDestructedOp` contain fields called `value` and `value_prev`
which basically are `bool`s marking whether the access to these values in the operation are WARM or not.

Makes more sense to name them as `is_warm`/`is_warm_prev`
(is_destructed/is_destructed_prev` for `AccountDestructedOp`.

Resolves: privacy-scaling-explorations#442
  • Loading branch information
CPerezz authored Apr 12, 2022
1 parent 31ae5a1 commit d525968
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 79 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,19 +1150,19 @@ impl<'a> CircuitInputStateRef<'a> {
self.sdb.set_storage(&op.address, &op.key, &op.value);
}
OpEnum::TxAccessListAccount(op) => {
if !op.value_prev && op.value {
if !op.is_warm_prev && op.is_warm {
self.sdb.add_account_to_access_list(op.address);
}
if op.value_prev && !op.value {
if op.is_warm_prev && !op.is_warm {
self.sdb.remove_account_from_access_list(&op.address);
}
}
OpEnum::TxAccessListAccountStorage(op) => {
if !op.value_prev && op.value {
if !op.is_warm_prev && op.is_warm {
self.sdb
.add_account_storage_to_access_list((op.address, op.key));
}
if op.value_prev && !op.value {
if op.is_warm_prev && !op.is_warm {
self.sdb
.remove_account_storage_from_access_list(&(op.address, op.key));
}
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ pub fn gen_begin_tx_ops(state: &mut CircuitInputStateRef) -> Result<ExecStep, Er
TxAccessListAccountOp {
tx_id: state.tx_ctx.id(),
address,
value: true,
value_prev: false,
is_warm: true,
is_warm_prev: false,
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ impl Opcode for Call {
TxAccessListAccountOp {
tx_id,
address: callee.address,
value: true,
value_prev: is_warm_access,
is_warm: true,
is_warm_prev: is_warm_access,
},
)?;

Expand Down
8 changes: 4 additions & 4 deletions bus-mapping/src/evm/opcodes/extcodehash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl Opcode for Extcodehash {
TxAccessListAccountOp {
tx_id: state.tx_ctx.id(),
address: external_address,
value: true,
value_prev: is_warm,
is_warm: true,
is_warm_prev: is_warm,
},
)?;

Expand Down Expand Up @@ -305,8 +305,8 @@ mod extcodehash_tests {
&TxAccessListAccountOp {
tx_id,
address: external_address,
value: true,
value_prev: is_warm
is_warm: true,
is_warm_prev: is_warm
}
)
);
Expand Down
8 changes: 4 additions & 4 deletions bus-mapping/src/evm/opcodes/sload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ impl Opcode for Sload {
tx_id: state.tx_ctx.id(),
address: contract_addr,
key,
value: true,
value_prev: is_warm,
is_warm: true,
is_warm_prev: is_warm,
},
)?;

Expand Down Expand Up @@ -209,8 +209,8 @@ mod sload_tests {
tx_id: 1,
address: MOCK_ACCOUNTS[0],
key: Word::from(0x0u32),
value: true,
value_prev: is_warm,
is_warm: true,
is_warm_prev: is_warm,
},
)
)
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes/sstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ impl Opcode for Sstore {
tx_id: state.tx_ctx.id(),
address: state.call()?.address,
key,
value: true,
value_prev: is_warm,
is_warm: true,
is_warm_prev: is_warm,
},
)?;

Expand Down
43 changes: 22 additions & 21 deletions bus-mapping/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,19 @@ pub struct TxAccessListAccountOp {
pub tx_id: usize,
/// Account Address
pub address: Address,
/// Value after the operation
pub value: bool,
/// Value before the operation
pub value_prev: bool,
/// Represents whether we can classify the access to the value as `WARM`.
pub is_warm: bool,
/// Represents whether we can classify the access to the previous value as
/// `WARM`.
pub is_warm_prev: bool,
}

impl fmt::Debug for TxAccessListAccountOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("TxAccessListAccountOp { ")?;
f.write_fmt(format_args!(
"tx_id: {:?}, addr: {:?}, val_prev: {:?}, val: {:?}",
self.tx_id, self.address, self.value_prev, self.value
"tx_id: {:?}, addr: {:?}, is_warm_prev: {:?}, is_warm: {:?}",
self.tx_id, self.address, self.is_warm_prev, self.is_warm
))?;
f.write_str(" }")
}
Expand All @@ -418,7 +419,7 @@ impl Op for TxAccessListAccountOp {

fn reverse(&self) -> Self {
let mut rev = self.clone();
swap(&mut rev.value, &mut rev.value_prev);
swap(&mut rev.is_warm, &mut rev.is_warm_prev);
rev
}
}
Expand All @@ -433,18 +434,18 @@ pub struct TxAccessListAccountStorageOp {
pub address: Address,
/// Storage Key
pub key: Word,
/// Value after the operation
pub value: bool,
/// Value before the operation
pub value_prev: bool,
/// Whether the access was classified as `WARM` or not.
pub is_warm: bool,
/// Whether the prev_value access was classified as `WARM` or not.
pub is_warm_prev: bool,
}

impl fmt::Debug for TxAccessListAccountStorageOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("TxAccessListAccountStorageOp { ")?;
f.write_fmt(format_args!(
"tx_id: {:?}, addr: {:?}, key: 0x{:x}, val_prev: {:?}, val: {:?}",
self.tx_id, self.address, self.key, self.value_prev, self.value
"tx_id: {:?}, addr: {:?}, key: 0x{:x}, is_warm_prev: {:?}, is_warm: {:?}",
self.tx_id, self.address, self.key, self.is_warm_prev, self.is_warm
))?;
f.write_str(" }")
}
Expand All @@ -469,7 +470,7 @@ impl Op for TxAccessListAccountStorageOp {

fn reverse(&self) -> Self {
let mut rev = self.clone();
swap(&mut rev.value, &mut rev.value_prev);
swap(&mut rev.is_warm, &mut rev.is_warm_prev);
rev
}
}
Expand Down Expand Up @@ -592,18 +593,18 @@ pub struct AccountDestructedOp {
pub tx_id: usize,
/// Account Address
pub address: Address,
/// Value after the operation
pub value: bool,
/// Value before the operation
pub value_prev: bool,
/// Whether the account is destructed.
pub is_destructed: bool,
/// Whether the account was previously destructed.
pub is_destructed_prev: bool,
}

impl fmt::Debug for AccountDestructedOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("AccountDestructedOp { ")?;
f.write_fmt(format_args!(
"tx_id: {:?}, addr: {:?}, val_prev: {:?}, val: {:?}",
self.tx_id, self.address, self.value_prev, self.value
"tx_id: {:?}, addr: {:?}, is_destructed_prev: {:?}, is_destructed: {:?}",
self.tx_id, self.address, self.is_destructed_prev, self.is_destructed
))?;
f.write_str(" }")
}
Expand All @@ -628,7 +629,7 @@ impl Op for AccountDestructedOp {

fn reverse(&self) -> Self {
let mut rev = self.clone();
swap(&mut rev.value, &mut rev.value_prev);
swap(&mut rev.is_destructed, &mut rev.is_destructed_prev);
rev
}
}
Expand Down
Loading

0 comments on commit d525968

Please sign in to comment.