Skip to content

Commit 65ce2b2

Browse files
MariusVanDerWijdenblakehhuynh
authored andcommitted
consensus/beacon: verify timestamp is greater than parent timestamp (ethereum#25236)
1 parent 9875caf commit 65ce2b2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

consensus/beacon/consensus.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var (
4545
errTooManyUncles = errors.New("too many uncles")
4646
errInvalidNonce = errors.New("invalid nonce")
4747
errInvalidUncleHash = errors.New("invalid uncle hash")
48+
errInvalidTimestamp = errors.New("invalid timestamp")
4849
)
4950

5051
// Beacon is a consensus engine that combines the eth1 consensus and proof-of-stake
@@ -213,7 +214,7 @@ func (beacon *Beacon) VerifyUncles(chain consensus.ChainReader, block *types.Blo
213214
// - nonce is expected to be 0
214215
// - unclehash is expected to be Hash(emptyHeader)
215216
// to be the desired constants
216-
// (b) the timestamp is not verified anymore
217+
// (b) we don't verify if a block is in the future anymore
217218
// (c) the extradata is limited to 32 bytes
218219
func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header) error {
219220
// Ensure that the header's extra-data section is of a reasonable size
@@ -227,6 +228,10 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
227228
if header.UncleHash != types.EmptyUncleHash {
228229
return errInvalidUncleHash
229230
}
231+
// Verify the timestamp
232+
if header.Time <= parent.Time {
233+
return errInvalidTimestamp
234+
}
230235
// Verify the block's difficulty to ensure it's the default constant
231236
if beaconDifficulty.Cmp(header.Difficulty) != 0 {
232237
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, beaconDifficulty)

0 commit comments

Comments
 (0)