Truffle Upgrades on Windows: Error: Artifacts are from different compiler runs

Follow the author’s @abcoathup steps (OpenZeppelin Truffle Upgrades: Step by Step Tutorial) and everything is OK . but if Box2V is inherited from Box, problem occurs . modify the BoxV2 to:

// contracts/BoxV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

import "./Box.sol";
 
contract BoxV2 is Box{
   
    // Increments the stored value by 1
    function increment() public {
        value = value + 1;
        emit ValueChanged(value);
    }
}

Then run: npx truffle migrate,An error occurred

===============

2_deploy_box.js
Error: Artifacts are from different compiler runs
    Run a full recompilation using `truffle compile --all`
    https://zpl.in/upgrades/truffle-recompile-all
    at reconstructSolcInputOutput (E:\work\eth\oz\node_modules\@openzeppelin\truffle-upgrades\src\validate.ts:61:15)
    at Object.validateArtifacts (E:\work\eth\oz\node_modules\@openzeppelin\truffle-upgrades\src\validate.ts:14:29)
    at deployProxy (E:\work\eth\oz\node_modules\@openzeppelin\truffle-upgrades\src\deploy-proxy.ts:28:23)
    at module.exports (E:\work\eth\oz\migrations\2_deploy_box.js:14:3)
    at Migration._deploy (E:\work\eth\oz\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:73:1)
    at Migration._load (E:\work\eth\oz\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:55:1)
    at Migration.run (E:\work\eth\oz\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:171:1)
    at Object.runMigrations (E:\work\eth\oz\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
    at Object.runFrom (E:\work\eth\oz\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
    at Object.run (E:\work\eth\oz\node_modules\truffle\build\webpack:\packages\migrate\index.js:87:1)
    at runMigrations (E:\work\eth\oz\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:269:1)
    at E:\work\eth\oz\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:231:1
Truffle v5.1.45 (core: 5.1.45)
Node v12.18.4

I feel this problem occurs if BoxV2.sol contains import .
my env:

Truffle v5.1.45 (core: 5.1.45)
Solidity - 0.7.0 (solc-js)
Node v12.18.4
Web3.js v1.2.1

Please help to solve the problem, thank you very much.

1 Like

Hi @redn,

Welcome to the community :wave:

I was able to use your BoxV2 (after modifying Box.sol to make value internal) and run prepare upgrade.

My configuration:

$ npx truffle version
Truffle v5.1.45 (core: 5.1.45)
Solidity - 0.7.1 (solc-js)
Node v12.18.4
Web3.js v1.2.1

Did you try doing truffle compile --all?
See the documentation for details:

As an aside, I use WSL2 in Windows 10. You may want to consider using Windows Subsystem for Linux, see: Solidity Smart Contract development on Windows

Hi @redn,

I wanted to check if you were still having issues?

I’ve ran into the same issue myself and I’m able to reproduce.

  1. mkdir repro && cd repro
  2. npm init -y
npm i --save-dev truffle &&
npm i --save-dev @openzeppelin/truffle-upgrades &&
npm i --save-dev @openzeppelin/contracts-ethereum-package &&
npm i --save-dev @truffle/hdwallet-provider

If you are from the future it is already fixed and you want to reproduce use these:

"devDependencies": {
    "@openzeppelin/contracts-ethereum-package": "^3.0.0",
    "@openzeppelin/truffle-upgrades": "^1.2.0",
    "@truffle/hdwallet-provider": "^1.1.1",
    "truffle": "^5.1.49"
}
  1. npx truffle init

  2. Copy-paste content into files

// contracts/Coin.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.0;

import "@openzeppelin/contracts-ethereum-package/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/presets/ERC20PresetMinterPauser.sol";

contract Coin is ERC20PresetMinterPauserUpgradeSafe {    
    bytes32 public constant WHITELIST_ROLE = keccak256("WHITELIST_ROLE");
    modifier onlyWhitelister {
        require(hasRole(WHITELIST_ROLE, _msgSender()), "must have WHITELIST ROLE");
        _;
    }
    function initialize(string memory name, string memory symbol) public override virtual initializer {
        ERC20PresetMinterPauserUpgradeSafe.initialize(name, symbol);
        _setupRole(WHITELIST_ROLE, _msgSender());
    }
}

// test/coin.js
function toWei(eth){
    return web3.utils.toWei(eth);
}

const Coin = artifacts.require('Coin');

contract('Coin ', async function(accounts) {
    const creator = accounts[0]
    const user1 = accounts[1];
    const user2 = accounts[2];
    let coin;
    beforeEach(async function() {
        coin= await Coin.new({ from: creator } );
        await coin.initialize("Sample Coin", "SC ", { from: creator } );
        await coin.mint(user1, toWei("200000"), { from: creator });
    })
    it('User 1 should be able to send tokens to User 2', async () => {
        await coin.transfer(user2, toWei("10"), { from: user1 })
        assert.equal(await coin.balanceOf(user2), toWei("10"), "User 2 does not have 10 tokens");
    });
})

Some housekeeping otherwise the compiler will complain:

  1. Compiler version in truffle-config.js should be compilers: { solc: { version: "^0.6.0" } } (line 85)
  2. Add virtual to the initialize function in node_modules\@openzeppelin\contracts-ethereum-package\contracts\presets\ERC20PresetMinterPauser.sol (line 35)

DONE-ish. Can run truffle test, it compiles, it works, it pass the test… :clinking_glasses::tada::raised_hands:

So far so good…

…now this is failing.

// migrations/2_breaking_migration.js
const Coin = artifacts.require('Coin');
 
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
 
module.exports = async function (deployer) {
  await deployProxy(Coin, ["New token", "NTKN"], { deployer, initializer: 'initialize', unsafeAllowCustomTypes : true });
};

Error: Artifacts are from different compiler runs
Run a full recompilation using truffle compile --all
https://zpl.in/upgrades/truffle-recompile-all

Deleting the build folder / recompiling does not help.


I think it has something to do with some of the contracts being precompiled, see this post: Add instructions on how to verify to Upgrades Plugins step by step guides

It works on Mac BTW.

1 Like

Hi @marsxr,

I am sorry that you have this issue on Windows.

Thanks for the detailed steps, I can reproduce on Windows 10. This will help track down the issue.

> npx truffle migrate

Compiling your contracts...
===========================
√ Fetching solc version list from solc-bin. Attempt #1
> Everything is up to date, there is nothing to compile.

...

2_breaking_migration.js
=======================

Error: Artifacts are from different compiler runs
    Run a full recompilation using `truffle compile --all`
    https://zpl.in/upgrades/truffle-recompile-all
    at reconstructSolcInputOutput (C:\Users\andre\projects\mars\node_modules\@openzeppelin\truffle-upgrades\src\validate.ts:72:15)
    at Object.validateArtifacts (C:\Users\andre\projects\mars\node_modules\@openzeppelin\truffle-upgrades\src\validate.ts:20:29)
Truffle v5.1.49 (core: 5.1.49)
Node v10.16.3
> npx truffle version
Truffle v5.1.49 (core: 5.1.49)
Solidity - ^0.6.0 (solc-js)
Node v10.16.3
Web3.js v1.2.1

I recommend using Windows Subsystem for Linux (WSL) for smart contract development: Solidity Smart Contract development on Windows

I wasn’t able to reproduce on WSL2.