Platform: Code4rena
Start Date: 04/01/2022
Pot Size: $75,000 USDC
Total HM: 17
Participants: 33
Period: 7 days
Judge: 0xean
Total Solo HM: 14
Id: 74
League: ETH
Rank: 14/33
Findings: 2
Award: $690.61
🌟 Selected for report: 2
🚀 Solo Findings: 0
🌟 Selected for report: ye0lde
567.9485 USDC - $567.95
ye0lde
The function below fails to perform input validation on arrays to verify the lengths match. A mismatch could lead to an exception or undefined behavior.
ids
, assetsIn
(copied into from maxAssetsIn
on line 18)
https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Convenience/contracts/libraries/PayMath.sol#L15-L28
While givenMaxAssetsIn
is an internal function if you trace the code back the parameters are passed in by an external function (pay
or payEthAsset
or payEthCollateral
) with no array length validation.
Visual Studio Code, Remix
Add input validation to check that the length of all arrays match (ids
, maxAssetsIn
).
#0 - Mathepreneur
2022-01-18T10:57:43Z
🌟 Selected for report: ye0lde
93.0809 USDC - $93.08
ye0lde
The pool.state.totalLiquidity
is increased instead of set to the value directly.
This performs an unnecessary addition as pool.state.totalLiquidity
is zero.
Visual Studio Code, Remix
Change
pool.state.totalLiquidity += liquidityTotal;
to
pool.state.totalLiquidity = liquidityTotal;
#0 - Mathepreneur
2022-01-18T10:58:40Z
There is a refactor in the mint function.
ye0lde
Gas savings
"> 0" is used in the following locations: https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Convenience/contracts/libraries/SquareRoot.sol#L21 https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Convenience/contracts/libraries/PayMath.sol#L27
Visual Studio Code, Remix
Change "> 0" to "!=0" for small gas savings.
#0 - amateur-dev
2022-01-14T11:06:33Z
Similar issue reported over here #172; hence closing this.
25.1318 USDC - $25.13
ye0lde
Redundant arithmetic underflow/overflow checks can be avoided when an underflow/overflow cannot happen.
The "unchecked" keyword can be applied here since there is an "if" statement to ensure the arithmetic operations would not cause an integer underflow or overflow. https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Convenience/contracts/libraries/Mint.sol#L278
Change the code at 278 to:
unchecked { if (maxCollateral > dueOut.collateral) ETH.transfer(payable(msg.sender), maxCollateral - dueOut.collateral); }
Similar changes can be made here: https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Convenience/contracts/libraries/Mint.sol#L396 https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Convenience/contracts/libraries/Mint.sol#L436 https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Convenience/contracts/libraries/Mint.sol#L557
Visual Studio Code, Remix
Add the "unchecked" keyword as shown above.
#0 - amateur-dev
2022-01-15T03:44:42Z
Similar issue highlighted over here #156 ; hence closing this.