From d2a7cd0c97f1c714dfd3e758fd978431a3ca8aa7 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 21 May 2026 21:27:13 +0800 Subject: [PATCH] core: fix auth refund --- core/state/statedb.go | 12 ------------ core/state/statedb_hooked.go | 4 ---- core/state_transition.go | 18 +++++++++--------- core/vm/interface.go | 5 ----- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 15c175fd30..1c49d46020 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -397,18 +397,6 @@ func (s *StateDB) GetCodeHash(addr common.Address) common.Hash { return common.Hash{} } -// GetCommittedCode returns the contract code committed at the start of the -// current execution, ignoring any in-progress SetCode mutations. Returns -// nil when the account had no code (or did not exist) prior to this -// execution. -func (s *StateDB) GetCommittedCode(addr common.Address) []byte { - stateObject := s.getStateObject(addr) - if stateObject != nil { - return stateObject.GetCommittedCode() - } - return nil -} - // GetState retrieves the value associated with the specific key. func (s *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash { stateObject := s.getStateObject(addr) diff --git a/core/state/statedb_hooked.go b/core/state/statedb_hooked.go index 184629ea41..98d01343a4 100644 --- a/core/state/statedb_hooked.go +++ b/core/state/statedb_hooked.go @@ -75,10 +75,6 @@ func (s *hookedStateDB) GetCode(addr common.Address) []byte { return s.inner.GetCode(addr) } -func (s *hookedStateDB) GetCommittedCode(addr common.Address) []byte { - return s.inner.GetCommittedCode(addr) -} - func (s *hookedStateDB) GetCodeSize(addr common.Address) int { return s.inner.GetCodeSize(addr) } diff --git a/core/state_transition.go b/core/state_transition.go index 5f52570bc7..02b80f7f21 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -935,7 +935,7 @@ func (st *stateTransition) applyAuthorizations(rules params.Rules, auths []types // (auth.Address == 0) for an authority in this set refunds the prior bill // and removes the entry, since the net delegation bytes written by the // chain are zero. -func (st *stateTransition) applyAuthorization(rules params.Rules, auth *types.SetCodeAuthorization, authBilledCreations map[common.Address]struct{}) error { +func (st *stateTransition) applyAuthorization(rules params.Rules, auth *types.SetCodeAuthorization, authBilled map[common.Address]struct{}) error { authority, err := st.validateAuthorization(auth) if err != nil { return err @@ -957,7 +957,7 @@ func (st *stateTransition) applyAuthorization(rules params.Rules, auth *types.Se // Refill the auth-base for the current authorization if ANY of: // // - the authority was already delegated at the start of the tx - // (the 23 bytes are already accounted for in committed state), + // (the 23 bytes are already accounted for in pre-tx state), // // - a prior auth in this tx has already billed the auth-base for // this authority (per-tx per-authority creation budget is 1), @@ -975,19 +975,19 @@ func (st *stateTransition) applyAuthorization(rules params.Rules, auth *types.Se // auths writes zero net delegation bytes, so the earlier bill is no // longer justified. var ( - clearing = auth.Address == (common.Address{}) - _, committedDelegated = types.ParseDelegation(st.state.GetCommittedCode(authority)) - _, alreadyBilled = authBilledCreations[authority] + clearing = auth.Address == (common.Address{}) + _, delegated = types.ParseDelegation(st.state.GetCode(authority)) + _, billed = authBilled[authority] ) - if committedDelegated || alreadyBilled || clearing { + if delegated || billed || clearing { st.gasRemaining.RefundState(params.AuthorizationCreationSize * st.evm.Context.CostPerStateByte) } else { - authBilledCreations[authority] = struct{}{} + authBilled[authority] = struct{}{} } // Refund that prior bill and drop the mark - if clearing && alreadyBilled { + if clearing && billed { st.gasRemaining.RefundState(params.AuthorizationCreationSize * st.evm.Context.CostPerStateByte) - delete(authBilledCreations, authority) + delete(authBilled, authority) } } diff --git a/core/vm/interface.go b/core/vm/interface.go index dc897f0c69..a9938c2a28 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -42,11 +42,6 @@ type StateDB interface { GetCodeHash(common.Address) common.Hash GetCode(common.Address) []byte - // GetCommittedCode returns the contract code at the start of the current - // execution, ignoring any in-progress SetCode mutations. Returns nil when - // the account had no code prior to this execution. - GetCommittedCode(common.Address) []byte - // SetCode sets the new code for the address, and returns the previous code, if any. SetCode(common.Address, []byte, tracing.CodeChangeReason) []byte GetCodeSize(common.Address) int