Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Cannot verify complex contract infrastructure #13

Closed
filippetroviccc opened this issue Aug 13, 2019 · 8 comments
Closed

Cannot verify complex contract infrastructure #13

filippetroviccc opened this issue Aug 13, 2019 · 8 comments
Labels
bug Something isn't working

Comments

@filippetroviccc
Copy link

Hi,

I am trying to verify contracts from this repo https://github.com/swarmfund/swarm-compliant-contract.

But my contracts cannot get verified.

Here are the migration scripts.

1_deploy_src20registry.js


require('dotenv').config({path: '../.env'});
const Registry = artifacts.require("SRC20Registry");
const MockToken = artifacts.require("SwarmTokenMock");

const {
  ERC20_SWM,
  DEVELOPMENT_SWM_TOKEN_OWNER,
  DEVELOPMENT_SWM_TOTAL_SUPPLY
} = process.env;

module.exports = function (deployer, network) {
  if (!network.includes('mainnet')) {
    return deployer.deploy(MockToken,
      DEVELOPMENT_SWM_TOKEN_OWNER,
      DEVELOPMENT_SWM_TOTAL_SUPPLY
    ).then(async function (token) {
      return deployer.deploy(Registry,
        token.address
      );
    });
  } else {
    deployer.deploy(Registry,
      ERC20_SWM
    );
  }
};

2_deploy_factory.js

const Factory = artifacts.require("SRC20Factory");
const Registry = artifacts.require("SRC20Registry");

module.exports = function (deployer) {
  deployer.then(function () {
    return Registry.deployed().then(registry => {
      return deployer.deploy(Factory,
        registry.address
      ).then(async factory => {
        await registry.addFactory(factory.address);
      });
    });
  });
};

Here is truffle-config.js

/**
 * Use this file to configure your truffle project. It's seeded with some
 * common settings for different networks and features like migrations,
 * compilation and testing. Uncomment the ones you need or modify
 * them to suit your project as necessary.
 *
 * More information about configuration can be found at:
 *
 * truffleframework.com/docs/advanced/configuration
 *
 * To deploy via Infura you'll need a wallet provider (like truffle-hdwallet-provider)
 * to sign your transactions before they're sent to a remote public node. Infura API
 * keys are available for free at: infura.io/register
 *
 * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
 * public/private key pairs. If you're publishing your code to GitHub make sure you load this
 * phrase from a file you've .gitignored so it doesn't accidentally become public.
 *
 */

require('dotenv').config();

const {
  ETHERSCAN_API_KEY,
  INFURA_KEY
} = process.env;

const HDWalletProvider = require('truffle-hdwallet-provider');
const PrivateKeyProvider = require("truffle-privatekey-provider");
const infuraKey = INFURA_KEY;

const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
const privateKey = fs.readFileSync(".private_key").toString().trim();

