0
0
Blockchain / Solidityprogramming~10 mins

Proxy pattern (upgradeable contracts) in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the proxy contract's storage variable for the implementation address.

Blockchain / Solidity
address public [1];
Drag options to blanks, or click blank then click option'
Aowner
Bimplementation
Cproxy
Dadmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using owner or admin instead of implementation.
Forgetting to declare the variable as public.
2fill in blank
medium

Complete the fallback function to delegate calls to the implementation contract.

Blockchain / Solidity
fallback() external payable {
    (bool success, ) = [1].delegatecall(msg.data);
    require(success, "Delegatecall failed");
}
Drag options to blanks, or click blank then click option'
Aimplementation
Bowner
Cmsg.sender
Daddress(this)
Attempts:
3 left
💡 Hint
Common Mistakes
Using owner or msg.sender instead of implementation.
Using call instead of delegatecall.
3fill in blank
hard

Fix the error in the upgrade function to correctly update the implementation address.

Blockchain / Solidity
function upgradeTo(address newImplementation) external {
    require(newImplementation != address(0), "Invalid address");
    [1] = newImplementation;
}
Drag options to blanks, or click blank then click option'
Aowner
Badmin
Cproxy
Dimplementation
Attempts:
3 left
💡 Hint
Common Mistakes
Updating owner or admin instead of implementation.
Not checking for zero address before upgrade.
4fill in blank
hard

Fill both blanks to create a mapping for admin addresses and a modifier to restrict access.

Blockchain / Solidity
mapping(address => bool) public [1];

modifier only[2]() {
    require(admins[msg.sender], "Not admin");
    _;
}
Drag options to blanks, or click blank then click option'
Aadmins
Bowners
CAdmins
DOwners
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent names between mapping and modifier.
Not capitalizing the modifier name correctly.
5fill in blank
hard

Fill all three blanks to write a dictionary comprehension that maps function selectors to implementation addresses if the selector is valid.

Blockchain / Solidity
mapping(bytes4 => address) public [1] = {
    [2]: [3] for selector in selectors if isValid(selector)
};
Drag options to blanks, or click blank then click option'
AselectorToImpl
Bselector
Cimplementation
Dselectors
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable names for keys or values.
Confusing the iterable selectors with the key variable selector.