01 - ReturnBool
Goal: Return a boolean value (true
or false
) from the Yul assembly block.
In Yul, to return data we must explicitly store the value in memory and use the return
opcode with a pointer and size. Booleans in the EVM are represented as 32-byte values (1 for true, 0 for false). To return true
, we store 1 in memory and return 32 bytes; for false
, we store 0.
Why not use free memory pointer?
In this scenario we just overwrite the scratch space with a single byte, it will not overwritten important memory regions. In future levels we will use free memory pointer if the data is long.
Run test:
Last updated