Challenge - 5 Problems
Storage Layout Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Storage slot assignment in Solidity structs
Consider the following Solidity contract snippet. What will be the storage slot of the variable
c inside the struct Data?Blockchain / Solidity
pragma solidity ^0.8.0;
contract StorageTest {
struct Data {
uint128 a;
uint128 b;
uint256 c;
}
Data public data;
}Attempts:
2 left
💡 Hint
Remember that Solidity packs variables into 32-byte slots when possible.
✗ Incorrect
The struct has two uint128 variables (a and b) which fit together into slot 0. The uint256 variable c requires a full slot and is stored in slot 1.
❓ Predict Output
intermediate2:00remaining
Storage layout of dynamic arrays in Solidity
Given the following Solidity contract, what is the storage slot of the first element of the dynamic array
arr?Blockchain / Solidity
pragma solidity ^0.8.0;
contract ArrayStorage {
uint256[] public arr;
}Attempts:
2 left
💡 Hint
Dynamic arrays store their length at the declared slot, elements start at keccak256(slot).
✗ Incorrect
The array length is stored at slot 0. The elements start at the slot computed by keccak256(0).
🔧 Debug
advanced3:00remaining
Identify storage collision in upgradeable contracts
You have two versions of a Solidity contract. Version 1 has variables
uint256 x and uint256 y. Version 2 adds a new variable uint256 z before y. What problem arises with this change?Attempts:
2 left
💡 Hint
Changing variable order in upgradeable contracts can cause storage slot mismatches.
✗ Incorrect
Adding
z before y shifts y to a new slot, but existing storage still expects y at the old slot, causing z to overwrite y data.🧠 Conceptual
advanced2:30remaining
Storage layout of mappings in Solidity
How does Solidity compute the storage slot for a value in a mapping like
mapping(address => uint256) balances stored at slot 3?Attempts:
2 left
💡 Hint
Mapping storage uses keccak256 hash of the key concatenated with the slot.
✗ Incorrect
Solidity stores mapping values at keccak256 of the concatenation of the key and the mapping's slot number.
❓ Predict Output
expert3:00remaining
Storage layout with inheritance and variable shadowing
Consider these Solidity contracts:
pragma solidity ^0.8.0;
contract A {
uint256 public x = 1;
}
contract B is A {
uint256 public x = 2;
}
What is the value of B.x() when called?Attempts:
2 left
💡 Hint
Derived contracts can shadow base contract variables, but the derived variable is accessed.
✗ Incorrect
Contract B declares its own
x, which shadows A.x. Calling B.x() returns 2.