rkalis / truffle-plugin-verify

✅ Verify your smart contracts on Etherscan from the Truffle CLI
https://kalis.me/verify-truffle-smart-contracts-etherscan/
MIT License
467 stars 130 forks source link

Unable to verify contracts on Etherscan programatically, manually works #27

Closed chpiatt closed 4 years ago

chpiatt commented 4 years ago

I'm unable to verify my contract via the plugin, but if I copy the source directly into the verifier on Rinkeby Etherscan the verification works perfectly.

I noticed the API call is stripping the multiline comments from the "sourceCode" field in the API call, but that is the only thing I can see that's different. The compiler version, runs, etc. are all the same. Here's the output of the debug call if it helps:

DEBUG logging is turned ON
Verifying PromotedPool@0x3D0Cb6CC9ddc16e96B26b4a0613bb46667ff2928
Reading artifact file at /Users/chrispiatt/workspace/blocklytics/promoted-pools/contracts/build/contracts/PromotedPool.json
Custom address 0x3D0Cb6CC9ddc16e96B26b4a0613bb46667ff2928 specified
Retrieving constructor parameters from https://api-rinkeby.etherscan.io/api?module=account&action=txlist&address=0x3D0Cb6CC9ddc16e96B26b4a0613bb46667ff2928&page=1&sort=asc&offset=1
Constructor parameters received: 0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000f57b2c51ded3a29e6891aba85459d600256cf317000000000000000000000000000000000000000000000000000000000000000f506f6f6c732e6679692050726f6d6f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034659490000000000000000000000000000000000000000000000000000000000
Flattening source file /Users/chrispiatt/workspace/blocklytics/promoted-pools/contracts/contracts/PromotedPool.sol
Sending verify request with POST arguments:
{
  "apikey": "27M9WCQP64YCKCZ74ENNVKCVR771X76BZM",
  "module": "contract",
  "action": "verifysourcecode",
  "contractaddress": "0x3D0Cb6CC9ddc16e96B26b4a0613bb46667ff2928",
  "sourceCode": "pragma solidity ^0.5.0;\n\n\ncontract Context {\n    // Empty internal constructor, to prevent people from mistakenly deploying\n    // an instance of this contract, which should be used via inheritance.\n    constructor () internal { }\n    // solhint-disable-previous-line no-empty-blocks\n\n    function _msgSender() internal view returns (address payable) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view returns (bytes memory) {\n        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n        return msg.data;\n    }\n}\n\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n\ncontract IERC721 is IERC165 {\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n    /**\n     * @dev Returns the number of NFTs in `owner`'s account.\n     */\n    function balanceOf(address owner) public view returns (uint256 balance);\n\n    /**\n     * @dev Returns the owner of the NFT specified by `tokenId`.\n     */\n    function ownerOf(uint256 tokenId) public view returns (address owner);\n\n    /**\n     * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to\n     * another (`to`).\n     *\n     *\n     *\n     * Requirements:\n     * - `from`, `to` cannot be zero.\n     * - `tokenId` must be owned by `from`.\n     * - If the caller is not `from`, it must be have been allowed to move this\n     * NFT by either {approve} or {setApprovalForAll}.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId) public;\n    /**\n     * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to\n     * another (`to`).\n     *\n     * Requirements:\n     * - If the caller is not `from`, it must be approved to move this NFT by\n     * either {approve} or {setApprovalForAll}.\n     */\n    function transferFrom(address from, address to, uint256 tokenId) public;\n    function approve(address to, uint256 tokenId) public;\n    function getApproved(uint256 tokenId) public view returns (address operator);\n\n    function setApprovalForAll(address operator, bool _approved) public;\n    function isApprovedForAll(address owner, address operator) public view returns (bool);\n\n\n    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public;\n}\n\ncontract IERC721Receiver {\n    /**\n     * @notice Handle the receipt of an NFT\n     * @dev The ERC721 smart contract calls this function on the recipient\n     * after a {IERC721-safeTransferFrom}. This function MUST return the function selector,\n     * otherwise the caller will revert the transaction. The selector to be\n     * returned can be obtained as `this.onERC721Received.selector`. This\n     * function MAY throw to revert and reject the transfer.\n     * Note: the ERC721 contract address is always the message sender.\n     * @param operator The address which called `safeTransferFrom` function\n     * @param from The address which previously owned the token\n     * @param tokenId The NFT identifier which is being transferred\n     * @param data Additional data with no specified format\n     * @return bytes4 `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\n     */\n    function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data)\n    public returns (bytes4);\n}\n\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 c = a + b;\n        require(c >= a, \"SafeMath: addition overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        return sub(a, b, \"SafeMath: subtraction overflow\");\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     * - Subtraction cannot overflow.\n     *\n     * _Available since v2.4.0._\n     */\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b <= a, errorMessage);\n        uint256 c = a - b;\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n        // benefit is lost if 'b' is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) {\n            return 0;\n        }\n\n        uint256 c = a * b;\n        require(c / a == b, \"SafeMath: multiplication overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        return div(a, b, \"SafeMath: division by zero\");\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     * - The divisor cannot be zero.\n     *\n     * _Available since v2.4.0._\n     */\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        // Solidity only automatically asserts when dividing by 0\n        require(b > 0, errorMessage);\n        uint256 c = a / b;\n        // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        return mod(a, b, \"SafeMath: modulo by zero\");\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts with custom message when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     * - The divisor cannot be zero.\n     *\n     * _Available since v2.4.0._\n     */\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b != 0, errorMessage);\n        return a % b;\n    }\n}\n\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * This test is non-exhaustive, and there may be false-negatives: during the\n     * execution of a contract's constructor, its address will be reported as\n     * not containing a contract.\n     *\n     * IMPORTANT: It is unsafe to assume that an address for which this\n     * function returns false is an externally-owned account (EOA) and not a\n     * contract.\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies in extcodesize, which returns 0 for contracts in\n        // construction, since the code is only stored at the end of the\n        // constructor execution.\n\n        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts\n        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned\n        // for accounts without code, i.e. `keccak256('')`\n        bytes32 codehash;\n        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { codehash := extcodehash(account) }\n        return (codehash != 0x0 && codehash != accountHash);\n    }\n\n    /**\n     * @dev Converts an `address` into `address payable`. Note that this is\n     * simply a type cast: the actual underlying value is not changed.\n     *\n     * _Available since v2.4.0._\n     */\n    function toPayable(address account) internal pure returns (address payable) {\n        return address(uint160(account));\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} 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 be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     *\n     * _Available since v2.4.0._\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        // solhint-disable-next-line avoid-call-value\n        (bool success, ) = recipient.call.value(amount)(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n}\n\nlibrary Counters {\n    using SafeMath for uint256;\n\n    struct Counter {\n        // This variable should never be directly accessed by users of the library: interactions must be restricted to\n        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add\n        // this feature: see https://github.com/ethereum/solidity/issues/4637\n        uint256 _value; // default: 0\n    }\n\n    function current(Counter storage counter) internal view returns (uint256) {\n        return counter._value;\n    }\n\n    function increment(Counter storage counter) internal {\n        counter._value += 1;\n    }\n\n    function decrement(Counter storage counter) internal {\n        counter._value = counter._value.sub(1);\n    }\n}\n\ncontract ERC165 is IERC165 {\n    /*\n     * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7\n     */\n    bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;\n\n    /**\n     * @dev Mapping of interface ids to whether or not it's supported.\n     */\n    mapping(bytes4 => bool) private _supportedInterfaces;\n\n    constructor () internal {\n        // Derived contracts need only register support for their own interfaces,\n        // we register support for ERC165 itself here\n        _registerInterface(_INTERFACE_ID_ERC165);\n    }\n\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     *\n     * Time complexity O(1), guaranteed to always use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool) {\n        return _supportedInterfaces[interfaceId];\n    }\n\n    /**\n     * @dev Registers the contract as an implementer of the interface defined by\n     * `interfaceId`. Support of the actual ERC165 interface is automatic and\n     * registering its interface id is not required.\n     *\n     * See {IERC165-supportsInterface}.\n     *\n     * Requirements:\n     *\n     * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).\n     */\n    function _registerInterface(bytes4 interfaceId) internal {\n        require(interfaceId != 0xffffffff, \"ERC165: invalid interface id\");\n        _supportedInterfaces[interfaceId] = true;\n    }\n}\n\ncontract ERC721 is Context, ERC165, IERC721 {\n    using SafeMath for uint256;\n    using Address for address;\n    using Counters for Counters.Counter;\n\n    // Equals to `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\n    // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`\n    bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;\n\n    // Mapping from token ID to owner\n    mapping (uint256 => address) private _tokenOwner;\n\n    // Mapping from token ID to approved address\n    mapping (uint256 => address) private _tokenApprovals;\n\n    // Mapping from owner to number of owned token\n    mapping (address => Counters.Counter) private _ownedTokensCount;\n\n    // Mapping from owner to operator approvals\n    mapping (address => mapping (address => bool)) private _operatorApprovals;\n\n    /*\n     *     bytes4(keccak256('balanceOf(address)')) == 0x70a08231\n     *     bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e\n     *     bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3\n     *     bytes4(keccak256('getApproved(uint256)')) == 0x081812fc\n     *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465\n     *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5\n     *     bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd\n     *     bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e\n     *     bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde\n     *\n     *     => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^\n     *        0xa22cb465 ^ 0xe985e9c ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd\n     */\n    bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;\n\n    constructor () public {\n        // register the supported interfaces to conform to ERC721 via ERC165\n        _registerInterface(_INTERFACE_ID_ERC721);\n    }\n\n    /**\n     * @dev Gets the balance of the specified address.\n     * @param owner address to query the balance of\n     * @return uint256 representing the amount owned by the passed address\n     */\n    function balanceOf(address owner) public view returns (uint256) {\n        require(owner != address(0), \"ERC721: balance query for the zero address\");\n\n        return _ownedTokensCount[owner].current();\n    }\n\n    /**\n     * @dev Gets the owner of the specified token ID.\n     * @param tokenId uint256 ID of the token to query the owner of\n     * @return address currently marked as the owner of the given token ID\n     */\n    function ownerOf(uint256 tokenId) public view returns (address) {\n        address owner = _tokenOwner[tokenId];\n        require(owner != address(0), \"ERC721: owner query for nonexistent token\");\n\n        return owner;\n    }\n\n    /**\n     * @dev Approves another address to transfer the given token ID\n     * The zero address indicates there is no approved address.\n     * There can only be one approved address per token at a given time.\n     * Can only be called by the token owner or an approved operator.\n     * @param to address to be approved for the given token ID\n     * @param tokenId uint256 ID of the token to be approved\n     */\n    function approve(address to, uint256 tokenId) public {\n        address owner = ownerOf(tokenId);\n        require(to != owner, \"ERC721: approval to current owner\");\n\n        require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),\n            \"ERC721: approve caller is not owner nor approved for all\"\n        );\n\n        _tokenApprovals[tokenId] = to;\n        emit Approval(owner, to, tokenId);\n    }\n\n    /**\n     * @dev Gets the approved address for a token ID, or zero if no address set\n     * Reverts if the token ID does not exist.\n     * @param tokenId uint256 ID of the token to query the approval of\n     * @return address currently approved for the given token ID\n     */\n    function getApproved(uint256 tokenId) public view returns (address) {\n        require(_exists(tokenId), \"ERC721: approved query for nonexistent token\");\n\n        return _tokenApprovals[tokenId];\n    }\n\n    /**\n     * @dev Sets or unsets the approval of a given operator\n     * An operator is allowed to transfer all tokens of the sender on their behalf.\n     * @param to operator address to set the approval\n     * @param approved representing the status of the approval to be set\n     */\n    function setApprovalForAll(address to, bool approved) public {\n        require(to != _msgSender(), \"ERC721: approve to caller\");\n\n        _operatorApprovals[_msgSender()][to] = approved;\n        emit ApprovalForAll(_msgSender(), to, approved);\n    }\n\n    /**\n     * @dev Tells whether an operator is approved by a given owner.\n     * @param owner owner address which you want to query the approval of\n     * @param operator operator address which you want to query the approval of\n     * @return bool whether the given operator is approved by the given owner\n     */\n    function isApprovedForAll(address owner, address operator) public view returns (bool) {\n        return _operatorApprovals[owner][operator];\n    }\n\n    /**\n     * @dev Transfers the ownership of a given token ID to another address.\n     * Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\n     * Requires the msg.sender to be the owner, approved, or operator.\n     * @param from current owner of the token\n     * @param to address to receive the ownership of the given token ID\n     * @param tokenId uint256 ID of the token to be transferred\n     */\n    function transferFrom(address from, address to, uint256 tokenId) public {\n        //solhint-disable-next-line max-line-length\n        require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: transfer caller is not owner nor approved\");\n\n        _transferFrom(from, to, tokenId);\n    }\n\n    /**\n     * @dev Safely transfers the ownership of a given token ID to another address\n     * If the target address is a contract, it must implement {IERC721Receiver-onERC721Received},\n     * which is called upon a safe transfer, and return the magic value\n     * `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`; otherwise,\n     * the transfer is reverted.\n     * Requires the msg.sender to be the owner, approved, or operator\n     * @param from current owner of the token\n     * @param to address to receive the ownership of the given token ID\n     * @param tokenId uint256 ID of the token to be transferred\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId) public {\n        safeTransferFrom(from, to, tokenId, \"\");\n    }\n\n    /**\n     * @dev Safely transfers the ownership of a given token ID to another address\n     * If the target address is a contract, it must implement {IERC721Receiver-onERC721Received},\n     * which is called upon a safe transfer, and return the magic value\n     * `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`; otherwise,\n     * the transfer is reverted.\n     * Requires the _msgSender() to be the owner, approved, or operator\n     * @param from current owner of the token\n     * @param to address to receive the ownership of the given token ID\n     * @param tokenId uint256 ID of the token to be transferred\n     * @param _data bytes data to send along with a safe transfer check\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public {\n        require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: transfer caller is not owner nor approved\");\n        _safeTransferFrom(from, to, tokenId, _data);\n    }\n\n    /**\n     * @dev Safely transfers the ownership of a given token ID to another address\n     * If the target address is a contract, it must implement `onERC721Received`,\n     * which is called upon a safe transfer, and return the magic value\n     * `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`; otherwise,\n     * the transfer is reverted.\n     * Requires the msg.sender to be the owner, approved, or operator\n     * @param from current owner of the token\n     * @param to address to receive the ownership of the given token ID\n     * @param tokenId uint256 ID of the token to be transferred\n     * @param _data bytes data to send along with a safe transfer check\n     */\n    function _safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) internal {\n        _transferFrom(from, to, tokenId);\n        require(_checkOnERC721Received(from, to, tokenId, _data), \"ERC721: transfer to non ERC721Receiver implementer\");\n    }\n\n    /**\n     * @dev Returns whether the specified token exists.\n     * @param tokenId uint256 ID of the token to query the existence of\n     * @return bool whether the token exists\n     */\n    function _exists(uint256 tokenId) internal view returns (bool) {\n        address owner = _tokenOwner[tokenId];\n        return owner != address(0);\n    }\n\n    /**\n     * @dev Returns whether the given spender can transfer a given token ID.\n     * @param spender address of the spender to query\n     * @param tokenId uint256 ID of the token to be transferred\n     * @return bool whether the msg.sender is approved for the given token ID,\n     * is an operator of the owner, or is the owner of the token\n     */\n    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {\n        require(_exists(tokenId), \"ERC721: operator query for nonexistent token\");\n        address owner = ownerOf(tokenId);\n        return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));\n    }\n\n    /**\n     * @dev Internal function to safely mint a new token.\n     * Reverts if the given token ID already exists.\n     * If the target address is a contract, it must implement `onERC721Received`,\n     * which is called upon a safe transfer, and return the magic value\n     * `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`; otherwise,\n     * the transfer is reverted.\n     * @param to The address that will own the minted token\n     * @param tokenId uint256 ID of the token to be minted\n     */\n    function _safeMint(address to, uint256 tokenId) internal {\n        _safeMint(to, tokenId, \"\");\n    }\n\n    /**\n     * @dev Internal function to safely mint a new token.\n     * Reverts if the given token ID already exists.\n     * If the target address is a contract, it must implement `onERC721Received`,\n     * which is called upon a safe transfer, and return the magic value\n     * `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`; otherwise,\n     * the transfer is reverted.\n     * @param to The address that will own the minted token\n     * @param tokenId uint256 ID of the token to be minted\n     * @param _data bytes data to send along with a safe transfer check\n     */\n    function _safeMint(address to, uint256 tokenId, bytes memory _data) internal {\n        _mint(to, tokenId);\n        require(_checkOnERC721Received(address(0), to, tokenId, _data), \"ERC721: transfer to non ERC721Receiver implementer\");\n    }\n\n    /**\n     * @dev Internal function to mint a new token.\n     * Reverts if the given token ID already exists.\n     * @param to The address that will own the minted token\n     * @param tokenId uint256 ID of the token to be minted\n     */\n    function _mint(address to, uint256 tokenId) internal {\n        require(to != address(0), \"ERC721: mint to the zero address\");\n        require(!_exists(tokenId), \"ERC721: token already minted\");\n\n        _tokenOwner[tokenId] = to;\n        _ownedTokensCount[to].increment();\n\n        emit Transfer(address(0), to, tokenId);\n    }\n\n    /**\n     * @dev Internal function to burn a specific token.\n     * Reverts if the token does not exist.\n     * Deprecated, use {_burn} instead.\n     * @param owner owner of the token to burn\n     * @param tokenId uint256 ID of the token being burned\n     */\n    function _burn(address owner, uint256 tokenId) internal {\n        require(ownerOf(tokenId) == owner, \"ERC721: burn of token that is not own\");\n\n        _clearApproval(tokenId);\n\n        _ownedTokensCount[owner].decrement();\n        _tokenOwner[tokenId] = address(0);\n\n        emit Transfer(owner, address(0), tokenId);\n    }\n\n    /**\n     * @dev Internal function to burn a specific token.\n     * Reverts if the token does not exist.\n     * @param tokenId uint256 ID of the token being burned\n     */\n    function _burn(uint256 tokenId) internal {\n        _burn(ownerOf(tokenId), tokenId);\n    }\n\n    /**\n     * @dev Internal function to transfer ownership of a given token ID to another address.\n     * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\n     * @param from current owner of the token\n     * @param to address to receive the ownership of the given token ID\n     * @param tokenId uint256 ID of the token to be transferred\n     */\n    function _transferFrom(address from, address to, uint256 tokenId) internal {\n        require(ownerOf(tokenId) == from, \"ERC721: transfer of token that is not own\");\n        require(to != address(0), \"ERC721: transfer to the zero address\");\n\n        _clearApproval(tokenId);\n\n        _ownedTokensCount[from].decrement();\n        _ownedTokensCount[to].increment();\n\n        _tokenOwner[tokenId] = to;\n\n        emit Transfer(from, to, tokenId);\n    }\n\n    /**\n     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\n     * The call is not executed if the target address is not a contract.\n     *\n     * This function is deprecated.\n     * @param from address representing the previous owner of the given token ID\n     * @param to target address that will receive the tokens\n     * @param tokenId uint256 ID of the token to be transferred\n     * @param _data bytes optional data to send along with the call\n     * @return bool whether the call correctly returned the expected magic value\n     */\n    function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)\n        internal returns (bool)\n    {\n        if (!to.isContract()) {\n            return true;\n        }\n\n        bytes4 retval = IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data);\n        return (retval == _ERC721_RECEIVED);\n    }\n\n    /**\n     * @dev Private function to clear current approval of a given token ID.\n     * @param tokenId uint256 ID of the token to be transferred\n     */\n    function _clearApproval(uint256 tokenId) private {\n        if (_tokenApprovals[tokenId] != address(0)) {\n            _tokenApprovals[tokenId] = address(0);\n        }\n    }\n}\n\ncontract IERC721Enumerable is IERC721 {\n    function totalSupply() public view returns (uint256);\n    function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256 tokenId);\n\n    function tokenByIndex(uint256 index) public view returns (uint256);\n}\n\ncontract ERC721Enumerable is Context, ERC165, ERC721, IERC721Enumerable {\n    // Mapping from owner to list of owned token IDs\n    mapping(address => uint256[]) private _ownedTokens;\n\n    // Mapping from token ID to index of the owner tokens list\n    mapping(uint256 => uint256) private _ownedTokensIndex;\n\n    // Array with all token ids, used for enumeration\n    uint256[] private _allTokens;\n\n    // Mapping from token id to position in the allTokens array\n    mapping(uint256 => uint256) private _allTokensIndex;\n\n    /*\n     *     bytes4(keccak256('totalSupply()')) == 0x18160ddd\n     *     bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59\n     *     bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7\n     *\n     *     => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63\n     */\n    bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;\n\n    /**\n     * @dev Constructor function.\n     */\n    constructor () public {\n        // register the supported interface to conform to ERC721Enumerable via ERC165\n        _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);\n    }\n\n    /**\n     * @dev Gets the token ID at a given index of the tokens list of the requested owner.\n     * @param owner address owning the tokens list to be accessed\n     * @param index uint256 representing the index to be accessed of the requested tokens list\n     * @return uint256 token ID at the given index of the tokens list owned by the requested address\n     */\n    function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) {\n        require(index < balanceOf(owner), \"ERC721Enumerable: owner index out of bounds\");\n        return _ownedTokens[owner][index];\n    }\n\n    /**\n     * @dev Gets the total amount of tokens stored by the contract.\n     * @return uint256 representing the total amount of tokens\n     */\n    function totalSupply() public view returns (uint256) {\n        return _allTokens.length;\n    }\n\n    /**\n     * @dev Gets the token ID at a given index of all the tokens in this contract\n     * Reverts if the index is greater or equal to the total number of tokens.\n     * @param index uint256 representing the index to be accessed of the tokens list\n     * @return uint256 token ID at the given index of the tokens list\n     */\n    function tokenByIndex(uint256 index) public view returns (uint256) {\n        require(index < totalSupply(), \"ERC721Enumerable: global index out of bounds\");\n        return _allTokens[index];\n    }\n\n    /**\n     * @dev Internal function to transfer ownership of a given token ID to another address.\n     * As opposed to transferFrom, this imposes no restrictions on msg.sender.\n     * @param from current owner of the token\n     * @param to address to receive the ownership of the given token ID\n     * @param tokenId uint256 ID of the token to be transferred\n     */\n    function _transferFrom(address from, address to, uint256 tokenId) internal {\n        super._transferFrom(from, to, tokenId);\n\n        _removeTokenFromOwnerEnumeration(from, tokenId);\n\n        _addTokenToOwnerEnumeration(to, tokenId);\n    }\n\n    /**\n     * @dev Internal function to mint a new token.\n     * Reverts if the given token ID already exists.\n     * @param to address the beneficiary that will own the minted token\n     * @param tokenId uint256 ID of the token to be minted\n     */\n    function _mint(address to, uint256 tokenId) internal {\n        super._mint(to, tokenId);\n\n        _addTokenToOwnerEnumeration(to, tokenId);\n\n        _addTokenToAllTokensEnumeration(tokenId);\n    }\n\n    /**\n     * @dev Internal function to burn a specific token.\n     * Reverts if the token does not exist.\n     * Deprecated, use {ERC721-_burn} instead.\n     * @param owner owner of the token to burn\n     * @param tokenId uint256 ID of the token being burned\n     */\n    function _burn(address owner, uint256 tokenId) internal {\n        super._burn(owner, tokenId);\n\n        _removeTokenFromOwnerEnumeration(owner, tokenId);\n        // Since tokenId will be deleted, we can clear its slot in _ownedTokensIndex to trigger a gas refund\n        _ownedTokensIndex[tokenId] = 0;\n\n        _removeTokenFromAllTokensEnumeration(tokenId);\n    }\n\n    /**\n     * @dev Gets the list of token IDs of the requested owner.\n     * @param owner address owning the tokens\n     * @return uint256[] List of token IDs owned by the requested address\n     */\n    function _tokensOfOwner(address owner) internal view returns (uint256[] storage) {\n        return _ownedTokens[owner];\n    }\n\n    /**\n     * @dev Private function to add a token to this extension's ownership-tracking data structures.\n     * @param to address representing the new owner of the given token ID\n     * @param tokenId uint256 ID of the token to be added to the tokens list of the given address\n     */\n    function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {\n        _ownedTokensIndex[tokenId] = _ownedTokens[to].length;\n        _ownedTokens[to].push(tokenId);\n    }\n\n    /**\n     * @dev Private function to add a token to this extension's token tracking data structures.\n     * @param tokenId uint256 ID of the token to be added to the tokens list\n     */\n    function _addTokenToAllTokensEnumeration(uint256 tokenId) private {\n        _allTokensIndex[tokenId] = _allTokens.length;\n        _allTokens.push(tokenId);\n    }\n\n    /**\n     * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that\n     * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for\n     * gas optimizations e.g. when performing a transfer operation (avoiding double writes).\n     * This has O(1) time complexity, but alters the order of the _ownedTokens array.\n     * @param from address representing the previous owner of the given token ID\n     * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address\n     */\n    function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {\n        // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and\n        // then delete the last slot (swap and pop).\n\n        uint256 lastTokenIndex = _ownedTokens[from].length.sub(1);\n        uint256 tokenIndex = _ownedTokensIndex[tokenId];\n\n        // When the token to delete is the last token, the swap operation is unnecessary\n        if (tokenIndex != lastTokenIndex) {\n            uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];\n\n            _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token\n            _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index\n        }\n\n        // This also deletes the contents at the last position of the array\n        _ownedTokens[from].length--;\n\n        // Note that _ownedTokensIndex[tokenId] hasn't been cleared: it still points to the old slot (now occupied by\n        // lastTokenId, or just over the end of the array if the token was the last one).\n    }\n\n    /**\n     * @dev Private function to remove a token from this extension's token tracking data structures.\n     * This has O(1) time complexity, but alters the order of the _allTokens array.\n     * @param tokenId uint256 ID of the token to be removed from the tokens list\n     */\n    function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {\n        // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and\n        // then delete the last slot (swap and pop).\n\n        uint256 lastTokenIndex = _allTokens.length.sub(1);\n        uint256 tokenIndex = _allTokensIndex[tokenId];\n\n        // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so\n        // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding\n        // an 'if' statement (like in _removeTokenFromOwnerEnumeration)\n        uint256 lastTokenId = _allTokens[lastTokenIndex];\n\n        _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token\n        _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index\n\n        // This also deletes the contents at the last position of the array\n        _allTokens.length--;\n        _allTokensIndex[tokenId] = 0;\n    }\n}\n\ncontract IERC721Metadata is IERC721 {\n    function name() external view returns (string memory);\n    function symbol() external view returns (string memory);\n    function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n\ncontract ERC721Metadata is Context, ERC165, ERC721, IERC721Metadata {\n    // Token name\n    string private _name;\n\n    // Token symbol\n    string private _symbol;\n\n    // Optional mapping for token URIs\n    mapping(uint256 => string) private _tokenURIs;\n\n    /*\n     *     bytes4(keccak256('name()')) == 0x06fdde03\n     *     bytes4(keccak256('symbol()')) == 0x95d89b41\n     *     bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd\n     *\n     *     => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f\n     */\n    bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;\n\n    /**\n     * @dev Constructor function\n     */\n    constructor (string memory name, string memory symbol) public {\n        _name = name;\n        _symbol = symbol;\n\n        // register the supported interfaces to conform to ERC721 via ERC165\n        _registerInterface(_INTERFACE_ID_ERC721_METADATA);\n    }\n\n    /**\n     * @dev Gets the token name.\n     * @return string representing the token name\n     */\n    function name() external view returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Gets the token symbol.\n     * @return string representing the token symbol\n     */\n    function symbol() external view returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns an URI for a given token ID.\n     * Throws if the token ID does not exist. May return an empty string.\n     * @param tokenId uint256 ID of the token to query\n     */\n    function tokenURI(uint256 tokenId) external view returns (string memory) {\n        require(_exists(tokenId), \"ERC721Metadata: URI query for nonexistent token\");\n        return _tokenURIs[tokenId];\n    }\n\n    /**\n     * @dev Internal function to set the token URI for a given token.\n     * Reverts if the token ID does not exist.\n     * @param tokenId uint256 ID of the token to set its URI\n     * @param uri string URI to assign\n     */\n    function _setTokenURI(uint256 tokenId, string memory uri) internal {\n        require(_exists(tokenId), \"ERC721Metadata: URI set of nonexistent token\");\n        _tokenURIs[tokenId] = uri;\n    }\n\n    /**\n     * @dev Internal function to burn a specific token.\n     * Reverts if the token does not exist.\n     * Deprecated, use _burn(uint256) instead.\n     * @param owner owner of the token to burn\n     * @param tokenId uint256 ID of the token being burned by the msg.sender\n     */\n    function _burn(address owner, uint256 tokenId) internal {\n        super._burn(owner, tokenId);\n\n        // Clear metadata (if any)\n        if (bytes(_tokenURIs[tokenId]).length != 0) {\n            delete _tokenURIs[tokenId];\n        }\n    }\n}\n\ncontract ERC721Full is ERC721, ERC721Enumerable, ERC721Metadata {\n    constructor (string memory name, string memory symbol) public ERC721Metadata(name, symbol) {\n        // solhint-disable-previous-line no-empty-blocks\n    }\n}\n\ncontract ERC721Burnable is Context, ERC721 {\n    /**\n     * @dev Burns a specific ERC721 token.\n     * @param tokenId uint256 id of the ERC721 token to be burned.\n     */\n    function burn(uint256 tokenId) public {\n        //solhint-disable-next-line max-line-length\n        require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721Burnable: caller is not owner nor approved\");\n        _burn(tokenId);\n    }\n}\n\ncontract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor () internal {\n        _owner = _msgSender();\n        emit OwnershipTransferred(address(0), _owner);\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(isOwner(), \"Ownable: caller is not the owner\");\n        _;\n    }\n\n    /**\n     * @dev Returns true if the caller is the current owner.\n     */\n    function isOwner() public view returns (bool) {\n        return _msgSender() == _owner;\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public onlyOwner {\n        emit OwnershipTransferred(_owner, address(0));\n        _owner = address(0);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public onlyOwner {\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     */\n    function _transferOwnership(address newOwner) internal {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        emit OwnershipTransferred(_owner, newOwner);\n        _owner = newOwner;\n    }\n}\n\nlibrary Strings {\n  // via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol\n  function strConcat(string memory _a, string memory _b, string memory _c, string memory _d, string memory _e) internal pure returns (string memory) {\n      bytes memory _ba = bytes(_a);\n      bytes memory _bb = bytes(_b);\n      bytes memory _bc = bytes(_c);\n      bytes memory _bd = bytes(_d);\n      bytes memory _be = bytes(_e);\n      string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);\n      bytes memory babcde = bytes(abcde);\n      uint k = 0;\n      for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];\n      for (uint i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];\n      for (uint i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];\n      for (uint i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];\n      for (uint i = 0; i < _be.length; i++) babcde[k++] = _be[i];\n      return string(babcde);\n    }\n\n    function strConcat(string memory _a, string memory _b, string memory _c, string memory _d) internal pure returns (string memory) {\n        return strConcat(_a, _b, _c, _d, \"\");\n    }\n\n    function strConcat(string memory _a, string memory _b, string memory _c) internal pure returns (string memory) {\n        return strConcat(_a, _b, _c, \"\", \"\");\n    }\n\n    function strConcat(string memory _a, string memory _b) internal pure returns (string memory) {\n        return strConcat(_a, _b, \"\", \"\", \"\");\n    }\n\n    function uint2str(uint _i) internal pure returns (string memory _uintAsString) {\n        if (_i == 0) {\n            return \"0\";\n        }\n        uint j = _i;\n        uint len;\n        while (j != 0) {\n            len++;\n            j /= 10;\n        }\n        bytes memory bstr = new bytes(len);\n        uint k = len - 1;\n        while (_i != 0) {\n            bstr[k--] = byte(uint8(48 + _i % 10));\n            _i /= 10;\n        }\n        return string(bstr);\n    }\n}\n\ncontract OwnableDelegateProxy { }\n\ncontract ProxyRegistry {\n    mapping(address => OwnableDelegateProxy) public proxies;\n}\n\ncontract PromotedPool is ERC721Full, ERC721Burnable, Ownable {\n  using Strings for string;\n\n  address proxyRegistryAddress;\n  uint256 private _currentTokenId;\n  uint256 private _activeTokenId;\n  uint8 public currentTermsVersion;\n\n  struct PromotionPeriod {\n    uint256 startTime;\n    uint256 endTime;\n  }\n\n  struct PoolProposal {\n    address proposedPool;\n    address approvedPool;\n  }\n\n  mapping (uint256 => PromotionPeriod) promotionPeriods;\n  mapping (uint256 => PoolProposal) proposedPools;\n  mapping (uint256 => uint8) termsVersions;\n  mapping (uint8 => string) terms;\n\n  event MintedToken(uint256 indexed tokenId, address indexed tokenOwner, uint256 indexed startTime, uint256 endTime);\n  event PromotedPoolProposed(address indexed poolAddress, uint256 indexed tokenId, uint256 indexed startTime, uint256 endTime);\n  event PromotedPoolApproved(address indexed poolAddress, uint256 indexed tokenId, uint256 indexed startTime, uint256 endTime);\n  event ActiveTokenUpdated(uint256 indexed tokenId);\n  event PromotedPoolReset(uint256 indexed tokenId);\n\n  constructor(string memory _name, string memory _symbol, address _proxyRegistryAddress) ERC721Full(_name, _symbol) public {\n    proxyRegistryAddress = _proxyRegistryAddress;\n  }\n\n  /**\n    * @dev Mints a token to an address with a tokenURI.\n    * @param _to address of the future owner of the token\n    */\n  function mintTo(address _to, uint256 _startTime, uint256 _endTime, string memory _termsHash, uint8 _termsVersion) public onlyOwner {\n    require(_startTime > now, \"Token must have start time in the future.\");\n    require(_startTime > promotionPeriods[_currentTokenId].endTime, \"Token must have start time > most recent token's end time\");\n    if(promotionPeriods[_currentTokenId].endTime != 0) {\n      require(_startTime - promotionPeriods[_currentTokenId].endTime < 7890000 , \"Token must have start time < 1 year after the most recent token's end time\");\n    }\n    uint256 newTokenId = _getNextTokenId();\n    _mint(_to, newTokenId);\n    _incrementTokenId();\n    promotionPeriods[newTokenId] = PromotionPeriod(_startTime, _endTime);\n    proposedPools[newTokenId] = PoolProposal(address(0), address(0));\n    if(_termsVersion > currentTermsVersion) {\n      terms[_termsVersion] = _termsHash;\n      currentTermsVersion = _termsVersion;\n    }\n    termsVersions[newTokenId] = _termsVersion;\n    emit MintedToken(newTokenId, _to, _startTime, _endTime);\n  }\n\n  function proposePromotedPool(uint256 _tokenId, address _poolAddress) public {\n    require(msg.sender == ownerOf(_tokenId), \"You must be the owner of a valid token to propose a promoted pool\");\n    require(promotionPeriods[_tokenId].endTime > now, \"Sorry, this token has expired\");\n    proposedPools[_tokenId].proposedPool = _poolAddress;\n    emit PromotedPoolProposed(_poolAddress, _tokenId, promotionPeriods[_tokenId].startTime, promotionPeriods[_tokenId].endTime);\n  }\n\n  function approvePromotedPool(uint256 _tokenId, address _poolAddress) public onlyOwner {\n    require(proposedPools[_tokenId].proposedPool == _poolAddress, \"Pool address must match pool proposed by token holder\");\n    require(promotionPeriods[_tokenId].endTime > now, \"This token has expired\");\n    proposedPools[_tokenId].approvedPool = _poolAddress;\n    emit PromotedPoolApproved(_poolAddress, _tokenId, promotionPeriods[_tokenId].startTime, promotionPeriods[_tokenId].endTime);\n  }\n\n  function resetPromotedPool(uint256 _tokenId) public onlyOwner {\n    proposedPools[_tokenId].approvedPool = address(0);\n    emit PromotedPoolReset(_tokenId);\n  }\n\n  function getPromotedPool() public view returns (address) {\n    return proposedPools[_activeTokenId].approvedPool;\n  }\n\n  function setPromotedPool() public {\n    require(_currentTokenId > _activeTokenId, \"Mint new token first.\");\n    if (now >= promotionPeriods[_activeTokenId].endTime) {\n      ++_activeTokenId;\n      emit ActiveTokenUpdated(_activeTokenId);\n    }\n  }\n\n  function getTermsHash(uint8 _termsVersion) public view returns(string memory) {\n    return terms[_termsVersion];\n  }\n\n  function getTermsVersion(uint256 _tokenId) public view returns(uint8) {\n    return termsVersions[_tokenId];\n  }\n\n  /**\n    * @dev calculates the next token ID based on value of _currentTokenId \n    * @return uint256 for the next token ID\n    */\n  function _getNextTokenId() private view returns (uint256) {\n    return _currentTokenId.add(1);\n  }\n\n  /**\n    * @dev increments the value of _currentTokenId \n    */\n  function _incrementTokenId() private  {\n    _currentTokenId++;\n  }\n\n  function baseTokenURI() public view returns (string memory) {\n    return \"https://promoted-pools.herokuapp.com/\";\n  }\n\n  function tokenURI(uint256 _tokenId) external view returns (string memory) {\n    return Strings.strConcat(\n        baseTokenURI(),\n        Strings.uint2str(_tokenId)\n    );\n  }\n\n  /**\n   * Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.\n   */\n  function isApprovedForAll(\n    address owner,\n    address operator\n  )\n    public\n    view\n    returns (bool)\n  {\n    // Whitelist OpenSea proxy contract for easy trading.\n    ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);\n    if (address(proxyRegistry.proxies(owner)) == operator) {\n        return true;\n    }\n\n    return super.isApprovedForAll(owner, operator);\n  }\n}",
  "codeformat": "solidity-single-file",
  "contractname": "PromotedPool",
  "compilerversion": "v0.5.12+commit.7709ece9",
  "optimizationUsed": 0,
  "runs": 200,
  "constructorArguements": "000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000f57b2c51ded3a29e6891aba85459d600256cf317000000000000000000000000000000000000000000000000000000000000000f506f6f6c732e6679692050726f6d6f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034659490000000000000000000000000000000000000000000000000000000000"
}
Checking status of verification request g1n6nymenzuc4aim5qfyzwird8nmbh4z8nmwnuy96zb9rxrarb
Fail - Unable to verify
Failed to verify 1 contract(s): PromotedPool@0x3D0Cb6CC9ddc16e96B26b4a0613bb46667ff2928

