Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit a265998

Browse files
committed
fmt and lint
1 parent f628e0c commit a265998

File tree

6 files changed

+90
-89
lines changed

6 files changed

+90
-89
lines changed

bus-mapping/src/circuit_input_builder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ mod block;
66
mod call;
77
mod execution;
88
mod input_state_ref;
9+
#[cfg(feature = "scroll")]
10+
mod l2;
911
#[cfg(test)]
1012
mod tracer_tests;
1113
mod transaction;
12-
#[cfg(feature="scroll")]
13-
mod l2;
1414

1515
use self::access::gen_state_access_trace;
1616
pub use self::block::BlockHead;
@@ -48,15 +48,15 @@ use ethers_core::utils::keccak256;
4848
pub use input_state_ref::CircuitInputStateRef;
4949
use itertools::Itertools;
5050
use log::warn;
51+
#[cfg(feature = "scroll")]
52+
use mpt_zktrie::state::ZktrieState;
5153
use std::{
5254
collections::{BTreeMap, HashMap},
5355
iter,
5456
};
5557
pub use transaction::{
5658
Transaction, TransactionContext, TxL1Fee, TX_L1_COMMIT_EXTRA_COST, TX_L1_FEE_PRECISION,
5759
};
58-
#[cfg(feature="scroll")]
59-
use mpt_zktrie::state::ZktrieState;
6060

6161
/// Setup parameters for ECC-related precompile calls.
6262
#[derive(Debug, Clone, Copy)]
@@ -164,7 +164,7 @@ pub struct CircuitInputBuilder {
164164
pub block: Block,
165165
/// Block Context
166166
pub block_ctx: BlockContext,
167-
#[cfg(feature="scroll")]
167+
#[cfg(feature = "scroll")]
168168
/// Zktrie Status
169169
pub mpt_state: ZktrieState,
170170
}
@@ -178,7 +178,7 @@ impl<'a> CircuitInputBuilder {
178178
code_db,
179179
block: block.clone(),
180180
block_ctx: BlockContext::new(),
181-
#[cfg(feature="scroll")]
181+
#[cfg(feature = "scroll")]
182182
mpt_state: Default::default(),
183183
}
184184
}

bus-mapping/src/circuit_input_builder/l2.rs

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1-
use mpt_zktrie::state::{ZktrieState, AccountData};
1+
pub use super::block::{Block, BlockContext};
22
use crate::{
3+
circuit_input_builder::{self, BlockHead, CircuitInputBuilder, CircuitsParams},
34
error::Error,
45
state_db::{self, CodeDB, StateDB},
5-
circuit_input_builder::{self, CircuitInputBuilder, BlockHead, CircuitsParams},
66
};
7-
pub use super::block::{Block, BlockContext};
8-
use ethers_core::types::{Bytes, U256};
97
use eth_types::{
108
self,
11-
l2_types::{BlockTrace, ExecStep, EthBlock},
129
evm_types::OpcodeId,
10+
l2_types::{BlockTrace, EthBlock, ExecStep},
1311
ToAddress, H256,
1412
};
13+
use ethers_core::types::{Bytes, U256};
14+
use mpt_zktrie::state::{AccountData, ZktrieState};
1515
use std::collections::hash_map::Entry;
1616

1717
impl From<&AccountData> for state_db::Account {
18-
1918
fn from(acc_data: &AccountData) -> Self {
2019
Self {
2120
nonce: acc_data.nonce.into(),
2221
balance: acc_data.balance,
2322
code_hash: acc_data.poseidon_code_hash,
2423
keccak_code_hash: acc_data.keccak_code_hash,
2524
code_size: acc_data.code_size.into(),
26-
storage: Default::default(),
25+
storage: Default::default(),
2726
}
2827
}
2928
}
3029

3130
impl From<&ZktrieState> for StateDB {
32-
3331
fn from(mpt_state: &ZktrieState) -> Self {
34-
3532
let mut sdb = StateDB::new();
3633

3734
for (addr, acc) in mpt_state.state() {
@@ -45,7 +42,7 @@ impl From<&ZktrieState> for StateDB {
4542
}
4643

4744
sdb
48-
}
45+
}
4946
}
5047

5148
fn decode_bytecode(bytecode: &str) -> Result<Vec<u8>, hex::FromHexError> {
@@ -127,7 +124,6 @@ fn trace_code(
127124
}
128125

129126
fn update_codedb(cdb: &mut CodeDB, sdb: &StateDB, block: &BlockTrace) {
130-
131127
log::debug!("build_codedb for block {:?}", block.header.number);
132128
for (er_idx, execution_result) in block.execution_results.iter().enumerate() {
133129
if let Some(bytecode) = &execution_result.byte_code {
@@ -165,7 +161,10 @@ fn update_codedb(cdb: &mut CodeDB, sdb: &StateDB, block: &BlockTrace) {
165161
1
166162
};
167163
let callee_code = data.get_code_at(code_idx);
168-
assert!(callee_code.is_none(), "invalid trace: cannot get code of call: {step:?}");
164+
assert!(
165+
callee_code.is_none(),
166+
"invalid trace: cannot get code of call: {step:?}"
167+
);
169168
let code_hash = match step.op {
170169
OpcodeId::CALL | OpcodeId::CALLCODE => data.get_code_hash_at(1),
171170
OpcodeId::STATICCALL => data.get_code_hash_at(0),
@@ -179,7 +178,10 @@ fn update_codedb(cdb: &mut CodeDB, sdb: &StateDB, block: &BlockTrace) {
179178
}
180179
OpcodeId::EXTCODESIZE | OpcodeId::EXTCODECOPY => {
181180
let code = data.get_code_at(0);
182-
assert!(code.is_none(), "invalid trace: cannot get code of ext: {step:?}");
181+
assert!(
182+
code.is_none(),
183+
"invalid trace: cannot get code of ext: {step:?}"
184+
);
183185
trace_code(cdb, None, code.unwrap(), step, sdb, 0);
184186
}
185187

@@ -192,22 +194,20 @@ fn update_codedb(cdb: &mut CodeDB, sdb: &StateDB, block: &BlockTrace) {
192194
log::debug!("updating codedb done");
193195
}
194196

195-
fn dump_code_db(cdb: &CodeDB){
197+
fn dump_code_db(cdb: &CodeDB) {
196198
for (k, v) in &cdb.0 {
197199
assert!(!k.is_zero());
198200
log::trace!("codedb codehash {:?}, len {}", k, v.len());
199-
}
201+
}
200202
}
201203

202204
impl CircuitInputBuilder {
203-
204-
fn apply_l2_trace(
205-
&mut self,
206-
block_trace: &BlockTrace,
207-
is_last: bool,
208-
) -> Result<(), Error>{
209-
let geth_trace : Vec<eth_types::GethExecTrace>
210-
= block_trace.execution_results.iter().map(From::from).collect();
205+
fn apply_l2_trace(&mut self, block_trace: &BlockTrace, is_last: bool) -> Result<(), Error> {
206+
let geth_trace: Vec<eth_types::GethExecTrace> = block_trace
207+
.execution_results
208+
.iter()
209+
.map(From::from)
210+
.collect();
211211
let eth_block: EthBlock = block_trace.clone().into();
212212
assert_eq!(
213213
self.block.chain_id, block_trace.chain_id,
@@ -241,7 +241,6 @@ impl CircuitInputBuilder {
241241
l2_trace: &BlockTrace,
242242
more: bool,
243243
) -> Result<Self, Error> {
244-
245244
let chain_id = l2_trace.chain_id;
246245

247246
let mut code_db = CodeDB::new();
@@ -257,35 +256,34 @@ impl CircuitInputBuilder {
257256
l2_trace.header.number,
258257
hex::encode(old_root),
259258
);
260-
let account_proofs = l2_trace
261-
.storage_trace
262-
.proofs.iter().flat_map(
263-
|kv_map| {
264-
kv_map
265-
.iter()
266-
.map(|(k, bts)| (k, bts.iter().map(Bytes::as_ref)))
267-
});
268-
let storage_proofs = l2_trace
269-
.storage_trace
270-
.storage_proofs
271-
.iter()
272-
.flat_map(|(k, kv_map)| {
273-
kv_map
274-
.iter()
275-
.map(move |(sk, bts)| (k, sk, bts.iter().map(Bytes::as_ref)))
276-
});
259+
let account_proofs = l2_trace.storage_trace.proofs.iter().flat_map(|kv_map| {
260+
kv_map
261+
.iter()
262+
.map(|(k, bts)| (k, bts.iter().map(Bytes::as_ref)))
263+
});
264+
let storage_proofs =
265+
l2_trace
266+
.storage_trace
267+
.storage_proofs
268+
.iter()
269+
.flat_map(|(k, kv_map)| {
270+
kv_map
271+
.iter()
272+
.map(move |(sk, bts)| (k, sk, bts.iter().map(Bytes::as_ref)))
273+
});
277274
let additional_proofs = l2_trace
278275
.storage_trace
279276
.deletion_proofs
280277
.iter()
281278
.map(Bytes::as_ref);
282279

283280
let mpt_state = ZktrieState::from_trace_with_additional(
284-
old_root,
285-
account_proofs,
286-
storage_proofs,
287-
additional_proofs
288-
).unwrap();
281+
old_root,
282+
account_proofs,
283+
storage_proofs,
284+
additional_proofs,
285+
)
286+
.unwrap();
289287

290288
log::debug!(
291289
"building partial statedb done, root {}",
@@ -308,13 +306,11 @@ impl CircuitInputBuilder {
308306
builder.apply_l2_trace(l2_trace, !more)?;
309307
Ok(builder)
310308
}
311-
309+
312310
/// make finalize actions on building, must called after
313311
/// all block trace have been input
314-
pub fn finalize_building(&mut self) -> Result<(), Error>{
312+
pub fn finalize_building(&mut self) -> Result<(), Error> {
315313
self.set_value_ops_call_context_rwc_eor();
316-
self.set_end_block()
314+
self.set_end_block()
317315
}
318-
319316
}
320-

eth-types/src/geth_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pub struct GethData {
378378
/// Accounts
379379
pub accounts: Vec<Account>,
380380
}
381-
/*
381+
/*
382382
impl GethData {
383383
/// Signs transactions with selected wallets
384384
pub fn sign(&mut self, wallets: &HashMap<Address, LocalWallet>) {
@@ -397,4 +397,4 @@ impl GethData {
397397
}
398398
}
399399
}
400-
*/
400+
*/

external-tracer/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! This module generates traces by connecting to an external tracer
22
3+
#[cfg(feature = "scroll")]
4+
use eth_types::l2_types::BlockTrace;
35
use eth_types::{
46
geth_types::{Account, BlockConstants, Transaction},
57
Address, Error, GethExecTrace, Word,
68
};
7-
#[cfg(feature="scroll")]
8-
use eth_types::l2_types::BlockTrace;
99
use serde::Serialize;
1010
use std::collections::HashMap;
1111

@@ -104,9 +104,8 @@ pub fn trace(config: &TraceConfig) -> Result<Vec<GethExecTrace>, Error> {
104104
Ok(trace)
105105
}
106106

107-
108107
/// Creates a l2-trace for the specified config
109-
#[cfg(feature="scroll")]
108+
#[cfg(feature = "scroll")]
110109
pub fn l2trace(config: &TraceConfig) -> Result<BlockTrace, Error> {
111110
// Get the trace
112111
let trace_string = geth_utils::l2trace(&serde_json::to_string(&config).unwrap()).map_err(

mock/src/test_ctx.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//! Mock types and functions to generate Test enviroments for ZKEVM tests
22
33
use crate::{eth, MockAccount, MockBlock, MockTransaction};
4+
#[cfg(feature = "scroll")]
5+
use eth_types::l2_types::BlockTrace;
46
use eth_types::{
57
geth_types::{Account, BlockConstants, GethData},
68
BigEndianHash, Block, Bytecode, Error, Transaction, Word, H256,
79
};
8-
#[cfg(feature="scroll")]
9-
use eth_types::l2_types::BlockTrace;
10-
use external_tracer::TraceConfig;
11-
#[cfg(not(feature="scroll"))]
12-
use external_tracer::trace;
13-
#[cfg(feature="scroll")]
10+
#[cfg(feature = "scroll")]
1411
use external_tracer::l2trace;
12+
#[cfg(not(feature = "scroll"))]
13+
use external_tracer::trace;
14+
use external_tracer::TraceConfig;
1515
use helpers::*;
1616
use itertools::Itertools;
1717

@@ -96,7 +96,7 @@ pub struct TestContext<const NACC: usize, const NTX: usize> {
9696
/// Execution Trace from geth
9797
pub geth_traces: Vec<eth_types::GethExecTrace>,
9898

99-
#[cfg(feature="scroll")]
99+
#[cfg(feature = "scroll")]
100100
block_trace: BlockTrace,
101101
}
102102

@@ -190,14 +190,17 @@ impl<const NACC: usize, const NTX: usize> TestContext<NACC, NTX> {
190190
logger_config,
191191
)?;
192192

193-
#[cfg(feature="scroll")]
193+
#[cfg(feature = "scroll")]
194194
let block_trace = l2trace(&trace_config)?;
195195

196-
#[cfg(feature="scroll")]
197-
let geth_traces = block_trace.execution_results
198-
.iter().map(From::from).collect::<Vec<_>>();
196+
#[cfg(feature = "scroll")]
197+
let geth_traces = block_trace
198+
.execution_results
199+
.iter()
200+
.map(From::from)
201+
.collect::<Vec<_>>();
199202

200-
#[cfg(not(feature="scroll"))]
203+
#[cfg(not(feature = "scroll"))]
201204
let geth_traces = trace(&trace_config)?;
202205

203206
Ok(Self {
@@ -206,7 +209,7 @@ impl<const NACC: usize, const NTX: usize> TestContext<NACC, NTX> {
206209
history_hashes: history_hashes.unwrap_or_default(),
207210
eth_block: block,
208211
geth_traces,
209-
#[cfg(feature="scroll")]
212+
#[cfg(feature = "scroll")]
210213
block_trace,
211214
})
212215
}
@@ -238,8 +241,10 @@ impl<const NACC: usize, const NTX: usize> TestContext<NACC, NTX> {
238241
}
239242

240243
/// obtain the full l2 block trace
241-
#[cfg(feature="scroll")]
242-
pub fn l2_trace(&self) -> &BlockTrace { &self.block_trace }
244+
#[cfg(feature = "scroll")]
245+
pub fn l2_trace(&self) -> &BlockTrace {
246+
&self.block_trace
247+
}
243248

244249
/// Returns a simple TestContext setup with a single tx executing the
245250
/// bytecode passed as parameters. The balances of the 2 accounts and

0 commit comments

Comments
 (0)