Skip to content

Commit 4ad3f61

Browse files
committed
core: prevent no-op code change when clearing a 7702 delegation on an account that wasn't previously delegated, re-delegating to the same contract that was previously-delegated.
1 parent f6064f3 commit 4ad3f61

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

core/state_transition.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ package core
1919
import (
2020
"bytes"
2121
"fmt"
22-
"math"
23-
"math/big"
24-
2522
"github.com/ethereum/go-ethereum/common"
2623
"github.com/ethereum/go-ethereum/core/tracing"
2724
"github.com/ethereum/go-ethereum/core/types"
2825
"github.com/ethereum/go-ethereum/core/vm"
2926
"github.com/ethereum/go-ethereum/crypto/kzg4844"
3027
"github.com/ethereum/go-ethereum/params"
3128
"github.com/holiman/uint256"
29+
"math"
30+
"math/big"
3231
)
3332

3433
// ExecutionResult includes all output after executing given evm
@@ -617,16 +616,22 @@ func (st *stateTransition) applyAuthorization(auth *types.SetCodeAuthorization)
617616
st.state.AddRefund(params.CallNewAccountGas - params.TxAuthTupleGas)
618617
}
619618

619+
prevDelegation, isDelegated := types.ParseDelegation(st.state.GetCode(authority))
620+
620621
// Update nonce and account code.
621622
st.state.SetNonce(authority, auth.Nonce+1, tracing.NonceChangeAuthorization)
622623
if auth.Address == (common.Address{}) {
623624
// Delegation to zero address means clear.
624-
st.state.SetCode(authority, nil, tracing.CodeChangeAuthorizationClear)
625+
if isDelegated {
626+
st.state.SetCode(authority, nil, tracing.CodeChangeAuthorizationClear)
627+
}
625628
return nil
626629
}
627630

628-
// Otherwise install delegation to auth.Address.
629-
st.state.SetCode(authority, types.AddressToDelegation(auth.Address), tracing.CodeChangeAuthorization)
631+
// install delegation to auth.Address if the delegation changed
632+
if !isDelegated || auth.Address != prevDelegation {
633+
st.state.SetCode(authority, types.AddressToDelegation(auth.Address), tracing.CodeChangeAuthorization)
634+
}
630635

631636
return nil
632637
}

0 commit comments

Comments
 (0)