Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f00aaee
update
0xmountaintop Feb 13, 2022
afcde83
fix clippy
0xmountaintop Feb 13, 2022
20de4a7
clean up
0xmountaintop Feb 13, 2022
ef434f4
cargo fmt
0xmountaintop Feb 13, 2022
958aa40
cargo clippy
0xmountaintop Feb 13, 2022
29a59f9
minor
0xmountaintop Feb 14, 2022
45e18fc
Merge remote-tracking branch 'origin/main' into re-init
0xmountaintop Feb 15, 2022
8c3987c
Merge branch 'main' into re-init
0xmountaintop Feb 17, 2022
3e1aaa0
merge with master
0xmountaintop Feb 21, 2022
6e7e4d2
Merge remote-tracking branch 'origin/main' into re-init
0xmountaintop Feb 21, 2022
6555051
minor
0xmountaintop Feb 21, 2022
8541fe9
cargo fmt
0xmountaintop Feb 21, 2022
9a53e70
add more to StorageOp
0xmountaintop Feb 21, 2022
a438997
skip for now
0xmountaintop Feb 21, 2022
167b1c3
cargo fmt
0xmountaintop Feb 21, 2022
2473e5b
minor
0xmountaintop Feb 21, 2022
e087cf9
minor
0xmountaintop Feb 21, 2022
43bee1e
minor
0xmountaintop Feb 21, 2022
191c86f
minor
0xmountaintop Feb 21, 2022
5250724
minor
0xmountaintop Feb 21, 2022
bb21899
minor
0xmountaintop Feb 21, 2022
c14aa07
minor
0xmountaintop Feb 22, 2022
69a97a0
minor
0xmountaintop Feb 22, 2022
d0c03a0
update
0xmountaintop Feb 22, 2022
be6fe59
fix
0xmountaintop Feb 22, 2022
d4de9bd
cargo fmt
0xmountaintop Feb 22, 2022
bf79194
cargo clippy
0xmountaintop Feb 22, 2022
5797745
init test_with_busmapping
0xmountaintop Feb 22, 2022
75e1244
WIP
0xmountaintop Feb 23, 2022
b9b6ea7
merge with latest master again
0xmountaintop Feb 23, 2022
f8c7887
update
0xmountaintop Feb 23, 2022
350d881
Merge remote-tracking branch 'origin/main' into deal_with_call_context
0xmountaintop Feb 23, 2022
2283e97
fix
0xmountaintop Feb 23, 2022
e0fcbb7
Merge branch 're-init' into busmapping/sload_new
0xmountaintop Feb 23, 2022
e3f24b2
update
0xmountaintop Feb 23, 2022
7f280ef
handle TxAccessListAccountStorageOp
0xmountaintop Feb 23, 2022
5c1092d
minor
0xmountaintop Feb 23, 2022
d400d4e
update
0xmountaintop Feb 23, 2022
8dfc555
minor
0xmountaintop Feb 23, 2022
58b80a0
Merge branch 'main' into re-init
0xmountaintop Feb 24, 2022
5dc1a51
Merge remote-tracking branch 'origin/re-init' into busmapping/sload_new
0xmountaintop Feb 24, 2022
0764ff3
minor
0xmountaintop Feb 24, 2022
2bb826b
merge and fix conflicts
0xmountaintop Feb 25, 2022
5f4387b
Merge branch 'main' into busmapping/sload_new
0xmountaintop Feb 27, 2022
9f09a76
merge and fix conflicts
0xmountaintop Feb 27, 2022
809fd14
remove call_id cell
0xmountaintop Mar 1, 2022
96ffbff
rename result to is_persist
0xmountaintop Mar 3, 2022
a0f91c6
cargo clippy
0xmountaintop Mar 3, 2022
e54b012
Merge branch 'main' into busmapping/sload_new
0xmountaintop Mar 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 99 additions & 2 deletions bus-mapping/src/evm/opcodes/sload.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::Opcode;
use crate::circuit_input_builder::CircuitInputStateRef;
use crate::{
operation::{StorageOp, RW},
operation::{CallContextField, CallContextOp, StorageOp, TxAccessListAccountStorageOp, RW},
Error,
};
use eth_types::GethExecStep;
use eth_types::{GethExecStep, ToWord, Word};

/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the [`OpcodeId::SLOAD`](crate::evm::OpcodeId::SLOAD)
Expand All @@ -19,6 +19,39 @@ impl Opcode for Sload {
) -> Result<(), Error> {
let step = &steps[0];

state.push_op(
RW::READ,
CallContextOp {
call_id: state.call().call_id,
field: CallContextField::TxId,
value: Word::from(state.tx_ctx.id()),
},
);
state.push_op(
RW::READ,
CallContextOp {
call_id: state.call().call_id,
field: CallContextField::RwCounterEndOfReversion,
value: Word::from(state.call().rw_counter_end_of_reversion),
},
);
state.push_op(
RW::READ,
CallContextOp {
call_id: state.call().call_id,
field: CallContextField::IsPersistent,
value: Word::from(state.call().is_persistent as u8),
},
);
state.push_op(
RW::READ,
CallContextOp {
call_id: state.call().call_id,
field: CallContextField::CalleeAddress,
value: state.call().address.to_word(),
},
);

// First stack read
let stack_value_read = step.stack.last()?;
let stack_position = step.stack.last_filled();
Expand All @@ -35,12 +68,25 @@ impl Opcode for Sload {
stack_value_read,
storage_value_read,
storage_value_read,
state.tx_ctx.id(),
storage_value_read, // TODO: committed_value
),
);

// First stack write
state.push_stack_op(RW::WRITE, stack_position, storage_value_read);

state.push_op_reversible(
RW::WRITE,
TxAccessListAccountStorageOp {
tx_id: state.tx_ctx.id(),
address: state.call().address,
key: stack_value_read,
value: true,
value_prev: false, // TODO:
},
);

Ok(())
}
}
Expand All @@ -49,6 +95,10 @@ impl Opcode for Sload {
mod sload_tests {
use super::*;
use crate::circuit_input_builder::{ExecStep, TransactionContext};
use crate::{
operation::{CallContextField, CallContextOp, StorageOp, TxAccessListAccountStorageOp, RW},
Error,
};
use eth_types::evm_types::StackAddress;
use eth_types::{bytecode, Address, Word};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -90,6 +140,40 @@ mod sload_tests {
0,
);
let mut state_ref = test_builder.state_ref(&mut tx, &mut tx_ctx, &mut step);

state_ref.push_op(
RW::READ,
CallContextOp {
call_id: state_ref.call().call_id,
field: CallContextField::TxId,
value: Word::from(state_ref.tx_ctx.id()),
},
);
state_ref.push_op(
RW::READ,
CallContextOp {
call_id: state_ref.call().call_id,
field: CallContextField::RwCounterEndOfReversion,
value: Word::from(state_ref.call().rw_counter_end_of_reversion),
},
);
state_ref.push_op(
RW::READ,
CallContextOp {
call_id: state_ref.call().call_id,
field: CallContextField::IsPersistent,
value: Word::from(state_ref.call().is_persistent as u8),
},
);
state_ref.push_op(
RW::READ,
CallContextOp {
call_id: state_ref.call().call_id,
field: CallContextField::CalleeAddress,
value: state_ref.call().address.to_word(),
},
);

// Add StackOp associated to the stack pop.
state_ref.push_stack_op(RW::READ, StackAddress::from(1023), Word::from(0x0u32));
// Add StorageOp associated to the storage read.
Expand All @@ -100,10 +184,23 @@ mod sload_tests {
Word::from(0x0u32),
Word::from(0x6fu32),
Word::from(0x6fu32),
1usize,
Word::from(0x6fu32),
),
);
// Add StackOp associated to the stack push.
state_ref.push_stack_op(RW::WRITE, StackAddress::from(1023), Word::from(0x6fu32));
state_ref.push_op_reversible(
RW::WRITE,
TxAccessListAccountStorageOp {
tx_id: state_ref.tx_ctx.id(),
address: Address::from([0u8; 20]),
key: Word::from(0x0u32),
value: true,
value_prev: false, // TODO:
},
);

tx.steps_mut().push(step);
test_builder.block.txs_mut().push(tx);

Expand Down
19 changes: 16 additions & 3 deletions bus-mapping/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,27 +286,40 @@ pub struct StorageOp {
pub value: Word,
/// Storage Value before the operation
pub value_prev: Word,
/// Transaction ID: Transaction index in the block starting at 1.
pub tx_id: usize,
/// Storage Value before the transaction
pub committed_value: Word,
}

impl fmt::Debug for StorageOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("StorageOp { ")?;
f.write_fmt(format_args!(
"addr: {:?}, key: {:?}, val_prev: 0x{:x}, val: 0x{:x}",
self.address, self.key, self.value_prev, self.value,
"tx_id: {:?}, addr: {:?}, key: {:?}, committed_val: 0x{:x}, val_prev: 0x{:x}, val: 0x{:x}",
self.tx_id, self.address, self.key, self.committed_value, self.value_prev, self.value
))?;
f.write_str(" }")
}
}

