0
0
Blockchain / Solidityprogramming~20 mins

Upgrade strategies in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Upgrade Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a Proxy Upgrade Pattern
Consider a simple proxy contract pattern where the proxy delegates calls to an implementation contract. What will be the output of the following Solidity code snippet when calling getVersion() after upgrading the implementation?
Blockchain / Solidity
contract ImplementationV1 {
    function getVersion() public pure returns (string memory) {
        return "V1";
    }
}

contract ImplementationV2 {
    function getVersion() public pure returns (string memory) {
        return "V2";
    }
}

contract Proxy {
    address public implementation;

    constructor(address _impl) {
        implementation = _impl;
    }

    function upgrade(address _newImpl) public {
        implementation = _newImpl;
    }

    fallback() external payable {
        (bool success, bytes memory data) = implementation.delegatecall(msg.data);
        require(success);
        assembly {
            return(add(data, 0x20), mload(data))
        }
    }
}
A"V1"
BCompilation error due to delegatecall
C"V2"
DRuntime revert due to fallback
Attempts:
2 left
💡 Hint
Think about what happens when the proxy's implementation address is changed and a function is called.
🧠 Conceptual
intermediate
1:30remaining
Choosing Upgrade Strategy for Immutable Contracts
Which upgrade strategy is best suited for smart contracts that cannot be changed after deployment but require new features?
AUse a proxy contract with delegatecall to the implementation contract
BUse self-destruct to remove the old contract and redeploy
CModify the contract bytecode directly on the blockchain
DDeploy a new contract and use a registry to point users to the latest version
Attempts:
2 left
💡 Hint
Immutable contracts cannot be changed, so think about how to redirect users.
🔧 Debug
advanced
2:30remaining
Identify the Bug in Upgradeable Contract Storage
Given the following Solidity contracts, what is the cause of the unexpected behavior where the stored value does not persist after upgrading?
Blockchain / Solidity
contract StorageV1 {
    uint256 public value;

    function setValue(uint256 _value) public {
        value = _value;
    }
}

contract StorageV2 {
    uint256 public newValue;
    uint256 public value;

    function setValue(uint256 _value) public {
        value = _value;
    }

    function setNewValue(uint256 _newValue) public {
        newValue = _newValue;
    }
}
AStorage layout mismatch between V1 and V2 causes data corruption
BDelegatecall is not used in the proxy contract
CThe upgrade function does not update the implementation address
DThe fallback function is missing in the proxy contract
Attempts:
2 left
💡 Hint
Think about how storage variables are ordered and how that affects upgradeable contracts.
📝 Syntax
advanced
1:00remaining
Syntax Error in Upgradeable Contract Code
Which option contains the correct syntax for a Solidity function that upgrades the implementation address in a proxy contract?
Afunction upgrade(address newImpl) public { implementation = newImpl; }
Bfunction upgrade(address newImpl) public { implementation = newImpl }
Cfunction upgrade(address newImpl) public { implementation == newImpl; }
Dfunction upgrade(address newImpl) public { implementation := newImpl; }
Attempts:
2 left
💡 Hint
Remember Solidity statements end with semicolons and assignment uses a single equals sign.
🚀 Application
expert
1:30remaining
Calculate Number of Upgrade Steps in a Multi-Stage Upgrade
A blockchain project uses a multi-stage upgrade strategy where each upgrade deploys a new implementation contract and updates the proxy. If the project starts at version 1 and plans to reach version 5, how many upgrade transactions are needed to reach version 5 from version 1?
A5
B4
C3
D1
Attempts:
2 left
💡 Hint
Count how many times the implementation must be changed to go from version 1 to 5.