Error invalid constructor arguments provided please verify that they are in abi encoded format

Update: so these 2 lines in my code seem to be causing the problem and removing them got everything to work but I still need to include them so if someone can figure out why they are breaking that ...

Update: so these 2 lines in my code seem to be causing the problem and removing them got everything to work but I still need to include them so if someone can figure out why they are breaking that would help.

require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay.");
        require(delay_ <= MAXIMUM_DELAY, "Timelock::constructor: Delay must not exceed maximum delay.");

Here is the contract I’m trying to deploy to ropsten

https://ropsten.etherscan.io/address/0x2126d060b8858a025c8238e5553af0d6cee98121#code
Here is the code

// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, 'SafeMath: addition overflow');

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, 'SafeMath: subtraction overflow');
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, 'SafeMath: multiplication overflow');

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, 'SafeMath: division by zero');
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return mod(a, b, 'SafeMath: modulo by zero');
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }

    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = x < y ? x : y;
    }

    // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
    function sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
    }
}




// COPIED FROM https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/GovernorAlpha.sol
// Copyright 2020 Compound Labs, Inc.
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Ctrl+f for XXX to see all the modifications.



contract Timelock {
    using SafeMath for uint;

    event NewAdmin(address indexed newAdmin);
    event NewPendingAdmin(address indexed newPendingAdmin);
    event NewDelay(uint indexed newDelay);
    event CancelTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature,  bytes data, uint eta);
    event ExecuteTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature,  bytes data, uint eta);
    event QueueTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta);

    uint public constant GRACE_PERIOD = 14 days;
    uint public constant MINIMUM_DELAY = 24 hours;
    uint public constant MAXIMUM_DELAY = 30 days;

    address public admin;
    address public pendingAdmin;
    uint public delay;
    bool public admin_initialized;

    mapping (bytes32 => bool) public queuedTransactions;


    constructor(address admin_, uint delay_) public {
        require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay.");
        require(delay_ <= MAXIMUM_DELAY, "Timelock::constructor: Delay must not exceed maximum delay.");

        admin = admin_;
        delay = delay_;
        admin_initialized = false;
    }

    // XXX: function() external payable { }
    receive() external payable { }

    function setDelay(uint delay_) public {
        require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock.");
        require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay.");
        require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay.");
        delay = delay_;

        emit NewDelay(delay);
    }

    function acceptAdmin() public {
        require(msg.sender == pendingAdmin, "Timelock::acceptAdmin: Call must come from pendingAdmin.");
        admin = msg.sender;
        pendingAdmin = address(0);

        emit NewAdmin(admin);
    }

    function setPendingAdmin(address pendingAdmin_) public {
        // allows one time setting of admin for deployment purposes
        if (admin_initialized) {
            require(msg.sender == address(this), "Timelock::setPendingAdmin: Call must come from Timelock.");
        } else {
            require(msg.sender == admin, "Timelock::setPendingAdmin: First call must come from admin.");
            admin_initialized = true;
        }
        pendingAdmin = pendingAdmin_;

        emit NewPendingAdmin(pendingAdmin);
    }

    function queueTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public returns (bytes32) {
        require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin.");
        require(eta >= getBlockTimestamp().add(delay), "Timelock::queueTransaction: Estimated execution block must satisfy delay.");

        bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
        queuedTransactions[txHash] = true;

        emit QueueTransaction(txHash, target, value, signature, data, eta);
        return txHash;
    }

    function cancelTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public {
        require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin.");

        bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
        queuedTransactions[txHash] = false;

        emit CancelTransaction(txHash, target, value, signature, data, eta);
    }

    function executeTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public payable returns (bytes memory) {
        require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin.");

        bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
        require(queuedTransactions[txHash], "Timelock::executeTransaction: Transaction hasn't been queued.");
        require(getBlockTimestamp() >= eta, "Timelock::executeTransaction: Transaction hasn't surpassed time lock.");
        require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), "Timelock::executeTransaction: Transaction is stale.");

        queuedTransactions[txHash] = false;

        bytes memory callData;

        if (bytes(signature).length == 0) {
            callData = data;
        } else {
            callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
        }

        // solium-disable-next-line security/no-call-value
        (bool success, bytes memory returnData) = target.call.value(value)(callData);
        require(success, "Timelock::executeTransaction: Transaction execution reverted.");

        emit ExecuteTransaction(txHash, target, value, signature, data, eta);

        return returnData;
    }

    function getBlockTimestamp() internal view returns (uint) {
        // solium-disable-next-line security/no-block-members
        return block.timestamp;
    }
}

I’ve tried looking at these solutions but it seems that my constructor is correctly created so their solution doesn’t work for me..

https://forum.openzeppelin.com/t/error-invalid-constructor-arguments-provided-please-verify-that-they-are-in-abi-encoded-format/2241/6
https://forum.openzeppelin.com/t/error-verifying-contract-with-no-constructor-arguments-on-etherscan/3890/5

@mcplums

Hello, I’m running:

truffle migrate --network mainnet --reset

And then I’m immediately running

truffle run verify ContractName@address --network mainnet

and I get «Invalid constructor arguments provided. Please verify that they are in ABI-encoded format».

How can they be invalid when I’ve only just deployed it?

Btw. I love this plugin so much :) it has worked many times in the past

@rkalis

Hey @mcplums! That does sound weird. Could you run the command again with the --debug flag and post the details? Also, did you deploy your contract through a factory contract?

@mcplums

I have tried to re-create this error and this time using the —debug flag, this time I’m getting 503 error which I assume is a problem at etherscan’s end so I will try again later and report back. If I take too long to do so feel free to close 👍

I can confirm it was not a factory. I’m aware that etherscan cannot handle those just yet.

@rkalis

@storming0x

Getting the same error. When i add --debug

Constructor parameters received: 0x697066735822122009eb274d752106666b7b763e3ba5a150b94b8bf7d130791f17324bb70e54903e64736f6c634300060c0033000000000000000000000000c1dcb653a21e3c0069fe494cbe1644206c641ff6
...other output

"constructorArguements": "697066735822122009eb274d752106666b7b763e3ba5a150b94b8bf7d130791f17324bb70e54903e64736f6c634300060c0033000000000000000000000000c1dcb653a21e3c0069fe494cbe1644206c641ff6"

The payload to etherscan API is missing the ‘0x’ from the beginning

@rkalis

Hey @dmolina79, thanks for chipping in!

That should be fine, Etherscan doesn’t expect the 0x prefix. So I assume there’s something else going on. Do you have a repository I can look at to try to reproduce this?

@storming0x

Hi @rkalis sure, i’ve created this repo as an example

https://github.com/dmolina79/yearn-truffle-verify

Trying to verify this contract in rinkeby using this command:

truffle run verify StrategyCreamCRV@0xF477479a6bf71F41b8935EFDd347D1794F18e6C1 --network infuraRinkeby --license GPL-3.0

These are the compiler settings which should be good:
Compiling contracts... Solc version: 0.6.12 Optimizer: Enabled Runs: 200 EVM Version: Istanbul

The plugin has worked great so far with other simpler contracts, but it bricks on this one with the constructor error for some reason. Lmk if you need anything else.

@rkalis

So it looks like it somehow retrieved incorrect constructor arguments. When I ran it on my end it retrieved this as the constructor arguments: 0x000000000000000000000000f2e47c29fc9f31cc50a62dea24956545772921bc, which are completely different from the ones you got.

When running with the installed version v0.4.0, I did get an error because the flattened source code included multiple SPDX license identifiers. As a fix, I updated to the latest version v0.5.0 (which uses multi-file verification) and I was able to verify the contract.

I was able to run migrations and accurately verify those newly deployed contracts as well. I’m still not sure why it got different constructor args on your end than on my end, but I can’t reproduce the issue. Could you try updating to v0.5.0 and running compile + migrate + verify again to see if it’s working for you?

@Grandthrax

Hi, I am getting the same issue @dmolina79. When running verify it gets my contructor parameters received as: 0x00000000005d3a536e4d6dbd6114cc1ead35777bab948e3643a26469706673582212203f6b1b16b84a192fc410f2b7252382703c506f806748d5f6b2299317b56927cc64736f6c634300060c00330000000000000000000000009b142c2cdab89941e9dcd0b6c1cf6dea378a8d7c

when they should be:
0x0000000000000000000000009B142C2CDAb89941E9dcd0B6C1cf6dEa378A8D7C

This is a different project to @dmolina79 but we are both built off the same baseStrategy.sol
Is there a way to declare contructor arguments manually?

@rkalis

That is so odd that it works on my end. Could you guys share your Truffle versions as well?

@Grandthrax

Truffle v5.1.50 (core: 5.1.50)
Solidity — 0.6.12 (solc-js)
Node v12.18.2
Web3.js v1.2.9

@storming0x

So it looks like it somehow retrieved incorrect constructor arguments. When I ran it on my end it retrieved this as the constructor arguments: 0x000000000000000000000000f2e47c29fc9f31cc50a62dea24956545772921bc, which are completely different from the ones you got.

When running with the installed version v0.4.0, I did get an error because the flattened source code included multiple SPDX license identifiers. As a fix, I updated to the latest version v0.5.0 (which uses multi-file verification) and I was able to verify the contract.

I was able to run migrations and accurately verify those newly deployed contracts as well. I’m still not sure why it got different constructor args on your end than on my end, but I can’t reproduce the issue. Could you try updating to v0.5.0 and running compile + migrate + verify again to see if it’s working for you?

thanks a lot @rkalis updating the plugin to 0.5.0 did the trick, so it was not the abi constructor issue it was the mix licenses, but that worked in any case.

@Grandthrax

I cloned @dmolina79 repo and added my contract, but still getting the same constructor error when trying to verify.

Here is the repo: https://github.com/Grandthrax/yearn-truffle-verify

And I am running command:
truffle run verify YearnDaiCompStratV2@0x5b62F24581Ea4bc6d6C5C101DD2Ae7233E422884 —network infuraMainnet

@Grandthrax

I am using truffle-plugin-verify@0.5.0.

Error is: Invalid constructor arguments provided. Please verify that they are in ABI-encoded format

Constructor parameters retrieved: 0xcf6dea378a8d7c

so I am now getting different constructor parameters, but still the wrong ones…

@rkalis

Strange. Do you have a link to your forked repo with your contract added?

@Grandthrax

@Grandthrax

So looking into it a bit more it seems that ‘Invalid constructor arguments provided error’ just happens when the transaction data is a different length to the artifact.bytecode.length. So probably something I am doing wrong rather than an error on your end

@rkalis

So the way the plugin works is it gets the contract creation transaction. The input data of that transaction is the contract bytecode + the constructor args. By splitting the input data on the bytecode length, what should be left over is the constructor args. But if the bytecode doesn’t match, then it’s possible that the split is wrong.

So are you absolutely sure that the compile settings that you used locally are exactly the same as the ones you used when deploying? i.e.:

	compilers: {
		solc: {
			version: "0.6.12",
			settings: {
				optimizer: {
					enabled: true,
					runs: 200
				},
			},
		}
	},

@Grandthrax

I compiled and deployed using brownie rather than truffle. So have redeployed (0xd1da63f8ab9b8ce335f0f0e40f0e2a05c20c93bf) using truffle from the repo i linked to above. Now constructor parameters look right but verify is still failing.

One thing I did have to do was edit the json build file for truffle-plugin-verify to work. I was getting «Cannot find module ‘/D/Source/….l'» so changed all /D/ to D:/. Would that change the result of verify?

@rkalis

Which fields did you have to change the paths for in the JSON file?

@rkalis

Also could you push the migration code that you used to the library?

@rkalis

Closing this issue for inactivity. Feel free to open it with more information.

@rkalis
rkalis

added

bug

Something isn’t working

waiting

Waiting for response from reporter

labels

May 7, 2021

Cannot verify contract with multiple arguments at etherscan.io

When I enter all the information about a contract, the system displays the error:

Error! Invalid constructor arguments provided. Please verify that they are in ABI-encoded format

I fill in the following fields

I used this system to compile the contract:

Can you please explain how to verify this contract? Thanks!

3 Answers 3

You need to correctly ABI-encode your constructor parameters. You can easily do this with online tool https://abi.hashex.org. Just paste in your abi to auto-parse constructor parameters or manually add them and enter values. ABI-encoded constructor parameters would be automatically calculated. Just copy them and paste in etherscan.io constructor parameters input.

You are passing in the entire bytecode, when it only wants the ABI-encoded arguments, which in your case appear to be

You can find the ABI encoded constructor arguments by simply checking the difference between the encoded unlinked binary of your contract and the encoded transaction arguments of the transaction that created the contract. This is probably what @Tjaden Hess did, without explaining.

If you can’t figure out your ABI-encoded constructor arguments, first look at the encoded unlinked binary of your contract, then look at the encoded transaction-arguments of the transaction that created your contract. If your contract was deployed with constructor arguments, they should have been appended to the transaction data. So the difference between the two will be the ABI-encoded constructor arguments.

Источник

«Invalid constructor arguments» error, running immediately after deployment #34

Comments

Hello, I’m running:

truffle migrate —network mainnet —reset

And then I’m immediately running

truffle run verify ContractName@address —network mainnet

and I get «Invalid constructor arguments provided. Please verify that they are in ABI-encoded format».

How can they be invalid when I’ve only just deployed it?

Btw. I love this plugin so much 🙂 it has worked many times in the past

The text was updated successfully, but these errors were encountered:

Hey @mcplums! That does sound weird. Could you run the command again with the —debug flag and post the details? Also, did you deploy your contract through a factory contract?

I have tried to re-create this error and this time using the —debug flag, this time I’m getting 503 error which I assume is a problem at etherscan’s end so I will try again later and report back. If I take too long to do so feel free to close 👍

I can confirm it was not a factory. I’m aware that etherscan cannot handle those just yet.

Any news on this?

Getting the same error. When i add —debug

The payload to etherscan API is missing the ‘0x’ from the beginning

Hey @dmolina79, thanks for chipping in!

That should be fine, Etherscan doesn’t expect the 0x prefix. So I assume there’s something else going on. Do you have a repository I can look at to try to reproduce this?

Hi @rkalis sure, i’ve created this repo as an example

Trying to verify this contract in rinkeby using this command:

truffle run verify StrategyCreamCRV@0xF477479a6bf71F41b8935EFDd347D1794F18e6C1 —network infuraRinkeby —license GPL-3.0

These are the compiler settings which should be good:
Compiling contracts. Solc version: 0.6.12 Optimizer: Enabled Runs: 200 EVM Version: Istanbul

The plugin has worked great so far with other simpler contracts, but it bricks on this one with the constructor error for some reason. Lmk if you need anything else.

So it looks like it somehow retrieved incorrect constructor arguments. When I ran it on my end it retrieved this as the constructor arguments: 0x000000000000000000000000f2e47c29fc9f31cc50a62dea24956545772921bc , which are completely different from the ones you got.

When running with the installed version v0.4.0, I did get an error because the flattened source code included multiple SPDX license identifiers. As a fix, I updated to the latest version v0.5.0 (which uses multi-file verification) and I was able to verify the contract.

I was able to run migrations and accurately verify those newly deployed contracts as well. I’m still not sure why it got different constructor args on your end than on my end, but I can’t reproduce the issue. Could you try updating to v0.5.0 and running compile + migrate + verify again to see if it’s working for you?

Hi, I am getting the same issue @dmolina79. When running verify it gets my contructor parameters received as: 0x00000000005d3a536e4d6dbd6114cc1ead35777bab948e3643a26469706673582212203f6b1b16b84a192fc410f2b7252382703c506f806748d5f6b2299317b56927cc64736f6c634300060c00330000000000000000000000009b142c2cdab89941e9dcd0b6c1cf6dea378a8d7c

when they should be:
0x0000000000000000000000009B142C2CDAb89941E9dcd0B6C1cf6dEa378A8D7C

This is a different project to @dmolina79 but we are both built off the same baseStrategy.sol
Is there a way to declare contructor arguments manually?

That is so odd that it works on my end. Could you guys share your Truffle versions as well?

Truffle v5.1.50 (core: 5.1.50)
Solidity — 0.6.12 (solc-js)
Node v12.18.2
Web3.js v1.2.9

So it looks like it somehow retrieved incorrect constructor arguments. When I ran it on my end it retrieved this as the constructor arguments: 0x000000000000000000000000f2e47c29fc9f31cc50a62dea24956545772921bc , which are completely different from the ones you got.

When running with the installed version v0.4.0, I did get an error because the flattened source code included multiple SPDX license identifiers. As a fix, I updated to the latest version v0.5.0 (which uses multi-file verification) and I was able to verify the contract.

I was able to run migrations and accurately verify those newly deployed contracts as well. I’m still not sure why it got different constructor args on your end than on my end, but I can’t reproduce the issue. Could you try updating to v0.5.0 and running compile + migrate + verify again to see if it’s working for you?

thanks a lot @rkalis updating the plugin to 0.5.0 did the trick, so it was not the abi constructor issue it was the mix licenses, but that worked in any case.

I cloned @dmolina79 repo and added my contract, but still getting the same constructor error when trying to verify.

And I am running command:
truffle run verify YearnDaiCompStratV2@0x5b62F24581Ea4bc6d6C5C101DD2Ae7233E422884 —network infuraMainnet

I am using truffle-plugin-verify@0.5.0.

Error is: Invalid constructor arguments provided. Please verify that they are in ABI-encoded format

Constructor parameters retrieved: 0xcf6dea378a8d7c

so I am now getting different constructor parameters, but still the wrong ones.

Strange. Do you have a link to your forked repo with your contract added?

Источник

Error verifying Proxy contracts #150

Comments

Bug Description

A bug in the verfy.js prevents verifying Proxy smartcontrat. When I tried verifying a proxy smartcontract, It started verifying the implementation contract and failed with the message: «Invalid constructor arguments provided. Please verify that they are in ABI-encoded format». After debugging the process, I found that retrieved constructor argument parameters are different from the actual constructor parameter. I then tried verifying the implementation contract separately and it succeeded. This issue comes only when verifying the implementation contract with the proxy contract. This issue occurs because for verifying the implementation contract also, you are using the artifact from the proxy contract.
let status = proxyImplementationAddress ? await verifyProxyContract(artifact, proxyImplementationAddress, options) : await verifyContract(artifact, options)
so on the following step, you will get a different length than the actual length and end up with a wrong constructor argument.

const constructorArgs = res.data.result[0].input.substring(artifact.bytecode.length) .

Environment information

Please provide environment information as complete as possible. Before submitting a bug report, please make sure that you’re running an LTS version of Node and the latest versions of Truffle and truffle-plugin-verify.

  • Operating System: Windows 11
  • Node version: 16.13.0
  • Truffle version: 8.1.0
  • truffle-plugin-verify version: 0.5.20

Debug output

