Caviar contest - 0xAgro'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: 84/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-19

External Links

Gas Report

Finding Summary

IssueInstancesUser Savings (total avg)Deployment Savings (total avg)
[G-01]Value Not Pre-Calculated150280
[G-02]uint256 Iterator Checked Each Iteration7337968
[G-03]x += y Used For State Variables14660

[G-01] Value Not Pre-Calculated

Readability can be sacrificed for user gas savings. The value 160 - 4 * 4 can be pre-calculated to 144 and inlined to save gas.

Findings:

/src/lib/SafeERC20Namer.sol Links: 55.

55:	return Strings.toHexString(uint160(token) >> (160 - 4 * 4));

Suggested Change

55:	return Strings.toHexString(uint160(token) >> (144));

[G-02] uint256 Iterator Checked Each Iteration

A uint256 iterator will not overflow before the check variable overflows. Unchecking the iterator increment saves gas. Example

//From
for (uint256 i; i < len; ++i) {
	//Do Something
}
//To
for (uint256 i; i < len;) {
	//Do Something
	unchecked { ++i; }
}
Findings:

/src/Pair.sol Links: 238, 258, 468.

238:	for (uint256 i = 0; i < tokenIds.length; i++) {
258:	for (uint256 i = 0; i < tokenIds.length; i++) {
468:	for (uint256 i = 0; i < tokenIds.length; i++) {

/src/lib/SafeERC20Namer.sol Links: 13, 22, 33, 39.

13:	for (uint256 j = 0; j < 32; j++) {
22:	for (uint256 j = 0; j < charCount; j++) {
33:	for (uint256 i = 32; i < 64; i++) {
39:	for (uint256 i = 0; i < charCount; i++) {

[G-03] x += y Used

x = x + y is cheaper than x += y in some cases like below.

Findings:

/src/lib/SafeERC20Namer.sol Links: 35.

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

Suggested Change

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

#0 - c4-judge

2023-01-14T17:16:05Z

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