mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: alloy-evm and new revm integration (#14021)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> Co-authored-by: rakita <rakita@users.noreply.github.com>
This commit is contained in:
@ -19,10 +19,12 @@ reth-codecs = { workspace = true, optional = true }
|
||||
alloy-consensus.workspace = true
|
||||
alloy-eips.workspace = true
|
||||
alloy-genesis.workspace = true
|
||||
alloy-primitives.workspace = true
|
||||
alloy-primitives = { workspace = true, features = ["k256"] }
|
||||
alloy-rlp.workspace = true
|
||||
alloy-trie.workspace = true
|
||||
revm-primitives.workspace = true
|
||||
revm-bytecode.workspace = true
|
||||
revm-state.workspace = true
|
||||
|
||||
# op
|
||||
op-alloy-consensus = { workspace = true, optional = true }
|
||||
@ -90,6 +92,8 @@ std = [
|
||||
"op-alloy-consensus?/std",
|
||||
"serde_json/std",
|
||||
"reth-chainspec/std",
|
||||
"revm-bytecode/std",
|
||||
"revm-state/std",
|
||||
]
|
||||
secp256k1 = ["dep:secp256k1"]
|
||||
test-utils = [
|
||||
@ -134,6 +138,8 @@ serde = [
|
||||
"k256/serde",
|
||||
"secp256k1?/serde",
|
||||
"alloy-trie/serde",
|
||||
"revm-bytecode/serde",
|
||||
"revm-state/serde",
|
||||
]
|
||||
reth-codec = [
|
||||
"dep:reth-codecs",
|
||||
|
||||
@ -3,24 +3,25 @@ use alloy_genesis::GenesisAccount;
|
||||
use alloy_primitives::{keccak256, Bytes, B256, U256};
|
||||
use alloy_trie::TrieAccount;
|
||||
use derive_more::Deref;
|
||||
use revm_primitives::{AccountInfo, Bytecode as RevmBytecode, BytecodeDecodeError};
|
||||
use revm_bytecode::{Bytecode as RevmBytecode, BytecodeDecodeError};
|
||||
use revm_state::AccountInfo;
|
||||
|
||||
#[cfg(any(test, feature = "reth-codec"))]
|
||||
/// Identifiers used in [`Compact`](reth_codecs::Compact) encoding of [`Bytecode`].
|
||||
pub mod compact_ids {
|
||||
/// Identifier for [`LegacyRaw`](revm_primitives::Bytecode::LegacyRaw).
|
||||
/// Identifier for legacy raw bytecode.
|
||||
pub const LEGACY_RAW_BYTECODE_ID: u8 = 0;
|
||||
|
||||
/// Identifier for removed bytecode variant.
|
||||
pub const REMOVED_BYTECODE_ID: u8 = 1;
|
||||
|
||||
/// Identifier for [`LegacyAnalyzed`](revm_primitives::Bytecode::LegacyAnalyzed).
|
||||
/// Identifier for [`LegacyAnalyzed`](revm_bytecode::Bytecode::LegacyAnalyzed).
|
||||
pub const LEGACY_ANALYZED_BYTECODE_ID: u8 = 2;
|
||||
|
||||
/// Identifier for [`Eof`](revm_primitives::Bytecode::Eof).
|
||||
/// Identifier for [`Eof`](revm_bytecode::Bytecode::Eof).
|
||||
pub const EOF_BYTECODE_ID: u8 = 3;
|
||||
|
||||
/// Identifier for [`Eip7702`](revm_primitives::Bytecode::Eip7702).
|
||||
/// Identifier for [`Eip7702`](revm_bytecode::Bytecode::Eip7702).
|
||||
pub const EIP7702_BYTECODE_ID: u8 = 4;
|
||||
}
|
||||
|
||||
@ -90,7 +91,7 @@ impl Bytecode {
|
||||
Self(RevmBytecode::new_raw(bytes))
|
||||
}
|
||||
|
||||
/// Creates a new raw [`revm_primitives::Bytecode`].
|
||||
/// Creates a new raw [`revm_bytecode::Bytecode`].
|
||||
///
|
||||
/// Returns an error on incorrect Bytecode format.
|
||||
#[inline]
|
||||
@ -105,13 +106,9 @@ impl reth_codecs::Compact for Bytecode {
|
||||
where
|
||||
B: bytes::BufMut + AsMut<[u8]>,
|
||||
{
|
||||
use compact_ids::{
|
||||
EIP7702_BYTECODE_ID, EOF_BYTECODE_ID, LEGACY_ANALYZED_BYTECODE_ID,
|
||||
LEGACY_RAW_BYTECODE_ID,
|
||||
};
|
||||
use compact_ids::{EIP7702_BYTECODE_ID, EOF_BYTECODE_ID, LEGACY_ANALYZED_BYTECODE_ID};
|
||||
|
||||
let bytecode = match &self.0 {
|
||||
RevmBytecode::LegacyRaw(bytes) => bytes,
|
||||
RevmBytecode::LegacyAnalyzed(analyzed) => analyzed.bytecode(),
|
||||
RevmBytecode::Eof(eof) => eof.raw(),
|
||||
RevmBytecode::Eip7702(eip7702) => eip7702.raw(),
|
||||
@ -119,10 +116,6 @@ impl reth_codecs::Compact for Bytecode {
|
||||
buf.put_u32(bytecode.len() as u32);
|
||||
buf.put_slice(bytecode.as_ref());
|
||||
let len = match &self.0 {
|
||||
RevmBytecode::LegacyRaw(_) => {
|
||||
buf.put_u8(LEGACY_RAW_BYTECODE_ID);
|
||||
1
|
||||
}
|
||||
// [`REMOVED_BYTECODE_ID`] has been removed.
|
||||
RevmBytecode::LegacyAnalyzed(analyzed) => {
|
||||
buf.put_u8(LEGACY_ANALYZED_BYTECODE_ID);
|
||||
@ -165,7 +158,7 @@ impl reth_codecs::Compact for Bytecode {
|
||||
RevmBytecode::new_analyzed(
|
||||
bytes,
|
||||
buf.read_u64::<byteorder::BigEndian>().unwrap() as usize,
|
||||
revm_primitives::JumpTable::from_slice(buf),
|
||||
revm_bytecode::JumpTable::from_slice(buf),
|
||||
)
|
||||
}),
|
||||
EOF_BYTECODE_ID | EIP7702_BYTECODE_ID => {
|
||||
@ -221,11 +214,10 @@ impl From<Account> for AccountInfo {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use alloy_primitives::{hex_literal::hex, B256, U256};
|
||||
use reth_codecs::Compact;
|
||||
use revm_primitives::{JumpTable, LegacyAnalyzedBytecode};
|
||||
|
||||
use super::*;
|
||||
use revm_bytecode::{JumpTable, LegacyAnalyzedBytecode};
|
||||
|
||||
#[test]
|
||||
fn test_account() {
|
||||
@ -273,12 +265,12 @@ mod tests {
|
||||
let mut buf = vec![];
|
||||
let bytecode = Bytecode::new_raw(Bytes::default());
|
||||
let len = bytecode.to_compact(&mut buf);
|
||||
assert_eq!(len, 5);
|
||||
assert_eq!(len, 46);
|
||||
|
||||
let mut buf = vec![];
|
||||
let bytecode = Bytecode::new_raw(Bytes::from(&hex!("ffff")));
|
||||
let len = bytecode.to_compact(&mut buf);
|
||||
assert_eq!(len, 7);
|
||||
assert_eq!(len, 49);
|
||||
|
||||
let mut buf = vec![];
|
||||
let bytecode = Bytecode(RevmBytecode::LegacyAnalyzed(LegacyAnalyzedBytecode::new(
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
//! Abstraction of an executable transaction.
|
||||
|
||||
use alloy_primitives::Address;
|
||||
use revm_primitives::TxEnv;
|
||||
|
||||
/// Loads transaction into execution environment.
|
||||
pub trait FillTxEnv {
|
||||
/// Fills [`TxEnv`] with an [`Address`] and transaction.
|
||||
pub trait FillTxEnv<TxEnv> {
|
||||
/// Fills `TxEnv` with an [`Address`] and transaction.
|
||||
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address);
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::{
|
||||
crypto::secp256k1::{recover_signer, recover_signer_unchecked},
|
||||
FillTxEnv, InMemorySize, MaybeCompact, MaybeSerde, MaybeSerdeBincodeCompat,
|
||||
InMemorySize, MaybeCompact, MaybeSerde, MaybeSerdeBincodeCompat,
|
||||
};
|
||||
use alloc::{fmt, vec::Vec};
|
||||
use alloy_consensus::{
|
||||
@ -14,15 +14,8 @@ use alloy_primitives::{keccak256, Address, PrimitiveSignature as Signature, TxHa
|
||||
use core::hash::Hash;
|
||||
|
||||
/// Helper trait that unifies all behaviour required by block to support full node operations.
|
||||
pub trait FullSignedTx:
|
||||
SignedTransaction + FillTxEnv + MaybeCompact + MaybeSerdeBincodeCompat
|
||||
{
|
||||
}
|
||||
|
||||
impl<T> FullSignedTx for T where
|
||||
T: SignedTransaction + FillTxEnv + MaybeCompact + MaybeSerdeBincodeCompat
|
||||
{
|
||||
}
|
||||
pub trait FullSignedTx: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {}
|
||||
impl<T> FullSignedTx for T where T: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {}
|
||||
|
||||
/// A signed transaction.
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
|
||||
Reference in New Issue
Block a user