-
Notifications
You must be signed in to change notification settings - Fork 24
fix: Add an explicit bounds check to prevent silent truncation in _approveWithPermit2
#207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary by OctaneNew ContractsNo new contracts were added. Updated Contracts
🔗 Commit Hash: 4a1a221 |
|
Warning Rate limit exceeded@deluca-mike has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 34 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughAdded a runtime guard in UniswapV4Lib::_approveWithPermit2 to revert with "MC/amount-too-large-for-permit2" when the approved amount exceeds type(uint160).max; updated tests to use fixed inputs, expect this revert, and renamed several test functions to reflect the new boundary semantics. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Comment |
Overview
🔗 Commit Hash: 4a1a221 |
4a1a221 to
f908fd2
Compare
f908fd2 to
caba61b
Compare
caba61b to
ec7bb87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
src/libraries/UniswapV4Lib.sol(1 hunks)test/mainnet-fork/Uniswapv4.t.sol(10 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-11-04T17:15:21.481Z
Learnt from: deluca-mike
Repo: sparkdotfi/spark-alm-controller PR: 185
File: test/base-fork/Aave.t.sol:59-63
Timestamp: 2025-11-04T17:15:21.481Z
Learning: In the spark-alm-controller repository, test files in test/base-fork/ use ForkTestBase from test/base-fork/ForkTestBase.t.sol where _setControllerEntered() defaults to writing the reentrancy guard state to foreignController, while test files in test/mainnet-fork/ use ForkTestBase from test/mainnet-fork/ForkTestBase.t.sol where _setControllerEntered() defaults to mainnetController.
Applied to files:
test/mainnet-fork/Uniswapv4.t.sol
📚 Learning: 2025-11-04T17:15:39.489Z
Learnt from: deluca-mike
Repo: sparkdotfi/spark-alm-controller PR: 185
File: test/base-fork/Morpho.t.sol:122-126
Timestamp: 2025-11-04T17:15:39.489Z
Learning: In the spark-alm-controller repository, tests in the `test/base-fork/` directory use `ForkTestBase` from `test/base-fork/ForkTestBase.t.sol`, where the `_setControllerEntered()` helper function defaults to setting the reentrancy guard state on `foreignController`. Tests in `test/mainnet-fork/` use their own `ForkTestBase` which defaults to `mainnetController`.
Applied to files:
test/mainnet-fork/Uniswapv4.t.sol
📚 Learning: 2025-11-11T19:43:16.032Z
Learnt from: deluca-mike
Repo: sparkdotfi/spark-alm-controller PR: 0
File: :0-0
Timestamp: 2025-11-11T19:43:16.032Z
Learning: In spark-alm-controller, the burnPosition and decreasePosition functions in UniswapV4Lib.sol intentionally do not validate ownership because burning someone else's position would cause the underlying tokens to flow to the proxy, which benefits the system rather than harming it.
Applied to files:
test/mainnet-fork/Uniswapv4.t.sol
📚 Learning: 2025-11-11T19:43:16.032Z
Learnt from: deluca-mike
Repo: sparkdotfi/spark-alm-controller PR: 0
File: :0-0
Timestamp: 2025-11-11T19:43:16.032Z
Learning: In spark-alm-controller, rate limits for Uniswap positions sum both tokens normalized to 18 decimals, which doesn't account for actual USD values. This is a known design decision where normalized balance is used rather than USD-denominated values.
Applied to files:
test/mainnet-fork/Uniswapv4.t.sol
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build
- GitHub Check: coverage
- GitHub Check: test
🔇 Additional comments (2)
src/libraries/UniswapV4Lib.sol (1)
258-259: LGTM! Excellent defensive programming.The bounds check correctly prevents silent truncation when casting
amounttouint160at line 292. Without this guard, amounts exceedingtype(uint160).maxwould have been silently truncated, potentially approving far less than intended and causing transaction failures or allowing operations with insufficient approvals.test/mainnet-fork/Uniswapv4.t.sol (1)
1020-1060: Well-structured boundary tests.The permit2 boundary test correctly validates:
- amount0Max exceeding type(uint160).max reverts with "MC/amount-too-large-for-permit2"
- amount1Max exceeding type(uint160).max reverts with "MC/amount-too-large-for-permit2"
- Valid amounts within bounds succeed
Using fixed deal amounts (1_000_000e6) is appropriate here since we're testing the boundary check, not the liquidity provision logic.
ec7bb87 to
a94ce31
Compare
5e6c5bc to
c239b0a
Compare
c239b0a to
074d5ab
Compare
|
Coverage after merging fix/cantina-13-_approveWithPermit2 into dev will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.