Learn EVM Opcodes X
We focus on the relationship among SLOAD opcode and YUL’s offset and slot codes. We will learn how to use the Sload opcode and YUL’s offset and slot codes together.
We have 4 values .
Once our values are uint256, they cover one slot in the storage.
We use the Yul language to see the slot locations of the our values.
slotA := a.slot
slotB := b.slot
slotC := c.slot
slotD := d.slot
Bingo!
We use the Yul language to see the offset locations of the our values.
offsetA := a.offset
offsetB := b.offset
offsetC := c.offset
offsetD := d.offset
Bingo!
We can indicate this result as follows.
0x0000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000006
Note that both characters are 1 byte(offset);
Our variable 9 is on the 0th offset above the 0.slot,
Our variable 8 is on the 0th offset above the 1.slot,
Our variable 7 is on the 0th offset above the 2.slot,
Our variable 6 is on the 0th offset above the 3.slot.
Ok.
We have the new variables which are sized uint64.
This is the result.
Since all our state variables are uint64, we have packed them all into a single slot (slot 0).
loc := sload(a.slot) gives the following result. Remember “a.slot=0”
0x0000000000000006000000000000000700000000000000080000000000000009
Note that both characters are 1 byte(offset);
Our variable 9 is on the 0th offset above the 0.slot,
Our variable 8 is on the 8th offset above the 0.slot,
Our variable 7 is on the 16th offset above the 0.slot,
Our variable 6 is on the 24th offset above the 0.slot.