openzeppelin-contracts icon indicating copy to clipboard operation
openzeppelin-contracts copied to clipboard

Migration of simple ERC20 token fails with constantinople

Open BlinkyStitt opened this issue 7 years ago • 10 comments

I have this very simple test contract:

pragma solidity 0.5.4;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";

contract TutorialToken is ERC20 {
    string public name = "TutorialToken";
    string public symbol = "TT";
    uint8 public decimals = 18;
    uint public INITIAL_SUPPLY = 1000000000000;

    constructor() public {
        _mint(msg.sender, INITIAL_SUPPLY);
    }
}

I added evmVersion: 'constantinople' to my truffle-config.js and tried to migrate, but got this error:

   Deploying 'TutorialToken'
   -------------------------
Error:  *** Deployment Failed ***

"TutorialToken" hit an invalid opcode while deploying. Try:
   * Verifying that your constructor params satisfy all assert conditions.
   * Verifying your constructor code doesn't access an array out of bounds.
   * Adding reason strings to your assert statements.

    at /usr/src/app/node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:364:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.5 (core: 5.0.5)
Node v10.15.1

It migrates fine on byzantium.

💻 Environment

[email protected]

BlinkyStitt avatar Mar 01 '19 00:03 BlinkyStitt

I also get this error when trying to use solidity >=0.5.5 since it changed the default EVM to Petersburg

BlinkyStitt avatar Mar 14 '19 17:03 BlinkyStitt

Hi @WyseNynja! I was not able to reproduce this. Could you share your full truffle-config.js, and your migrations files?

frangio avatar Mar 18 '19 16:03 frangio

I'm getting the same issue. It seems to be related to calling a function inside the constructor. If I remove the function call and move the code directly inside the constructor it works just fine.

I believe it has to do with Truffle.

AleG94 avatar Apr 04 '19 20:04 AleG94

@AleG94 what makes you believe truffle is the culprit?

nventuro avatar Apr 04 '19 21:04 nventuro

@nventuro I'm using my own contract and had the same issue. I solved it by updating to solc 0.5.7 and removing evmVersion from settings. So it probably wasn't truffle's fault.

AleG94 avatar Apr 05 '19 08:04 AleG94

@WyseNynja have you tried what @AleG94 suggests?

nventuro avatar Apr 05 '19 18:04 nventuro

Just cleared my build artifacts, ran yarn upgrade, changed my contracts to use solc 0.5.7, and removed evmVersion from settings. yarn compile works successfully and most of the contracts are able to migrate, but TutorialToken still fails:

2_bootstrap_development.js
==========================

   Deploying 'GasToken2'
   ---------------------
   > transaction hash:    0x65af43004b33ebc99096e06b5b37dd7b29f03a1ab82fcc55fab29ad67774ad73
   > Blocks: 0            Seconds: 0
   > contract address:    0x7C7cC36FcE214C0D61a5BbFE592dae71422321B5
   > block number:        19
   > block timestamp:     1555100577
   > account:             0xa2138e2a036cd5468868b8f50B921040Bd5aE092
   > balance:             9999999999999.7409726
   > gas used:            800928
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.01601856 ETH


   Deploying 'TutorialToken'
   -------------------------
Error:  *** Deployment Failed ***

"TutorialToken" hit an invalid opcode while deploying. Try:
   * Verifying that your constructor params satisfy all assert conditions.
   * Verifying your constructor code doesn't access an array out of bounds.
   * Adding reason strings to your assert statements.

    at /usr/src/app/node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:364:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.12 (core: 5.0.12)
Node v10.15.1

I can't share my repo, but I'll try to make a repo that can reproduce this sometime in the next week o two.

BlinkyStitt avatar Apr 12 '19 20:04 BlinkyStitt

bump! @WyseNynja did you ever find the problem and relevant solution?

hudhaifahz avatar Feb 09 '21 22:02 hudhaifahz

@hudhaifahz This is an old issue, can I ask you to post your issue in the OpenZeppelin forum so we can help you solve it? Please include the version of OpenZeppelin Contracts that you're using, details about your environment, and the exact error you're getting.

frangio avatar Feb 09 '21 22:02 frangio

Sure! Reesolved though. I'd just like to leave a note that my difficulty was with "truffle-hdwallet-provider": "1.0.5" and I got around it by using "@truffle/hdwallet-provider": "1.0.34" instead.

hudhaifahz avatar Feb 10 '21 06:02 hudhaifahz