1/5
_Follow along with this video:_ --- ### evm.codes Playground evm.codes provides us a brilliant [**playground**](https://www.evm.codes/playground) to test some this out and perform a sanity check on our math! We'll consider again our original value `0x0102`. If we `shr` by 4 we expect a hex output of `0x10`, which is `16` in decimal notation. > **Note:** We're able to convert our returned hex value into its decimal form with the command `cast --to-base 0x10 dec` Let's see how this works in the evm.codes playground! Recall what's required on our stack for our `shr` op code to function. `shr` takes `number of bits to shift` and the `32 bytes to shift`. These items need to be in our stack, in this order (top down). Our order of operations in the playground should look like this: ::image{src='/formal-verification-1/15-evm-playground/evm-playground-1.png' style='width: 100%; height: auto;'} By clicking `Run` in the playground we can then step through each op code and see how it affects our **memory**, **stack**, **storage** and **return values**. Stepping through our first operation, we can see that 102 is added to our stack. ::image{src='/formal-verification-1/15-evm-playground/evm-playground-2.png' style='width: 100%; height: auto;'} The second operation adds 4 to the top of our stack. ::image{src='/formal-verification-1/15-evm-playground/evm-playground-3.png' style='width: 100%; height: auto;'} And our final step leaves us with `10` on our stack. ::image{src='/formal-verification-1/15-evm-playground/evm-playground-4.png' style='width: 100%; height: auto;'} This is a hex value which we know we can convert using `cast --to-base 0x10 dec`. We indeed get 16! ### A Note On calldataload It's important to note that `calldataload` will only place **32 bytes** on the stack. This means, in our previous `calldata` example, **_the last 8 digits of our call data will not be included_** ``` 0xe026c0170000000000000000000000000000000000000000000000000000000000000001 Becomes 0xe026c01700000000000000000000000000000000000000000000000000000000 ``` Would that we needed to access the data further in the `calldata` string, that's when we would utilize an offset greater than 0!
A practical demonstration of EVM right shift operation using a playground. The lesson covers how to implement a right shift operation in a playground using various inputs and then checks the results by casting the value to base 10 decimal.
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