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
36 changes: 36 additions & 0 deletions crates/evm2/src/evm/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,24 @@ mod tests {
drop(evm.transact_async_send(&tx));
}

#[test]
#[should_panic = "async EVM execution requires EVM erased fields to be verified as Send with Evm::evm_is_send"]
fn transaction_async_send_panics_after_state_mut_replaces_database() {
let marker = Rc::new(());
let mut evm = Evm::<BaseEvmTypes>::new(
SpecId::OSAKA,
BlockEnvExt::default(),
TxRegistry::new(),
InMemoryDB::default(),
Precompiles::base(SpecId::OSAKA),
);
evm.evm_is_send::<InMemoryDB, Precompiles<BaseEvmTypes>>();
evm.state_mut().set_initial(Db::new(NonSendDb { marker }));
let tx = test_tx(41);

drop(evm.transact_async_send(&tx));
}

#[test]
fn transaction_async_accepts_non_send_erased_fields() {
let marker = Rc::new(());
Expand Down Expand Up @@ -902,6 +920,24 @@ mod tests {
assert_eq!(result.tx_gas_used(), 0);
}

#[test]
#[should_panic = "async EVM execution requires EVM erased fields to be verified as Send with Evm::evm_is_send"]
fn system_call_async_send_panics_after_overlay_db_mut_replaces_database() {
let marker = Rc::new(());
let contract = Address::from([0x42; 20]);
let mut evm = Evm::<BaseEvmTypes>::new(
SpecId::OSAKA,
BlockEnvExt::default(),
TxRegistry::new(),
InMemoryDB::default(),
Precompiles::base(SpecId::OSAKA),
);
evm.evm_is_send::<InMemoryDB, Precompiles<BaseEvmTypes>>();
evm.overlay_db_mut().db = Box::new(Db::new(NonSendDb { marker }));

drop(evm.system_call_async_send(SystemTx::new(contract, Bytes::new())));
}

#[test]
fn system_call_async_clears_stale_error_code() {
let contract = Address::from([0x42; 20]);
Expand Down
2 changes: 2 additions & 0 deletions crates/evm2/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ impl<'a, T: EvmTypes> Evm<'a, T> {
/// available through [`Self::database_mut`].
#[inline]
pub fn overlay_db_mut(&mut self) -> &mut CacheDB<Box<dyn DynDatabase + 'a>> {
self.evm_send = false;
self.state.overlay_db_mut()
}

Expand Down Expand Up @@ -747,6 +748,7 @@ impl<'a, T: EvmTypes> Evm<'a, T> {
/// Returns the mutable EVM state.
#[inline]
pub const fn state_mut(&mut self) -> &mut State<'a> {
self.evm_send = false;
&mut self.state
}

Expand Down
Loading