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
Rank: 29/105
Findings: 3
Award: $184.91
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xNineDec
Also found by: 0x1f8b, 0x29A, 0x52, 0xDjango, 0xdanial, 0xf15ers, Cheeezzyyyy, Chom, Franfran, GalloDaSballo, Green, IllIllI, Meera, Ruhum, bardamu, cccz, codexploder, defsec, hake, hansfriese, horsefacts, hubble, hyh, jonatascm, kebabsec, oyc_109, pashov, rbserver, simon135, tabish, tintin, zzzitron
14.8726 USDC - $14.87
The currentPrice function in the contract JBChainlinkV3PriceFeed.sol fetches the asset price from a Chainlink aggregator using the latestRoundData function. However, there are no checks on roundID nor timeStamp, resulting in stale prices. The oracle wrapper calls out to a chainlink oracle receiving the latestRoundData(). It then checks freshness by verifying that the answer is indeed for the last known round. The returned updatedAt timestamp is not checked.
If there is a problem with chainlink starting a new round and finding consensus on the new value for the oracle (e.g. chainlink nodes abandon the oracle, chain congestion, vulnerability/attacks on the chainlink system) consumers of this contract may continue using outdated stale data (if oracles are unable to submit no new round is started)
Timestamp and Round ID are not checked in the function. That can also cause stale price.
Medium Severity Issue From The FEI Protocol : https://consensys.net/diligence/audits/2021/09/fei-protocol-v2-phase-1/#chainlinkoraclewrapper-latestrounddata-might-return-stale-results
Code Review
Consider to add checks on the return data with proper revert messages if the price is stale or the round is incomplete, for example:
(uint80 roundID, int256 price, , uint256 timeStamp, uint80 answeredInRound) = ETH_CHAINLINK.latestRoundData(); require(price > 0, "Chainlink price <= 0"); require(answeredInRound >= roundID, "..."); require(timeStamp != 0, "...");
Consider checking the oracle responses updatedAt value after calling out to chainlinkOracle.latestRoundData() verifying that the result is within an allowed margin of freshness.
#0 - mejango
2022-07-12T18:51:25Z
dup #138
🌟 Selected for report: IllIllI
Also found by: 0v3rf10w, 0x1f8b, 0x29A, 0xDjango, 0xNazgul, 0xNineDec, 0xdanial, 0xf15ers, Bnke0x0, Ch_301, Chandr, Chom, Funen, GimelSec, Hawkeye, JC, Kaiziron, Lambda, Meera, MiloTruck, Noah3o6, Picodes, ReyAdmirado, Rohan16, Sm4rty, TerrierLover, TomJ, Waze, _Adam, __141345__, asutorufos, aysha, berndartmueller, brgltd, cccz, codexploder, defsec, delfin454000, djxploit, durianSausage, fatherOfBlocks, hake, horsefacts, hubble, jayfromthe13th, joestakey, jonatascm, m_Rassska, oyc_109, pashov, rajatbeladiya, rbserver, robee, sach1r0, sahar, samruna, simon135, svskaushik, zzzitron
89.271 USDC - $89.27
The critical procedures should be two step process. The contracts inherit OpenZeppelin's Ownable contract which enables the onlyOwner role to transfer ownership to another address. It's possible that the onlyOwner role mistakenly transfers ownership to the wrong address, resulting in a loss of the onlyOwner role. The current ownership transfer process involves the current owner calling Unlock.transferOwnership(). This function checks the new owner is not the zero address and proceeds to write the new owner's address into the owner's state variable. If the nominated EOA account is not a valid account, it is entirely possible the owner may accidentally transfer ownership to an uncontrolled account, breaking all functions with the onlyOwner() modifier. Lack of two-step procedure for critical operations leaves them error-prone if the address is incorrect, the new address will take on the functionality of the new role immediately
for Ex : -Alice deploys a new version of the whitehack group address. When she invokes the whitehack group address setter to replace the address, she accidentally enters the wrong address. The new address now has access to the role immediately and is too late to revert
https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBPrices.sol#L20
Code Review
Lack of two-step procedure for critical operations leaves them error-prone. Consider adding two step procedure on the critical functions.
It is good to add a require() statement that checks the return value of token transfers or to use something like OpenZeppelin’s safeTransfer/safeTransferFrom unless one is sure the given token reverts in case of a failure. Failure to do so will cause silent failures of transfers and affect token accounting in contract.
Reference: This similar medium-severity finding from Consensys Diligence Audit of Fei Protocol: https://consensys.net/diligence/audits/2021/01/fei-protocol/#unchecked-return-value-for-iweth-transfer-call
Navigate to the following contract.
transfer/transferFrom functions are used instead of safe transfer/transferFrom on the following contracts.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol::87 => ? IERC20(token).transfer(_to, _amount) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol::88 => : IERC20(token).transferFrom(_from, _to, _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol::99 => IERC20(token).approve(_to, _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::271 => IERC20(_token).transferFrom(msg.sender, address(this), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::315 => IERC20(_token).transferFrom(msg.sender, address(this), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::364 => if (_token != JBTokens.ETH) IERC20(_token).approve(address(_terminal), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::412 => if (_token != JBTokens.ETH) IERC20(_token).approve(address(_terminal), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::256 => IERC20(_token).transferFrom(msg.sender, address(this), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::301 => IERC20(_token).transfer( juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::348 => IERC20(_token).transferFrom(msg.sender, address(this), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::384 => IERC20(_token).transfer( juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::493 => IERC20(_token).approve(address(_split.allocator), _splitAmount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::534 => IERC20(_token).transfer(
Code Review
Consider using safeTransfer/safeTransferFrom or require() consistently.
Missing checks for zero-addresses may lead to infunctional protocol, if the variable addresses are updated incorrectly.
https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol#L37
Code Review
Consider adding zero-address checks in the discussed constructors: require(newAddr != address(0));.
The protocol is using low level calls with solidity version 0.8.6 which can result in optimizer bug.
https://medium.com/certora/overly-optimistic-optimizer-certora-bug-disclosure-2101e3f7994d
https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHPaymentTerminal.sol#L25
Code Review
Consider upgrading to solidity 0.8.15.
Some tokens (like USDT L199) do not work when changing the allowance from an existing non-zero allowance value. They must first be approved by zero and then the actual allowance must be approved.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol::99 => IERC20(token).approve(_to, _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::493 => IERC20(_token).approve(address(_split.allocator), _splitAmount);
When trying to re-approve an already approved token, all transactions revert and the protocol cannot be used.
(https://github.com/code-423n4/2022-06-yieldy/blob/main/src/contracts/LiquidityReserve.sol#L81)
None
Approve with a zero amount first before setting the actual amount.
Block timestamps have historically been used for a variety of applications, such as entropy for random numbers (see the Entropy Illusion for further details), locking funds for periods of time, and various state-changing conditional statements that are time-dependent. Miners have the ability to adjust timestamps slightly, which can prove to be dangerous if block timestamps are used incorrectly in smart contracts.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol:206: if (block.timestamp >= _currentSplits[_i].lockedUntil) continue; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:162: if (fundingCycle.start > block.timestamp) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:230: if (!_isApproved(_projectId, _fundingCycle) || block.timestamp < _fundingCycle.start) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:332: uint256 _configuration = block.timestamp; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:340: _mustStartAtOrAfter > block.timestamp ? _mustStartAtOrAfter : block.timestamp juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:408: if (!_isApproved(_projectId, _baseFundingCycle) || block.timestamp < _baseFundingCycle.start) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:550: if (block.timestamp >= _fundingCycle.start) return 0; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:561: block.timestamp < _fundingCycle.start - _baseFundingCycle.duration juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:589: _fundingCycle.duration > 0 && block.timestamp >= _fundingCycle.start + _fundingCycle.duration juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:593: if (block.timestamp >= _fundingCycle.start) return _fundingCycle.configuration; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:602: block.timestamp >= _baseFundingCycle.start + _baseFundingCycle.duration juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:632: ? block.timestamp + 1 juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:633: : block.timestamp - _baseFundingCycle.duration + 1; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:815: else if (_ballotFundingCycle.ballot.duration() >= block.timestamp - _configuration) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/system_tests/TestTokenFlow.sol:64: block.timestamp,
Manual Code Review
Block timestamps should not be used for entropy or generating random numbers—i.e., they should not be the deciding factor (either directly or through some derivation) for winning a game or changing an important state.
Time-sensitive logic is sometimes required; e.g., for unlocking contracts (time-locking), completing an ICO after a few weeks, or enforcing expiry dates. It is sometimes recommended to use block.number and an average block time to estimate times; with a 10 second block time, 1 week equates to approximately, 60480 blocks. Thus, specifying a block number at which to change a contract state can be more secure, as miners are unable to easily manipulate the block number.
PrePo protocol do not appear to support rebasing/deflationary/inflationary tokens whose balance changes during transfers or over time. The necessary checks include at least verifying the amount of tokens transferred to contracts before and after the actual transfer to infer any fees/interest.
During the lending, If the inflationary/deflationary tokens are used excepted amount will be lower than deposit.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol::87 => ? IERC20(token).transfer(_to, _amount) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol::88 => : IERC20(token).transferFrom(_from, _to, _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol::99 => IERC20(token).approve(_to, _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::271 => IERC20(_token).transferFrom(msg.sender, address(this), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::315 => IERC20(_token).transferFrom(msg.sender, address(this), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::364 => if (_token != JBTokens.ETH) IERC20(_token).approve(address(_terminal), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::412 => if (_token != JBTokens.ETH) IERC20(_token).approve(address(_terminal), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::256 => IERC20(_token).transferFrom(msg.sender, address(this), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::301 => IERC20(_token).transfer( juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::348 => IERC20(_token).transferFrom(msg.sender, address(this), _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::384 => IERC20(_token).transfer( juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::493 => IERC20(_token).approve(address(_split.allocator), _splitAmount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::534 => IERC20(_token).transfer(
Manual Code Review
Defining initial values for variables when declaring them in a contract like in the code below does not work for upgradeable contracts.
Refer to explanation below:
Also, one should not leave the implementation contract uninitialized. None of the implementation contracts in the code base contains the code recommended by OpenZeppelin below, or an empty constructor with the initializer modifier.
Code Review
/// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); }
Refer to the link below:
The following contract functions performs an ERC20.approve() call but does not check the success return value. Some tokens do not revert if the approval failed but return false instead.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol::99 => IERC20(token).approve(_to, _amount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::493 => IERC20(_token).approve(address(_split.allocator), _splitAmount);
None
Its recommend to using OpenZeppelin’s SafeERC20 versions with the safeApprove function that handles the return value check as well as non-standard-compliant tokens.
#0 - drgorillamd
2022-07-12T21:59:34Z
This looks like a copy-paste of tooling with some "issues" not part of Juicebox codebase
🌟 Selected for report: 0xA5DF
Also found by: 0v3rf10w, 0x09GTO, 0x1f8b, 0x29A, 0xDjango, 0xKitsune, 0xNazgul, 0xdanial, 0xf15ers, Aymen0909, Bnke0x0, Ch_301, Cheeezzyyyy, Chom, ElKu, Funen, Hawkeye, IllIllI, JC, JohnSmith, Kaiziron, Lambda, Limbooo, Meera, Metatron, MiloTruck, Noah3o6, Picodes, Randyyy, RedOneN, ReyAdmirado, Rohan16, Saintcode_, Sm4rty, TomJ, Tomio, Tutturu, UnusualTurtle, Waze, _Adam, __141345__, ajtra, apostle0x01, asutorufos, brgltd, c3phas, cRat1st0s, codexploder, defsec, delfin454000, djxploit, durianSausage, exd0tpy, fatherOfBlocks, hake, horsefacts, ignacio, jayfromthe13th, joestakey, jonatascm, kaden, kebabsec, m_Rassska, mektigboy, mrpathfindr, oyc_109, rajatbeladiya, rbserver, rfa, robee, sach1r0, sashik_eth, simon135
80.7665 USDC - $80.77
[S]: Suggested optimation, save a decent amount of gas without compromising readability;
[M]: Minor optimation, the amount of gas saved is minor, change when you see fit;
[N]: Non-preferred, the amount of gas saved is at cost of readability, only apply when gas saving is a top priority.
> 0
can be replaced with != 0
for gas optimizationFor the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::438 => if (_terminals.length > 0) directory.setTerminalsOf(projectId, _terminals); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::498 => if (_terminals.length > 0) directory.setTerminalsOf(_projectId, _terminals); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::913 => for (uint256 _i = 0; _i < _splits.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::1014 => for (uint256 _i; _i < _fundAccessConstraints.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol::139 => for (uint256 _i; _i < _terminalsOf[_projectId].length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol::167 => for (uint256 _i; _i < _terminalsOf[_projectId].length; _i++) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol::274 => if (_terminals.length > 1) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol::275 => for (uint256 _i; _i < _terminals.length; _i++) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol::276 => for (uint256 _j = _i + 1; _j < _terminals.length; _j++) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::466 => for (uint256 i = 0; i < _splits.length; i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::85 => for (uint256 _i = 0; _i < _permissionIndexes.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::135 => for (uint256 _i = 0; _i < _operatorData.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::165 => for (uint256 _i = 0; _i < _indexes.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBProjects.sol::143 => if (bytes(_metadata.content).length > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSingleTokenPaymentTerminalStore.sol::862 => for (uint256 _i = 0; _i < _terminals.length; _i++) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::161 => // Push array length in stack juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::162 => uint256 _groupedSplitsLength = _groupedSplits.length; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::204 => for (uint256 _i = 0; _i < _currentSplits.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::211 => for (uint256 _j = 0; _j < _splits.length; _j++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::229 => for (uint256 _i = 0; _i < _splits.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::278 => // Set the new length of the splits. juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::279 => _splitCountOf[_projectId][_domain][_group] = _splits.length; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::300 => // Initialize an array to be returned that has the set length. juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol::194 => if (bytes(_name).length == 0) revert EMPTY_NAME(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol::197 => if (bytes(_symbol).length == 0) revert EMPTY_SYMBOL(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::590 => // Push array length in stack juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::591 => uint256 _heldFeeLength = _heldFees.length; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1008 => for (uint256 _i = 0; _i < _splits.length; ) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1392 => // Push length in stack juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1393 => uint256 _heldFeesLength = _heldFees.length;
None
Consider applying unchecked arithmetic where overflow/underflow is not possible. Example can be seen from below.
Unchecked{i++};
Since _amount can be 0. Checking if (_amount != 0) before the transfer can potentially save an external call and the unnecessary gas cost of a 0 token transfer.
https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol#L87
All Contracts
None
Consider checking amount != 0.
Uint is default initialized to 0. There is no need assign false to variable.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::85 => for (uint256 _i = 0; _i < _permissionIndexes.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::135 => for (uint256 _i = 0; _i < _operatorData.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::165 => for (uint256 _i = 0; _i < _indexes.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1008 => for (uint256 _i = 0; _i < _splits.length; ) {
Code Review
uint x = 0 costs more gas than uint x without having any different functionality.
Using double require instead of operator && can save more gas.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBOperatable.sol:99: msg.sender != _account && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBOperatable.sol:100: !operatorStore.hasPermission(msg.sender, _account, _domain, _permissionIndex) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBOperatable.sol:121: !_override && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBOperatable.sol:122: msg.sender != _account && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBOperatable.sol:123: !operatorStore.hasPermission(msg.sender, _account, _domain, _permissionIndex) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol:214: _splits[_j].percent == _currentSplits[_i].percent && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol:215: _splits[_j].beneficiary == _currentSplits[_i].beneficiary && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol:216: _splits[_j].allocator == _currentSplits[_i].allocator && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol:217: _splits[_j].projectId == _currentSplits[_i].projectId && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol:242: if (_token == IJBToken(address(0)) && requireClaimFor[_projectId]) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol:249: if (_token != IJBToken(address(0)) && _token.decimals() != 18) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol:265: if (_newOwner != address(0) && oldToken != IJBToken(address(0))) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol:293: bool _shouldClaimTokens = (requireClaimFor[_projectId] || _preferClaimedTokens) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol:134: _primaryTerminalOf[_projectId][_token] != IJBPaymentTerminal(address(0)) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol:219: (isAllowedToSetFirstController[msg.sender] && controllerOf[_projectId] == address(0))) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol:230: msg.sender != address(controllerOf[_projectId]) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol:231: controllerOf[_projectId] != address(0) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol:266: msg.sender != address(controllerOf[_projectId]) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBDirectory.sol:364: msg.sender != address(controllerOf[_projectId]) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:560: _baseFundingCycle.duration > 0 && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:589: _fundingCycle.duration > 0 && block.timestamp >= _fundingCycle.start + _fundingCycle.duration juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol:601: _baseFundingCycle.duration > 0 && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol:655: !_fundingCycle.mintingAllowed() && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol:656: !directory.isTerminalOf(_projectId, IJBPaymentTerminal(msg.sender)) && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol:736: _fundingCycle.burnPaused() &&
Code Review
Example
using &&: function check(uint x)public view{ require(x == 0 && x < 1 ); } // gas cost 21630 using double require: require(x == 0 ); require( x < 1); } } // gas cost 21622
Strict inequalities add a check of non equality which costs around 3 gas.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::438 => if (_terminals.length > 0) directory.setTerminalsOf(projectId, _terminals); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::481 => if (fundingCycleStore.latestConfigurationOf(_projectId) > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::498 => if (_terminals.length > 0) directory.setTerminalsOf(_projectId, _terminals); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::875 => if (_leftoverTokenCount > 0) tokenStore.mintFor(_owner, _projectId, _leftoverTokenCount, false); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::925 => if (_tokenCount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::1032 => if (_constraints.distributionLimit > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::1040 => if (_constraints.overflowAllowance > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::268 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::312 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::253 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::275 => if (_leftoverAmount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::345 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::367 => if (_leftoverAmount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::477 => if (_splitAmount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::149 => if (_standbyFundingCycleConfiguration > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::210 => if (_fundingCycleConfiguration > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::347 => _data.duration > 0 || juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::348 => _data.discountRate > 0 juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::364 => if (_metadata > 0) _metadataOf[_projectId][_configuration] = _metadata; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::469 => _weight = _weight > 0 juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::560 => _baseFundingCycle.duration > 0 && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::589 => _fundingCycle.duration > 0 && block.timestamp >= _fundingCycle.start + _fundingCycle.duration juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::601 => _baseFundingCycle.duration > 0 && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBProjects.sol::143 => if (bytes(_metadata.content).length > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSingleTokenPaymentTerminalStore.sol::475 => if (_currentOverflow > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSingleTokenPaymentTerminalStore.sol::518 => if (reclaimAmount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::259 => if (_splits[_i].lockedUntil > 0 || _splits[_i].allocator != IJBSplitAllocator(address(0))) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::272 => } else if (_packedSplitParts2Of[_projectId][_domain][_group][_i] > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::326 => if (_packedSplitPart2 > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol::356 => if (_unclaimedTokensToBurn > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol::367 => if (_claimedTokensToBurn > 0) _token.burn(_projectId, _holder, _claimedTokensToBurn); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::346 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::516 => if (balance > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::552 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::745 => if (_tokenCount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::772 => if (reclaimAmount > 0) _transferFrom(address(this), _beneficiary, reclaimAmount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::884 => if (netLeftoverDistributionAmount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::964 => if (netDistributedAmount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1022 => if (_payoutAmount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1297 => if (_tokenCount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/system_tests/TestDistributeHeldFee.sol::154 => if (fee > 0 && payAmountInWei > 0) {
Code Review
Use >= or <= instead of > and < when possible.
A division/multiplication by any number x being a power of 2 can be calculated by shifting log2(x) to the right/left.
While the DIV opcode uses 5 gas, the SHR opcode only uses 3 gas. Furthermore, Solidity's division operation also includes a division-by-0 prevention which is bypassed using shifting.
Contracts
None
A division/multiplication by any number x being a power of 2 can be calculated by shifting log2(x) to the right/left.
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::85 => for (uint256 _i = 0; _i < _permissionIndexes.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::135 => for (uint256 _i = 0; _i < _operatorData.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::165 => for (uint256 _i = 0; _i < _indexes.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1008 => for (uint256 _i = 0; _i < _splits.length; ) {
None
Consider to cache array length.
In some cases, having function arguments in calldata instead of memory is more optimal.
Consider the following generic example:
contract C { function add(uint[] memory arr) external returns (uint sum) { uint length = arr.length; for (uint i = 0; i < arr.length; i++) { sum += arr[i]; } } }
In the above example, the dynamic array arr has the storage location memory. When the function gets called externally, the array values are kept in calldata and copied to memory during ABI decoding (using the opcode calldataload and mstore). And during the for loop, arr[i] accesses the value in memory using a mload. However, for the above example this is inefficient. Consider the following snippet instead:
contract C { function add(uint[] calldata arr) external returns (uint sum) { uint length = arr.length; for (uint i = 0; i < arr.length; i++) { sum += arr[i]; } } }
In the above snippet, instead of going via memory, the value is directly read from calldata using calldataload. That is, there are no intermediate memory operations that carries this value.
Gas savings: In the former example, the ABI decoding begins with copying value from calldata to memory in a for loop. Each iteration would cost at least 60 gas. In the latter example, this can be completely avoided. This will also reduce the number of instructions and therefore reduces the deploy time cost of the contract.
In short, use calldata instead of memory if the function argument is only read.
Note that in older Solidity versions, changing some function arguments from memory to calldata may cause "unimplemented feature error". This can be avoided by using a newer (0.8.*) Solidity compiler.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/libraries/JBFundingCycleMetadataResolver.sol:11: function global(JBFundingCycle memory _fundingCycle) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/libraries/JBFundingCycleMetadataResolver.sol:14: returns (JBGlobalFundingCycleMetadata memory metadata) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/libraries/JBFundingCycleMetadataResolver.sol:19: function reservedRate(JBFundingCycle memory _fundingCycle) internal pure returns (uint256) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/libraries/JBFundingCycleMetadataResolver.sol:23: function redemptionRate(JBFundingCycle memory _fundingCycle) internal pure returns (uint256) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/libraries/JBFundingCycleMetadataResolver.sol:28: function ballotRedemptionRate(JBFundingCycle memory _fundingCycle) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/libraries/JBFundingCycleMetadataResolver.sol:37: function payPaused(JBFundingCycle memory _fundingCycle) internal pure returns (bool) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/libraries/JBFundingCycleMetadataResolver.sol:41: function distributionsPaused(JBFundingCycle memory _fundingCycle) internal pure returns (bool) {
None
Some parameters in examples given above are later hashed. It may be beneficial for those parameters to be in memory rather than calldata.
++i is more gas efficient than i++ in loops forwarding.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::85 => for (uint256 _i = 0; _i < _permissionIndexes.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::135 => for (uint256 _i = 0; _i < _operatorData.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBOperatorStore.sol::165 => for (uint256 _i = 0; _i < _indexes.length; _i++) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1008 => for (uint256 _i = 0; _i < _splits.length; ) {
Code Review
It is recommend to use unchecked{++i} and change i declaration to uint256.
> 0
can be replaced with != 0
for gas optimization!= 0
is a cheaper operation compared to > 0
, when dealing with uint.
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::438 => if (_terminals.length > 0) directory.setTerminalsOf(projectId, _terminals); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::481 => if (fundingCycleStore.latestConfigurationOf(_projectId) > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::498 => if (_terminals.length > 0) directory.setTerminalsOf(_projectId, _terminals); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::875 => if (_leftoverTokenCount > 0) tokenStore.mintFor(_owner, _projectId, _leftoverTokenCount, false); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::925 => if (_tokenCount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::1032 => if (_constraints.distributionLimit > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol::1040 => if (_constraints.overflowAllowance > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::268 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol::312 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::253 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::275 => if (_leftoverAmount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::345 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::367 => if (_leftoverAmount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20SplitsPayer.sol::477 => if (_splitAmount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::149 => if (_standbyFundingCycleConfiguration > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::210 => if (_fundingCycleConfiguration > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::347 => _data.duration > 0 || juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::348 => _data.discountRate > 0 juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::364 => if (_metadata > 0) _metadataOf[_projectId][_configuration] = _metadata; juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::469 => _weight = _weight > 0 juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::560 => _baseFundingCycle.duration > 0 && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::589 => _fundingCycle.duration > 0 && block.timestamp >= _fundingCycle.start + _fundingCycle.duration juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBFundingCycleStore.sol::601 => _baseFundingCycle.duration > 0 && juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBProjects.sol::143 => if (bytes(_metadata.content).length > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSingleTokenPaymentTerminalStore.sol::475 => if (_currentOverflow > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSingleTokenPaymentTerminalStore.sol::518 => if (reclaimAmount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::259 => if (_splits[_i].lockedUntil > 0 || _splits[_i].allocator != IJBSplitAllocator(address(0))) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::272 => } else if (_packedSplitParts2Of[_projectId][_domain][_group][_i] > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBSplitsStore.sol::326 => if (_packedSplitPart2 > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol::356 => if (_unclaimedTokensToBurn > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol::367 => if (_claimedTokensToBurn > 0) _token.burn(_projectId, _holder, _claimedTokensToBurn); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::346 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::516 => if (balance > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::552 => if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED(); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::745 => if (_tokenCount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::772 => if (reclaimAmount > 0) _transferFrom(address(this), _beneficiary, reclaimAmount); juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::884 => if (netLeftoverDistributionAmount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::964 => if (netDistributedAmount > 0) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1022 => if (_payoutAmount > 0) { juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol::1297 => if (_tokenCount > 0)
None
Consider to replace > 0
with != 0
for gas optimization.
The contracts assigns two constants to the result of a keccak operation, which results in gas waste since the expression is computed each time the constant is accessed.
See this issue for more context: ethereum/solidity#9232 (https://github.com/ethereum/solidity/issues/9232)
juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol:215: if (keccak256(abi.encodePacked(_memo)) != keccak256(abi.encodePacked(defaultMemo))) juice-contracts-v2-code4rena-828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHERC20ProjectPayer.sol:219: if (keccak256(abi.encodePacked(_metadata)) != keccak256(abi.encodePacked(defaultMetadata)))
None
Replace the constant directive with immutable, or assign the already hashed value to the constants.
Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks are available for free.
All Contracts
Solidity 0.8.10 has a useful change which reduced gas costs of external calls which expect a return value: https://blog.soliditylang.org/2021/11/09/solidity-0.8.10-release-announcement/
Solidity 0.8.13 has some improvements too but not well tested.
Code Generator: Skip existence check for external contract if return data is expected. In this case, the ABI decoder will revert if the contract does not exist
All Contracts
None
Consider to upgrade pragma to at least 0.8.10.