Shell Protocol - 0x4non's results

A set of EVM-based smart contracts on Arbitrum One. In a nutshell it is DeFi made simple.

General Information

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

Shell Protocol

Findings Distribution

Researcher Performance

Rank: 27/43

Findings: 1

Award: $22.46

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Labels

bug
G (Gas Optimization)
grade-b
sufficient quality report
G-07

Awards

22.4575 USDC - $22.46

External Links

Gas

_applyFeeByRounding(int256 amount, bool feeUp) cand be optimized

Simplify negative variable

Instead of;

bool negative = amount < 0 ? true : false;

Use this;

bool negative = amount < 0;

Sum opcode is cheaper than multiplication opcode;

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);

Recommendation

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

  1. Invalid

#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

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter