Skip to content

Commit 596733d

Browse files
chore: Refactor and fix lints
Fix unused variables, results and imports lints Refactor some format arg captures Refactor nested if statements into guard clauses Refactor if-else chains into match pattern
1 parent 41edfc8 commit 596733d

31 files changed

+284
-302
lines changed

lib/src/builder/execute/ethereum.rs

+24-32
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,27 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
5656
// Compute the spec id
5757
let spec_id = block_builder.chain_spec.spec_id(header.number);
5858
if !SpecId::enabled(spec_id, MIN_SPEC_ID) {
59-
bail!(
60-
"Invalid protocol version: expected >= {:?}, got {:?}",
61-
MIN_SPEC_ID,
62-
spec_id,
63-
)
59+
bail!("Invalid protocol version: expected >= {MIN_SPEC_ID:?}, got {spec_id:?}");
6460
}
6561

6662
#[cfg(not(target_os = "zkvm"))]
6763
{
6864
use chrono::{TimeZone, Utc};
6965
use log::info;
7066
let dt = Utc
71-
.timestamp_opt(block_builder.input.timestamp.try_into().unwrap(), 0)
67+
.timestamp_opt(
68+
block_builder
69+
.input
70+
.timestamp
71+
.try_into()
72+
.expect("Timestamp could not fit into i64"),
73+
0,
74+
)
7275
.unwrap();
7376

7477
info!("Block no. {}", header.number);
75-
info!(" EVM spec ID: {:?}", spec_id);
76-
info!(" Timestamp: {}", dt);
78+
info!(" EVM spec ID: {spec_id:?}");
79+
info!(" Timestamp: {dt}");
7780
info!(" Transactions: {}", block_builder.input.transactions.len());
7881
info!(" Withdrawals: {}", block_builder.input.withdrawals.len());
7982
info!(" Fee Recipient: {:?}", block_builder.input.beneficiary);
@@ -92,15 +95,15 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
9295
})
9396
.modify_block_env(|blk_env| {
9497
// set the EVM block environment
95-
blk_env.number = header.number.try_into().unwrap();
98+
blk_env.number = U256::from(header.number);
9699
blk_env.coinbase = block_builder.input.beneficiary;
97100
blk_env.timestamp = header.timestamp;
98101
blk_env.difficulty = U256::ZERO;
99102
blk_env.prevrandao = Some(header.mix_hash);
100103
blk_env.basefee = header.base_fee_per_gas;
101104
blk_env.gas_limit = block_builder.input.gas_limit;
102105
})
103-
.with_db(block_builder.db.take().unwrap())
106+
.with_db(block_builder.db.take().expect("No database"))
104107
.build();
105108

106109
// bloom filter over all transaction logs
@@ -118,34 +121,34 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
118121
// verify the transaction signature
119122
let tx_from = tx
120123
.recover_from()
121-
.with_context(|| format!("Error recovering address for transaction {}", tx_no))?;
124+
.with_context(|| format!("Error recovering address for transaction {tx_no}"))?;
122125

123126
#[cfg(not(target_os = "zkvm"))]
124127
{
125128
let tx_hash = tx.hash();
126-
debug!("Tx no. {} (hash: {})", tx_no, tx_hash);
129+
debug!("Tx no. {tx_no} (hash: {tx_hash})");
127130
debug!(" Type: {}", tx.essence.tx_type());
128-
debug!(" Fr: {:?}", tx_from);
131+
debug!(" Fr: {tx_from:?}");
129132
debug!(" To: {:?}", tx.essence.to().unwrap_or_default());
130133
}
131134

132135
// verify transaction gas
133136
let block_available_gas = block_builder.input.gas_limit - cumulative_gas_used;
134137
if block_available_gas < tx.essence.gas_limit() {
135-
bail!("Error at transaction {}: gas exceeds block limit", tx_no);
138+
bail!("Error at transaction {tx_no}: gas exceeds block limit");
136139
}
137140

138141
// process the transaction
139142
fill_eth_tx_env(&mut evm.env().tx, &tx.essence, tx_from);
140143
let ResultAndState { result, state } = evm
141144
.transact()
142-
.map_err(|evm_err| anyhow!("Error at transaction {}: {:?}", tx_no, evm_err))?;
145+
.map_err(|evm_err| anyhow!("Error at transaction {tx_no}: {evm_err:?}"))?;
143146

