Canto contest - DijkstraDev'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: 33/37

Findings: 1

Award: $13.69

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

84.7394 CANTO - $13.69

Labels

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

External Links

  • Register function:

    • Replace the use of the Counter library by the use of a private variable of type uint256 see code.
      • register:
        • 157540 -> 157528 (-12 gas units).
      • currentCounterId:
        • 400 -> 362 (-38 gas units | 9.5 %)
      • deployment:
        • 1729845 -> 1725638 (-4162 gas units | ~ 0.24%)
  • Replace variable smartContract with direct use of msg.value L50, L69, L95, L97, L112 and L114

    • deployment:
      • 1725638 -> 1717231 (-8407 gas units | ~ 0.49%)
    • register:
      • 157528 -> 157484 (- 44 gas units | ~ 0.03%)
    • assign:
      • 44884 -> 44817 (-67 gas units | ~ 0.15%)
  • Assign:

    • Replace the use of _exist(_tokenId) with if(_tokenId >= _tokenIdTracker). The use that is given is only to know if the token is valid. It would fail in the event that the NFT was burned, although it is unlikely that the owner would do so of their own free will and in the event that it does, it would not cause any serious problems. The use of _exist(_tokenID) in the distributeFees function would be more useful see code
      • deployment:
        • 1717231 -> 1713424 ( -3807 gas units | ~ 0.22%)
      • assign:
        • 44817 -> 44714 (-103 gas units | ~ 0.23%)
  • Withdraw:

    • Swap the order of the If statements. This way if the earnedFee variable is zero, any value of _amount will be updated to zero. With this, we can simplify the now second If statement, which would look like this: if (_amount == 0) revert NothingToWithdraw() see code
      • 5173 -> 4673 (-500 gas units | ~ 9.67%)
      • deployment:
        • 1713424 -> 1711824 (-1600 gas units | ~ 0.09%)
    • Replace Address.sendValue(...) with _recipient.call{value: _amount}(""). Balance will always be limited to balance[_tokenId] see code.
      • 4673 -> 4484 (-189 gas units | ~ 4.05%)
      • deployment:
        • 1711824 -> 1672982 (-38842 gas units | ~ 2.27%)

Total (applying all the above points):

  • register -> -56 gas units | ~ 0.04%
  • currentCounterId -> -38 gas units | 9.5 %
  • assign -> -170 gas units | ~ 0.38%
  • withdraw -> -689 gas units | ~ 13.32%
  • deployment -> -56863 gas units | ~ 3.29%

#0 - c4-judge

2022-11-29T19:17:23Z

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