Blur Exchange contest - Rahoz's results

An NFT exchange.

General Information

Platform: Code4rena

Start Date: 11/11/2022

Pot Size: $36,500 USDC

Total HM: 5

Participants: 62

Period: 3 days

Judge: berndartmueller

Id: 181

League: ETH

Blur Exchange

Findings Distribution

Researcher Performance

Rank: 56/62

Findings: 1

Award: $22.22

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

22.2155 USDC - $22.22

Labels

bug
G (Gas Optimization)
grade-b
G-16

External Links

USING EXTERNAL RATHER THAN PUBLIC FOR FUNCTIONS, SAVES GAS

Some functions only call by external should declare at external visibility.

Proof of Concept

https://github.com/code-423n4/2022-11-non-fungible/blob/323b7cbf607425dd81da96c0777c8b12e800305d/contracts/Pool.sol#L58 https://github.com/code-423n4/2022-11-non-fungible/blob/323b7cbf607425dd81da96c0777c8b12e800305d/contracts/Pool.sol#L44

Use ++ instead of += 1

In function incrementNonce we should use ++ to save gas

Proof of Concept

https://github.com/code-423n4/2022-11-non-fungible/blob/323b7cbf607425dd81da96c0777c8b12e800305d/contracts/Exchange.sol#L316

function incrementNonce() external {
    ++nonces[msg.sender];
    emit NonceIncremented(msg.sender, nonces[msg.sender]);
}

Should switch between non-zero and non-zero instead of zero and non-zero

Variable Exchange.isOpen now switch between 0-1 We should consider to change it to 1-2 because convert from non-zero to non-zero is cheaper than non-zero to zero According to EIP-1087: https://eips.ethereum.org/EIPS/eip-1087, it take 20,000 gas to set a slot from 0 to non-zero with SSTORE while it takes only 5000 gas for any other change

Proof of Concept

https://github.com/code-423n4/2022-11-non-fungible/blob/323b7cbf607425dd81da96c0777c8b12e800305d/contracts/Exchange.sol#L56-L63

uint256 public isOpen = 1;
modifier whenOpen() {
    require(isOpen == 2, "Closed");
    _;
}
function open() external onlyOwner {
    isOpen = 2;
    emit Opened();
}
function close() external onlyOwner {
    isOpen = 1;
    emit Closed();
}

#0 - c4-judge

2022-11-17T14:12:43Z

berndartmueller marked the issue as grade-b

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