mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
remove: Remove HlPrecompiles (not used)
This commit is contained in:
@ -1,10 +1,8 @@
|
|||||||
use super::precompiles::HlPrecompiles;
|
|
||||||
use revm::{
|
use revm::{
|
||||||
context::{ContextSetters, Evm as EvmCtx},
|
context::{ContextSetters, Evm as EvmCtx},
|
||||||
context_interface::ContextTr,
|
context_interface::ContextTr,
|
||||||
handler::{
|
handler::{
|
||||||
instructions::{EthInstructions, InstructionProvider},
|
instructions::{EthInstructions, InstructionProvider}, EthPrecompiles, EvmTr, PrecompileProvider
|
||||||
EvmTr, PrecompileProvider,
|
|
||||||
},
|
},
|
||||||
inspector::{InspectorEvmTr, JournalExt},
|
inspector::{InspectorEvmTr, JournalExt},
|
||||||
interpreter::{interpreter::EthInterpreter, Interpreter, InterpreterAction, InterpreterTypes},
|
interpreter::{interpreter::EthInterpreter, Interpreter, InterpreterAction, InterpreterTypes},
|
||||||
@ -15,19 +13,19 @@ pub mod builder;
|
|||||||
pub mod ctx;
|
pub mod ctx;
|
||||||
mod exec;
|
mod exec;
|
||||||
|
|
||||||
pub struct HlEvmInner<CTX, INSP, I = EthInstructions<EthInterpreter, CTX>, P = HlPrecompiles>(
|
pub struct HlEvmInner<CTX, INSP, I = EthInstructions<EthInterpreter, CTX>, P = EthPrecompiles>(
|
||||||
pub EvmCtx<CTX, INSP, I, P>,
|
pub EvmCtx<CTX, INSP, I, P>,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<CTX: ContextTr, INSP>
|
impl<CTX: ContextTr, INSP>
|
||||||
HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, HlPrecompiles>
|
HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, EthPrecompiles>
|
||||||
{
|
{
|
||||||
pub fn new(ctx: CTX, inspector: INSP) -> Self {
|
pub fn new(ctx: CTX, inspector: INSP) -> Self {
|
||||||
Self(EvmCtx {
|
Self(EvmCtx {
|
||||||
ctx,
|
ctx,
|
||||||
inspector,
|
inspector,
|
||||||
instruction: EthInstructions::new_mainnet(),
|
instruction: EthInstructions::new_mainnet(),
|
||||||
precompiles: HlPrecompiles::default(),
|
precompiles: EthPrecompiles::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
mod handler;
|
mod handler;
|
||||||
pub mod precompiles;
|
|
||||||
pub mod spec;
|
pub mod spec;
|
||||||
pub mod transaction;
|
pub mod transaction;
|
||||||
|
|||||||
@ -1,146 +0,0 @@
|
|||||||
#![allow(unused)]
|
|
||||||
|
|
||||||
use crate::node::types::ReadPrecompileResult;
|
|
||||||
use crate::node::types::{ReadPrecompileInput, ReadPrecompileMap};
|
|
||||||
use revm::interpreter::{Gas, InstructionResult};
|
|
||||||
use revm::precompile::PrecompileError;
|
|
||||||
use revm::precompile::PrecompileOutput;
|
|
||||||
use revm::primitives::Bytes;
|
|
||||||
|
|
||||||
use super::spec::HlSpecId;
|
|
||||||
use cfg_if::cfg_if;
|
|
||||||
use once_cell::{race::OnceBox, sync::Lazy};
|
|
||||||
use revm::{
|
|
||||||
context::Cfg,
|
|
||||||
context_interface::ContextTr,
|
|
||||||
handler::{EthPrecompiles, PrecompileProvider},
|
|
||||||
interpreter::{InputsImpl, InterpreterResult},
|
|
||||||
precompile::{bls12_381, kzg_point_evaluation, modexp, secp256r1, Precompiles},
|
|
||||||
primitives::{hardfork::SpecId, Address},
|
|
||||||
};
|
|
||||||
use std::boxed::Box;
|
|
||||||
|
|
||||||
// HL precompile provider
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct HlPrecompiles {
|
|
||||||
/// Inner precompile provider is same as Ethereums.
|
|
||||||
inner: EthPrecompiles,
|
|
||||||
/// Precompile calls
|
|
||||||
precompile_calls: ReadPrecompileMap,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HlPrecompiles {
|
|
||||||
/// Create a new precompile provider with the given hl spec.
|
|
||||||
#[inline]
|
|
||||||
pub fn new(spec: HlSpecId, precompile_calls: ReadPrecompileMap) -> Self {
|
|
||||||
let precompiles = cancun();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
inner: EthPrecompiles {
|
|
||||||
precompiles,
|
|
||||||
spec: spec.into_eth_spec(),
|
|
||||||
},
|
|
||||||
precompile_calls,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn precompiles(&self) -> &'static Precompiles {
|
|
||||||
self.inner.precompiles
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns precompiles for Istanbul spec.
|
|
||||||
pub fn cancun() -> &'static Precompiles {
|
|
||||||
static INSTANCE: OnceBox<Precompiles> = OnceBox::new();
|
|
||||||
INSTANCE.get_or_init(|| {
|
|
||||||
let mut precompiles = Precompiles::cancun().clone();
|
|
||||||
// precompiles.extend([tendermint::TENDERMINT_HEADER_VALIDATION, iavl::IAVL_PROOF_VALIDATION]);
|
|
||||||
Box::new(precompiles)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTX> PrecompileProvider<CTX> for HlPrecompiles
|
|
||||||
where
|
|
||||||
CTX: ContextTr<Cfg: Cfg<Spec = HlSpecId>>,
|
|
||||||
{
|
|
||||||
type Output = InterpreterResult;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_spec(&mut self, spec: <CTX::Cfg as Cfg>::Spec) -> bool {
|
|
||||||
*self = Self::new(spec, self.precompile_calls.clone());
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn run(
|
|
||||||
&mut self,
|
|
||||||
context: &mut CTX,
|
|
||||||
address: &Address,
|
|
||||||
inputs: &InputsImpl,
|
|
||||||
is_static: bool,
|
|
||||||
gas_limit: u64,
|
|
||||||
) -> Result<Option<Self::Output>, String> {
|
|
||||||
let Some(precompile_calls) = self.precompile_calls.get(address) else {
|
|
||||||
return self
|
|
||||||
.inner
|
|
||||||
.run(context, address, inputs, is_static, gas_limit);
|
|
||||||
};
|
|
||||||
|
|
||||||
let input = ReadPrecompileInput {
|
|
||||||
input: inputs.input.bytes(context),
|
|
||||||
gas_limit,
|
|
||||||
};
|
|
||||||
let mut result = InterpreterResult {
|
|
||||||
result: InstructionResult::Return,
|
|
||||||
gas: Gas::new(gas_limit),
|
|
||||||
output: Bytes::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let Some(get) = precompile_calls.get(&input) else {
|
|
||||||
result.gas.spend_all();
|
|
||||||
result.result = InstructionResult::PrecompileError;
|
|
||||||
return Ok(Some(result));
|
|
||||||
};
|
|
||||||
|
|
||||||
return match *get {
|
|
||||||
ReadPrecompileResult::Ok {
|
|
||||||
gas_used,
|
|
||||||
ref bytes,
|
|
||||||
} => {
|
|
||||||
let underflow = result.gas.record_cost(gas_used);
|
|
||||||
assert!(underflow, "Gas underflow is not possible");
|
|
||||||
result.output = bytes.clone();
|
|
||||||
Ok(Some(result))
|
|
||||||
}
|
|
||||||
ReadPrecompileResult::OutOfGas => {
|
|
||||||
// Use all the gas passed to this precompile
|
|
||||||
result.gas.spend_all();
|
|
||||||
result.result = InstructionResult::OutOfGas;
|
|
||||||
Ok(Some(result))
|
|
||||||
}
|
|
||||||
ReadPrecompileResult::Error => {
|
|
||||||
result.gas.spend_all();
|
|
||||||
result.result = InstructionResult::PrecompileError;
|
|
||||||
Ok(Some(result))
|
|
||||||
}
|
|
||||||
ReadPrecompileResult::UnexpectedError => panic!("unexpected precompile error"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn warm_addresses(&self) -> Box<impl Iterator<Item = Address>> {
|
|
||||||
self.inner.warm_addresses()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn contains(&self, address: &Address) -> bool {
|
|
||||||
self.inner.contains(address)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for HlPrecompiles {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new(HlSpecId::default(), ReadPrecompileMap::default())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,11 +5,9 @@ use crate::{
|
|||||||
builder::HlBuilder,
|
builder::HlBuilder,
|
||||||
ctx::{DefaultHl, HlContext},
|
ctx::{DefaultHl, HlContext},
|
||||||
},
|
},
|
||||||
precompiles::HlPrecompiles,
|
|
||||||
spec::HlSpecId,
|
spec::HlSpecId,
|
||||||
transaction::HlTxEnv,
|
transaction::HlTxEnv,
|
||||||
},
|
},
|
||||||
node::types::ReadPrecompileMap,
|
|
||||||
};
|
};
|
||||||
use reth_evm::{precompiles::PrecompilesMap, EvmEnv, EvmFactory};
|
use reth_evm::{precompiles::PrecompilesMap, EvmEnv, EvmFactory};
|
||||||
use reth_revm::{Context, Database};
|
use reth_revm::{Context, Database};
|
||||||
@ -18,6 +16,7 @@ use revm::{
|
|||||||
result::{EVMError, HaltReason},
|
result::{EVMError, HaltReason},
|
||||||
TxEnv,
|
TxEnv,
|
||||||
},
|
},
|
||||||
|
handler::EthPrecompiles,
|
||||||
inspector::NoOpInspector,
|
inspector::NoOpInspector,
|
||||||
Inspector,
|
Inspector,
|
||||||
};
|
};
|
||||||
@ -42,15 +41,15 @@ impl EvmFactory for HlEvmFactory {
|
|||||||
db: DB,
|
db: DB,
|
||||||
input: EvmEnv<HlSpecId>,
|
input: EvmEnv<HlSpecId>,
|
||||||
) -> Self::Evm<DB, NoOpInspector> {
|
) -> Self::Evm<DB, NoOpInspector> {
|
||||||
let precompiles =
|
|
||||||
HlPrecompiles::new(input.cfg_env.spec, ReadPrecompileMap::default()).precompiles();
|
|
||||||
HlEvm {
|
HlEvm {
|
||||||
inner: Context::hl()
|
inner: Context::hl()
|
||||||
.with_block(input.block_env)
|
.with_block(input.block_env)
|
||||||
.with_cfg(input.cfg_env)
|
.with_cfg(input.cfg_env)
|
||||||
.with_db(db)
|
.with_db(db)
|
||||||
.build_hl_with_inspector(NoOpInspector {})
|
.build_hl_with_inspector(NoOpInspector {})
|
||||||
.with_precompiles(PrecompilesMap::from_static(precompiles)),
|
.with_precompiles(PrecompilesMap::from_static(
|
||||||
|
EthPrecompiles::default().precompiles,
|
||||||
|
)),
|
||||||
inspect: false,
|
inspect: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,15 +63,15 @@ impl EvmFactory for HlEvmFactory {
|
|||||||
input: EvmEnv<HlSpecId>,
|
input: EvmEnv<HlSpecId>,
|
||||||
inspector: I,
|
inspector: I,
|
||||||
) -> Self::Evm<DB, I> {
|
) -> Self::Evm<DB, I> {
|
||||||
let precompiles =
|
|
||||||
HlPrecompiles::new(input.cfg_env.spec, ReadPrecompileMap::default()).precompiles();
|
|
||||||
HlEvm {
|
HlEvm {
|
||||||
inner: Context::hl()
|
inner: Context::hl()
|
||||||
.with_block(input.block_env)
|
.with_block(input.block_env)
|
||||||
.with_cfg(input.cfg_env)
|
.with_cfg(input.cfg_env)
|
||||||
.with_db(db)
|
.with_db(db)
|
||||||
.build_hl_with_inspector(inspector)
|
.build_hl_with_inspector(inspector)
|
||||||
.with_precompiles(PrecompilesMap::from_static(precompiles)),
|
.with_precompiles(PrecompilesMap::from_static(
|
||||||
|
EthPrecompiles::default().precompiles,
|
||||||
|
)),
|
||||||
inspect: true,
|
inspect: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
evm::{
|
evm::{
|
||||||
api::{ctx::HlContext, HlEvmInner},
|
api::{ctx::HlContext, HlEvmInner},
|
||||||
precompiles::HlPrecompiles,
|
|
||||||
spec::HlSpecId,
|
spec::HlSpecId,
|
||||||
transaction::{HlTxEnv, HlTxTr},
|
transaction::{HlTxEnv, HlTxTr},
|
||||||
},
|
},
|
||||||
@ -19,7 +18,7 @@ use revm::{
|
|||||||
result::{EVMError, HaltReason, ResultAndState},
|
result::{EVMError, HaltReason, ResultAndState},
|
||||||
BlockEnv, TxEnv,
|
BlockEnv, TxEnv,
|
||||||
},
|
},
|
||||||
handler::{instructions::EthInstructions, PrecompileProvider},
|
handler::{instructions::EthInstructions, EthPrecompiles, PrecompileProvider},
|
||||||
interpreter::{interpreter::EthInterpreter, InterpreterResult},
|
interpreter::{interpreter::EthInterpreter, InterpreterResult},
|
||||||
Context, Database, ExecuteEvm, InspectEvm, Inspector,
|
Context, Database, ExecuteEvm, InspectEvm, Inspector,
|
||||||
};
|
};
|
||||||
@ -36,7 +35,7 @@ mod patch;
|
|||||||
/// This is a wrapper type around the `revm` evm with optional [`Inspector`] (tracing)
|
/// This is a wrapper type around the `revm` evm with optional [`Inspector`] (tracing)
|
||||||
/// support. [`Inspector`] support is configurable at runtime because it's part of the underlying
|
/// support. [`Inspector`] support is configurable at runtime because it's part of the underlying
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct HlEvm<DB: Database, I, P = HlPrecompiles> {
|
pub struct HlEvm<DB: Database, I, P = EthPrecompiles> {
|
||||||
pub inner: HlEvmInner<HlContext<DB>, I, EthInstructions<EthInterpreter, HlContext<DB>>, P>,
|
pub inner: HlEvmInner<HlContext<DB>, I, EthInstructions<EthInterpreter, HlContext<DB>>, P>,
|
||||||
pub inspect: bool,
|
pub inspect: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user