-
Notifications
You must be signed in to change notification settings - Fork 39
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
WEB3-315: feat: Add EVM Event support to Steel #409
Open
Wollac
wants to merge
17
commits into
main
Choose a base branch
from
feat/sufficient-event-query
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bc7997a
add event support
Wollac 5bfd6d9
improve documentation
Wollac f1a9e7e
Merge remote-tracking branch 'origin/main' into feat/sufficient-event…
Wollac a098422
fix serialization
Wollac 4ba0ddc
add USDT event example
Wollac 02b344e
add workaround of Ethereum only receipts
Wollac 87f5ded
cleanups
Wollac cc965be
hide event support behind unstable feature
Wollac 9fe8326
fix
Wollac 682a211
update license header
Wollac 3bda990
fix warnings
Wollac 369c8b3
fix warning
Wollac 38985d1
add README
Wollac 2c1e548
add CHANGELOG
Wollac fb5c014
Merge branch 'main' into feat/sufficient-event-query
Wollac 0226b31
minor fixes
Wollac 03779d2
Merge branch 'main' into feat/sufficient-event-query
Wollac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,10 +13,11 @@ | |||||
// limitations under the License. | ||||||
|
||||||
use crate::{ | ||||||
config::ChainSpec, state::StateDb, BlockHeaderCommit, Commitment, CommitmentVersion, | ||||||
EvmBlockHeader, EvmEnv, GuestEvmEnv, MerkleTrie, | ||||||
config::ChainSpec, serde::Eip2718Wrapper, state::StateDb, BlockHeaderCommit, Commitment, | ||||||
CommitmentVersion, EvmBlockHeader, EvmEnv, GuestEvmEnv, MerkleTrie, | ||||||
}; | ||||||
use ::serde::{Deserialize, Serialize}; | ||||||
use alloy_consensus::ReceiptEnvelope; | ||||||
use alloy_primitives::{map::HashMap, Bytes, Sealed, B256}; | ||||||
|
||||||
/// Input committing to the corresponding execution block hash. | ||||||
|
@@ -27,6 +28,7 @@ pub struct BlockInput<H> { | |||||
storage_tries: Vec<MerkleTrie>, | ||||||
contracts: Vec<Bytes>, | ||||||
ancestors: Vec<H>, | ||||||
receipts: Option<Vec<Eip2718Wrapper<ReceiptEnvelope>>>, | ||||||
} | ||||||
|
||||||
/// Implement [BlockHeaderCommit] for the unit type. | ||||||
|
@@ -72,11 +74,38 @@ impl<H: EvmBlockHeader> BlockInput<H> { | |||||
previous_header = ancestor; | ||||||
} | ||||||
|
||||||
#[cfg(not(feature = "unstable-event"))] | ||||||
// there must not be any receipts, if events are not supported | ||||||
let logs = { | ||||||
assert!(self.receipts.is_none(), "Receipts not supported"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
None | ||||||
}; | ||||||
#[cfg(feature = "unstable-event")] | ||||||
// verify the root hash of the included receipts and extract their logs | ||||||
let logs = self.receipts.map(|receipts| { | ||||||
let root = alloy_trie::root::ordered_trie_root_with_encoder(&receipts, |r, out| { | ||||||
alloy_eips::eip2718::Encodable2718::encode_2718(r, out) | ||||||
}); | ||||||
assert_eq!(header.receipts_root(), &root, "Receipts root mismatch"); | ||||||
|
||||||
receipts | ||||||
.into_iter() | ||||||
.flat_map(|wrapper| match wrapper.into_inner() { | ||||||
ReceiptEnvelope::Legacy(t) => t.receipt.logs, | ||||||
ReceiptEnvelope::Eip2930(t) => t.receipt.logs, | ||||||
ReceiptEnvelope::Eip1559(t) => t.receipt.logs, | ||||||
ReceiptEnvelope::Eip4844(t) => t.receipt.logs, | ||||||
ReceiptEnvelope::Eip7702(t) => t.receipt.logs, | ||||||
}) | ||||||
.collect() | ||||||
}); | ||||||
|
||||||
let db = StateDb::new( | ||||||
self.state_trie, | ||||||
self.storage_tries, | ||||||
self.contracts, | ||||||
block_hashes, | ||||||
logs, | ||||||
); | ||||||
let commit = Commitment::new( | ||||||
CommitmentVersion::Block as u16, | ||||||
|
@@ -91,19 +120,19 @@ impl<H: EvmBlockHeader> BlockInput<H> { | |||||
|
||||||
#[cfg(feature = "host")] | ||||||
pub mod host { | ||||||
use std::fmt::Display; | ||||||
|
||||||
use super::BlockInput; | ||||||
use crate::{ | ||||||
host::db::{AlloyDb, ProofDb, ProviderDb}, | ||||||
serde::Eip2718Wrapper, | ||||||
EvmBlockHeader, | ||||||
}; | ||||||
use alloy::{network::Network, providers::Provider, transports::Transport}; | ||||||
use alloy_primitives::Sealed; | ||||||
use anyhow::{anyhow, ensure}; | ||||||
use log::debug; | ||||||
use std::fmt::Display; | ||||||
|
||||||
impl<H: EvmBlockHeader> BlockInput<H> { | ||||||
impl<H> BlockInput<H> { | ||||||
/// Creates the `BlockInput` containing the necessary EVM state that can be verified against | ||||||
/// the block hash. | ||||||
pub(crate) async fn from_proof_db<T, N, P>( | ||||||
|
@@ -137,6 +166,11 @@ pub mod host { | |||||
ancestors.push(header); | ||||||
} | ||||||
|
||||||
let receipts = db.receipt_proof().await?; | ||||||
// wrap the receipts so that they can be serialized | ||||||
let receipts = | ||||||
receipts.map(|receipts| receipts.into_iter().map(Eip2718Wrapper::new).collect()); | ||||||
|
||||||
debug!("state size: {}", state_trie.size()); | ||||||
debug!("storage tries: {}", storage_tries.len()); | ||||||
debug!( | ||||||
|
@@ -145,13 +179,15 @@ pub mod host { | |||||
); | ||||||
debug!("contracts: {}", contracts.len()); | ||||||
debug!("ancestor blocks: {}", ancestors.len()); | ||||||
debug!("receipts: {:?}", receipts.as_ref().map(Vec::len)); | ||||||
|
||||||
let input = BlockInput { | ||||||
header: header.into_inner(), | ||||||
state_trie, | ||||||
storage_tries, | ||||||
contracts, | ||||||
ancestors, | ||||||
receipts, | ||||||
}; | ||||||
|
||||||
Ok(input) | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ReceiptEnvelope
cannot be serialized using bincode or similar, so it must be RLP encoded. However, since the hash calculation also relies on the RLP encoding, this may actually be a performance improvement.