Skip to content

Commit

Permalink
EIP-4788: set nonce of beacon root history address to nonzero (#7952)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis authored and AskAlexSharov committed Sep 6, 2023
1 parent 4f1829e commit 7bbd4e9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions consensus/misc/eip4788.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/holiman/uint256"

libcommon "github.com/ledgerwatch/erigon-lib/common"

"github.com/ledgerwatch/erigon/consensus"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
Expand All @@ -20,4 +21,11 @@ func ApplyBeaconRootEip4788(chain consensus.ChainHeaderReader, header *types.Hea
parentBeaconBlockRootInt := *uint256.NewInt(0).SetBytes(header.ParentBeaconBlockRoot.Bytes())
state.SetState(historyStorageAddress, &timestampIndex, *uint256.NewInt(header.Time))
state.SetState(historyStorageAddress, &rootIndex, parentBeaconBlockRootInt)

// Ensure that the historyStorageAddress has nonzero nonce to prevent wipe-out of its storage stipulated by EIP-161
// (when the historyStorageAddress has zero balance).
// See https://github.com/ethereum/EIPs/pull/7431
if state.GetNonce(historyStorageAddress) == 0 {
state.SetNonce(historyStorageAddress, 1)
}
}

0 comments on commit 7bbd4e9

Please sign in to comment.