Juicebox contest - lukris02's results

The decentralized fundraising and treasury protocol.

General Information

Platform: Code4rena

Start Date: 18/10/2022

Pot Size: $50,000 USDC

Total HM: 13

Participants: 67

Period: 5 days

Judge: Picodes

Total Solo HM: 7

Id: 172

League: ETH

Juicebox

Findings Distribution

Researcher Performance

Rank: 25/67

Findings: 2

Award: $63.84

QA:
grade-b
Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

QA Report for Juicebox contest

Overview

During the audit, 1 low and 9 non-critical issues were found.

â„–TitleRisk RatingInstance Count
L-1Possible DoSLow4
NC-1Order of FunctionsNon-Critical7
NC-2Public functions can be externalNon-Critical7
NC-3Comment lines are too longNon-Critical10
NC-4No error message in requireNon-Critical2
NC-5Unused named return variablesNon-Critical4
NC-6Constants may be usedNon-Critical8
NC-7Missing NatSpecNon-Critical7
NC-8British English and American EnglishNon-Critical1
NC-9Typos and grammar errorsNon-Critical38

Low Risk Findings (1)

L-1. Possible DoS

Description

If the user adds too many tiers, four functions can run out of gas.

Instances
Recommendation

Add the check in this function to prevent the user from adding too many tiers.

Non-Critical Risk Findings (9)

NC-1. Order of Functions

Description

According to Style Guide, ordering helps readers identify which functions they can call and to find the constructor and fallback definitions easier.
Functions should be grouped according to their visibility and ordered:

  1. constructor
  2. receive function (if exists)
  3. fallback function (if exists)
  4. external
  5. public
  6. internal
  7. private

Within a grouping, place the view and pure functions last.

Instances

Constructor after functions:

External functions after public:

External functions between public:

Public functions between external:

Recommendation

Reorder functions where possible.

NC-2. Public functions can be external

Description

If functions are not called by the contract where they are defined, they can be declared external.

Instances
Recommendation

Make public functions external, where possible.

NC-3. Comment lines are too long

Instances
Recommendation

For readability, split comments across multiple lines.

NC-4. No error message in require

Instances

NC-5. Unused named return variables

Description

Both named return variable(s) and return statement are used.

Instances
Recommendation

To improve clarity use only named return variables.
For example, change:

function functionName() returns (uint id) { return x;

to

function functionName() returns (uint id) { id = x;

NC-6. Constants may be used

Description

Constants may be used instead of literal values.

Instances

For 58:

For 256:

NC-7. Missing NatSpec

Description

NatSpec is missing for 7 functions in 2 contracts.

Instances
Recommendation

Add NatSpec for all functions.

NC-8. British English and American English

Instances
Recommendation

Choose one.

NC-9. Typos and grammar errors

Instances

#0 - c4-judge

2022-11-04T14:52:29Z

Picodes marked the issue as grade-b

Awards

25.9629 USDC - $25.96

Labels

bug
G (Gas Optimization)
grade-b
G-30

External Links

Gas Optimizations Report for Juicebox contest

Overview

During the audit, 6 gas issues were found.
Total savings ~2030.

Gas Optimizations Findings (6)

G-1. Use unchecked blocks for incrementing i

Description

In Solidity 0.8+, there’s a default overflow and underflow check on unsigned integers. In the loops, "i" will not overflow because the loop will run out of gas before that.

Instances
Recommendation

Change:

for (uint256 i; i < n; ++i) { // ... }

to:

for (uint256 i; i < n;) { // ... unchecked { ++i; } }
Saved

This saves ~30-40 gas per iteration.
So, ~35*7 = 245

G-2. Use unchecked blocks for subtractions where underflow is impossible

Description

In Solidity 0.8+, there’s a default overflow and underflow check on unsigned integers. When an overflow or underflow isn’t possible (after require or if-statement), some gas can be saved by using unchecked blocks.

Instances
Saved

This saves ~35.
So, ~35*1 = 35

G-3. Use calldata instead of memory for read-only arguments

Description

Since Solidity v0.6.9, memory and calldata are allowed in all functions regardless of their visibility type (See "Calldata Variables" section here).
When function arguments should not be modified, it is cheaper to use calldata.

Instances
Recommendation

Use calldata where possible.

Saved

This saves at least 60 gas per iteration.
So, ~60*17 = 1020

G-4. Use inline function for internal function called once

Description

Function calls need two extra JUMP instructions and other stack operations.

Instances
Saved

This saves ~20-40. So, ~30*3 = 90

G-5. Cache state variables instead of reading them from storage multiple times

Description

Stack read is much cheaper than storage read.

Instances
Saved

This saves ~100.
So, ~100*6 = 600

G-6. Use local variable cache instead of accessing mapping or array multiple times

Description

It saves gas due to not having to perform the same key’s keccak256 hash and/or offset recalculation.

Instances
Saved

This saves ~40.
So, ~40*1 = 40

#0 - c4-judge

2022-11-08T18:06:40Z

Picodes marked the issue as 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