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

fix: override eth_getProof to enable withdrawals #97

Merged
merged 12 commits into from
Nov 26, 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
19 changes: 19 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"bin/odyssey/",
"crates/common",
"crates/node",
"crates/e2e-tests",
"crates/wallet",
Expand Down Expand Up @@ -134,6 +135,7 @@ strip = false

[workspace.dependencies]
# odyssey
odyssey-common = { path = "crates/common" }
odyssey-node = { path = "crates/node" }
odyssey-wallet = { path = "crates/wallet" }
odyssey-walltime = { path = "crates/walltime" }
Expand All @@ -149,6 +151,7 @@ alloy-eips = "0.6.4"
alloy-network = "0.6.4"
alloy-primitives = "0.8.11"
alloy-rpc-types = "0.6.4"
alloy-rpc-types-eth = "0.6.4"
alloy-signer-local = { version = "0.6.4", features = ["mnemonic"] }

# tokio
Expand All @@ -158,6 +161,7 @@ tokio = { version = "1.21", default-features = false }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-errors = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-evm = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
Expand All @@ -181,13 +185,17 @@ reth-payload-builder = { git = "https://github.com/paradigmxyz/reth.git", rev =
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac", features = [
"optimism",
] }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-provider = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac", features = [
"optimism",
] }
reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-rpc-types-compat = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-rpc-eth-types = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-storage-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-trie-common = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-network = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-network-types = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
Expand Down
11 changes: 10 additions & 1 deletion bin/odyssey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ use alloy_primitives::Address;
use alloy_signer_local::PrivateKeySigner;
use clap::Parser;
use eyre::Context;
use odyssey_node::{chainspec::OdysseyChainSpecParser, node::OdysseyNode};
use odyssey_node::{
chainspec::OdysseyChainSpecParser,
node::OdysseyNode,
rpc::{EthApiExt, EthApiOverrideServer},
};
use odyssey_wallet::{OdysseyWallet, OdysseyWalletApiServer};
use odyssey_walltime::{OdysseyWallTime, OdysseyWallTimeRpcApiServer};
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
Expand Down Expand Up @@ -56,6 +60,11 @@ fn main() {
.with_components(OdysseyNode::components(&rollup_args))
.with_add_ons(OpAddOns::new(rollup_args.sequencer_http))
.extend_rpc_modules(move |ctx| {
// override eth namespace
ctx.modules.replace_configured(
EthApiExt::new(ctx.registry.eth_api().clone()).into_rpc(),
)?;

// register odyssey wallet namespace
if let Ok(sk) = std::env::var("EXP1_SK") {
let signer: PrivateKeySigner =
Expand Down
16 changes: 16 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "odyssey-common"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true

[dependencies]
alloy-primitives.workspace = true

[lints]
workspace = true
8 changes: 8 additions & 0 deletions crates/common/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Odyssey constants.

use alloy_primitives::{address, Address};

/// Withdrawal predeployed contract address.
///
/// [The L2ToL1MessagePasser](https://specs.optimism.io/protocol/withdrawals.html#the-l2tol1messagepasser-contract)
pub const WITHDRAWAL_CONTRACT: Address = address!("4200000000000000000000000000000000000016");
7 changes: 7 additions & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Odyssey common types and constants

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![warn(unused_crate_dependencies)]

mod constants;
pub use constants::WITHDRAWAL_CONTRACT;
5 changes: 5 additions & 0 deletions crates/e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ keywords.workspace = true
categories.workspace = true

[dev-dependencies]
odyssey-common.workspace = true

reth-primitives-traits.workspace = true
reth-trie-common.workspace = true

alloy.workspace = true
alloy-network.workspace = true
alloy-rpc-types.workspace = true
Expand Down
62 changes: 61 additions & 1 deletion crates/e2e-tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use alloy::{
signers::SignerSync,
};
use alloy_network::{TransactionBuilder, TransactionBuilder7702};
use alloy_rpc_types::TransactionRequest;
use alloy_rpc_types::{Block, BlockNumberOrTag, EIP1186AccountProofResponse, TransactionRequest};
use alloy_signer_local::PrivateKeySigner;
use reth_primitives_traits::Account;
use reth_trie_common::{AccountProof, StorageProof};
use url::Url;

static REPLICA_RPC: LazyLock<Url> = LazyLock::new(|| {
Expand Down Expand Up @@ -127,3 +129,61 @@ async fn test_new_wallet_api() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[tokio::test]
async fn test_withdrawal_proof_with_fallback() -> Result<(), Box<dyn std::error::Error>> {
if !ci_info::is_ci() {
return Ok(());
}

let provider = ProviderBuilder::new().on_http(REPLICA_RPC.clone());
let block: Block = provider
.client()
.request("eth_getBlockByNumber", (BlockNumberOrTag::Latest, false))
.await?;
let block_number = BlockNumberOrTag::Number(block.header.number);

// Withdrawal contract will return an empty account proof, since it only handles storage proofs
let withdrawal_contract_response: EIP1186AccountProofResponse = provider
.client()
.request(
"eth_getProof",
(odyssey_common::WITHDRAWAL_CONTRACT, vec![B256::ZERO], block_number),
)
.await?;

assert!(withdrawal_contract_response.account_proof.is_empty());
assert!(!withdrawal_contract_response.storage_proof.is_empty());

let storage_root = withdrawal_contract_response.storage_hash;
for proof in withdrawal_contract_response.storage_proof {
StorageProof::new(proof.key.as_b256()).with_proof(proof.proof).verify(storage_root)?
}

// If not targeting the withdrawal contract, it defaults back to the standard getProof
// implementation
let signer = PrivateKeySigner::from_bytes(&b256!(
"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
))?;

let eoa_response: EIP1186AccountProofResponse = provider
.client()
.request("eth_getProof", (signer.address(), [0; 0], block_number))
.await
.unwrap();

assert!(!eoa_response.account_proof.is_empty());
AccountProof {
address: signer.address(),
info: Some(Account {
nonce: eoa_response.nonce,
balance: eoa_response.balance,
bytecode_hash: Some(eoa_response.code_hash),
}),
proof: eoa_response.account_proof,
..Default::default()
}
.verify(block.header.state_root)?;

Ok(())
}
11 changes: 11 additions & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ keywords.workspace = true
categories.workspace = true

[dependencies]
odyssey-common.workspace = true

revm-precompile.workspace = true
revm-primitives.workspace = true

reth-cli.workspace = true
reth-errors.workspace = true
reth-node-api.workspace = true
reth-node-builder.workspace = true
reth-optimism-node.workspace = true
Expand All @@ -25,18 +28,26 @@ reth-payload-builder.workspace = true
reth-primitives.workspace = true
reth-evm.workspace = true
reth-revm.workspace = true
reth-rpc-eth-api.workspace = true
reth-rpc-eth-types.workspace = true
reth-rpc-types-compat.workspace = true
reth-transaction-pool.workspace = true
reth-trie-common.workspace = true
reth-trie-db.workspace = true
reth-network.workspace = true
reth-network-types.workspace = true

alloy-consensus.workspace = true
alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rpc-types.workspace = true
alloy-rpc-types-eth.workspace = true


serde_json.workspace = true
tracing.workspace = true
eyre.workspace = true
jsonrpsee.workspace = true

[lints]
workspace = true
1 change: 1 addition & 0 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
pub mod chainspec;
pub mod evm;
pub mod node;
pub mod rpc;
Loading