Caviar contest - Breeje's results

A fully on-chain NFT AMM that allows you to trade every NFT in a collection.

General Information

Platform: Code4rena

Start Date: 12/12/2022

Pot Size: $36,500 USDC

Total HM: 8

Participants: 103

Period: 7 days

Judge: berndartmueller

Id: 193

League: ETH

Caviar

Findings Distribution

Researcher Performance

Rank: 86/103

Findings: 1

Award: $14.83

Gas:
grade-b

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Awards

14.833 USDC - $14.83

Labels

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

External Links

Report

Gas Optimizations

IssueInstances
GAS-1x += y costs more gas than x = x + y for state variables3
GAS-2Splitting require() statements that use && saves gas1
GAS-3Add Unchecked {} For Subtractions Where The Operands Cannot Underflow Because Of A Previous Require() Or If-statement1
GAS-4Functions Guaranteed To Revert When Called By Normal Users Can Be Marked Payable2

[GAS-1] x += y costs more gas than x = x + y for state variables

use = + or = - instead to save gas

Instances (3):

File: src/Pair.sol

448:             balanceOf[from] -= amount;

453:             balanceOf[to] += amount;

Link to code

File: src/lib/SafeERC20Namer.sol

35:             charCount += uint8(b[i]);

Link to code

[GAS-2] Splitting require() statements that use && saves gas

Saves 16 gas per instance. If you’re using the Optimizer at 200, instead of using the && operator in a single require statement to check multiple conditions, multiple require statements with 1 condition per require statement should be used to save gas.

Instances (1):

File: src/Pair.sol

71:             require(baseTokenAmount > 0 && fractionalTokenAmount > 0, "Input token amount is zero");

Link to code

[GAS-3] Add Unchecked {} For Subtractions Where The Operands Cannot Underflow Because Of A Previous Require() Or If-statement

The unchecked keyword can saves 30-40 gas per line.

Instances (1):

File: src/Pair.sol

168:             uint256 refundAmount = maxInputAmount - inputAmount;

Link to code

[GAS-4] Functions Guaranteed To Revert When Called By Normal Users Can Be Marked Payable

If a function modifier such as onlyOwner is used, the function will revert if a normal user tries to pay the function. Marking the function as payable will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.

Instances (2):

File: src/LpToken.sol

19:             function mint(address to, uint256 amount) public onlyOwner {

26:             function burn(address from, uint256 amount) public onlyOwner {

Link to code

#0 - c4-judge

2023-01-14T17:12:52Z

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