JPEG'd contest - sorrynotsorry's results

Bridging the gap between DeFi and NFTs.

General Information

Platform: Code4rena

Start Date: 07/04/2022

Pot Size: $100,000 USDC

Total HM: 20

Participants: 62

Period: 7 days

Judge: LSDan

Total Solo HM: 11

Id: 107

League: ETH

JPEG'd

Findings Distribution

Researcher Performance

Rank: 57/62

Findings: 1

Award: $80.91

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Awards

80.9074 USDC - $80.91

Labels

bug
G (Gas Optimization)
sponsor disputed

External Links

GAS OPTIMIZATIONS

  • Using both named returns and a return statement isn’t necessary Removing unused named returns variables can reduce gas usage (MSTOREs/MLOADs) and improve code clarity. To save gas and improve code quality: consider using only one of those. This can be found in the following; NFTEscrow.sol, LPFarming.sol, yVaultLPFarming.sol, CryptoPunksHelper.sol , EtherRocksHelper.sol, StrategyPUSDConvex.sol, Controller.sol, YVault.sol, FungibleAssetVaultForDAO.sol, NFTVault.sol

  • Strings are broken into 32 byte chunks for operations. Error strings in reverts more than 32 bytes consume more gas. Therefore, error messages less than 32 bytes shold be selected. If possible, custom error messages consume much more less and supported by Solidity ^0.8.0. E.g.

function mint(address to, uint256 amount) external {
        require(
            hasRole(MINTER_ROLE, _msgSender()),
            "JPEG: must have minter role to mint"
        );
        _mint(to, amount);
    }

Also the variable names more than 32 bytes is recommended to reduce to save more gas. Below is the list

At Controller.sol : inCaseStrategyTokensGetStuck() At NFTVault.sol : setInsuranceLiquidationPenaltyRate(), _validateCreditLimitAndLiquidationRate(),

  • By minimising the number of SLOADs which are expensive (100 gas) compared to MLOADs/MSTOREs (3 gas), SLOADs calls can be cached to memory variables to turn the proces into MLOADs. And prior to writing to storage again, those can also be cached back. Following contract sections are having this optimization;

    1. At LPFarming.sol, pendingReward method, cache the pool and the user to memory variables after initiliazing to save 6 SLOADs
    2. At LPFarming.sol, deposit method, cache the pool and the user to memory variables after initiliazing to save 3 SLOADs
    3. At LPFarming.sol, withdraw method, cache the pool and the user to memory variables after initiliazing to save 3 SLOADs
    4. At LPFarming.sol, _updatePool method, cache the pool to a memory variable after initiliazing to save 8 SLOADs
    5. At NFTVault.sol, borrow method, cache the position to a memory variable after initiliazing to save 9 SLOADs
  • 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. The optimization can be applied to following contract sections:

    1. At LPFarming.sol, claimAll method, caching poolInfo.length
    2. At StrategyPUSDConvex.sol, harvest method, caching rewardTokens.length
    3. Also using unchecked {++i} for all the iterations in the contracts will bring more gas saving (for >= 0.8).
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