Trick or Treat

First Flight #27
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Contract requires optimization to reduce gas costs

Summary

  1. it is a better know the number of treats we are adding to the constructor. As numerous additions can be computationally expensive in an unbounded loop.
    https://github.com/Cyfrin/2024-10-trick-or-treat/blob/9cb3955058cad9dd28a24eb5162a96d759bfa842/src/TrickOrTreat.sol#L29

  2. returning excess payments in function resolveTrick needs to be refactored such that excess payment is successful before sending nft to user and deleting state changes. while the whole transaction will revert if not successful, gas has already been spent. function also fails to follow Checks-Effect-interaction(CEI) and will easily be broken if not for the re-entrant modifier.
    https://github.com/Cyfrin/2024-10-trick-or-treat/blob/9cb3955058cad9dd28a24eb5162a96d759bfa842/src/TrickOrTreat.sol#L139

Impact

spending more gas

Tools Used

manual search

Recommendations

optimize code to follow CEI and use less gas

Updates

Appeal created

bube Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.