Redacted Cartel contest - dharma09's results

Boosted GMX assets from your favorite liquid token wrapper, Pirex - brought to you by Redacted Cartel.

General Information

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

Redacted Cartel

Findings Distribution

Researcher Performance

Rank: 88/101

Findings: 1

Award: $39.65

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

39.6537 USDC - $39.65

Labels

bug
G (Gas Optimization)
grade-b
sponsor disputed
G-21

External Links

1.OR CONDITIONS COST LESS THAN THEIR EQUIVALENT, AND CONDITIONS (“NOT(SOMETHING IS FALSE)” COSTS LESS THAN “EVERYTHING IS TRUE”)

the equivalent of (a && b) is !(!a || !b)

Even with the 10k Optimizer enabled, OR conditions cost less than their equivalent AND conditions.

Proof of Concept.

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.

Affected Code

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

MITIGATION

Use if !(globalRewards == 0 || userRewards == 0)instead of if (globalRewards != 0 && userRewards != 0)

2.Constant expressions are re-calculated each time it is in use, costing an extra 97 gas than a constant every time they are called.

PROOF OF CONCEPT

Instances include:

MITIGATION

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");

3. functions called by only the owner it's should be declared external instead of public

PirexGmx.sol

#L895 : function clearVoteDelegate() public onlyOwner {

MITIGATION

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

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