Skip to content

Fix uint64 underflow in getHeader msIntoSlot for requests arriving before slot start#906

Open
vsaraikin wants to merge 2 commits into
flashbots:developfrom
vsaraikin:fix/getheader-msintoslot-underflow
Open

Fix uint64 underflow in getHeader msIntoSlot for requests arriving before slot start#906
vsaraikin wants to merge 2 commits into
flashbots:developfrom
vsaraikin:fix/getheader-msintoslot-underflow

Conversation

@vsaraikin

Copy link
Copy Markdown

Closes #902.

getHeader computes msIntoSlot with unsigned arithmetic. When the CL's request arrives even 1ms before slot start (sub-ms scheduling jitter between VC and BN is enough), the subtraction wraps to ~2^64, the late-in-slot guard concludes the request is hopelessly late, and mev-boost returns 204 without querying any relay — the proposer silently falls back to a locally built block and loses the MEV reward. The wrapped value also corrupts the mev_boost_millisec_into_slot metric.

This computes the value with signed arithmetic and clamps negatives to zero, i.e. treats an early request as arriving exactly at slot start with the full time budget — mirroring how mev-boost-relay handled its analogous underflow.

Complements #900, which fixes the sibling underflow in the timing-games delay path but is not reached in this scenario: with a wrapped msIntoSlot the late-in-slot guard returns before timing games run.

Adds a regression test: a getHeader request arriving before slot start must still query relays and return the bid.

@vsaraikin
vsaraikin marked this pull request as ready for review July 7, 2026 20:40
Copilot AI review requested due to automatic review settings July 7, 2026 20:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a uint64 underflow in getHeader’s msIntoSlot computation that could incorrectly trigger the late-in-slot guard when a request arrives slightly before slot start, causing mev-boost to skip all relays and return 204 (and corrupting the mev_boost_millisec_into_slot metric). The PR switches to signed arithmetic and clamps negative values to zero, plus adds a regression test to ensure relays are still queried.

Changes:

  • Compute msIntoSlot using signed subtraction and clamp negative values to 0 before applying late-in-slot logic.
  • Add a regression test verifying that an early (pre-slot-start) getHeader request still queries relays and returns a bid.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
server/get_header.go Prevents msIntoSlot underflow by using signed arithmetic and clamping early arrivals to 0ms into slot.
server/service_test.go Adds a regression test for pre-slot-start getHeader requests to ensure relays are still queried.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/service_test.go Outdated
Comment on lines +334 to +337
// setting genesisTime so slot 1 starts one second in the future,
// making msIntoSlot negative. Without clamping, the unsigned
// subtraction wraps and the late-in-slot guard skips all relays.
backend.boost.genesisTime = uint64(time.Now().Unix()) - 11

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — moved the slot start to ~5s in the future so msIntoSlot is reliably negative regardless of the second truncation. Verified the test still fails against the pre-fix code.

Copilot AI review requested due to automatic review settings July 8, 2026 10:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

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.

uint64 underflow in getHeader msIntoSlot: request arriving before slot start silently skips all relays

2 participants