Challenge - 5 Problems
Diamond Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Diamond Storage Access
Consider a Diamond contract using EIP-2535. Given the following Solidity snippet, what will be the output of the function
getValue() when called after deployment?contract DiamondStorage {
struct DS {
uint256 value;
}
bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.storage.example");
function diamondStorage() internal pure returns (DS storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly {
ds.slot := position
}
}
function setValue(uint256 _value) external {
DS storage ds = diamondStorage();
ds.value = _value;
}
function getValue() external view returns (uint256) {
DS storage ds = diamondStorage();
return ds.value;
}
}Blockchain / Solidity
DiamondStorage ds = new DiamondStorage();
ds.setValue(42);
uint256 result = ds.getValue();Attempts:
2 left
💡 Hint
Think about how the diamond storage pattern uses a fixed storage slot to keep data consistent across facets.
✗ Incorrect
The diamond storage pattern uses a fixed storage slot identified by a hash to store data. Setting the value to 42 stores it in that slot, so calling getValue() returns 42.
🧠 Conceptual
intermediate1:30remaining
Facet Function Selector Collision
In the Diamond pattern (EIP-2535), what happens if two facets added to the diamond have functions with the same selector?
Choose the correct behavior:
Choose the correct behavior:
Attempts:
2 left
💡 Hint
Think about how the diamond manages function selectors in its mapping.
✗ Incorrect
In EIP-2535, when adding facets, if a function selector already exists, the new facet's function selector overwrites the previous one in the diamond's selector-to-facet mapping.
🔧 Debug
advanced2:30remaining
Debugging Diamond Cut Failure
You try to add a new facet to your diamond contract using the diamondCut function, but the transaction reverts with an error related to function selectors.
Given this diamondCut call snippet:
What is the most likely cause of the revert?
Given this diamondCut call snippet:
diamondCut(
[
{
facetAddress: newFacetAddress,
action: FacetCutAction.Add,
functionSelectors: [bytes4(keccak256("foo()")), bytes4(keccak256("bar()"))]
}
],
address(0),
""
);What is the most likely cause of the revert?
Attempts:
2 left
💡 Hint
Check if the facet contract actually has the functions matching the selectors you want to add.
✗ Incorrect
The diamondCut function verifies that the facet address implements all function selectors being added. If any selector does not correspond to a function in the facet, the call reverts.
📝 Syntax
advanced2:00remaining
Correct Solidity Syntax for Diamond Storage
Which of the following Solidity code snippets correctly implements the diamond storage pattern to access a struct stored at a fixed storage slot?
Attempts:
2 left
💡 Hint
Remember the correct assembly syntax to assign a storage slot to a variable.
✗ Incorrect
The correct syntax uses 'ds.slot := position' to assign the storage slot. Using '=' or missing '.slot' causes errors or incorrect behavior.
🚀 Application
expert3:00remaining
Number of Function Selectors in Diamond
You have a diamond contract with 3 facets added. Facet A has 5 functions, Facet B has 3 functions, and Facet C has 4 functions. Facet B and Facet C share 1 function selector (same function signature).
How many unique function selectors does the diamond contract have after adding all three facets?
How many unique function selectors does the diamond contract have after adding all three facets?
Attempts:
2 left
💡 Hint
Count all functions, then subtract duplicates due to shared selectors.
✗ Incorrect
Total functions: 5 + 3 + 4 = 12. One selector is shared between Facet B and C, so it counts once. Unique selectors = 12 - 1 = 11.