SHA3, CALLDATA, CALLDATALOAD, CALLVALUE, CODESIZE and GASLIMIT new opcodes. Today, in the fifth lesson of our series, as you can guess, we will dive into more boring and difficult opcode topics.
Keccak256 encrypts the desired(we want it) part of the data in memory. For this reason, we must first save the data to the memory. We do this with the MSTORE opcode. I will explain it in detail in the future.
What are offset and size in MSTORE opcode?
offset: byte offset in the memory.(The point on the memory where the data will start to be received)
size: byte size to read in the memory.
We saved 32 bytes of data to the memory.
PUSH1 4 (This is size)
PUSH1 0 (This is offset)
Then, starting from the 0th byte, we encrypted 4 bytes of data (FFFFFFFF) with Keccak256.
The result will be seen in the Stack screen.
I also confirmed the result with the keccak256 tool on the internet. Note that “hex” must be selected as input type when using this tool.
Calldata is actually a field/database like memory. See the following source to read the differences between memory and calldata. Now let’s see the 3 opcodes we will use in the calldata.
It is determined which byte of the data in the calldata will be transferred to the stack.
Our data is as follows.
By writing PUSH1 30, we requested the last two bytes to be pulled.
Result is DDEE
Returns the size of the calldata in bytes. It will return 0xFFEECC as 3.
destOffset: The data to be retrieved from calldata will be saved in memory starting from which byte
offset: Starting from which byte in calldata data will be received
size: Byte length to copy
PUSH1 2 (Byte length to be copied)
PUSH1 30 (Starting from which byte in Calldata data will be received)
PUSH1 0 (The data to be retrieved from Calldata will be saved in memory starting from which byte)
The result is DDEE .
It is exactly equal to the value of msg.value when we use the call function in solidity. The importance of the opcode for us is that we can send the value we want to the stack with this opcode.
This opcode measures the size of our code in bytes.
Why the result is 5?
PUSH2 (1 byte) 2227(2 byte)
POP (1 byte)
CODESIZE (1 byte)
Could you answer this question ?
The answer is 6.
This opcodes gives block gas limit number. 0xffffffffffff