Can a Proxy written in Solidity 0.5 upgrade a Solidity 0.5 contract to a Solidity 0.6 contract?

Do you know if a Proxy written in solidity 5, can upgrade a solidity 5 contract into a contract written in solidity 6 and if so, would there be any tradeoffs?

1 Like

Hi @ccolorado,

I’m not aware of any issues. We still need to ensure that we don’t change the order in which the contract state variables are declared, nor their type. (See Modifying Your Contracts)

Any such upgrade would need appropriate testing.

I don’t think there would be any issues either! And I agree that it would be necessary to thoroughly test it just because it’s something new. Please share your results if you do.

1 Like

Hi @ccolorado,

I tried a quick check, though any solution would need thorough testing.

Box.sol

Solidity 0.5 from Upgrading a Contract using the CLI

// contracts/Box.sol
pragma solidity ^0.5.0;

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

Deploy using OpenZeppelin CLI 2.8 (otherwise use oz create for earlier versions)

$ npx oz deploy
βœ“ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy Box
βœ“ Added contract Box
βœ“ Contract Box deployed
All implementations have been deployed
? Call a function to initialize the instance after creating it? No
βœ“ Setting everything up to create contract instances
βœ“ Instance created at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
0xCfEB869F69431e42cdB54A4F4f105C19C080A601

$ npx oz send-tx
? Pick a network development
? Pick an instance Box at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
? Select which function store(newValue: uint256)
? newValue: uint256: 42
βœ“ Transaction successful. Transaction hash: 0x9f007d7f0fcb278a979fafecfceb45a9190b707bb8a0c08a90ce33a16e5feaff
Events emitted:
 - ValueChanged(42)

Box.sol (modified to Solidity 0.6)

// contracts/Box.sol
pragma solidity ^0.6.0;

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }

    // Increments the stored value by 1
    function increment() public {
        value = value + 1;
        emit ValueChanged(value);
    }
}

Compile with solc 0.6, upgrade and interact

$ npx oz compile --solc-version 0.6.3
βœ“ Compiled contracts with solc 0.6.3 (commit.8dda9521)

$ npx oz upgrade
? Pick a network development
Nothing to compile, all contracts are up to date.
βœ“ Contract Box deployed
All implementations have been deployed
? Which instances would you like to upgrade? Choose by address
? Pick an instance to upgrade Box at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
? Call a function on the instance after upgrading it? No
βœ“ Instance upgraded at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601. Transaction receipt: 0xcd85e8481c8e15f37a2822e5ac829cec315484dc8cddde37625270358ff9370f
βœ“ Instance at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 upgraded

$ npx oz send-tx
? Pick a network development
? Pick an instance Box at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
? Select which function increment()
βœ“ Transaction successful. Transaction hash: 0xb3eaceb24df52c4933d868113aabb02c12a91080e0c923373e1ddedae7b46325
Events emitted:
 - ValueChanged(43)
1 Like

Thank you, I am very grateful you put so much effort in this answer.

1 Like