mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
core: fix auth refund
This commit is contained in:
parent
324ccdffe1
commit
d2a7cd0c97
4 changed files with 9 additions and 30 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue