Skip to content

Commit bc9a43a

Browse files
MariusVanDerWijdencp-wjhan
authored andcommitted
consensus/beacon: verify timestamp is greater than parent timestamp (ethereum#25236)
1 parent 19f5f7c commit bc9a43a

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
@@ -214,7 +215,7 @@ func (beacon *Beacon) VerifyUncles(chain consensus.ChainReader, block *types.Blo
214215
// - unclehash is expected to be Hash(emptyHeader)
215216
// to be the desired constants
216217
//
217-
// (b) the timestamp is not verified anymore
218+
// (b) we don't verify if a block is in the future anymore
218219
// (c) the extradata is limited to 32 bytes
219220
func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header) error {
220221
// Ensure that the header's extra-data section is of a reasonable size
@@ -228,6 +229,10 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
228229
if header.UncleHash != types.EmptyUncleHash {
229230
return errInvalidUncleHash
230231
}
232+
// Verify the timestamp
233+
if header.Time <= parent.Time {
234+
return errInvalidTimestamp
235+
}
231236
// Verify the block's difficulty to ensure it's the default constant
232237
if beaconDifficulty.Cmp(header.Difficulty) != 0 {
233238
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, beaconDifficulty)

0 commit comments

Comments
 (0)