module.exports = {
  /**
   * Networks define how you connect to your ethereum client and let you set the
   * defaults web3 uses to send transactions. If you don't specify one truffle
   * will spin up a development blockchain for you on port 9545 when you
   * run `develop` or `test`. You can ask a truffle command to use a specific
   * network from the command line, e.g
   *
   * $ truffle test --network <network-name>
   */
  networks: {
    // Useful for testing. The `development` name is special - truffle uses it by default
    // if it's defined here and no other network is specified at the command line.
    // You should run a client (like ganache-cli, geth or parity) in a separate terminal
    // tab if you use this network and you must also set the `host`, `port` and `network_id`
    // options below to some value.
    //
    // development: {
    //   host: "127.0.0.1",     // Localhost (default: none)
    //   port: 9545,            // Standard Ethereum port (default: none)
    //   network_id: "*",       // Any network (default: none)
    // },

    // Another network with more advanced options...
    // advanced: {
      // port: 8777,             // Custom port
      // network_id: 1342,       // Custom network
      // gas: 8500000,           // Gas sent with each transaction (default: ~6700000)
      // gasPrice: 20000000000,  // 20 gwei (in wei) (default: 100 gwei)
      // from: <address>,        // Account to send txs from (default: accounts[0])
      // websockets: true        // Enable EventEmitter interface for web3 (default: false)
    // },

    // Useful for deploying to a public network.
    // NB: It's important to wrap the provider as a function.
    rinkebyMnemonic: {
      provider: () => new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/v3/${infuraKey}`),
      network_id: 4,       // rinkeby's id
      gas: 5500000,        // rinkeby has a lower block limit than mainnet
      confirmations: 2,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: false     // Skip dry run before migrations? (default: false for public nets )
    },

    rinkebyPrivateKey: {
      provider: () => new PrivateKeyProvider(privateKey, `https://rinkeby.infura.io/v3/${infuraKey}`),
      network_id: 4,       // rinkeby's id
      gas: 5500000,        // rinkeby has a lower block limit than mainnet
      confirmations: 2,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: false     // Skip dry run before migrations? (default: false for public nets )
    },

    mainnetPrivateKey: {
      provider: () => new PrivateKeyProvider(privateKey, `https://mainnet.infura.io/v3/${infuraKey}`),
      network_id: 1,       // Mainnet's id
      gas: 8000000,        // Mainnet has a lower block limit than mainnet
      confirmations: 20,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: false     // Skip dry run before migrations? (default: false for public nets )
      // gasPrice: 100000  // gas price in wei
    },

    mainnetMnemonic: {
      provider: () => new HDWalletProvider(mnemonic, `https://mainnet.infura.io/v3/${infuraKey}`),
      network_id: 1,       // Mainnet's id
      gas: 8000000,        // Mainnet has a lower block limit than mainnet
      confirmations: 20,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: false     // Skip dry run before migrations? (default: false for public nets )
      // gasPrice: 100000  // gas price in wei
    },

    // Useful for private networks
    // private: {
      // provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
      // network_id: 2111,   // This network is yours, in the cloud.
      // production: true    // Treats this network as if it was a public net. (default: false)
    // }
  },

  plugins: [
    'truffle-plugin-verify'
  ],

  api_keys: {
    etherscan: ETHERSCAN_API_KEY,
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: '^0.5.2', // 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: "byzantine"
      // }
    }
  }
};

Looking forward to this issue beeing fixed @rkalis :)

@rkalis
Copy link
Owner

rkalis commented Aug 13, 2019

Thanks for opening this issue. I'm currently on holiday, so I'll be able to take a look at this next week.

@filippetroviccc
Copy link
Author

ping @rkalis

@rkalis
Copy link
Owner

rkalis commented Sep 9, 2019

Hey thanks for the additional ping. Sorry for dropping the ball on this one. I finally came back to the real world after finishing my Master's thesis.

I'm trying to debug this one, but when I clone the repo you linked, the code is very different from what you posted in here. I copy-pasted in your comments above, and was able to run the migrations, and pushed the code to a new repo rkalis/issue13.

After migration to Rinkeby I tried to run truffle run verify SRC20Registry --network rinkeby, and the verification failed. I inspected the API request the plugin was sending, and apparently there's an error in the flattened source code, which can be seen here.

I suspect this might have something to do with the flattening of the code with sol-merger. Perhaps it's because of the 'contract' keyword inside the revert reason string. What do you think @RyuuGan?

@filippetroviccc
Copy link
Author

Thank you for taking the time researching the issue that could have happened.

I'll try to remove all solidity keywords from comments and revert messages in order for this to go through.

Are you aware of any other problem that I can encounter when verifying contract?

@RyuuGan
Copy link

RyuuGan commented Sep 9, 2019

@rkalis I can check it out, it might be a bug in sol-merger, but not sure when it will be.

@RyuuGan
Copy link

RyuuGan commented Sep 10, 2019

@rkalis, @filippetroviccc

I fixed the sol-merger. So update the library version and it should close this issue.

@filippetroviccc
Copy link
Author

Hey @rkalis,

Just want to know what is your possible ETA on this? Just want to organize my work and sorry for additional ping.

@rkalis
Copy link
Owner

rkalis commented Sep 11, 2019

Just published truffle-plugin-verify@0.3.3, which uses the updated sol-merger@1.0.1. With this version I was able to verify your contracts (e.g. https://rinkeby.etherscan.io/address/0x3B79aAE4c61Bf311093F0F97300514DB8A6B9923#contracts)

@rkalis rkalis closed this as completed Sep 11, 2019
@rkalis rkalis added the bug Something isn't working label May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants