Much of the NFT code was inspired by Huffmate
-
High - 100xp
-
Medium - 20xp
-
Low - 2xp
-
Starts: January 11, 2024 Noon UTC
-
Ends: January 18, 2024 Noon UTC
- nSLOC:
- Solidity: 26
- Huff: 434
- Complexity Score:
- Solidity: 28
- Huff: 🐴
Neiiigghhhhhh
We are the equestrian lovers, and we LOVE all things horses! So we've created an NFT to commemorate our love of horses.
But, here is the thing, horses are fast and don't burn gas, but burn oats. So we wanted to make sure our codebase was hyper optimized, and to do so, we've written our contracts in Huff, a horse-themed assembly-like language so our code can be hyper-optimized and FAST.
🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎🐎
So, we wrote our codebase into 2 parts.
- The Solidity Rendition
- The Huff Rendition
Every function in the solidity rendition has been re-written in huff. We wrote it in solidity first to get a better understanding of what the codebase should do, and then optimized it in huff. We consider the solidity written code to be our reference code, and the huff code to be our actual code.
This setup was inspired by the Seaport protocol, which did something similar with solidity reference contracts, and assembly actual contracts.
Our contracts are simple, they allow the following functionality:
mintHorse
: Allow anyone to mint their own horse NFT.feedHorse
: Allow anyone to feed a horse NFT. This will add ablock.timestamp
to a mapping tracking when the horse was last fed.isHappyHorse
: Allow anyone to see if a horse is happy. A horse is happy if and only if they have been fed within the past 24 hours.
We consider the horse happiness the most important aspect of the codebase, and our invariants can be defined as follows:
If horse X has been fed within the past 24 hours, horse X must be happy.
Horses must be able to be fed at all times.
Even if you don't understand Huff... Maybe you can write some tests...
- Git
- You'll know you've done it right if you can run
git --version
- You'll know you've done it right if you can run
- Foundry / Foundryup
- This will install
forge
,cast
, andanvil
- You can test you've installed them right by running
forge --version
and get an output like:forge 0.2.0 (f016135 2022-07-04T00:15:02.930499Z)
- To get the latest of each, just run
foundryup
- This will install
- Huff Compiler
- You'll know you've done it right if you can run
huffc --version
and get an output like:huffc 0.2.0
- You'll know you've done it right if you can run
- Clone the repo & install dependencies
git clone https://github.com/Cyfrin/2024-01-horse-store
cd 2024-01-horse-store
make
- Run tests
forge test
- Commit Hash:
01bce4f0a2271c4105ee7c9121b27fe7973b0eaf
- In Scope: (For this contest, just use the main branch)
#-- HorseStore.huff
#-- HorseStore.sol
#-- IHorseStore.sol
- Solc Version:
0.8.20
- Chain(s) to deploy contract to:
- Arbitrum
- Ethereum
- Tokens:
- None
For this codebase, we consider any of the following to be in-scope:
- An issue with
HorseStore.sol
- An issue with
HorseStore.huff
- Any issue where
HorseStore.huff
functionality does not matchHorseStore.sol
functionality, not including gas costs, or specific storage slots. Sending any X calldata to either contract should result in them being in the same state.
- We understand that the exact 24 hour time frame for a horse to be happy can be manipulated on some chains. Please ignore any discrepancies in timestamps up to 120 seconds. If you find a way for a horse to be labelled incorrectly outside of a 120 second grace window, it should be considered a valid finding.
- We do not consider gas efficiency differences between the two valid findings.
- The exact error names can be different between the huff and solidity versions