1/5
_Follow along with this video:_ --- ### Bringing It Back To HorseStore Ok! With everything we've just learnt firmly understood, lets return to our `HorseStore.huff` contract. ```js #define macro MAIN() = takes(0) returns(0) { 0x00 // [0] calldataload // [calldata (32)] } ``` The `calldata` we've added to our stack is the first 32 bytes of the `calldata` sent to our contract. ``` 0xe026c01700000000000000000000000000000000000000000000000000000000 ``` We only need the `function selector`, or the first 4 bytes. In order to isolate this section of the `calldata` we will need to utilize `shr` to shift 28 bytes to the right. > **Remember:** `shr` takes the number of _bits_ to shift. 28 x 8 = 224 bits. Use `cast --to-base 224 hex` to glean that this number is `0xe0` in hexadecimal format. With that determined, let's add what we need to our contract. ```js #define macro MAIN() = takes(0) returns(0) { 0x00 // [0] calldataload // [calldata (32)] 0xe0 // [0xe0, calldata (32)] } ``` And our stack should look like this: ::image{src='/formal-verification-1/16-shr-calldata/shr-calldata-1.png' style='width: 100%; height: auto;'} Our final step to isolate the `function selector` from our received `call data` is going to be executing the `shr` operation, exciting! ```js #define macro MAIN() = takes(0) returns(0) { 0x00 // [0] calldataload // [calldata (32)] 0xe0 // [0xe0, calldata (32)] shr // [function_selector] } ``` The stack now: ::image{src='/formal-verification-1/16-shr-calldata/shr-calldata-2.png' style='width: 100%; height: auto;'} This is great! We finally have our `function selector` on the stack and we can finally start to do some function dispatching! See you in the next one!
A detailed explanation of the `SHR` opcode in Solidity. The lesson covers how to right shift a hexadecimal number in Solidity, how to determine the number of bits to shift by, and how to use the `SHR` opcode to perform a right shift of 224 bits.
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