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
Rank: 28/72
Findings: 1
Award: $27.98
🌟 Selected for report: 0
🚀 Solo Findings: 0
27.9811 USDC - $27.98
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