Skip to content

Commit

Permalink
feat(executor): Export receipts (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby authored Jan 28, 2025
1 parent 882a71e commit 976ad0c
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ workspace = true
[dependencies]
# Workspace
kona-derive.workspace = true
kona-executor.workspace = true

# Maili
maili-rpc.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions crates/driver/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::{DriverError, DriverPipeline, DriverResult, Executor, PipelineCursor, TipCursor};
use alloc::{sync::Arc, vec::Vec};
use alloy_consensus::{BlockBody, Sealable};
use alloy_consensus::BlockBody;
use alloy_primitives::B256;
use alloy_rlp::Decodable;
use core::fmt::Debug;
Expand Down Expand Up @@ -119,7 +119,7 @@ where
};

self.executor.update_safe_head(tip_cursor.l2_safe_head_header.clone());
let header = match self.executor.execute_payload(attributes.clone()).await {
let execution_result = match self.executor.execute_payload(attributes.clone()).await {
Ok(header) => header,
Err(e) => {
error!(target: "client", "Failed to execute L2 block: {}", e);
Expand Down Expand Up @@ -162,7 +162,7 @@ where

// Construct the block.
let block = OpBlock {
header: header.clone(),
header: execution_result.block_header.inner().clone(),
body: BlockBody {
transactions: attributes
.transactions
Expand All @@ -183,7 +183,7 @@ where
)?;
let tip_cursor = TipCursor::new(
l2_info,
header.clone().seal_slow(),
execution_result.block_header,
self.executor.compute_output_root().map_err(DriverError::Executor)?,
);

Expand Down
3 changes: 2 additions & 1 deletion crates/driver/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use core::{
error::Error,
fmt::{Debug, Display},
};
use kona_executor::ExecutionArtifacts;

use alloc::string::ToString;
use alloy_consensus::{Header, Sealed};
Expand All @@ -30,7 +31,7 @@ pub trait Executor {
async fn execute_payload(
&mut self,
attributes: OpPayloadAttributes,
) -> Result<Header, Self::Error>;
) -> Result<ExecutionArtifacts, Self::Error>;

/// Computes the output root.
/// Expected to be called after the payload has been executed.
Expand Down
8 changes: 6 additions & 2 deletions crates/executor/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Protocol constants for the executor.
use alloy_primitives::{address, Address};
use alloy_primitives::{address, b256, Address, B256};

/// The address of the fee recipient.
pub(crate) const FEE_RECIPIENT: Address = address!("4200000000000000000000000000000000000011");
Expand All @@ -9,7 +9,11 @@ pub(crate) const FEE_RECIPIENT: Address = address!("4200000000000000000000000000
pub(crate) const L2_TO_L1_BRIDGE: Address = address!("4200000000000000000000000000000000000016");

/// The current version of the output root format.
pub(crate) const OUTPUT_ROOT_VERSION: u8 = 0;
pub(crate) const OUTPUT_ROOT_VERSION: u8 = 0x00;

/// The version byte for the Holocene extra data.
pub(crate) const HOLOCENE_EXTRA_DATA_VERSION: u8 = 0x00;

/// Empty SHA-256 hash.
pub(crate) const SHA256_EMPTY: B256 =
b256!("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
29 changes: 20 additions & 9 deletions crates/executor/src/executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A stateless block executor for the OP Stack.
use crate::{
constants::{L2_TO_L1_BRIDGE, OUTPUT_ROOT_VERSION},
constants::{L2_TO_L1_BRIDGE, OUTPUT_ROOT_VERSION, SHA256_EMPTY},
db::TrieDB,
errors::TrieDBError,
syscalls::{
Expand All @@ -12,9 +12,11 @@ use crate::{
ExecutorError, ExecutorResult, TrieDBProvider,
};
use alloc::vec::Vec;
use alloy_consensus::{Header, Sealable, Transaction, EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH};
use alloy_consensus::{
Header, Sealable, Sealed, Transaction, EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH,
};
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{b256, keccak256, logs_bloom, Bytes, Log, B256, U256};
use alloy_primitives::{keccak256, logs_bloom, Bytes, Log, B256, U256};
use kona_mpt::{ordered_trie_with_encoder, TrieHinter};
use maili_genesis::RollupConfig;
use op_alloy_consensus::{OpReceiptEnvelope, OpTxEnvelope};
Expand All @@ -33,9 +35,15 @@ mod env;
mod util;
use util::encode_holocene_eip_1559_params;

/// Empty SHA-256 hash.
const SHA256_EMPTY: B256 =
b256!("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
/// The [ExecutionArtifacts] holds the produced block header and receipts from the execution of a
/// block.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExecutionArtifacts {
/// The block header.
pub block_header: Sealed<Header>,
/// The receipts generated during execution.
pub receipts: Vec<OpReceiptEnvelope>,
}

/// The block executor for the L2 client program. Operates off of a [TrieDB] backed [State],
/// allowing for stateless block execution of OP Stack blocks.
Expand Down Expand Up @@ -96,7 +104,10 @@ where
/// 4. Merge all state transitions into the cache state.
/// 5. Compute the [state root, transactions root, receipts root, logs bloom] for the processed
/// block.
pub fn execute_payload(&mut self, payload: OpPayloadAttributes) -> ExecutorResult<&Header> {
pub fn execute_payload(
&mut self,
payload: OpPayloadAttributes,
) -> ExecutorResult<ExecutionArtifacts> {
// Prepare the `revm` environment.
let base_fee_params = Self::active_base_fee_params(
self.config,
Expand Down Expand Up @@ -417,8 +428,8 @@ where
);

// Update the parent block hash in the state database.
state.database.set_parent_block_header(header);
Ok(state.database.parent_block_header())
state.database.set_parent_block_header(header.clone());
Ok(ExecutionArtifacts { block_header: header, receipts })
}

/// Computes the current output root of the executor, based on the parent header and the
Expand Down
5 changes: 4 additions & 1 deletion crates/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ mod errors;
pub use errors::{ExecutorError, ExecutorResult, TrieDBError, TrieDBResult};

mod executor;
pub use executor::{KonaHandleRegister, StatelessL2BlockExecutor, StatelessL2BlockExecutorBuilder};
pub use executor::{
ExecutionArtifacts, KonaHandleRegister, StatelessL2BlockExecutor,
StatelessL2BlockExecutorBuilder,
};

mod db;
pub use db::{NoopTrieDBProvider, TrieAccount, TrieDB, TrieDBProvider};
Expand Down
9 changes: 5 additions & 4 deletions crates/executor/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ impl ExecutorTestFixtureCreator {
let mut executor = StatelessL2BlockExecutor::builder(rollup_config, self, NoopTrieHinter)
.with_parent_header(parent_header)
.build();
let produced_header =
let exec_artifacts =
executor.execute_payload(payload_attrs).expect("Failed to execute block").clone();

assert_eq!(
produced_header, executing_header.inner,
exec_artifacts.block_header.inner(),
&executing_header.inner,
"Produced header does not match the expected header"
);
fs::write(fixture_path.as_path(), serde_json::to_vec(&fixture).unwrap()).await.unwrap();
Expand Down Expand Up @@ -338,10 +339,10 @@ pub(crate) async fn run_test_fixture(fixture_path: PathBuf) {
.with_parent_header(fixture.parent_header.seal_slow())
.build();

let produced_header = executor.execute_payload(fixture.executing_payload).unwrap();
let exec_artifacts = executor.execute_payload(fixture.executing_payload).unwrap();

assert_eq!(
produced_header.hash_slow(),
exec_artifacts.block_header.hash(),
fixture.expected_block_hash,
"Produced header does not match the expected header"
);
Expand Down
17 changes: 8 additions & 9 deletions crates/proof-sdk/proof/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use alloy_consensus::{Header, Sealed};
use alloy_primitives::B256;
use async_trait::async_trait;
use kona_driver::Executor;
use kona_executor::{KonaHandleRegister, StatelessL2BlockExecutor, TrieDBProvider};
use kona_executor::{
ExecutionArtifacts, KonaHandleRegister, StatelessL2BlockExecutor, TrieDBProvider,
};
use kona_mpt::TrieHinter;
use maili_genesis::RollupConfig;
use op_alloy_rpc_types_engine::OpPayloadAttributes;
Expand Down Expand Up @@ -82,14 +84,11 @@ where
async fn execute_payload(
&mut self,
attributes: OpPayloadAttributes,
) -> Result<Header, Self::Error> {
self.inner
.as_mut()
.map_or_else(
|| Err(kona_executor::ExecutorError::MissingExecutor),
|e| e.execute_payload(attributes),
)
.cloned()
) -> Result<ExecutionArtifacts, Self::Error> {
self.inner.as_mut().map_or_else(
|| Err(kona_executor::ExecutorError::MissingExecutor),
|e| e.execute_payload(attributes),
)
}

/// Computes the output root.
Expand Down

0 comments on commit 976ad0c

Please sign in to comment.