$ truffle run verify Vizva721Proxy —network rinkeby —debug
DEBUG logging is turned ON
Running truffle-plugin-verify v0.5.20
Retrieving network’s chain ID
Verifying Vizva721Proxy
Reading artifact file at D:buildcontractsVizva721Proxy.json
Verifying proxy implementation at 0xf848d5eaddb9748f559d7be3c6d7d544424f964f
Retrieving constructor parameters from https://api-rinkeby.etherscan.io/api?apiKey=0XXXXXXXXXX&module=account&action=txlist&address=0xf848d5eaddb9748f559d7be3c6d7d544424f964f&page=1&sort=asc&offset=1
Constructor parameters retrieved: 0x1b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610458565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610e183390565b816001600160a01b0316836001600160a01b031614156110085760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610458565b6001600160a01b038381166000818152606a6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611080848484610bc9565b61108c84848484611150565b6109215760405162461bcd60e51b8152600401610458906117cd565b6110b2838361125d565b6110bf6000848484611150565b61058e5760405162461bcd60e51b8152600401610458906117cd565b600054610100900460ff166106735760405162461bcd60e51b8152600401610458906118a5565b600054610100900460ff166111295760405162461bcd60e51b8152600401610458906118a5565b815161113c90606590602085019061139f565b50805161058e90606690602084019061139f565b60006001600160a01b0384163b1561125257604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061119490339089908890889060040161177d565b602060405180830381600087803b1580156111ae57600080fd5b505af19250505080156111de575060408051601f3d908101601f191682019092526111db9181019061166a565b60015b611238573d80801561120c576040519150601f19603f3d011682016040523d82523d6000602084013e611211565b606091505b5080516112305760405162461bcd60e51b8152600401610458906117cd565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610bc1565b506001949350505050565b6001600160a01b0382166112b35760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610458565b6000818152606760205260409020546001600160a01b0316156113185760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610458565b6001600160a01b03821660009081526068602052604081208054600192906113419084906118f0565b909155505060008181526067602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b8280546113ab9061191f565b90600052602060002090601f0160209004810192826113cd5760008555611413565b82601f106113e657805160ff1916838001178555611413565b82800160010185558215611413579182015b828111156114135782518255916020019190600101906113f8565b5061141f929150611423565b5090565b5b8082111561141f5760008155600101611424565b600067ffffffffffffffff8084111561145357611453611970565b604051601f8501601f19908116603f0116810190828211818310171561147b5761147b611970565b8160405280935085815286868601111561149457600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b038116811461034c57600080fd5b600082601f8301126114d5578081fd5b6114e483833560208501611438565b9392505050565b6000602082840312156114fc578081fd5b6114e4826114ae565b60008060408385031215611517578081fd5b611520836114ae565b915061152e602084016114ae565b90509250929050565b60008060006060848603121561154b578081fd5b611554846114ae565b9250611562602085016114ae565b9150604084013590509250925092565b60008060008060808587031215611587578081fd5b611590856114ae565b935061159e602086016114ae565b925060408501359150606085013567ffffffffffffffff8111156115c0578182fd5b8501601f810187136115d0578182fd5b6115df87823560208401611438565b91505092959194509250565b600080604083850312156115fd578182fd5b611606836114ae565b91506020830135801515811461161a578182fd5b809150509250929050565b60008060408385031215611637578182fd5b611640836114ae565b946020939093013593505050565b60006020828403121561165f578081fd5b81356114e481611986565b60006020828403121561167b578081fd5b81516114e481611986565b600060208284031215611697578081fd5b813567ffffffffffffffff8111156116ad578182fd5b610bc1848285016114c5565b600080604083850312156116cb578182fd5b823567ffffffffffffffff808211156116e2578384fd5b6116ee868387016114c5565b93506020850135915080821115611703578283fd5b50611710858286016114c5565b9150509250929050565b60006020828403121561172b578081fd5b5035919050565b60008151808452815b818110156117575760208185018101518683018201520161173b565b818111156117685782602083870101525b50601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906117b090830184611732565b9695505050505050565b6000602082526114e46020830184611732565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600082198211156119035761190361195a565b500190565b60008282101561191a5761191a61195a565b500390565b60028104600182168061193357607f821691505b6020821081141561195457634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114610a6157600080fdfea2646970667358221220b93d96f03f8a3c92e93fcc63620696fc0191a00f43f18c50fdbd35a67d4c9f9164736f6c63430008020033
Sending verify request with POST arguments:
<
«apikey»: «0XXXXXXXXXXXXXXXX»,
«module»: «contract»,
«action»: «verifysourcecode»,
«contractaddress»: «0xf848d5eaddb9748f559d7be3c6d7d544424f964f»,
«sourceCode»: «<«language»:»Solidity»,»sources»:<«/contracts/Vizva721Proxy.sol»:<«content»:»//SPDX-License-Identifier: MITrnrnpragma solidity ^0.8.0;rnrnimport ‘@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol’;rnrncontract Vizva721Proxy is TransparentUpgradeableProxy<rn constructor(rn address logic,rn address admin,rn bytes memory _datarn ) payable TransparentUpgradeableProxy(logic, admin, _data) <>rn>»>,»@openzeppelin/contracts/utils/StorageSlot.sol»:<«content»:»// SPDX-License-Identifier: MITn// OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol)nnpragma solidity ^0.8.0;nn/n * @dev Library for reading and writing primitive types to specific storage slots.n *n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.n * This library helps with reading and writing to such slots without the need for inline assembly.n *n * The functions in this library return Slot structs that contain a value member that can be used to read or write.n *n * Example usage to set ERC1967 implementation slot:n * \n * contract ERC1967 <\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) <\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * >\n *\n * function _setImplementation(address newImplementation) internal <\n * require(Address.isContract(newImplementation), \»ERC1967: new implementation is not a contract\»);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * >\n * >\n * n *n * Available since v4.1 for address , bool , bytes32 , and uint256 .n */nlibrary StorageSlot <n struct AddressSlot <n address value;n >nn struct BooleanSlot <n bool value;n >nn struct Bytes32Slot <n bytes32 value;n >nn struct Uint256Slot <n uint256 value;n >nn /n * @dev Returns an AddressSlot with member value located at slot .n */n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) <n assembly <n r.slot := slotn >n >nn /n * @dev Returns an BooleanSlot with member value located at slot .n */n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) <n assembly <n r.slot := slotn >n >nn /n * @dev Returns an Bytes32Slot with member value located at slot .n */n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) <n assembly <n r.slot := slotn >n >nn /n * @dev Returns an Uint256Slot with member value located at slot .n */n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) <n assembly <n r.slot := slotn >n >n>n»>,»@openzeppelin/contracts/utils/Address.sol»:<«content»:»// SPDX-License-Identifier: MITn// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)nnpragma solidity ^0.8.0;nn/n * @dev Collection of functions related to the address typen */nlibrary Address <n /n * @dev Returns true if account is a contract.n *n * [IMPORTANT]n * ====n * It is unsafe to assume that an address for which this function returnsn * false is an externally-owned account (EOA) and not a contract.n *n * Among others, isContract will return false for the followingn * types of addresses:n *n * — an externally-owned accountn * — a contract in constructionn * — an address where a contract will be createdn * — an address where a contract lived, but was destroyedn * ====n */n function isContract(address account) internal view returns (bool) <n // This method relies on extcodesize, which returns 0 for contracts inn // construction, since the code is only stored at the end of then // constructor execution.nn uint256 size;n assembly <n size := extcodesize(account)n >n return size > 0;n >nn /n * @dev Replacement for Solidity’s transfer : sends amount wei ton * recipient , forwarding all available gas and reverting on errors.n *n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas costn * of certain opcodes, possibly making contracts go over the 2300 gas limitn * imposed by transfer , making them unable to receive funds vian * transfer . removes this limitation.n *n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].n *n * IMPORTANT: because control is transferred to recipient , care must ben * taken to not create reentrancy vulnerabilities. Consider usingn * or then * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].n */n function sendValue(address payable recipient, uint256 amount) internal <n require(address(this).balance >= amount, »Address: insufficient balance»);nn (bool success, ) = recipient.call(»»);n require(success, »Address: unable to send value, recipient may have reverted»);n >nn /n * @dev Performs a Solidity function call using a low level call . An * plain call is an unsafe replacement for a function call: use thisn * function instead.n *n * If target reverts with a revert reason, it is bubbled up by thisn * function (like regular Solidity function calls).n *n * Returns the raw returned data. To convert to the expected return value,n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *n * Requirements:n *n * — target must be a contract.n * — calling target with data must not revert.n *n * Available since v3.1.n */n function functionCall(address target, bytes memory data) internal returns (bytes memory) <n return functionCall(target, data, «Address: low-level call failed»);n >nn /n * @dev Same as [ functionCall ], but withn * errorMessage as a fallback revert reason when target reverts.n *n * Available since v3.1.n */n function functionCall(n address target,n bytes memory data,n string memory errorMessagen ) internal returns (bytes memory) <n return functionCallWithValue(target, data, 0, errorMessage);n >nn /n * @dev Same as [ functionCall ],n * but also transferring value wei to target .n *n * Requirements:n *n * — the calling contract must have an ETH balance of at least value .n * — the called Solidity function must be payable .n *n * Available since v3.1.n */n function functionCallWithValue(n address target,n bytes memory data,n uint256 valuen ) internal returns (bytes memory) <n return functionCallWithValue(target, data, value, «Address: low-level call with value failed»);n >nn /n * @dev Same as [ functionCallWithValue ], butn * with errorMessage as a fallback revert reason when target reverts.n *n * Available since v3.1.n */n function functionCallWithValue(n address target,n bytes memory data,n uint256 value,n string memory errorMessagen ) internal returns (bytes memory) <n require(address(this).balance >= value, »Address: insufficient balance for call»);n require(isContract(target), »Address: call to non-contract»);nn (bool success, bytes memory returndata) = target.call(data);n return verifyCallResult(success, returndata, errorMessage);n >nn /n * @dev Same as [ functionCall ],n * but performing a static call.n *n * Available since v3.3.n */n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) <n return functionStaticCall(target, data, «Address: low-level static call failed»);n >nn /n * @dev Same as [ functionCall ],n * but performing a static call.n *n * Available since v3.3.n */n function functionStaticCall(n address target,n bytes memory data,n string memory errorMessagen ) internal view returns (bytes memory) <n require(isContract(target), «Address: static call to non-contract»);nn (bool success, bytes memory returndata) = target.staticcall(data);n return verifyCallResult(success, returndata, errorMessage);n >nn /n * @dev Same as [ functionCall ],n * but performing a delegate call.n *n * Available since v3.4.n */n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) <n return functionDelegateCall(target, data, «Address: low-level delegate call failed»);n >nn /n * @dev Same as [ functionCall ],n * but performing a delegate call.n *n * Available since v3.4.n */n function functionDelegateCall(n address target,n bytes memory data,n string memory errorMessagen ) internal returns (bytes memory) <n require(isContract(target), «Address: delegate call to non-contract»);nn (bool success, bytes memory returndata) = target.delegatecall(data);n return verifyCallResult(success, returndata, errorMessage);n >nn /n * @dev Tool to verifies that a low level call was successful, and revert if it wasn’t, either by bubbling then * revert reason using the provided one.n *n * Available since v4.3.n */n function verifyCallResult(n bool success,n bytes memory returndata,n string memory errorMessagen ) internal pure returns (bytes memory) <n if (success) <n return returndata;n >else <n // Look for revert reason and bubble it up if presentn if (returndata.length >0) <n // The easiest way to bubble the revert reason is using memory via assemblynn assembly <n let returndata_size := mload(returndata)n revert(add(32, returndata), returndata_size)n >n > else <n revert(errorMessage);n >n >n >n>n»>,»@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol»:<«content»:»// SPDX-License-Identifier: MITn// OpenZeppelin Contracts v4.4.1 (proxy/transparent/TransparentUpgradeableProxy.sol)nnpragma solidity ^0.8.0;nnimport «../ERC1967/ERC1967Proxy.sol»;nn/n * @dev This contract implements a proxy that is upgradeable by an admin.n *n * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selectorn * clashing], which can potentially be used in an attack, this contract uses then * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies twon * things that go hand in hand:n *n * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even ifn * that call matches one of the admin functions exposed by the proxy itself.n * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to then * implementation. If the admin tries to call a function on the implementation it will fail with an error that saysn * »admin cannot fallback to proxy target».n *n * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changingn * the admin, so it’s best if it’s a dedicated account that is not used for anything else. This will avoid headaches duen * to sudden errors when trying to call a function from the proxy implementation.n *n * Our recommendation is for the dedicated account to be an instance of the contract. If set up this way,n * you should think of the ProxyAdmin instance as the real administrative interface of your proxy.n */ncontract TransparentUpgradeableProxy is ERC1967Proxy <n /n * @dev Initializes an upgradeable proxy managed by _admin , backed by the implementation at _logic , andn * optionally initialized with _data as explained in .n */n constructor(n address logic,n address admin,n bytes memory _datan ) payable ERC1967Proxy(_logic, _data) <n assert(_ADMIN_SLOT == bytes32(uint256(keccak256(«eip1967.proxy.admin»)) — 1));n changeAdmin(admin);n >nn /n * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.n */n modifier ifAdmin() <n if (msg.sender == getAdmin()) <n ;n > else <n fallback();n >n >nn /**n * @dev Returns the current admin.n *n * NOTE: Only the admin can call this function. See .n *n * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using then * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.n * 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103 n */n function admin() external ifAdmin returns (address admin) <n admin= getAdmin();n >nn /**n * @dev Returns the current implementation.n *n * NOTE: Only the admin can call this function. See .n *n * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using then * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.n * 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc n */n function implementation() external ifAdmin returns (address implementation) <n implementation= _implementation();n >nn /n * @dev Changes the admin of the proxy.n *n * Emits an event.n *n * NOTE: Only the admin can call this function. See .n */n function changeAdmin(address newAdmin) external virtual ifAdmin <n _changeAdmin(newAdmin);n >nn /n * @dev Upgrade the implementation of the proxy.n *n * NOTE: Only the admin can call this function. See .n */n function upgradeTo(address newImplementation) external ifAdmin <n _upgradeToAndCall(newImplementation, bytes(«»), false);n >nn /n * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specifiedn * by data , which should be an encoded function call. This is useful to initialize new storage variables in then * proxied contract.n *n * NOTE: Only the admin can call this function. See .n */n function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin <n _upgradeToAndCall(newImplementation, data, true);n >nn /n * @dev Returns the current admin.n */n function _admin() internal view virtual returns (address) <n return _getAdmin();n >nn /n * @dev Makes sure the admin cannot access the fallback function. See .n */n function _beforeFallback() internal virtual override <n require(msg.sender != _getAdmin(), «TransparentUpgradeableProxy: admin cannot fallback to proxy target»);n super._beforeFallback();n >n>n»>,»@openzeppelin/contracts/proxy/beacon/IBeacon.sol»:<«content»:»// SPDX-License-Identifier: MITn// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)nnpragma solidity ^0.8.0;nn/n * @dev This is the interface that expects of its beacon.n */ninterface IBeacon <n /n * @dev Must return an address that can be used as a delegate call target.n *n * will check that this address is a contract.n */n function implementation() external view returns (address);n>n»>,»@openzeppelin/contracts/proxy/Proxy.sol»:<«content»:»// SPDX-License-Identifier: MITn// OpenZeppelin Contracts v4.4.1 (proxy/Proxy.sol)nnpragma solidity ^0.8.0;nn/n * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVMn * instruction delegatecall . We refer to the second contract as the implementation behind the proxy, and it has ton * be specified by overriding the virtual <_implementation>function.n *n * Additionally, delegation to the implementation can be triggered manually through the <_fallback>function, or to an * different contract through the <_delegate>function.n *n * The success and return data of the delegated call will be returned back to the caller of the proxy.n */nabstract contract Proxy <n /n * @dev Delegates the current call to implementation .n *n * This function does not return to its internall call site, it will return directly to the external caller.n */n function _delegate(address implementation) internal virtual <n assembly <n // Copy msg.data. We take full control of memory in this inline assemblyn // block because it will not return to Solidity code. We overwrite then
// Solidity scratch pad at memory position 0.n calldatacopy(0, 0, calldatasize())nn // Call the implementation.n // out and outsize are 0 because we don’t know the size yet.n let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)nn // Copy the returned data.n returndatacopy(0, 0, returndatasize())nn switch resultn // delegatecall returns 0 on error.n case 0 <n revert(0, returndatasize())n >n default <n return(0, returndatasize())n >n >n >nn /
n * @dev This is a virtual function that should be overriden so it returns the address to which the fallback functionn * and <_fallback>should delegate.n */n function _implementation() internal view virtual returns (address);nn /n * @dev Delegates the current call to the address returned by _implementation() .n *n * This function does not return to its internall call site, it will return directly to the external caller.n */n function _fallback() internal virtual <n _beforeFallback();n _delegate(_implementation());n >nn /n * @dev Fallback function that delegates calls to the address returned by _implementation() . Will run if no othern * function in the contract matches the call data.n */n fallback() external payable virtual <n _fallback();n >nn /n * @dev Fallback function that delegates calls to the address returned by _implementation() . Will run if call datan * is empty.n */n receive() external payable virtual <n _fallback();n >nn /n * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual _fallback n * call, or as part of the Solidity fallback or receive functions.n *n * If overriden should call super._beforeFallback() .n */n function _beforeFallback() internal virtual <>n>n»>,»@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol»:<«content»:»// SPDX-License-Identifier: MITn// OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol)nnpragma solidity ^0.8.2;nnimport «../beacon/IBeacon.sol»;nimport «../../utils/Address.sol»;nimport «../../utils/StorageSlot.sol»;nn/n * @dev This abstract contract provides getters and event emitting update functions forn * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.n *n * Available since v4.1.n *n * @Custom:oz-upgrades-unsafe-allow delegatecalln */nabstract contract ERC1967Upgrade <n // This is the keccak-256 hash of «eip1967.proxy.rollback» subtracted by 1n bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;nn /n * @dev Storage slot with the address of the current implementation.n * This is the keccak-256 hash of »eip1967.proxy.implementation» subtracted by 1, and isn * validated in the constructor.n */n bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;nn /n * @dev Emitted when the implementation is upgraded.n */n event Upgraded(address indexed implementation);nn /n * @dev Returns the current implementation address.n */n function _getImplementation() internal view returns (address) <n return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;n >nn /n * @dev Stores a new address in the EIP1967 implementation slot.n */n function _setImplementation(address newImplementation) private <n require(Address.isContract(newImplementation), «ERC1967: new implementation is not a contract»);n StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;n >nn /n * @dev Perform implementation upgraden *n * Emits an event.n */n function _upgradeTo(address newImplementation) internal <n _setImplementation(newImplementation);n emit Upgraded(newImplementation);n >nn /n * @dev Perform implementation upgrade with additional setup call.n *n * Emits an event.n */n function _upgradeToAndCall(n address newImplementation,n bytes memory data,n bool forceCalln ) internal <n _upgradeTo(newImplementation);n if (data.length >0 || forceCall) <n Address.functionDelegateCall(newImplementation, data);n >n >nn /n * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.n *n * Emits an event.n */n function _upgradeToAndCallSecure(n address newImplementation,n bytes memory data,n bool forceCalln ) internal <n address oldImplementation = _getImplementation();nn // Initial upgrade and setup calln _setImplementation(newImplementation);n if (data.length >0 || forceCall) <n Address.functionDelegateCall(newImplementation, data);n >nn // Perform rollback test if not already in progressn StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);n if (!rollbackTesting.value) <n // Trigger rollback using upgradeTo from the new implementationn rollbackTesting.value = true;n Address.functionDelegateCall(n newImplementation,n abi.encodeWithSignature(«upgradeTo(address)», oldImplementation)n );n rollbackTesting.value = false;n // Check rollback was effectiven require(oldImplementation == _getImplementation(), «ERC1967Upgrade: upgrade breaks further upgrades»);n // Finally reset to the new implementation and log the upgraden _upgradeTo(newImplementation);n >n >nn /n * @dev Storage slot with the admin of the contract.n * This is the keccak-256 hash of »eip1967.proxy.admin» subtracted by 1, and isn * validated in the constructor.n */n bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;nn /n * @dev Emitted when the admin account has changed.n */n event AdminChanged(address previousAdmin, address newAdmin);nn /n * @dev Returns the current admin.n */n function _getAdmin() internal view returns (address) <n return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;n >nn /n * @dev Stores a new address in the EIP1967 admin slot.n */n function _setAdmin(address newAdmin) private <n require(newAdmin != address(0), «ERC1967: new admin is the zero address»);n StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;n >nn /n * @dev Changes the admin of the proxy.n *n * Emits an event.n */n function _changeAdmin(address newAdmin) internal <n emit AdminChanged(_getAdmin(), newAdmin);n _setAdmin(newAdmin);n >nn /n * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.n * This is bytes32(uint256(keccak256(‘eip1967.proxy.beacon’)) — 1)) and is validated in the constructor.n */n bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;nn /n * @dev Emitted when the beacon is upgraded.n */n event BeaconUpgraded(address indexed beacon);nn /n * @dev Returns the current beacon.n */n function _getBeacon() internal view returns (address) <n return StorageSlot.getAddressSlot(_BEACON_SLOT).value;n >nn /n * @dev Stores a new beacon in the EIP1967 beacon slot.n */n function _setBeacon(address newBeacon) private <n require(Address.isContract(newBeacon), «ERC1967: new beacon is not a contract»);n require(n Address.isContract(IBeacon(newBeacon).implementation()),n «ERC1967: beacon implementation is not a contract»n );n StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;n >nn /n * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it doesn * not upgrade the implementation contained in the beacon (see for that).n *n * Emits a event.n */n function _upgradeBeaconToAndCall(n address newBeacon,n bytes memory data,n bool forceCalln ) internal <n _setBeacon(newBeacon);n emit BeaconUpgraded(newBeacon);n if (data.length >0 || forceCall) <n Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);n >n >n>n»>,»@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol»:<«content»:»// SPDX-License-Identifier: MITn// OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Proxy.sol)nnpragma solidity ^0.8.0;nnimport «../Proxy.sol»;nimport «./ERC1967Upgrade.sol»;nn/n * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to ann * implementation address that can be changed. This address is stored in storage in the location specified byn * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn’t conflict with the storage layout of then * implementation behind the proxy.n */ncontract ERC1967Proxy is Proxy, ERC1967Upgrade <n /n * @dev Initializes the upgradeable proxy with an initial implementation specified by _logic .n *n * If _data is nonempty, it’s used as data in a delegate call to _logic . This will typically be an encodedn * function call, and allows initializating the storage of the proxy like a Solidity constructor.n */n constructor(address _logic, bytes memory _data) payable <n assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256(«eip1967.proxy.implementation»)) — 1));n _upgradeToAndCall(_logic, _data, false);n >nn /**n * @dev Returns the current implementation address.n */n function _implementation() internal view virtual override returns (address impl) <n return ERC1967Upgrade._getImplementation();n >n>n»>>,»settings»:<«remappings»:[],»optimizer»:<«enabled»:true,»runs»:200>,»evmVersion»:»istanbul»,»libraries»:<>>>»,
«codeformat»: «solidity-standard-json-input»,
«contractname»: «/contracts/Vizva721Proxy.sol:Vizva721Proxy»,
«compilerversion»: «v0.8.2+commit.661d1103»,
«constructorArguements»: «1b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610458565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610e183390565b816001600160a01b0316836001600160a01b031614156110085760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610458565b6001600160a01b038381166000818152606a6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611080848484610bc9565b61108c84848484611150565b6109215760405162461bcd60e51b8152600401610458906117cd565b6110b2838361125d565b6110bf6000848484611150565b61058e5760405162461bcd60e51b8152600401610458906117cd565b600054610100900460ff166106735760405162461bcd60e51b8152600401610458906118a5565b600054610100900460ff166111295760405162461bcd60e51b8152600401610458906118a5565b815161113c90606590602085019061139f565b50805161058e90606690602084019061139f565b60006001600160a01b0384163b1561125257604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061119490339089908890889060040161177d565b602060405180830381600087803b1580156111ae57600080fd5b505af19250505080156111de575060408051601f3d908101601f191682019092526111db9181019061166a565b60015b611238573d80801561120c576040519150601f19603f3d011682016040523d82523d6000602084013e611211565b606091505b5080516112305760405162461bcd60e51b8152600401610458906117cd565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610bc1565b506001949350505050565b6001600160a01b0382166112b35760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610458565b6000818152606760205260409020546001600160a01b0316156113185760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610458565b6001600160a01b03821660009081526068602052604081208054600192906113419084906118f0565b909155505060008181526067602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b8280546113ab9061191f565b90600052602060002090601f0160209004810192826113cd5760008555611413565b82601f106113e657805160ff1916838001178555611413565b82800160010185558215611413579182015b828111156114135782518255916020019190600101906113f8565b5061141f929150611423565b5090565b5b8082111561141f5760008155600101611424565b600067ffffffffffffffff8084111561145357611453611970565b604051601f8501601f19908116603f0116810190828211818310171561147b5761147b611970565b8160405280935085815286868601111561149457600080fd5b858560208301376000602087830101525050509392505050565b80356001600160a01b038116811461034c57600080fd5b600082601f8301126114d5578081fd5b6114e483833560208501611438565b9392505050565b6000602082840312156114fc578081fd5b6114e4826114ae565b60008060408385031215611517578081fd5b611520836114ae565b915061152e602084016114ae565b90509250929050565b60008060006060848603121561154b578081fd5b611554846114ae565b9250611562602085016114ae565b9150604084013590509250925092565b60008060008060808587031215611587578081fd5b611590856114ae565b935061159e602086016114ae565b925060408501359150606085013567ffffffffffffffff8111156115c0578182fd5b8501601f810187136115d0578182fd5b6115df87823560208401611438565b91505092959194509250565b600080604083850312156115fd578182fd5b611606836114ae565b91506020830135801515811461161a578182fd5b809150509250929050565b60008060408385031215611637578182fd5b611640836114ae565b946020939093013593505050565b60006020828403121561165f578081fd5b81356114e481611986565b60006020828403121561167b578081fd5b81516114e481611986565b600060208284031215611697578081fd5b813567ffffffffffffffff8111156116ad578182fd5b610bc1848285016114c5565b600080604083850312156116cb578182fd5b823567ffffffffffffffff808211156116e2578384fd5b6116ee868387016114c5565b93506020850135915080821115611703578283fd5b50611710858286016114c5565b9150509250929050565b60006020828403121561172b578081fd5b5035919050565b60008151808452815b818110156117575760208185018101518683018201520161173b565b818111156117685782602083870101525b50601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906117b090830184611732565b9695505050505050565b6000602082526114e46020830184611732565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600082198211156119035761190361195a565b500190565b60008282101561191a5761191a61195a565b500390565b60028104600182168061193357607f821691505b6020821081141561195457634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114610a6157600080fdfea2646970667358221220b93d96f03f8a3c92e93fcc63620696fc0191a00f43f18c50fdbd35a67d4c9f9164736f6c63430008020033»
>
Invalid constructor arguments provided. Please verify that they are in ABI-encoded format
Failed to verify 1 contract(s): Vizva721Proxy

