execution/state: an existence read at a seeded destruct stays valid once a re-run removes the account

Open
#26,476 2 comments 0 reactions 2 assignees View on GitHub

Maintainers usually reply within 1 day

@mh0lt is already working on this.

Since Nov 18, 2026.

Assessment

This issue has not been assessed yet.

Description

On a block with an access list, a read of an account's existence can stay valid at the seal although a re-run finds the account absent. It is the existence version of #26463.

  • The access list seeds a removal of x at tx 3, as a Done destruct at incarnation 0.
  • The first run of tx 3 creates x at (3, 0). tx 4 calls Exist(x) and gets true. In versionedAccountBase, an account cell at the destruct's tx that does not come from the access list makes the read return the committed record ("Only a re-creation by the destroying tx itself is left to the committed reader"), and nothing records that decision. tx 4 records only the destruct and the wiped fields at the destruct's version.
  • The re-run of tx 3 removes x, as the access list says. The drop deletes the create's cells, and the flush keeps the seeded destruct at its version (#26326), so every read of tx 4 stays valid, while a fresh Exist(x) returns false.

tx 4 is then committed as if x existed, for example with the gas of a call to an existing account. The trigger is a tx that runs at least twice with different results, and a later tx validated in between. A harness of 144 run sequences over a seeded removal finds 34 such reads on main.

Repro

In execution/state (uses accountStateReader from versionmap_seed_removal_test.go). It fails on main (3e201075dc) at the last assertion.

func TestExistenceReadAtASeededDestructIsStaleOnceTheRemovalReturns(t *testing.T) {
	x := accounts.InternAddress(common.HexToAddress("0xd6"))
	acc := accounts.NewAccount()
	acc.Balance = *uint256.NewInt(5)
	base := &accountStateReader{accounts: map[accounts.Address]*accounts.Account{x: &acc}}
	// The access list seeds a removal of x at tx 3.
	vm := NewVersionMap(types.BlockAccessList{{Address: x.Value(), BalanceChanges: []*types.BalanceChange{{Index: 4, Value: uint256.Int{}}}}})
	vm.SeedAddresses()
	require.NoError(t, vm.SeedEmptyRemovals(true, false, base))
	exists := func() (bool, ReadSet) {
		ibs := NewWithVersionMap(base, vm)
		defer ibs.Close()
		ibs.SetTxContext(1, 4)
		ok, err := ibs.Exist(x)
		require.NoError(t, err)
		require.False(t, ibs.HadInvalidRead())
		return ok, ibs.VersionedReads()
	}

	// The first run of tx 3 creates x.
	run := NewWithVersionMap(base, vm)
	run.SetTxContext(1, 3)
	require.NoError(t, run.CreateAccount(x, true))
	require.NoError(t, run.SetNonce(x, 1, tracing.NonceChangeUnspecified))
	require.NoError(t, run.SetBalance(x, uint256.Int{}, tracing.BalanceChangeUnspecified))
	require.NoError(t, run.MakeWriteSet(&chain.Rules{IsAmsterdam: true}, NewNoopWriter()))
	create := run.VersionedWrites()
	run.Close()
	vm.FlushVersionedWrites(create, false)
	vm.MarkWritesValidated(create, nil)
	existed, reads := exists()
	require.True(t, existed)

	// The re-run of tx 3 removes x, as the access list says.
	rerun := Version{TxIndex: 3, Incarnation: 1}
	removal := &WriteSet{}
	removal.SetEmptyRemoval(x, rerun)
	for h := range create.AllHeaders() {
		if !removal.Has(h) {
			vm.DropWrite(h.Address, h.Path, h.Key, rerun)
		}
	}
	vm.FlushVersionedWrites(removal, false)
	vm.MarkWritesValidated(removal, nil)
	vm.MarkWritesComplete(removal)
	vm.SealUpTo(3)

	existsAtSeal, _ := exists()
	require.False(t, existsAtSeal)
	require.Equal(t, VersionInvalid, vm.ValidateReadSet(4, reads, validateEqualVersion, false, ""), "tx 4 read x as existing")
}

Found in the review of #26447.

Dominant language
Go
Stars
3.6k
Forks
1.6k
Avg merge
1d 17h
Merged PRs (30d)
820

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from erigontech/erigon

All issues in erigontech/erigon

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.