Any thoughts/additional checks I can do?

rkalis commented 4 years ago

Hey @pyython, thanks for the report. Do you have the code in an open source repo somewhere so I can try it out?

chpiatt commented 4 years ago

Sure thing. Here is the source code: https://github.com/blocklytics/promoted-pools-contracts

rkalis commented 4 years ago

Hey @pyython, sorry for dropping the ball on this for so long!

I cloned your repository, added in the correct .env parameters, then ran:

truffle compile
truffle migrate --rinkeby
truffle run verify PromotedPool --network rinkeby --debug

And I got similar results. The truffle run verify didn't work.

I tried copy-pasting these values into the Etherscan verify web form. This worked correctly.

So then I tried copy-pasting these values into the Etherscan verify API demo. This did not work.

This leads me to believe that there might be an issue with the Etherscan verify API at the moment, since both truffle-plugin-verify and the API demo did not work, while the web form did work.

@mtbitcoin, could you guys look into this?

OsoianMarcel commented 4 years ago

Subscribed. I have same problem as @rkalis

OsoianMarcel commented 4 years ago

@rkalis Amazing plugin, thank you! I hope the problem going to be solved soon.

FYI: Verification works fine on Ropsten network. I created a ticket on etherscan, I hope they'll fix the problem.

mtbitcoin commented 4 years ago

