Truffle: deployProxy error: Cannot read property ‘evm’ of undefined

Hi @abcoathup

deployProxy error: Cannot read property ‘evm’ of undefined

SupportUpgrades

:computer: Environment

Truffle deployproxy API
@openzeppelin/truffle-upgrades”: “^1.3.0”,
dependencies
“truffle”: “^5.0.10”,
“truffle-hdwallet-provider”: “^1.0.16”,
Node.js vs 12.18.3

:memo:Details

I get the typeError cannot read property EVM of undefined deploying this contract

:1234: Code to reproduce

`
module.exports = (deployer, network, accounts) => {…

.then(()=> deployProxy( contractInstance, [ __address, _address, accounts[0], _address, _address, _address, accounts[13]], {deployer, initializer:‘initialize’,unsafeAllowCustomTypes:true} ) )`
}

2 Likes

Hi @Godtide,

OpenZeppelin Upgrades Plugins for Truffle requires Truffle version 5.1.35 or greater.

The latest version of Truffle is 5.1.55,
truffle-hdwallet-provider has been deprecated, so we should use @truffle/hdwallet-provider.

I recommend updating both Truffle and @truffle/hdwallet-provider and trying again.

What network were you trying to deploy to?

1 Like

Network: Development.
I’ll do that then circle back

1 Like

still experiencing the issue after update

1 Like

Hi @Godtide,

Your initializer takes 7 addresses? I will try to replicate tomorrow.

Yes right now! I’m working on reducing the params to test

1 Like

Hi @Godtide,

What version of Truffle are you using? Is this local or a global install?
What operating system are you using?
Can you share your networks configuration from truffle-config.js for your development network that you are deploying to? (:warning: Please do not include any secrets such as private keys or API keys)

I tried to reproduce with the following example with a larger number of parameters but didn’t get any issues. I am using Windows Subsystem for Linux (WSL2) on Windows 10.

Box.sol

// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
 
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);
    }
 
    // Stores a new value in the contract
    function initialize(address a1, address a2, address a3, address a4, address a5, address a6, address a7) public {
        value = 23;
        emit ValueChanged(23);
    }

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

2_deploy_box.js

// migrations/2_deploy_box.js
const Box = artifacts.require('Box');
 
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
 
module.exports = async function (deployer, networks, accounts) {
  await deployProxy(Box, [accounts[1], accounts[2], accounts[3], accounts[4], accounts[5], accounts[6], accounts[7]], { deployer, initializer: 'initialize' });
};

Migrate

Using Truffle develop, with Truffle installed locally

$ npx truffle develop
...
truffle(develop)> migrate

Compiling your contracts...
...
Starting migrations...
======================
> Network name:    'develop'
> Network id:      5777
> Block gas limit: 6721975 (0x6691b7)


1_initial_migration.js
...
2_deploy_box.js
===============

   Deploying 'Box'
   ---------------
...
   Deploying 'ProxyAdmin'
   ----------------------
...
   Deploying 'AdminUpgradeabilityProxy'
   ------------------------------------
...

Truffle version v5.1.55 installed globally

npm run big-chain (development version of ganache) to avoid gas prices restriction

cmd on Windows 10 OS

1 Like

@Godtide Can you share a repository with the code you’re using? At least the Solidity contract you’re trying to deploy.

And please share the full error that you see, including the stack trace that gets printed.

1 Like

Hi @frangio
I’m unable to share the contracts right now, but attached below is the stack trace and everything needed

1 Like

Can you try reproducing the bug with a minimal contract or project? I understand that you can’t share your actual contracts but a way to reproduce the error would be extremely helpful for us to debug and find out what’s going on. Thank you.

2 Likes

@frangio This finally works with ethers js. Ok, I’ll try reproducing truffle

2 Likes

Hi @Godtide,

We have found an error in Upgrades Plugins for Truffle and Hardhat. Users of the flag unsafeAllowCustomTypes should update their dependencies to the latest version.

See post for more details: Problem in Upgrades Plugins for users of unsafeAllowCustomTypes.

1 Like

I had the same problem and was able to reproduce it in the following way:

slots.sol:

pragma solidity ^0.6.0;
contract Slots {   function test()  external view returns (uint) { return 1; } }
interface Oracle{  function test()  external view returns (uint); }

Oracle.sol:

pragma solidity ^0.6.0;
contract Oracle { function test()  external view returns (uint) { return 1; }} 

2_slots_deploy.js

const { deployProxy } = require('@openzeppelin/truffle-upgrades');
var Slots = artifacts.require("slots");
module.exports = async function (deployer) {  const SlotsS = await deployProxy(Slots, [ ] ,{ deployer }); }

And the run truffle migrate twice.
The first time i see error: “Oracle” is an abstract contract or an interface and cannot be deployed.
The second time: TypeError: Cannot read property ‘evm’ of undefined

2 Likes

I can’t reproduce the issue. In your example there are two contracts with name Oracle, one of them an interface. That could be a source of non determinism and it could be related to the problem.

1 Like

I’ve tried to reproduce it again.
One detail is missing, it has to be “truffle migrate --reset” twice

I am aware “Oracle” is defined twice; when you rename one of them the problem is also gone.
However this might help to figure out the deeper cause.

I also noticed that after the first time a directory .openzeppelin is made with the file:
unknown-1337.json:

{
  "manifestVersion": "3.1",
  "impls": {
    "9125bbe01dab374cd44445257b4059e7673d7a07f860ca5f66cd4f0739d5e5cf": {
      "address": "0xD92eED87D91DF7A149a140D71C9A6ba324Ae0391",
      "txHash": "0x7fa2646b15054b35ed887b609a5c5b6746a729fca5b4c0458dc16389457a841c",
      "layout": {
        "storage": [],
        "types": {}
      }
    }
  },
  "admin": {
    "address": "0xf45E597a6e2f068375cee4Bc6Ab723423B76A0a8",
    "txHash": "0x178e308a4a4b9ea261f5621e4d418c9fa5b492be54d58334f64895e3293089bf"
  }
}
1 Like

Okay I was able to identify what is causing the issue in this particular case. Thanks for providing the example!

It is indeed due to the duplicate contract/interface name, and in particular because one of the two duplicates is colocated in the same file with another contract. Since Truffle emits the artifact for only one of the duplicates, it turns out that we have the AST for one but not its bytecode. We need to account for this situation.

As a workaround, avoid having multiple contracts with the same name. I’m not aware of a situation where this is actually required.

1 Like

I released a new version of @openzeppelin/upgrades-core (a dependency of the Truffle plugin) that should fix this issue.

1 Like