Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

chore: bump alloy, reth, revm, and eip3074-instructions #88

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6,079 changes: 2,321 additions & 3,758 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 13 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,34 @@ incremental = false
alphanet-node = { path = "crates/node" }
alphanet-precompile = { path = "crates/precompile" }

alloy = { git = "https://github.com/alloy-rs/alloy", rev = "5796024", features = [
alloy = { version = "0.2", features = [
"contract",
"providers",
"provider-http",
"signers",
] }
alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "5796024" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "5796024" }
alloy-network = { version = "0.2" }
alloy-signer-local = { version = "0.2", features = ["mnemonic"] }

# tokio
tokio = { version = "1.21", default-features = false }

# reth
reth = { git = "https://github.com/paradigmxyz/reth.git", rev = "40d8ac0", features = ["optimism"] }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "40d8ac0" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "40d8ac0" }
reth-node-optimism = { git = "https://github.com/paradigmxyz/reth.git", rev = "40d8ac0" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", rev = "40d8ac0" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "40d8ac0" }
reth = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4", features = ["optimism"] }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4" }
reth-node-optimism = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "539b4e4" }
Copy link
Contributor

Choose a reason for hiding this comment

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

lets start using tags "v1.0.2"

Copy link
Contributor Author

Choose a reason for hiding this comment

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


# misc
clap = "4"
eyre = "0.6.12"
tracing = "0.1.0"
eip3074-instructions = { git = "https://github.com/paradigmxyz/eip3074-instructions.git", rev = "a9022e4" }
eip3074-instructions = { git = "https://github.com/emostov/eip3074-instructions.git", branch = "bump-revm" }
Copy link
Contributor

Choose a reason for hiding this comment

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

could you perhaps also bump the eip3074 instructions repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually looks like i need to bump msrv here and in eip3074 prs


# misc-testing
rstest = "0.18.2"

