Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(inspector): add value parameter to Inspector::selfdestruct #645

Merged
merged 1 commit into from
Aug 25, 2023
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
8 changes: 5 additions & 3 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>
},
SuccessOrHalt::Halt(reason) => ExecutionResult::Halt { reason, gas_used },
SuccessOrHalt::FatalExternalError => {
return Err(EVMError::Database(self.data.error.take().unwrap()))
return Err(EVMError::Database(self.data.error.take().unwrap()));
}
SuccessOrHalt::InternalContinue => {
panic!("Internal return flags should remain internal {exit_reason:?}")
Expand Down Expand Up @@ -393,7 +393,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
created_address: None,
gas,
return_value: Bytes::new(),
})
});
}
};

Expand Down Expand Up @@ -825,7 +825,9 @@ impl<'a, GSPEC: Spec, DB: Database + 'a, const INSPECT: bool> Host

fn selfdestruct(&mut self, address: B160, target: B160) -> Option<SelfDestructResult> {
if INSPECT {
self.inspector.selfdestruct(address, target);
let acc = self.data.journaled_state.state.get(&address).unwrap();
self.inspector
.selfdestruct(address, target, acc.info.balance);
}
self.data
.journaled_state
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/inspector.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::evm_impl::EVMData;
use crate::interpreter::{CallInputs, CreateInputs, Gas, InstructionResult, Interpreter};
use crate::primitives::{db::Database, Bytes, B160, B256};
use crate::primitives::{db::Database, Bytes, B160, B256, U256};

use auto_impl::auto_impl;

Expand Down Expand Up @@ -136,5 +136,5 @@ pub trait Inspector<DB: Database> {
}

/// Called when a contract has been self-destructed with funds transferred to target.
fn selfdestruct(&mut self, _contract: B160, _target: B160) {}
fn selfdestruct(&mut self, _contract: B160, _target: B160, _value: U256) {}
}
11 changes: 7 additions & 4 deletions crates/revm/src/inspector/customprinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! It is a great tool if some debugging is needed.
//!
use crate::interpreter::{opcode, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter};
use crate::primitives::{hex, Bytes, B160};
use crate::primitives::{hex, Bytes, B160, U256};
use crate::{inspectors::GasInspector, Database, EVMData, Inspector};
#[derive(Clone, Default)]
pub struct CustomPrintTracer {
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<DB: Database> Inspector<DB> for CustomPrintTracer {
inputs: &mut CallInputs,
) -> (InstructionResult, Gas, Bytes) {
println!(
"SM CALL: {:?},context:{:?}, is_static:{:?}, transfer:{:?}, input_size:{:?}",
"SM CALL: {:?}, context:{:?}, is_static:{:?}, transfer:{:?}, input_size:{:?}",
inputs.contract,
inputs.context,
inputs.is_static,
Expand All @@ -115,8 +115,11 @@ impl<DB: Database> Inspector<DB> for CustomPrintTracer {
(InstructionResult::Continue, None, Gas::new(0), Bytes::new())
}

fn selfdestruct(&mut self, contract: B160, target: B160) {
println!("SELFDESTRUCT on {contract:?} refund target: {target:?}");
fn selfdestruct(&mut self, contract: B160, target: B160, value: U256) {
println!(
"SELFDESTRUCT: contract: {:?}, refund target: {:?}, value {:?}",
contract, target, value
);
}
}

Expand Down