From 58eac317b1483827d85bfa3ab37494a9d3757f0d Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 13 Oct 2025 20:40:00 +0800 Subject: [PATCH] ensure that CodeChange tracer hooks don't get called for noop cases where the cur and prev code is the same --- core/state/statedb_hooked.go | 7 +++++++ core/state_transition.go | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/state/statedb_hooked.go b/core/state/statedb_hooked.go index 11f43df4b3..205acb41da 100644 --- a/core/state/statedb_hooked.go +++ b/core/state/statedb_hooked.go @@ -314,6 +314,13 @@ func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) { } prevCodeHash := s.inner.GetCodeHash(addr) prevCode := s.inner.GetCode(addr) + + // don't record a code change if its a selfdestructing initcode + // ^ TODO: I assume that this is the only case where this can occur but should double-check + // just to be totally sure + if prevCodeHash == types.EmptyCodeHash { + continue + } if s.hooks.OnCodeChangeV2 != nil { s.hooks.OnCodeChangeV2(addr, prevCodeHash, prevCode, types.EmptyCodeHash, nil, tracing.CodeChangeSelfDestruct) } else if s.hooks.OnCodeChange != nil { diff --git a/core/state_transition.go b/core/state_transition.go index b18e24fdf3..622d66806d 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -616,16 +616,22 @@ func (st *stateTransition) applyAuthorization(auth *types.SetCodeAuthorization) st.state.AddRefund(params.CallNewAccountGas - params.TxAuthTupleGas) } + prevDelegation, isDelegated := types.ParseDelegation(st.state.GetCode(authority)) + // Update nonce and account code. st.state.SetNonce(authority, auth.Nonce+1, tracing.NonceChangeAuthorization) if auth.Address == (common.Address{}) { // Delegation to zero address means clear. - st.state.SetCode(authority, nil, tracing.CodeChangeAuthorizationClear) + if isDelegated { + st.state.SetCode(authority, nil, tracing.CodeChangeAuthorizationClear) + } return nil } - // Otherwise install delegation to auth.Address. - st.state.SetCode(authority, types.AddressToDelegation(auth.Address), tracing.CodeChangeAuthorization) + // install delegation to auth.Address if the delegation changed + if !isDelegated || auth.Address != prevDelegation { + st.state.SetCode(authority, types.AddressToDelegation(auth.Address), tracing.CodeChangeAuthorization) + } return nil }