Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: init4tech/trevm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.20.9
Choose a base ref
...
head repository: init4tech/trevm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.20.10
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Apr 14, 2025

  1. feat: object safety for fillers

    prestwich committed Apr 14, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3dba391 View commit details
Showing with 57 additions and 4 deletions.
  1. +1 −1 Cargo.toml
  2. +56 −3 src/fill/traits.rs
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trevm"
version = "0.20.9"
version = "0.20.10"
rust-version = "1.83.0"
edition = "2021"
authors = ["init4"]
59 changes: 56 additions & 3 deletions src/fill/traits.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ use revm::{
context::{BlockEnv, CfgEnv, Evm, TxEnv},
Database,
};
use std::sync::Arc;

/// Types that can fill the EVM transaction environment [`TxEnv`].
pub trait Tx: Send + Sync {
@@ -18,11 +19,26 @@ pub trait Tx: Send + Sync {
fn fill_tx_env(&self, tx_env: &mut TxEnv);

/// Fill the transaction environment on the EVM.
fn fill_tx<Db: Database, Insp, Inst, Prec>(&self, evm: &mut Evm<Ctx<Db>, Insp, Inst, Prec>) {
fn fill_tx<Db: Database, Insp, Inst, Prec>(&self, evm: &mut Evm<Ctx<Db>, Insp, Inst, Prec>)
where
Self: Sized,
{
evm.data.ctx.modify_tx(|tx_env| self.fill_tx_env(tx_env));
}
}

impl Tx for Arc<dyn Tx> {
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
self.as_ref().fill_tx_env(tx_env);
}
}

impl Tx for Box<dyn Tx> {
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
self.as_ref().fill_tx_env(tx_env);
}
}

impl<T> Tx for T
where
T: Fn(&mut TxEnv) + Send + Sync,
@@ -45,7 +61,10 @@ pub trait Block: Send + Sync {
fn fill_block_env(&self, block_env: &mut BlockEnv);

/// Fill the block environment on the EVM.
fn fill_block<Db: Database, Insp, Inst, Prec>(&self, evm: &mut Evm<Ctx<Db>, Insp, Inst, Prec>) {
fn fill_block<Db: Database, Insp, Inst, Prec>(&self, evm: &mut Evm<Ctx<Db>, Insp, Inst, Prec>)
where
Self: Sized,
{
evm.data.ctx.modify_block(|block_env| self.fill_block_env(block_env));
}

@@ -65,6 +84,18 @@ where
}
}

impl Block for Arc<dyn Block> {
fn fill_block_env(&self, block_env: &mut BlockEnv) {
self.as_ref().fill_block_env(block_env);
}
}

impl Block for Box<dyn Block> {
fn fill_block_env(&self, block_env: &mut BlockEnv) {
self.as_ref().fill_block_env(block_env);
}
}

/// Types that can fill the EVM configuration environment [`CfgEnv`].
///
/// Because the CFG env has quite a few conditionally compiled properties, it
@@ -87,11 +118,26 @@ pub trait Cfg: Send + Sync {
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv);

/// Fill the configuration environment on the EVM.
fn fill_cfg<Db: Database, Insp, Inst, Prec>(&self, evm: &mut Evm<Ctx<Db>, Insp, Inst, Prec>) {
fn fill_cfg<Db: Database, Insp, Inst, Prec>(&self, evm: &mut Evm<Ctx<Db>, Insp, Inst, Prec>)
where
Self: Sized,
{
evm.data.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env));
}
}

impl Cfg for Arc<dyn Cfg> {
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv) {
self.as_ref().fill_cfg_env(cfg_env);
}
}

impl Cfg for Box<dyn Cfg> {
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv) {
self.as_ref().fill_cfg_env(cfg_env);
}
}

impl<T> Cfg for T
where
T: Fn(&mut CfgEnv) + Send + Sync,
@@ -114,6 +160,13 @@ mod test {

use super::*;

#[allow(dead_code)]
fn object_safety(cfg: Box<dyn Cfg>, block: Box<dyn Block>, tx: Box<dyn Tx>) {
crate::test_utils::test_trevm().fill_cfg(&cfg).fill_block(&block).fill_tx(&tx);

unimplemented!("compilation check only")
}

impl Block for () {
fn fill_block_env(&self, block_env: &mut BlockEnv) {
let BlockEnv {