Skip to content

Improve scenario of timestamp check in Rio hardfork#2091

Open
lucca30 wants to merge 4 commits intodevelopfrom
lmartins/sec-fix-60
Open

Improve scenario of timestamp check in Rio hardfork#2091
lucca30 wants to merge 4 commits intodevelopfrom
lmartins/sec-fix-60

Conversation

@lucca30
Copy link
Contributor

@lucca30 lucca30 commented Feb 27, 2026

Description

Problem

The Rio HF relaxed verifyHeader()'s timestamp check to support flexible block times, but left header.Time completely unbounded. A block with header.Time = year 2126 passes all validation. Once accepted, Prepare() computes a ~100-year delay and blocks forever.

Fix

Add a 30-second upper bound on how far ahead of local clock a block timestamp may be:

const maxAllowedFutureBlockTimeSeconds = uint64(30)

if header.Time > now+maxAllowedFutureBlockTimeSeconds {
    return consensus.ErrFutureBlock
}

Tests

Three cases added to TestVerifyHeader:

  • far-future timestamp in Rio mode is rejected (chain-halt attack) — year 2126 timestamp must return ErrFutureBlock
  • timestamp beyond allowed future bound in Rio mode is rejected — boundary check at now + 35s
  • normal timestamp in Rio mode is accepted — regression, valid blocks still pass

Changes

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Changes only for a subset of nodes

Breaking changes

No breaking changes

@lucca30 lucca30 requested a review from a team February 27, 2026 13:30
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.58%. Comparing base (fdbc857) to head (35df9d3).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2091      +/-   ##
===========================================
- Coverage    50.59%   50.58%   -0.01%     
===========================================
  Files          875      875              
  Lines       151820   151824       +4     
===========================================
- Hits         76815    76805      -10     
- Misses       69929    69941      +12     
- Partials      5076     5078       +2     
Files with missing lines Coverage Δ
consensus/bor/bor.go 83.47% <100.00%> (+0.28%) ⬆️

... and 22 files with indirect coverage changes

Files with missing lines Coverage Δ
consensus/bor/bor.go 83.47% <100.00%> (+0.28%) ⬆️

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lucca30 lucca30 changed the title fix chain-halt scenario via unbounded timestamp in Rio hardfork Improve scenario of timestamp check in Rio hardfork Feb 27, 2026
Removed detailed comments regarding block timestamp checks to simplify the code.
@sonarqubecloud
Copy link

@lucca30 lucca30 requested a review from a team March 2, 2026 10:03
@lucca30 lucca30 requested a review from a team March 2, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants