1

I have added the compiler options in truffle-config.js -

compilers: {
    solc: {
      version: "0.8.16",
      settings: {
        optimizer: {
          enabled: false,
          runs: 200
        }
      }
    }
  }

I am deploying an upgradable erc20 contract using truffle. To do that I am using OpenZeppelin truffle suite.

truffle console --network testnet
truffle(testnet)> compile --all
truffle(testnet)> migrate

for migrate, I have 1_deploy_contracts.js as below

const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const Erc20Token = artifacts.require('Erc20Token');

module.exports = async function (deployer) {
    const instance = await deployProxy(Erc20Token, [], { deployer, initializer: 'initialize' });
}

This deploys 3 contracts for me:

Erc20Token
proxyAdmin
TransparentUpgradeableProxy

Now, The proxy (TransparentUpgradeableProxy) is verified automatically on the testnet with optimiser shows as "Yes with 200"

enter image description here

Now my aim is to deploy this proxy with NO optimisations since the life cycle of the contract is suppose to last indefinitely.

Then I checked the verified code on bsc scan testnet. I found this: enter image description here So I traced back the code where open-zeppelin library adds this settings which turned out to be in

node_modules/@openzeppelin/upgrades-core/artifacts/build-info.json

There I manually edited the build-info.json and set enabled: false.

enter image description here

I could also see the same solc compiler version in build-info.json which matches with the verified proxy contract on testnet, you can see that in first image.

"solcLongVersion": "0.8.2+commit.661d1103",

Still the problem persists. Do let me know or point to any relevant resources

Update

I tried with hardhat as well, and the result is same. On both places I'm using deployProxy module of open-Zeppelin.

So either, the problem is with deployProxy.

halfer
  • 19,824
  • 17
  • 99
  • 186
Parshuram Thorat
  • 101
  • 1
  • 2
  • 13

2 Answers2

1

I was able to solve the issue by deploying each of the contract individually and verifying them individually by flattening the code using truffle-flattener. Make sure after flattening, remove all but top one // SPDX-License-Identifier: MIT licenses from the flatten code.

And for TransparentUpgradeableProxy there are three input to constructor, while verifying make sure to find the abi code for arguments by using https://abi.hashex.org/ Also use this this link to find proper bytecode for your constructor arguments. Happy Coding.

deploy.js

const { ethers } = require("hardhat");
async function main() {
  const Erc20 = await ethers.getContractFactory("erc20");
  const Admin = await ethers.getContractFactory("ProxyAdmin");
  const Proxy = await ethers.getContractFactory("TransparentUpgradeableProxy");

  const erc20 = await Erc20.deploy();
  const admin = await Admin.deploy();
  const iface = new ethers.utils.Interface(["function initialize()"]);
  const encodedFunctionData = iface.encodeFunctionData(
        "initialize",
        []
    )
  const proxy = await Proxy.deploy(erc20.address, admin.address, encodedFunctionData, { gasLimit: 2000000 });
  console.log(`Address of proxy: ${proxy.address}`);

  }
  
  main()
    .then(() => process.exit(0))
    .catch(error => {
      console.error(error);
      process.exit(1);
    });

We may be able to do it using the truffle or hardhat plugins deployProxy.

halfer
  • 19,824
  • 17
  • 99
  • 186
Parshuram Thorat
  • 101
  • 1
  • 2
  • 13
  • Note that the bounty you've set can't be recovered - you're paying for exposure not results. It can either be awarded to someone else, or be allowed to evaporate. – halfer Sep 18 '22 at 18:00
  • wow, I didn't know that. I thought it would be returned. sigh! today is not a good day for me. – Parshuram Thorat Sep 20 '22 at 06:25
  • It's probably better that points are for exposure. We sometimes get people setting onerous levels of work in their bounties, and they stray into the category of demanding free labour from volunteers. The points are mostly worthless, and they certainly don't put food on the table! – halfer Sep 22 '22 at 11:58
0

not sure about truffle but are you the following setting with hardhat it will work. I was stuck once with same problem after 2 days got to know that you gotta put it inside the compiler indent. If it helps dun forget to accept the answer.

solidity: {
    compilers: [
      {
        version: "0.8.13",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      },
    ],
  },
Muhammad Hassan
  • 424
  • 3
  • 5
  • Thank you for answering. I tried this and it did not work. I want to disable the optimizer, so I set the enabled: false in above. – Parshuram Thorat Sep 11 '22 at 11:48
  • sorry, my bad I got the idea that you wanna make it work, but if you don't want the optimizer to run just don't add the above code, I mean no code related to the compiler at all. Because as I remember once I was getting the error that your code size exceeds the maximum limit I was using no code and then I put the above one and it optimized and the error vanished. This gives me the idea that not putting it all will do what you want, rather than changing true to false. – Muhammad Hassan Sep 12 '22 at 06:04
  • Ah, I see, Unfortunately, this also did not work. But nvm, thanks. – Parshuram Thorat Sep 12 '22 at 17:31