src/StakedCitadelVester.sol:138: require(_amount > 0, "StakedCitadelVester: cannot vest 0");
src/Funding.sol:170: require(_assetAmountIn > 0, "_assetAmountIn must not be 0");
src/Funding.sol:322: require(amount > 0, "nothing to sweep");
src/Funding.sol:340: require(amount > 0, "nothing to claim");
src/Funding.sol:424: require(_citadelPriceInAsset > 0, "citadel price must not be zero");
src/Funding.sol:452: require(_citadelPriceInAsset > 0, "citadel price must not be zero");
src/CitadelMinter.sol:343: require(length > 0, "CitadelMinter: no funding pools");
src/KnightingRound.sol:172: require(_tokenInAmount > 0, "_tokenInAmount should be > 0");
src/KnightingRound.sol:215: require(tokenOutAmount_ > 0, "nothing to claim");
src/KnightingRound.sol:411: require(amount > 0, "nothing to sweep");
Float multiplication optimization
We can use the following function to save gas on float multiplications
// out = x * y unchecked{/} z
function fmul(uint256 x, uint256 y, uint256 z) internal pure returns(uint256 out){
assembly{
if iszero(eq(div(mul(x,y),x),y)) {revert(0,0)}
out := div(mul(x,y),z)
}
}
> 0
is less efficient than!= 0
for uint in require conditionRef: https://twitter.com/GalloDaSballo/status/1485430908165443590
Float multiplication optimization
We can use the following function to save gas on float multiplications
e.g.
Cache vesting parameters
https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/StakedCitadelVester.sol#L108
Unchecked safe math
https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/Funding.sol#L175
https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/KnightingRound.sol#L198
Use custom errors
Solidity ^0.8.4 allow the use of custom errors to optimize gas usage. https://blog.soliditylang.org/2021/04/21/custom-errors/