Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 17 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ alloy-transport = "0.12.6"
alloy-trie = "0.7.9"

# Will remove [revm] with https://github.com/risechain/pevm/issues/382.
revm = { git = "https://github.com/risechain/revm", rev = "a79e833be41199a140dc85a222141c4bdf0b9aa5", features = [
"serde",
] }
revme = { git = "https://github.com/risechain/revm", rev = "a79e833be41199a140dc85a222141c4bdf0b9aa5" }
revm = { version = "19.4.0", features = ["serde"] }
revme = "2.4.0"

# OP
op-alloy-consensus = "0.11.3"
Expand Down
6 changes: 5 additions & 1 deletion crates/pevm/src/chain/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ impl PevmChain for PevmEthereum {
spec_id: SpecId,
with_reward_beneficiary: bool,
) -> Handler<'a, revm::Context<EXT, DB>, EXT, DB> {
Handler::mainnet_with_spec(spec_id, with_reward_beneficiary)
let mut handler = Handler::mainnet_with_spec(spec_id);
if !with_reward_beneficiary {
handler.post_execution.reward_beneficiary = std::sync::Arc::new(|_, _| Ok(()));
}
handler
}

fn get_reward_policy(&self) -> RewardPolicy {
Expand Down
6 changes: 5 additions & 1 deletion crates/pevm/src/chain/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ impl PevmChain for PevmOptimism {
spec_id: SpecId,
with_reward_beneficiary: bool,
) -> Handler<'a, revm::Context<EXT, DB>, EXT, DB> {
Handler::optimism_with_spec(spec_id, with_reward_beneficiary)
let mut handler = Handler::optimism_with_spec(spec_id);
if !with_reward_beneficiary {
handler.post_execution.reward_beneficiary = std::sync::Arc::new(|_, _| Ok(()));
}
handler
}

fn get_reward_policy(&self) -> RewardPolicy {
Expand Down
20 changes: 8 additions & 12 deletions crates/pevm/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ impl From<Bytecode> for EvmCode {
// This arm will recursively fallback to LegacyAnalyzed.
Bytecode::LegacyRaw(_) => to_analysed(code).into(),
Bytecode::LegacyAnalyzed(code) => Self::Legacy(LegacyCode {
bytecode: code.bytecode,
original_len: code.original_len,
jump_table: code.jump_table.0,
// We should be able to consume these instead of cloning if the
// fields are `pub`. Won't be relevant as we rewrite `revm` anyway.
bytecode: code.bytecode().clone(),
original_len: code.original_len(),
jump_table: code.jump_table().0.clone(),
}),
Bytecode::Eip7702(code) => Self::Eip7702(Eip7702Code {
delegated_address: code.delegated_address,
Expand Down Expand Up @@ -258,12 +260,6 @@ impl<S: Storage> DatabaseRef for StorageWrapper<'_, S> {
})
}

fn has_storage_ref(&self, address: Address) -> Result<bool, Self::Error> {
self.0
.has_storage(&address)
.map_err(StorageWrapperError::StorageError)
}

fn storage_ref(&self, address: Address, index: U256) -> Result<U256, Self::Error> {
self.0
.storage(&address, &index)
Expand Down Expand Up @@ -305,9 +301,9 @@ mod tests {
fn eq_bytecodes(revm_code: &Bytecode, pevm_code: &EvmCode) -> bool {
match (revm_code, pevm_code) {
(Bytecode::LegacyAnalyzed(revm), EvmCode::Legacy(pevm)) => {
revm.bytecode == pevm.bytecode
&& revm.original_len == pevm.original_len
&& revm.jump_table.0 == pevm.jump_table
revm.bytecode() == &pevm.bytecode
&& revm.original_len() == pevm.original_len
&& revm.jump_table().0 == pevm.jump_table
}
(Bytecode::Eip7702(revm), EvmCode::Eip7702(pevm)) => {
revm.delegated_address == pevm.delegated_address && revm.version == pevm.version
Expand Down
7 changes: 0 additions & 7 deletions crates/pevm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,6 @@ impl<S: Storage, C: PevmChain> Database for VmDb<'_, S, C> {
}
}

fn has_storage(&mut self, address: Address) -> Result<bool, Self::Error> {
self.vm
.storage
.has_storage(&address)
.map_err(|err| ReadError::StorageError(err.to_string()))
}

fn storage(&mut self, address: Address, index: U256) -> Result<U256, Self::Error> {
let location_hash = hash_deterministic(MemoryLocation::Storage(address, index));

Expand Down
25 changes: 22 additions & 3 deletions crates/pevm/tests/ethereum/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ use revm::primitives::InvalidTransaction;
use revm::primitives::ruint::ParseError;
use revm::primitives::{
AccountInfo, BlobExcessGasAndPrice, BlockEnv, Bytecode, KECCAK_EMPTY, SpecId, TransactTo,
TxEnv, U256, calc_excess_blob_gas,
TxEnv, calc_excess_blob_gas,
};
use revme::cmd::statetest::models::{Env, SpecName, Test, TestSuite, TestUnit, TransactionParts};
use revme::cmd::statetest::{
merkle_trie::{log_rlp_hash, state_merkle_trie_root},
utils::recover_address,
};
use std::path::Path;
use std::str::FromStr;
use std::sync::Arc;
use std::{fs, num::NonZeroUsize};
use walkdir::{DirEntry, WalkDir};
Expand Down Expand Up @@ -87,7 +86,7 @@ fn build_tx_env(path: &Path, tx: &TransactionParts, test: &Test) -> Result<TxEnv
Some(address) => TransactTo::Call(address),
None => TransactTo::Create,
},
value: U256::from_str(&tx.value[test.indexes.value])?,
value: tx.value[test.indexes.value],
data: tx.data[test.indexes.data].clone(),
nonce: Some(tx.nonce.saturating_to()),
chain_id: Some(1), // Ethereum mainnet
Expand Down Expand Up @@ -244,6 +243,26 @@ fn ethereum_state_tests() {
.filter_map(Result::ok)
.map(DirEntry::into_path)
.filter(|path| path.extension() == Some("json".as_ref()))
.filter(|path| {
// Skip tests `revm` cannot handle. We'll support these as we replace
// `revm` with our EVM implementation, or maybe migrate to newer state
// tests anyway.
!matches!(
path.file_name().unwrap().to_str().unwrap(),
"InitCollision.json"
| "InitCollisionParis.json"
| "create2collisionStorage.json"
| "create2collisionStorageParis.json"
| "dynamicAccountOverwriteEmpty_Paris.json"
| "RevertInCreateInInitCreate2.json"
| "dynamicAccountOverwriteEmpty.json"
| "RevertInCreateInInit.json"
| "RevertInCreateInInit_Paris.json"
| "RevertInCreateInInitCreate2Paris.json"
| "ValueOverflow.json"
| "ValueOverflowParis.json"
)
})
// For development, we can further filter to run a small set of tests,
// or filter out time-consuming tests like:
// - stTimeConsuming/**
Expand Down