More logging around self destruct

This commit is contained in:
Matthieu Vachon 2025-06-09 16:44:45 -04:00
parent 6c707504ff
commit 713f67421e
3 changed files with 6 additions and 4 deletions

View file

@ -887,8 +887,6 @@ func (s *StateDB) SetStorage(addr common.Address, storage map[common.Hash]common
// The account's state object is still available until the state is committed, // The account's state object is still available until the state is committed,
// getStateObject will return a non-nil account after SelfDestruct. // getStateObject will return a non-nil account after SelfDestruct.
func (s *StateDB) SelfDestruct(addr common.Address) uint256.Int { func (s *StateDB) SelfDestruct(addr common.Address) uint256.Int {
fmt.Fprintf(os.Stderr, "[Firehose] SelfDestruct called (addr=%s)\n", addr)
stateObject := s.getStateObject(addr) stateObject := s.getStateObject(addr)
var prevBalance uint256.Int var prevBalance uint256.Int
if stateObject == nil { if stateObject == nil {
@ -918,8 +916,6 @@ func (s *StateDB) SelfDestruct(addr common.Address) uint256.Int {
} }
func (s *StateDB) SelfDestruct6780(addr common.Address) (uint256.Int, bool) { func (s *StateDB) SelfDestruct6780(addr common.Address) (uint256.Int, bool) {
fmt.Fprintf(os.Stderr, "[Firehose] SelfDestruct6780 called (addr=%s)\n", addr)
stateObject := s.getStateObject(addr) stateObject := s.getStateObject(addr)
if stateObject == nil { if stateObject == nil {
fmt.Fprintf(os.Stderr, "[Firehose] SelfDestruct6780: stateObject is nil (addr=%s)\n", addr) fmt.Fprintf(os.Stderr, "[Firehose] SelfDestruct6780: stateObject is nil (addr=%s)\n", addr)

View file

@ -17,7 +17,9 @@
package state package state
import ( import (
"fmt"
"math/big" "math/big"
"os"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -257,6 +259,7 @@ func (s *hookedStateDB) SelfDestruct6780(address common.Address) (uint256.Int, b
prev, changed := s.inner.SelfDestruct6780(address) prev, changed := s.inner.SelfDestruct6780(address)
if s.hooks.OnBalanceChange != nil && changed && !prev.IsZero() { if s.hooks.OnBalanceChange != nil && changed && !prev.IsZero() {
fmt.Fprintf(os.Stderr, "[Firehose] SelfDestruct6780 (hooked): previous balance withdraw (addr=%s, prev_balance=%s)\n", address, &prev)
s.hooks.OnBalanceChange(address, prev.ToBig(), new(big.Int), tracing.BalanceDecreaseSelfdestruct) s.hooks.OnBalanceChange(address, prev.ToBig(), new(big.Int), tracing.BalanceDecreaseSelfdestruct)
} }

View file

@ -17,7 +17,9 @@
package vm package vm
import ( import (
"fmt"
"math" "math"
"os"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/tracing"
@ -1009,6 +1011,7 @@ func opSelfdestruct6780(pc *uint64, interpreter *EVMInterpreter, scope *ScopeCon
} }
beneficiary := scope.Stack.pop() beneficiary := scope.Stack.pop()
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address()) balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
fmt.Fprintf(os.Stderr, "[Firehose] SelfDestruct6780 (instructions): previous balance withdraw (addr=%s, prev_balance=%s)\n", scope.Contract.Address(), balance)
interpreter.evm.StateDB.SubBalance(scope.Contract.Address(), balance, tracing.BalanceDecreaseSelfdestruct) interpreter.evm.StateDB.SubBalance(scope.Contract.Address(), balance, tracing.BalanceDecreaseSelfdestruct)
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance, tracing.BalanceIncreaseSelfdestruct) interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance, tracing.BalanceIncreaseSelfdestruct)
interpreter.evm.StateDB.SelfDestruct6780(scope.Contract.Address()) interpreter.evm.StateDB.SelfDestruct6780(scope.Contract.Address())