Trick or Treat

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

Functions Could Be Declared as `external` Instead of `public`

Description:

Functions that are not called internally within the contract can be marked as external to optimize gas usage.

Instances:

  1. setTreatCost Function (Line 43):

    function setTreatCost(string memory _treatName, uint256 _cost) public onlyOwner {
  2. trickOrTreat Function (Line 48):

    function trickOrTreat(string memory _treatName) public payable nonReentrant {
  3. resolveTrick Function (Line 118):

    function resolveTrick(uint256 tokenId) public payable nonReentrant {
  4. withdrawFees Function (Line 146):

    function withdrawFees() public onlyOwner {
  5. getTreats Function (Line 152):

    function getTreats() public view returns (string[] memory) {
  6. changeOwner Function (Line 156):

    function changeOwner(address _newOwner) public onlyOwner {

Impact:

  • Gas Efficiency:

    • Declaring functions as external can reduce gas consumption when the functions are called externally.

    • The Solidity compiler optimizes external function calls by avoiding unnecessary copying of arguments to memory.

Recommendation:

  • Update Function Visibility:

    • Change the visibility of functions not used internally from public to external.

      function setTreatCost(string memory _treatName, uint256 _cost) external onlyOwner {
  • Ensure No Internal Calls:

    • Verify that the functions are not called from within the contract before changing their visibility.

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.