Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase upstream with Reth & refactor #29

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7e9e874
Enable RPC retries (#42)
intoverflow Oct 19, 2023
90b1468
Introduce op-info tool (#48)
intoverflow Oct 26, 2023
31c3c50
upgrade risc0 to v0.19 (#50) # Please enter the commit message for y…
Wollac Nov 1, 2023
053a1bf
chore(deps): bump risc0 to v0.19.1 (#54)
Wollac Nov 18, 2023
ec19095
cleanup transaction code (#53)
Wollac Nov 18, 2023
2ff9b22
Reintroduce data() on TxEssence (#57)
intoverflow Nov 21, 2023
4ce1cdc
chore: MPT cleanups (#56)
Wollac Nov 21, 2023
97dac55
Pre-flight and block building improvements (#55)
Wollac Nov 27, 2023
d7cd529
fix: clippy complain (#64)
dyxushuai Dec 11, 2023
43c5398
fix: use PathBuf instead of String to compatible different platforms …
dyxushuai Dec 12, 2023
ea66d72
Update CI (#60)
Wollac Dec 12, 2023
3d92ea1
Optimism L1 -> L2 derivation (#51)
intoverflow Dec 18, 2023
ba51d9a
Fix frame parsing and loading in Optimism derivation (#68)
Wollac Dec 19, 2023
cbfab6e
Fix channel bank handling in Optimism derivation (#71)
Wollac Dec 22, 2023
8750ebe
feat: Use revm Optimism execution (#44)
Wollac Jan 22, 2024
3e8b9db
Fix batch queue handling in Optimism derivation (#73)
Wollac Jan 22, 2024
6259801
Fix OP block header validation (#74)
Wollac Jan 23, 2024
2a483c2
wip
CeciliaZ030 Feb 5, 2024
7c1de44
change dependency
CeciliaZ030 Feb 12, 2024
b83cece
Squashed commit of the following:
CeciliaZ030 Feb 12, 2024
a3aae6c
wip
CeciliaZ030 Feb 13, 2024
89c5ad3
fixed merged err in lib
CeciliaZ030 Feb 13, 2024
3595dcc
seperate taiko host functions for std/no-std
CeciliaZ030 Feb 14, 2024
017116c
compiled raiko guest & host
CeciliaZ030 Feb 14, 2024
1697b2c
static TKO_MAINNET_CHAIN_SPEC & get_contracts with str
CeciliaZ030 Feb 14, 2024
9d4069b
delete guest & host, compile optimism flag
CeciliaZ030 Feb 14, 2024
4d17fd0
fixed test no-std imports & fmt & clippy
CeciliaZ030 Feb 14, 2024
41edfc8
delete primitives/taiko & fmt & fix ci OP flag
CeciliaZ030 Feb 15, 2024
596733d
chore: Refactor and fix lints
petarvujovic98 Feb 16, 2024
583cea0
fix Preflight trait
CeciliaZ030 Feb 20, 2024
8afb0d8
fix: not optional alloy-sol-types
CeciliaZ030 Feb 20, 2024
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
Prev Previous commit
Next Next commit
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
  • Loading branch information
petarvujovic98 committed Feb 16, 2024
commit 596733d6d455e920962ce4cc9b5b7f30c4827a37
56 changes: 24 additions & 32 deletions lib/src/builder/execute/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,27 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
// Compute the spec id
let spec_id = block_builder.chain_spec.spec_id(header.number);
if !SpecId::enabled(spec_id, MIN_SPEC_ID) {
bail!(
"Invalid protocol version: expected >= {:?}, got {:?}",
MIN_SPEC_ID,
spec_id,
)
bail!("Invalid protocol version: expected >= {MIN_SPEC_ID:?}, got {spec_id:?}");
}

#[cfg(not(target_os = "zkvm"))]
{
use chrono::{TimeZone, Utc};
use log::info;
let dt = Utc
.timestamp_opt(block_builder.input.timestamp.try_into().unwrap(), 0)
.timestamp_opt(
block_builder
.input
.timestamp
.try_into()
.expect("Timestamp could not fit into i64"),
0,
)
.unwrap();

info!("Block no. {}", header.number);
info!(" EVM spec ID: {:?}", spec_id);
info!(" Timestamp: {}", dt);
info!(" EVM spec ID: {spec_id:?}");
info!(" Timestamp: {dt}");
info!(" Transactions: {}", block_builder.input.transactions.len());
info!(" Withdrawals: {}", block_builder.input.withdrawals.len());
info!(" Fee Recipient: {:?}", block_builder.input.beneficiary);
Expand All @@ -92,15 +95,15 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
})
.modify_block_env(|blk_env| {
// set the EVM block environment
blk_env.number = header.number.try_into().unwrap();
blk_env.number = U256::from(header.number);
blk_env.coinbase = block_builder.input.beneficiary;
blk_env.timestamp = header.timestamp;
blk_env.difficulty = U256::ZERO;
blk_env.prevrandao = Some(header.mix_hash);
blk_env.basefee = header.base_fee_per_gas;
blk_env.gas_limit = block_builder.input.gas_limit;
})
.with_db(block_builder.db.take().unwrap())
.with_db(block_builder.db.take().expect("No database"))
.build();

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

#[cfg(not(target_os = "zkvm"))]
{
let tx_hash = tx.hash();
debug!("Tx no. {} (hash: {})", tx_no, tx_hash);
debug!("Tx no. {tx_no} (hash: {tx_hash})");
debug!(" Type: {}", tx.essence.tx_type());
debug!(" Fr: {:?}", tx_from);
debug!(" Fr: {tx_from:?}");
debug!(" To: {:?}", tx.essence.to().unwrap_or_default());
}

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

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

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

#[cfg(not(target_os = "zkvm"))]
debug!(" Ok: {:?}", result);
debug!(" Ok: {result:?}");

// create the receipt from the EVM result
let receipt = Receipt::new(
Expand Down Expand Up @@ -175,8 +178,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
if account.is_touched() {
// log account
debug!(
" State {:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={}, is_empty={})",
address,
" State {address:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={}, is_empty={})",
account.is_selfdestructed(),
account.is_loaded_as_not_existing(),
account.is_created(),
Expand All @@ -191,7 +193,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
// log state changes
for (addr, slot) in &account.storage {
if slot.is_changed() {
debug!(" Storage address: {:?}", addr);
debug!(" Storage address: {addr:?}");
debug!(" Before: {:?}", slot.original_value());
debug!(" After: {:?}", slot.present_value());
}
Expand All @@ -217,7 +219,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
{
debug!("Withdrawal no. {}", withdrawal.index);
debug!(" Recipient: {:?}", withdrawal.address);
debug!(" Value: {}", amount_wei);
debug!(" Value: {amount_wei}");
}
// Credit withdrawal amount
increase_account_balance(&mut evm.context.evm.db, withdrawal.address, amount_wei)?;
Expand All @@ -233,11 +235,7 @@ impl TxExecStrategy<EthereumTxEssence> for EthTxExecStrategy {
header.receipts_root = receipt_trie.hash();
header.logs_bloom = logs_bloom;
header.gas_used = cumulative_gas_used;
header.withdrawals_root = if spec_id < SpecId::SHANGHAI {
None
} else {
Some(withdrawals_trie.hash())
};
header.withdrawals_root = (spec_id < SpecId::SHANGHAI).then_some(withdrawals_trie.hash());

// Leak memory, save cycles
guest_mem_forget([tx_trie, receipt_trie, withdrawals_trie]);
Expand Down Expand Up @@ -311,13 +309,7 @@ where
// Read account from database
let mut account: Account = db
.basic(address)
.map_err(|db_err| {
anyhow!(
"Error increasing account balance for {}: {:?}",
address,
db_err
)
})?
.map_err(|db_err| anyhow!("Error increasing account balance for {address}: {db_err:?}"))?
.unwrap_or_default()
.into();
// Credit withdrawal amount
Expand Down
38 changes: 20 additions & 18 deletions lib/src/builder/execute/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
// Compute the spec id
let spec_id = block_builder.chain_spec.spec_id(header.number);
if !SpecId::enabled(spec_id, MIN_SPEC_ID) {
bail!(
"Invalid protocol version: expected >= {:?}, got {:?}",
MIN_SPEC_ID,
spec_id,
)
bail!("Invalid protocol version: expected >= {MIN_SPEC_ID:?}, got {spec_id:?}")
}
let chain_id = block_builder.chain_spec.chain_id();

Expand All @@ -71,12 +67,19 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
use chrono::{TimeZone, Utc};
use log::info;
let dt = Utc
.timestamp_opt(block_builder.input.timestamp.try_into().unwrap(), 0)
.timestamp_opt(
block_builder
.input
.timestamp
.try_into()
.expect("Timestamp could not fit into i64"),
0,
)
.unwrap();

info!("Block no. {}", header.number);
info!(" EVM spec ID: {:?}", spec_id);
info!(" Timestamp: {}", dt);
info!(" EVM spec ID: {spec_id:?}");
info!(" Timestamp: {dt}");
info!(" Transactions: {}", block_builder.input.transactions.len());
info!(" Fee Recipient: {:?}", block_builder.input.beneficiary);
info!(" Gas limit: {}", block_builder.input.gas_limit);
Expand All @@ -93,7 +96,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
})
.modify_block_env(|blk_env| {
// set the EVM block environment
blk_env.number = header.number.try_into().unwrap();
blk_env.number = U256::from(header.number);
blk_env.coinbase = block_builder.input.beneficiary;
blk_env.timestamp = header.timestamp;
blk_env.difficulty = U256::ZERO;
Expand All @@ -120,21 +123,21 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
// verify the transaction signature
let tx_from = tx
.recover_from()
.with_context(|| format!("Error recovering address for transaction {}", tx_no))?;
.with_context(|| format!("Error recovering address for transaction {tx_no}"))?;

#[cfg(not(target_os = "zkvm"))]
{
let tx_hash = tx.hash();
debug!("Tx no. {} (hash: {})", tx_no, tx_hash);
debug!("Tx no. {tx_no} (hash: {tx_hash})");
debug!(" Type: {}", tx.essence.tx_type());
debug!(" Fr: {:?}", tx_from);
debug!(" Fr: {tx_from:?}");
debug!(" To: {:?}", tx.essence.to().unwrap_or_default());
}

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

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

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

#[cfg(not(target_os = "zkvm"))]
debug!(" Ok: {:?}", result);
debug!(" Ok: {result:?}");

// create the receipt from the EVM result
let receipt = Receipt::new(
Expand All @@ -179,8 +182,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
if account.is_touched() {
// log account
debug!(
" State {:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={})",
address,
" State {address:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={})",
account.is_selfdestructed(),
account.is_loaded_as_not_existing(),
account.is_created()
Expand All @@ -194,7 +196,7 @@ impl TxExecStrategy<OptimismTxEssence> for OpTxExecStrategy {
// log state changes
for (addr, slot) in &account.storage {
if slot.is_changed() {
debug!(" Storage address: {:?}", addr);
debug!(" Storage address: {addr:?}");
debug!(" Before: {:?}", slot.original_value());
debug!(" After: {:?}", slot.present_value());
}
Expand Down
44 changes: 22 additions & 22 deletions lib/src/builder/execute/taiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use core::{fmt::Debug, mem::take, str::from_utf8};
use anyhow::{anyhow, bail, Context, Result};
#[cfg(not(target_os = "zkvm"))]
use log::debug;
use log::info;
use revm::{
interpreter::Host,
primitives::{Address, ResultAndState, SpecId, TxEnv},
Expand Down Expand Up @@ -58,11 +57,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
// Compute the spec id
let spec_id = block_builder.chain_spec.spec_id(header.number);
if !SpecId::enabled(spec_id, MIN_SPEC_ID) {
bail!(
"Invalid protocol version: expected >= {:?}, got {:?}",
MIN_SPEC_ID,
spec_id,
)
bail!("Invalid protocol version: expected >= {MIN_SPEC_ID:?}, got {spec_id:?}")
}
let chain_id = block_builder.chain_spec.chain_id();

Expand All @@ -71,12 +66,19 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
use chrono::{TimeZone, Utc};
use log::info;
let dt = Utc
.timestamp_opt(block_builder.input.timestamp.try_into().unwrap(), 0)
.timestamp_opt(
block_builder
.input
.timestamp
.try_into()
.expect("Timestamp could not fit into i64"),
0,
)
.unwrap();

info!("Block no. {}", header.number);
info!(" EVM spec ID: {:?}", spec_id);
info!(" Timestamp: {}", dt);
info!(" EVM spec ID: {spec_id:?}");
info!(" Timestamp: {dt}");
info!(" Transactions: {}", block_builder.input.transactions.len());
info!(" Fee Recipient: {:?}", block_builder.input.beneficiary);
info!(" Gas limit: {}", block_builder.input.gas_limit);
Expand All @@ -93,7 +95,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
})
.modify_block_env(|blk_env| {
// set the EVM block environment
blk_env.number = header.number.try_into().unwrap();
blk_env.number = U256::from(header.number);
blk_env.coinbase = block_builder.input.beneficiary;
blk_env.timestamp = header.timestamp;
blk_env.difficulty = U256::ZERO;
Expand All @@ -113,6 +115,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
// process all the transactions
let mut tx_trie = MptNode::default();
let mut receipt_trie = MptNode::default();
#[allow(unused_variables)]
let mut actual_tx_no = 0usize;

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

#[cfg(not(target_os = "zkvm"))]
{
let tx_hash = tx.hash();
debug!("Tx no. {} (hash: {})", tx_no, tx_hash);
debug!("Tx no. {tx_no} (hash: {tx_hash})");
debug!(" Type: {}", tx.essence.tx_type());
debug!(" Fr: {:?}", tx_from);
debug!(" Fr: {tx_from:?}");
debug!(" To: {:?}", tx.essence.to().unwrap_or_default());
}

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

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

if is_anchor && !result.is_success() {
bail!(
"Error at transaction {}: execute anchor failed {:?}, output {:?}",
tx_no,
result,
"Error at transaction {tx_no}: execute anchor failed {result:?}, output {:?}",
result.output().map(|o| from_utf8(o).unwrap_or_default())
);
}
Expand All @@ -167,7 +168,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
cumulative_gas_used = cumulative_gas_used.checked_add(gas_used).unwrap();

#[cfg(not(target_os = "zkvm"))]
debug!(" Ok: {:?}", result);
debug!(" Ok: {result:?}");

// create the receipt from the EVM result
let receipt = Receipt::new(
Expand All @@ -183,8 +184,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
if account.is_touched() {
// log account
debug!(
" State {:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={})",
address,
" State {address:?} (is_selfdestructed={}, is_loaded_as_not_existing={}, is_created={})",
account.is_selfdestructed(),
account.is_loaded_as_not_existing(),
account.is_created()
Expand All @@ -198,7 +198,7 @@ impl TxExecStrategy<EthereumTxEssence> for TkoTxExecStrategy {
// log state changes
for (addr, slot) in &account.storage {
if slot.is_changed() {
debug!(" Storage address: {:?}", addr);
debug!(" Storage address: {addr:?}");
debug!(" Before: {:?}", slot.original_value());
debug!(" After: {:?}", slot.present_value());
}
Expand Down
Loading
Loading