Skip to content

Commit

Permalink
add l2 prestate
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing committed Nov 27, 2023
1 parent 1a43b24 commit 00f6015
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[target.'cfg(target_os="macos")']
rustflags = ["-C", "link-args=-framework CoreFoundation -framework Security"]
rustflags = ["-C", "link-args=-framework CoreFoundation -framework Security -framework CoreServices"]
[net]
git-fetch-with-cli = true
[env]
Expand Down
34 changes: 1 addition & 33 deletions bus-mapping/src/circuit_input_builder/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,46 +104,14 @@ impl AccessSet {
self.code.extend(other.code.drain());
}

#[cfg(not(feature = "scroll"))]
pub(crate) fn from_geth_data(geth_data: &GethData) -> Self {
let mut access_set = AccessSet::default();
access_set.add_account(geth_data.eth_block.author.unwrap());
for trace in geth_data.geth_traces.iter() {
access_set.extend_from_traces(trace.prestate.as_ref().unwrap());
access_set.extend_from_traces(&trace.prestate);
}
access_set
}

#[cfg(feature = "scroll")]
pub(crate) fn from_geth_data(geth_data: &GethData) -> Self {
let mut access_set = AccessSet::default();
access_set.add_account(geth_data.eth_block.author.unwrap());
for (addr, storage) in geth_data.block_trace.storage_trace.storage_proofs.iter() {
log::info!("add addr {:?} to access_set", addr);
access_set.add_account(*addr);
access_set.add_code(*addr);
for key in storage.keys() {
log::info!("add addr {:?} key {:?} to access_set", addr, key);
access_set.add_storage(*addr, *key);
}
}
if let Some(ref proofs) = geth_data.block_trace.storage_trace.proofs {
for addr in proofs.keys() {
log::info!("add addr {:?} to access_set", addr);
access_set.add_account(*addr);
access_set.add_code(*addr);
}
}
access_set
}
}

impl From<Vec<Access>> for AccessSet {
fn from(list: Vec<Access>) -> Self {
let mut access_set = AccessSet::default();
access_set.extend_from_access(list);
access_set
}
}

/// Source of the code in the EVM execution.
Expand Down
5 changes: 0 additions & 5 deletions eth-types/src/geth_types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Types needed for generating Ethereum traces

#[cfg(feature = "scroll")]
use crate::l2_types::BlockTrace;
use crate::{
sign_types::{biguint_to_32bytes_le, ct_option_ok_or, recover_pk2, SignData, SECP256K1_Q},
AccessList, Address, Block, Bytes, Error, GethExecTrace, Hash, ToBigEndian, ToLittleEndian,
Expand Down Expand Up @@ -383,9 +381,6 @@ pub struct GethData {
pub geth_traces: Vec<GethExecTrace>,
/// Accounts
pub accounts: Vec<Account>,
/// block trace
#[cfg(feature = "scroll")]
pub block_trace: BlockTrace,
}
/*
impl GethData {
Expand Down
8 changes: 5 additions & 3 deletions eth-types/src/l2_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use crate::{
evm_types::{Gas, GasCost, OpcodeId, ProgramCounter},
Block, GethCallTrace, GethExecError, GethExecStep, GethExecTrace, Hash, Transaction, Word,
H256,
Block, GethCallTrace, GethExecError, GethExecStep, GethExecTrace, GethPrestateTrace, Hash,
Transaction, Word, H256,
};
use ethers_core::types::{Address, Bytes, U256, U64};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -208,6 +208,8 @@ pub struct ExecutionResult {
/// callTrace
#[serde(rename = "callTrace")]
pub call_trace: GethCallTrace,
/// prestate
pub prestate: HashMap<Address, GethPrestateTrace>,
}

impl From<ExecutionResult> for GethExecTrace {
Expand All @@ -220,7 +222,7 @@ impl From<ExecutionResult> for GethExecTrace {
return_value: e.return_value,
struct_logs,
account_after: e.account_after,
prestate: None,
prestate: e.prestate,
call_trace: e.call_trace,
}
}
Expand Down
5 changes: 3 additions & 2 deletions eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ pub struct GethExecTrace {
/// Only viable for scroll mode
pub account_after: Vec<crate::l2_types::AccountProofWrapper>,
/// prestate trace
pub prestate: Option<HashMap<Address, GethPrestateTrace>>,
pub prestate: HashMap<Address, GethPrestateTrace>,
/// call trace
#[serde(rename = "callTrace")]
pub call_trace: GethCallTrace,
Expand Down Expand Up @@ -870,6 +870,7 @@ mod tests {
]
}
],
"prestate": {},
"callTrace": {
"calls": [],
"error": null,
Expand Down Expand Up @@ -957,7 +958,7 @@ mod tests {
]),
}
],
prestate: None,
prestate: HashMap::new(),
call_trace: GethCallTrace {
calls: Vec::new(),
error: None,
Expand Down
2 changes: 1 addition & 1 deletion geth-utils/l2geth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/imdario/mergo v0.3.16
github.com/scroll-tech/go-ethereum v1.10.14-0.20231108100028-cb76ecd42bf7
github.com/scroll-tech/go-ethereum v1.10.14-0.20231127055938-52511afb103f
)

require (
Expand Down
4 changes: 3 additions & 1 deletion geth-utils/l2geth/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ github.com/scroll-tech/go-ethereum v1.10.14-0.20230901060443-e1eebd17067c h1:GuA
github.com/scroll-tech/go-ethereum v1.10.14-0.20230901060443-e1eebd17067c/go.mod h1:DiN3p2inoXOxGffxSswDKqWjQ7bU+Mp0c9v0XQXKmaA=
github.com/scroll-tech/go-ethereum v1.10.14-0.20230919024151-fa0be69a3fb9 h1:QiqH+ZGNNzMcKy21VGX6XYg81DXE+/9j1Ik7owm13hs=
github.com/scroll-tech/go-ethereum v1.10.14-0.20230919024151-fa0be69a3fb9/go.mod h1:DiN3p2inoXOxGffxSswDKqWjQ7bU+Mp0c9v0XQXKmaA=
github.com/scroll-tech/go-ethereum v1.10.14-0.20231127055938-52511afb103f h1:rWae0zTgyQg41TnbUl1u8QC5VDfN8FA4WTMn7UTkUKo=
github.com/scroll-tech/go-ethereum v1.10.14-0.20231127055938-52511afb103f/go.mod h1:4HrFcoStbViFVy/9l/rvKl1XmizVAaPdgqI8v0U8hOc=
github.com/scroll-tech/zktrie v0.6.0 h1:xLrMAO31Yo2BiPg1jtYKzcjpEFnXy8acbB7iIsyshPs=
github.com/scroll-tech/zktrie v0.6.0/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
Expand Down Expand Up @@ -243,4 +245,4 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 0 additions & 2 deletions mock/src/test_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ impl<const NACC: usize, const NTX: usize> From<TestContext<NACC, NTX>> for GethD
eth_block: ctx.eth_block,
geth_traces: ctx.geth_traces.to_vec(),
accounts: ctx.accounts.into(),
#[cfg(feature = "scroll")]
block_trace: ctx.block_trace,
}
}
}
Expand Down

0 comments on commit 00f6015

Please sign in to comment.