[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm", rev = "a28a543" }
revm-interpreter = { git = "https://github.com/bluealloy/revm", rev = "a28a543" }
revm-precompile = { git = "https://github.com/bluealloy/revm", rev = "a28a543" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "a28a543" }
1 change: 1 addition & 0 deletions bin/alphanet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workspace = true
alphanet-node.workspace = true
tracing.workspace = true
reth.workspace = true
reth-cli-util.workspace = true
reth-node-optimism.workspace = true
clap = { workspace = true, features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion bin/alphanet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

#[doc(hidden)]
fn main() {
reth::sigsegv_handler::install();
reth_cli_util::sigsegv_handler::install();

// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
Expand Down
1 change: 1 addition & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ alphanet-precompile.workspace = true
reth.workspace = true
reth-node-api.workspace = true
reth-node-optimism.workspace = true
reth-chainspec.workspace = true

eip3074-instructions.workspace = true

Expand Down
84 changes: 35 additions & 49 deletions crates/node/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
//! precompiles defined by [`alphanet_precompile`].

use alphanet_precompile::{bls12_381, secp256r1};
use eip3074_instructions::{
context::InstructionsContext, instructions as eip3074, BoxedInstructionWithOpCode,
};
use eip3074_instructions::{context::InstructionsContext, instructions as eip3074};
use reth::{
primitives::{
revm_primitives::{CfgEnvWithHandlerCfg, TxEnv},
Address, ChainSpec, Header, TransactionSigned, U256,
Address, Bytes, Header, TransactionSigned, U256,
},
revm::{
handler::register::EvmHandler,
inspector_handle_register,
interpreter::{opcode::InstructionTables, Host},
precompile::{PrecompileSpecId, PrecompileWithAddress, Precompiles},
Database, Evm, EvmBuilder, GetInspector,
handler::register::EvmHandler, inspector_handle_register, precompile::PrecompileSpecId,
primitives::Env, ContextPrecompiles, Database, Evm, EvmBuilder, GetInspector,
},
};
use reth_chainspec::ChainSpec;
use reth_node_api::{ConfigureEvm, ConfigureEvmEnv};
use reth_node_optimism::OptimismEvmConfig;
use std::sync::Arc;
Expand All @@ -36,32 +32,6 @@ use std::sync::Arc;
#[non_exhaustive]
pub struct AlphaNetEvmConfig;

/// Inserts the given precompiles with address in the context precompiles.
fn insert_precompiles<I>(precompiles: &mut Precompiles, precompiles_with_address: I)
where
I: Iterator<Item = PrecompileWithAddress>,
{
for precompile_with_address in precompiles_with_address {
precompiles.inner.insert(precompile_with_address.0, precompile_with_address.1);
}
}

/// Inserts the given boxed instructions with opcodes in the instructions table.
fn insert_boxed_instructions<'a, I, H>(
table: &mut InstructionTables<'a, H>,
boxed_instructions_with_opcodes: I,
) where
I: Iterator<Item = BoxedInstructionWithOpCode<'a, H>>,
H: Host + 'a,
{
for boxed_instruction_with_opcode in boxed_instructions_with_opcodes {
table.insert_boxed(
boxed_instruction_with_opcode.opcode,
boxed_instruction_with_opcode.boxed_instruction,
);
}
}

impl AlphaNetEvmConfig {
/// Sets the precompiles to the EVM handler
///
Expand All @@ -78,11 +48,13 @@ impl AlphaNetEvmConfig {

// install the precompiles
handler.pre_execution.load_precompiles = Arc::new(move || {
let mut precompiles = Precompiles::new(PrecompileSpecId::from_spec_id(spec_id)).clone();
insert_precompiles(&mut precompiles, secp256r1::precompiles());
insert_precompiles(&mut precompiles, bls12_381::precompiles());
let mut loaded_precompiles: ContextPrecompiles<DB> =
ContextPrecompiles::new(PrecompileSpecId::from_spec_id(spec_id));

loaded_precompiles.extend(secp256r1::precompiles());
loaded_precompiles.extend(bls12_381::precompiles());

precompiles.into()
loaded_precompiles
});
}

Expand All @@ -98,10 +70,12 @@ impl AlphaNetEvmConfig {
) where
DB: Database,
{
insert_boxed_instructions(
&mut handler.instruction_table,
eip3074::boxed_instructions(instructions_context.clone()),
);
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();
}
Expand Down Expand Up @@ -162,17 +136,28 @@ impl ConfigureEvm for AlphaNetEvmConfig {
}

impl ConfigureEvmEnv for AlphaNetEvmConfig {
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
OptimismEvmConfig::fill_tx_env(tx_env, transaction, sender)
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
OptimismEvmConfig::default().fill_tx_env(tx_env, transaction, sender)
}

fn fill_cfg_env(
&self,
cfg_env: &mut CfgEnvWithHandlerCfg,
chain_spec: &ChainSpec,
header: &Header,
total_difficulty: U256,
) {
OptimismEvmConfig::fill_cfg_env(cfg_env, chain_spec, header, total_difficulty);
OptimismEvmConfig::default().fill_cfg_env(cfg_env, chain_spec, header, total_difficulty);
}

fn fill_tx_env_system_contract_call(
&self,
env: &mut Env,
caller: Address,
contract: Address,
data: Bytes,
) {
OptimismEvmConfig::default().fill_tx_env_system_contract_call(env, caller, contract, data)
}
}

Expand All @@ -181,8 +166,9 @@ mod tests {
use super::*;
use reth::primitives::{
revm_primitives::{BlockEnv, CfgEnv, SpecId},
Chain, ChainSpecBuilder, ForkCondition, Genesis, Hardfork,
ForkCondition, Genesis, Hardfork,
};
use reth_chainspec::{Chain, ChainSpecBuilder, EthereumHardfork};

#[test]
fn test_fill_cfg_and_block_env() {
Expand All @@ -192,11 +178,11 @@ mod tests {
let chain_spec = ChainSpecBuilder::default()
.chain(Chain::optimism_mainnet())
.genesis(Genesis::default())
.with_fork(Hardfork::Frontier, ForkCondition::Block(0))
.with_fork(EthereumHardfork::Frontier, ForkCondition::Block(0))
.build();
let total_difficulty = U256::ZERO;

AlphaNetEvmConfig::fill_cfg_and_block_env(
AlphaNetEvmConfig::default().fill_cfg_and_block_env(
&mut cfg_env,
&mut block_env,
&chain_spec,
Expand Down
14 changes: 11 additions & 3 deletions crates/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use reth::builder::{
use reth_node_api::FullNodeTypes;
use reth_node_optimism::{
args::RollupArgs,
node::{OptimismNetworkBuilder, OptimismPayloadBuilder, OptimismPoolBuilder},
node::{
OptimismAddOns, OptimismConsensusBuilder, OptimismNetworkBuilder, OptimismPayloadBuilder,
OptimismPoolBuilder,
},
OpExecutorProvider, OptimismEngineTypes,
};

Expand All @@ -37,6 +40,7 @@ impl AlphaNetNode {
OptimismPayloadBuilder<AlphaNetEvmConfig>,
OptimismNetworkBuilder,
AlphaNetExecutorBuilder,
OptimismConsensusBuilder,
>
where
Node: FullNodeTypes<Engine = OptimismEngineTypes>,
Expand All @@ -51,6 +55,7 @@ impl AlphaNetNode {
))
.network(OptimismNetworkBuilder { disable_txpool_gossip })
.executor(AlphaNetExecutorBuilder::default())
.consensus(OptimismConsensusBuilder::default())
}
}

Expand All @@ -70,11 +75,14 @@ where
OptimismPayloadBuilder<AlphaNetEvmConfig>,
OptimismNetworkBuilder,
AlphaNetExecutorBuilder,
OptimismConsensusBuilder,
>;

fn components_builder(self) -> Self::ComponentsBuilder {
type AddOns = OptimismAddOns;

fn components_builder(&self) -> Self::ComponentsBuilder {
let Self { args } = self;
Self::components(args)
Self::components(args.clone())
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ p256 = { version = "0.13.2", features = ["ecdsa"] }

[dev-dependencies]
reth-node-api.workspace = true
reth-chainspec.workspace = true
eyre.workspace = true
rstest.workspace = true

Expand Down
46 changes: 28 additions & 18 deletions crates/precompile/src/secp256r1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
//! ```
//! use alphanet_precompile::secp256r1;
//! use reth::{
//! primitives::{ChainSpec, TransactionSigned, U256},
//! primitives::{TransactionSigned, U256},
//! revm::{
//! precompile::{PrecompileSpecId, Precompiles},
//! primitives::{Address, Bytes, CfgEnvWithHandlerCfg, TxEnv},
//! Database, Evm, EvmBuilder,
//! primitives::{Address, Bytes, CfgEnvWithHandlerCfg, Env, TxEnv},
//! ContextPrecompiles, Database, Evm, EvmBuilder,
//! },
//! };
//! use reth_chainspec::ChainSpec;
//! use reth_node_api::{ConfigureEvm, ConfigureEvmEnv};
//! use std::sync::Arc;
//!
Expand All @@ -34,39 +35,47 @@
//! .append_handler_register(|handler| {
//! let spec_id = handler.cfg.spec_id;
//! handler.pre_execution.load_precompiles = Arc::new(move || {
//! let mut precompiles =
//! Precompiles::new(PrecompileSpecId::from_spec_id(spec_id)).clone();
//! for precompile_with_address in secp256r1::precompiles() {
//! precompiles
//! .inner
//! .insert(precompile_with_address.0, precompile_with_address.1);
//! }
//! precompiles.into()
//! let mut loaded_precompiles: ContextPrecompiles<DB> =
//! ContextPrecompiles::new(PrecompileSpecId::from_spec_id(spec_id));
//! loaded_precompiles.extend(secp256r1::precompiles());
//!
//! loaded_precompiles
//! });
//! })
//! .build()
//! }
//! }
//!
//! impl ConfigureEvmEnv for AlphaNetEvmConfig {
//! fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
//! fn fill_tx_env(
//! &self,
//! tx_env: &mut TxEnv,
//! transaction: &TransactionSigned,
//! sender: Address,
//! ) {
//! todo!()
//! }
//! fn fill_cfg_env(
//! &self,
//! _: &mut CfgEnvWithHandlerCfg,
//! _: &ChainSpec,
//! _: &reth::primitives::Header,
//! _: U256,
//! ) {
//! todo!()
//! }
//! fn fill_tx_env_system_contract_call(&self, _: &mut Env, _: Address, _: Address, _: Bytes) {
//! todo!()
//! }
//! }
//! ```
use crate::addresses::P256VERIFY_ADDRESS;
use p256::ecdsa::{signature::hazmat::PrehashVerifier, Signature, VerifyingKey};
use reth::revm::{
precompile::{u64_to_address, Precompile, PrecompileWithAddress},
primitives::{Bytes, PrecompileError, PrecompileResult, B256},
primitives::{
Bytes, PrecompileError, PrecompileErrors, PrecompileOutput, PrecompileResult, B256,
},
};

/// Base gas fee for secp256r1 p256verify operation.
Expand All @@ -93,10 +102,11 @@ pub const P256VERIFY: PrecompileWithAddress =
/// | 32 | 32 | 32 | 32 | 32 |
fn p256_verify(input: &Bytes, gas_limit: u64) -> PrecompileResult {
if P256VERIFY_BASE > gas_limit {
return Err(PrecompileError::OutOfGas);
return Err(PrecompileErrors::Error(PrecompileError::OutOfGas));
}
let result = verify_impl(input).is_some();
Ok((P256VERIFY_BASE, B256::with_last_byte(result as u8).into()))
let out = PrecompileOutput::new(P256VERIFY_BASE, B256::with_last_byte(result as u8).into());
Ok(out)
}

/// Returns `Some(())` if the signature included in the input byte slice is
Expand Down Expand Up @@ -149,10 +159,10 @@ mod test {
fn test_sig_verify(#[case] input: &str, #[case] expect_success: bool) {
let input = Bytes::from_hex(input).unwrap();
let target_gas = 3_500u64;
let (gas_used, res) = p256_verify(&input, target_gas).unwrap();
let PrecompileOutput { gas_used, bytes } = p256_verify(&input, target_gas).unwrap();
assert_eq!(gas_used, 3_450u64);
let expected_result = B256::with_last_byte(expect_success as u8);
assert_eq!(res, expected_result.to_vec());
assert_eq!(bytes, expected_result.to_vec());
}

#[rstest]
Expand All @@ -162,7 +172,7 @@ mod test {
let result = p256_verify(&input, target_gas);

assert!(result.is_err());
assert_eq!(result.err(), Some(PrecompileError::OutOfGas));
assert_eq!(result.err(), Some(PrecompileErrors::Error(PrecompileError::OutOfGas)));
}

#[rstest]
Expand Down
Loading
Loading