Canto contest - Beepidibop's results

Execution layer for original work.

General Information

Platform: Code4rena

Start Date: 23/11/2022

Pot Size: $24,500 CANTO

Total HM: 5

Participants: 37

Period: 5 days

Judge: berndartmueller

Total Solo HM: 2

Id: 185

League: ETH

Canto

Findings Distribution

Researcher Performance

Rank: 10/37

Findings: 1

Award: $207.65

Gas:
grade-a

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

1285.7408 CANTO - $207.65

Labels

bug
G (Gas Optimization)
grade-a
edited-by-warden
G-05

External Links

Gas Optimization Report

I found 3 different changes that can reduce gas usage for Turnstile.sol

  1. Deprecate Counter and use totalSupply for tokenId when minting
  2. Refactor withdraw()'s logic for updating balances[_tokenId]
  3. Deprecate NftData, use tokenId to check for registration instead (This also starts tokenId at 1 instead of 0)

#3 requires structural changes. However, I have not seen NftData actually referenced by external contract, code, or test cases, so I included it as a serparate branch for the team to consider.

The two branches can be found here:

Here are the gas reports:

Original:

Deployment CostDeployment Size
17298458915
Function Nameminavgmedianmax# calls
assign558448844656446564152
balanceOf6296426292629150
balances5281028528252812
currentCounterId3744003742374300
distributeFees5131224212122240726
getTokenId8798968792671303
isRegistered661661661661300
owner24212421242124211
ownerOf6246376242649150
register656157578161436163436155
transferFrom420154201542015420151
withdraw76044949692994811

Gas Savings Without Structural Change:

Compared to Original:

Function Nameminavgmedianmax# calls
register656157578 -> 156224 (-1354)161436 -> 161209 (-227)163436 -> 163209 (-227)155
withdraw7604494 -> 4666 (+172)96929948 -> 29878 (-70)11

Details

Deployment CostDeployment Size
17298458915
Function Nameminavgmedianmax# calls
assign558448844656446564152
balanceOf6296426292629150
balances5281028528252812
currentCounterId3744003742374300
distributeFees5131224212122240726
getTokenId8798968792671303
isRegistered661661661661300
owner24212421242124211
ownerOf6246376242649150
register656156224161209163209155
transferFrom420154201542015420151
withdraw76046669692987811

Gas Savings With Structural Change:

Compared to Original:

Function Nameminavgmedianmax# calls
assign558 -> 504 (-54)44884 -> 23616 (-21268)46564 -> 24184 (-22380)46564 -> 24184 (-22380)152
currentCounterId374 -> 449 (+75)400 -> 475 (+75)374 -> 449 (+75)2374 -> 2449 (+75)300
getTokenId879 -> 837 (-42)896 -> 854 (-42)879 -> 837 (-42)2671 -> 2629 (-42)303
isRegistered661 -> 643 (-18)661 -> 643 (-18)661 -> 643 (-18)661 -> 643 (-18)300
register656 -> 602 (-54)157578 -> 137290 (-20288)161436 -> 138907 (-22529)163436 -> 142907 (-20529)155
withdraw7604494 -> 4481 (-13)96929948 -> 29878 (-70)11

| currentCounterId | 374 | 400 | 374 | 2374 | 300 | | currentCounterId | 449 | 475 | 449 | 2449 | 300 |

| currentCounterId| 374 -> 449 (75)|400 -> 475 (75)|374 -> 449 (75)|2374 -> 2449 (75)|

Details

Deployment CostDeployment Size
17308458920
Function Nameminavgmedianmax# calls
assign504236162418424184152
balanceOf6296426292629150
balances5281028528252812
currentCounterId4494754492449300
distributeFees5131224212122240726
getTokenId8378548372629303
isRegistered643643643643300
owner24212421242124211
ownerOf6246376242649150
register602137290138907142907155
transferFrom420154201542015420151
withdraw76044819692987811

#0 - c4-judge

2022-11-29T19:53:40Z

berndartmueller marked the issue as grade-a

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