code-423n4 / 2022-03-joyn-findings

4 stars 1 forks source link

Gas Optimizations #70

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Gas Optimizations

Saving some SLOADs in sendToSplitter():

https://github.com/code-423n4/2022-03-joyn/blob/main/royalty-vault/contracts/RoyaltyVault.sol#L31 cache splitterProxy, royaltyAsset, platformFeeRecipient in sendToSplitter(). each direct read of state vars cost 100 gas.

Use calldata instead of memory in createProject():

https://github.com/code-423n4/2022-03-joyn/blob/main/core-contracts/contracts/CoreFactory.sol#L72

For external function's dynamic params, calldata is the cheapest location to use.

Recommended Mitigation Steps:

Change params memory to calldata

Use Custom Errors to save Gas:

Custom errors from Solidity 0.8.4 are cheaper than require messages. https://blog.soliditylang.org/2021/04/21/custom-errors/

++i use less gas than i++:

https://github.com/code-423n4/2022-03-joyn/blob/main/core-contracts/contracts/CoreCollection.sol#L279 https://github.com/code-423n4/2022-03-joyn/blob/main/core-contracts/contracts/CoreFactory.sol#L79 https://github.com/code-423n4/2022-03-joyn/blob/main/splits/contracts/Splitter.sol#L50 https://github.com/code-423n4/2022-03-joyn/blob/main/splits/contracts/Splitter.sol#L274

Redundant == true in require:

transfer return boolean and require expect a boolean. so removing these == true can save some gas: https://github.com/code-423n4/2022-03-joyn/blob/main/royalty-vault/contracts/RoyaltyVault.sol#L44 https://github.com/code-423n4/2022-03-joyn/blob/main/royalty-vault/contracts/RoyaltyVault.sol#L48 https://github.com/code-423n4/2022-03-joyn/blob/main/royalty-vault/contracts/RoyaltyVault.sol#L55