Learn EVM Opcodes XI

Solidity Programming Language
3 min readApr 6, 2023

--

Mapping storage in solidity ! To get slot index of the mapping’s value under it is given the key.

Thank you Jesper!

We know that x variable is in the slot 0.

What do you think on finding key and value variables in storage ?

Mapping includes key and value variables and we need to know firstly mapping’s slot position.

In our code, mapping is in the slot 1.

Ok!

Secondly we need to know the key variable.

keccak256(uint mappingSlot, uint key) gives slot position of the value.

Remix time!

1- We add new mapping, key is 3 and value is 4 with addToM function.

2- We use readStorageSlot function but we cant find our value.

3-We use getLocationOfMapping function.Bingo. This is our mapping slot.

4- We use readStorageSlot function with newly long slot number. We found it !

5- Other example. We add new mapping, key is 9 and value is 8. Please remember, our mapping slot is 1.

6- We use getLocationOfMapping function.Bingo. This is our new mapping slot.

7- We use readStorageSlot function with newly newly long slot number. We found it !

NESTED MAPPING

1- We add our nested mapping values ! (3,4,5)

2- We find the first slot location.(1,3)

3- Last transaction is we use new slot and second key(4).

Click call!

4- Yes, you can put this slot location to the readStorageSlot function.

Associate Professor Engin YILMAZ (VeriDelisi)

--

--

Solidity Programming Language

Solidity basics for beginners: Learn the fundamentals of smart contract development and build your first DApp! #Solidity #Foundry #Ethereum #Opcodes #DApps