Blur Exchange contest - shark'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: 53/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-14

External Links

Return named variables to save gas

You can have further gas savings by using named return values as a temporary local variable.

For example:

File: Pool.sol Line 83-85

function totalSupply() public view returns (uint256) { return address(this).balance; }

Instead of the above code, you can return a named variable like so:

function totalSupply() public view returns (uint256 supply) { supply = address(this).balance; }

Here are the rest of the instances found:

File: Exchange.sol Line 369 File: Exchange.sol Line 390 File: Exchange.sol Line 448 File: Exchange.sol Line 476 File: Exchange.sol Line 522 File: Exchange.sol Line 540 File: Exchange.sol Line 596 File: Pool.sol Line 60

x = x + y is more efficient than x += y (same for subtracting)

Using + instead of += saves around 113 gas.

There are 7 instances of this issue:

File: Exchange.sol (Line 316, Line 574, Line 601)

File: contracts/Exchange.sol 316: nonces[msg.sender] += 1; 574: remainingETH -= price; 601: totalFee += fee;

File: Pool.sol (Line 36, Line 46, Line 73, Line 74)

File: contracts/Pool.sol 36: _balances[msg.sender] += msg.value; 46: _balances[msg.sender] -= amount; 73: _balances[from] -= amount; 74: _balances[to] += amount;

Unnecessary variable cache

The following instance of state variable cache is unnecessary because remainingETH is referenced only once in the function.

File: Exchange.sol Line 213

212 function _returnDust() private { 213 uint256 _remainingETH = remainingETH; 214 assembly { 215 if gt(_remainingETH, 0) { 216 let callStatus := call( 217 gas(), 218 caller(), 219 selfbalance(), 220 0, 221 0, 222 0, 223 0 224 ) 225 } 226 } 227 }

Function Order Affects Gas Consumption

The order of the functions will have an impact on gas consumption. The reason why is that the order is dependent on the Method ID. Each function position will use up an extra 22 gas.

For more info visit this medium article

#0 - c4-judge

2022-11-17T14:14:18Z

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