The text was updated successfully, but these errors were encountered:

Источник

@panayiotischri_twitter I dug in for hours but unfortunately couldn’t find anything in the docs that could satisfy my reqmt.
@MicahZoltu it does, but the AST doesn’t exactly solve the problem. I’m looking for a data structure containing all identifiers & their info like scopes (so everything in 1 place). This COULD be derived from the AST but I was wondering if we could get something ready-made. After-all, the EVM too must be using some kind of symbol table..

hi guys, can anyone help me? i am trying to invoke a function from smart contract using the accounts created from ethereumjs-utils. what should i do? i tried to sign using rawtransaction . how should the order be like? create accounts first or signing transactions? thank you

hey guys- Is anyone familiar with how to get encoded ABI from a deployed smart contract (on remix), or just in general? When trying to verify the contract etherscan asks for constructor function ABI. — I have been looking the entire day and its really frustrating :(

I am willing to pay for services at this point- anyone who can help me with finding out how to get ABI

@jacobsimon thanks for the reply

i did see that. am i supposed to write it out like Arg[0] : xx?

i wrote all of them at once- Error! Invalid constructor arguments provided. Please verify that they are in ABI-encoded format

thats what i got in verify page on etherscan

ive been up for 2 days for this. now at end i can’t publish -_-

hi jacob, can you help me find the answers for my question?

@vraken0 it looks like you’re supposed to do it all together in the encoded format, but I haven’t done it before so can’t explain why it wouldn’t work

@vraken0 Remix spits out the ABI for you.

@MicahZoltu could the issue be using the older one?

I see remix does, but a really big number uint256, seems like the abi is wrong

@yubi00 rawtransaction requires that your transaction is already signed by the account, if I’m understanding what you’re asking

Hmm, maybe I was wrong and Remix doesn’t make the constructor parameters obvious.

for the most part it does

but i know for uint256 — large number, it doesnt know what to do

Does your contract have constructor parameters?

It has always been unclear to me why etherscan doesn’t just do the ABI encoding itself.

Asking for the user to supply ABI encoded parameters makes verification a huge PITA.

has address, string, uint256, and uint8

would i have to provide abi for anything else?

only the parameters in the constructor right?

Just the constructor parameters I believe.

my uint256 is quite a large number

how would i find abi for that

i didn’t know it was this difficult to verify a contract lol -_-

For simple parameters, they are just concatenated end on end.

The string is the tricky one.

my number is 100000000000000000000000000

Yeah, it is stupid how difficult it is to verify a contract in EtherScan. Some parts of it make sense, but others like the need for ABI encoded parameters are just annoying.

string remix did for me, at least i think

any idea how that huge number can convert to abi?

uint256 is just 32 bytes of hex (where each 2 characters is one hex byte).

So a string of 64 numbers.

so i would just pad the front of my # with 0’s until its 64>?

Something along the lines of 0x00000000000000000000000000000000000000000052B7D2DCC80CD2E4000000 (should be 66 characters totaly, counting the leading 0x.

The string is the hard one. ABI encoding of strings is much more complicated than uint and address.

I called simple getter and setter method in solidity using web3js.but its return empty string

pragma solidity ^0.4.0;

contract Text {

bytes32 name;
function setName(bytes32 name){
name = name;
}
function getName() constant returns (bytes32){
return name;
}
}

@karthickkumar863 Use three ` on a line before and after your code block so it stays formatted. You can edit your text by hovering and clicking the … on the right.

@MicahZoltu so this would be my number? 0x0000000000000000000000000000000000000100000000000000000000000000

Probably not, since I suspect your number is base 10?

The number I put above is the hex version of what you had.

and i should be using v2?

of the ether smart contract verification?

I have never been able to get v1 to work.

also, if i had safemath library included in my code

do i still need to add that to libraries part

@MicahZoltu how to use three on before and after code?

Like this:

contract Text {
    ...
}

@vraken0 Depends on how you are using SafeMath. If all of the methods on it are internal and you are using using SafeMath for uint256 then you need to include the code, but you don’t have to upload it separately and fill in the library addresses thing.

yes code was already in contract

So your code references library code deployed at a different address?

code references library code in the same file

i put using SafeMath for uint256 when i needed to use it

Error! Invalid constructor arguments provided. Please verify that they are in ABI-encoded format

can i print data in solidity? if yes mean how is it?

@MicahZoltu am i able to msg you directly?

library SafeMath {
  function add(uint256 a, uint256 b) internal returns (uint256) {
    return a  + b;
  }
}
contract MyContract {
  using SafeMath for uint256;
  ...
}

Like this @vraken0?

As long as the library source code is part of the code in the verified contracts source area you are fine.

@karthickkumar863 Depends on what you mean by «print».

ABI encoding is the pits.

Someone should make a tiny little webapp that just lets you add fields and values and it spits out the ABI encoded result.

how to trigger the smart contract code using contract accounts?

can anyone help me please ?

how to make token show up on etherscan?

smart contract for token went thru and also verified… but it shows as contract

@MicahZoltu Print means console.log() .How to check it in solidity?

@karthickkumar863 closest you can get is sending events

seems like last week when my contract triggered revert() from a modifier my web3 interpreted the response as an error and I could field it correctly, now I’m getting successful responses from reverted transactions and don’t know how to tell whether the response was successful or not. is there a better method for handling these or could something be wrong with my modifier syntax?

struct Account {
 bool exists;
 ...
}
mapping (bytes16 => Account) public accounts;
modifier exists(bytes16 b) { if (!accounts[b].exists) revert(); _; }
function accountExists (bytes16 b) public exists(b) constant {}

accountExists() gives a successful response on all transaction calls, shouldn’t it give an error when the account doesn’t exist?

@mcdee «Yeah, delegatecall needs to know the size of the data being returned so dynamic information cannot be returned» => It will be fixed by Metropolis HF. We will have new opcodes for that

it seems TestRPC returns an invalid op_code when revert() occurs whereas rinkeby returns no such error. Does anyone have another method for detecting reverted transactions?

@duaraghav8 not sure if axic already answered your question, but the json-AST contains all that information, especially in the new format

I have started testrpc.Here i have created one contract and deployed.How to see account and addressfor that contract using javascript console.

Hi, can anyone point me to an example of switch statement use?

im getting acompile error, not sure why

can i create a new instance of a struct (on the stack), populate it and then pass it to another function?

and why doesnt this compile:

var proposal = memory Proposal({ typ: ProposalType.CreateManager, createManagerId: id});
createProposal(proposal);

sender doesn’t have enough funds to send tx. The upfront cost is: 1096934302059488651232480448213795118311813168 and the senders account only has: 10000000000000000000

can anyone help me please ?

i am trying to send raw transaction using contract account using contract accounts created using ethereumjs-util

web3.eth.sendRawTransaction(serializedTx.toString(‘hex’), function(err, transactionhash) {
if (!err){
console.log(transactionhash);
}else
{
console.log(«Raw transaction Error:»+err);
}

});

can anyone help me ? the account created has enough ethers too

Is there any library code that would help extract from msg.data the function name and the associated data? Thanks for any pointers.

contract.transfer.getData() is giving me error — getData() is not the function

@Janaka-Steph Do you have a link to the EIP describing the changes (or just the EIP number)?

@mcdee Sure, ethereum/EIPs#211

contract A is B(this) => this is suppose to work, right ? passing the address of A to B

is getData() still working to get data or it is deprecated

@Janaka-Steph If A is B, then B’s functions would have access to everything in A, they are part of the same contract. You can just refer to this anywhere in B’s code. So why bother with passing this is this way?

Hi I have one issue i run below code function send(address receiver, uint amount) returns(uint success){
if (balances[msg.sender] < amount) return amount;
balances[msg.sender] -= amount;
balances[receiver] += amount;
success = balances[msg.sender];
return success;
}

Result: {
«transactionHash»: «0xa3c8c792d8ecc26ccafc7eeb0d3a1e394577c2651b610eb8fa089d62a1d22e0f»,
«transactionIndex»: 0,
«blockHash»: «0x619896d1d4cb448197f190f10adaea4351861b6247a375e2603357aca16d80d6»,
«blockNumber»: 26,
«gasUsed»: 23486,
«cumulativeGasUsed»: 23486,
«contractAddress»: null,
«logs»: []
}
Transaction cost: 23486 gas.

what is the recommended token specification to implement?

I thought I read that there is a problem with ERC20

@phalexo this is A address

but yes I will try with a global var

@felixwatts ERC20 isn’t without issues but it’s perfectly usable and used for most tokens today.

ERC223 isn’t even out of discussion stage

@mcdee Just curious why ERC223 is out of discussion?

ERC223 events aren’t tracked by any of the big guys (Like etherscan)

So if you intend to implement the ERC223 protocol like I did, make sure you have fallback events firing instead of the new ones as well otherwise your token cannot be tracked or implemented in exchanges correctly.

I learned that the hard way.

ah.. I got it. sure. Thanks a lot @alekakoC

Names haven’t been decided, functionality hasn’t been decided, there’s a long way for it to go

@Janaka-Steph This is confusing. A is B is an inheritance mechanism. this becomes available only when you actually instantiate a contract.

so A is not instanciate yet ?

@Janaka-Steph Not until you deploy it, and it gets mined, and you get a transaction number for the deployment. It is cobbled together by that time.

I am playing with that as well.

because even with a global var I have kind off the same issue

You would not use inheritance with that goal in mind.

I need A is B, then I need B address in A, this is why I inherits

but registry should be cleaner

There is only one address. It is the same within the derived contract’s instance.

A and B become two aspects of ONE thing, AandB

You could also do C is A, B and use C.

@phalexo I want to implement a modifier ifSenderIs()

then in B I have a method that can only be called by A

if A and B have the same adress, what am I suppose to do ? :-/

A is B basically means import all of the code from B in to this contract, so just make the method internal

but I was thinking that an attacker can simply recreate A

and be able to call B methods

They can, but that would be in their contract not yours.

(A is public facing methods, B is storage)

evil A will override good A and call good B

If you made B storage to keep it separate from A then you want a different configuration. You want B to be standalone and instantiated with the address of the contract that can access it. So the you create A, and inside A create B with A’s address

@mcdee So you don’t use SimpleTokenStorage directly in Token, you use DividendTokenStore but the idea is here

instead of inheritance you instantiate the storage contract into Token or use an existing addr

@mcdee I meant to ask you. In your approach, is it still important to keep the storage order the same when code is upgraded?

Hi, is it possible to declare a bytes32[] literal? I tried:
bytes32[] memory candidates = ['Alice', 'Bob', 'Carol'];
But it says that strings are not implicitly convertible to bytes32.

How do dapp make revenue to sustain the team behind it? If they charge a fee, someone can simply clone a version of the dapp and remove the fees

Adding use/value to the community and centralization can be a factor: Anyone can spin up a new version of Bitcoin with a bigger block reward and/or less fees (Dogecoin, etc.), but getting others to use it is the trick then; the fork is not the real/original, and must rebuild a community around itself. If other services provide incentives for holding the «real/original» thing, and don’t acknowledge any forks, then the original holds.

@nyxynyx Build a centralized component to the platform.

@nvonpentz bytes32[3] memory candidates = [bytes32('Alice'), 'Bob', 'Carol'];

array sub-type is derived from first element when you do it like that.

@MicahZoltu You said above «Someone should make a tiny little webapp that just lets you add fields and values and it spits out the ABI encoded result.» QuickBlocks has a tool called grabABI which, given an Ethereum address will pull down the ABI from Etherscan, if it finds one, and present all the functions and all the events with their encodings. Like this grabABI -e 0x021020432898whatever.... and it spits out the encodings. It’s a command line not a web app, but still.

The issue in this case is that in order to verify a contract with a constructor on EtherScan you have to first ABI encode your constructor parameters and give them to etherscan.

Is it more gas efficient to access a struct through a mapping or to access individual mappings?

I believe they compile down to the same or similar.

I’m not sure if they end up actually using the same gas though.

@alekakoC If you have a single map then you need only one copy of keys, otherwise multiple copies. The tricky part would be to lay out the structure so that it is well packed.

@phalexo Could you elaborate on «well packed»?

Depending on types (I am thinking about how structs are packed in other languages) a compiler may stick in padding if there are alignment requirements.

If some struct fields are needed rarely and others frequently maybe keeping those separate would be better.

Okay now I understand, uint256 types shouldn’t cause any padding issues I presume. Would the following pieces of code cost the same gas?:

mapping(address => Account) accounts;
struct Account {
    uint256 lastBalance;
    uint256 balance;
}
function accessStruct() {
    uint256 temp1 = accounts(msg.sender).balance;
    uint256 temp2 = accounts(msg.sender).lastBalance;
}
mapping(address => Account) accounts;
struct Account {
    uint256 lastBalance;
    uint256 balance;
}
function accessStruct() {
    Account temp = accounts(msg.sender);
    uint256 temp1 = temp.balance;
    uint256 temp2 = temp.lastBalance;
}
mapping(address => uint256) balance;
mapping(address => uint256) lastBalance;
function accessStruct() {
    uint256 temp1 = balance(msg.sender);
    uint256 temp2 = lastBalance(msg.sender);
}

How often would you need to be accessing lastBalance versus balance?

I think maps to structs are the same as multiple maps to each item in the struct.

@phalexo Same, I had an additional address in there but that is rarely accessed so I will create a separate mapping for it

1 look up versus multiple.

@MicahZoltu grabABI pulls the ABI from anywhere, not just Etherscan, but I get your point.

@alekakoC Then keep them as a struct.

How about the first code snippet compared to the second one?

I know for example in Java you can improve efficiency if you do it the way I did in the second code snippet.

I would recommend using the struct as well. Without compelling evidence to suggest there is some performance advantage to splitting the data apart, group them logically so the code is easier to read.

Although the new struct variable initialization would offset the double mapping access gas cost I guess.

I prefer the second because I find it easier to read, especially when there are a lot of variables.

Make sure to change your code to Account storage temp = accounts(msg.sender) though.

I forget what the default is, but in general I recommend being explicit because the difference between memory and storage in this context is potentially a lot of copying.

@MicahZoltu So the storage keyword essentially saves the memory address instead of copying a new copy of the struct in memory right?

Wouldn’t the second code snippet cost more gas than the first one though?

temp in that snippet (when using storage keyword) would just be a reference variable.

Ah okay so no initialization

@alekakoC The second one requires one call versus two.

I think the difference in gas cost for the two is negligible.

If it was memory then the gas cost would be higher since it would copy the data from storage into memory.

The Constructor Arguments are automatically appended to the end of the contract source bytecode when the contract is compiled by Solidity.

These are a few examples of contracts with Constructor Arguments:

https://etherscan.io/address/0x7da82c7ab4771ff031b66538d2fb9b0b047f6cf9#code
https://etherscan.io/address/0x85bc00724203d53536072b000c44a2cc16cd12c5#code
https://etherscan.io/address/0x63091244180ae240c87d1f528f5f269134cb07b3#code

When verifying the contract source code at Etherscan we require that you also provide us with the Constructor Arguments (if the contract required these) used when deploying your Ethereum Smart contract. We will use this information to perform a blockchain search to see if it matches with the existing bytecodes. The Constructor argument should be provided in ABI hex encoded form (see https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI for additional information).

00000000000000000000000033daedabab9085bd1a94460a652e7ffff592dfe3000000000000000000000000fec8bb460c2501b8c1d4801f34b4408c1fbbccb1

Which when decoded would be

Arg [0] : 00000000000000000000000033daedabab9085bd1a94460a652e7ffff592dfe3
Arg [1] : 000000000000000000000000fec8bb460c2501b8c1d4801f34b4408c1fbbccb1

Another quick and dirty way of figuring out what your constructor arguments are is to compare both the browser solidity / remix compiled byte code and compare this with the input creation byte code. If you look carefully you will notice that the additional hex codes attached at the END of the input created byte code. This is your ‘Constructor Arguments’.

POA Network is now a part of the Gnosis ecosystem.

Learn more

The swap is expired. POA tokens are still used on the POA network to pay for transaction costs, however tokens have been delisted from all reputable exchanges. You should not purchase POA with the expectation of any associated financial value.

The following is for informational purposes only, there is no longer an ability to swap POA or POA20 tokens.

Swap Information (Deprecated)


POA can be swapped for the STAKE token on xDai at a rate of
466.6163443 POA per 1 STAKE. This price was derived using a TWAP (Time-weighted Average Price) for the 2 tokens between October 21, 2021 and November 3, 2021.

This opportunity is available until May 5, 2022 at which time swapping will stop. The network will continue to operate in a staging capacity without value-based emissions or rewards.

Some users have been sending STAKE directly from the xDai chain to Huobi or Gate exchanges. DO NOT DO THIS OR YOU WILL LOSE YOUR TOKENS!

The ONLY EXCHANGE THAT ACCEPTS STAKE FROM XDAI IS

ASCENDEX

.

Recommend Projects

  • React photo

    React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo

    Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo

    Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo

    TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo

    Django

    The Web framework for perfectionists with deadlines.

  • Laravel photo

    Laravel

    A PHP framework for web artisans

  • D3 photo

    D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Visualization

    Some thing interesting about visualization, use data art

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo

    Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo

    Microsoft

    Open source projects and samples from Microsoft.

  • Google photo

    Google

    Google ❤️ Open Source for everyone.

  • Alibaba photo

    Alibaba

    Alibaba Open Source for everyone

  • D3 photo

    D3

    Data-Driven Documents codes.

  • Tencent photo

    Tencent

    China tencent open source team.

Понравилась статья? Поделить с друзьями:
  • Error invalid class object
  • Error invalid captcha response
  • Error invalid byte sequence for encoding utf8 0xff
  • Error invalid byte sequence for encoding utf8 0xd0
  • Error invalid byte sequence for encoding utf8 0x00