Skip to content

Commit 8cc5cb8

Browse files
tonyke-botEvalir
authored andcommitted
add value parameter to Inspector::selfdestruct (bluealloy#645)
1 parent 4991949 commit 8cc5cb8

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

crates/revm/src/db/states/state.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,15 @@ mod tests {
554554
let mut state = StateBuilder::default().build();
555555

556556
// Non-existing account.
557-
let new_account_address = B160::from_slice(&[0x1; 20]);
557+
let new_account_address = Address::from_slice(&[0x1; 20]);
558558
let new_account_created_info = AccountInfo {
559559
nonce: 1,
560560
balance: U256::from(1),
561561
..Default::default()
562562
};
563563

564564
// Existing account.
565-
let existing_account_address = B160::from_slice(&[0x2; 20]);
565+
let existing_account_address = Address::from_slice(&[0x2; 20]);
566566
let existing_account_initial_info = AccountInfo {
567567
nonce: 1,
568568
..Default::default()
@@ -575,7 +575,7 @@ mod tests {
575575

576576
// Existing account with storage.
577577
let (slot1, slot2) = (U256::from(1), U256::from(2));
578-
let existing_account_with_storage_address = B160::from_slice(&[0x3; 20]);
578+
let existing_account_with_storage_address = Address::from_slice(&[0x3; 20]);
579579
let existing_account_with_storage_info = AccountInfo {
580580
nonce: 1,
581581
..Default::default()
@@ -722,7 +722,7 @@ mod tests {
722722
let mut state = StateBuilder::default().build();
723723

724724
// Existing account.
725-
let existing_account_address = B160::from_slice(&[0x1; 20]);
725+
let existing_account_address = Address::from_slice(&[0x1; 20]);
726726
let existing_account_info = AccountInfo {
727727
nonce: 1,
728728
..Default::default()

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:?}")
@@ -425,7 +425,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
425425
created_address: None,
426426
gas,
427427
return_value: Bytes::new(),
428-
})
428+
});
429429
}
430430
};
431431

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

858858
fn selfdestruct(&mut self, address: Address, target: Address) -> Option<SelfDestructResult> {
859859
if INSPECT {
860-
self.inspector.selfdestruct(address, target);
860+
let acc = self.data.journaled_state.state.get(&address).unwrap();
861+
self.inspector
862+
.selfdestruct(address, target, acc.info.balance);
861863
}
862864
self.data
863865
.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, Address, Bytes, B256};
3+
use crate::primitives::{db::Database, Bytes, Address, 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: Address, _target: Address) {}
139+
fn selfdestruct(&mut self, _contract: Address, _target: Address, _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::{Address, Bytes};
5+
use crate::primitives::{Bytes, Address, 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,
@@ -111,8 +111,11 @@ impl<DB: Database> Inspector<DB> for CustomPrintTracer {
111111
(InstructionResult::Continue, None, Gas::new(0), Bytes::new())
112112
}
113113

114-
fn selfdestruct(&mut self, contract: Address, target: Address) {
115-
println!("SELFDESTRUCT on {contract:?} refund target: {target:?}");
114+
fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) {
115+
println!(
116+
"SELFDESTRUCT: contract: {:?}, refund target: {:?}, value {:?}",
117+
contract, target, value
118+
);
116119
}
117120
}
118121

0 commit comments

Comments
 (0)