Full Smart Contract Upgradeability Discussion

Hi @thecil. I would appreciate your help!

Would you be able to create a github repo for this project? I might need to check your migration files and smart contract files

Carlos Z

I made the project with solidity 0.6.1 and I am not able to set the proxy owner with the initilization function call. Even if I copy the example code from Github I get troubles. I copy everything exactly with exception of the solidity version I use, and I also delete the “owner = msg.sender” line from the Proxy constructor because I want to set the owner with the function “initialize()”. After calling “initialize()” owner of proxy is still “0x0000000000000000”. Anyone has the same issue and knows how to solve this ?

Hi Guys,

I’m struggling to install Atom, I don’t know what version I should install, as now we’re using solidity version 0.8.20, not 0.5.1, as in Filip’s lecture, also which truffle version I should install in the command prompt?

I have installed Atom
I used the link provided is the lecture, and selected the atom-windows.zip. but my code, not colored like in the lecture.

Also my command prompt not working the same as the lecture.

I’m in part 6 but when I try to develop the contract on command prompt it freeze
I’m using windows.

My code:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Storage{

    mapping(string => uint256) _uintStorage;
    mapping(string => address) _addressStorage;
    mapping(string => bool) _boolStorage;
    mapping(string => string) _stringStorage;
    mapping(string => bytes4) _bytesStorage;

    address public owner;

    bool public _initialized;    
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "./Storage.sol";

contract Dogs is Storage{

    modifier onlyOnwer(){
        require(msg.sender == owner);
        _;
    }

    constructor () public{
        owner == msg.sender;
    }

    function getNumberOfDogs() public view returns (uint256){
        return _uintStorage["Dogs"];
    }

    function setNumberOfDogs(uint256 toSet) public{
        _uintStorage["Dogs"] = toSet;
    }
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "./Storage.sol";

contract Proxy is Storage{

    address currentAddress;

    constructor(address _currentAddress) public{
        currentAddress = _currentAddress;
    }

    function upgrade(address _newAddress) public {
        currentAddress = _newAddress;
     
    }
    function () payable external {
        address implementaion = currentAddress;
        require(currentAddress != address(0));
        bytes memory data = msg.data;

        assembly {
            let result := delegatecall(gas, implementaion, add(data, 0x20), mload(data), 0, 0)
            let size := returndatasize
            let ptr := mload(0x40)
            returndatacopy(ptr, 0, size)
            switch result 
            case 0 {revert(ptr, size)}
            default {return(ptr, size)}
        }

    }
}
const Dogs = artifacts.require("Dogs");
const Proxy = artifacts.require("Proxy");

module.exports = async function(deployer, network, accounts) {
 const dogs = await Dogs.new();
 const proxy = await Proxy.new(dogs.address);   
}

It might not be an error from code. Have you tried restarting your machine?

1 Like

Hi @JohnVersus,

Or maybe because of this error of the fallback function?

Would ypu please advice how to resolve this error

Thanks in advance

Hi, Can you share the code here? I will test it on my end.

Hi, in the proxy contract.

The error says: (Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the “fallback” keyword or the “receive” keyword instead.(2915)
Function: null
Contract: Proxy
function null()
payable external )
I’m using VS code and tried to deploy it in the terminal from VS code (command prompt.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "./Storage.sol";

contract Proxy is Storage{

    address currentAddress;

    constructor(address _currentAddress) public{
        currentAddress = _currentAddress;
    }

    function upgrade(address _newAddress) public {
        currentAddress = _newAddress;
     
    }
    function () payable external {
        address implementaion = currentAddress;
        require(currentAddress != address(0));
        bytes memory data = msg.data;

        assembly {
            let result := delegatecall(gas, implementaion, add(data, 0x20), mload(data), 0, 0)
            let size := returndatasize
            let ptr := mload(0x40)
            returndatacopy(ptr, 0, size)
            switch result 
            case 0 {revert(ptr, size)}
            default {return(ptr, size)}
        }

    }
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Storage{

    mapping(string => uint256) _uintStorage;
    mapping(string => address) _addressStorage;
    mapping(string => bool) _boolStorage;
    mapping(string => string) _stringStorage;
    mapping(string => bytes4) _bytesStorage;

    address public owner;

    bool public _initialized;    
}`Preformatted text`
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "./Storage.sol";

contract Dogs is Storage{

    modifier onlyOnwer(){
        require(msg.sender == owner);
        _;
    }

    constructor () public{
        owner == msg.sender;
    }

    function getNumberOfDogs() public view returns (uint256){
        return _uintStorage["Dogs"];
    }

    function setNumberOfDogs(uint256 toSet) public{
        _uintStorage["Dogs"] = toSet;
    }
}
const Dogs = artifacts.require("Dogs");
const Proxy = artifacts.require("Proxy");

module.exports = async function(deployer, network, accounts) {
 const dogs = await Dogs.new();
 const proxy = await Proxy.new(dogs.address);   
}

Replace this line with the below line. In the latest solidity versions function is not allowed without a name and it is replaced by a fallback keyword in the latest version.

    fallback () payable external {
1 Like

Thanks @JohnVersus,

But in the assembly, the gas should be called


        assembly {
            let result := delegatecall(gas, implementaion, add(data, 0x20), mload(data), 0, 0)
            let size := returndatasize
            let ptr := mload(0x40)
            returndatacopy(ptr, 0, size)
            switch result 
            case 0 {revert(ptr, size)}
            default {return(ptr, size)}
        }

What do you think?

Yes, you can keep the remaining code as it is

    fallback () payable external {
    address implementaion = currentAddress;
    require(currentAddress != address(0));
    bytes memory data = msg.data;

    assembly {
        let result := delegatecall(gas(), implementaion, add(data, 0x20), mload(data), 0, 0)
        let size := returndatasize()
        let ptr := mload(0x40)
        returndatacopy(ptr, 0, size)
        switch result 
        case 0 {revert(ptr, size)}
        default {return(ptr, size)}
    }
    }
1 Like

I have a new error while the compile

What is your compiler version as per truffle?

As per your proxy code your compiler version should be >=0.4.22 <0.9.0. Mismatch in the compiler version can also cause your error.

Here it’s

Hi @Ahmad_Abd_Allah

Can you please try with any compiler version greater than or equal to 0.6.2 .
It seems fallback was not present in the older version of solidity.

I can see the same error when I try with your solidity version.

1 Like

Hi @JohnVersus

I tried many versions such 0.6.2 and 0.8.19 and 0.8.2 and, but same issues :crazy_face: :tired_face: :rage:

There is no issue with your code so it must be an error with the compiler.:thinking:
Can you try with this command? It will remove previously compiled data and will compile it again.

truffle compile --reset --all

Unfortunately, the same issue persists.