We have someone from the team looking into this..

@OsoianMarcel if i understand this correctly, it only doesn't work with the rinkeby network ?

Enigmatic331 commented 4 years ago

Dear all - Just had this sorted and managed to verify a couple of contracts on my end. Could you have a quick check to see if your contracts verify fine through API now?

Thanks!

OsoianMarcel commented 4 years ago

@mtbitcoin Yes

OsoianMarcel commented 4 years ago

The verification started to work on rinkeby too (checked today). Thanks all.

mtbitcoin commented 4 years ago

@pyython are you still running into issues ?

rkalis commented 4 years ago

I tested it out using @pyython's repo, and everything looks to be working again. Thanks for the fix @mtbitcoin and @Enigmatic331!

interfect commented 4 years ago

I think that this issue may have recurred. I too am having trouble verifying contracts on Rinkeby with this plugin through the API, but they seem to verify fine through the web site.

Here's a contract that wouldn't verify programmatically but verified manually when I copy-pasted the source code:

https://rinkeby.etherscan.io/address/0x7a5b1a0ce60c0bb7ea228c265cd526bbf5bbdb32

Here's the source code on Github:

https://github.com/NovakDistributed/macroverse/blob/7472f7e5bbcc9ea06739e02ae871c7a43c1cd839/contracts/RealMath.sol

Here's what the plugin sent, minus API key:

