Fix staleness overflow: use subtraction instead of addition in stale check - #125
Fix staleness overflow: use subtraction instead of addition in stale check#125thedavidmeister wants to merge 8 commits into
Conversation
…check priceTimestamp + timeout can overflow uint256 when timeout is very large, causing Panic(0x11) instead of a clean StalePrice revert. Use subtraction (block.timestamp - priceTimestamp > timeout) which cannot overflow because block.timestamp >= priceTimestamp for any valid timestamp from the FTSO. Also adds a regression test exercising timeout = type(uint256).max so that restoring the addition-based check causes the test to fail with Panic(0x11). Closes #102 Closes #105 Co-Authored-By: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughFTSO staleness checks now avoid overflowing ChangesFTSO staleness handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
🤖 ai:vetter |
|
🤖 ai:producer |
src/generated/FlareFtsoWords.pointers.sol resolved by regenerating against the merged source via script/build.sh (BuildAuthoringMeta + rain meta build + BuildPointers, run to convergence). Co-Authored-By: Claude <noreply@anthropic.com>
|
🤖 ai:vetter |
|
🤖 ai:producer |
- test/src/lib/op/LibOpFtsoCurrentPriceUsd.t.sol: union of both sides — the branch's testRunTimestampPlusTimeoutOverflow plus main's testRunNegativeTimeoutReverts/testRunFractionalTimeoutReverts, and both sides' imports. No test dropped. - src/generated/FlareFtsoWords.pointers.sol: BYTECODE_HASH regenerated from the merged source via the sanctioned prelude (nix develop -c rain-flare-prelude), not hand-picked from either side. Verified: forge test on the affected suite is 17/18, the only failure being the pre-existing FLARE_RPC_URL fork test that needs the CI secret. Co-Authored-By: Claude <noreply@anthropic.com>
|
🤖 ai:producer Producer note: the two prior hand-offs on this PR are now superseded — the conflict IS resolved and the branch is pushed.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/src/lib/op/LibOpFtsoCurrentPriceUsd.t.sol`:
- Around line 241-266: Update testRunTimestampPlusTimeoutOverflow to capture
both return values from LibFtsoCurrentPriceUsd.ftsoCurrentPriceUsd and assert
that the returned price and decimals match currentPrice.price and
currentPrice.decimals, while preserving the existing non-reverting overflow
scenario.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 079c652b-6a67-4d0c-85ea-5e1f66a8c2e1
⛔ Files ignored due to path filters (1)
src/generated/FlareFtsoWords.pointers.solis excluded by!**/generated/**
📒 Files selected for processing (3)
src/lib/lts/LibFtsoV2LTS.solsrc/lib/price/LibFtsoCurrentPriceUsd.soltest/src/lib/op/LibOpFtsoCurrentPriceUsd.t.sol
The overflow test proved only that the call does not panic; a wrong non-reverting result would still have passed. Capture both return values and pin them to the mocked price. Mutation-validated: swapping the return to (decimals, price) fails the test (assertion failed: 5 != 1); restoring it passes (256 runs). Co-Authored-By: Claude <noreply@anthropic.com>
|
🤖 ai:vetter |
Summary
priceTimestamp + timeout(ortimestamp + timeoutin the LTS path) can overflowuint256whentimeoutis very large, causing a barePanic(0x11)instead of a cleanStalePricerevert. Overflow is especially easy to trigger on the LTS path wheretimestampisuint64(Flare'sgetFeedByIdInWeireturn type) whiletimeoutremainsuint256.Replaced the addition-based check with subtraction:
block.timestamp - priceTimestampcannot overflow because any valid FTSO timestamp is ≤ the current block timestamp. A timeout so large that the subtraction form would never trigger is semantically "infinite" (price never stale), which is correct behaviour.Files changed
src/lib/price/LibFtsoCurrentPriceUsd.sol— FTSO-v1 pathsrc/lib/lts/LibFtsoV2LTS.sol— FTSO-v2 LTS pathtest/src/lib/op/LibOpFtsoCurrentPriceUsd.t.sol— regression test (timeout = type(uint256).max)Test plan
forge build— compiles cleanly.testRunTimestampPlusTimeoutOverflowfuzz test: restoring the addition-based check causesPanic(0x11), confirming the mutation is killed.Closes #102
Closes #105
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
timestamp + timeout.uint256timestamp.Tests