Juicebox V2 contest - djxploit's results

The decentralized fundraising and treasury protocol.

General Information

Platform: Code4rena

Start Date: 01/07/2022

Pot Size: $75,000 USDC

Total HM: 17

Participants: 105

Period: 7 days

Judge: Jack the Pug

Total Solo HM: 5

Id: 143

League: ETH

Juicebox

Findings Distribution

Researcher Performance

Rank: 62/105

Findings: 2

Award: $127.43

🌟 Selected for report: 0

🚀 Solo Findings: 0

  1. In File : https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol: Below mappings can be converted to a struct, which will optimize gas usage.
mapping(uint256 => IJBToken) public override tokenOf; mapping(uint256 => uint256) public override unclaimedTotalSupplyOf; mapping(uint256 => bool) public override requireClaimFor;
  1. In https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L448, we can use _unclaimedBalance in place of unclaimedBalanceOf[_holder][_projectId] to save gas. So the line will be unclaimedBalanceOf[_holder][_projectId] = _unclaimedBalance - _amount; These same optimisations are also applicable in https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L409 and https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L406

In line https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L359, unclaimedBalanceOf[_holder][_projectId] can be replaced by _unclaimedBalance to save gas.

  1. Use of >= or <= is cheaper than > or < in terms of gas : https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L445

  2. In line https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L356 and https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L367 , the if comparison with 0 can be modified as below to save gas: if (_unclaimedTokensToBurn) { and if (_claimedTokensToBurn)

In line , https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol#L149, 0-comparison if clause can be modified as : if (_standbyFundingCycleConfiguration)

Line : https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol#L210 , can be modified as : if (_fundingCycleConfiguration) {

  1. Use of unchecked:

Also in same line, unchecked can be used in the subtraction operation, as we know _amount < _unclaimedBalance as depicted by the if clause in #L445

In line https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L350, we can use unchecked in the substraction as the if clause specifies that _unclaimedBalance < _amount, so no chance of underflowing.

In line https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L353 also, we can use unchecked , because the subtraction can never underflow. Because from the if-else statements in betweeen #L344 and #L350 , it is clear that value of _claimedTokensToBurn will always be less than or equal to _amount but can never be greater.

  1. Multiple returns: https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol#L86-L93

https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol#L136-L181

https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol#L194-L245

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