{
  "apikey": "...",
  "module": "contract",
  "action": "verifysourcecode",
  "contractaddress": "0x7a5B1a0Ce60c0Bb7eA228c265CD526bbF5Bbdb32",
  "sourceCode": "pragma solidity ^0.5.2;\n\n\n/**\n * RealMath: fixed-point math library, based on fractional and integer parts.\n * Using int128 as real88x40, which isn't in Solidity yet.\n * 40 fractional bits gets us down to 1E-12 precision, while still letting us\n * go up to galaxy scale counting in meters.\n * Internally uses the wider int256 for some math.\n *\n * Note that for addition, subtraction, and mod (%), you should just use the\n * built-in Solidity operators. Functions for these operations are not provided.\n *\n * Note that the fancy functions like sqrt, atan2, etc. aren't as accurate as\n * they should be. They are (hopefully) Good Enough for doing orbital mechanics\n * on block timescales in a game context, but they may not be good enough for\n * other applications.\n */\nlibrary RealMath {\n    \n    /**\n     * How many total bits are there?\n     */\n    int256 constant REAL_BITS = 128;\n    \n    /**\n     * How many fractional bits are there?\n     */\n    int256 constant REAL_FBITS = 40;\n    \n    /**\n     * How many integer bits are there?\n     */\n    int256 constant REAL_IBITS = REAL_BITS - REAL_FBITS;\n    \n    /**\n     * What's the first non-fractional bit\n     */\n    int128 constant REAL_ONE = int128(1) << REAL_FBITS;\n    \n    /**\n     * What's the last fractional bit?\n     */\n    int128 constant REAL_HALF = REAL_ONE >> 1;\n    \n    /**\n     * What's two? Two is pretty useful.\n     */\n    int128 constant REAL_TWO = REAL_ONE << 1;\n    \n    /**\n     * And our logarithms are based on ln(2).\n     */\n    int128 constant REAL_LN_TWO = 762123384786;\n    \n    /**\n     * It is also useful to have Pi around.\n     */\n    int128 constant REAL_PI = 3454217652358;\n    \n    /**\n     * And half Pi, to save on divides.\n     * TODO: That might not be how the compiler handles constants.\n     */\n    int128 constant REAL_HALF_PI = 1727108826179;\n    \n    /**\n     * And two pi, which happens to be odd in its most accurate representation.\n     */\n    int128 constant REAL_TWO_PI = 6908435304715;\n    \n    /**\n     * What's the sign bit?\n     */\n    int128 constant SIGN_MASK = int128(1) << 127;\n    \n\n    /**\n     * Convert an integer to a real. Preserves sign.\n     */\n    function toReal(int88 ipart) public pure returns (int128) {\n        return int128(ipart) * REAL_ONE;\n    }\n    \n    /**\n     * Convert a real to an integer. Preserves sign.\n     */\n    function fromReal(int128 real_value) public pure returns (int88) {\n        return int88(real_value / REAL_ONE);\n    }\n    \n    /**\n     * Round a real to the nearest integral real value.\n     */\n    function round(int128 real_value) public pure returns (int128) {\n        // First, truncate.\n        int88 ipart = fromReal(real_value);\n        if ((fractionalBits(real_value) & (uint40(1) << (REAL_FBITS - 1))) > 0) {\n            // High fractional bit is set. Round up.\n            if (real_value < int128(0)) {\n                // Rounding up for a negative number is rounding down.\n                ipart -= 1;\n            } else {\n                ipart += 1;\n            }\n        }\n        return toReal(ipart);\n    }\n    \n    /**\n     * Get the absolute value of a real. Just the same as abs on a normal int128.\n     */\n    function abs(int128 real_value) public pure returns (int128) {\n        if (real_value > 0) {\n            return real_value;\n        } else {\n            return -real_value;\n        }\n    }\n    \n    /**\n     * Returns the fractional bits of a real. Ignores the sign of the real.\n     */\n    function fractionalBits(int128 real_value) public pure returns (uint40) {\n        return uint40(abs(real_value) % REAL_ONE);\n    }\n    \n    /**\n     * Get the fractional part of a real, as a real. Ignores sign (so fpart(-0.5) is 0.5).\n     */\n    function fpart(int128 real_value) public pure returns (int128) {\n        // This gets the fractional part but strips the sign\n        return abs(real_value) % REAL_ONE;\n    }\n\n    /**\n     * Get the fractional part of a real, as a real. Respects sign (so fpartSigned(-0.5) is -0.5).\n     */\n    function fpartSigned(int128 real_value) public pure returns (int128) {\n        // This gets the fractional part but strips the sign\n        int128 fractional = fpart(real_value);\n        if (real_value < 0) {\n            // Add the negative sign back in.\n            return -fractional;\n        } else {\n            return fractional;\n        }\n    }\n    \n    /**\n     * Get the integer part of a fixed point value.\n     */\n    function ipart(int128 real_value) public pure returns (int128) {\n        // Subtract out the fractional part to get the real part.\n        return real_value - fpartSigned(real_value);\n    }\n    \n    /**\n     * Multiply one real by another. Truncates overflows.\n     */\n    function mul(int128 real_a, int128 real_b) public pure returns (int128) {\n        // When multiplying fixed point in x.y and z.w formats we get (x+z).(y+w) format.\n        // So we just have to clip off the extra REAL_FBITS fractional bits.\n        return int128((int256(real_a) * int256(real_b)) >> REAL_FBITS);\n    }\n    \n    /**\n     * Divide one real by another real. Truncates overflows.\n     */\n    function div(int128 real_numerator, int128 real_denominator) public pure returns (int128) {\n        // We use the reverse of the multiplication trick: convert numerator from\n        // x.y to (x+z).(y+w) fixed point, then divide by denom in z.w fixed point.\n        return int128((int256(real_numerator) * REAL_ONE) / int256(real_denominator));\n    }\n    \n    /**\n     * Create a real from a rational fraction.\n     */\n    function fraction(int88 numerator, int88 denominator) public pure returns (int128) {\n        return div(toReal(numerator), toReal(denominator));\n    }\n    \n    // Now we have some fancy math things (like pow and trig stuff). This isn't\n    // in the RealMath that was deployed with the original Macroverse\n    // deployment, so it needs to be linked into your contract statically.\n    \n    /**\n     * Raise a number to a positive integer power in O(log power) time.\n     * See <https://stackoverflow.com/a/101613>\n     */\n    function ipow(int128 real_base, int88 exponent) public pure returns (int128) {\n        if (exponent < 0) {\n            // Negative powers are not allowed here.\n            revert();\n        }\n        \n        // Start with the 0th power\n        int128 real_result = REAL_ONE;\n        while (exponent != 0) {\n            // While there are still bits set\n            if ((exponent & 0x1) == 0x1) {\n                // If the low bit is set, multiply in the (many-times-squared) base\n                real_result = mul(real_result, real_base);\n            }\n            // Shift off the low bit\n            exponent = exponent >> 1;\n            // Do the squaring\n            real_base = mul(real_base, real_base);\n        }\n        \n        // Return the final result.\n        return real_result;\n    }\n    \n    /**\n     * Zero all but the highest set bit of a number.\n     * See <https://stackoverflow.com/a/53184>\n     */\n    function hibit(uint256 val) internal pure returns (uint256) {\n        // Set all the bits below the highest set bit\n        val |= (val >>  1);\n        val |= (val >>  2);\n        val |= (val >>  4);\n        val |= (val >>  8);\n        val |= (val >> 16);\n        val |= (val >> 32);\n        val |= (val >> 64);\n        val |= (val >> 128);\n        return val ^ (val >> 1);\n    }\n    \n    /**\n     * Given a number with one bit set, finds the index of that bit.\n     */\n    function findbit(uint256 val) internal pure returns (uint8 index) {\n        index = 0;\n        // We and the value with alternating bit patters of various pitches to find it.\n        \n        if (val & 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA != 0) {\n            // Picth 1\n            index |= 1;\n        }\n        if (val & 0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC != 0) {\n            // Pitch 2\n            index |= 2;\n        }\n        if (val & 0xF0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0 != 0) {\n            // Pitch 4\n            index |= 4;\n        }\n        if (val & 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 != 0) {\n            // Pitch 8\n            index |= 8;\n        }\n        if (val & 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 != 0) {\n            // Pitch 16\n            index |= 16;\n        }\n        if (val & 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000 != 0) {\n            // Pitch 32\n            index |= 32;\n        }\n        if (val & 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000 != 0) {\n            // Pitch 64\n            index |= 64;\n        }\n        if (val & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000 != 0) {\n            // Pitch 128\n            index |= 128;\n        }\n    }\n    \n    /**\n     * Shift real_arg left or right until it is between 1 and 2. Return the\n     * rescaled value, and the number of bits of right shift applied. Shift may be negative.\n     *\n     * Expresses real_arg as real_scaled * 2^shift, setting shift to put real_arg between [1 and 2).\n     *\n     * Rejects 0 or negative arguments.\n     */\n    function rescale(int128 real_arg) internal pure returns (int128 real_scaled, int88 shift) {\n        if (real_arg <= 0) {\n            // Not in domain!\n            revert();\n        }\n        \n        // Find the high bit\n        int88 high_bit = findbit(hibit(uint256(real_arg)));\n        \n        // We'll shift so the high bit is the lowest non-fractional bit.\n        shift = high_bit - int88(REAL_FBITS);\n        \n        if (shift < 0) {\n            // Shift left\n            real_scaled = real_arg << -shift;\n        } else if (shift >= 0) {\n            // Shift right\n            real_scaled = real_arg >> shift;\n        }\n    }\n    \n    /**\n     * Calculate the natural log of a number. Rescales the input value and uses\n     * the algorithm outlined at <https://math.stackexchange.com/a/977836> and\n     * the ipow implementation.\n     *\n     * Lets you artificially limit the number of iterations.\n     *\n     * Note that it is potentially possible to get an un-converged value; lack\n     * of convergence does not throw.\n     */\n    function lnLimited(int128 real_arg, int max_iterations) public pure returns (int128) {\n        if (real_arg <= 0) {\n            // Outside of acceptable domain\n            revert();\n        }\n        \n        if (real_arg == REAL_ONE) {\n            // Handle this case specially because people will want exactly 0 and\n            // not ~2^-39 ish.\n            return 0;\n        }\n        \n        // We know it's positive, so rescale it to be between [1 and 2)\n        int128 real_rescaled;\n        int88 shift;\n        (real_rescaled, shift) = rescale(real_arg);\n        \n        // Compute the argument to iterate on\n        int128 real_series_arg = div(real_rescaled - REAL_ONE, real_rescaled + REAL_ONE);\n        \n        // We will accumulate the result here\n        int128 real_series_result = 0;\n        \n        for (int88 n = 0; n < max_iterations; n++) {\n            // Compute term n of the series\n            int128 real_term = div(ipow(real_series_arg, 2 * n + 1), toReal(2 * n + 1));\n            // And add it in\n            real_series_result += real_term;\n            if (real_term == 0) {\n                // We must have converged. Next term is too small to represent.\n                break;\n            }\n            // If we somehow never converge I guess we will run out of gas\n        }\n        \n        // Double it to account for the factor of 2 outside the sum\n        real_series_result = mul(real_series_result, REAL_TWO);\n        \n        // Now compute and return the overall result\n        return mul(toReal(shift), REAL_LN_TWO) + real_series_result;\n        \n    }\n    \n    /**\n     * Calculate a natural logarithm with a sensible maximum iteration count to\n     * wait until convergence. Note that it is potentially possible to get an\n     * un-converged value; lack of convergence does not throw.\n     */\n    function ln(int128 real_arg) public pure returns (int128) {\n        return lnLimited(real_arg, 100);\n    }\n    \n    /**\n     * Calculate e^x. Uses the series given at\n     * <http://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/exp.html>.\n     *\n     * Lets you artificially limit the number of iterations.\n     *\n     * Note that it is potentially possible to get an un-converged value; lack\n     * of convergence does not throw.\n     */\n    function expLimited(int128 real_arg, int max_iterations) public pure returns (int128) {\n        // We will accumulate the result here\n        int128 real_result = 0;\n        \n        // We use this to save work computing terms\n        int128 real_term = REAL_ONE;\n        \n        for (int88 n = 0; n < max_iterations; n++) {\n            // Add in the term\n            real_result += real_term;\n            \n            // Compute the next term\n            real_term = mul(real_term, div(real_arg, toReal(n + 1)));\n            \n            if (real_term == 0) {\n                // We must have converged. Next term is too small to represent.\n                break;\n            }\n            // If we somehow never converge I guess we will run out of gas\n        }\n        \n        // Return the result\n        return real_result;\n        \n    }\n    \n    /**\n     * Calculate e^x with a sensible maximum iteration count to wait until\n     * convergence. Note that it is potentially possible to get an un-converged\n     * value; lack of convergence does not throw.\n     */\n    function exp(int128 real_arg) public pure returns (int128) {\n        return expLimited(real_arg, 100);\n    }\n    \n    /**\n     * Raise any number to any power, except for negative bases to fractional powers.\n     */\n    function pow(int128 real_base, int128 real_exponent) public pure returns (int128) {\n        if (real_exponent == 0) {\n            // Anything to the 0 is 1\n            return REAL_ONE;\n        }\n        \n        if (real_base == 0) {\n            if (real_exponent < 0) {\n                // Outside of domain!\n                revert();\n            }\n            // Otherwise it's 0\n            return 0;\n        }\n        \n        if (fpart(real_exponent) == 0) {\n            // Anything (even a negative base) is super easy to do to an integer power.\n            \n            if (real_exponent > 0) {\n                // Positive integer power is easy\n                return ipow(real_base, fromReal(real_exponent));\n            } else {\n                // Negative integer power is harder\n                return div(REAL_ONE, ipow(real_base, fromReal(-real_exponent)));\n            }\n        }\n        \n        if (real_base < 0) {\n            // It's a negative base to a non-integer power.\n            // In general pow(-x^y) is undefined, unless y is an int or some\n            // weird rational-number-based relationship holds.\n            revert();\n        }\n        \n        // If it's not a special case, actually do it.\n        return exp(mul(real_exponent, ln(real_base)));\n    }\n    \n    /**\n     * Compute the square root of a number.\n     */\n    function sqrt(int128 real_arg) public pure returns (int128) {\n        return pow(real_arg, REAL_HALF);\n    }\n    \n    /**\n     * Compute the sin of a number to a certain number of Taylor series terms.\n     */\n    function sinLimited(int128 real_arg, int88 max_iterations) public pure returns (int128) {\n        // First bring the number into 0 to 2 pi\n        // TODO: This will introduce an error for very large numbers, because the error in our Pi will compound.\n        // But for actual reasonable angle values we should be fine.\n        real_arg = real_arg % REAL_TWO_PI;\n        \n        int128 accumulator = REAL_ONE;\n        \n        // We sum from large to small iteration so that we can have higher powers in later terms\n        for (int88 iteration = max_iterations - 1; iteration >= 0; iteration--) {\n            accumulator = REAL_ONE - mul(div(mul(real_arg, real_arg), toReal((2 * iteration + 2) * (2 * iteration + 3))), accumulator);\n            // We can't stop early; we need to make it to the first term.\n        }\n        \n        return mul(real_arg, accumulator);\n    }\n    \n    /**\n     * Calculate sin(x) with a sensible maximum iteration count to wait until\n     * convergence.\n     */\n    function sin(int128 real_arg) public pure returns (int128) {\n        return sinLimited(real_arg, 15);\n    }\n    \n    /**\n     * Calculate cos(x).\n     */\n    function cos(int128 real_arg) public pure returns (int128) {\n        return sin(real_arg + REAL_HALF_PI);\n    }\n    \n    /**\n     * Calculate tan(x). May overflow for large results. May throw if tan(x)\n     * would be infinite, or return an approximation, or overflow.\n     */\n    function tan(int128 real_arg) public pure returns (int128) {\n        return div(sin(real_arg), cos(real_arg));\n    }\n    \n    /**\n     * Calculate atan(x) for x in [-1, 1].\n     * Uses the Chebyshev polynomial approach presented at\n     * https://www.mathworks.com/help/fixedpoint/examples/calculate-fixed-point-arctangent.html\n     * Uses polynomials received by personal communication.\n     * 0.999974x-0.332568x^3+0.193235x^5-0.115729x^7+0.0519505x^9-0.0114658x^11\n     */\n    function atanSmall(int128 real_arg) public pure returns (int128) {\n        int128 real_arg_squared = mul(real_arg, real_arg);\n        return mul(mul(mul(mul(mul(mul(\n            - 12606780422,  real_arg_squared) // x^11\n            + 57120178819,  real_arg_squared) // x^9\n            - 127245381171, real_arg_squared) // x^7\n            + 212464129393, real_arg_squared) // x^5\n            - 365662383026, real_arg_squared) // x^3\n            + 1099483040474, real_arg);       // x^1\n    }\n    \n    /**\n     * Compute the nice two-component arctangent of y/x.\n     */\n    function atan2(int128 real_y, int128 real_x) public pure returns (int128) {\n        int128 atan_result;\n        \n        // Do the angle correction shown at\n        // https://www.mathworks.com/help/fixedpoint/examples/calculate-fixed-point-arctangent.html\n        \n        // We will re-use these absolute values\n        int128 real_abs_x = abs(real_x);\n        int128 real_abs_y = abs(real_y);\n        \n        if (real_abs_x > real_abs_y) {\n            // We are in the (0, pi/4] region\n            // abs(y)/abs(x) will be in 0 to 1.\n            atan_result = atanSmall(div(real_abs_y, real_abs_x));\n        } else {\n            // We are in the (pi/4, pi/2) region\n            // abs(x) / abs(y) will be in 0 to 1; we swap the arguments\n            atan_result = REAL_HALF_PI - atanSmall(div(real_abs_x, real_abs_y));\n        }\n        \n        // Now we correct the result for other regions\n        if (real_x < 0) {\n            if (real_y < 0) {\n                atan_result -= REAL_PI;\n            } else {\n                atan_result = REAL_PI - atan_result;\n            }\n        } else {\n            if (real_y < 0) {\n                atan_result = -atan_result;\n            }\n        }\n        \n        return atan_result;\n    }\n}",
  "codeformat": "solidity-single-file",
  "contractname": "RealMath",
  "compilerversion": "v0.5.14+commit.01f1aaa4",
  "optimizationUsed": 0,
  "runs": 200,
  "constructorArguements": ""
}

