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: 21/33
Findings: 1
Award: $148.58
🌟 Selected for report: 2
🚀 Solo Findings: 0
🌟 Selected for report: OriDabush
93.0809 USDC - $93.08
OriDabush
calculate the condition in line 362 before the loop instead of calculating it in every iteration.
for (uint256 i; i < ids.length; i++) { ... if (owner != msg.sender) require(collateralsOut[i] == 0, 'E213'); ... }
bool condition = (owner != msg.sender); for (uint256 i; i < ids.length; i++) { ... if (condition) require(collateralsOut[i] == 0, 'E213'); ... }
#0 - Mathepreneur
2022-01-15T22:29:20Z
Yes its more gas efficient this way, but it's possible for users to pay the collateralized debt of other users together with the collateralized debts they owned.
OriDabush
calculate BlockNumber.get() before the loop in line 289 and save it in a variable to prevent calculating it (and calling the get function) in every iteration.
for (uint256 i; i < ids.length; i++) { ... require(due.startBlock != BlockNumber.get(), 'E207'); ... }
uint32 startblock = BlockNumber.get(); for (uint256 i; i < ids.length; i++) { ... require(due.startBlock != startblock , 'E207'); ... }
#0 - amateur-dev
2022-01-15T04:24:15Z
Similar issue reported over here #142; hence closing this
OriDabush
In line 359 in the TimeswapPair contract, you can prefix increment the loop index instead of postfix incrementing it. This change will save gas (it will prevent a useless operation in every iteration of the loop).
code before: for (uint256 i; i < ids.length; i++) { ... }
code after: for (uint256 i; i < ids.length; ++i) { ... }
#0 - amateur-dev
2022-01-14T11:29:15Z
Similar issue reported over here #170; hence closing this
41.8864 USDC - $41.89
OriDabush
Lines 289-290 can be transferred into the if statements to avoid subtract 0 from the variables.
pool.state.reserves.asset -= tokensOut.asset;
pool.state.reserves.collateral -= tokensOut.collateral;
if (tokensOut.asset > 0) asset.safeTransfer(assetTo, tokensOut.asset);
if (tokensOut.collateral > 0) collateral.safeTransfer(collateralTo, tokensOut.collateral);
if (tokensOut.asset > 0) { asset.safeTransfer(assetTo, tokensOut.asset); pool.state.reserves.asset -= tokensOut.asset; }
if (tokensOut.collateral > 0) { collateral.safeTransfer(collateralTo, tokensOut.collateral); pool.state.reserves.collateral -= tokensOut.collateral; }
#0 - Mathepreneur
2022-01-24T13:00:47Z