Open code423n4 opened 2 years ago
SLOAD
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.
splitterProxy
royaltyAsset
platformFeeRecipient
calldata
memory
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.
Change params memory to calldata
Custom errors from Solidity 0.8.4 are cheaper than require messages. https://blog.soliditylang.org/2021/04/21/custom-errors/
require
++i
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
== true
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
transfer
Gas Optimizations
Saving some
SLOAD
s insendToSplitter()
:https://github.com/code-423n4/2022-03-joyn/blob/main/royalty-vault/contracts/RoyaltyVault.sol#L31 cache
splitterProxy
,royaltyAsset
,platformFeeRecipient
insendToSplitter()
. each direct read of state vars cost 100 gas.Use
calldata
instead ofmemory
increateProject()
: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
tocalldata
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 thani++
: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 andrequire
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