Skip to content

Commit 1461604

Browse files
committed
explicitly check for swap amounts being too large (instead of depending on checked arithmetic overflows)
1 parent c64b5b5 commit 1461604

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/EulerSwap.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ contract EulerSwap is IEulerSwap, EVCUtil {
5151
error Locked();
5252
error Overflow();
5353
error BadParam();
54+
error AmountTooBig();
5455
error DifferentEVC();
5556
error AssetsOutOfOrderOrEqual();
5657
error CurveViolation();
@@ -105,6 +106,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
105106
callThroughEVC
106107
nonReentrant
107108
{
109+
require(amount0Out <= type(uint112).max && amount1Out <= type(uint112).max, AmountTooBig());
110+
108111
// Optimistically send tokens
109112

110113
if (amount0Out > 0) withdrawAssets(vault0, amount0Out, to);

test/Limits.t.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,12 @@ contract LimitsTest is EulerSwapTestBase {
107107
assertEq(inLimit, type(uint112).max - 110e18);
108108
assertEq(outLimit, 18.5e18); // 10 in balance, plus 8.5 borrow cap
109109
}
110+
111+
function test_amountTooBig() public monotonicHolderNAV {
112+
vm.expectRevert(EulerSwap.AmountTooBig.selector);
113+
eulerSwap.swap(type(uint256).max, 0, address(this), "");
114+
115+
vm.expectRevert(EulerSwap.AmountTooBig.selector);
116+
eulerSwap.swap(0, type(uint256).max, address(this), "");
117+
}
110118
}

0 commit comments

Comments
 (0)