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

chore: bump alloy-eip7702 #11986

Merged
merged 10 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
133 changes: 67 additions & 66 deletions Cargo.lock

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ reth-trie-db = { path = "crates/trie/db" }
reth-trie-parallel = { path = "crates/trie/parallel" }

# revm
revm = { version = "16.0.0", features = ["std"], default-features = false }
revm-inspectors = "0.9.0"
revm-primitives = { version = "12.0.0", features = [
revm = { version = "17.0.0", features = ["std"], default-features = false }
revm-inspectors = "0.10.0"
revm-primitives = { version = "13.0.0", features = [
"std",
], default-features = false }

Expand All @@ -425,39 +425,39 @@ alloy-rlp = "0.3.4"
alloy-sol-types = "0.8.0"
alloy-trie = { version = "0.7", default-features = false }

alloy-consensus = { version = "0.5.2", default-features = false }
alloy-eips = { version = "0.5.2", default-features = false }
alloy-genesis = { version = "0.5.2", default-features = false }
alloy-json-rpc = { version = "0.5.2", default-features = false }
alloy-network = { version = "0.5.2", default-features = false }
alloy-network-primitives = { version = "0.5.2", default-features = false }
alloy-node-bindings = { version = "0.5.2", default-features = false }
alloy-provider = { version = "0.5.2", features = [
alloy-consensus = { version = "0.5.3", default-features = false }
alloy-eips = { version = "0.5.3", default-features = false }
alloy-genesis = { version = "0.5.3", default-features = false }
alloy-json-rpc = { version = "0.5.3", default-features = false }
alloy-network = { version = "0.5.3", default-features = false }
alloy-network-primitives = { version = "0.5.3", default-features = false }
alloy-node-bindings = { version = "0.5.3", default-features = false }
alloy-provider = { version = "0.5.3", features = [
"reqwest",
], default-features = false }
alloy-pubsub = { version = "0.5.2", default-features = false }
alloy-rpc-client = { version = "0.5.2", default-features = false }
alloy-rpc-types = { version = "0.5.2", features = [
alloy-pubsub = { version = "0.5.3", default-features = false }
alloy-rpc-client = { version = "0.5.3", default-features = false }
alloy-rpc-types = { version = "0.5.3", features = [
"eth",
], default-features = false }
alloy-rpc-types-admin = { version = "0.5.2", default-features = false }
alloy-rpc-types-anvil = { version = "0.5.2", default-features = false }
alloy-rpc-types-beacon = { version = "0.5.2", default-features = false }
alloy-rpc-types-debug = { version = "0.5.2", default-features = false }
alloy-rpc-types-engine = { version = "0.5.2", default-features = false }
alloy-rpc-types-eth = { version = "0.5.2", default-features = false }
alloy-rpc-types-mev = { version = "0.5.2", default-features = false }
alloy-rpc-types-trace = { version = "0.5.2", default-features = false }
alloy-rpc-types-txpool = { version = "0.5.2", default-features = false }
alloy-serde = { version = "0.5.2", default-features = false }
alloy-signer = { version = "0.5.2", default-features = false }
alloy-signer-local = { version = "0.5.2", default-features = false }
alloy-transport = { version = "0.5.2" }
alloy-transport-http = { version = "0.5.2", features = [
alloy-rpc-types-admin = { version = "0.5.3", default-features = false }
alloy-rpc-types-anvil = { version = "0.5.3", default-features = false }
alloy-rpc-types-beacon = { version = "0.5.3", default-features = false }
alloy-rpc-types-debug = { version = "0.5.3", default-features = false }
alloy-rpc-types-engine = { version = "0.5.3", default-features = false }
alloy-rpc-types-eth = { version = "0.5.3", default-features = false }
alloy-rpc-types-mev = { version = "0.5.3", default-features = false }
alloy-rpc-types-trace = { version = "0.5.3", default-features = false }
alloy-rpc-types-txpool = { version = "0.5.3", default-features = false }
alloy-serde = { version = "0.5.3", default-features = false }
alloy-signer = { version = "0.5.3", default-features = false }
alloy-signer-local = { version = "0.5.3", default-features = false }
alloy-transport = { version = "0.5.3" }
alloy-transport-http = { version = "0.5.3", features = [
"reqwest-rustls-tls",
], default-features = false }
alloy-transport-ipc = { version = "0.5.2", default-features = false }
alloy-transport-ws = { version = "0.5.2", default-features = false }
alloy-transport-ipc = { version = "0.5.3", default-features = false }
alloy-transport-ws = { version = "0.5.3", default-features = false }

# op
op-alloy-rpc-types = "0.5"
Expand Down
13 changes: 8 additions & 5 deletions book/sources/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[workspace]
members = [
"exex/hello-world",
"exex/remote",
"exex/tracking-state",
]
members = ["exex/hello-world", "exex/remote", "exex/tracking-state"]

# Explicitly set the resolver to version 2, which is the default for packages with edition >= 2021
# https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html
resolver = "2"

[patch.'https://github.com/paradigmxyz/reth']
reth = { path = "../../bin/reth" }
reth-exex = { path = "../../crates/exex/exex" }
reth-node-ethereum = { path = "../../crates/ethereum/node" }
reth-tracing = { path = "../../crates/tracing" }
reth-node-api = { path = "../../crates/node/api" }
8 changes: 4 additions & 4 deletions book/sources/exex/hello-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = "0.1.0"
edition = "2021"

[dependencies]
reth = { git = "https://github.com/paradigmxyz/reth.git" } # Reth
reth-exex = { git = "https://github.com/paradigmxyz/reth.git" } # Execution Extensions
reth = { git = "https://github.com/paradigmxyz/reth.git" } # Reth
reth-exex = { git = "https://github.com/paradigmxyz/reth.git" } # Execution Extensions
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth.git" } # Ethereum Node implementation
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git" } # Logging
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git" } # Logging

eyre = "0.6" # Easy error handling
eyre = "0.6" # Easy error handling
futures-util = "0.3" # Stream utilities for consuming notifications
10 changes: 6 additions & 4 deletions book/sources/exex/tracking-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ edition = "2021"

[dependencies]
reth = { git = "https://github.com/paradigmxyz/reth.git" }
reth-exex = { git = "https://github.com/paradigmxyz/reth.git", features = ["serde"] }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth.git"}
reth-exex = { git = "https://github.com/paradigmxyz/reth.git", features = [
"serde",
] }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth.git" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git" }

eyre = "0.6" # Easy error handling
futures-util = "0.3" # Stream utilities for consuming notifications
eyre = "0.6" # Easy error handling
futures-util = "0.3" # Stream utilities for consuming notifications
alloy-primitives = "0.8.7"
90 changes: 15 additions & 75 deletions crates/primitives/src/transaction/sidecar.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![cfg_attr(docsrs, doc(cfg(feature = "c-kzg")))]

use crate::{Signature, Transaction, TransactionSigned};
use alloy_consensus::{
constants::EIP4844_TX_TYPE_ID, transaction::TxEip4844, TxEip4844WithSidecar,
};
use alloy_primitives::{keccak256, TxHash};
use alloy_rlp::{Decodable, Error as RlpError, Header};
use alloy_consensus::{constants::EIP4844_TX_TYPE_ID, TxEip4844WithSidecar};
use alloy_primitives::TxHash;
use alloy_rlp::Header;
use serde::{Deserialize, Serialize};

#[doc(inline)]
Expand All @@ -14,8 +12,6 @@ pub use alloy_eips::eip4844::BlobTransactionSidecar;
#[cfg(feature = "c-kzg")]
pub use alloy_eips::eip4844::BlobTransactionValidationError;

use alloc::vec::Vec;

/// A response to `GetPooledTransactions` that includes blob data, their commitments, and their
/// corresponding proofs.
///
Expand All @@ -36,7 +32,7 @@ impl BlobTransaction {
/// Constructs a new [`BlobTransaction`] from a [`TransactionSigned`] and a
/// [`BlobTransactionSidecar`].
///
/// Returns an error if the signed transaction is not [`TxEip4844`]
/// Returns an error if the signed transaction is not [`Transaction::Eip4844`]
pub fn try_from_signed(
tx: TransactionSigned,
sidecar: BlobTransactionSidecar,
Expand All @@ -57,7 +53,7 @@ impl BlobTransaction {

/// Verifies that the transaction's blob data, commitments, and proofs are all valid.
///
/// See also [`TxEip4844::validate_blob`]
/// See also [`alloy_consensus::TxEip4844::validate_blob`]
#[cfg(feature = "c-kzg")]
pub fn validate(
&self,
Expand Down Expand Up @@ -163,7 +159,7 @@ impl BlobTransaction {

// The payload length is the length of the `tranascation_payload_body` list, plus the
// length of the blobs, commitments, and proofs.
let payload_length = tx_length + self.transaction.sidecar.fields_len();
let payload_length = tx_length + self.transaction.sidecar.rlp_encoded_fields_length();

// We use the calculated payload len to construct the first list header, which encompasses
// everything in the tx - the length of the second, inner list header is part of
Expand All @@ -188,74 +184,17 @@ impl BlobTransaction {
/// Note: this should be used only when implementing other RLP decoding methods, and does not
/// represent the full RLP decoding of the `PooledTransactionsElement` type.
pub(crate) fn decode_inner(data: &mut &[u8]) -> alloy_rlp::Result<Self> {
// decode the _first_ list header for the rest of the transaction
let outer_header = Header::decode(data)?;
if !outer_header.list {
return Err(RlpError::Custom("PooledTransactions blob tx must be encoded as a list"))
}

let outer_remaining_len = data.len();

// Now we need to decode the inner 4844 transaction and its signature:
//
// `[chain_id, nonce, max_priority_fee_per_gas, ..., y_parity, r, s]`
let inner_header = Header::decode(data)?;
if !inner_header.list {
return Err(RlpError::Custom(
"PooledTransactions inner blob tx must be encoded as a list",
))
}

let inner_remaining_len = data.len();

// inner transaction
let transaction = TxEip4844::decode_fields(data)?;

// signature
let signature = Signature::decode_rlp_vrs(data)?;

// the inner header only decodes the transaction and signature, so we check the length here
let inner_consumed = inner_remaining_len - data.len();
if inner_consumed != inner_header.payload_length {
return Err(RlpError::UnexpectedLength)
}

// All that's left are the blobs, commitments, and proofs
let sidecar = BlobTransactionSidecar::decode(data)?;

// # Calculating the hash
//
// The full encoding of the `PooledTransaction` response is:
// `tx_type (0x03) || rlp([tx_payload_body, blobs, commitments, proofs])`
//
// The transaction hash however, is:
// `keccak256(tx_type (0x03) || rlp(tx_payload_body))`
//
// Note that this is `tx_payload_body`, not `[tx_payload_body]`, which would be
// `[[chain_id, nonce, max_priority_fee_per_gas, ...]]`, i.e. a list within a list.
//
// Because the pooled transaction encoding is different than the hash encoding for
// EIP-4844 transactions, we do not use the original buffer to calculate the hash.
//
// Instead, we use `encode_with_signature`, which RLP encodes the transaction with a
// signature for hashing without a header. We then hash the result.
let mut buf = Vec::new();
transaction.encode_with_signature(&signature, &mut buf, false);
let hash = keccak256(&buf);

// the outer header is for the entire transaction, so we check the length here
let outer_consumed = outer_remaining_len - data.len();
if outer_consumed != outer_header.payload_length {
return Err(RlpError::UnexpectedLength)
}
let (transaction, signature, hash) =
TxEip4844WithSidecar::decode_signed_fields(data)?.into_parts();

Ok(Self { transaction: TxEip4844WithSidecar { tx: transaction, sidecar }, hash, signature })
Ok(Self { transaction, hash, signature })
}
}

/// Generates a [`BlobTransactionSidecar`] structure containing blobs, commitments, and proofs.
#[cfg(all(feature = "c-kzg", any(test, feature = "arbitrary")))]
pub fn generate_blob_sidecar(blobs: Vec<c_kzg::Blob>) -> BlobTransactionSidecar {
use alloc::vec::Vec;
use alloy_eips::eip4844::env_settings::EnvKzgSettings;
use c_kzg::{KzgCommitment, KzgProof};

Expand Down Expand Up @@ -285,12 +224,12 @@ pub fn generate_blob_sidecar(blobs: Vec<c_kzg::Blob>) -> BlobTransactionSidecar
mod tests {
use super::*;
use crate::{kzg::Blob, PooledTransactionsElement};
use alloc::vec::Vec;
use alloy_eips::{
eip2718::{Decodable2718, Encodable2718},
eip4844::Bytes48,
};
use alloy_primitives::hex;
use alloy_rlp::Encodable;
use std::{fs, path::PathBuf, str::FromStr};

#[test]
Expand Down Expand Up @@ -392,7 +331,7 @@ mod tests {
let mut encoded_rlp = Vec::new();

// Encode the inner data of the BlobTransactionSidecar into RLP
sidecar.encode(&mut encoded_rlp);
sidecar.rlp_encode_fields(&mut encoded_rlp);

// Assert the equality between the expected RLP from the JSON and the encoded RLP
assert_eq!(json_value.get("rlp").unwrap().as_str().unwrap(), hex::encode(&encoded_rlp));
Expand Down Expand Up @@ -423,10 +362,11 @@ mod tests {
let mut encoded_rlp = Vec::new();

// Encode the inner data of the BlobTransactionSidecar into RLP
sidecar.encode(&mut encoded_rlp);
sidecar.rlp_encode_fields(&mut encoded_rlp);

// Decode the RLP-encoded data back into a BlobTransactionSidecar
let decoded_sidecar = BlobTransactionSidecar::decode(&mut encoded_rlp.as_slice()).unwrap();
let decoded_sidecar =
BlobTransactionSidecar::rlp_decode_fields(&mut encoded_rlp.as_slice()).unwrap();

// Assert the equality between the original BlobTransactionSidecar and the decoded one
assert_eq!(sidecar, decoded_sidecar);
Expand Down
14 changes: 5 additions & 9 deletions crates/storage/codecs/src/alloy/authorization_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,25 @@ impl Compact for SignedAuthorization {
where
B: bytes::BufMut + AsMut<[u8]>,
{
let signature = self.signature();
let (v, r, s) = (signature.v(), signature.r(), signature.s());
buf.put_u8(v.y_parity_byte());
buf.put_slice(r.as_le_slice());
buf.put_slice(s.as_le_slice());
buf.put_u8(self.y_parity());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks correct now because this always writes the u8 value as is

buf.put_slice(self.r().as_le_slice());
buf.put_slice(self.s().as_le_slice());

// to_compact doesn't write the len to buffer.
// By placing it as last, we don't need to store it either.
1 + 32 + 32 + self.deref().to_compact(buf)
}

fn from_compact(mut buf: &[u8], len: usize) -> (Self, &[u8]) {
let y = alloy_primitives::Parity::Parity(buf.get_u8() == 1);
let y_parity = buf.get_u8();
let r = U256::from_le_slice(&buf[0..32]);
buf.advance(32);
let s = U256::from_le_slice(&buf[0..32]);
buf.advance(32);

let signature = alloy_primitives::Signature::from_rs_and_parity(r, s, y)
.expect("invalid authorization signature");
let (auth, buf) = AlloyAuthorization::from_compact(buf, len);

(auth.into_signed(signature), buf)
(Self::new_unchecked(auth, y_parity, r, s), buf)
}
}

Expand Down
13 changes: 6 additions & 7 deletions crates/transaction-pool/src/blobstore/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::blobstore::{BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobStoreSize};
use alloy_eips::eip4844::BlobAndProofV1;
use alloy_primitives::{TxHash, B256};
use alloy_rlp::{Decodable, Encodable};
use parking_lot::{Mutex, RwLock};
use reth_primitives::BlobTransactionSidecar;
use schnellru::{ByLength, LruMap};
Expand Down Expand Up @@ -204,8 +203,8 @@ impl DiskFileBlobStoreInner {

/// Ensures blob is in the blob cache and written to the disk.
fn insert_one(&self, tx: B256, data: BlobTransactionSidecar) -> Result<(), BlobStoreError> {
let mut buf = Vec::with_capacity(data.fields_len());
data.encode(&mut buf);
let mut buf = Vec::with_capacity(data.rlp_encoded_fields_length());
data.rlp_encode_fields(&mut buf);
self.blob_cache.lock().insert(tx, data);
let size = self.write_one_encoded(tx, &buf)?;

Expand All @@ -219,8 +218,8 @@ impl DiskFileBlobStoreInner {
let raw = txs
.iter()
.map(|(tx, data)| {
let mut buf = Vec::with_capacity(data.fields_len());
data.encode(&mut buf);
let mut buf = Vec::with_capacity(data.rlp_encoded_fields_length());
data.rlp_encode_fields(&mut buf);
(self.blob_disk_file(*tx), buf)
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -312,7 +311,7 @@ impl DiskFileBlobStoreInner {
}
}
};
BlobTransactionSidecar::decode(&mut data.as_slice())
BlobTransactionSidecar::rlp_decode_fields(&mut data.as_slice())
.map(Some)
.map_err(BlobStoreError::DecodeError)
}
Expand All @@ -322,7 +321,7 @@ impl DiskFileBlobStoreInner {
self.read_many_raw(txs)
.into_iter()
.filter_map(|(tx, data)| {
BlobTransactionSidecar::decode(&mut data.as_slice())
BlobTransactionSidecar::rlp_decode_fields(&mut data.as_slice())
.map(|sidecar| (tx, sidecar))
.ok()
})
Expand Down
Loading