mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-18 22:09:26 +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 {
|
func (s *hookedStateDB) SetCode(address common.Address, code []byte, reason tracing.CodeChangeReason) []byte {
|
||||||
prev := s.inner.SetCode(address, code, reason)
|
prev := s.inner.SetCode(address, code, reason)
|
||||||
|
|
||||||
if s.hooks.OnCodeChangeV2 != nil || s.hooks.OnCodeChange != nil {
|
if s.hooks.OnCodeChangeV2 != nil || s.hooks.OnCodeChange != nil {
|
||||||
prevHash := types.EmptyCodeHash
|
prevHash := crypto.Keccak256Hash(prev)
|
||||||
if len(prev) != 0 {
|
|
||||||
prevHash = crypto.Keccak256Hash(prev)
|
|
||||||
}
|
|
||||||
codeHash := crypto.Keccak256Hash(code)
|
codeHash := crypto.Keccak256Hash(code)
|
||||||
|
|
||||||
if s.hooks.OnCodeChangeV2 != nil {
|
// Invoke the hooks only if the contract code is changed
|
||||||
s.hooks.OnCodeChangeV2(address, prevHash, prev, codeHash, code, reason)
|
if prevHash != codeHash {
|
||||||
} else if s.hooks.OnCodeChange != nil {
|
if s.hooks.OnCodeChangeV2 != nil {
|
||||||
s.hooks.OnCodeChange(address, prevHash, prev, codeHash, code)
|
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
|
return prev
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue