forked from privacy-scaling-explorations/zkevm-circuits
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…ons#1147) Close privacy-scaling-explorations#1119 Spec markdown PR privacy-scaling-explorations/zkevm-specs#381 ### Summary 1. Merge OOG errors for `SLOAD` and `SSTORE` into `OogError::SloadSstore`, and error states into `ExecutionState::ErrorOutOfGasSloadSstore`. 2. Move both `SloadGasGadget` and `SstoreGasGadget` to common gadget which could be reused by `SloadGadget`, `SstoreGadget` and `ErrorOOGSloadSstoreGadget`. 3. Implement `ErrorOutOfGasSloadSstore` state in both bus-mapping and zkevm-circuit. 4. Constrain `SSTORE` OOG error for both `gas_cost` and `gas_sentry`. Gas reentrancy sentry could be referenced in [this go-ethereum code](https://github.com/ethereum/go-ethereum/blob/master/core/vm/operations_acl.go#L30). --------- Co-authored-by: Han <[email protected]>
- Loading branch information
1 parent
3bf0cf1
commit 96c8617
Showing
13 changed files
with
873 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use super::{Opcode, OpcodeId}; | ||
use crate::circuit_input_builder::{CircuitInputStateRef, ExecStep}; | ||
use crate::error::{ExecError, OogError}; | ||
use crate::operation::{CallContextField, RW}; | ||
use crate::operation::{StorageOp, TxAccessListAccountStorageOp}; | ||
use crate::Error; | ||
use eth_types::{GethExecStep, ToWord}; | ||
|
||
/// Placeholder structure used to implement [`Opcode`] trait over it | ||
/// corresponding to the | ||
/// [`OogError::SloadSstore`](crate::error::OogError::SloadSstore). | ||
#[derive(Clone, Copy, Debug)] | ||
pub(crate) struct OOGSloadSstore; | ||
|
||
impl Opcode for OOGSloadSstore { | ||
fn gen_associated_ops( | ||
state: &mut CircuitInputStateRef, | ||
geth_steps: &[GethExecStep], | ||
) -> Result<Vec<ExecStep>, Error> { | ||
let geth_step = &geth_steps[0]; | ||
debug_assert!([OpcodeId::SLOAD, OpcodeId::SSTORE].contains(&geth_step.op)); | ||
|
||
let mut exec_step = state.new_step(geth_step)?; | ||
exec_step.error = Some(ExecError::OutOfGas(OogError::SloadSstore)); | ||
|
||
let call_id = state.call()?.call_id; | ||
let callee_address = state.call()?.address; | ||
let tx_id = state.tx_ctx.id(); | ||
|
||
state.call_context_read( | ||
&mut exec_step, | ||
call_id, | ||
CallContextField::TxId, | ||
tx_id.into(), | ||
); | ||
|
||
state.call_context_read( | ||
&mut exec_step, | ||
call_id, | ||
CallContextField::IsStatic, | ||
(state.call()?.is_static as u8).into(), | ||
); | ||
|
||
state.call_context_read( | ||
&mut exec_step, | ||
call_id, | ||
CallContextField::CalleeAddress, | ||
callee_address.to_word(), | ||
); | ||
|
||
let key = geth_step.stack.last()?; | ||
state.stack_read(&mut exec_step, geth_step.stack.last_filled(), key)?; | ||
|
||
let is_warm = state | ||
.sdb | ||
.check_account_storage_in_access_list(&(callee_address, key)); | ||
state.push_op( | ||
&mut exec_step, | ||
RW::READ, | ||
TxAccessListAccountStorageOp { | ||
tx_id, | ||
address: callee_address, | ||
key, | ||
is_warm, | ||
is_warm_prev: is_warm, | ||
}, | ||
); | ||
|
||
// Special operations are only used for SSTORE. | ||
if geth_step.op == OpcodeId::SSTORE { | ||
let value = geth_step.stack.nth_last(1)?; | ||
state.stack_read(&mut exec_step, geth_step.stack.nth_last_filled(1), value)?; | ||
|
||
let (_, value_prev) = state.sdb.get_storage(&callee_address, &key); | ||
let (_, original_value) = state.sdb.get_committed_storage(&callee_address, &key); | ||
|
||
state.push_op( | ||
&mut exec_step, | ||
RW::READ, | ||
StorageOp::new( | ||
callee_address, | ||
key, | ||
*value_prev, | ||
*value_prev, | ||
tx_id, | ||
*original_value, | ||
), | ||
); | ||
} | ||
|
||
state.gen_restore_context_ops(&mut exec_step, geth_steps)?; | ||
state.handle_return(geth_step)?; | ||
|
||
Ok(vec![exec_step]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.