Skip to content

Commit ff5a2bc

Browse files
authored
add value parameter to Inspector::selfdestruct (#645)
1 parent b2d6f7a commit ff5a2bc

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

crates/revm/src/evm_impl.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>
236236
},
237237
SuccessOrHalt::Halt(reason) => ExecutionResult::Halt { reason, gas_used },
238238
SuccessOrHalt::FatalExternalError => {
239-
return Err(EVMError::Database(self.data.error.take().unwrap()))
239+
return Err(EVMError::Database(self.data.error.take().unwrap()));
240240
}
241241
SuccessOrHalt::InternalContinue => {
242242
panic!("Internal return flags should remain internal {exit_reason:?}")
@@ -422,7 +422,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
422422
created_address: None,
423423
gas,
424424
return_value: Bytes::new(),
425-
})
425+
});
426426
}
427427
};
428428

@@ -854,7 +854,9 @@ impl<'a, GSPEC: Spec, DB: Database + 'a, const INSPECT: bool> Host
854854

855855
fn selfdestruct(&mut self, address: B160, target: B160) -> Option<SelfDestructResult> {
856856
if INSPECT {
857-
self.inspector.selfdestruct(address, target);
857+
let acc = self.data.journaled_state.state.get(&address).unwrap();
858+
self.inspector
859+
.selfdestruct(address, target, acc.info.balance);
858860
}
859861
self.data
860862
.journaled_state

crates/revm/src/inspector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::evm_impl::EVMData;
22
use crate::interpreter::{CallInputs, CreateInputs, Gas, InstructionResult, Interpreter};
3-
use crate::primitives::{db::Database, Bytes, B160, B256};
3+
use crate::primitives::{db::Database, Bytes, B160, B256, U256};
44

55
use auto_impl::auto_impl;
66

@@ -136,5 +136,5 @@ pub trait Inspector<DB: Database> {
136136
}
137137

138138
/// Called when a contract has been self-destructed with funds transferred to target.
139-
fn selfdestruct(&mut self, _contract: B160, _target: B160) {}
139+
fn selfdestruct(&mut self, _contract: B160, _target: B160, _value: U256) {}
140140
}

crates/revm/src/inspector/customprinter.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! It is a great tool if some debugging is needed.
33
//!
44
use crate::interpreter::{opcode, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter};
5-
use crate::primitives::{hex, Bytes, B160};
5+
use crate::primitives::{hex, Bytes, B160, U256};
66
use crate::{inspectors::GasInspector, Database, EVMData, Inspector};
77
#[derive(Clone, Default)]
88
pub struct CustomPrintTracer {
@@ -89,7 +89,7 @@ impl<DB: Database> Inspector<DB> for CustomPrintTracer {
8989
inputs: &mut CallInputs,
9090
) -> (InstructionResult, Gas, Bytes) {
9191
println!(
92-
"SM CALL: {:?},context:{:?}, is_static:{:?}, transfer:{:?}, input_size:{:?}",
92+
"SM CALL: {:?}, context:{:?}, is_static:{:?}, transfer:{:?}, input_size:{:?}",
9393
inputs.contract,
9494
inputs.context,
9595
inputs.is_static,
@@ -115,8 +115,11 @@ impl<DB: Database> Inspector<DB> for CustomPrintTracer {
115115
(InstructionResult::Continue, None, Gas::new(0), Bytes::new())
116116
}
117117

118-
fn selfdestruct(&mut self, contract: B160, target: B160) {
119-
println!("SELFDESTRUCT on {contract:?} refund target: {target:?}");
118+
fn selfdestruct(&mut self, contract: B160, target: B160, value: U256) {
119+
println!(
120+
"SELFDESTRUCT: contract: {:?}, refund target: {:?}, value {:?}",
121+
contract, target, value
122+
);
120123
}
121124
}
122125

0 commit comments

Comments
 (0)