erigontech / erigontech/erigon
Clearing account code to empty leaves stale CodeDomain entry (codeHash mismatch / INVALID under ERIGON_ASSERT)
- Dominant language
- Go
- Stars
- 3.6k
- Forks
- 1.5k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 455
Description
### Summary
On `main`, clearing an account's code to empty (e.g. an `eth_simulateV1` `stateOverride` of `"code":"0x"`, or an EIP-7702 delegation clear) leaves the stale prior code in `CodeDomain`, inconsistent with the now-empty account `codeHash`. With `ERIGON_ASSERT` the commitment codeHash-mismatch check then fires and the block/call is reported `INVALID`.
### Root cause
`accounts.NewCode` collapses any empty input to `EmptyCode{Bytes: nil}`, and both write paths gate the code write on the code slice being non-nil, so a clear-to-empty is silently dropped:
- serial `MakeWriteSet` / `Writer.UpdateAccountCode`
- parallel `applyVersionedWrites`
Because `GetCode` masks the staleness behind the emptied account `codeHash`, it only surfaces via a direct `CodeDomain` read or the `ERIGON_ASSERT` commitment check.
### Fix
Key the code write off an explicit "code changed" signal (`stateObject.dirtyCode` / a `codeWritten` flag) rather than the slice, and route empty code to `DomainDel(CodeDomain)` (since `DomainPut` rejects a nil value) on both paths.
The fix is implemented on the typed-vio branch as commit `8814383304` and is covered by `TestMakeWriteSetClearsCodeDomainOnEmptyOverride` (serial) and `TestApplyVersionedWritesClearsCodeDomain` (parallel). Filing this so the main-side occurrence can be assessed for a standalone fix / backport independently of #21536.
Contributor guide
Assessment
This issue has not been assessed yet.