144147
let gas_used = result.gas_used().try_into().unwrap();
145148
cumulative_gas_used = cumulative_gas_used.checked_add(gas_used).unwrap();
146149

147150
#[cfg(not(target_os = "zkvm"))]
148-
debug!(" Ok: {:?}", result);
151+
debug!(" Ok: {result:?}");
149152

150153
// create the receipt from the EVM result
151154
let receipt = Receipt::new(
@@ -175,8 +178,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
175178
if account.is_touched() {
176179
// log account
177180
debug!(
178-
" State {:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={}, is_empty={})",
179-
address,
181+
" State {address:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={}, is_empty={})",
180182
account.is_selfdestructed(),
181183
account.is_loaded_as_not_existing(),
182184
account.is_created(),
@@ -191,7 +193,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
191193
// log state changes
192194
for (addr, slot) in &account.storage {
193195
if slot.is_changed() {
194-
debug!(" Storage address: {:?}", addr);
196+
debug!(" Storage address: {addr:?}");
195197
debug!(" Before: {:?}", slot.original_value());
196198
debug!(" After: {:?}", slot.present_value());
197199
}
@@ -217,7 +219,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
217219
{
218220
debug!("Withdrawal no. {}", withdrawal.index);
219221
debug!(" Recipient: {:?}", withdrawal.address);
220-
debug!(" Value: {}", amount_wei);
222+
debug!(" Value: {amount_wei}");
221223
}
222224
// Credit withdrawal amount
223225
increase_account_balance(&mut evm.context.evm.db, withdrawal.address, amount_wei)?;
@@ -233,11 +235,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
233235
header.receipts_root = receipt_trie.hash();
234236
header.logs_bloom = logs_bloom;
235237
header.gas_used = cumulative_gas_used;
236-
header.withdrawals_root = if spec_id < SpecId::SHANGHAI {
237-
None
238-
} else {
239-
Some(withdrawals_trie.hash())
240-
};
238+
header.withdrawals_root = (spec_id < SpecId::SHANGHAI).then_some(withdrawals_trie.hash());
241239

242240
// Leak memory, save cycles
243241
guest_mem_forget([tx_trie, receipt_trie, withdrawals_trie]);
@@ -311,13 +309,7 @@ where
311309
// Read account from database
312310
let mut account: Account = db
313311
.basic(address)
314-
.map_err(|db_err| {
315-
anyhow!(
316-
"Error increasing account balance for {}: {:?}",
317-
address,
318-
db_err
319-
)
320-
})?
312+
.map_err(|db_err| anyhow!("Error increasing account balance for {address}: {db_err:?}"))?
321313
.unwrap_or_default()
322314
.into();
323315
// Credit withdrawal amount

lib/src/builder/execute/optimism.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
5858
// Compute the spec id
5959
let spec_id = block_builder.chain_spec.spec_id(header.number);
6060
if !SpecId::enabled(spec_id, MIN_SPEC_ID) {
61-
bail!(
62-
"Invalid protocol version: expected >= {:?}, got {:?}",
63-
MIN_SPEC_ID,
64-
spec_id,
65-
)
61+
bail!("Invalid protocol version: expected >= {MIN_SPEC_ID:?}, got {spec_id:?}")
6662
}
6763
let chain_id = block_builder.chain_spec.chain_id();
6864

@@ -71,12 +67,19 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
7167
use chrono::{TimeZone, Utc};
7268
use log::info;
7369
let dt = Utc
74-
.timestamp_opt(block_builder.input.timestamp.try_into().unwrap(), 0)
70+
.timestamp_opt(
71+
block_builder
72+
.input
73+
.timestamp
74+
.try_into()
75+
.expect("Timestamp could not fit into i64"),
76+
0,
77+
)
7578
.unwrap();
7679

7780
info!("Block no. {}", header.number);
78-
info!(" EVM spec ID: {:?}", spec_id);
79-
info!(" Timestamp: {}", dt);
81+
info!(" EVM spec ID: {spec_id:?}");
82+
info!(" Timestamp: {dt}");
8083
info!(" Transactions: {}", block_builder.input.transactions.len());
8184
info!(" Fee Recipient: {:?}", block_builder.input.beneficiary);
8285
info!(" Gas limit: {}", block_builder.input.gas_limit);
@@ -93,7 +96,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
9396
})
9497
.modify_block_env(|blk_env| {
9598
// set the EVM block environment
96-
blk_env.number = header.number.try_into().unwrap();
99+
blk_env.number = U256::from(header.number);
97100
blk_env.coinbase = block_builder.input.beneficiary;
98101
blk_env.timestamp = header.timestamp;
99102
blk_env.difficulty = U256::ZERO;
@@ -120,21 +123,21 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
120123
// verify the transaction signature
121124
let tx_from = tx
122125
.recover_from()
123-
.with_context(|| format!("Error recovering address for transaction {}", tx_no))?;
126+
.with_context(|| format!("Error recovering address for transaction {tx_no}"))?;
124127

125128
#[cfg(not(target_os = "zkvm"))]
126129
{
127130
let tx_hash = tx.hash();
128-
debug!("Tx no. {} (hash: {})", tx_no, tx_hash);
131+
debug!("Tx no. {tx_no} (hash: {tx_hash})");
129132
debug!(" Type: {}", tx.essence.tx_type());
130-
debug!(" Fr: {:?}", tx_from);
133+
debug!(" Fr: {tx_from:?}");
131134
debug!(" To: {:?}", tx.essence.to().unwrap_or_default());
132135
}
133136

134137
// verify transaction gas
135138
let block_available_gas = block_builder.input.gas_limit - cumulative_gas_used;
136139
if block_available_gas < tx.essence.gas_limit() {
137-
bail!("Error at transaction {}: gas exceeds block limit", tx_no);
140+
bail!("Error at transaction {tx_no}: gas exceeds block limit");
138141
}
139142

140143
match &tx.essence {
@@ -157,13 +160,13 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
157160
// process the transaction
158161
let ResultAndState { result, state } = evm
159162
.transact()
160-
.map_err(|evm_err| anyhow!("Error at transaction {}: {:?}", tx_no, evm_err))?;
163+
.map_err(|evm_err| anyhow!("Error at transaction {tx_no}: {evm_err:?}"))?;
161164

162165
let gas_used = result.gas_used().try_into().unwrap();
163166
cumulative_gas_used = cumulative_gas_used.checked_add(gas_used).unwrap();
164167

165168
#[cfg(not(target_os = "zkvm"))]
166-
debug!(" Ok: {:?}", result);
169+
debug!(" Ok: {result:?}");
167170

168171
// create the receipt from the EVM result
169172
let receipt = Receipt::new(
@@ -179,8 +182,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
179182
if account.is_touched() {
180183
// log account
181184
debug!(
182-
" State {:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={})",
183-
address,
185+
" State {address:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={})",
184186
account.is_selfdestructed(),
185187
account.is_loaded_as_not_existing(),
186188
account.is_created()
@@ -194,7 +196,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
194196
// log state changes
195197
for (addr, slot) in &account.storage {
196198
if slot.is_changed() {
197-
debug!(" Storage address: {:?}", addr);
199+
debug!(" Storage address: {addr:?}");
198200
debug!(" Before: {:?}", slot.original_value());
199201
debug!(" After: {:?}", slot.present_value());
200202
}

lib/src/builder/execute/taiko.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use core::{fmt::Debug, mem::take, str::from_utf8};
1717
use anyhow::{anyhow, bail, Context, Result};
1818
#[cfg(not(target_os = "zkvm"))]
1919
use log::debug;
20-
use log::info;
2120
use revm::{
2221
interpreter::Host,
2322
primitives::{Address, ResultAndState, SpecId, TxEnv},
@@ -58,11 +57,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
5857
// Compute the spec id
5958
let spec_id = block_builder.chain_spec.spec_id(header.number);
6059
if !SpecId::enabled(spec_id, MIN_SPEC_ID) {
61-
bail!(
62-
"Invalid protocol version: expected >= {:?}, got {:?}",
63-
MIN_SPEC_ID,
64-
spec_id,
65-
)
60+
bail!("Invalid protocol version: expected >= {MIN_SPEC_ID:?}, got {spec_id:?}")
6661
}
6762
let chain_id = block_builder.chain_spec.chain_id();
6863

@@ -71,12 +66,19 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
7166
use chrono::{TimeZone, Utc};
7267
use log::info;
7368
let dt = Utc
74-
.timestamp_opt(block_builder.input.timestamp.try_into().unwrap(), 0)
69+
.timestamp_opt(
70+
block_builder
71+
.input
72+
.timestamp
73+
.try_into()
74+
.expect("Timestamp could not fit into i64"),
75+
0,
76+
)
7577
.unwrap();
7678

7779
info!("Block no. {}", header.number);
78-
info!(" EVM spec ID: {:?}", spec_id);
79-
info!(" Timestamp: {}", dt);
80+
info!(" EVM spec ID: {spec_id:?}");
81+
info!(" Timestamp: {dt}");
8082
info!(" Transactions: {}", block_builder.input.transactions.len());
8183
info!(" Fee Recipient: {:?}", block_builder.input.beneficiary);
8284
info!(" Gas limit: {}", block_builder.input.gas_limit);
@@ -93,7 +95,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
9395
})
9496
.modify_block_env(|blk_env| {
9597
// set the EVM block environment
96-
blk_env.number = header.number.try_into().unwrap();
98+
blk_env.number = U256::from(header.number);
9799
blk_env.coinbase = block_builder.input.beneficiary;
98100
blk_env.timestamp = header.timestamp;
99101
blk_env.difficulty = U256::ZERO;
@@ -113,6 +115,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
113115
// process all the transactions
114116
let mut tx_trie = MptNode::default();
115117
let mut receipt_trie = MptNode::default();
118+
#[allow(unused_variables)]
116119
let mut actual_tx_no = 0usize;
117120

118121
for (tx_no, tx) in take(&mut block_builder.input.transactions)
@@ -124,21 +127,21 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
124127
// verify the transaction signature
125128
let tx_from = tx
126129
.recover_from()
127-
.with_context(|| anyhow!("Error recovering address for transaction {}", tx_no))?;
130+
.with_context(|| anyhow!("Error recovering address for transaction {tx_no}"))?;
128131

129132
#[cfg(not(target_os = "zkvm"))]
130133
{
131134
let tx_hash = tx.hash();
132-
debug!("Tx no. {} (hash: {})", tx_no, tx_hash);
135+
debug!("Tx no. {tx_no} (hash: {tx_hash})");
133136
debug!(" Type: {}", tx.essence.tx_type());
134-
debug!(" Fr: {:?}", tx_from);
137+
debug!(" Fr: {tx_from:?}");
135138
debug!(" To: {:?}", tx.essence.to().unwrap_or_default());
136139
}
137140

138141
// verify transaction gas
139142
let block_available_gas = block_builder.input.gas_limit - cumulative_gas_used;
140143
if block_available_gas < tx.essence.gas_limit() {
141-
bail!("Error at transaction {}: gas exceeds block limit", tx_no);
144+
bail!("Error at transaction {tx_no}: gas exceeds block limit");
142145
}
143146

144147
fill_eth_tx_env(
@@ -152,13 +155,11 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
152155
// process the transaction
153156
let ResultAndState { result, state } = evm
154157
.transact()
155-
.map_err(|evm_err| anyhow!("Error at transaction {}: {:?}", tx_no, evm_err))?;
158+
.map_err(|evm_err| anyhow!("Error at transaction {tx_no}: {evm_err:?}"))?;
156159

157160
if is_anchor && !result.is_success() {
158161
bail!(
159-
"Error at transaction {}: execute anchor failed {:?}, output {:?}",
160-
tx_no,
161-
result,
162+
"Error at transaction {tx_no}: execute anchor failed {result:?}, output {:?}",
162163
result.output().map(|o| from_utf8(o).unwrap_or_default())
163164
);
164165
}
@@ -167,7 +168,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
167168
cumulative_gas_used = cumulative_gas_used.checked_add(gas_used).unwrap();
168169

169170
#[cfg(not(target_os = "zkvm"))]
170-
debug!(" Ok: {:?}", result);
171+
debug!(" Ok: {result:?}");
171172

172173
// create the receipt from the EVM result
173174
let receipt = Receipt::new(
@@ -183,8 +184,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
183184
if account.is_touched() {
184185
// log account
185186
debug!(
186-
" State {:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={})",
187-
address,
187+
" State {address:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={})",
188188
account.is_selfdestructed(),
189189
account.is_loaded_as_not_existing(),
190190
account.is_created()
@@ -198,7 +198,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
198198
// log state changes
199199
for (addr, slot) in &account.storage {
200200
if slot.is_changed() {
201-
debug!(" Storage address: {:?}", addr);
201+
debug!(" Storage address: {addr:?}");
202202
debug!(" Before: {:?}", slot.original_value());
203203
debug!(" After: {:?}", slot.present_value());
204204
}

0 commit comments

Comments
 (0)