mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 15:47:21 +00:00
core/state: prevent SetCode hook if contract code is not changed (#32980)
This PR prevents the SetCode hook from being called when the contract code remains unchanged. This situation can occur in the following cases: - The deployed runtime code has zero length - An EIP-7702 authorization attempt tries to unset a non-delegated account - An EIP-7702 authorization attempt tries to delegate to the same account
This commit is contained in:
parent
d73bfeb3d9
commit
79b6a56d3a
1 changed files with 9 additions and 8 deletions
|
|
@ -191,17 +191,18 @@ func (s *hookedStateDB) SetNonce(address common.Address, nonce uint64, reason tr
|
|||
|
||||
func (s *hookedStateDB) SetCode(address common.Address, code []byte, reason tracing.CodeChangeReason) []byte {
|
||||
prev := s.inner.SetCode(address, code, reason)
|
||||
|
||||
if s.hooks.OnCodeChangeV2 != nil || s.hooks.OnCodeChange != nil {
|
||||
prevHash := types.EmptyCodeHash
|
||||
if len(prev) != 0 {
|
||||
prevHash = crypto.Keccak256Hash(prev)
|
||||
}
|
||||
prevHash := crypto.Keccak256Hash(prev)
|
||||
codeHash := crypto.Keccak256Hash(code)
|
||||
|
||||
if s.hooks.OnCodeChangeV2 != nil {
|
||||
s.hooks.OnCodeChangeV2(address, prevHash, prev, codeHash, code, reason)
|
||||
} else if s.hooks.OnCodeChange != nil {
|
||||
s.hooks.OnCodeChange(address, prevHash, prev, codeHash, code)
|
||||
// Invoke the hooks only if the contract code is changed
|
||||
if prevHash != codeHash {
|
||||
if s.hooks.OnCodeChangeV2 != nil {
|
||||
s.hooks.OnCodeChangeV2(address, prevHash, prev, codeHash, code, reason)
|
||||
} else if s.hooks.OnCodeChange != nil {
|
||||
s.hooks.OnCodeChange(address, prevHash, prev, codeHash, code)
|
||||
}
|
||||
}
|
||||
}
|
||||
return prev
|
||||
|
|
|
|||
Loading…
Reference in a new issue