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

feat: add sstore circuit #383

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions bus-mapping/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ impl Op for TxAccessListAccountStorageOp {
pub struct TxRefundOp {
/// Transaction ID: Transaction index in the block starting at 1.
pub tx_id: usize,
/// Refund of gas after the operation
/// Refund Value in units of gas after the operation.
pub value: u64,
/// Refund of gas before the operation
/// Refund Value in units of gas after the operation.
pub value_prev: u64,
}

Expand Down
8 changes: 8 additions & 0 deletions eth-types/src/evm_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ impl GasCost {
pub const COLD_ACCOUNT_ACCESS_COST: Self = Self(2600);
/// Constant cost for a warm storage read
pub const WARM_STORAGE_READ_COST: Self = Self(100);
/// Constant cost for a basic storage operation
pub const SLOAD_GAS: Self = Self(100);
/// Constant cost for a storage set
pub const SSTORE_SET_GAS: Self = Self(20000);
/// Constant cost for a storage reset
pub const SSTORE_RESET_GAS: Self = Self(2900);
/// Constant cost for a storage clear
pub const SSTORE_CLEARS_SCHEDULE: Self = Self(15000);
/// Constant cost for a non-creation transaction
pub const TX: Self = Self(21000);
/// Constant cost for creation transaction
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 @@ -48,6 +48,7 @@ mod selfbalance;
mod signed_comparator;
mod signextend;
mod sload;
mod sstore;
mod stop;
mod swap;
mod timestamp;
Expand Down Expand Up @@ -83,6 +84,7 @@ use selfbalance::SelfbalanceGadget;
use signed_comparator::SignedComparatorGadget;
use signextend::SignextendGadget;
use sload::SloadGadget;
use sstore::SstoreGadget;
use stop::StopGadget;
use swap::SwapGadget;
use timestamp::TimestampGadget;
Expand Down Expand Up @@ -146,6 +148,7 @@ pub(crate) struct ExecutionConfig<F> {
selfbalance_gadget: SelfbalanceGadget<F>,
number_gadget: NumberGadget<F>,
sload_gadget: SloadGadget<F>,
sstore_gadget: SstoreGadget<F>,
}

impl<F: Field> ExecutionConfig<F> {
Expand Down Expand Up @@ -360,6 +363,7 @@ impl<F: Field> ExecutionConfig<F> {
timestamp_gadget: configure_gadget!(),
number_gadget: configure_gadget!(),
sload_gadget: configure_gadget!(),
sstore_gadget: configure_gadget!(),
step: step_curr,
presets_map,
};
Expand Down Expand Up @@ -629,6 +633,7 @@ impl<F: Field> ExecutionConfig<F> {
}
ExecutionState::SELFBALANCE => assign_exec_step!(self.selfbalance_gadget),
ExecutionState::SLOAD => assign_exec_step!(self.sload_gadget),
ExecutionState::SSTORE => assign_exec_step!(self.sstore_gadget),
ExecutionState::CALLDATACOPY => {
assign_exec_step!(self.calldatacopy_gadget)
}
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<F: Field> ExecutionGadget<F> for EndTxGadget<F> {
step: &ExecStep,
) -> Result<(), Error> {
let gas_used = tx.gas - step.gas_left;
let refund = block.rws[step.rw_indices[1]].tx_refund_value();
let (refund, _) = block.rws[step.rw_indices[1]].tx_refund_value_pair();
let [caller_balance_pair, coinbase_balance_pair] =
[step.rw_indices[2], step.rw_indices[3]].map(|idx| block.rws[idx].account_value_pair());

Expand Down
Loading