Skip to content

Commit 76c69df

Browse files
committed
feat: Add index input validation (SC-960) (#34)
* feat: add index input validation * feat: update to add testing * ifx: update to use n coins
1 parent 0dd91f4 commit 76c69df

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/MainnetController.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,19 @@ contract MainnetController is AccessControl {
562562
{
563563
_checkRole(RELAYER);
564564

565+
require(inputIndex != outputIndex, "MainnetController/invalid-indices");
566+
565567
uint256 maxSlippage = maxSlippages[pool];
566568
require(maxSlippage != 0, "MainnetController/max-slippage-not-set");
567569

568570
ICurvePoolLike curvePool = ICurvePoolLike(pool);
569571

572+
uint256 numCoins = curvePool.N_COINS();
573+
require(
574+
inputIndex < numCoins && outputIndex < numCoins,
575+
"MainnetController/index-too-high"
576+
);
577+
570578
// Normalized to provide 36 decimal precision when multiplied by asset amount
571579
uint256[] memory rates = curvePool.stored_rates();
572580

@@ -599,8 +607,8 @@ contract MainnetController is AccessControl {
599607
abi.encodeCall(
600608
curvePool.exchange,
601609
(
602-
int128(int256(inputIndex)), // Assuming safe cast because of 8 token max
603-
int128(int256(outputIndex)), // Assuming safe cast because of 8 token max
610+
int128(int256(inputIndex)), // safe cast because of 8 token max
611+
int128(int256(outputIndex)), // safe cast because of 8 token max
604612
amountIn,
605613
minAmountOut,
606614
address(proxy)

test/mainnet-fork/Curve.t.sol

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,40 @@ contract MainnetControllerSwapCurveFailureTests is CurveTestBase {
550550
mainnetController.swapCurve(CURVE_POOL, 1, 0, 1_000_000e18, 980_000e6);
551551
}
552552

553+
function test_swapCurve_sameIndex() public {
554+
vm.prank(relayer);
555+
vm.expectRevert("MainnetController/invalid-indices");
556+
mainnetController.swapCurve(CURVE_POOL, 1, 1, 1_000_000e18, 980_000e6);
557+
}
558+
559+
function test_swapCurve_firstIndexTooHighBoundary() public {
560+
_addLiquidity();
561+
skip(1 days); // Recharge swap rate limit from deposit
562+
563+
deal(RLUSD, address(almProxy), 1_000_000e18);
564+
565+
vm.prank(relayer);
566+
vm.expectRevert("MainnetController/index-too-high");
567+
mainnetController.swapCurve(CURVE_POOL, 2, 0, 1_000_000e18, 980_000e6);
568+
569+
vm.prank(relayer);
570+
mainnetController.swapCurve(CURVE_POOL, 1, 0, 1_000_000e18, 980_000e6);
571+
}
572+
573+
function test_swapCurve_secondIndexTooHighBoundary() public {
574+
_addLiquidity();
575+
skip(1 days); // Recharge swap rate limit from deposit
576+
577+
deal(address(usdc), address(almProxy), 1_000_000e6);
578+
579+
vm.prank(relayer);
580+
vm.expectRevert("MainnetController/index-too-high");
581+
mainnetController.swapCurve(CURVE_POOL, 0, 2, 1_000_000e6, 980_000e18);
582+
583+
vm.prank(relayer);
584+
mainnetController.swapCurve(CURVE_POOL, 0, 1, 1_000_000e6, 980_000e18);
585+
}
586+
553587
function test_swapCurve_slippageNotSet() public {
554588
vm.prank(SPARK_PROXY);
555589
mainnetController.setMaxSlippage(CURVE_POOL, 0);

0 commit comments

Comments
 (0)