Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
4,021 changes: 2,574 additions & 1,447 deletions Cargo.lock

Large diffs are not rendered by default.

127 changes: 81 additions & 46 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace.package]
version = "0.1.0"
edition = "2021"
rust-version = "1.85"
rust-version = "1.93"
license = "MIT OR Apache-2.0"
homepage = "https://github.com/flashbots/rbuilder"
repository = "https://github.com/flashbots/rbuilder"
Expand Down Expand Up @@ -70,61 +70,71 @@ codegen-units = 1
incremental = false

[workspace.dependencies]
reth = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-db-common = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-errors = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-trie = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-trie-parallel = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-ethereum-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-provider = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646", features = [
# reth crates β€” paradigmxyz/reth bal-devnet-6 (glamsterdam-devnet-3): adds
# engine_getPayloadV6, BlockAccessList (EIP-7928), and ExecutionPayloadGloas.
reth = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-db-common = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-errors = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-trie = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-trie-parallel = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-ethereum-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-primitives-traits = { version = "0.3.0" }
reth-provider = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7", features = [
"test-utils",
] }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-execution-errors = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth", rev = "27a8c0f5a6dfb27dea84c5751776ecabdd069646" }

# compatible with reth 27a8c0f5a6dfb27dea84c5751776ecabdd069646 dependencies
revm = { version = "31.0.2", features = [
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-execution-errors = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }
reth-tasks = { git = "https://github.com/paradigmxyz/reth", rev = "8ebfaff134a973ea7b89f619a0562882e97b93c7" }

# compatible with local reth dependencies (bumped for bal-devnet-6)
revm = { version = "=38.0.0", features = [
"std",
"secp256k1",
"optional_balance_check",
], default-features = false }
revm-inspectors = { version = "0.32.0", default-features = false }
revm-inspectors = { version = "=0.39.0", default-features = false }

ethereum_ssz_derive = "0.9.0"
ethereum_ssz = "0.9.0"
ethereum_ssz_derive = "0.10.0"
ethereum_ssz = "0.10.0"
tree_hash = "0.12.0"

alloy-primitives = { version = "1.4.1", default-features = false, features = [
# Lighthouse consensus types for Gloas/EPBS SSZ types β€” glamsterdam-devnet-3
# branch (has `execution_requests_root` on ExecutionPayloadBid and the new
# Gloas envelope schema with `parent_beacon_block_root`, no `slot`/`state_root`).
lighthouse_types = { git = "https://github.com/sigp/lighthouse", rev = "27cfa18c17e148fb75827d0ea3c9a2c69db0aae0", package = "types", default-features = false, features = ["saturating-arith"] }
lighthouse_bls = { git = "https://github.com/sigp/lighthouse", rev = "27cfa18c17e148fb75827d0ea3c9a2c69db0aae0", package = "bls" }
lighthouse_ssz_types = { version = "0.14.1", package = "ssz_types", features = ["context_deserialize", "runtime_types"] }

alloy-primitives = { version = "1.5.6", default-features = false, features = [
"getrandom",
] }
alloy-rlp = "0.3.10"
alloy-chains = "0.2.5"
alloy-trie = { version = "0.8.1", default-features = false }
alloy-evm = { version = "0.23.3", default-features = false }
alloy-provider = { version = "1.0.41", features = ["ipc", "pubsub", "ws"] }
alloy-eips = { version = "1.0.41" }
alloy-rpc-types = { version = "1.0.41" }
alloy-json-rpc = { version = "1.0.41" }
alloy-network = { version = "1.0.41" }
alloy-network-primitives = { version = "1.0.41" }
alloy-node-bindings = { version = "1.0.41" }
alloy-consensus = { version = "1.0.41", features = ["kzg"] }
alloy-rpc-types-beacon = { version = "1.0.41", features = ["ssz"] }
alloy-rpc-types-engine = { version = "1.0.41", features = ["ssz"] }
alloy-rpc-types-eth = { version = "1.0.41" }
alloy-signer = { version = "1.0.41" }
alloy-signer-local = { version = "1.0.41" }
alloy-rlp = "0.3.13"
alloy-chains = "0.2.33"
alloy-trie = { version = "0.9.4", default-features = false }
alloy-evm = { version = "0.34.0", default-features = false }
alloy-provider = { version = "2.0.1", features = ["ipc", "pubsub", "ws"] }
alloy-eips = { version = "2.0.1" }
alloy-rpc-types = { version = "2.0.1" }
alloy-json-rpc = { version = "2.0.1" }
alloy-network = { version = "2.0.1" }
alloy-network-primitives = { version = "2.0.1" }
alloy-node-bindings = { version = "2.0.1" }
alloy-consensus = { version = "2.0.1", features = ["kzg"] }
alloy-rpc-types-beacon = { version = "2.0.1", features = ["ssz"] }
alloy-rpc-types-engine = { version = "2.0.1", features = ["ssz"] }
alloy-rpc-types-eth = { version = "2.0.1" }
alloy-signer = { version = "2.0.1" }
alloy-signer-local = { version = "2.0.1" }

# Version required by ethereum-consensus beacon-api-client
mev-share-sse = { git = "https://github.com/paradigmxyz/mev-share-rs", rev = "9eb2b0138ab3202b9eb3af4b19c7b3bf40b0faa8", default-features = false }
Expand Down Expand Up @@ -185,3 +195,28 @@ metrics_macros = { path = "crates/rbuilder/src/telemetry/metrics_macros" }
[workspace.metadata.cargo-shear]
# cargo-shear invalidly marks these as unused.
ignored = ["prost", "prost-types"]

# Mirror upstream reth's patch section so revm/alloy-evm/reth-codecs resolve to
# the same revs reth itself is built against. If this gets out of sync with
# reth's Cargo.toml, the build fails with conflicting type definitions for the
# `revm` types reth's API surface uses.
[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-bytecode = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-context = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-context-interface = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-database = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-database-interface = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-handler = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-inspector = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-interpreter = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-precompile = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-state = { git = "https://github.com/bluealloy/revm", rev = "7ac2a4a922d70e73f7b45baa16ed996f479d6a41" }
revm-inspectors = { git = "https://github.com/paradigmxyz/revm-inspectors", rev = "1c2e997a33baa698decdaaba5f14326fc40dfee6" }
alloy-evm = { git = "https://github.com/alloy-rs/evm", rev = "13c9068fe8d0b112f2836783f9702eb3d3b7871f" }
reth-codecs = { git = "https://github.com/paradigmxyz/reth-core", rev = "afa5162668db00749b14bf30d06d3bed5c71aa4c" }
reth-codecs-derive = { git = "https://github.com/paradigmxyz/reth-core", rev = "afa5162668db00749b14bf30d06d3bed5c71aa4c" }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth-core", rev = "afa5162668db00749b14bf30d06d3bed5c71aa4c" }
reth-rpc-traits = { git = "https://github.com/paradigmxyz/reth-core", rev = "afa5162668db00749b14bf30d06d3bed5c71aa4c" }
reth-zstd-compressors = { git = "https://github.com/paradigmxyz/reth-core", rev = "afa5162668db00749b14bf30d06d3bed5c71aa4c" }
2 changes: 1 addition & 1 deletion crates/eth-sparse-mpt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rustc-hash = "2.0.0"
rayon = "1.10.0"
smallvec = "1.13.2"
alloy-trie.workspace = true
nybbles = { version = "0.3.3", features = ["serde"] }
nybbles = { version = "0.4", features = ["serde"] }

tracing.workspace = true

Expand Down
28 changes: 15 additions & 13 deletions crates/eth-sparse-mpt/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,28 @@ pub fn rlp_pointer(rlp_encode: Bytes) -> Bytes {
}

pub fn concat_path(p1: &Nibbles, p2: &[u8]) -> Nibbles {
let mut result = Nibbles::with_capacity(p1.len() + p2.len());
result.extend_from_slice_unchecked(p1);
result.extend_from_slice_unchecked(p2);
let mut result = *p1;
let p2_nibbles = Nibbles::from_nibbles_unchecked(p2);
result.extend(&p2_nibbles);
result
}

pub fn strip_first_nibble_mut(p: &mut Nibbles) -> u8 {
let nibble = p[0];
let vec = p.as_mut_vec_unchecked();
let nibble = p.get_unchecked(0);
let mut vec = p.to_vec();
vec.remove(0);
*p = Nibbles::from_nibbles_unchecked(vec);
nibble
}

#[inline]
pub fn extract_prefix_and_suffix(p1: &Nibbles, p2: &Nibbles) -> (Nibbles, Nibbles, Nibbles) {
let prefix_len = p1.common_prefix_length(p2);
let prefix = Nibbles::from_nibbles_unchecked(&p1[..prefix_len]);
let suffix1 = Nibbles::from_nibbles_unchecked(&p1[prefix_len..]);
let suffix2 = Nibbles::from_nibbles_unchecked(&p2[prefix_len..]);
let p1_vec = p1.to_vec();
let p2_vec = p2.to_vec();
let prefix = Nibbles::from_nibbles_unchecked(&p1_vec[..prefix_len]);
let suffix1 = Nibbles::from_nibbles_unchecked(&p1_vec[prefix_len..]);
let suffix2 = Nibbles::from_nibbles_unchecked(&p2_vec[prefix_len..]);

(prefix, suffix1, suffix2)
}
Expand Down Expand Up @@ -137,15 +140,14 @@ fn mismatch_chunks<const N: usize>(xs: &[u8], ys: &[u8]) -> usize {
.count()
}

// rbuilder uses nybbles v3.3.0 and reth_trie uses nybbles v4.3.0. This is a temporary fix to convert between the two.
// We can remove the below methods once rbuilder has been upgraded to nybbles v4.3.0.
// nybbles v4.3.0 has a breaking change (byte array with 1 byte per nybble vs U256 packed data + length) in the API which breaks a lot of parts of the eth sparse trie code.
// rbuilder and reth_trie now both use nybbles v0.4.x, so these are identity conversions.
// Kept for backward compatibility with call sites.
#[inline]
pub fn convert_reth_nybbles_to_nibbles(n: reth_trie::Nibbles) -> Nibbles {
Nibbles::from_nibbles(n.to_vec())
n
}

#[inline]
pub fn convert_nibbles_to_reth_nybbles(n: Nibbles) -> reth_trie::Nibbles {
reth_trie::Nibbles::from_nibbles(n.as_slice())
n
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ impl RethSparseTrieShareCacheInternal {
multiproof: MultiProof,
) -> Result<(), AddNodeError> {
let mut nodes: Vec<_> = multiproof.account_subtree.into_iter().collect();
nodes.sort_by_key(|(p, _)| p.clone());
nodes.sort_by_key(|(p, _)| *p);
self.account_trie.add_nodes(&nodes)?;
for (account, storge_proofs) in multiproof.storages {
let mut nodes: Vec<_> = storge_proofs.subtree.into_iter().collect();
nodes.sort_by_key(|(p, _)| p.clone());
nodes.sort_by_key(|(p, _)| *p);
let account = Bytes::copy_from_slice(account.as_slice());
let storage_trie = self.storage_tries.entry(account).or_default();
storage_trie.add_nodes(&nodes)?;
Expand Down
24 changes: 13 additions & 11 deletions crates/eth-sparse-mpt/src/v1/reth_sparse_trie/trie_fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reth_provider::{
providers::ConsistentDbView, BlockReader, DBProvider, DatabaseProviderFactory,
};
use reth_trie::{proof::Proof, MultiProof as RethMultiProof, MultiProofTargets, EMPTY_ROOT_HASH};
use reth_trie_db::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory};
use reth_trie_db::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory, LegacyKeyAdapter};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Seq};

Expand Down Expand Up @@ -78,7 +78,7 @@ where
let start = Instant::now();
let provider = self.consistent_db_view.provider_ro()?;
let proof = Proof::new(
DatabaseTrieCursorFactory::new(provider.tx_ref()),
DatabaseTrieCursorFactory::<_, LegacyKeyAdapter>::new(provider.tx_ref()),
DatabaseHashedCursorFactory::new(provider.tx_ref()),
);
let targets_accounts = targets.len();
Expand All @@ -105,10 +105,12 @@ where
}
}

fn pad_path(mut path: Nibbles) -> B256 {
path.as_mut_vec_unchecked().resize(64, 0);
fn pad_path(path: Nibbles) -> B256 {
let mut v = path.to_vec();
v.resize(64, 0);
let padded = Nibbles::from_nibbles_unchecked(v);
let mut res = B256::default();
path.pack_to(res.as_mut_slice());
padded.pack_to(res.as_mut_slice());
res
}

Expand Down Expand Up @@ -164,16 +166,16 @@ fn merge_results(
let mut result = MultiProof::default();
for mut proof in multiproofs {
result.account_subtree.append(&mut proof.account_subtree);
result.account_subtree.sort_by_key(|s| s.0.clone());
result.account_subtree.dedup_by_key(|s| s.0.clone());
result.account_subtree.sort_by_key(|s| s.0);
result.account_subtree.dedup_by_key(|s| s.0);

for (account, mut storage_proof) in proof.storages {
let result_storage_proof = result.storages.entry(account).or_default();
result_storage_proof
.subtree
.append(&mut storage_proof.subtree);
result_storage_proof.subtree.sort_by_key(|s| s.0.clone());
result_storage_proof.subtree.dedup_by_key(|s| s.0.clone());
result_storage_proof.subtree.sort_by_key(|s| s.0);
result_storage_proof.subtree.dedup_by_key(|s| s.0);
}
}

Expand All @@ -194,7 +196,7 @@ fn convert_reth_multiproof(
for (k, v) in reth_proof.account_subtree.into_inner() {
account_subtree.push((convert_reth_nybbles_to_nibbles(k), v));
}
account_subtree.sort_by_key(|a| a.0.clone());
account_subtree.sort_by_key(|a| a.0);
let mut storages = hash_map_with_capacity(reth_proof.storages.len());
for (k, reth_storage_proof) in reth_proof.storages {
if !all_requested_accounts.contains(&k) {
Expand All @@ -208,7 +210,7 @@ fn convert_reth_multiproof(
for (k, v) in reth_storage_proof.subtree.into_inner() {
subtree.push((convert_reth_nybbles_to_nibbles(k), v));
}
subtree.sort_by_key(|a| a.0.clone());
subtree.sort_by_key(|a| a.0);
let v = StorageMultiProof { subtree };
storages.insert(k, v);
}
Expand Down
Loading