Platform: Code4rena
Start Date: 21/08/2023
Pot Size: $36,500 USDC
Total HM: 1
Participants: 43
Period: 7 days
Judge: Dravee
Id: 277
League: ETH
Rank: 27/43
Findings: 1
Award: $22.46
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: lsaudit
Also found by: 0x11singh99, 0x4non, 0xAnah, 0xSmartContract, 0xhacksmithh, JP_Courses, Jorgect, MrPotatoMagic, Sathish9098, epistkr, pfapostol, pontifex
22.4575 USDC - $22.46
_applyFeeByRounding(int256 amount, bool feeUp)
cand be optimizednegative
variableInstead of;
bool negative = amount < 0 ? true : false;
Use this;
bool negative = amount < 0;
Instead of;
FIXED_FEE * 2
Use this;
FIXED_FEE + FIXED_FEE
roundedAbsoluteAmount
can be extracted to remove suplicate code:Instead of;
uint256 roundedAbsoluteAmount; if (feeUp) { roundedAbsoluteAmount = absoluteValue + (absoluteValue / BASE_FEE) + FIXED_FEE; require(roundedAbsoluteAmount < INT_MAX); } else // @audit missing bracket could difficult readability roundedAbsoluteAmount = // @audit this could be simplified absoluteValue - (absoluteValue / BASE_FEE) - FIXED_FEE;
Use this;
uint256 roundedAbsoluteAmount = absoluteValue + (absoluteValue / BASE_FEE); if (feeUp) { roundedAbsoluteAmount += FIXED_FEE; } else { roundedAbsoluteAmount -= FIXED_FEE; } require(roundedAbsoluteAmount < INT_MAX);
diff --git a/src/proteus/EvolvingProteus.sol b/src/proteus/EvolvingProteus.sol index 85341bb..7cbf103 100644 --- a/src/proteus/EvolvingProteus.sol +++ b/src/proteus/EvolvingProteus.sol @@ -826,25 +826,20 @@ contract EvolvingProteus is ILiquidityPoolImplementation { pure returns (int256 roundedAmount) { - bool negative = amount < 0 ? true : false; + bool negative = amount < 0; uint256 absoluteValue = negative ? uint256(-amount) : uint256(amount); // FIXED_FEE * 2 because we will possibly deduct the FIXED_FEE from // this amount, and we don't want the final amount to be less than // the FIXED_FEE. - if (absoluteValue < FIXED_FEE * 2) revert AmountError(); + if (absoluteValue < FIXED_FEE + FIXED_FEE) revert AmountError(); - uint256 roundedAbsoluteAmount; + uint256 roundedAbsoluteAmount = absoluteValue +(absoluteValue / BASE_FEE); if (feeUp) { - roundedAbsoluteAmount = - absoluteValue + - (absoluteValue / BASE_FEE) + - FIXED_FEE; + roundedAbsoluteAmount += FIXED_FEE; require(roundedAbsoluteAmount < INT_MAX); - } else - roundedAbsoluteAmount = - absoluteValue - - (absoluteValue / BASE_FEE) - - FIXED_FEE; + } else { + roundedAbsoluteAmount -= FIXED_FEE; + } roundedAmount = negative ? -int256(roundedAbsoluteAmount)
#0 - c4-pre-sort
2023-08-30T02:13:28Z
0xRobocop marked the issue as sufficient quality report
#1 - 0xRobocop
2023-08-30T02:13:37Z
#2 - c4-judge
2023-09-11T20:06:38Z
JustDravee marked the issue as grade-b
#3 - JustDravee
2023-09-11T20:07:43Z
Report is lacking but "Sum opcode is cheaper than multiplication opcode;" is a unique finding hence grade B