From 9fb0b25818d529713dba05bdc01bbc8caf0b99c4 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 12 Aug 2024 22:14:42 +0000 Subject: [PATCH] chore: remove eip3074 instructions --- Cargo.lock | 9 -- Cargo.toml | 1 - crates/node/Cargo.toml | 2 - crates/node/src/evm.rs | 49 --------- crates/testing/src/tests.rs | 189 +---------------------------------- crates/testing/src/wallet.rs | 12 --- 6 files changed, 2 insertions(+), 260 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b3de76a..a4cfba1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -751,7 +751,6 @@ name = "alphanet-node" version = "0.0.0" dependencies = [ "alphanet-precompile", - "eip3074-instructions", "eyre", "reth", "reth-chainspec", @@ -2486,14 +2485,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "eip3074-instructions" -version = "0.1.0" -source = "git+https://github.com/paradigmxyz/eip3074-instructions.git#5629b523b9022408b1d7a623849026704050dae8" -dependencies = [ - "revm", -] - [[package]] name = "either" version = "1.13.0" diff --git a/Cargo.toml b/Cargo.toml index 0fc2689..441a700 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,6 @@ reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "v1.0.4" clap = "4" eyre = "0.6.12" tracing = "0.1.0" -eip3074-instructions = { git = "https://github.com/paradigmxyz/eip3074-instructions.git" } # misc-testing rstest = "0.18.2" diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 8e0f8bf..75f20ab 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -16,8 +16,6 @@ reth-node-api.workspace = true reth-node-optimism.workspace = true reth-chainspec.workspace = true -eip3074-instructions.workspace = true - eyre.workspace = true [features] diff --git a/crates/node/src/evm.rs b/crates/node/src/evm.rs index 031d064..2c2c044 100644 --- a/crates/node/src/evm.rs +++ b/crates/node/src/evm.rs @@ -11,7 +11,6 @@ //! precompiles defined by [`alphanet_precompile`]. use alphanet_precompile::{bls12_381, secp256r1}; -use eip3074_instructions::{context::InstructionsContext, instructions as eip3074}; use reth::{ primitives::{ revm_primitives::{CfgEnvWithHandlerCfg, TxEnv}, @@ -57,52 +56,17 @@ impl AlphaNetEvmConfig { loaded_precompiles }); } - - /// Appends custom instructions to the EVM handler - /// - /// This will be invoked when the EVM is created via [ConfigureEvm::evm] or - /// [ConfigureEvm::evm_with_inspector] - /// - /// This will use the default mainnet instructions and append additional instructions. - fn append_custom_instructions( - handler: &mut EvmHandler<'_, EXT, DB>, - instructions_context: InstructionsContext, - ) where - DB: Database, - { - let boxed_instruction_with_op_code = - eip3074::boxed_instructions(instructions_context.clone()); - - for b in boxed_instruction_with_op_code { - handler.instruction_table.insert_boxed(b.opcode, b.boxed_instruction); - } - - instructions_context.clear(); - } } impl ConfigureEvm for AlphaNetEvmConfig { type DefaultExternalContext<'a> = (); fn evm(&self, db: DB) -> Evm<'_, Self::DefaultExternalContext<'_>, DB> { - let instructions_context = InstructionsContext::default(); EvmBuilder::default() .with_db(db) .optimism() // add additional precompiles .append_handler_register(Self::set_precompiles) - // add custom instructions - .append_handler_register_box(Box::new(move |h| { - Self::append_custom_instructions(h, instructions_context.clone()); - let post_execution_context = instructions_context.clone(); - #[allow(clippy::arc_with_non_send_sync)] - { - h.post_execution.end = Arc::new(move |_, outcome: _| { - post_execution_context.clear(); - outcome - }); - } - })) .build() } @@ -111,25 +75,12 @@ impl ConfigureEvm for AlphaNetEvmConfig { DB: Database, I: GetInspector, { - let instructions_context = InstructionsContext::default(); EvmBuilder::default() .with_db(db) .with_external_context(inspector) .optimism() // add additional precompiles .append_handler_register(Self::set_precompiles) - // add custom instructions - .append_handler_register_box(Box::new(move |h| { - Self::append_custom_instructions(h, instructions_context.clone()); - let post_execution_context = instructions_context.clone(); - #[allow(clippy::arc_with_non_send_sync)] - { - h.post_execution.end = Arc::new(move |_, outcome: _| { - post_execution_context.clear(); - outcome - }); - } - })) .append_handler_register(inspector_handle_register) .build() } diff --git a/crates/testing/src/tests.rs b/crates/testing/src/tests.rs index 3c43b69..7e45a05 100644 --- a/crates/testing/src/tests.rs +++ b/crates/testing/src/tests.rs @@ -1,36 +1,18 @@ -use crate::{test_suite::TestSuite, wallet::Wallet}; +use crate::test_suite::TestSuite; use alloy::{ primitives::hex, providers::{Provider, ProviderBuilder}, sol, - sol_types::SolValue, }; -use alloy_network::EthereumWallet; use alphanet_node::node::AlphaNetNode; use once_cell::sync::Lazy; use reth::{builder::NodeHandle, tasks::TaskManager}; use reth_chainspec::DEV; use reth_node_builder::NodeBuilder; use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig}; -use reth_primitives::{keccak256, Address, Bytes, U256}; +use reth_primitives::Bytes; use url::Url; -sol!( - #[allow(clippy::too_many_arguments)] - #[allow(missing_docs)] - #[sol(rpc)] - GasSponsorInvoker, - "resources/eip3074/out/GasSponsorInvoker.sol/GasSponsorInvoker.json" -); - -sol!( - #[allow(clippy::too_many_arguments)] - #[allow(missing_docs)] - #[sol(rpc)] - SenderRecorder, - "resources/eip3074/out/SenderRecorder.sol/SenderRecorder.json" -); - sol!( #[allow(clippy::too_many_arguments)] #[allow(missing_docs)] @@ -39,173 +21,6 @@ sol!( "resources/bls12-381/out/BlsG1AddCaller.sol/BlsG1AddCaller.json" ); -#[tokio::test] -async fn test_eip3074_integration() { - reth_tracing::init_test_tracing(); - let tasks = TaskManager::current(); - let test_suite = TestSuite::new(); - - // spin up alphanet node - let chain_spec = Lazy::force(&DEV).clone(); - let node_config = NodeConfig::test() - .dev() - .with_chain(chain_spec) - .with_rpc(RpcServerArgs::default().with_unused_ports().with_http()); - let NodeHandle { node, .. } = NodeBuilder::new(node_config) - .testing_node(tasks.executor()) - .node(AlphaNetNode::default()) - .launch() - .await - .unwrap(); - - let rpc_url = node.rpc_server_handle().http_url().unwrap(); - let deployer = test_suite.signer(); - let provider = ProviderBuilder::new() - .with_recommended_fillers() - .wallet(deployer) - .on_http(Url::parse(&rpc_url).unwrap()); - let base_fee = provider.get_gas_price().await.unwrap(); - - // Deploy sender recorder contract. - let sender_recorder_builder = SenderRecorder::deploy_builder(&provider); - let estimate = sender_recorder_builder.estimate_gas().await.unwrap(); - let sender_recorder_address = - sender_recorder_builder.gas(estimate).gas_price(base_fee).nonce(0).deploy().await.unwrap(); - let sender_recorder = SenderRecorder::new(sender_recorder_address, &provider); - let SenderRecorder::lastSenderReturn { _0 } = - sender_recorder.lastSender().call().await.unwrap(); - assert_eq!(_0, Address::ZERO); - - // Deploy invoker contract. - let invoker_builder = GasSponsorInvoker::deploy_builder(&provider); - let estimate = invoker_builder.estimate_gas().await.unwrap(); - let invoker_address = - invoker_builder.gas(estimate).gas_price(base_fee).nonce(1).deploy().await.unwrap(); - let invoker = GasSponsorInvoker::new(invoker_address, &provider); - - // signer account. - let signer_wallet = Wallet::random(); - let signer_account: EthereumWallet = signer_wallet.clone().into(); - let signer_address = signer_account.default_signer().address(); - let signer_balance = provider.get_balance(signer_address).await.unwrap(); - assert_eq!(signer_balance, U256::ZERO); - let signer_nonce = provider.get_transaction_count(signer_address).await.unwrap(); - - // abi encoded method call. - let binding = sender_recorder.recordSender(); - let data = reth_primitives::Bytes(binding.calldata().0.clone()); - - // commit, digest and signature. - let commit = keccak256((sender_recorder_address, data.clone()).abi_encode_sequence()); - let GasSponsorInvoker::getDigestReturn { digest } = - invoker.getDigest(commit, U256::from(signer_nonce)).call().await.unwrap(); - let (v, r, s) = signer_wallet.sign_hash(digest).await; - - let builder = invoker.sponsorCall( - signer_address, - v, - r.into(), - s.into(), - sender_recorder_address, - data, - U256::ZERO, - ); - let estimate = builder.estimate_gas().await.unwrap(); - let receipt = builder - .gas(estimate) - .gas_price(base_fee) - .nonce(2) - .send() - .await - .unwrap() - .get_receipt() - .await; - assert!(receipt.is_ok()); - - let SenderRecorder::lastSenderReturn { _0 } = - sender_recorder.lastSender().call().await.unwrap(); - assert_eq!(_0, signer_address); -} - -#[tokio::test] -async fn test_eip3074_send_eth() { - reth_tracing::init_test_tracing(); - let tasks = TaskManager::current(); - let test_suite = TestSuite::new(); - - // spin up alphanet node - let chain_spec = Lazy::force(&DEV).clone(); - let node_config = NodeConfig::test() - .dev() - .with_chain(chain_spec) - .with_rpc(RpcServerArgs::default().with_unused_ports().with_http()); - let NodeHandle { node, .. } = NodeBuilder::new(node_config) - .testing_node(tasks.executor()) - .node(AlphaNetNode::default()) - .launch() - .await - .unwrap(); - - let rpc_url = node.rpc_server_handle().http_url().unwrap(); - let deployer = test_suite.signer(); - let provider = ProviderBuilder::new() - .with_recommended_fillers() - .wallet(deployer) - .on_http(Url::parse(&rpc_url).unwrap()); - let base_fee = provider.get_gas_price().await.unwrap(); - - // Deploy invoker contract. - let invoker_builder = GasSponsorInvoker::deploy_builder(&provider); - let estimate = invoker_builder.estimate_gas().await.unwrap(); - let invoker_address = - invoker_builder.gas(estimate).gas_price(base_fee).nonce(0).deploy().await.unwrap(); - let invoker = GasSponsorInvoker::new(invoker_address, &provider); - - // signer account. - let signer_wallet = Wallet::new(1); - let signer_account: EthereumWallet = signer_wallet.clone().into(); - let signer_address = signer_account.default_signer().address(); - let start_signer_balance = provider.get_balance(signer_address).await.unwrap(); - assert!(start_signer_balance.ne(&U256::ZERO)); - let signer_nonce = provider.get_transaction_count(signer_address).await.unwrap(); - - let data = reth_primitives::Bytes::new(); - - // receiver account - let receiver_wallet = Wallet::random(); - let receiver_account: EthereumWallet = receiver_wallet.clone().into(); - let receiver_address = receiver_account.default_signer().address(); - let receiver_balance = provider.get_balance(receiver_address).await.unwrap(); - assert_eq!(receiver_balance, U256::ZERO); - - // commit, digest and signature. - let commit = keccak256((receiver_address, data.clone()).abi_encode_sequence()); - let GasSponsorInvoker::getDigestReturn { digest } = - invoker.getDigest(commit, U256::from(signer_nonce)).call().await.unwrap(); - let (v, r, s) = signer_wallet.sign_hash(digest).await; - - let amount = U256::from_str_radix("1000000000000000000", 10).unwrap(); // 1 ETH - - let builder = - invoker.sponsorCall(signer_address, v, r.into(), s.into(), receiver_address, data, amount); - let estimate = builder.estimate_gas().await.unwrap(); - let receipt = builder - .gas(estimate) - .gas_price(base_fee) - .nonce(1) - .send() - .await - .unwrap() - .get_receipt() - .await; - assert!(receipt.is_ok()); - - let receiver_balance = provider.get_balance(receiver_address).await.unwrap(); - assert_eq!(receiver_balance, amount); - let end_signer_balance = provider.get_balance(signer_address).await.unwrap(); - assert!(end_signer_balance.eq(&start_signer_balance.saturating_sub(amount))); -} - #[tokio::test] async fn test_bls12_381_g1_add() { reth_tracing::init_test_tracing(); diff --git a/crates/testing/src/wallet.rs b/crates/testing/src/wallet.rs index fd841b0..6ec9a51 100644 --- a/crates/testing/src/wallet.rs +++ b/crates/testing/src/wallet.rs @@ -1,7 +1,5 @@ -use alloy::signers::Signer; use alloy_network::EthereumWallet; use alloy_signer_local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}; -use reth_primitives::{B256, U256}; /// Mnemonic used to derive the test accounts const TEST_MNEMONIC: &str = "test test test test test test test test test test test junk"; @@ -29,16 +27,6 @@ impl Wallet { .unwrap(); Self { inner } } - - pub(crate) fn random() -> Self { - let inner = MnemonicBuilder::::default().build_random().unwrap(); - Self { inner } - } - - pub(crate) async fn sign_hash(&self, message: B256) -> (u8, U256, U256) { - let signature = self.inner.sign_hash(&message).await.unwrap(); - (signature.v().y_parity_byte() + 27, signature.r(), signature.s()) - } } impl From for EthereumWallet { fn from(val: Wallet) -> Self {