Full Smart Contract Upgradeability Discussion

Hello,

I was wonder if someone could help?
I keep getting truffle error when i try to migrate;

Error: Dogs has no network configuration for its current network id (5777).
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);

}

Hey @Javier_Flores, hope you are well.

What about the truffle config file? can you share it here to take a look ? You are using ganache or truffle to create the instance of the local blockchain?

Carlos Z

Actually I firgured out what was the issue , now Im having problem in smart contract maybe you can help me with?

truffle(develop)> compile --all

Compiling your contracts...
===========================
> Compiling .\contracts\Dogs.sol
> Compiling .\contracts\DogsUpdated.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\Proxy.sol
> Compiling .\contracts\Storage.sol
> Compiling .\contracts\Dogs.sol
> Compiling .\contracts\Storage.sol

/C/Users/jflor/Documents/ProxySystemExample/contracts/DogsUpdated.sol:15:14: DeclarationError: Undeclared identifier. Did you mean "_intialized" or "initialize"?
    require(!_initialized);
             ^----------^

Compilation failed. See above.

truffle(develop)>
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;



import "./Dogs.sol";

contract DogsUpdated is Dogs {

  constructor() public {
    initialize(msg.sender);
  }

  function initialize(address _owner) public {
    require(!_initialized);
    owner = _owner;
    _initialize = true;
  }
}

Hey @Javier_Flores, hope you are well.

Where is the _initialized variable declared? maybe you are just having a syntax error whit that one.

Carlos Z

Hi everyone,

Iā€™m stuck with " Part 7 ā€“ Interacting & Testing our proxy"
Every time I type in ā€œtruffle developā€, itā€™s getting stuck and I have to restart my VS Code.
I donā€™t know what Iā€™m doing wrong.
Below you can find some information.

Could not connect to your Ethereum client with the following parameters:
    - host       > 127.0.0.1
    - port       > 7545
    - network_id > 5777
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

Truffle v5.0.6 (core: 5.0.6)
Node v16.13.1
% truffle version
Truffle v5.0.6 (core: 5.0.6)
Solidity - 0.5.17 (solc-js)
Node v16.13.1
silkuijt@MBP-van-sil SmartContractUpgradeabilityFullExample % 
pragma solidity 0.5.17;

import "./Storage.sol";

contract Proxy is Storage{

    address currentAddress;

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

    function upgrade(address _newAddress) public{
        currentAddress = _newAddress;        
    }

    //Fallback Functie
    function () payable external {
        // Doorsturen naar currentAddress

        address implementation = currentAddress;
        require(currentAddress != address(0));
        bytes memory data = msg.data;

        assembly {
            let result := delegatecall(gas, implementation, 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)}
        }
    } 
}

The only thing I changed at the truffle-config.js file, was:

compilers: {
    solc: {
      version: "0.5.17",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },

Can someone please help me? I really want to go forward, but this is keeping me behindā€‹:sweat_smile::sweat_smile:

1 Like

Hey @Sil, hope you are well.

You can try downgrading the nodejs, which most times solve this kind of issues:

https://forum.ivanontech.com/t/faq-how-to-downgrade-node-js/22908/3

Carlos Z

Wouldnā€™t there be a security vulnerability here if someone called the initialize method on the contract before us? That way someone else could take control of the proxy contract:

1 Like

Hey there,
I was having the same issue as Sil a few comments above. I had to downgrade my node version in order to get an output from ā€˜truffle developā€™
Still not out of the woods yet unfortunately now it throws an error when I try to ā€˜migrate --resetā€™
Does that look like thereā€™s an error in my code or is it still a version issue?
Any help with this would be greatly appreciated. Thanks

1 Like

Can you please share the migration file for the proxy? apparently the issue comes from that file.

Carlos Z

Cheers for the reply, Iā€™ve taken a look through the file and compared to the code on github I canā€™t find anything. Itā€™s a little different to the github file but I reckon itā€™s probably because the github file is the finished file mine is still a bit from being finished. It seems identical to where I am in the videos when I need to call migrate --reset.

Could you be able to create a github repo and upload your project? that way i can easily replicate the issue you have :nerd_face:

Carlos Z

Thanks so much for taking a look!
https://github.com/danboyce92/UpgradableContract
much appreciated! Hopefully it\s something easy to spot!

What truffle version should I be using?
Iā€™ve reinstalled Node.js to a previous version (v10.21.0)
But Iā€™m wondering could my version of truffle have anything to do with my issue?
It says Iā€™ve got truffle v4.1.14 installed along with Solidity v0.4.24
Could these be the issue?

1 Like

Not sure if might be the truffle version, there are some other errors being show up to me which are related to bad syntax in your contracts.

First of all, all your .sol files, which are contracts, must be inside your contract folder, not outside, after it, you have some syntax errors like this one:

Remember requires must be inside a condition like this: require(msg.sender == owner);

Here are the versions that im using, just in case you want to use the same has mine
image

Carlos Z

2 Likes

Thanks a million Carlos, changed my truffle version to yours, tried to compile again, got all the syntax errors and now the migrate --reset is working. Really appreciate the help man!

2 Likes

Hey there guys! I had a simple question, I got my code to compile with truffle(finally) but when I compile my SC, I see that my terminal doesnā€™t output ā€œCompile successfully using:ā€ like philips does in the video. My says simply:

Is this a different functionality? because I think heā€™s using ubuntu and Iā€™m using unix. thanks for the clarification :slight_smile:

2 Likes

Have you create the migration file for that contract? :nerd_face:

Carlos Z

1 Like

@thecil yes I have

Iā€™m not sure how to check my outputs for this migrations section iā€™m looking for my setNumber of dogs from my proxy(10) and my setNumber of dogs from functional which should be(0). thanks for help

2 Likes

would you be able to share your project on a git hub repo? that way will be easier for me to replicate your issue.

https://www.youtube.com/watch?v=u-_uGO95xco

Carlos Z

1 Like

Hi guys, I hope you well.
Iā€™m making practice with a mine project.
In the functional contract I need to do the mapping, and memorizing them in the storage contract, also for the variables that I create and use in a function and then discard (so memorized using memory) or I can just use use ā€œnormal creationā€?

1 Like