-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add support for 7594 blobs to anvil #12238
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
Closed
stevencartavia
wants to merge
6
commits into
foundry-rs:master
from
stevencartavia:support-for-7594-anvil
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5dc5488
feat: add support for 7594 blobs to anvil
stevencartavia 11843ad
Merge branch 'master' into support-for-7594-anvil
grandizzy 0ae15a2
comments
stevencartavia 5fe60e7
Merge branch 'master' into support-for-7594-anvil
stevencartavia 1145bf5
Merge branch 'support-for-7594-anvil' of https://github.com/stevencar…
stevencartavia 4fab009
updates
stevencartavia 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,7 +8,10 @@ use alloy_consensus::{ | |
| }, | ||
| }; | ||
|
|
||
| use alloy_eips::eip2718::{Decodable2718, Eip2718Error, Encodable2718}; | ||
| use alloy_eips::{ | ||
| eip2718::{Decodable2718, Eip2718Error, Encodable2718}, | ||
| eip7594::BlobTransactionSidecarVariant, | ||
| }; | ||
| use alloy_network::{AnyReceiptEnvelope, AnyRpcTransaction, AnyTransactionReceipt, AnyTxEnvelope}; | ||
| use alloy_primitives::{Address, B256, Bloom, Bytes, Signature, TxHash, TxKind, U64, U256}; | ||
| use alloy_rlp::{Decodable, Encodable, Header}; | ||
|
|
@@ -166,7 +169,10 @@ pub fn transaction_request_to_typed( | |
|
|
||
| if let Some(sidecar) = sidecar { | ||
| Some(TypedTransactionRequest::EIP4844(TxEip4844Variant::TxEip4844WithSidecar( | ||
| TxEip4844WithSidecar::from_tx_and_sidecar(tx, sidecar), | ||
| TxEip4844WithSidecar::from_tx_and_sidecar( | ||
| tx, | ||
| BlobTransactionSidecarVariant::Eip4844(sidecar), | ||
| ), | ||
| ))) | ||
| } else { | ||
| Some(TypedTransactionRequest::EIP4844(TxEip4844Variant::TxEip4844(tx))) | ||
|
|
@@ -188,7 +194,7 @@ pub enum TypedTransactionRequest { | |
| EIP2930(TxEip2930), | ||
| EIP1559(TxEip1559), | ||
| EIP7702(TxEip7702), | ||
| EIP4844(TxEip4844Variant), | ||
| EIP4844(TxEip4844Variant<BlobTransactionSidecarVariant>), | ||
| Deposit(TxDeposit), | ||
| } | ||
|
|
||
|
|
@@ -328,13 +334,42 @@ pub fn to_alloy_transaction_with_hash_and_sender( | |
| } | ||
| TypedTransaction::EIP4844(t) => { | ||
| let (tx, sig, _) = t.into_parts(); | ||
| // Convert BlobTransactionSidecarVariant to BlobTransactionSidecar for TxEnvelope | ||
| let converted_tx = match tx { | ||
| TxEip4844Variant::TxEip4844(tx) => TxEip4844Variant::TxEip4844(tx), | ||
| TxEip4844Variant::TxEip4844WithSidecar(tx_with_sidecar) => { | ||
| let sidecar = match tx_with_sidecar.sidecar { | ||
| BlobTransactionSidecarVariant::Eip4844(sidecar) => sidecar, | ||
| BlobTransactionSidecarVariant::Eip7594(_) => { | ||
| // For EIP-7594, extract the base transaction without sidecar | ||
| return RpcTransaction { | ||
| block_hash: None, | ||
| block_number: None, | ||
| transaction_index: None, | ||
| effective_gas_price: None, | ||
| inner: Recovered::new_unchecked( | ||
| TxEnvelope::Eip4844(Signed::new_unchecked( | ||
| TxEip4844Variant::TxEip4844(tx_with_sidecar.tx), | ||
| sig, | ||
| hash, | ||
| )), | ||
| from, | ||
| ), | ||
| }; | ||
| } | ||
| }; | ||
| TxEip4844Variant::TxEip4844WithSidecar( | ||
| TxEip4844WithSidecar::from_tx_and_sidecar(tx_with_sidecar.tx, sidecar), | ||
| ) | ||
| } | ||
| }; | ||
| RpcTransaction { | ||
| block_hash: None, | ||
| block_number: None, | ||
| transaction_index: None, | ||
| effective_gas_price: None, | ||
| inner: Recovered::new_unchecked( | ||
| TxEnvelope::Eip4844(Signed::new_unchecked(tx, sig, hash)), | ||
| TxEnvelope::Eip4844(Signed::new_unchecked(converted_tx, sig, hash)), | ||
| from, | ||
| ), | ||
| } | ||
|
|
@@ -609,7 +644,7 @@ pub enum TypedTransaction { | |
| /// EIP-1559 transaction | ||
| EIP1559(Signed<TxEip1559>), | ||
| /// EIP-4844 transaction | ||
| EIP4844(Signed<TxEip4844Variant>), | ||
| EIP4844(Signed<TxEip4844Variant<BlobTransactionSidecarVariant>>), | ||
| /// EIP-7702 transaction | ||
| EIP7702(Signed<TxEip7702>), | ||
| /// op-stack deposit transaction | ||
|
|
@@ -627,7 +662,23 @@ impl TryFrom<AnyRpcTransaction> for TypedTransaction { | |
| TxEnvelope::Legacy(tx) => Ok(Self::Legacy(tx)), | ||
| TxEnvelope::Eip2930(tx) => Ok(Self::EIP2930(tx)), | ||
| TxEnvelope::Eip1559(tx) => Ok(Self::EIP1559(tx)), | ||
| TxEnvelope::Eip4844(tx) => Ok(Self::EIP4844(tx)), | ||
| TxEnvelope::Eip4844(tx) => { | ||
| // Convert from TxEip4844Variant to | ||
| // TxEip4844Variant<BlobTransactionSidecarVariant> | ||
| let (variant, sig, hash) = tx.into_parts(); | ||
| let blob_variant = match variant { | ||
| TxEip4844Variant::TxEip4844(tx) => TxEip4844Variant::TxEip4844(tx), | ||
| TxEip4844Variant::TxEip4844WithSidecar(tx_with_sidecar) => { | ||
| TxEip4844Variant::TxEip4844WithSidecar( | ||
| TxEip4844WithSidecar::from_tx_and_sidecar( | ||
| tx_with_sidecar.tx, | ||
| BlobTransactionSidecarVariant::Eip4844(tx_with_sidecar.sidecar), | ||
| ), | ||
| ) | ||
| } | ||
| }; | ||
| Ok(Self::EIP4844(Signed::new_unchecked(blob_variant, sig, hash))) | ||
| } | ||
| TxEnvelope::Eip7702(tx) => Ok(Self::EIP7702(tx)), | ||
| }, | ||
| AnyTxEnvelope::Unknown(mut tx) => { | ||
|
|
@@ -738,7 +789,7 @@ impl TypedTransaction { | |
| } | ||
| } | ||
|
|
||
| pub fn sidecar(&self) -> Option<&TxEip4844WithSidecar> { | ||
| pub fn sidecar(&self) -> Option<&TxEip4844WithSidecar<BlobTransactionSidecarVariant>> { | ||
| match self { | ||
| Self::EIP4844(signed_variant) => match signed_variant.tx() { | ||
| TxEip4844Variant::TxEip4844WithSidecar(with_sidecar) => Some(with_sidecar), | ||
|
|
@@ -1013,7 +1064,7 @@ impl Encodable2718 for TypedTransaction { | |
| Self::Legacy(tx) => TxEnvelope::from(tx.clone()).encode_2718_len(), | ||
| Self::EIP2930(tx) => TxEnvelope::from(tx.clone()).encode_2718_len(), | ||
| Self::EIP1559(tx) => TxEnvelope::from(tx.clone()).encode_2718_len(), | ||
|
Comment on lines
1038
to
1040
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. I think even those from calls here are redundant, if you want, please submit this separately |
||
| Self::EIP4844(tx) => TxEnvelope::from(tx.clone()).encode_2718_len(), | ||
| Self::EIP4844(tx) => tx.encode_2718_len(), | ||
| Self::EIP7702(tx) => TxEnvelope::from(tx.clone()).encode_2718_len(), | ||
| Self::Deposit(tx) => 1 + tx.length(), | ||
| } | ||
|
|
@@ -1024,7 +1075,7 @@ impl Encodable2718 for TypedTransaction { | |
| Self::Legacy(tx) => TxEnvelope::from(tx.clone()).encode_2718(out), | ||
| Self::EIP2930(tx) => TxEnvelope::from(tx.clone()).encode_2718(out), | ||
| Self::EIP1559(tx) => TxEnvelope::from(tx.clone()).encode_2718(out), | ||
| Self::EIP4844(tx) => TxEnvelope::from(tx.clone()).encode_2718(out), | ||
| Self::EIP4844(tx) => tx.encode_2718(out), | ||
| Self::EIP7702(tx) => TxEnvelope::from(tx.clone()).encode_2718(out), | ||
| Self::Deposit(tx) => { | ||
| tx.encode_2718(out); | ||
|
|
@@ -1041,7 +1092,22 @@ impl Decodable2718 for TypedTransaction { | |
| match TxEnvelope::typed_decode(ty, buf)? { | ||
| TxEnvelope::Eip2930(tx) => Ok(Self::EIP2930(tx)), | ||
| TxEnvelope::Eip1559(tx) => Ok(Self::EIP1559(tx)), | ||
| TxEnvelope::Eip4844(tx) => Ok(Self::EIP4844(tx)), | ||
| TxEnvelope::Eip4844(tx) => { | ||
| // Convert from TxEip4844Variant to TxEip4844Variant<BlobTransactionSidecarVariant> | ||
| let (variant, sig, hash) = tx.into_parts(); | ||
| let blob_variant = match variant { | ||
| TxEip4844Variant::TxEip4844(tx) => TxEip4844Variant::TxEip4844(tx), | ||
| TxEip4844Variant::TxEip4844WithSidecar(tx_with_sidecar) => { | ||
| TxEip4844Variant::TxEip4844WithSidecar( | ||
| TxEip4844WithSidecar::from_tx_and_sidecar( | ||
| tx_with_sidecar.tx, | ||
| BlobTransactionSidecarVariant::Eip4844(tx_with_sidecar.sidecar), | ||
| ), | ||
| ) | ||
| } | ||
| }; | ||
| Ok(Self::EIP4844(Signed::new_unchecked(blob_variant, sig, hash))) | ||
| } | ||
| TxEnvelope::Eip7702(tx) => Ok(Self::EIP7702(tx)), | ||
| _ => Err(Eip2718Error::RlpError(alloy_rlp::Error::Custom("unexpected tx type"))), | ||
| } | ||
|
|
@@ -1061,7 +1127,22 @@ impl From<TxEnvelope> for TypedTransaction { | |
| TxEnvelope::Legacy(tx) => Self::Legacy(tx), | ||
| TxEnvelope::Eip2930(tx) => Self::EIP2930(tx), | ||
| TxEnvelope::Eip1559(tx) => Self::EIP1559(tx), | ||
| TxEnvelope::Eip4844(tx) => Self::EIP4844(tx), | ||
| TxEnvelope::Eip4844(tx) => { | ||
| // Convert from TxEip4844Variant to TxEip4844Variant<BlobTransactionSidecarVariant> | ||
| let (variant, sig, hash) = tx.into_parts(); | ||
| let blob_variant = match variant { | ||
| TxEip4844Variant::TxEip4844(tx) => TxEip4844Variant::TxEip4844(tx), | ||
| TxEip4844Variant::TxEip4844WithSidecar(tx_with_sidecar) => { | ||
| TxEip4844Variant::TxEip4844WithSidecar( | ||
| TxEip4844WithSidecar::from_tx_and_sidecar( | ||
| tx_with_sidecar.tx, | ||
| BlobTransactionSidecarVariant::Eip4844(tx_with_sidecar.sidecar), | ||
| ), | ||
| ) | ||
| } | ||
| }; | ||
| Self::EIP4844(Signed::new_unchecked(blob_variant, sig, hash)) | ||
| } | ||
| TxEnvelope::Eip7702(tx) => Self::EIP7702(tx), | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ use alloy_eips::{ | |
| Encodable2718, | ||
| eip1559::BaseFeeParams, | ||
| eip4844::{BlobTransactionSidecar, kzg_to_versioned_hash}, | ||
| eip7594::BlobTransactionSidecarVariant, | ||
| eip7840::BlobParams, | ||
| eip7910::SystemContract, | ||
| }; | ||
|
|
@@ -3303,7 +3304,11 @@ impl Backend { | |
| && let Ok(typed_tx) = TypedTransaction::try_from(tx) | ||
| && let Some(sidecar) = typed_tx.sidecar() | ||
| { | ||
| return Ok(Some(sidecar.sidecar.blobs.clone())); | ||
| let blobs = match &sidecar.sidecar { | ||
| BlobTransactionSidecarVariant::Eip4844(sidecar) => &sidecar.blobs, | ||
| BlobTransactionSidecarVariant::Eip7594(sidecar) => &sidecar.blobs, | ||
| }; | ||
| return Ok(Some(blobs.clone())); | ||
| } | ||
|
||
|
|
||
| Ok(None) | ||
|
|
@@ -3319,8 +3324,13 @@ impl Backend { | |
| .transactions | ||
| .iter() | ||
| .filter_map(|tx| tx.as_ref().sidecar()) | ||
| .flat_map(|sidecar| { | ||
| sidecar.sidecar.blobs.iter().zip(sidecar.sidecar.commitments.iter()) | ||
| .flat_map(|sidecar| match &sidecar.sidecar { | ||
| BlobTransactionSidecarVariant::Eip4844(sc) => { | ||
| sc.blobs.iter().zip(sc.commitments.iter()) | ||
| } | ||
| BlobTransactionSidecarVariant::Eip7594(sc) => { | ||
| sc.blobs.iter().zip(sc.commitments.iter()) | ||
| } | ||
| }) | ||
| .filter(|(_, commitment)| { | ||
| // Filter blobs by versioned_hashes if provided | ||
|
|
@@ -3344,9 +3354,18 @@ impl Backend { | |
| typed_tx_result.ok()?.sidecar().map(|sidecar| sidecar.sidecar().clone()) | ||
| }) | ||
| .fold(BlobTransactionSidecar::default(), |mut acc, sidecar| { | ||
| acc.blobs.extend(sidecar.blobs); | ||
| acc.commitments.extend(sidecar.commitments); | ||
| acc.proofs.extend(sidecar.proofs); | ||
| match sidecar { | ||
| BlobTransactionSidecarVariant::Eip4844(sc) => { | ||
| acc.blobs.extend(sc.blobs); | ||
| acc.commitments.extend(sc.commitments); | ||
| acc.proofs.extend(sc.proofs); | ||
| } | ||
| BlobTransactionSidecarVariant::Eip7594(sc) => { | ||
| acc.blobs.extend(sc.blobs); | ||
| acc.commitments.extend(sc.commitments); | ||
| acc.proofs.extend(sc.cell_proofs); | ||
| } | ||
| } | ||
| acc | ||
| }); | ||
| Ok(Some(sidecar)) | ||
|
|
@@ -3363,11 +3382,22 @@ impl Backend { | |
| if let Some(sidecar) = typed_tx.sidecar() { | ||
| for versioned_hash in sidecar.sidecar.versioned_hashes() { | ||
| if versioned_hash == hash | ||
| && let Some(index) = | ||
| sidecar.sidecar.commitments.iter().position(|commitment| { | ||
| kzg_to_versioned_hash(commitment.as_slice()) == *hash | ||
| }) | ||
| && let Some(blob) = sidecar.sidecar.blobs.get(index) | ||
| && let Some(index) = match &sidecar.sidecar { | ||
| BlobTransactionSidecarVariant::Eip4844(sc) => { | ||
| sc.commitments.iter().position(|commitment| { | ||
| kzg_to_versioned_hash(commitment.as_slice()) == *hash | ||
| }) | ||
| } | ||
| BlobTransactionSidecarVariant::Eip7594(sc) => { | ||
| sc.commitments.iter().position(|commitment| { | ||
| kzg_to_versioned_hash(commitment.as_slice()) == *hash | ||
| }) | ||
| } | ||
| } | ||
| && let Some(blob) = match &sidecar.sidecar { | ||
| BlobTransactionSidecarVariant::Eip4844(sc) => sc.blobs.get(index), | ||
| BlobTransactionSidecarVariant::Eip7594(sc) => sc.blobs.get(index), | ||
| } | ||
| { | ||
| return Ok(Some(*blob)); | ||
| } | ||
|
|
||
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.
instead of converting, we should also update the return type here
https://github.com/foundry-rs/foundry/blob/master/crates/anvil/core/src/eth/transaction/mod.rs#L294-L294
which is