Juicebox Buyback Delegate - K42's results

Thousands of projects use Juicebox to fund, operate, and scale their ideas & communities transparently on Ethereum.

General Information

Platform: Code4rena

Start Date: 18/05/2023

Pot Size: $24,500 USDC

Total HM: 3

Participants: 72

Period: 4 days

Judge: LSDan

Id: 237

League: ETH

Juicebox

Findings Distribution

Researcher Performance

Rank: 28/72

Findings: 1

Award: $27.98

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: JCN

Also found by: 0x4non, Arz, Dimagu, K42, QiuhaoLi, Sathish9098, Tripathi, hunter_w3b, niser93, pfapostol

Labels

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

Awards

27.9811 USDC - $27.98

External Links

Gas(mana) Optimization Report by K42

Possible Optimizations in JBXBuybackDelegate.sol

Scope = https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol

Possible Optimization 1 = Lines referenced: #L150(https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#L150) and #L278(https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#L278) -- In two separate functions, you're using PRBMath.mulDiv for calculating _tokenCount Although this is a safe operation, it's also more gas costly due to its internal complexity. If you can be sure that an overflow won't happen, replacing it with basic multiplication and division would save gas. Change uint256 _tokenCount = PRBMath.mulDiv(_data.amount.value, _data.weight, 10 ** 18); To uint256 _tokenCount = (_data.amount.value * _data.weight) / 10 ** 18;

Estimated gas savings for this change: ~5,000 to 10,000 gas ✅

Possible Optimization 2 = Lines referenced: #LL335C5-L335C5(https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#LL335C5-L335C5) and #L290 (https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#L290) -- In the _mint and _swap functions, the statement jbxTerminal.directory().controllerOf(_data.projectId)` is used twice. Repeated external calls can be inefficient and cost more gas. You could save some gas by storing the result in a local variable after the first call and reusing it. Suggested change: IJBDirectory directory = jbxTerminal.directory(); IJBController controller = IJBController(directory.controllerOf(_data.projectId));``

-- Estimated gas savings for this change: ~2,000 to 3,000 gas ✅

Possible Optimization 3 = Lines referenced: #LL106C2-L113C38 (https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#LL106C2-L113C38)

-- You're setting mintedAmount and reservedRate to 1 in multiple places. SSTORE operations are expensive in terms of gas, and if these variables are already set to 1, you're incurring unnecessary gas costs. Consider updating these values only when they have changed. Suggested change: if (mintedAmount != 1) mintedAmount = 1; if (reservedRate != 1) reservedRate = 1;

-- Estimated gas savings for this change: ~20,000 gas saved per avoided SSTORE operation ✅

#0 - c4-judge

2023-06-02T12:26:03Z

dmvt 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