Skip to content

Round toRange() bounds outward at every step - #1315

Merged
tbrent merged 5 commits into
4.3.0-audit-bypass-on-switchfrom
4.3.0-audit-torange-rounding
Dec 1, 2026
Merged

tbrent merged 5 commits into
4.3.0-audit-bypass-on-switchfrom
4.3.0-audit-torange-rounding

Conversation

@tbrent

@tbrent tbrent commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

PoolTokens.toRange() and AerodromePoolTokens.toRange() now pass an explicit rounding mode to every multiplication: down for low, up for high.

Stacked on #1314.

Why

Trust audit finding "Assessment of changed rounding directions" (QA).

Since #1283, FixLib.mul(x, y) rounds down by default. In toRange() that made two of the three products of the high bound round down:

high = x.mul(FIX_ONE + xErr).mul(y.mul(FIX_ONE + yErr), CEIL);

The audit flagged the inner y.mul(FIX_ONE + yErr) term. The left x.mul(FIX_ONE + xErr) term has the same problem, so this PR fixes both. The low bound was already correct and is only made explicit.

The effect is far below oracle error: each inner product moves by at most one unit of 1e-18, and the outer product scales that difference by the other price. It only applies to plugins deployed from these sources; no deployed plugin changes.

The audit found the other two-argument mul() calls in plugins acceptable in either direction, so they are left alone.

Changes

  • contracts/plugins/assets/curve/PoolTokens.sol, contracts/plugins/assets/aerodrome/AerodromePoolTokens.sol: explicit FLOOR / CEIL in toRange().
  • CHANGELOG.md: the rounding section no longer lists toRange() under the default-rounding change, and notes the explicit rounding.

Verification

  • Aerodrome plugin fork tests on Base: 189 passing, 60 pending (skipped in the suite).
  • Curve plugin fork tests on mainnet (crv, cvx, stakedao): 416 passing, 87 pending (skipped in the suite).
  • No new test: toRange() is private, and the change is a last-digit rounding direction.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected range rounding so low values consistently round down and high values round up, improving the accuracy of pool token range calculations.

FixLib.mul(x, y) now rounds down by default, so the inner products of
toRange() rounded the high bound down. Round every product down for low
and up for high. Only affects future plugin deployments.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Curve and Aerodrome toRange functions now specify rounding for each multiplication: down for low bounds and up for high bounds. The changelog documents these changes.

Changes: Pool token range rounding

Layer / File(s) Summary
Explicit bound rounding
contracts/plugins/assets/curve/PoolTokens.sol, contracts/plugins/assets/aerodrome/AerodromePoolTokens.sol, CHANGELOG.md
Both toRange functions now explicitly round each low-bound multiplication down and each high-bound multiplication up. The changelog records this behavior and notes that the inner products previously used default rounding.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: julianmrodri

Merge Risk: Minimal · up to 567b9

This change makes the Curve and Aerodrome pool-token price ranges round outward at every multiplication. It shifts the bounds by at most a last-digit amount in the conservative direction and does not change already deployed plugins. I found no merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Round toRange() bounds outward at every step" matches the main change: explicit FLOOR rounding on every multiplication in the low bound and CEIL rounding on every multiplication in the high…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Round toRange() bounds outward at every step" matches the main change: explicit FLOOR rounding on every multiplication in the low bound and CEIL rounding on every multiplication in the high bound of toRange() in PoolTokens and AerodromePoolTokens. It names the function and the rounding direction, so a reviewer scanning history can identify the primary change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f0194b07-dda0-48e5-8505-cf43b007db09
Commits

Reviewing files that changed from the base of the PR and between e8da163 and 567b964.

Files selected for processing: 3

  • CHANGELOG.md
  • contracts/plugins/assets/aerodrome/AerodromePoolTokens.sol
  • contracts/plugins/assets/curve/PoolTokens.sol

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@akshatmittal
akshatmittal added this pull request to stack #1318 November 27, 2026 19:44
akshatmittal
akshatmittal previously approved these changes Nov 30, 2026
Reverts ab3d74a on this branch. The guard and its test now come in with
refreshBasket(bool skipTradingDelay), which rewrites the same lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Reverts fed7a77. The guard stays in its own PR after all.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@tbrent
tbrent merged commit bd01378 into master Dec 1, 2026
17 checks passed
@tbrent
tbrent deleted the 4.3.0-audit-torange-rounding branch December 1, 2026 17:31
tbrent added a commit that referenced this pull request Dec 1, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
tbrent added a commit that referenced this pull request Dec 1, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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