1/5
_Follow along with this video:_ --- Ok, this is exciting. By this point we should have a working macro, that allows us to set a value to our numberOfHorses variable and save it to storage! In future we'll go through how you can test these things in Foundry, but for now - let's head back to evm.codes and try out our function in the playground. Remember how to get your contracts bytecode: `huffc src/HorseStoreV1/HorseStore.huff --bin-runtime` Paste the output into the playground's provided workspace and assure you've entered calldata which contains our valid function selector in the field to the bottom left. By stepping through each line of execution we can clearly trace what's happening with our function call. Here's an example of valid call data to set our number of horses to 7 and the call trace we can expect: ``` 0xcdfead2e0000000000000000000000000000000000000000000000000000000000000007 ``` ::image{src='/formal-verification-1/32-testing-macro-evm-codes/testing-macro-evm-codes-1.png' style='width: 100%; height: auto;'} I want to draw you attention to the `stop` op code I've added near the end. This code is an imperative aspect of handling functions in Huff. Code doesn't know when you want it to start and stop, it'll keep running until the application runs out of code. The `stop` op code affords a developer the power to explicitly tell the EVM 'We're done here, this execution is complete. This will prevent our code from continuing to run subsequent operations after completion our function call! This is amazing! What you'll find when we decompile our Solidity version of Horse Store, is that what we've just built out in Huff is effectively what Solidity is doing for us under the hood. Great work! Let's look at how to add the logic of our `getNumberOfHorses` function.
A practical guide to building a function in Huff and understand how its bytecode functions - This lesson covers how to build a function using Huff to update the number of horses in a smart contract using raw EVM bytecode. It also demonstrates how to test the function using the EVM.codes playground.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Assembly
Writing smart contracts using Huff and Yul
Ethereum Virtual Machine OPCodes
Formal verification testing
Smart contract invariant testing
Halmos, Certora, Kontrol
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Josselin Feist
Head of Blockchain at Trail of Bits
Last updated on January 17, 2025
Solidity Developer
Assembly and Formal VerificationDuration: 30min
Duration: 4h 38min
Duration: 3h 57min
Duration: 1h 56min
Course Overview
About the course
Assembly
Writing smart contracts using Huff and Yul
Ethereum Virtual Machine OPCodes
Formal verification testing
Smart contract invariant testing
Halmos, Certora, Kontrol
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Josselin Feist
Head of Blockchain at Trail of Bits
Last updated on January 17, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar