Platform: Code4rena
Start Date: 21/11/2022
Pot Size: $90,500 USDC
Total HM: 18
Participants: 101
Period: 7 days
Judge: Picodes
Total Solo HM: 4
Id: 183
League: ETH
Rank: 88/101
Findings: 1
Award: $39.65
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: gzeon
Also found by: 0xPanda, 0xSmartContract, B2, Deivitto, Diana, JohnSmith, PaludoX0, Rahoz, RaymondFam, ReyAdmirado, Rolezn, Schlagatron, Secureverse, Tomio, __141345__, adriro, ajtra, aphak5010, c3phas, chaduke, codeislight, cryptonue, datapunk, dharma09, halden, karanctf, keccak123, oyc_109, pavankv, sakshamguruji, saneryee, unforgiven
39.6537 USDC - $39.65
the equivalent of (a && b)
is !(!a || !b)
Even with the 10k Optimizer enabled, OR
conditions cost less than their equivalent AND
conditions.
Compare in Remix this example contract’s 2 diffs (or any test contract of your choice, as experimentation always shows the same results).
pragma solidity 0.8.13; contract Test { bool isOpen; bool channelPreviouslyOpen; function boolTest() external view returns (uint) { - if (isOpen && !channelPreviouslyOpen) { + if (!(!isOpen || channelPreviouslyOpen)) { return 1; - } else if (!isOpen && channelPreviouslyOpen) { + } else if (!(isOpen || !channelPreviouslyOpen)) { return 2; } } function setBools(bool _isOpen, bool _channelPreviouslyOpen) external { isOpen = _isOpen; channelPreviouslyOpen= _channelPreviouslyOpen; } }
effectively saving 12 gas.
It’s possible to save a significant amount of gas by replacing the &&
conditions with their ||
equivalent in the solution.
PirexRewards.sol#L385
PxGmxReward.sol#L115
Use if !(globalRewards == 0 || userRewards == 0)
instead of if (globalRewards != 0 && userRewards != 0)
97
gas than a constant every time they are called.Instances include:
Mark these as immutable
instead of constant
PxERC20.sol#
#L9: bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); #L10: bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
#L895 : function clearVoteDelegate() public onlyOwner {
Mark these as external
instead of public
#0 - c4-judge
2022-12-05T13:55:26Z
Picodes marked the issue as grade-b
#1 - drahrealm
2022-12-09T06:52:32Z
clearVoteDelegate
is also called internally thus the need for external
modifier.
#2 - c4-sponsor
2022-12-09T06:52:41Z
drahrealm marked the issue as sponsor disputed