As far as I can tell, what the plugin sent matches the settings I managed to use to actually verify the contract through the web UI. This contract happens to be a single file, so there's no question of getting the concatenation wrong.

@Enigmatic331 is something broken again today?

Enigmatic331 commented 4 years ago

Hey @interfect,

I don't think so though - Was able to verify the same contract through our API demo:

image

https://rinkeby.etherscan.io/address/0x56d5febb6644e228a52f5052f3770f9a7dbe7e04#code

Though earlier this morning I recalled there was a quick server restart on the testnet servers, so you may have caught us then. Perhaps keep an eye out, and let me know if your contract verification fails again? Happy to hear from you if there's anything.

Enigmatic331 commented 4 years ago

Oh! Could it be the compiler version? Being v0.5.14+commit.01f1aaa4? I think the actual version is v0.5.14+commit.1f1aaa4 - Let me have a quick look.

Enigmatic331 commented 4 years ago

So yea, does appear to be the case: If I use v0.5.14+commit.01f1aaa4 as the version it fails, whereas v0.5.14+commit.1f1aaa4 passes.

@rkalis - I reckon you'd just take the compiler settings from Truffle yeap? Mmm. I reckon this bit of inconsistency came upstream somewhere.

A bit of trivia to think about: Is v0.5.14 the only release with a seven character commit hash at the back? Another version with leading zero (v0.6.8) ended up with eight.

image

rkalis commented 4 years ago

Hey @Enigmatic331, that is some good detective work :muscle:! You're right that I get the compiler version from the Truffle artifact files. So yeah it looks that there is a mismatch there.

It looks like the mismatch here might actually be on the Remix/Etherscan side, because when I install solc v0.5.14 either through npm or Homebrew and output the version, it gives me 0.5.14+commit.01f1aaa4. Haven't tried building from source yet, but I think that is what Homebrew does by default.

Where are you getting the 0.5.14+commit.1f1aaa4 value?

Enigmatic331 commented 4 years ago

Where we maintain a list here (https://etherscan.io/solcversions) which would be the solc-bin list: https://github.com/ethereum/solc-bin/blob/gh-pages/bin/list.txt, also where we pull our soljson from. Hmmm so the files names themselves seem to discard leading zeros (per commit https://github.com/ethereum/solc-bin/commit/578626cd3552ead144cf1245b24454ea7a12a6be)...

rkalis commented 4 years ago

That is interesting. Odd that it doesn't do so for the 0.6.8 version 🤔

Hi @chriseth, so we're running into this issue that the solidity versions in the solc-bin list remove leading zeroes from the commit hash (except for 0.6.8). But when reporting the version from within solc (solc --version), it still includes the leading zeroes. Some context is included in the few comments above.

I was hoping you might shine some light on these mismatches and what the expected behaviour is.

chriseth commented 4 years ago

I'm sorry for this inconvenience! The semver standard disallows leading zeros in numeric components, both in the version itself and in the "prerelease" part following the -. It allows leading zeros in numeric components after the +, though. We were not aware of this exception and thus removed all leading zeros in the past. I think we did not want to change historic file names and versions and thus did not re-add the leading zero for 0.5.14. @ekpyron do you know more here?

Is it important that you also compare the +-part - wouldn't the version number be enough for release compilers? (Or am I misunderstanding the issue here?)

ekpyron commented 4 years ago

Yes, we did change our release scripts by now, so that they will no longer remove leading zeroes in the commit hash in the future, but we did nothing about the historic releases (I think we said people hopefully use list.txt anyways and didn't want to break anything with the full historic URL hardcoded in it).

Seeing this here, I suggest to do the following: we change lists.txt and the "proper" 0.5.14 and 0.6.8 releases to include the leading zeros in the commit hash, but create symlinks for the historic version without the leading zero in solc-bin.

As a side note: the wasm rebuilds of the releases in https://github.com/ethereum/solc-bin/wasm/ on the other hand, do have the leading zeroes for 0.5.14 and 0.6.8...

interfect commented 4 years ago

I've upgraded to Solidity 0.6.10 (which also starts with leading zeroes in its commit hash, but seems to be synchronized in both places) and tried again.

Now it seems that I can verify some (simple?) contracts but not others. Here's a successful one (my project's migrations contract):

{
  "apikey": "REDACTED",
  "module": "contract",
  "action": "verifysourcecode",
  "contractaddress": "0xc0b87a40C18cB718D931DD7356f38CB03687b9D0",
  "sourceCode": "pragma solidity ^0.6.10;\n\n\ncontract Migrations {\n  address public owner;\n  uint public last_completed_migration;\n\n  modifier restricted() {\n    if (msg.sender == owner) _;\n  }\n\n  constructor() public {\n    owner = msg.sender;\n  }\n\n  function setCompleted(uint completed) public restricted {\n    last_completed_migration = completed;\n  }\n\n  function upgrade(address new_address) public restricted {\n    Migrations upgraded = Migrations(new_address);\n    upgraded.setCompleted(last_completed_migration);\n  }\n}\n\n// SPDX-License-Identifier: UNLICENSED",
  "codeformat": "solidity-single-file",
  "contractname": "Migrations",
  "compilerversion": "v0.6.10+commit.00c0fcaf",
  "optimizationUsed": 0,
  "runs": 200,
  "constructorArguements": ""
}

And here's a failed one, which isn't much longer or much more interesting:

{
  "apikey": "REDACTED",
  "module": "contract",
  "action": "verifysourcecode",
  "contractaddress": "0x91084757ebfD1110d00A5691dab687e20069178d",
  "sourceCode": "pragma solidity ^0.6.10;\n\n\n/**\n * Interface for an access control strategy for Macrtoverse contracts.\n * Can be asked if a certain query should be allowed, and will return true or false.\n * Allows for different access control strategies (unrestricted, minimum balance, subscription, etc.) to be swapped in.\n */\nabstract contract AccessControl {\n    /**\n     * Should a query be allowed for this msg.sender (calling contract) and this tx.origin (calling user)?\n     */\n    function allowQuery(address sender, address origin) virtual public view returns (bool);\n}\n\n// SPDX-License-Identifier: UNLICENSED\n\n/**\n * Represents an access control strategy where all requests are accepted.\n */\ncontract UnrestrictedAccessControl {\n    /**\n     * Always approve access, ignoring the addresses passed in.\n     * Note that this raises solidity compiler warnings about unused variables.\n     */\n    function allowQuery(address /* sender */, address /* origin */) public pure returns (bool) {\n        return true;\n    }\n}\n\n// SPDX-License-Identifier: UNLICENSED",
  "codeformat": "solidity-single-file",
  "contractname": "UnrestrictedAccessControl",
  "compilerversion": "v0.6.10+commit.00c0fcaf",
  "optimizationUsed": 0,
  "runs": 200,
  "constructorArguements": ""
}
Enigmatic331 commented 4 years ago

PS: There were two SPDX License Identifier on the second contract - Removed the bottom one and it seems to verify fine now: https://rinkeby.etherscan.io/address/0x91084757ebfD1110d00A5691dab687e20069178d#contracts

Ah! So it is a compilation error: image

rkalis commented 4 years ago

Ah that is interesting @Enigmatic331.

@RyuuGan I remember that you filter out duplicate pragma statements. I guess that duplicate SPDX license identifiers should also be filtered out. Is that possible to do on the sol-merger side?

ekpyron commented 4 years ago

For the record about the missing leading zeroes in commit hashes in https://github.com/ethereum/solc-bin/ - we added the missing leading zeroes everywhere now, and changed e.g. lists.txt accordingly - but we still provide symlinks to the historic names without the leading zeroes.

rkalis commented 4 years ago

Awesome, thanks for the help on this @ekpyron @chriseth!

RyuuGan commented 4 years ago

Hello @rkalis,

I'm also writing the plugin that will also be removing this type of comments:

https://github.com/RyuuGan/sol-merger/blob/va/exportPlugins/lib/plugins/SPDXLicenseRemovePlugin.ts

Also this feature will allow you to write your own plugins if you need them to postprocess any export.

interfect commented 4 years ago

How is filtering out the duplicate license comments going to interact with actual licensing? If you have includes with different licensing than each other, or different licensing then the main contract, the combined source file isn't going to be accurately described by any of the SPDX comments, and if Etherscan tries to use them to determine an official license for the concatenated source, it's going to be wrong.

rkalis commented 4 years ago

That sounds awesome! Great job @RyuuGan.

@interfect I don't think Etherscan uses the SPDX comments for their official license stuff, but maybe @Enigmatic331 can shed light on that. In any case I can imagine that it could make sense to only leave the first-seen SPDX license comment, and then it's up to the contract dev to make sure that their inherited contracts/libraries are compatible.

chriseth commented 4 years ago

Would it be very difficult to just use multi-file source verification or even better - metadata-based verification?

interfect commented 4 years ago

Sed-ing out all the SPDX license identifiers from my code before verifying doesn't really seem to help. I use OpenZeppelin contracts, and they all have their own license identifiers, and when I include anything that ends up with more than two files from OZ in it, I run into this issue.

I guess I could try tampering with the OZ contract sources from node_modules. Or the built JSONs.

interfect commented 4 years ago

@Enigmatic331 OK, I've tried removing all the SPDX license identifiers from my and the OZ sources before trying to verify, and it still doesn't quite work. Here's another example contract that doesn't verify through the API and does verify when I submit it manually through the website. There's no "SPDX" in it anymore; it has me pick a license on the form.

Does there need to be exactly one SPDX comment for the API to work? (EDIT: I tested that by adding an SPDX comment to the verifier-prepended preamble, and that still didn't help.)

{
  "apikey": "REDACTED",
  "module": "contract",
  "action": "verifysourcecode",
  "contractaddress": "0x6a15A608EEa496b0540d7604713fd3d5a443D2E4",
  "sourceCode": "pragma solidity ^0.6.10;\n\n\n/**\n * RealMath: fixed-point math library, based on fractional and integer parts.\n * Using int128 as real88x40, which isn't in Solidity yet.\n * 40 fractional bits gets us down to 1E-12 precision, while still letting us\n * go up to galaxy scale counting in meters.\n * Internally uses the wider int256 for some math.\n *\n * Note that for addition, subtraction, and mod (%), you should just use the\n * built-in Solidity operators. Functions for these operations are not provided.\n *\n * Note that the fancy functions like sqrt, atan2, etc. aren't as accurate as\n * they should be. They are (hopefully) Good Enough for doing orbital mechanics\n * on block timescales in a game context, but they may not be good enough for\n * other applications.\n */\nlibrary RealMath {\n    \n    /**@dev\n     * How many total bits are there?\n     */\n    int256 constant REAL_BITS = 128;\n    \n    /**@dev\n     * How many fractional bits are there?\n     */\n    int256 constant REAL_FBITS = 40;\n    \n    /**@dev\n     * How many integer bits are there?\n     */\n    int256 constant REAL_IBITS = REAL_BITS - REAL_FBITS;\n    \n    /**@dev\n     * What's the first non-fractional bit\n     */\n    int128 constant REAL_ONE = int128(1) << int128(REAL_FBITS);\n    \n    /**@dev\n     * What's the last fractional bit?\n     */\n    int128 constant REAL_HALF = REAL_ONE >> int128(1);\n    \n    /**@dev\n     * What's two? Two is pretty useful.\n     */\n    int128 constant REAL_TWO = REAL_ONE << int128(1);\n    \n    /**@dev\n     * And our logarithms are based on ln(2).\n     */\n    int128 constant REAL_LN_TWO = 762123384786;\n    \n    /**@dev\n     * It is also useful to have Pi around.\n     */\n    int128 constant REAL_PI = 3454217652358;\n    \n    /**@dev\n     * And half Pi, to save on divides.\n     * TODO: That might not be how the compiler handles constants.\n     */\n    int128 constant REAL_HALF_PI = 1727108826179;\n    \n    /**@dev\n     * And two pi, which happens to be odd in its most accurate representation.\n     */\n    int128 constant REAL_TWO_PI = 6908435304715;\n    \n    /**@dev\n     * What's the sign bit?\n     */\n    int128 constant SIGN_MASK = int128(1) << int128(127);\n    \n\n    /**\n     * Convert an integer to a real. Preserves sign.\n     */\n    function toReal(int88 ipart) public pure returns (int128) {\n        return int128(ipart) * REAL_ONE;\n    }\n    \n    /**\n     * Convert a real to an integer. Preserves sign.\n     */\n    function fromReal(int128 real_value) public pure returns (int88) {\n        return int88(real_value / REAL_ONE);\n    }\n    \n    /**\n     * Round a real to the nearest integral real value.\n     */\n    function round(int128 real_value) public pure returns (int128) {\n        // First, truncate.\n        int88 ipart = fromReal(real_value);\n        if ((fractionalBits(real_value) & (uint40(1) << uint40(REAL_FBITS - 1))) > 0) {\n            // High fractional bit is set. Round up.\n            if (real_value < int128(0)) {\n                // Rounding up for a negative number is rounding down.\n                ipart -= 1;\n            } else {\n                ipart += 1;\n            }\n        }\n        return toReal(ipart);\n    }\n    \n    /**\n     * Get the absolute value of a real. Just the same as abs on a normal int128.\n     */\n    function abs(int128 real_value) public pure returns (int128) {\n        if (real_value > 0) {\n            return real_value;\n        } else {\n            return -real_value;\n        }\n    }\n    \n    /**\n     * Returns the fractional bits of a real. Ignores the sign of the real.\n     */\n    function fractionalBits(int128 real_value) public pure returns (uint40) {\n        return uint40(abs(real_value) % REAL_ONE);\n    }\n    \n    /**\n     * Get the fractional part of a real, as a real. Ignores sign (so fpart(-0.5) is 0.5).\n     */\n    function fpart(int128 real_value) public pure returns (int128) {\n        // This gets the fractional part but strips the sign\n        return abs(real_value) % REAL_ONE;\n    }\n\n    /**\n     * Get the fractional part of a real, as a real. Respects sign (so fpartSigned(-0.5) is -0.5).\n     */\n    function fpartSigned(int128 real_value) public pure returns (int128) {\n        // This gets the fractional part but strips the sign\n        int128 fractional = fpart(real_value);\n        if (real_value < 0) {\n            // Add the negative sign back in.\n            return -fractional;\n        } else {\n            return fractional;\n        }\n    }\n    \n    /**\n     * Get the integer part of a fixed point value.\n     */\n    function ipart(int128 real_value) public pure returns (int128) {\n        // Subtract out the fractional part to get the real part.\n        return real_value - fpartSigned(real_value);\n    }\n    \n    /**\n     * Multiply one real by another. Truncates overflows.\n     */\n    function mul(int128 real_a, int128 real_b) public pure returns (int128) {\n        // When multiplying fixed point in x.y and z.w formats we get (x+z).(y+w) format.\n        // So we just have to clip off the extra REAL_FBITS fractional bits.\n        return int128((int256(real_a) * int256(real_b)) >> REAL_FBITS);\n    }\n    \n    /**\n     * Divide one real by another real. Truncates overflows.\n     */\n    function div(int128 real_numerator, int128 real_denominator) public pure returns (int128) {\n        // We use the reverse of the multiplication trick: convert numerator from\n        // x.y to (x+z).(y+w) fixed point, then divide by denom in z.w fixed point.\n        return int128((int256(real_numerator) * REAL_ONE) / int256(real_denominator));\n    }\n    \n    /**\n     * Create a real from a rational fraction.\n     */\n    function fraction(int88 numerator, int88 denominator) public pure returns (int128) {\n        return div(toReal(numerator), toReal(denominator));\n    }\n    \n    // Now we have some fancy math things (like pow and trig stuff). This isn't\n    // in the RealMath that was deployed with the original Macroverse\n    // deployment, so it needs to be linked into your contract statically.\n    \n    /**\n     * Raise a number to a positive integer power in O(log power) time.\n     * See <https://stackoverflow.com/a/101613>\n     */\n    function ipow(int128 real_base, int88 exponent) public pure returns (int128) {\n        if (exponent < 0) {\n            // Negative powers are not allowed here.\n            revert();\n        }\n        \n        // Start with the 0th power\n        int128 real_result = REAL_ONE;\n        while (exponent != 0) {\n            // While there are still bits set\n            if ((exponent & 0x1) == 0x1) {\n                // If the low bit is set, multiply in the (many-times-squared) base\n                real_result = mul(real_result, real_base);\n            }\n            // Shift off the low bit\n            exponent = exponent >> 1;\n            // Do the squaring\n            real_base = mul(real_base, real_base);\n        }\n        \n        // Return the final result.\n        return real_result;\n    }\n    \n    /**\n     * Zero all but the highest set bit of a number.\n     * See <https://stackoverflow.com/a/53184>\n     */\n    function hibit(uint256 val) internal pure returns (uint256) {\n        // Set all the bits below the highest set bit\n        val |= (val >>  1);\n        val |= (val >>  2);\n        val |= (val >>  4);\n        val |= (val >>  8);\n        val |= (val >> 16);\n        val |= (val >> 32);\n        val |= (val >> 64);\n        val |= (val >> 128);\n        return val ^ (val >> 1);\n    }\n    \n    /**\n     * Given a number with one bit set, finds the index of that bit.\n     */\n    function findbit(uint256 val) internal pure returns (uint8 index) {\n        index = 0;\n        // We and the value with alternating bit patters of various pitches to find it.\n        \n        if (val & 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA != 0) {\n            // Picth 1\n            index |= 1;\n        }\n        if (val & 0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC != 0) {\n            // Pitch 2\n            index |= 2;\n        }\n        if (val & 0xF0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0 != 0) {\n            // Pitch 4\n            index |= 4;\n        }\n        if (val & 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00 != 0) {\n            // Pitch 8\n            index |= 8;\n        }\n        if (val & 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000 != 0) {\n            // Pitch 16\n            index |= 16;\n        }\n        if (val & 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000 != 0) {\n            // Pitch 32\n            index |= 32;\n        }\n        if (val & 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000 != 0) {\n            // Pitch 64\n            index |= 64;\n        }\n        if (val & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000 != 0) {\n            // Pitch 128\n            index |= 128;\n        }\n    }\n    \n    /**\n     * Shift real_arg left or right until it is between 1 and 2. Return the\n     * rescaled value, and the number of bits of right shift applied. Shift may be negative.\n     *\n     * Expresses real_arg as real_scaled * 2^shift, setting shift to put real_arg between [1 and 2).\n     *\n     * Rejects 0 or negative arguments.\n     */\n    function rescale(int128 real_arg) internal pure returns (int128 real_scaled, int88 shift) {\n        if (real_arg <= 0) {\n            // Not in domain!\n            revert();\n        }\n        \n        // Find the high bit\n        int88 high_bit = findbit(hibit(uint256(real_arg)));\n        \n        // We'll shift so the high bit is the lowest non-fractional bit.\n        shift = high_bit - int88(REAL_FBITS);\n        \n        if (shift < 0) {\n            // Shift left\n            real_scaled = real_arg << int128(-shift);\n        } else if (shift >= 0) {\n            // Shift right\n            real_scaled = real_arg >> int128(shift);\n        }\n    }\n    \n    /**\n     * Calculate the natural log of a number. Rescales the input value and uses\n     * the algorithm outlined at <https://math.stackexchange.com/a/977836> and\n     * the ipow implementation.\n     *\n     * Lets you artificially limit the number of iterations.\n     *\n     * Note that it is potentially possible to get an un-converged value; lack\n     * of convergence does not throw.\n     */\n    function lnLimited(int128 real_arg, int max_iterations) public pure returns (int128) {\n        if (real_arg <= 0) {\n            // Outside of acceptable domain\n            revert();\n        }\n        \n        if (real_arg == REAL_ONE) {\n            // Handle this case specially because people will want exactly 0 and\n            // not ~2^-39 ish.\n            return 0;\n        }\n        \n        // We know it's positive, so rescale it to be between [1 and 2)\n        int128 real_rescaled;\n        int88 shift;\n        (real_rescaled, shift) = rescale(real_arg);\n        \n        // Compute the argument to iterate on\n        int128 real_series_arg = div(real_rescaled - REAL_ONE, real_rescaled + REAL_ONE);\n        \n        // We will accumulate the result here\n        int128 real_series_result = 0;\n        \n        for (int88 n = 0; n < max_iterations; n++) {\n            // Compute term n of the series\n            int128 real_term = div(ipow(real_series_arg, 2 * n + 1), toReal(2 * n + 1));\n            // And add it in\n            real_series_result += real_term;\n            if (real_term == 0) {\n                // We must have converged. Next term is too small to represent.\n                break;\n            }\n            // If we somehow never converge I guess we will run out of gas\n        }\n        \n        // Double it to account for the factor of 2 outside the sum\n        real_series_result = mul(real_series_result, REAL_TWO);\n        \n        // Now compute and return the overall result\n        return mul(toReal(shift), REAL_LN_TWO) + real_series_result;\n        \n    }\n    \n    /**\n     * Calculate a natural logarithm with a sensible maximum iteration count to\n     * wait until convergence. Note that it is potentially possible to get an\n     * un-converged value; lack of convergence does not throw.\n     */\n    function ln(int128 real_arg) public pure returns (int128) {\n        return lnLimited(real_arg, 100);\n    }\n    \n    /**\n     * Calculate e^x. Uses the series given at\n     * <http://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/exp.html>.\n     *\n     * Lets you artificially limit the number of iterations.\n     *\n     * Note that it is potentially possible to get an un-converged value; lack\n     * of convergence does not throw.\n     */\n    function expLimited(int128 real_arg, int max_iterations) public pure returns (int128) {\n        // We will accumulate the result here\n        int128 real_result = 0;\n        \n        // We use this to save work computing terms\n        int128 real_term = REAL_ONE;\n        \n        for (int88 n = 0; n < max_iterations; n++) {\n            // Add in the term\n            real_result += real_term;\n            \n            // Compute the next term\n            real_term = mul(real_term, div(real_arg, toReal(n + 1)));\n            \n            if (real_term == 0) {\n                // We must have converged. Next term is too small to represent.\n                break;\n            }\n            // If we somehow never converge I guess we will run out of gas\n        }\n        \n        // Return the result\n        return real_result;\n        \n    }\n    \n    /**\n     * Calculate e^x with a sensible maximum iteration count to wait until\n     * convergence. Note that it is potentially possible to get an un-converged\n     * value; lack of convergence does not throw.\n     */\n    function exp(int128 real_arg) public pure returns (int128) {\n        return expLimited(real_arg, 100);\n    }\n    \n    /**\n     * Raise any number to any power, except for negative bases to fractional powers.\n     */\n    function pow(int128 real_base, int128 real_exponent) public pure returns (int128) {\n        if (real_exponent == 0) {\n            // Anything to the 0 is 1\n            return REAL_ONE;\n        }\n        \n        if (real_base == 0) {\n            if (real_exponent < 0) {\n                // Outside of domain!\n                revert();\n            }\n            // Otherwise it's 0\n            return 0;\n        }\n        \n        if (fpart(real_exponent) == 0) {\n            // Anything (even a negative base) is super easy to do to an integer power.\n            \n            if (real_exponent > 0) {\n                // Positive integer power is easy\n                return ipow(real_base, fromReal(real_exponent));\n            } else {\n                // Negative integer power is harder\n                return div(REAL_ONE, ipow(real_base, fromReal(-real_exponent)));\n            }\n        }\n        \n        if (real_base < 0) {\n            // It's a negative base to a non-integer power.\n            // In general pow(-x^y) is undefined, unless y is an int or some\n            // weird rational-number-based relationship holds.\n            revert();\n        }\n        \n        // If it's not a special case, actually do it.\n        return exp(mul(real_exponent, ln(real_base)));\n    }\n    \n    /**\n     * Compute the square root of a number.\n     */\n    function sqrt(int128 real_arg) public pure returns (int128) {\n        return pow(real_arg, REAL_HALF);\n    }\n    \n    /**\n     * Compute the sin of a number to a certain number of Taylor series terms.\n     */\n    function sinLimited(int128 real_arg, int88 max_iterations) public pure returns (int128) {\n        // First bring the number into 0 to 2 pi\n        // TODO: This will introduce an error for very large numbers, because the error in our Pi will compound.\n        // But for actual reasonable angle values we should be fine.\n        real_arg = real_arg % REAL_TWO_PI;\n        \n        int128 accumulator = REAL_ONE;\n        \n        // We sum from large to small iteration so that we can have higher powers in later terms\n        for (int88 iteration = max_iterations - 1; iteration >= 0; iteration--) {\n            accumulator = REAL_ONE - mul(div(mul(real_arg, real_arg), toReal((2 * iteration + 2) * (2 * iteration + 3))), accumulator);\n            // We can't stop early; we need to make it to the first term.\n        }\n        \n        return mul(real_arg, accumulator);\n    }\n    \n    /**\n     * Calculate sin(x) with a sensible maximum iteration count to wait until\n     * convergence.\n     */\n    function sin(int128 real_arg) public pure returns (int128) {\n        return sinLimited(real_arg, 15);\n    }\n    \n    /**\n     * Calculate cos(x).\n     */\n    function cos(int128 real_arg) public pure returns (int128) {\n        return sin(real_arg + REAL_HALF_PI);\n    }\n    \n    /**\n     * Calculate tan(x). May overflow for large results. May throw if tan(x)\n     * would be infinite, or return an approximation, or overflow.\n     */\n    function tan(int128 real_arg) public pure returns (int128) {\n        return div(sin(real_arg), cos(real_arg));\n    }\n    \n    /**\n     * Calculate atan(x) for x in [-1, 1].\n     * Uses the Chebyshev polynomial approach presented at\n     * https://www.mathworks.com/help/fixedpoint/examples/calculate-fixed-point-arctangent.html\n     * Uses polynomials received by personal communication.\n     * 0.999974x-0.332568x^3+0.193235x^5-0.115729x^7+0.0519505x^9-0.0114658x^11\n     */\n    function atanSmall(int128 real_arg) public pure returns (int128) {\n        int128 real_arg_squared = mul(real_arg, real_arg);\n        return mul(mul(mul(mul(mul(mul(\n            - 12606780422,  real_arg_squared) // x^11\n            + 57120178819,  real_arg_squared) // x^9\n            - 127245381171, real_arg_squared) // x^7\n            + 212464129393, real_arg_squared) // x^5\n            - 365662383026, real_arg_squared) // x^3\n            + 1099483040474, real_arg);       // x^1\n    }\n    \n    /**\n     * Compute the nice two-component arctangent of y/x.\n     */\n    function atan2(int128 real_y, int128 real_x) public pure returns (int128) {\n        int128 atan_result;\n        \n        // Do the angle correction shown at\n        // https://www.mathworks.com/help/fixedpoint/examples/calculate-fixed-point-arctangent.html\n        \n        // We will re-use these absolute values\n        int128 real_abs_x = abs(real_x);\n        int128 real_abs_y = abs(real_y);\n        \n        if (real_abs_x > real_abs_y) {\n            // We are in the (0, pi/4] region\n            // abs(y)/abs(x) will be in 0 to 1.\n            atan_result = atanSmall(div(real_abs_y, real_abs_x));\n        } else {\n            // We are in the (pi/4, pi/2) region\n            // abs(x) / abs(y) will be in 0 to 1; we swap the arguments\n            atan_result = REAL_HALF_PI - atanSmall(div(real_abs_x, real_abs_y));\n        }\n        \n        // Now we correct the result for other regions\n        if (real_x < 0) {\n            if (real_y < 0) {\n                atan_result -= REAL_PI;\n            } else {\n                atan_result = REAL_PI - atan_result;\n            }\n        } else {\n            if (real_y < 0) {\n                atan_result = -atan_result;\n            }\n        }\n        \n        return atan_result;\n    }\n}\n\n// This code is part of Macroverse and is licensed: MIT\n\nlibrary RNG {\n    using RealMath for *;\n\n    /**\n     * We are going to define a RandNode struct to allow for hash chaining.\n     * You can extend a RandNode with a bunch of different stuff and get a new RandNode.\n     * You can then use a RandNode to get a single, repeatable random value.\n     * This eliminates the need for concatenating string selfs, which is a huge pain in Solidity.\n     */\n    struct RandNode {\n        // We hash this together with whatever we're mixing in to get the child hash.\n        bytes32 _hash;\n    }\n    \n    // All the functions that touch RandNodes need to be internal.\n    // If you want to pass them in and out of contracts just use the bytes32.\n    \n    // You can get all these functions as methods on RandNodes by \"using RNG for *\" in your library/contract.\n    \n    /**\n     * Mix string data into a RandNode. Returns a new RandNode.\n     */\n    function derive(RandNode memory self, string memory entropy) internal pure returns (RandNode memory) {\n        // Hash what's there now with the new stuff.\n        return RandNode(sha256(abi.encodePacked(self._hash, entropy)));\n    }\n    \n    /**\n     * Mix signed int data into a RandNode. Returns a new RandNode.\n     */\n    function derive(RandNode memory self, int256 entropy) internal pure returns (RandNode memory) {\n        return RandNode(sha256(abi.encodePacked(self._hash, entropy)));\n    }\n    \n     /**\n     * Mix unsigned int data into a RandNode. Returns a new RandNode.\n     */\n    function derive(RandNode memory self, uint256 entropy) internal pure returns (RandNode memory) {\n        return RandNode(sha256(abi.encodePacked(self._hash, entropy)));\n    }\n\n    /**\n     * Returns the base RNG hash for the given RandNode.\n     * Does another round of hashing in case you made a RandNode(\"Stuff\").\n     */\n    function getHash(RandNode memory self) internal pure returns (bytes32) {\n        return sha256(abi.encodePacked(self._hash));\n    }\n    \n    /**\n     * Return true or false with 50% probability.\n     */\n    function getBool(RandNode memory self) internal pure returns (bool) {\n        return uint256(getHash(self)) & 0x1 > 0;\n    }\n    \n    /**\n     * Get an int128 full of random bits.\n     */\n    function getInt128(RandNode memory self) internal pure returns (int128) {\n        // Just cast to int and truncate\n        return int128(int256(getHash(self)));\n    }\n    \n    /**\n     * Get a real88x40 between 0 (inclusive) and 1 (exclusive).\n     */\n    function getReal(RandNode memory self) internal pure returns (int128) {\n        return getInt128(self).fpart();\n    }\n    \n    /**\n     * Get an integer between low, inclusive, and high, exclusive. Represented as a normal int, not a real.\n     */\n    function getIntBetween(RandNode memory self, int88 low, int88 high) internal pure returns (int88) {\n        return RealMath.fromReal((getReal(self).mul(RealMath.toReal(high) - RealMath.toReal(low))) + RealMath.toReal(low));\n    }\n    \n    /**\n     * Get a real between realLow (inclusive) and realHigh (exclusive).\n     * Only actually has the bits of entropy from getReal, so some values will not occur.\n     */\n    function getRealBetween(RandNode memory self, int128 realLow, int128 realHigh) internal pure returns (int128) {\n        return getReal(self).mul(realHigh - realLow) + realLow;\n    }\n    \n    /**\n     * Roll a number of die of the given size, add/subtract a bonus, and return the result.\n     * Max size is 100.\n     */\n    function d(RandNode memory self, int8 count, int8 size, int8 bonus) internal pure returns (int16) {\n        if (count == 1) {\n            // Base case\n            return int16(getIntBetween(self, 1, size)) + bonus;\n        } else {\n            // Loop and sum\n            int16 sum = bonus;\n            for(int8 i = 0; i < count; i++) {\n                // Roll each die with no bonus\n                sum += d(derive(self, i), 1, size, 0);\n            }\n            return sum;\n        }\n    }\n}\n\n// This code is part of Macroverse and is licensed: MIT\n\n/**\n * Interface for an access control strategy for Macroverse contracts.\n * Can be asked if a certain query should be allowed, and will return true or false.\n * Allows for different access control strategies (unrestricted, minimum balance, subscription, etc.) to be swapped in.\n */\nabstract contract AccessControl {\n    /**\n     * Should a query be allowed for this msg.sender (calling contract) and this tx.origin (calling user)?\n     */\n    function allowQuery(address sender, address origin) virtual public view returns (bool);\n}\n\n// This code is part of Macroverse and is licensed: UNLICENSED\n\n// This code is part of OpenZeppelin and is licensed: MIT\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\ncontract Context {\n    // Empty internal constructor, to prevent people from mistakenly deploying\n    // an instance of this contract, which should be used via inheritance.\n    constructor () internal { }\n\n    function _msgSender() internal view virtual returns (address payable) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes memory) {\n        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n        return msg.data;\n    }\n}\n\n// This code is part of OpenZeppelin and is licensed: MIT\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\ncontract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor () internal {\n        address msgSender = _msgSender();\n        _owner = msgSender;\n        emit OwnershipTransferred(address(0), msgSender);\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(_owner == _msgSender(), \"Ownable: caller is not the owner\");\n        _;\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        emit OwnershipTransferred(_owner, address(0));\n        _owner = address(0);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        emit OwnershipTransferred(_owner, newOwner);\n        _owner = newOwner;\n    }\n}\n\n/**\n * Represents a contract that is Ownable, and which has methods that are to be protected by an AccessControl strategy selected by the owner.\n */\ncontract ControlledAccess is Ownable {\n\n    // This AccessControl contract determines who can run onlyControlledAccess methods.\n    AccessControl accessControl;\n    \n    /**\n     * Make a new ControlledAccess contract, controlling access with the given AccessControl strategy.\n     */\n    constructor(address originalAccessControl) internal {\n        accessControl = AccessControl(originalAccessControl);\n    }\n    \n    /**\n     * Change the access control strategy of the prototype.\n     */\n    function changeAccessControl(address newAccessControl) public onlyOwner {\n        accessControl = AccessControl(newAccessControl);\n    }\n    \n    /**\n     * Only allow queries approved by the access control contract.\n     */\n    modifier onlyControlledAccess {\n        if (!accessControl.allowQuery(msg.sender, tx.origin)) revert();\n        _;\n    }\n    \n\n}\n\n// This code is part of Macroverse and is licensed: UNLICENSED\n\n/**\n * Represents a Macroverse Generator for a galaxy.\n *\n * Permission to call methods on this contract is regulated by a configurable\n * AccessControl contract. One such set of terms might be to require that the\n * account initiating a transaction have a certain minimum MRV token balance.\n *\n * The owner of this contract reserves the right to supersede it with a new\n * version, and to modify the terms for accessing this contract, at any time,\n * for any reason, and without notice. This includes the right to indefinitely\n * or permanently suspend or terminate access to this contract for any person,\n * account, or other contract, or for all persons, accounts, or other\n * contracts. The owner also reserves the right to not do any of the above.\n */\ncontract MacroverseStarGenerator is ControlledAccess {\n    // TODO: RNG doesn't get linked against because we can't pass the struct to the library...\n    using RNG for *;\n    using RealMath for *;\n    // No SafeMath or it might confuse RealMath\n\n    // How big is a sector on a side in LY?\n    int16 constant SECTOR_SIZE = 25;\n    // How far out does the sector system extend?\n    int16 constant MAX_SECTOR = 10000;\n    // How big is the galaxy?\n    int16 constant DISK_RADIUS_IN_SECTORS = 6800;\n    // How thick is its disk?\n    int16 constant DISK_HALFHEIGHT_IN_SECTORS = 40;\n    // How big is the central sphere?\n    int16 constant CORE_RADIUS_IN_SECTORS = 1000;\n    \n    // There are kinds of stars.\n    // We can add more later; these are from http://www.mit.edu/afs.new/sipb/user/sekullbe/furble/planet.txt\n    //                 0           1      2             3           4            5\n    enum ObjectClass { Supergiant, Giant, MainSequence, WhiteDwarf, NeutronStar, BlackHole }\n    // Actual stars have a spectral type\n    //                  0      1      2      3      4      5      6      7\n    enum SpectralType { TypeO, TypeB, TypeA, TypeF, TypeG, TypeK, TypeM, NotApplicable }\n    // Each type has subtypes 0-9, except O which only has 5-9\n    \n    // This root RandNode provides the seed for the universe.\n    RNG.RandNode root;\n    \n    /**\n     * Deploy a new copy of the Macroverse generator contract. Use the given seed to generate a galaxy, down to the star level.\n     * Use the contract at the given address to regulate access.\n     */\n    constructor(bytes32 baseSeed, address accessControlAddress) ControlledAccess(accessControlAddress) public {\n        root = RNG.RandNode(baseSeed);\n    }\n    \n    /**\n     * Get the density (between 0 and 1 as a fixed-point real88x40) of stars in the given sector. Sector 0,0,0 is centered on the galactic origin.\n     * +Y is upwards.\n     */\n    function getGalaxyDensity(int16 sectorX, int16 sectorY, int16 sectorZ) public view onlyControlledAccess returns (int128 realDensity) {\n        // We have a central sphere and a surrounding disk.\n        \n        // Enforce absolute bounds.\n        if (sectorX > MAX_SECTOR) return 0;\n        if (sectorY > MAX_SECTOR) return 0;\n        if (sectorZ > MAX_SECTOR) return 0;\n        if (sectorX < -MAX_SECTOR) return 0;\n        if (sectorY < -MAX_SECTOR) return 0;\n        if (sectorZ < -MAX_SECTOR) return 0;\n        \n        if (int(sectorX) * int(sectorX) + int(sectorY) * int(sectorY) + int(sectorZ) * int(sectorZ) < int(CORE_RADIUS_IN_SECTORS) * int(CORE_RADIUS_IN_SECTORS)) {\n            // Central sphere\n            return RealMath.fraction(9, 10);\n        } else if (int(sectorX) * int(sectorX) + int(sectorZ) * int(sectorZ) < int(DISK_RADIUS_IN_SECTORS) * int(DISK_RADIUS_IN_SECTORS) && sectorY < DISK_HALFHEIGHT_IN_SECTORS && sectorY > -DISK_HALFHEIGHT_IN_SECTORS) {\n            // Disk\n            return RealMath.fraction(1, 2);\n        } else {\n            // General background object rate\n            // Set so that some background sectors do indeed have an object in them.\n            return RealMath.fraction(1, 60);\n        }\n    }\n    \n    /**\n     * Get the number of objects in the sector at the given coordinates.\n     */\n    function getSectorObjectCount(int16 sectorX, int16 sectorY, int16 sectorZ) public view onlyControlledAccess returns (uint16) {\n        // Decide on a base item count\n        RNG.RandNode memory sectorNode = root.derive(sectorX).derive(sectorY).derive(sectorZ);\n        int16 maxObjects = sectorNode.derive(\"count\").d(3, 20, 0);\n        \n        // Multiply by the density function\n        int128 presentObjects = RealMath.toReal(maxObjects).mul(getGalaxyDensity(sectorX, sectorY, sectorZ));\n        \n        return uint16(RealMath.fromReal(RealMath.round(presentObjects)));\n    }\n    \n    /**\n     * Get the seed for an object in a sector.\n     */\n    function getSectorObjectSeed(int16 sectorX, int16 sectorY, int16 sectorZ, uint16 object) public view onlyControlledAccess returns (bytes32) {\n        return root.derive(sectorX).derive(sectorY).derive(sectorZ).derive(uint(object))._hash;\n    }\n    \n    /**\n     * Get the class of the star system with the given seed.\n     */\n    function getObjectClass(bytes32 seed) public view onlyControlledAccess returns (ObjectClass) {\n        // Make a node for rolling for the class.\n        RNG.RandNode memory node = RNG.RandNode(seed).derive(\"class\");\n        // Roll an impractical d10,000\n        int88 roll = node.getIntBetween(1, 10000);\n        \n        if (roll == 1) {\n            // Should be a black hole\n            return ObjectClass.BlackHole;\n        } else if (roll <= 3) {\n            // Should be a neutron star\n            return ObjectClass.NeutronStar;\n        } else if (roll <= 700) {\n            // Should be a white dwarf\n            return ObjectClass.WhiteDwarf;\n        } else if (roll <= 9900) {\n            // Most things are main sequence\n            return ObjectClass.MainSequence;\n        } else if (roll <= 9990) {\n            return ObjectClass.Giant;\n        } else {\n            return ObjectClass.Supergiant;\n        }\n    }\n    \n    /**\n     * Get the spectral type for an object with the given seed of the given class.\n     */\n    function getObjectSpectralType(bytes32 seed, ObjectClass objectClass) public view onlyControlledAccess returns (SpectralType) {\n        RNG.RandNode memory node = RNG.RandNode(seed).derive(\"type\");\n        int88 roll = node.getIntBetween(1, 10000000); // Even more implausible dice\n\n        if (objectClass == ObjectClass.MainSequence) {\n            if (roll <= 3) {\n                return SpectralType.TypeO;\n            } else if (roll <= 13003) {\n                return SpectralType.TypeB;\n            } else if (roll <= 73003) {\n                return SpectralType.TypeA;\n            } else if (roll <= 373003) {\n                return SpectralType.TypeF;\n            } else if (roll <= 1133003) {\n                return SpectralType.TypeG;\n            } else if (roll <= 2343003) {\n                return SpectralType.TypeK;\n            } else {\n                return SpectralType.TypeM;\n            }\n        } else if (objectClass == ObjectClass.Giant) {\n            if (roll <= 500000) {\n                return SpectralType.TypeF;\n            } else if (roll <= 1000000) {\n                return SpectralType.TypeG;\n            } else if (roll <= 5500000) {\n                return SpectralType.TypeK;\n            } else {\n                return SpectralType.TypeM;\n            }\n        } else if (objectClass == ObjectClass.Supergiant) {\n            if (roll <= 1000000) {\n                return SpectralType.TypeB;\n            } else if (roll <= 2000000) {\n                return SpectralType.TypeA;\n            } else if (roll <= 4000000) {\n                return SpectralType.TypeF;\n            } else if (roll <= 6000000) {\n                return SpectralType.TypeG;\n            } else if (roll <= 8000000) {\n                return SpectralType.TypeK;\n            } else {\n                return SpectralType.TypeM;\n            }\n        } else {\n            // TODO: No spectral class for anyone else.\n            return SpectralType.NotApplicable;\n        }\n        \n    }\n    \n    /**\n     * Get the position of a star within its sector, as reals from 0 to 25.\n     * Note that stars may end up implausibly close together. Such is life in the Macroverse.\n     */\n    function getObjectPosition(bytes32 seed) public view onlyControlledAccess returns (int128 realX, int128 realY, int128 realZ) {\n        RNG.RandNode memory node = RNG.RandNode(seed).derive(\"position\");\n        \n        realX = node.derive(\"x\").getRealBetween(RealMath.toReal(0), RealMath.toReal(25));\n        realY = node.derive(\"y\").getRealBetween(RealMath.toReal(0), RealMath.toReal(25));\n        realZ = node.derive(\"z\").getRealBetween(RealMath.toReal(0), RealMath.toReal(25));\n    }\n    \n    /**\n     * Get the mass of a star, in solar masses as a real, given its seed and class and spectral type.\n     */\n    function getObjectMass(bytes32 seed, ObjectClass objectClass, SpectralType spectralType) public view onlyControlledAccess returns (int128) {\n        RNG.RandNode memory node = RNG.RandNode(seed).derive(\"mass\");\n         \n        if (objectClass == ObjectClass.BlackHole) {\n            return node.getRealBetween(RealMath.toReal(5), RealMath.toReal(50));\n        } else if (objectClass == ObjectClass.NeutronStar) {\n            return node.getRealBetween(RealMath.fraction(11, 10), RealMath.toReal(2));\n        } else if (objectClass == ObjectClass.WhiteDwarf) {\n            return node.getRealBetween(RealMath.fraction(3, 10), RealMath.fraction(11, 10));\n        } else if (objectClass == ObjectClass.MainSequence) {\n            if (spectralType == SpectralType.TypeO) {\n                return node.getRealBetween(RealMath.toReal(16), RealMath.toReal(40));\n            } else if (spectralType == SpectralType.TypeB) {\n                return node.getRealBetween(RealMath.fraction(21, 10), RealMath.toReal(16));\n            } else if (spectralType == SpectralType.TypeA) {\n                return node.getRealBetween(RealMath.fraction(14, 10), RealMath.fraction(21, 10));\n            } else if (spectralType == SpectralType.TypeF) {\n                return node.getRealBetween(RealMath.fraction(104, 100), RealMath.fraction(14, 10));\n            } else if (spectralType == SpectralType.TypeG) {\n                return node.getRealBetween(RealMath.fraction(80, 100), RealMath.fraction(104, 100));\n            } else if (spectralType == SpectralType.TypeK) {\n                return node.getRealBetween(RealMath.fraction(45, 100), RealMath.fraction(80, 100));\n            } else if (spectralType == SpectralType.TypeM) {\n                return node.getRealBetween(RealMath.fraction(8, 100), RealMath.fraction(45, 100));\n            }\n        } else if (objectClass == ObjectClass.Giant) {\n            // Just make it really big\n            return node.getRealBetween(RealMath.toReal(40), RealMath.toReal(50));\n        } else if (objectClass == ObjectClass.Supergiant) {\n            // Just make it really, really big\n            return node.getRealBetween(RealMath.toReal(50), RealMath.toReal(70));\n        }\n    }\n    \n    /**\n     * Determine if the given star has any orbiting planets or not.\n     */\n    function getObjectHasPlanets(bytes32 seed, ObjectClass objectClass, SpectralType spectralType) public view onlyControlledAccess returns (bool) {\n        RNG.RandNode memory node = RNG.RandNode(seed).derive(\"hasplanets\");\n        int88 roll = node.getIntBetween(1, 1000);\n\n        if (objectClass == ObjectClass.MainSequence) {\n            if (spectralType == SpectralType.TypeO || spectralType == SpectralType.TypeB) {\n                return (roll <= 1);\n            } else if (spectralType == SpectralType.TypeA) {\n                return (roll <= 500);\n            } else if (spectralType == SpectralType.TypeF || spectralType == SpectralType.TypeG || spectralType == SpectralType.TypeK) {\n                return (roll <= 990);\n            } else if (spectralType == SpectralType.TypeM) {\n                return (roll <= 634);\n            }\n        } else if (objectClass == ObjectClass.Giant) {\n            return (roll <= 90);\n        } else if (objectClass == ObjectClass.Supergiant) {\n            return (roll <= 50);\n        } else {\n           // Black hole, neutron star, or white dwarf\n           return (roll <= 70);\n        }\n    }\n    \n\n}\n\n// This code is part of Macroverse and is licensed: UNLICENSED",
  "codeformat": "solidity-single-file",
  "contractname": "MacroverseStarGenerator",
  "compilerversion": "v0.6.10+commit.00c0fcaf",
  "optimizationUsed": 0,
  "runs": 200,
  "constructorArguements": "46696174426c6f636b730000000000000000000000000000000000000000000000000000000000000000000019a1f4406462e21efab9c11ab366966e046f3020",
  "libraryname1": "RealMath",
  "libraryaddress1": "0xe7Ce47C030BED8a78889d0C46c5b9CA7a214a55D"
}
interfect commented 4 years ago

Here's a real short one that's still unverified, for testing. It didn't work for me with or without the preamble comment at the top, which contains the only SPDX-License-Identifier comment.

{
  "apikey": "REDACTED",
  "module": "contract",
  "action": "verifysourcecode",
  "contractaddress": "0x19A1f4406462e21EfAb9C11aB366966e046F3020",
  "sourceCode": "/**\nSPDX-License-Identifier: UNLICENSED\nSee https://github.com/OpenZeppelin/openzeppelin-contracts/blob/2a0f2a8ba807b41360e7e092c3d5bb1bfbeb8b50/LICENSE and https://github.com/NovakDistributed/macroverse/blob/eea161aff5dba9d21204681a3b0f5dbe1347e54b/LICENSE\n*/\n\npragma solidity ^0.6.10;\n\n\n// This code is part of OpenZeppelin and is licensed: MIT\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `recipient`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address recipient, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `sender` to `recipient` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n\n/**\n * Interface for an access control strategy for Macroverse contracts.\n * Can be asked if a certain query should be allowed, and will return true or false.\n * Allows for different access control strategies (unrestricted, minimum balance, subscription, etc.) to be swapped in.\n */\nabstract contract AccessControl {\n    /**\n     * Should a query be allowed for this msg.sender (calling contract) and this tx.origin (calling user)?\n     */\n    function allowQuery(address sender, address origin) virtual public view returns (bool);\n}\n\n// This code is part of Macroverse and is licensed: UNLICENSED\n\n/**\n * Represents an access control strategy where any end user (origin) with a minimum balance in an ERC20 token is allowed.\n */\ncontract MinimumBalanceAccessControl {\n    IERC20 tokenAddress;\n    uint minBalanceInAtomicUnits;\n    \n    /**\n     * Make a new MinimumBalanceAccessControl that requires the specified minimum balance of the specified token.\n     */\n    constructor(address tokenAddress_, uint minBalanceInAtomicUnits_) public {\n        tokenAddress = IERC20(tokenAddress_);\n        minBalanceInAtomicUnits = minBalanceInAtomicUnits_;\n    }\n    \n    /**\n     * Allow all queries resulting from a transaction initiated from an origin address with at least the required minimum balance.\n     * This means that any contract you use can make queries on your behalf, but that no contract with the minimum balance can proxy\n     * queries for others.\n     */\n    function allowQuery(address /* sender */, address origin) public view returns (bool) {\n        if (tokenAddress.balanceOf(origin) >= minBalanceInAtomicUnits) {\n            return true;\n        }\n        return false;\n    }\n}\n\n// This code is part of Macroverse and is licensed: UNLICENSED",
  "codeformat": "solidity-single-file",
  "contractname": "MinimumBalanceAccessControl",
  "compilerversion": "v0.6.10+commit.00c0fcaf",
  "optimizationUsed": 0,
  "runs": 200,
  "constructorArguements": "0000000000000000000000009f1b1436936549d05f594410e909b5a230e9b96f0000000000000000000000000000000000000000000000056bc75e2d63100000"
}
Enigmatic331 commented 4 years ago

Hey @interfect thanks for this - I am looking into it. Will ping back shortly.

Enigmatic331 commented 4 years ago

@interfect - All your feedback is very much appreciated!

So currently it seems that there's some issues when we run a compile on soljson v0.6.10. also affecting Remix. Dropping the version to 0.6.9 should resolve it but of course, not what we want. :)

Will crack on this a bit more from our side and report back.

image

interfect commented 4 years ago

Thanks! I ought to be able to use 0.6.9 as a workaround for now.

June 26, 2020 2:06 AM, "Enigmatic331" <notifications@github.com (mailto:notifications@github.com?to=%22Enigmatic331%22%20notifications@github.com)> wrote: @interfect (https://github.com/interfect) - All your feedback is very much appreciated!

So currently it seems that there's some issues when we run a compile on soljson v0.6.10. also affecting Remix. Dropping the version to 0.6.9 should resolve it but of course, not what we want. :) 

Will crack on this a bit more from our side and report back. 

 (https://user-images.githubusercontent.com/28551011/85840258-c8e7c580-b7ce-11ea-832f-cd4a83c23379.png) 

—

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub (https://github.com/rkalis/truffle-plugin-verify/issues/27#issuecomment-650074574), or unsubscribe (https://github.com/notifications/unsubscribe-auth/AAFXTNTPETS6MB7GQISJH7TRYRQJVANCNFSM4KPZ6R7A).

Enigmatic331 commented 4 years ago

@interfect - Thanks to @chriseth (:heart:), we are sorted for v0.6.10 - Had a quick run with your example contract via our API just now:

https://rinkeby.etherscan.io/address/0x68be475b1993c4bb400e8cf5d640b64ec89f2f8d#code

Feel free to ping if you might be facing any other issues. As for the SPDX license, on a flattened contract yes we will only be able to get solc to compile with a single SPDX identifier. Though I am now curious how standard-json with multiple files will work with multiple SPDX licenses - Will tinker around with this for a bit.

interfect commented 4 years ago

OK @Enigmatic331, it definitely seems to be all working right for me now (if I sed out the SPDXes and add a new one in the verifier plugin preamble, at least, which is the only way I've tested). Thanks for all your and @chriseth's hard work!

rkalis commented 4 years ago

@interfect I just released a new update that allows you to provide an SPDX license identifier using the --license parameter. e.g. truffle run verify MetaCoin --network rinkeby --license MIT. That should remove the need to manually sed the identifiers.