Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Default Function Dispatching Calls `totalSupply()`

Summary

The default function called (equivalent to Solidity's fallback()) when interacting with the Huff version of the HorseStore contract (HorseStore.huff) will call the logic of the totalSupply() function.

Vulnerability Details

Below is the code snippet where it is possible to see that the default function that will be called if no signature is matched will be GET_TOTAL_SUPPLY() which contains the logic of totalSupply().

dup1 __FUNC_SIG(balanceOf) eq balanceOf jumpi
dup1 __FUNC_SIG(ownerOf) eq ownerOf jumpi
totalSupply:
@> GET_TOTAL_SUPPLY()
...

Also, a default MINT_HORSE() is present at the end of the dispatching logic which doesn't really make sense:

ownerOf:
OWNER_OF()
@> MINT_HORSE()
}

Impact

Any user calling the contract with a random or empty function signature will be effectively calling totalSupply() instead of reverting.

Tools Used

Foundry and manual analysis.

Recommendations

It is recommended to add a failed dispatch logic when no function signature matches:

dup1 __FUNC_SIG(balanceOf) eq balanceOf jumpi
dup1 __FUNC_SIG(ownerOf) eq ownerOf jumpi
+ // Revert on failed dispatch
+ 0x00 dup1 revert
totalSupply:
GET_TOTAL_SUPPLY()

Also, make sure to also remove the last MINT_HORSE() function call at the end of the dispatching logic to avoid any future logic errors:

ownerOf:
OWNER_OF()
- MINT_HORSE()
}
Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

MAIN() macro is not properly implemented

Any call data sent to the contract that doesn't contain a function selector will randomly mint a horse.

Support

FAQs

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