Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

[L-1] Public Functions Not Used Internally Should Be External for Efficiency

Summary

Several functions in the EggVault contract are declared as public but are not called internally. These functions should be marked as external to reduce gas usage and bytecode size, improving contract efficiency without changing behavior.

Vulnerability Details

In Solidity, public functions are accessible both internally and externally, which causes the compiler to generate both an external and internal function wrapper. When a function is only ever called externally, this extra wrapper is unnecessary.

The following functions in EggVault.sol are only intended to be called by users or other contracts:

function depositEgg(uint256 tokenId, address depositor) public { ... }
function withdrawEgg(uint256 tokenId) public { ... }
function isEggDeposited(uint256 tokenId) public view returns (bool) { ... }

Because none of these are called from within the same contract, they can and should be declared external to optimize for gas and bytecode.

Impact

  • Using public generates both internal and external function wrappers.

  • Slight increase in contract size.

  • While minor, these changes can slightly reduce deployment and call costs.

Tools Used

  • Manual code review

  • Aderyn

Recommendations

Change the following function signatures in EggVault.sol:

- function depositEgg(uint256 tokenId, address depositor) public {
+ function depositEgg(uint256 tokenId, address depositor) external {
- function withdrawEgg(uint256 tokenId) public {
+ function withdrawEgg(uint256 tokenId) external {
- function isEggDeposited(uint256 tokenId) public view returns (bool) {
+ function isEggDeposited(uint256 tokenId) external view returns (bool) {
Updates

Lead Judging Commences

m3dython Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Out of scope
Assigned finding tags:

Gas optimization

Strategy to save gas and minimize transaction costs

Support

FAQs

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