impl StorageOp {
/// Create a new instance of a `StorageOp` from it's components.
pub const fn new(address: Address, key: Word, value: Word, value_prev: Word) -> StorageOp {
pub const fn new(
address: Address,
key: Word,
value: Word,
value_prev: Word,
tx_id: usize,
committed_value: Word,
) -> StorageOp {
StorageOp {
address,
key,
value,
value_prev,
tx_id,
committed_value,
}
}

Expand Down
2 changes: 2 additions & 0 deletions bus-mapping/src/operation/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ mod container_test {
Word::default(),
Word::from(0x1),
Word::default(),
1usize,
Word::default(),
),
);
let stack_ref = operation_container.insert(stack_operation.clone());
Expand Down
5 changes: 5 additions & 0 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod selfbalance;
mod signed_comparator;
mod signextend;
mod stop;
mod storage;
mod swap;
mod timestamp;

Expand Down Expand Up @@ -74,6 +75,7 @@ use selfbalance::SelfbalanceGadget;
use signed_comparator::SignedComparatorGadget;
use signextend::SignextendGadget;
use stop::StopGadget;
use storage::SloadGadget;
use swap::SwapGadget;
use timestamp::TimestampGadget;

Expand Down Expand Up @@ -130,6 +132,7 @@ pub(crate) struct ExecutionConfig<F> {
coinbase_gadget: CoinbaseGadget<F>,
timestamp_gadget: TimestampGadget<F>,
selfbalance_gadget: SelfbalanceGadget<F>,
sload_gadget: SloadGadget<F>,
}

impl<F: Field> ExecutionConfig<F> {
Expand Down Expand Up @@ -264,6 +267,7 @@ impl<F: Field> ExecutionConfig<F> {
msize_gadget: configure_gadget!(),
coinbase_gadget: configure_gadget!(),
timestamp_gadget: configure_gadget!(),
sload_gadget: configure_gadget!(),
step: step_curr,
presets_map,
};
Expand Down Expand Up @@ -519,6 +523,7 @@ impl<F: Field> ExecutionConfig<F> {
assign_exec_step!(self.timestamp_gadget)
}
ExecutionState::SELFBALANCE => assign_exec_step!(self.selfbalance_gadget),
ExecutionState::SLOAD => assign_exec_step!(self.sload_gadget),
ExecutionState::CALLDATACOPY => {
assign_exec_step!(self.calldatacopy_gadget)
}
Expand Down
3 changes: 3 additions & 0 deletions zkevm-circuits/src/evm_circuit/execution/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod sload;

pub(crate) use sload::SloadGadget;
Loading