Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
Latest 1 internal transaction
Advanced mode:
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
8889247 | 276 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Contract Name:
OptimismHost
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 200 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; import "./EvmHost.sol"; import "ismp/StateMachine.sol"; contract OptimismHost is EvmHost { constructor(HostParams memory params) EvmHost(params) {} /// chainId for the optimism mainnet uint256 public constant CHAIN_ID = 10; function chainId() public pure override returns (uint256) { return CHAIN_ID; } function host() public pure override returns (bytes memory) { return StateMachine.optimism(); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; import {Context} from "openzeppelin/utils/Context.sol"; import {Math} from "openzeppelin/utils/math/Math.sol"; import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol"; import {Bytes} from "solidity-merkle-trees/trie/Bytes.sol"; import {IIsmpModule} from "ismp/IIsmpModule.sol"; import {DispatchPost, DispatchPostResponse, DispatchGet} from "ismp/IDispatcher.sol"; import {IIsmpHost, FeeMetadata, ResponseReceipt} from "ismp/IIsmpHost.sol"; import {StateCommitment, StateMachineHeight} from "ismp/IConsensusClient.sol"; import {IHandler} from "ismp/IHandler.sol"; import {PostRequest, PostResponse, GetRequest, GetResponse, PostTimeout, Message} from "ismp/Message.sol"; // The IsmpHost parameters struct HostParams { // default timeout in seconds for requests. uint256 defaultTimeout; // base fee for GET requests uint256 baseGetRequestFee; // cost of cross-chain requests in $DAI per byte uint256 perByteFee; // The fee token contract. This will typically be DAI. // but we allow it to be configurable to prevent future regrets. address feeTokenAddress; // admin account, this only has the rights to freeze, or unfreeze the bridge address admin; // Ismp request/response handler address handler; // the authorized host manager contract address hostManager; // unstaking period uint256 unStakingPeriod; // minimum challenge period in seconds; uint256 challengePeriod; // consensus client contract address consensusClient; // current verified state of the consensus client; bytes consensusState; // timestamp for when the consensus was most recently updated uint256 lastUpdated; // latest state machine height uint256 latestStateMachineHeight; // state machine identifier for hyperbridge bytes hyperbridge; } // The host manager interface. This provides methods for modifying the host's params or withdrawing bridge revenue. // Can only be called used by the HostManager module. interface IHostManager { /** * @dev Updates IsmpHost params * @param params new IsmpHost params */ function setHostParams(HostParams memory params) external; /** * @dev withdraws bridge revenue to the given address * @param params, the parameters for withdrawal */ function withdraw(WithdrawParams memory params) external; } // Withdraw parameters struct WithdrawParams { // The beneficiary address address beneficiary; // the amount to be disbursed uint256 amount; } /// Ismp implementation for Evm hosts abstract contract EvmHost is IIsmpHost, IHostManager, Context { using Bytes for bytes; using Message for PostResponse; using Message for PostRequest; using Message for GetRequest; // commitment of all outgoing requests and amount put up for relayers. mapping(bytes32 => FeeMetadata) private _requestCommitments; // commitment of all outgoing responses and amount put up for relayers. mapping(bytes32 => FeeMetadata) private _responseCommitments; // commitment of all incoming requests and who delivered them. mapping(bytes32 => address) private _requestReceipts; // commitment of all incoming responses and who delivered them. // maps the request commitment to a receipt object mapping(bytes32 => ResponseReceipt) private _responseReceipts; // commitment of all incoming requests that have been responded to mapping(bytes32 => bool) private _responded; // (stateMachineId => (blockHeight => StateCommitment)) mapping(uint256 => mapping(uint256 => StateCommitment)) private _stateCommitments; // (stateMachineId => (blockHeight => timestamp)) mapping(uint256 => mapping(uint256 => uint256)) private _stateCommitmentsUpdateTime; // Parameters for the host HostParams private _hostParams; // monotonically increasing nonce for outgoing requests uint256 private _nonce; // emergency shutdown button, only the admin can do this bool private _frozen; // Emitted when an incoming POST request is handled event PostRequestHandled(bytes32 commitment, address relayer); // Emitted when an incoming POST response is handled event PostResponseHandled(bytes32 commitment, address relayer); // Emitted when an outgoing Get request is handled event GetRequestHandled(bytes32 commitment, address relayer); event PostRequestEvent( bytes source, bytes dest, bytes from, bytes to, uint256 indexed nonce, uint256 timeoutTimestamp, bytes data, uint256 gaslimit, uint256 fee ); event PostResponseEvent( bytes source, bytes dest, bytes from, bytes to, uint256 indexed nonce, uint256 timeoutTimestamp, bytes data, uint256 gaslimit, bytes response, uint256 resGaslimit, uint256 resTimeoutTimestamp, uint256 fee ); event GetRequestEvent( bytes source, bytes dest, bytes from, bytes[] keys, uint256 indexed nonce, uint256 height, uint256 timeoutTimestamp, uint256 gaslimit, uint256 fee ); modifier onlyAdmin() { require(_msgSender() == _hostParams.admin, "EvmHost: Only admin"); _; } modifier onlyHandler() { require(_msgSender() == address(_hostParams.handler), "EvmHost: Only handler"); _; } modifier onlyManager() { require(_msgSender() == _hostParams.hostManager, "EvmHost: Only Manager contract"); _; } constructor(HostParams memory params) { _hostParams = params; } /** * @return the host admin */ function admin() external view returns (address) { return _hostParams.admin; } /** * @return the host state machine id */ function host() public view virtual returns (bytes memory); /** * @return the mainnet evm chainId for this host */ function chainId() public virtual returns (uint256); /** * @return the address of the DAI ERC-20 contract on this state machine */ function dai() public view returns (address) { return _hostParams.feeTokenAddress; } /** * @return the per-byte fee for outgoing requests. */ function perByteFee() external view returns (uint256) { return _hostParams.perByteFee; } /** * @return the base fee for outgoing GET requests */ function baseGetRequestFee() external view returns (uint256) { return _hostParams.baseGetRequestFee; } /** * @return the state machine identifier for the connected hyperbridge instance */ function hyperbridge() external view returns (bytes memory) { return _hostParams.hyperbridge; } /** * @return the host timestamp */ function timestamp() external view returns (uint256) { return block.timestamp; } /** * @return the `frozen` status */ function frozen() external view returns (bool) { return _frozen; } function hostParams() external view returns (HostParams memory) { return _hostParams; } /** * @param height - state machine height * @return the state commitment at `height` */ function stateMachineCommitment(StateMachineHeight memory height) external view returns (StateCommitment memory) { return _stateCommitments[height.stateMachineId][height.height]; } /** * @param height - state machine height * @return the state machine update time at `height` */ function stateMachineCommitmentUpdateTime(StateMachineHeight memory height) external view returns (uint256) { return _stateCommitmentsUpdateTime[height.stateMachineId][height.height]; } /** * @dev Should return a handle to the consensus client based on the id * @return the consensus client contract */ function consensusClient() external view returns (address) { return _hostParams.consensusClient; } /** * @return the last updated time of the consensus client */ function consensusUpdateTime() external view returns (uint256) { return _hostParams.lastUpdated; } /** * @return the state of the consensus client */ function consensusState() external view returns (bytes memory) { return _hostParams.consensusState; } /** * @return the challenge period */ function challengePeriod() external view returns (uint256) { return _hostParams.challengePeriod; } /** * @return the latest state machine height */ function latestStateMachineHeight() external view returns (uint256) { return _hostParams.latestStateMachineHeight; } /** * @return the unstaking period */ function unStakingPeriod() external view returns (uint256) { return _hostParams.unStakingPeriod; } /** * @param commitment - commitment to the request * @return existence status of an incoming request commitment */ function requestReceipts(bytes32 commitment) external view returns (address) { return _requestReceipts[commitment]; } /** * @param commitment - commitment to the response * @return existence status of an incoming response commitment */ function responseReceipts(bytes32 commitment) external view returns (ResponseReceipt memory) { return _responseReceipts[commitment]; } /** * @param commitment - commitment to the request * @return existence status of an outgoing request commitment */ function requestCommitments(bytes32 commitment) external view returns (FeeMetadata memory) { return _requestCommitments[commitment]; } /** * @param commitment - commitment to the response * @return existence status of an outgoing response commitment */ function responseCommitments(bytes32 commitment) external view returns (FeeMetadata memory) { return _responseCommitments[commitment]; } /** * @dev Updates the HostParams, can only be called by cross-chain governance * @param params, the new host params. */ function setHostParams(HostParams memory params) external onlyManager { _hostParams = params; } /** * @dev Updates the HostParams * @param params, the new host params. Can only be called by admin on testnets. */ function setHostParamsAdmin(HostParams memory params) external onlyAdmin { require(chainId() != block.chainid, "Cannot set params on mainnet"); _hostParams = params; } /** * @dev withdraws host revenue to the given address, can only be called by cross-chain governance * @param params, the parameters for withdrawal */ function withdraw(WithdrawParams memory params) external onlyManager { require(IERC20(dai()).transfer(params.beneficiary, params.amount), "Host has an insufficient balance"); } /** * @dev Store an encoded consensus state */ function storeConsensusState(bytes memory state) external onlyHandler { _hostParams.consensusState = state; } /** * @dev Store the timestamp when the consensus client was updated */ function storeConsensusUpdateTime(uint256 time) external onlyHandler { _hostParams.lastUpdated = time; } /** * @dev Store the latest state machine height * @param height State Machine Latest Height */ function storeLatestStateMachineHeight(uint256 height) external onlyHandler { _hostParams.latestStateMachineHeight = height; } /** * @dev Store the commitment at `state height` */ function storeStateMachineCommitment(StateMachineHeight memory height, StateCommitment memory commitment) external onlyHandler { _stateCommitments[height.stateMachineId][height.height] = commitment; } /** * @dev Store the timestamp when the state machine was updated */ function storeStateMachineCommitmentUpdateTime(StateMachineHeight memory height, uint256 time) external onlyHandler { _stateCommitmentsUpdateTime[height.stateMachineId][height.height] = time; } /** * @dev set the new state of the bridge * @param newState new state */ function setFrozenState(bool newState) public onlyAdmin { _frozen = newState; } /** * @dev sets the initial consensus state * @param state initial consensus state */ function setConsensusState(bytes memory state) public onlyAdmin { // if we're on mainnet, then consensus state can only be initialized once. require( chainId() == block.chainid ? _hostParams.consensusState.equals(new bytes(0)) : true, "Unauthorized action" ); _hostParams.latestStateMachineHeight = 0; _hostParams.consensusState = state; } /** * @dev Dispatch an incoming post request to destination module * @param request - post request */ function dispatchIncoming(PostRequest memory request) external onlyHandler { address destination = _bytesToAddress(request.to); uint256 size; assembly { size := extcodesize(destination) } if (size == 0) { // instead of reverting the entire batch, early return here. return; } (bool success,) = address(destination).call(abi.encodeWithSelector(IIsmpModule.onAccept.selector, request)); if (success) { bytes32 commitment = request.hash(); _requestReceipts[commitment] = tx.origin; emit PostRequestHandled({commitment: commitment, relayer: tx.origin}); } } /** * @dev Dispatch an incoming post response to source module * @param response - post response */ function dispatchIncoming(PostResponse memory response) external onlyHandler { address origin = _bytesToAddress(response.request.from); (bool success,) = address(origin).call(abi.encodeWithSelector(IIsmpModule.onPostResponse.selector, response)); if (success) { bytes32 commitment = response.request.hash(); _responseReceipts[commitment] = ResponseReceipt({relayer: tx.origin, responseCommitment: response.hash()}); emit PostResponseHandled({commitment: commitment, relayer: tx.origin}); } } /** * @dev Dispatch an incoming get response to source module * @param response - get response */ function dispatchIncoming(GetResponse memory response, FeeMetadata memory meta) external onlyHandler { uint256 fee = 0; for (uint256 i = 0; i < response.values.length; i++) { fee += (_hostParams.perByteFee * response.values[i].value.length); } // Charge the originating user/application require(IERC20(dai()).transferFrom(meta.sender, address(this), fee), "Origin has insufficient funds"); address origin = _bytesToAddress(response.request.from); (bool success,) = address(origin).call(abi.encodeWithSelector(IIsmpModule.onGetResponse.selector, response)); if (success) { bytes32 commitment = response.request.hash(); // don't commit the full response object because, it's unused. _responseReceipts[commitment] = ResponseReceipt({relayer: tx.origin, responseCommitment: bytes32(0)}); if (meta.fee > 0) { require(IERC20(dai()).transfer(tx.origin, meta.fee), "EvmHost has insufficient funds"); } emit PostResponseHandled({commitment: commitment, relayer: tx.origin}); } } /** * @dev Dispatch an incoming get timeout to source module * @param request - get request */ function dispatchIncoming(GetRequest memory request, FeeMetadata memory meta, bytes32 commitment) external onlyHandler { address origin = _bytesToAddress(request.from); (bool success,) = address(origin).call(abi.encodeWithSelector(IIsmpModule.onGetTimeout.selector, request)); if (success) { // delete memory of this request delete _requestCommitments[commitment]; // refund relayer fee IERC20(dai()).transfer(meta.sender, meta.fee); } } /** * @dev Dispatch an incoming post timeout to source module * @param request - post timeout */ function dispatchIncoming(PostRequest memory request, FeeMetadata memory meta, bytes32 commitment) external onlyHandler { address origin = _bytesToAddress(request.from); (bool success,) = address(origin).call(abi.encodeWithSelector(IIsmpModule.onPostRequestTimeout.selector, request)); if (success) { // delete memory of this request delete _requestCommitments[commitment]; // refund relayer fee IERC20(dai()).transfer(meta.sender, meta.fee); } } /** * @dev Dispatch an incoming post response timeout to source module * @param response - timed-out post response */ function dispatchIncoming(PostResponse memory response, FeeMetadata memory meta, bytes32 commitment) external onlyHandler { address origin = _bytesToAddress(response.request.to); (bool success,) = address(origin).call(abi.encodeWithSelector(IIsmpModule.onPostResponseTimeout.selector, response)); if (success) { // delete memory of this response delete _responseCommitments[commitment]; delete _responded[response.request.hash()]; // refund relayer fee IERC20(dai()).transfer(meta.sender, meta.fee); } } /** * @dev Dispatch a POST request to the hyperbridge * @param post - post request */ function dispatch(DispatchPost memory post) external { uint256 fee = (_hostParams.perByteFee * post.body.length) + post.fee; require(IERC20(dai()).transferFrom(post.payer, address(this), fee), "Payer has insufficient funds"); // adjust the timeout uint64 timeout = post.timeout == 0 ? 0 : uint64(this.timestamp()) + uint64(Math.max(_hostParams.defaultTimeout, post.timeout)); PostRequest memory request = PostRequest({ source: host(), dest: post.dest, nonce: uint64(_nextNonce()), from: abi.encodePacked(_msgSender()), to: post.to, timeoutTimestamp: timeout, body: post.body, gaslimit: post.gaslimit }); // make the commitment _requestCommitments[request.hash()] = FeeMetadata({sender: post.payer, fee: post.fee}); emit PostRequestEvent( request.source, request.dest, request.from, abi.encodePacked(request.to), request.nonce, request.timeoutTimestamp, request.body, request.gaslimit, post.fee ); } /** * @dev Dispatch a get request to the hyperbridge * @param get - get request */ function dispatch(DispatchGet memory get) external { uint256 fee = _hostParams.baseGetRequestFee + get.fee; require(IERC20(dai()).transferFrom(get.payer, address(this), fee), "Payer has insufficient funds"); // adjust the timeout uint64 timeout = get.timeout == 0 ? 0 : uint64(this.timestamp()) + uint64(Math.max(_hostParams.defaultTimeout, get.timeout)); GetRequest memory request = GetRequest({ source: host(), dest: get.dest, nonce: uint64(_nextNonce()), from: abi.encodePacked(_msgSender()), timeoutTimestamp: timeout, keys: get.keys, height: get.height, gaslimit: get.gaslimit }); // make the commitment _requestCommitments[request.hash()] = FeeMetadata({sender: get.payer, fee: get.fee}); emit GetRequestEvent( request.source, request.dest, request.from, request.keys, request.nonce, request.height, request.timeoutTimestamp, request.gaslimit, get.fee ); } /** * @dev Dispatch a response to the hyperbridge * @param post - post response */ function dispatch(DispatchPostResponse memory post) external { bytes32 receipt = post.request.hash(); // known request? require(_requestReceipts[receipt] != address(0), "EvmHost: Unknown request"); // check that the authorized application is issuing this response require(_bytesToAddress(post.request.to) == _msgSender(), "EvmHost: Unauthorized Response"); // check that request has not already been responed to require(!_responded[receipt], "EvmHost: Duplicate Response"); uint256 fee = (_hostParams.perByteFee * post.response.length) + post.fee; require(IERC20(dai()).transferFrom(post.payer, address(this), fee), "Payer has insufficient funds"); // adjust the timeout uint64 timeout = post.timeout == 0 ? 0 : uint64(this.timestamp()) + uint64(Math.max(_hostParams.defaultTimeout, post.timeout)); PostResponse memory response = PostResponse({ request: post.request, response: post.response, timeoutTimestamp: timeout, gaslimit: post.gaslimit }); FeeMetadata memory meta = FeeMetadata({fee: post.fee, sender: post.payer}); _responseCommitments[response.hash()] = meta; _responded[receipt] = true; emit PostResponseEvent( response.request.source, response.request.dest, response.request.from, abi.encodePacked(response.request.to), response.request.nonce, response.request.timeoutTimestamp, response.request.body, response.request.gaslimit, response.response, response.timeoutTimestamp, response.gaslimit, meta.fee // sigh solidity ); } /** * @dev Get next available nonce for outgoing requests. */ function _nextNonce() private returns (uint256) { uint256 _nonce_copy = _nonce; unchecked { ++_nonce; } return _nonce_copy; } /** * @dev Converts bytes to address. * @param _bytes bytes value to be converted * @return addr returns the address */ function _bytesToAddress(bytes memory _bytes) private pure returns (address addr) { require(_bytes.length >= 20, "Invalid address length"); assembly { addr := mload(add(_bytes, 20)) } } }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; import {Strings} from "openzeppelin/utils/Strings.sol"; library StateMachine { /// The identifier for the relay chain. uint256 public constant RELAY_CHAIN = 0; // Address a state machine on the polkadot relay chain function polkadot(uint256 id) internal pure returns (bytes memory) { return bytes(string.concat("POLKADOT-", Strings.toString(id))); } // Address a state machine on the kusama relay chain function kusama(uint256 id) internal pure returns (bytes memory) { return bytes(string.concat("KUSAMA-", Strings.toString(id))); } // Address the ethereum "execution layer" function ethereum() internal pure returns (bytes memory) { return bytes("ETHE"); } // Address the Arbitrum state machine function arbitrum() internal pure returns (bytes memory) { return bytes("ARBI"); } // Address the Optimism state machine function optimism() internal pure returns (bytes memory) { return bytes("OPTI"); } // Address the Base state machine function base() internal pure returns (bytes memory) { return bytes("BASE"); } // Address the Polygon POS state machine function polygon() internal pure returns (bytes memory) { return bytes("POLY"); } // Address the Binance smart chain state machine function bsc() internal pure returns (bytes memory) { return bytes("BSC"); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
pragma solidity ^0.8.17; // SPDX-License-Identifier: Apache2 import {Memory} from "./Memory.sol"; struct ByteSlice { bytes data; uint256 offset; } library Bytes { uint256 internal constant BYTES_HEADER_SIZE = 32; // Checks if two `bytes memory` variables are equal. This is done using hashing, // which is much more gas efficient then comparing each byte individually. // Equality means that: // - 'self.length == other.length' // - For 'n' in '[0, self.length)', 'self[n] == other[n]' function equals(bytes memory self, bytes memory other) internal pure returns (bool equal) { if (self.length != other.length) { return false; } uint256 addr; uint256 addr2; assembly { addr := add(self, /*BYTES_HEADER_SIZE*/ 32) addr2 := add(other, /*BYTES_HEADER_SIZE*/ 32) } equal = Memory.equals(addr, addr2, self.length); } function readByte(ByteSlice memory self) internal pure returns (uint8) { if (self.offset + 1 > self.data.length) { revert("Out of range"); } uint8 b = uint8(self.data[self.offset]); self.offset += 1; return b; } // Copies 'len' bytes from 'self' into a new array, starting at the provided 'startIndex'. // Returns the new copy. // Requires that: // - 'startIndex + len <= self.length' // The length of the substring is: 'len' function read(ByteSlice memory self, uint256 len) internal pure returns (bytes memory) { require(self.offset + len <= self.data.length); if (len == 0) { return ""; } uint256 addr = Memory.dataPtr(self.data); bytes memory slice = Memory.toBytes(addr + self.offset, len); self.offset += len; return slice; } // Copies a section of 'self' into a new array, starting at the provided 'startIndex'. // Returns the new copy. // Requires that 'startIndex <= self.length' // The length of the substring is: 'self.length - startIndex' function substr(bytes memory self, uint256 startIndex) internal pure returns (bytes memory) { require(startIndex <= self.length); uint256 len = self.length - startIndex; uint256 addr = Memory.dataPtr(self); return Memory.toBytes(addr + startIndex, len); } // Copies 'len' bytes from 'self' into a new array, starting at the provided 'startIndex'. // Returns the new copy. // Requires that: // - 'startIndex + len <= self.length' // The length of the substring is: 'len' function substr(bytes memory self, uint256 startIndex, uint256 len) internal pure returns (bytes memory) { require(startIndex + len <= self.length); if (len == 0) { return ""; } uint256 addr = Memory.dataPtr(self); return Memory.toBytes(addr + startIndex, len); } // Combines 'self' and 'other' into a single array. // Returns the concatenated arrays: // [self[0], self[1], ... , self[self.length - 1], other[0], other[1], ... , other[other.length - 1]] // The length of the new array is 'self.length + other.length' function concat(bytes memory self, bytes memory other) internal pure returns (bytes memory) { bytes memory ret = new bytes(self.length + other.length); uint256 src; uint256 srcLen; (src, srcLen) = Memory.fromBytes(self); uint256 src2; uint256 src2Len; (src2, src2Len) = Memory.fromBytes(other); uint256 dest; (dest,) = Memory.fromBytes(ret); uint256 dest2 = dest + srcLen; Memory.copy(src, dest, srcLen); Memory.copy(src2, dest2, src2Len); return ret; } function toBytes32(bytes memory self) internal pure returns (bytes32 out) { require(self.length >= 32, "Bytes:: toBytes32: data is to short."); assembly { out := mload(add(self, 32)) } } function toBytes16(bytes memory self, uint256 offset) internal pure returns (bytes16 out) { for (uint256 i = 0; i < 16; i++) { out |= bytes16(bytes1(self[offset + i]) & 0xFF) >> (i * 8); } } function toBytes8(bytes memory self, uint256 offset) internal pure returns (bytes8 out) { for (uint256 i = 0; i < 8; i++) { out |= bytes8(bytes1(self[offset + i]) & 0xFF) >> (i * 8); } } function toBytes4(bytes memory self, uint256 offset) internal pure returns (bytes4) { bytes4 out; for (uint256 i = 0; i < 4; i++) { out |= bytes4(self[offset + i] & 0xFF) >> (i * 8); } return out; } function toBytes2(bytes memory self, uint256 offset) internal pure returns (bytes2) { bytes2 out; for (uint256 i = 0; i < 2; i++) { out |= bytes2(self[offset + i] & 0xFF) >> (i * 8); } return out; } function removeLeadingZero(bytes memory data) internal pure returns (bytes memory) { uint256 length = data.length; uint256 startIndex = 0; for (uint256 i = 0; i < length; i++) { if (data[i] != 0) { startIndex = i; break; } } return substr(data, startIndex); } function removeEndingZero(bytes memory data) internal pure returns (bytes memory) { uint256 length = data.length; uint256 endIndex = 0; for (uint256 i = length - 1; i >= 0; i--) { if (data[i] != 0) { endIndex = i; break; } } return substr(data, 0, endIndex + 1); } function reverse(bytes memory inbytes) internal pure returns (bytes memory) { uint256 inlength = inbytes.length; bytes memory outbytes = new bytes(inlength); for (uint256 i = 0; i <= inlength - 1; i++) { outbytes[i] = inbytes[inlength - i - 1]; } return outbytes; } }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; import {PostRequest, PostResponse, GetResponse, GetRequest} from "./Message.sol"; interface IIsmpModule { /** * @dev Called by the IsmpHost to notify a module of a new request the module may choose to respond immediately, or in a later block * @param request post request */ function onAccept(PostRequest memory request) external; /** * @dev Called by the IsmpHost to notify a module of a post response to a previously sent out request * @param response post response */ function onPostResponse(PostResponse memory response) external; /** * @dev Called by the IsmpHost to notify a module of a get response to a previously sent out request * @param response get response */ function onGetResponse(GetResponse memory response) external; /** * @dev Called by the IsmpHost to notify a module of post requests that were previously sent but have now timed-out * @param request post request */ function onPostRequestTimeout(PostRequest memory request) external; /** * @dev Called by the IsmpHost to notify a module of post requests that were previously sent but have now timed-out * @param request post request */ function onPostResponseTimeout(PostResponse memory request) external; /** * @dev Called by the IsmpHost to notify a module of get requests that were previously sent but have now timed-out * @param request get request */ function onGetTimeout(GetRequest memory request) external; } /// Abstract contract to make implementing `IIsmpModule` easier. abstract contract BaseIsmpModule is IIsmpModule { function onAccept(PostRequest calldata) external virtual { revert("IsmpModule doesn't expect Post requests"); } function onPostRequestTimeout(PostRequest memory) external virtual { revert("IsmpModule doesn't emit Post requests"); } function onPostResponse(PostResponse memory) external virtual { revert("IsmpModule doesn't emit Post responses"); } function onPostResponseTimeout(PostResponse memory) external virtual { revert("IsmpModule doesn't emit Post responses"); } function onGetResponse(GetResponse memory) external virtual { revert("IsmpModule doesn't emit Get requests"); } function onGetTimeout(GetRequest memory) external virtual { revert("IsmpModule doesn't emit Get requests"); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; import {StateMachineHeight} from "./IConsensusClient.sol"; import {PostRequest} from "./Message.sol"; // An object for dispatching post requests to the IsmpDispatcher struct DispatchPost { // bytes representation of the destination state machine bytes dest; // the destination module bytes to; // the request body bytes body; // timeout for this request in seconds uint64 timeout; // gas limit for executing this request on destination & its response (if any) on the source. uint64 gaslimit; // the amount put up to be paid to the relayer, this is in $DAI and charged to tx.origin uint256 fee; // who pays for this request? address payer; } // An object for dispatching get requests to the IsmpDispatcher struct DispatchGet { // bytes representation of the destination state machine bytes dest; // height at which to read the state machine uint64 height; // Storage keys to read bytes[] keys; // timeout for this request in seconds uint64 timeout; // gas limit for executing this request on destination & its response (if any) on the source. uint64 gaslimit; // the amount put up to be paid to the relayer, this is in $DAI and charged to tx.origin uint256 fee; // who pays for this request? address payer; } struct DispatchPostResponse { // The request that initiated this response PostRequest request; // bytes for post response bytes response; // timeout for this response in seconds uint64 timeout; // gas limit for executing this response on destination which is the source of the request. uint64 gaslimit; // the amount put up to be paid to the relayer, this is in $DAI and charged to tx.origin uint256 fee; // who pays for this request? address payer; } // The core ISMP API, IIsmpModules use this interface to send outgoing get/post requests & responses interface IDispatcher { /** * @dev Dispatch a post request to the ISMP router. * @param request - post request */ function dispatch(DispatchPost memory request) external; /** * @dev Dispatch a GET request to the ISMP router. * @param request - get request */ function dispatch(DispatchGet memory request) external; /** * @dev Provide a response to a previously received request. * @param response - post response */ function dispatch(DispatchPostResponse memory response) external; }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; import {StateCommitment, StateMachineHeight} from "./IConsensusClient.sol"; import {IDispatcher} from "./IDispatcher.sol"; import {PostRequest, PostResponse, GetResponse, PostTimeout, GetRequest} from "./Message.sol"; // Some metadata about the request struct FeeMetadata { // the relayer fee uint256 fee; // user who initiated the request address sender; } struct ResponseReceipt { // commitment of the response object bytes32 responseCommitment; // address of the relayer responsible for this response delivery address relayer; } interface IIsmpHost is IDispatcher { /** * @return the host admin */ function admin() external returns (address); /** * @return the address of the DAI ERC-20 contract on this state machine */ function dai() external view returns (address); /** * @return the per-byte fee for outgoing requests. */ function perByteFee() external view returns (uint256); /** * @return the host state machine id */ function host() external view returns (bytes memory); /** * @return the host timestamp */ function timestamp() external view returns (uint256); /** * @return the `frozen` status */ function frozen() external view returns (bool); /** * @param height - state machine height * @return the state commitment at `height` */ function stateMachineCommitment(StateMachineHeight memory height) external returns (StateCommitment memory); /** * @param height - state machine height * @return the state machine commitment update time at `height` */ function stateMachineCommitmentUpdateTime(StateMachineHeight memory height) external returns (uint256); /** * @dev Should return a handle to the consensus client based on the id * @return the consensus client contract */ function consensusClient() external view returns (address); /** * @return the last updated time of the consensus client */ function consensusUpdateTime() external view returns (uint256); /** * @return the latest state machine height */ function latestStateMachineHeight() external view returns (uint256); /** * @return the state of the consensus client */ function consensusState() external view returns (bytes memory); /** * @param commitment - commitment to the request * @return relayer address */ function requestReceipts(bytes32 commitment) external view returns (address); /** * @param commitment - commitment to the request of the response * @return response receipt */ function responseReceipts(bytes32 commitment) external view returns (ResponseReceipt memory); /** * @param commitment - commitment to the request * @return existence status of an outgoing request commitment */ function requestCommitments(bytes32 commitment) external view returns (FeeMetadata memory); /** * @param commitment - commitment to the response * @return existence status of an outgoing response commitment */ function responseCommitments(bytes32 commitment) external view returns (FeeMetadata memory); /** * @return the challenge period */ function challengePeriod() external view returns (uint256); /** * @return the unstaking period */ function unStakingPeriod() external view returns (uint256); /** * @dev Store an encoded consensus state * @param state new consensus state */ function storeConsensusState(bytes memory state) external; /** * @dev Store the timestamp when the consensus client was updated * @param timestamp - new timestamp */ function storeConsensusUpdateTime(uint256 timestamp) external; /** * @dev Store the latest state machine height * @param height State Machine Height */ function storeLatestStateMachineHeight(uint256 height) external; /** * @dev Store the commitment at `state height` * @param height state machine height * @param commitment state commitment */ function storeStateMachineCommitment(StateMachineHeight memory height, StateCommitment memory commitment) external; /** * @dev Store the timestamp when the state machine was updated * @param height state machine height * @param timestamp new timestamp */ function storeStateMachineCommitmentUpdateTime(StateMachineHeight memory height, uint256 timestamp) external; /** * @dev Dispatch an incoming request to destination module * @param request - post request */ function dispatchIncoming(PostRequest memory request) external; /** * @dev Dispatch an incoming post response to source module * @param response - post response */ function dispatchIncoming(PostResponse memory response) external; /** * @dev Dispatch an incoming get response to source module * @param response - get response */ function dispatchIncoming(GetResponse memory response, FeeMetadata memory meta) external; /** * @dev Dispatch an incoming get timeout to source module * @param timeout - timed-out get request */ function dispatchIncoming(GetRequest memory timeout, FeeMetadata memory meta, bytes32 commitment) external; /** * @dev Dispatch an incoming post timeout to source module * @param timeout - timed-out post request */ function dispatchIncoming(PostRequest memory timeout, FeeMetadata memory meta, bytes32 commitment) external; /** * @dev Dispatch an incoming post response timeout to source module * @param timeout - timed-out post response */ function dispatchIncoming(PostResponse memory timeout, FeeMetadata memory meta, bytes32 commitment) external; }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; // The state commiment identifies a commiment to some intermediate state in the state machine. // This contains some metadata about the state machine like it's own timestamp at the time of this commitment. struct StateCommitment { // This timestamp is useful for handling request timeouts. uint256 timestamp; // Overlay trie commitment to all ismp requests & response. bytes32 overlayRoot; // State trie commitment at the given block height bytes32 stateRoot; } // Identifies some state machine height. We allow for a state machine identifier here // as some consensus clients may track multiple, concurrent state machines. struct StateMachineHeight { // the state machine identifier uint256 stateMachineId; // height of this state machine uint256 height; } // An intermediate state in the series of state transitions undergone by a given state machine. struct IntermediateState { // the state machine identifier uint256 stateMachineId; // height of this state machine uint256 height; // state commitment StateCommitment commitment; } // The consensus client interface responsible for the verification of consensus datagrams. // It's internals is opaque to the ISMP framework allowing it to evolve as needed. interface IConsensusClient { /// Verify the consensus proof and return the new trusted consensus state and any intermediate states finalized /// by this consensus proof. function verifyConsensus(bytes memory trustedState, bytes memory proof) external returns (bytes memory, IntermediateState memory); }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; import {IIsmpHost} from "./IIsmpHost.sol"; import { PostRequestMessage, PostResponseMessage, GetResponseMessage, PostRequestTimeoutMessage, PostResponseTimeoutMessage, GetTimeoutMessage } from "./Message.sol"; /* The IHandler interface serves as the entry point for ISMP datagrams, i.e consensus, requests & response messages. The handler is decoupled from the IsmpHost as it allows for easy upgrading through the cross-chain governor contract. This way more efficient cryptographic schemes can be employed without cumbersome contract migrations. */ interface IHandler { /** * @dev Handle an incoming consensus message. This uses the IConsensusClient contract registered on the host to perform the consensus message verification. * @param host - Ismp host * @param proof - consensus proof */ function handleConsensus(IIsmpHost host, bytes memory proof) external; /** * @dev Handles incoming POST requests, check request proofs, message delay and timeouts, then dispatch POST requests to the apropriate contracts. * @param host - Ismp host * @param request - batch post requests */ function handlePostRequests(IIsmpHost host, PostRequestMessage memory request) external; /** * @dev Handles incoming POST responses, check response proofs, message delay and timeouts, then dispatch POST responses to the apropriate contracts. * @param host - Ismp host * @param response - batch post responses */ function handlePostResponses(IIsmpHost host, PostResponseMessage memory response) external; /** * @dev check response proofs, message delay and timeouts, then dispatch get responses to modules * @param host - Ismp host * @param message - batch get responses */ function handleGetResponses(IIsmpHost host, GetResponseMessage memory message) external; /** * @dev check timeout proofs then dispatch to modules * @param host - Ismp host * @param message - batch post request timeouts */ function handlePostRequestTimeouts(IIsmpHost host, PostRequestTimeoutMessage memory message) external; /** * @dev check timeout proofs then dispatch to modules * @param host - Ismp host * @param message - batch post response timeouts */ function handlePostResponseTimeouts(IIsmpHost host, PostResponseTimeoutMessage memory message) external; /** * @dev dispatch to modules * @param host - Ismp host * @param message - batch get request timeouts */ function handleGetRequestTimeouts(IIsmpHost host, GetTimeoutMessage memory message) external; }
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.17; import {StateMachineHeight} from "./IConsensusClient.sol"; import {StorageValue} from "solidity-merkle-trees/MerklePatricia.sol"; struct PostRequest { // the source state machine of this request bytes source; // the destination state machine of this request bytes dest; // request nonce uint64 nonce; // Module Id of this request origin bytes from; // destination module id bytes to; // timestamp by which this request times out. uint64 timeoutTimestamp; // request body bytes body; // gas limit for executing this request on destination & its response (if any) on the source. uint64 gaslimit; } struct GetRequest { // the source state machine of this request bytes source; // the destination state machine of this request bytes dest; // request nonce uint64 nonce; // Module Id of this request origin bytes from; // timestamp by which this request times out. uint64 timeoutTimestamp; // Storage keys to read. bytes[] keys; // height at which to read destination state machine uint64 height; // gas limit for executing this request on destination uint64 gaslimit; } struct GetResponse { // The request that initiated this response GetRequest request; // storage values for get response StorageValue[] values; } struct PostResponse { // The request that initiated this response PostRequest request; // bytes for post response bytes response; // timestamp by which this response times out. uint64 timeoutTimestamp; // gas limit for executing this response on destination which is the source of the request. uint64 gaslimit; } // A post request as a leaf in a merkle tree struct PostRequestLeaf { // The request PostRequest request; // It's index in the mmr leaves uint256 index; // it's k-index uint256 kIndex; } // A post response as a leaf in a merkle tree struct PostResponseLeaf { // The response PostResponse response; // It's index in the mmr leaves uint256 index; // it's k-index uint256 kIndex; } // A merkle mountain range proof. struct Proof { // height of the state machine StateMachineHeight height; // the multi-proof bytes32[] multiproof; // The total number of leaves in the mmr for this proof. uint256 leafCount; } // A message for handling incoming requests struct PostRequestMessage { // proof for the requests Proof proof; // the requests, contained in a merkle tree leaf PostRequestLeaf[] requests; } // A message for handling incoming GET responses struct GetResponseMessage { // the state (merkle-patricia) proof of the get request keys bytes[] proof; // the height of the state machine proof StateMachineHeight height; // The requests that initiated this response GetRequest[] requests; } struct GetTimeoutMessage { // requests which have timed-out GetRequest[] timeouts; } struct PostTimeout { PostRequest request; } struct PostRequestTimeoutMessage { // requests which have timed-out PostRequest[] timeouts; // the height of the state machine proof StateMachineHeight height; // non-membership proof of the requests bytes[] proof; } struct PostResponseTimeoutMessage { // responses which have timed-out PostResponse[] timeouts; // the height of the state machine proof StateMachineHeight height; // non-membership proof of the requests bytes[] proof; } // A message for handling incoming responses struct PostResponseMessage { // proof for the responses Proof proof; // the responses, contained in a merkle tree leaf PostResponseLeaf[] responses; } library Message { function timeout(PostRequest memory req) internal pure returns (uint64) { if (req.timeoutTimestamp == 0) { return type(uint64).max; } else { return req.timeoutTimestamp; } } function timeout(GetRequest memory req) internal pure returns (uint64) { if (req.timeoutTimestamp == 0) { return type(uint64).max; } else { return req.timeoutTimestamp; } } function timeout(PostResponse memory res) internal pure returns (uint64) { if (res.timeoutTimestamp == 0) { return type(uint64).max; } else { return res.timeoutTimestamp; } } function encodeRequest(PostRequest memory req) internal pure returns (bytes memory) { return abi.encodePacked( req.source, req.dest, req.nonce, req.timeoutTimestamp, req.from, req.to, req.body, req.gaslimit ); } function hash(PostResponse memory res) internal pure returns (bytes32) { return keccak256( bytes.concat(encodeRequest(res.request), abi.encodePacked(res.response, res.timeoutTimestamp, res.gaslimit)) ); } function hash(PostRequest memory req) internal pure returns (bytes32) { return keccak256(encodeRequest(req)); } function hash(GetRequest memory req) internal pure returns (bytes32) { bytes memory keysEncoding = bytes(""); uint256 len = req.keys.length; for (uint256 i = 0; i < len; i++) { keysEncoding = bytes.concat(keysEncoding, req.keys[i]); } return keccak256( abi.encodePacked( req.source, req.dest, req.nonce, req.height, req.timeoutTimestamp, req.from, keysEncoding, req.gaslimit ) ); } function hash(GetResponse memory res) internal pure returns (bytes32) { return hash(res.request); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; import "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
pragma solidity ^0.8.17; // SPDX-License-Identifier: Apache2 library Memory { uint256 internal constant WORD_SIZE = 32; // Compares the 'len' bytes starting at address 'addr' in memory with the 'len' // bytes starting at 'addr2'. // Returns 'true' if the bytes are the same, otherwise 'false'. function equals(uint256 addr, uint256 addr2, uint256 len) internal pure returns (bool equal) { assembly { equal := eq(keccak256(addr, len), keccak256(addr2, len)) } } // Compares the 'len' bytes starting at address 'addr' in memory with the bytes stored in // 'bts'. It is allowed to set 'len' to a lower value then 'bts.length', in which case only // the first 'len' bytes will be compared. // Requires that 'bts.length >= len' function equals(uint256 addr, uint256 len, bytes memory bts) internal pure returns (bool equal) { require(bts.length >= len); uint256 addr2; assembly { addr2 := add(bts, /*BYTES_HEADER_SIZE*/ 32) } return equals(addr, addr2, len); } // Returns a memory pointer to the data portion of the provided bytes array. function dataPtr(bytes memory bts) internal pure returns (uint256 addr) { assembly { addr := add(bts, /*BYTES_HEADER_SIZE*/ 32) } } // Creates a 'bytes memory' variable from the memory address 'addr', with the // length 'len'. The function will allocate new memory for the bytes array, and // the 'len bytes starting at 'addr' will be copied into that new memory. function toBytes(uint256 addr, uint256 len) internal pure returns (bytes memory bts) { bts = new bytes(len); uint256 btsptr; assembly { btsptr := add(bts, /*BYTES_HEADER_SIZE*/ 32) } copy(addr, btsptr, len); } // Copies 'self' into a new 'bytes memory'. // Returns the newly created 'bytes memory' // The returned bytes will be of length '32'. function toBytes(bytes32 self) internal pure returns (bytes memory bts) { bts = new bytes(32); assembly { mstore(add(bts, /*BYTES_HEADER_SIZE*/ 32), self) } } // Copy 'len' bytes from memory address 'src', to address 'dest'. // This function does not check the or destination, it only copies // the bytes. function copy(uint256 src, uint256 dest, uint256 len) internal pure { // Copy word-length chunks while possible for (; len >= WORD_SIZE; len -= WORD_SIZE) { assembly { mstore(dest, mload(src)) } dest += WORD_SIZE; src += WORD_SIZE; } // Copy remaining bytes uint256 mask = len == 0 ? 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff : 256 ** (WORD_SIZE - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } } // This function does the same as 'dataPtr(bytes memory)', but will also return the // length of the provided bytes array. function fromBytes(bytes memory bts) internal pure returns (uint256 addr, uint256 len) { len = bts.length; assembly { addr := add(bts, /*BYTES_HEADER_SIZE*/ 32) } } }
pragma solidity ^0.8.17; import "./trie/Node.sol"; import "./trie/Option.sol"; import "./trie/NibbleSlice.sol"; import "./trie/TrieDB.sol"; import "./trie/substrate/SubstrateTrieDB.sol"; import "./trie/ethereum/EthereumTrieDB.sol"; // SPDX-License-Identifier: Apache2 // Outcome of a successfully verified merkle-patricia proof struct StorageValue { // the storage key bytes key; // the encoded value bytes value; } /** * @title A Merkle Patricia library * @author Polytope Labs * @dev Use this library to verify merkle patricia proofs * @dev refer to research for more info. https://research.polytope.technology/state-(machine)-proofs */ library MerklePatricia { /// @notice libraries in solidity can only have constant variables /// @dev MAX_TRIE_DEPTH, we don't explore deeply nested trie keys. uint256 internal constant MAX_TRIE_DEPTH = 50; /** * @notice Verifies substrate specific merkle patricia proofs. * @param root hash of the merkle patricia trie * @param proof a list of proof nodes * @param keys a list of keys to verify * @return bytes[] a list of values corresponding to the supplied keys. */ function VerifySubstrateProof(bytes32 root, bytes[] memory proof, bytes[] memory keys) public pure returns (StorageValue[] memory) { StorageValue[] memory values = new StorageValue[](keys.length); TrieNode[] memory nodes = new TrieNode[](proof.length); for (uint256 i = 0; i < proof.length; i++) { nodes[i] = TrieNode(keccak256(proof[i]), proof[i]); } for (uint256 i = 0; i < keys.length; i++) { values[i].key = keys[i]; NibbleSlice memory keyNibbles = NibbleSlice(keys[i], 0); NodeKind memory node = SubstrateTrieDB.decodeNodeKind(TrieDB.get(nodes, root)); // worst case scenario, so we avoid unbounded loops for (uint256 j = 0; j < MAX_TRIE_DEPTH; j++) { NodeHandle memory nextNode; if (TrieDB.isLeaf(node)) { Leaf memory leaf = SubstrateTrieDB.decodeLeaf(node); if (NibbleSliceOps.eq(leaf.key, keyNibbles)) { values[i].value = TrieDB.load(nodes, leaf.value); } break; } else if (TrieDB.isNibbledBranch(node)) { NibbledBranch memory nibbled = SubstrateTrieDB.decodeNibbledBranch(node); uint256 nibbledBranchKeyLength = NibbleSliceOps.len(nibbled.key); if (!NibbleSliceOps.startsWith(keyNibbles, nibbled.key)) { break; } if (NibbleSliceOps.len(keyNibbles) == nibbledBranchKeyLength) { if (Option.isSome(nibbled.value)) { values[i].value = TrieDB.load(nodes, nibbled.value.value); } break; } else { uint256 index = NibbleSliceOps.at(keyNibbles, nibbledBranchKeyLength); NodeHandleOption memory handle = nibbled.children[index]; if (Option.isSome(handle)) { keyNibbles = NibbleSliceOps.mid(keyNibbles, nibbledBranchKeyLength + 1); nextNode = handle.value; } else { break; } } } else if (TrieDB.isEmpty(node)) { break; } node = SubstrateTrieDB.decodeNodeKind(TrieDB.load(nodes, nextNode)); } } return values; } /** * @notice Verify child trie keys * @dev substrate specific method in order to verify keys in the child trie. * @param root hash of the merkle root * @param proof a list of proof nodes * @param keys a list of keys to verify * @param childInfo data that can be used to compute the root of the child trie * @return bytes[], a list of values corresponding to the supplied keys. */ function ReadChildProofCheck(bytes32 root, bytes[] memory proof, bytes[] memory keys, bytes memory childInfo) public pure returns (StorageValue[] memory) { // fetch the child trie root hash; bytes memory prefix = bytes(":child_storage:default:"); bytes memory key = bytes.concat(prefix, childInfo); bytes[] memory _keys = new bytes[](1); _keys[0] = key; StorageValue[] memory values = VerifySubstrateProof(root, proof, _keys); bytes32 childRoot = bytes32(values[0].value); require(childRoot != bytes32(0), "Invalid child trie proof"); return VerifySubstrateProof(childRoot, proof, keys); } /** * @notice Verifies ethereum specific merkle patricia proofs as described by EIP-1188. * @param root hash of the merkle patricia trie * @param proof a list of proof nodes * @param keys a list of keys to verify * @return bytes[] a list of values corresponding to the supplied keys. */ function VerifyEthereumProof(bytes32 root, bytes[] memory proof, bytes[] memory keys) public pure returns (StorageValue[] memory) { StorageValue[] memory values = new StorageValue[](keys.length); TrieNode[] memory nodes = new TrieNode[](proof.length); for (uint256 i = 0; i < proof.length; i++) { nodes[i] = TrieNode(keccak256(proof[i]), proof[i]); } for (uint256 i = 0; i < keys.length; i++) { values[i].key = keys[i]; NibbleSlice memory keyNibbles = NibbleSlice(keys[i], 0); NodeKind memory node = EthereumTrieDB.decodeNodeKind(TrieDB.get(nodes, root)); // worst case scenario, so we avoid unbounded loops for (uint256 j = 0; j < MAX_TRIE_DEPTH; j++) { NodeHandle memory nextNode; if (TrieDB.isLeaf(node)) { Leaf memory leaf = EthereumTrieDB.decodeLeaf(node); // Let's retrieve the offset to be used uint256 offset = keyNibbles.offset % 2 == 0 ? keyNibbles.offset / 2 : keyNibbles.offset / 2 + 1; // Let's cut the key passed as input keyNibbles = NibbleSlice(NibbleSliceOps.bytesSlice(keyNibbles.data, offset), 0); if (NibbleSliceOps.eq(leaf.key, keyNibbles)) { values[i].value = TrieDB.load(nodes, leaf.value); } break; } else if (TrieDB.isExtension(node)) { Extension memory extension = EthereumTrieDB.decodeExtension(node); if (NibbleSliceOps.startsWith(keyNibbles, extension.key)) { // Let's cut the key passed as input keyNibbles = NibbleSlice( NibbleSliceOps.bytesSlice(keyNibbles.data, NibbleSliceOps.len(extension.key)), 0 ); nextNode = extension.node; } else { break; } } else if (TrieDB.isBranch(node)) { Branch memory branch = EthereumTrieDB.decodeBranch(node); if (NibbleSliceOps.isEmpty(keyNibbles)) { if (Option.isSome(branch.value)) { values[i].value = TrieDB.load(nodes, branch.value.value); } break; } else { NodeHandleOption memory handle = branch.children[NibbleSliceOps.at(keyNibbles, 0)]; if (Option.isSome(handle)) { keyNibbles = NibbleSliceOps.mid(keyNibbles, 1); nextNode = handle.value; } else { break; } } } else if (TrieDB.isEmpty(node)) { break; } node = EthereumTrieDB.decodeNodeKind(TrieDB.load(nodes, nextNode)); } } return values; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
pragma solidity ^0.8.17; // SPDX-License-Identifier: Apache2 import "./NibbleSlice.sol"; import "./Bytes.sol"; /// This is an enum for the different node types. struct NodeKind { bool isEmpty; bool isLeaf; bool isHashedLeaf; bool isNibbledValueBranch; bool isNibbledHashedValueBranch; bool isNibbledBranch; bool isExtension; bool isBranch; uint256 nibbleSize; ByteSlice data; } struct NodeHandle { bool isHash; bytes32 hash; bool isInline; bytes inLine; } struct Extension { NibbleSlice key; NodeHandle node; } struct Branch { NodeHandleOption value; NodeHandleOption[16] children; } struct NibbledBranch { NibbleSlice key; NodeHandleOption value; NodeHandleOption[16] children; } struct ValueOption { bool isSome; bytes value; } struct NodeHandleOption { bool isSome; NodeHandle value; } struct Leaf { NibbleSlice key; NodeHandle value; } struct TrieNode { bytes32 hash; bytes node; }
pragma solidity ^0.8.17; import "./Node.sol"; // SPDX-License-Identifier: Apache2 library Option { function isSome(ValueOption memory val) internal pure returns (bool) { return val.isSome == true; } function isSome(NodeHandleOption memory val) internal pure returns (bool) { return val.isSome == true; } }
pragma solidity ^0.8.17; // SPDX-License-Identifier: Apache2 struct NibbleSlice { bytes data; uint256 offset; } library NibbleSliceOps { uint256 internal constant NIBBLE_PER_BYTE = 2; uint256 internal constant BITS_PER_NIBBLE = 4; function len(NibbleSlice memory nibble) internal pure returns (uint256) { return nibble.data.length * NIBBLE_PER_BYTE - nibble.offset; } function mid(NibbleSlice memory self, uint256 i) internal pure returns (NibbleSlice memory) { return NibbleSlice(self.data, self.offset + i); } function isEmpty(NibbleSlice memory self) internal pure returns (bool) { return len(self) == 0; } function eq(NibbleSlice memory self, NibbleSlice memory other) internal pure returns (bool) { return len(self) == len(other) && startsWith(self, other); } function at(NibbleSlice memory self, uint256 i) internal pure returns (uint256) { uint256 ix = (self.offset + i) / NIBBLE_PER_BYTE; uint256 pad = (self.offset + i) % NIBBLE_PER_BYTE; uint8 data = uint8(self.data[ix]); return (pad == 1) ? data & 0x0F : data >> BITS_PER_NIBBLE; } function startsWith(NibbleSlice memory self, NibbleSlice memory other) internal pure returns (bool) { return commonPrefix(self, other) == len(other); } function commonPrefix(NibbleSlice memory self, NibbleSlice memory other) internal pure returns (uint256) { uint256 self_align = self.offset % NIBBLE_PER_BYTE; uint256 other_align = other.offset % NIBBLE_PER_BYTE; if (self_align == other_align) { uint256 self_start = self.offset / NIBBLE_PER_BYTE; uint256 other_start = other.offset / NIBBLE_PER_BYTE; uint256 first = 0; if (self_align != 0) { if ((self.data[self_start] & 0x0F) != (other.data[other_start] & 0x0F)) { return 0; } ++self_start; ++other_start; ++first; } bytes memory selfSlice = bytesSlice(self.data, self_start); bytes memory otherSlice = bytesSlice(other.data, other_start); return biggestDepth(selfSlice, otherSlice) + first; } else { uint256 s = min(len(self), len(other)); uint256 i = 0; while (i < s) { if (at(self, i) != at(other, i)) { break; } ++i; } return i; } } function biggestDepth(bytes memory a, bytes memory b) internal pure returns (uint256) { uint256 upperBound = min(a.length, b.length); uint256 i = 0; while (i < upperBound) { if (a[i] != b[i]) { return i * NIBBLE_PER_BYTE + leftCommon(a[i], b[i]); } ++i; } return i * NIBBLE_PER_BYTE; } function leftCommon(bytes1 a, bytes1 b) internal pure returns (uint256) { if (a == b) { return 2; } else if (uint8(a) & 0xF0 == uint8(b) & 0xF0) { return 1; } else { return 0; } } function bytesSlice(bytes memory _bytes, uint256 _start) internal pure returns (bytes memory) { uint256 bytesLength = _bytes.length; uint256 _length = bytesLength - _start; require(bytesLength >= _start, "slice_outOfBounds"); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { tempBytes := mload(0x40) // load free memory pointer let lengthmod := and(_length, 31) let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) mstore(0x40, and(add(mc, 31), not(31))) } default { tempBytes := mload(0x40) mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function min(uint256 a, uint256 b) private pure returns (uint256) { return (a < b) ? a : b; } }
// SPDX-License-Identifier: Apache2 pragma solidity ^0.8.17; import "./Node.sol"; library TrieDB { function get(TrieNode[] memory nodes, bytes32 hash) internal pure returns (bytes memory) { for (uint256 i = 0; i < nodes.length; i++) { if (nodes[i].hash == hash) { return nodes[i].node; } } revert("Incomplete Proof!"); } function load(TrieNode[] memory nodes, NodeHandle memory node) internal pure returns (bytes memory) { if (node.isInline) { return node.inLine; } else if (node.isHash) { return get(nodes, node.hash); } return bytes(""); } function isNibbledBranch(NodeKind memory node) internal pure returns (bool) { return (node.isNibbledBranch || node.isNibbledHashedValueBranch || node.isNibbledValueBranch); } function isExtension(NodeKind memory node) internal pure returns (bool) { return node.isExtension; } function isBranch(NodeKind memory node) internal pure returns (bool) { return node.isBranch; } function isLeaf(NodeKind memory node) internal pure returns (bool) { return (node.isLeaf || node.isHashedLeaf); } function isEmpty(NodeKind memory node) internal pure returns (bool) { return node.isEmpty; } function isHash(NodeHandle memory node) internal pure returns (bool) { return node.isHash; } function isInline(NodeHandle memory node) internal pure returns (bool) { return node.isInline; } }
pragma solidity ^0.8.17; import "../Node.sol"; import "../Bytes.sol"; import {NibbleSliceOps} from "../NibbleSlice.sol"; import {ScaleCodec} from "./ScaleCodec.sol"; import "openzeppelin/utils/Strings.sol"; // SPDX-License-Identifier: Apache2 library SubstrateTrieDB { uint8 public constant FIRST_PREFIX = 0x00 << 6; uint8 public constant PADDING_BITMASK = 0x0F; uint8 public constant EMPTY_TRIE = FIRST_PREFIX | (0x00 << 4); uint8 public constant LEAF_PREFIX_MASK = 0x01 << 6; uint8 public constant BRANCH_WITH_MASK = 0x03 << 6; uint8 public constant BRANCH_WITHOUT_MASK = 0x02 << 6; uint8 public constant ALT_HASHING_LEAF_PREFIX_MASK = FIRST_PREFIX | (0x01 << 5); uint8 public constant ALT_HASHING_BRANCH_WITH_MASK = FIRST_PREFIX | (0x01 << 4); uint8 public constant NIBBLE_PER_BYTE = 2; uint256 public constant NIBBLE_SIZE_BOUND = uint256(type(uint16).max); uint256 public constant BITMAP_LENGTH = 2; uint256 public constant HASH_lENGTH = 32; function decodeNodeKind(bytes memory encoded) internal pure returns (NodeKind memory) { NodeKind memory node; ByteSlice memory input = ByteSlice(encoded, 0); uint8 i = Bytes.readByte(input); if (i == EMPTY_TRIE) { node.isEmpty = true; return node; } uint8 mask = i & (0x03 << 6); if (mask == LEAF_PREFIX_MASK) { node.nibbleSize = decodeSize(i, input, 2); node.isLeaf = true; } else if (mask == BRANCH_WITH_MASK) { node.nibbleSize = decodeSize(i, input, 2); node.isNibbledValueBranch = true; } else if (mask == BRANCH_WITHOUT_MASK) { node.nibbleSize = decodeSize(i, input, 2); node.isNibbledBranch = true; } else if (mask == EMPTY_TRIE) { if (i & (0x07 << 5) == ALT_HASHING_LEAF_PREFIX_MASK) { node.nibbleSize = decodeSize(i, input, 3); node.isHashedLeaf = true; } else if (i & (0x0F << 4) == ALT_HASHING_BRANCH_WITH_MASK) { node.nibbleSize = decodeSize(i, input, 4); node.isNibbledHashedValueBranch = true; } else { // do not allow any special encoding revert("Unallowed encoding"); } } node.data = input; return node; } function decodeNibbledBranch(NodeKind memory node) internal pure returns (NibbledBranch memory) { NibbledBranch memory nibbledBranch; ByteSlice memory input = node.data; bool padding = node.nibbleSize % NIBBLE_PER_BYTE != 0; if (padding && (padLeft(uint8(input.data[input.offset])) != 0)) { revert("Bad Format!"); } uint256 nibbleLen = ((node.nibbleSize + (NibbleSliceOps.NIBBLE_PER_BYTE - 1)) / NibbleSliceOps.NIBBLE_PER_BYTE); nibbledBranch.key = NibbleSlice(Bytes.read(input, nibbleLen), node.nibbleSize % NIBBLE_PER_BYTE); bytes memory bitmapBytes = Bytes.read(input, BITMAP_LENGTH); uint16 bitmap = uint16(ScaleCodec.decodeUint256(bitmapBytes)); NodeHandleOption memory valueHandle; if (node.isNibbledHashedValueBranch) { valueHandle.isSome = true; valueHandle.value.isHash = true; valueHandle.value.hash = Bytes.toBytes32(Bytes.read(input, HASH_lENGTH)); } else if (node.isNibbledValueBranch) { uint256 len = ScaleCodec.decodeUintCompact(input); valueHandle.isSome = true; valueHandle.value.isInline = true; valueHandle.value.inLine = Bytes.read(input, len); } nibbledBranch.value = valueHandle; for (uint256 i = 0; i < 16; i++) { NodeHandleOption memory childHandle; if (valueAt(bitmap, i)) { childHandle.isSome = true; uint256 len = ScaleCodec.decodeUintCompact(input); // revert(string.concat("node index: ", Strings.toString(len))); if (len == HASH_lENGTH) { childHandle.value.isHash = true; childHandle.value.hash = Bytes.toBytes32(Bytes.read(input, HASH_lENGTH)); } else { childHandle.value.isInline = true; childHandle.value.inLine = Bytes.read(input, len); } } nibbledBranch.children[i] = childHandle; } return nibbledBranch; } function decodeLeaf(NodeKind memory node) internal pure returns (Leaf memory) { Leaf memory leaf; ByteSlice memory input = node.data; bool padding = node.nibbleSize % NIBBLE_PER_BYTE != 0; if (padding && padLeft(uint8(input.data[input.offset])) != 0) { revert("Bad Format!"); } uint256 nibbleLen = (node.nibbleSize + (NibbleSliceOps.NIBBLE_PER_BYTE - 1)) / NibbleSliceOps.NIBBLE_PER_BYTE; bytes memory nibbleBytes = Bytes.read(input, nibbleLen); leaf.key = NibbleSlice(nibbleBytes, node.nibbleSize % NIBBLE_PER_BYTE); NodeHandle memory handle; if (node.isHashedLeaf) { handle.isHash = true; handle.hash = Bytes.toBytes32(Bytes.read(input, HASH_lENGTH)); } else { uint256 len = ScaleCodec.decodeUintCompact(input); handle.isInline = true; handle.inLine = Bytes.read(input, len); } leaf.value = handle; return leaf; } function decodeSize(uint8 first, ByteSlice memory encoded, uint8 prefixMask) internal pure returns (uint256) { uint8 maxValue = uint8(255 >> prefixMask); uint256 result = uint256(first & maxValue); if (result < maxValue) { return result; } result -= 1; while (result <= NIBBLE_SIZE_BOUND) { uint256 n = uint256(Bytes.readByte(encoded)); if (n < 255) { return result + n + 1; } result += 255; } return NIBBLE_SIZE_BOUND; } function padLeft(uint8 b) internal pure returns (uint8) { return b & ~PADDING_BITMASK; } function valueAt(uint16 bitmap, uint256 i) internal pure returns (bool) { return bitmap & (uint16(1) << uint16(i)) != 0; } }
pragma solidity ^0.8.17; import "../Node.sol"; import "../Bytes.sol"; import {NibbleSliceOps} from "../NibbleSlice.sol"; import "./RLPReader.sol"; // SPDX-License-Identifier: Apache2 library EthereumTrieDB { using RLPReader for bytes; using RLPReader for RLPReader.RLPItem; using RLPReader for RLPReader.Iterator; bytes constant HASHED_NULL_NODE = hex"56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"; function decodeNodeKind(bytes memory encoded) external pure returns (NodeKind memory) { NodeKind memory node; ByteSlice memory input = ByteSlice(encoded, 0); if (Bytes.equals(encoded, HASHED_NULL_NODE)) { node.isEmpty = true; return node; } RLPReader.RLPItem[] memory itemList = encoded.toRlpItem().toList(); uint256 numItems = itemList.length; if (numItems == 0) { node.isEmpty = true; return node; } else if (numItems == 2) { //It may be a leaf or extension bytes memory key = itemList[0].toBytes(); uint256 prefix; assembly { let first := shr(248, mload(add(key, 32))) prefix := shr(4, first) } if (prefix == 2 || prefix == 3) { node.isLeaf = true; } else { node.isExtension = true; } } else if (numItems == 17) { node.isBranch = true; } else { revert("Invalid data"); } node.data = input; return node; } function decodeLeaf(NodeKind memory node) external pure returns (Leaf memory) { Leaf memory leaf; RLPReader.RLPItem[] memory decoded = node.data.data.toRlpItem().toList(); bytes memory data = decoded[1].toBytes(); //Remove the first byte, which is the prefix and not present in the user provided key leaf.key = NibbleSlice(Bytes.substr(decoded[0].toBytes(), 1), 0); leaf.value = NodeHandle(false, bytes32(0), true, data); return leaf; } function decodeExtension(NodeKind memory node) external pure returns (Extension memory) { Extension memory extension; RLPReader.RLPItem[] memory decoded = node.data.data.toRlpItem().toList(); bytes memory data = decoded[1].toBytes(); //Remove the first byte, which is the prefix and not present in the user provided key extension.key = NibbleSlice(Bytes.substr(decoded[0].toBytes(), 1), 0); extension.node = NodeHandle(true, Bytes.toBytes32(data), false, new bytes(0)); return extension; } function decodeBranch(NodeKind memory node) external pure returns (Branch memory) { Branch memory branch; RLPReader.RLPItem[] memory decoded = node.data.data.toRlpItem().toList(); NodeHandleOption[16] memory childrens; for (uint256 i = 0; i < 16; i++) { bytes memory dataAsBytes = decoded[i].toBytes(); if (dataAsBytes.length != 32) { childrens[i] = NodeHandleOption(false, NodeHandle(false, bytes32(0), false, new bytes(0))); } else { bytes32 data = Bytes.toBytes32(dataAsBytes); childrens[i] = NodeHandleOption(true, NodeHandle(true, data, false, new bytes(0))); } } if (isEmpty(decoded[16].toBytes())) { branch.value = NodeHandleOption(false, NodeHandle(false, bytes32(0), false, new bytes(0))); } else { branch.value = NodeHandleOption(true, NodeHandle(false, bytes32(0), true, decoded[16].toBytes())); } branch.children = childrens; return branch; } function isEmpty(bytes memory item) internal pure returns (bool) { return item.length > 0 && (item[0] == 0xc0 || item[0] == 0x80); } }
pragma solidity ^0.8.17; // SPDX-License-Identifier: Apache2 import {Bytes, ByteSlice} from "../Bytes.sol"; library ScaleCodec { // Decodes a SCALE encoded uint256 by converting bytes (bid endian) to little endian format function decodeUint256(bytes memory data) internal pure returns (uint256) { uint256 number; for (uint256 i = data.length; i > 0; i--) { number = number + uint256(uint8(data[i - 1])) * (2 ** (8 * (i - 1))); } return number; } // Decodes a SCALE encoded compact unsigned integer function decodeUintCompact(ByteSlice memory data) internal pure returns (uint256 v) { uint8 b = Bytes.readByte(data); // read the first byte uint8 mode = b % 4; // bitwise operation uint256 value; if (mode == 0) { // [0, 63] value = b >> 2; // right shift to remove mode bits } else if (mode == 1) { // [64, 16383] uint8 bb = Bytes.readByte(data); // read the second byte uint64 r = bb; // convert to uint64 r <<= 6; // multiply by * 2^6 r += b >> 2; // right shift to remove mode bits value = r; } else if (mode == 2) { // [16384, 1073741823] uint8 b2 = Bytes.readByte(data); // read the next 3 bytes uint8 b3 = Bytes.readByte(data); uint8 b4 = Bytes.readByte(data); uint32 x1 = uint32(b) | (uint32(b2) << 8); // convert to little endian uint32 x2 = x1 | (uint32(b3) << 16); uint32 x3 = x2 | (uint32(b4) << 24); x3 >>= 2; // remove the last 2 mode bits value = uint256(x3); } else if (mode == 3) { // [1073741824, 4503599627370496] uint8 l = (b >> 2) + 4; // remove mode bits require(l <= 8, "unexpected prefix decoding Compact<Uint>"); return decodeUint256(Bytes.read(data, l)); } else { revert("Code should be unreachable"); } return value; } // Decodes a SCALE encoded compact unsigned integer function decodeUintCompact(bytes memory data) internal pure returns (uint256 v, uint8 m) { uint8 b = readByteAtIndex(data, 0); // read the first byte uint8 mode = b & 3; // bitwise operation uint256 value; if (mode == 0) { // [0, 63] value = b >> 2; // right shift to remove mode bits } else if (mode == 1) { // [64, 16383] uint8 bb = readByteAtIndex(data, 1); // read the second byte uint64 r = bb; // convert to uint64 r <<= 6; // multiply by * 2^6 r += b >> 2; // right shift to remove mode bits value = r; } else if (mode == 2) { // [16384, 1073741823] uint8 b2 = readByteAtIndex(data, 1); // read the next 3 bytes uint8 b3 = readByteAtIndex(data, 2); uint8 b4 = readByteAtIndex(data, 3); uint32 x1 = uint32(b) | (uint32(b2) << 8); // convert to little endian uint32 x2 = x1 | (uint32(b3) << 16); uint32 x3 = x2 | (uint32(b4) << 24); x3 >>= 2; // remove the last 2 mode bits value = uint256(x3); } else if (mode == 3) { // [1073741824, 4503599627370496] uint8 l = b >> 2; // remove mode bits require(l > 32, "Not supported: number cannot be greater than 32 bytes"); } else { revert("Code should be unreachable"); } return (value, mode); } // The biggest compact supported uint is 2 ** 536 - 1. // But the biggest value supported by this method is 2 ** 256 - 1(max of uint256) function encodeUintCompact(uint256 v) internal pure returns (bytes memory) { if (v < 64) { return abi.encodePacked(uint8(v << 2)); } else if (v < 2 ** 14) { return abi.encodePacked(reverse16(uint16(((v << 2) + 1)))); } else if (v < 2 ** 30) { return abi.encodePacked(reverse32(uint32(((v << 2) + 2)))); } else { bytes memory valueBytes = Bytes.removeEndingZero(abi.encodePacked(reverse256(v))); uint256 length = valueBytes.length; uint8 prefix = uint8(((length - 4) << 2) + 3); return abi.encodePacked(prefix, valueBytes); } } // Read a byte at a specific index and return it as type uint8 function readByteAtIndex(bytes memory data, uint8 index) internal pure returns (uint8) { return uint8(data[index]); } // Sources: // * https://ethereum.stackexchange.com/questions/15350/how-to-convert-an-bytes-to-address-in-solidity/50528 // * https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel function reverse256(uint256 input) internal pure returns (uint256 v) { v = input; // swap bytes v = ((v & 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8); // swap 2-byte long pairs v = ((v & 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16); // swap 4-byte long pairs v = ((v & 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000) >> 32) | ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32); // swap 8-byte long pairs v = ((v & 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000) >> 64) | ((v & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) << 64); // swap 16-byte long pairs v = (v >> 128) | (v << 128); } function reverse128(uint128 input) internal pure returns (uint128 v) { v = input; // swap bytes v = ((v & 0xFF00FF00FF00FF00FF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF) << 8); // swap 2-byte long pairs v = ((v & 0xFFFF0000FFFF0000FFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF) << 16); // swap 4-byte long pairs v = ((v & 0xFFFFFFFF00000000FFFFFFFF00000000) >> 32) | ((v & 0x00000000FFFFFFFF00000000FFFFFFFF) << 32); // swap 8-byte long pairs v = (v >> 64) | (v << 64); } function reverse64(uint64 input) internal pure returns (uint64 v) { v = input; // swap bytes v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8); // swap 2-byte long pairs v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16); // swap 4-byte long pairs v = (v >> 32) | (v << 32); } function reverse32(uint32 input) internal pure returns (uint32 v) { v = input; // swap bytes v = ((v & 0xFF00FF00) >> 8) | ((v & 0x00FF00FF) << 8); // swap 2-byte long pairs v = (v >> 16) | (v << 16); } function reverse16(uint16 input) internal pure returns (uint16 v) { v = input; // swap bytes v = (v >> 8) | (v << 8); } function encode256(uint256 input) internal pure returns (bytes32) { return bytes32(reverse256(input)); } function encode128(uint128 input) internal pure returns (bytes16) { return bytes16(reverse128(input)); } function encode64(uint64 input) internal pure returns (bytes8) { return bytes8(reverse64(input)); } function encode32(uint32 input) internal pure returns (bytes4) { return bytes4(reverse32(input)); } function encode16(uint16 input) internal pure returns (bytes2) { return bytes2(reverse16(input)); } function encodeBytes(bytes memory input) internal pure returns (bytes memory) { return abi.encodePacked(encodeUintCompact(input.length), input); } }
// SPDX-License-Identifier: Apache-2.0 /* * @author Hamdi Allam [email protected] * Please reach out with any questions or concerns */ pragma solidity >=0.5.10 <0.9.0; library RLPReader { uint8 constant STRING_SHORT_START = 0x80; uint8 constant STRING_LONG_START = 0xb8; uint8 constant LIST_SHORT_START = 0xc0; uint8 constant LIST_LONG_START = 0xf8; uint8 constant WORD_SIZE = 32; struct RLPItem { uint256 len; uint256 memPtr; } struct Iterator { RLPItem item; // Item that's being iterated over. uint256 nextPtr; // Position of the next item in the list. } /* * @dev Returns the next element in the iteration. Reverts if it has not next element. * @param self The iterator. * @return The next element in the iteration. */ function next(Iterator memory self) internal pure returns (RLPItem memory) { require(hasNext(self)); uint256 ptr = self.nextPtr; uint256 itemLength = _itemLength(ptr); self.nextPtr = ptr + itemLength; return RLPItem(itemLength, ptr); } /* * @dev Returns true if the iteration has more elements. * @param self The iterator. * @return true if the iteration has more elements. */ function hasNext(Iterator memory self) internal pure returns (bool) { RLPItem memory item = self.item; return self.nextPtr < item.memPtr + item.len; } /* * @param item RLP encoded bytes */ function toRlpItem(bytes memory item) internal pure returns (RLPItem memory) { uint256 memPtr; assembly { memPtr := add(item, 0x20) } return RLPItem(item.length, memPtr); } /* * @dev Create an iterator. Reverts if item is not a list. * @param self The RLP item. * @return An 'Iterator' over the item. */ function iterator(RLPItem memory self) internal pure returns (Iterator memory) { require(isList(self)); uint256 ptr = self.memPtr + _payloadOffset(self.memPtr); return Iterator(self, ptr); } /* * @param the RLP item. */ function rlpLen(RLPItem memory item) internal pure returns (uint256) { return item.len; } /* * @param the RLP item. * @return (memPtr, len) pair: location of the item's payload in memory. */ function payloadLocation(RLPItem memory item) internal pure returns (uint256, uint256) { uint256 offset = _payloadOffset(item.memPtr); uint256 memPtr = item.memPtr + offset; uint256 len = item.len - offset; // data length return (memPtr, len); } /* * @param the RLP item. */ function payloadLen(RLPItem memory item) internal pure returns (uint256) { (, uint256 len) = payloadLocation(item); return len; } /* * @param the RLP item containing the encoded list. */ function toList(RLPItem memory item) internal pure returns (RLPItem[] memory) { require(isList(item)); uint256 items = numItems(item); RLPItem[] memory result = new RLPItem[](items); uint256 memPtr = item.memPtr + _payloadOffset(item.memPtr); uint256 dataLen; for (uint256 i = 0; i < items; i++) { dataLen = _itemLength(memPtr); result[i] = RLPItem(dataLen, memPtr); memPtr = memPtr + dataLen; } return result; } // @return indicator whether encoded payload is a list. negate this function call for isData. function isList(RLPItem memory item) internal pure returns (bool) { if (item.len == 0) return false; uint8 byte0; uint256 memPtr = item.memPtr; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < LIST_SHORT_START) return false; return true; } /* * @dev A cheaper version of keccak256(toRlpBytes(item)) that avoids copying memory. * @return keccak256 hash of RLP encoded bytes. */ function rlpBytesKeccak256(RLPItem memory item) internal pure returns (bytes32) { uint256 ptr = item.memPtr; uint256 len = item.len; bytes32 result; assembly { result := keccak256(ptr, len) } return result; } /* * @dev A cheaper version of keccak256(toBytes(item)) that avoids copying memory. * @return keccak256 hash of the item payload. */ function payloadKeccak256(RLPItem memory item) internal pure returns (bytes32) { (uint256 memPtr, uint256 len) = payloadLocation(item); bytes32 result; assembly { result := keccak256(memPtr, len) } return result; } /** * RLPItem conversions into data types * */ // @returns raw rlp encoding in bytes function toRlpBytes(RLPItem memory item) internal pure returns (bytes memory) { bytes memory result = new bytes(item.len); if (result.length == 0) return result; uint256 ptr; assembly { ptr := add(0x20, result) } copy(item.memPtr, ptr, item.len); return result; } // any non-zero byte except "0x80" is considered true function toBoolean(RLPItem memory item) internal pure returns (bool) { require(item.len == 1); uint256 result; uint256 memPtr = item.memPtr; assembly { result := byte(0, mload(memPtr)) } // SEE Github Issue #5. // Summary: Most commonly used RLP libraries (i.e Geth) will encode // "0" as "0x80" instead of as "0". We handle this edge case explicitly // here. if (result == 0 || result == STRING_SHORT_START) { return false; } else { return true; } } function toAddress(RLPItem memory item) internal pure returns (address) { // 1 byte for the length prefix require(item.len == 21); return address(uint160(toUint(item))); } function toUint(RLPItem memory item) internal pure returns (uint256) { require(item.len > 0 && item.len <= 33); (uint256 memPtr, uint256 len) = payloadLocation(item); uint256 result; assembly { result := mload(memPtr) // shift to the correct location if neccesary if lt(len, 32) { result := div(result, exp(256, sub(32, len))) } } return result; } // enforces 32 byte length function toUintStrict(RLPItem memory item) internal pure returns (uint256) { // one byte prefix require(item.len == 33); uint256 result; uint256 memPtr = item.memPtr + 1; assembly { result := mload(memPtr) } return result; } function toBytes(RLPItem memory item) internal pure returns (bytes memory) { require(item.len > 0); (uint256 memPtr, uint256 len) = payloadLocation(item); bytes memory result = new bytes(len); uint256 destPtr; assembly { destPtr := add(0x20, result) } copy(memPtr, destPtr, len); return result; } /* * Private Helpers */ // @return number of payload items inside an encoded list. function numItems(RLPItem memory item) private pure returns (uint256) { if (item.len == 0) return 0; uint256 count = 0; uint256 currPtr = item.memPtr + _payloadOffset(item.memPtr); uint256 endPtr = item.memPtr + item.len; while (currPtr < endPtr) { currPtr = currPtr + _itemLength(currPtr); // skip over an item count++; } return count; } // @return entire rlp item byte length function _itemLength(uint256 memPtr) private pure returns (uint256) { uint256 itemLen; uint256 byte0; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < STRING_SHORT_START) { itemLen = 1; } else if (byte0 < STRING_LONG_START) { itemLen = byte0 - STRING_SHORT_START + 1; } else if (byte0 < LIST_SHORT_START) { assembly { let byteLen := sub(byte0, 0xb7) // # of bytes the actual length is memPtr := add(memPtr, 1) // skip over the first byte /* 32 byte word size */ let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to get the len itemLen := add(dataLen, add(byteLen, 1)) } } else if (byte0 < LIST_LONG_START) { itemLen = byte0 - LIST_SHORT_START + 1; } else { assembly { let byteLen := sub(byte0, 0xf7) memPtr := add(memPtr, 1) let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to the correct length itemLen := add(dataLen, add(byteLen, 1)) } } return itemLen; } // @return number of bytes until the data function _payloadOffset(uint256 memPtr) private pure returns (uint256) { uint256 byte0; assembly { byte0 := byte(0, mload(memPtr)) } if (byte0 < STRING_SHORT_START) { return 0; } else if (byte0 < STRING_LONG_START || (byte0 >= LIST_SHORT_START && byte0 < LIST_LONG_START)) { return 1; } else if (byte0 < LIST_SHORT_START) { // being explicit return byte0 - (STRING_LONG_START - 1) + 1; } else { return byte0 - (LIST_LONG_START - 1) + 1; } } /* * @param src Pointer to source * @param dest Pointer to destination * @param len Amount of memory to copy from the source */ function copy(uint256 src, uint256 dest, uint256 len) private pure { if (len == 0) return; // copy as many word sizes as possible for (; len >= WORD_SIZE; len -= WORD_SIZE) { assembly { mstore(dest, mload(src)) } src += WORD_SIZE; dest += WORD_SIZE; } if (len > 0) { // left over bytes. Mask is used to remove unwanted bytes from the word uint256 mask = 256 ** (WORD_SIZE - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) // zero out src let destpart := and(mload(dest), mask) // retrieve the bytes mstore(dest, or(destpart, srcpart)) } } } }
{ "remappings": [ "ismp/=lib/ismp-solidity/src/", "openzeppelin/=lib/openzeppelin-contracts/contracts/", "solidity-merkle-trees/=lib/solidity-merkle-trees/src/", "ERC6160/=lib/ERC6160/src/", "stringutils/=lib/solidity-stringutils/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "ismp-solidity/=lib/ismp-solidity/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "solidity-stringutils/=lib/solidity-stringutils/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "libraries": { "lib/solidity-merkle-trees/src/MerkleMountainRange.sol": { "MerkleMountainRange": "0xf9d43b6c55742d13167959c344c543854118769f" }, "lib/solidity-merkle-trees/src/MerklePatricia.sol": { "MerklePatricia": "0x699fa9669f79d103ac86d097d9965525eddea22e" }, "lib/solidity-merkle-trees/src/trie/ethereum/EthereumTrieDB.sol": { "EthereumTrieDB": "0x284003b2f5c2e6894186ae5217d8226feb31135e" } } }
[{"inputs":[{"components":[{"internalType":"uint256","name":"defaultTimeout","type":"uint256"},{"internalType":"uint256","name":"baseGetRequestFee","type":"uint256"},{"internalType":"uint256","name":"perByteFee","type":"uint256"},{"internalType":"address","name":"feeTokenAddress","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"address","name":"handler","type":"address"},{"internalType":"address","name":"hostManager","type":"address"},{"internalType":"uint256","name":"unStakingPeriod","type":"uint256"},{"internalType":"uint256","name":"challengePeriod","type":"uint256"},{"internalType":"address","name":"consensusClient","type":"address"},{"internalType":"bytes","name":"consensusState","type":"bytes"},{"internalType":"uint256","name":"lastUpdated","type":"uint256"},{"internalType":"uint256","name":"latestStateMachineHeight","type":"uint256"},{"internalType":"bytes","name":"hyperbridge","type":"bytes"}],"internalType":"struct HostParams","name":"params","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"source","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"dest","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"from","type":"bytes"},{"indexed":false,"internalType":"bytes[]","name":"keys","type":"bytes[]"},{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"height","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timeoutTimestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"gaslimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"GetRequestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"commitment","type":"bytes32"},{"indexed":false,"internalType":"address","name":"relayer","type":"address"}],"name":"GetRequestHandled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"source","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"dest","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"from","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"to","type":"bytes"},{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timeoutTimestamp","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"gaslimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"PostRequestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"commitment","type":"bytes32"},{"indexed":false,"internalType":"address","name":"relayer","type":"address"}],"name":"PostRequestHandled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"source","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"dest","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"from","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"to","type":"bytes"},{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timeoutTimestamp","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"gaslimit","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"response","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"resGaslimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"resTimeoutTimestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"PostResponseEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"commitment","type":"bytes32"},{"indexed":false,"internalType":"address","name":"relayer","type":"address"}],"name":"PostResponseHandled","type":"event"},{"inputs":[],"name":"CHAIN_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseGetRequestFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"chainId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"challengePeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"consensusClient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"consensusState","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"consensusUpdateTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dai","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"uint64","name":"height","type":"uint64"},{"internalType":"bytes[]","name":"keys","type":"bytes[]"},{"internalType":"uint64","name":"timeout","type":"uint64"},{"internalType":"uint64","name":"gaslimit","type":"uint64"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"payer","type":"address"}],"internalType":"struct DispatchGet","name":"get","type":"tuple"}],"name":"dispatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"bytes","name":"source","type":"bytes"},{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"uint64","name":"nonce","type":"uint64"},{"internalType":"bytes","name":"from","type":"bytes"},{"internalType":"bytes","name":"to","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"bytes","name":"body","type":"bytes"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct PostRequest","name":"request","type":"tuple"},{"internalType":"bytes","name":"response","type":"bytes"},{"internalType":"uint64","name":"timeout","type":"uint64"},{"internalType":"uint64","name":"gaslimit","type":"uint64"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"payer","type":"address"}],"internalType":"struct DispatchPostResponse","name":"post","type":"tuple"}],"name":"dispatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"bytes","name":"to","type":"bytes"},{"internalType":"bytes","name":"body","type":"bytes"},{"internalType":"uint64","name":"timeout","type":"uint64"},{"internalType":"uint64","name":"gaslimit","type":"uint64"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"payer","type":"address"}],"internalType":"struct DispatchPost","name":"post","type":"tuple"}],"name":"dispatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"source","type":"bytes"},{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"uint64","name":"nonce","type":"uint64"},{"internalType":"bytes","name":"from","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"bytes[]","name":"keys","type":"bytes[]"},{"internalType":"uint64","name":"height","type":"uint64"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct GetRequest","name":"request","type":"tuple"},{"components":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"sender","type":"address"}],"internalType":"struct FeeMetadata","name":"meta","type":"tuple"},{"internalType":"bytes32","name":"commitment","type":"bytes32"}],"name":"dispatchIncoming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"source","type":"bytes"},{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"uint64","name":"nonce","type":"uint64"},{"internalType":"bytes","name":"from","type":"bytes"},{"internalType":"bytes","name":"to","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"bytes","name":"body","type":"bytes"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct PostRequest","name":"request","type":"tuple"},{"components":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"sender","type":"address"}],"internalType":"struct FeeMetadata","name":"meta","type":"tuple"},{"internalType":"bytes32","name":"commitment","type":"bytes32"}],"name":"dispatchIncoming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"source","type":"bytes"},{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"uint64","name":"nonce","type":"uint64"},{"internalType":"bytes","name":"from","type":"bytes"},{"internalType":"bytes","name":"to","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"bytes","name":"body","type":"bytes"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct PostRequest","name":"request","type":"tuple"}],"name":"dispatchIncoming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"bytes","name":"source","type":"bytes"},{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"uint64","name":"nonce","type":"uint64"},{"internalType":"bytes","name":"from","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"bytes[]","name":"keys","type":"bytes[]"},{"internalType":"uint64","name":"height","type":"uint64"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct GetRequest","name":"request","type":"tuple"},{"components":[{"internalType":"bytes","name":"key","type":"bytes"},{"internalType":"bytes","name":"value","type":"bytes"}],"internalType":"struct StorageValue[]","name":"values","type":"tuple[]"}],"internalType":"struct GetResponse","name":"response","type":"tuple"},{"components":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"sender","type":"address"}],"internalType":"struct FeeMetadata","name":"meta","type":"tuple"}],"name":"dispatchIncoming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"bytes","name":"source","type":"bytes"},{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"uint64","name":"nonce","type":"uint64"},{"internalType":"bytes","name":"from","type":"bytes"},{"internalType":"bytes","name":"to","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"bytes","name":"body","type":"bytes"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct PostRequest","name":"request","type":"tuple"},{"internalType":"bytes","name":"response","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct PostResponse","name":"response","type":"tuple"}],"name":"dispatchIncoming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"bytes","name":"source","type":"bytes"},{"internalType":"bytes","name":"dest","type":"bytes"},{"internalType":"uint64","name":"nonce","type":"uint64"},{"internalType":"bytes","name":"from","type":"bytes"},{"internalType":"bytes","name":"to","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"bytes","name":"body","type":"bytes"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct PostRequest","name":"request","type":"tuple"},{"internalType":"bytes","name":"response","type":"bytes"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"},{"internalType":"uint64","name":"gaslimit","type":"uint64"}],"internalType":"struct PostResponse","name":"response","type":"tuple"},{"components":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"sender","type":"address"}],"internalType":"struct FeeMetadata","name":"meta","type":"tuple"},{"internalType":"bytes32","name":"commitment","type":"bytes32"}],"name":"dispatchIncoming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"frozen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"host","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"hostParams","outputs":[{"components":[{"internalType":"uint256","name":"defaultTimeout","type":"uint256"},{"internalType":"uint256","name":"baseGetRequestFee","type":"uint256"},{"internalType":"uint256","name":"perByteFee","type":"uint256"},{"internalType":"address","name":"feeTokenAddress","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"address","name":"handler","type":"address"},{"internalType":"address","name":"hostManager","type":"address"},{"internalType":"uint256","name":"unStakingPeriod","type":"uint256"},{"internalType":"uint256","name":"challengePeriod","type":"uint256"},{"internalType":"address","name":"consensusClient","type":"address"},{"internalType":"bytes","name":"consensusState","type":"bytes"},{"internalType":"uint256","name":"lastUpdated","type":"uint256"},{"internalType":"uint256","name":"latestStateMachineHeight","type":"uint256"},{"internalType":"bytes","name":"hyperbridge","type":"bytes"}],"internalType":"struct HostParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hyperbridge","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestStateMachineHeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"perByteFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"commitment","type":"bytes32"}],"name":"requestCommitments","outputs":[{"components":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"sender","type":"address"}],"internalType":"struct FeeMetadata","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"commitment","type":"bytes32"}],"name":"requestReceipts","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"commitment","type":"bytes32"}],"name":"responseCommitments","outputs":[{"components":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"sender","type":"address"}],"internalType":"struct FeeMetadata","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"commitment","type":"bytes32"}],"name":"responseReceipts","outputs":[{"components":[{"internalType":"bytes32","name":"responseCommitment","type":"bytes32"},{"internalType":"address","name":"relayer","type":"address"}],"internalType":"struct ResponseReceipt","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"state","type":"bytes"}],"name":"setConsensusState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"newState","type":"bool"}],"name":"setFrozenState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"defaultTimeout","type":"uint256"},{"internalType":"uint256","name":"baseGetRequestFee","type":"uint256"},{"internalType":"uint256","name":"perByteFee","type":"uint256"},{"internalType":"address","name":"feeTokenAddress","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"address","name":"handler","type":"address"},{"internalType":"address","name":"hostManager","type":"address"},{"internalType":"uint256","name":"unStakingPeriod","type":"uint256"},{"internalType":"uint256","name":"challengePeriod","type":"uint256"},{"internalType":"address","name":"consensusClient","type":"address"},{"internalType":"bytes","name":"consensusState","type":"bytes"},{"internalType":"uint256","name":"lastUpdated","type":"uint256"},{"internalType":"uint256","name":"latestStateMachineHeight","type":"uint256"},{"internalType":"bytes","name":"hyperbridge","type":"bytes"}],"internalType":"struct HostParams","name":"params","type":"tuple"}],"name":"setHostParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"defaultTimeout","type":"uint256"},{"internalType":"uint256","name":"baseGetRequestFee","type":"uint256"},{"internalType":"uint256","name":"perByteFee","type":"uint256"},{"internalType":"address","name":"feeTokenAddress","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"address","name":"handler","type":"address"},{"internalType":"address","name":"hostManager","type":"address"},{"internalType":"uint256","name":"unStakingPeriod","type":"uint256"},{"internalType":"uint256","name":"challengePeriod","type":"uint256"},{"internalType":"address","name":"consensusClient","type":"address"},{"internalType":"bytes","name":"consensusState","type":"bytes"},{"internalType":"uint256","name":"lastUpdated","type":"uint256"},{"internalType":"uint256","name":"latestStateMachineHeight","type":"uint256"},{"internalType":"bytes","name":"hyperbridge","type":"bytes"}],"internalType":"struct HostParams","name":"params","type":"tuple"}],"name":"setHostParamsAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"stateMachineId","type":"uint256"},{"internalType":"uint256","name":"height","type":"uint256"}],"internalType":"struct StateMachineHeight","name":"height","type":"tuple"}],"name":"stateMachineCommitment","outputs":[{"components":[{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes32","name":"overlayRoot","type":"bytes32"},{"internalType":"bytes32","name":"stateRoot","type":"bytes32"}],"internalType":"struct StateCommitment","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"stateMachineId","type":"uint256"},{"internalType":"uint256","name":"height","type":"uint256"}],"internalType":"struct StateMachineHeight","name":"height","type":"tuple"}],"name":"stateMachineCommitmentUpdateTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"state","type":"bytes"}],"name":"storeConsensusState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"time","type":"uint256"}],"name":"storeConsensusUpdateTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"height","type":"uint256"}],"name":"storeLatestStateMachineHeight","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"stateMachineId","type":"uint256"},{"internalType":"uint256","name":"height","type":"uint256"}],"internalType":"struct StateMachineHeight","name":"height","type":"tuple"},{"components":[{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes32","name":"overlayRoot","type":"bytes32"},{"internalType":"bytes32","name":"stateRoot","type":"bytes32"}],"internalType":"struct StateCommitment","name":"commitment","type":"tuple"}],"name":"storeStateMachineCommitment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"stateMachineId","type":"uint256"},{"internalType":"uint256","name":"height","type":"uint256"}],"internalType":"struct StateMachineHeight","name":"height","type":"tuple"},{"internalType":"uint256","name":"time","type":"uint256"}],"name":"storeStateMachineCommitmentUpdateTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"timestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unStakingPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct WithdrawParams","name":"params","type":"tuple"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60806040523480156200001157600080fd5b50604051620043e1380380620043e1833981016040819052620000349162000243565b80516007908155602082015160085560408201516009556060820151600a80546001600160a01b03199081166001600160a01b03938416179091556080840151600b8054831691841691909117905560a0840151600c8054831691841691909117905560c0840151600d8054831691841691909117905560e0840151600e55610100840151600f5561012084015160108054909216921691909117905561014082015182918291601190620000ea908262000420565b50610160820151600b820155610180820151600c8201556101a0820151600d82019062000118908262000420565b509050505050620004ec565b634e487b7160e01b600052604160045260246000fd5b6040516101c081016001600160401b038111828210171562000160576200016062000124565b60405290565b604051601f8201601f191681016001600160401b038111828210171562000191576200019162000124565b604052919050565b80516001600160a01b0381168114620001b157600080fd5b919050565b600082601f830112620001c857600080fd5b81516001600160401b03811115620001e457620001e462000124565b6020620001fa601f8301601f1916820162000166565b82815285828487010111156200020f57600080fd5b60005b838110156200022f57858101830151828201840152820162000212565b506000928101909101919091529392505050565b6000602082840312156200025657600080fd5b81516001600160401b03808211156200026e57600080fd5b908301906101c082860312156200028457600080fd5b6200028e6200013a565b825181526020830151602082015260408301516040820152620002b46060840162000199565b6060820152620002c76080840162000199565b6080820152620002da60a0840162000199565b60a0820152620002ed60c0840162000199565b60c082015260e083015160e08201526101008084015181830152506101206200031881850162000199565b9082015261014083810151838111156200033157600080fd5b6200033f88828701620001b6565b8284015250506101608084015181830152506101808084015181830152506101a080840151838111156200037257600080fd5b6200038088828701620001b6565b918301919091525095945050505050565b600181811c90821680620003a657607f821691505b602082108103620003c757634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200041b57600081815260208120601f850160051c81016020861015620003f65750805b601f850160051c820191505b81811015620004175782815560010162000402565b5050505b505050565b81516001600160401b038111156200043c576200043c62000124565b62000454816200044d845462000391565b84620003cd565b602080601f8311600181146200048c5760008415620004735750858301515b600019600386901b1c1916600185901b17855562000417565b600085815260208120601f198616915b82811015620004bd578886015182559484019460019091019084016200049c565b5085821015620004dc5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b613ee580620004fc6000396000f3fe608060405234801561001057600080fd5b506004361061025d5760003560e01c8063641d729d11610146578063b4974cf0116100c3578063e8ce045411610087578063e8ce045414610669578063e95c866c1461067c578063f3f480d91461068f578063f437bc5914610697578063f4b9fa751461069f578063f851a440146106b057600080fd5b8063b4974cf01461062d578063b80777ea14610640578063bbad99d414610646578063d40784c71461064e578063d860cb471461065657600080fd5b80639a8425bc1161010a5780639a8425bc146105705780639a8a059214610578578063a0756ecd1461057f578063a15f743114610592578063a70a8c47146105a557600080fd5b8063641d729d146104e55780636a79c915146104ed5780636ebff5461461050057806385e1f4d0146105135780638856337e1461051b57600080fd5b80632211f1dd116101df5780633c565417116101a35780633c5654171461047e5780633fac32c914610491578063446b0bed146104a45780634f5b258a146104b7578063559efe9e146104ca57806356b65597146104dd57600080fd5b80632211f1dd146103795780632215364d146103f25780632476132b14610407578063368bf464146104185780633b8c2bf71461046b57600080fd5b80631678619c116102265780631678619c146102d157806319667a3e146102e457806319e8faf1146103255780631a1d46a7146103385780631a880a931461034a57600080fd5b80625e763e14610262578063054f7d9c1461028057806309cc21c31461029657806314863dcb146102ab57806315750c19146102be575b600080fd5b61026a6106c1565b60405161027791906126be565b60405180910390f35b60165460ff166040519015158152602001610277565b6102a96102a4366004612a51565b610756565b005b6102a96102b9366004612ad8565b610905565b6102a96102cc366004612b03565b61095b565b6102a96102df366004612ce7565b610c60565b61030d6102f2366004612d1e565b6000908152600260205260409020546001600160a01b031690565b6040516001600160a01b039091168152602001610277565b6102a9610333366004612d45565b610cc9565b6008545b604051908152602001610277565b61033c610358366004612d69565b80516000908152600660209081526040808320938201518352929052205490565b6103ce610387366004612d1e565b604080518082019091526000808252602082015250600090815260016020818152604092839020835180850190945280548452909101546001600160a01b03169082015290565b60408051825181526020928301516001600160a01b03169281019290925201610277565b6103fa610d0f565b6040516102779190612d85565b6010546001600160a01b031661030d565b6103ce610426366004612d1e565b60408051808201909152600080825260208201525060009081526020818152604091829020825180840190935280548352600101546001600160a01b03169082015290565b6102a9610479366004612e96565b610f61565b6102a961048c366004612ed2565b6110d4565b6102a961049f366004612f28565b61120a565b6102a96104b2366004612ff5565b61161f565b6102a96104c5366004613210565b6119af565b6102a96104d8366004613244565b611b4b565b60135461033c565b60095461033c565b6102a96104fb3660046132c4565b611bb6565b6102a961050e366004613369565b611ee2565b61033c600a81565b6103ce610529366004612d1e565b604080518082019091526000808252602082015250600090815260036020908152604091829020825180840190935280548352600101546001600160a01b03169082015290565b60125461033c565b600a61033c565b6102a961058d366004612d1e565b612044565b6102a96105a03660046134a2565b61207c565b61060b6105b3366004612d69565b6040805160608082018352600080835260208084018290529284018190528451815260058352838120948301518152938252928290208251938401835280548452600181015491840191909152600201549082015290565b6040805182518152602080840151908201529181015190820152606001610277565b6102a961063b3660046134a2565b6121c3565b4261033c565b61026a612202565b600e5461033c565b6102a9610664366004612d1e565b612214565b6102a9610677366004613369565b61224c565b6102a961068a3660046134d6565b6122af565b600f5461033c565b61026a612400565b600a546001600160a01b031661030d565b600b546001600160a01b031661030d565b60606007600d0180546106d39061350d565b80601f01602080910402602001604051908101604052809291908181526020018280546106ff9061350d565b801561074c5780601f106107215761010080835404028352916020019161074c565b820191906000526020600020905b81548152906001019060200180831161072f57829003601f168201915b5050505050905090565b600c546001600160a01b0316336001600160a01b0316146107925760405162461bcd60e51b815260040161078990613547565b60405180910390fd5b60006107a18460600151612428565b90506000816001600160a01b0316634c46c03560e01b866040516024016107c891906136a5565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161080691906136b8565b6000604051808303816000865af19150503d8060008114610843576040519150601f19603f3d011682016040523d82523d6000602084013e610848565b606091505b5050905080156108fe57600083815260208190526040812090815560010180546001600160a01b0319169055600a546001600160a01b03165b6020850151855160405163a9059cbb60e01b81526001600160a01b039283166004820152602481019190915291169063a9059cbb906044016020604051808303816000875af11580156108d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108fc91906136d4565b505b5050505050565b600c546001600160a01b0316336001600160a01b0316146109385760405162461bcd60e51b815260040161078990613547565b815160009081526006602090815260408083209482015183529390529190912055565b60a081015160085460009161096f91613707565b9050610983600a546001600160a01b031690565b6001600160a01b03166323b872dd8360c0015130846040518463ffffffff1660e01b81526004016109b69392919061371a565b6020604051808303816000875af11580156109d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f991906136d4565b610a155760405162461bcd60e51b81526004016107899061373e565b600082606001516001600160401b0316600014610ab957610a4860076000015484606001516001600160401b031661247d565b306001600160a01b031663b80777ea6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aaa9190613775565b610ab4919061378e565b610abc565b60005b90506000604051806101000160405280610ad4612400565b815285516020820152604001610af1601580546001810190915590565b6001600160401b0316815260200133604051602001610b28919060609190911b6bffffffffffffffffffffffff1916815260140190565b6040516020818303038152906040528152602001836001600160401b031681526020018560400151815260200185602001516001600160401b0316815260200185608001516001600160401b0316815250905060405180604001604052808560a0015181526020018560c001516001600160a01b0316815250600080610bad84612497565b815260208082019290925260409081016000208351815592820151600190930180546001600160a01b0319166001600160a01b039094169390931790925582820151835191840151606085015160a08087015160c0880151608089015160e08a0151938d015198516001600160401b03909716987f26ee1c64b9f56f087f6ba8e297c9d216d301cfc56cbefd4a7ed5a61a73c39bb698610c52989097969591906137b5565b60405180910390a250505050565b600c546001600160a01b0316336001600160a01b031614610c935760405162461bcd60e51b815260040161078990613547565b6000610ca28460600151612428565b90506000816001600160a01b031663d63bcf1860e01b866040516024016107c89190613908565b600b546001600160a01b0316336001600160a01b031614610cfc5760405162461bcd60e51b81526004016107899061391b565b6016805460ff1916911515919091179055565b610dae604051806101c0016040528060008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b03168152602001600081526020016000815260200160006001600160a01b03168152602001606081526020016000815260200160008152602001606081525090565b604080516101c081018252600780548252600854602083015260095492820192909252600a546001600160a01b039081166060830152600b5481166080830152600c54811660a0830152600d54811660c0830152600e5460e0830152600f54610100830152601054166101208201526011805491929161014084019190610e349061350d565b80601f0160208091040260200160405190810160405280929190818152602001828054610e609061350d565b8015610ead5780601f10610e8257610100808354040283529160200191610ead565b820191906000526020600020905b815481529060010190602001808311610e9057829003601f168201915b50505050508152602001600b8201548152602001600c8201548152602001600d82018054610eda9061350d565b80601f0160208091040260200160405190810160405280929190818152602001828054610f069061350d565b8015610f535780601f10610f2857610100808354040283529160200191610f53565b820191906000526020600020905b815481529060010190602001808311610f3657829003601f168201915b505050505081525050905090565b600c546001600160a01b0316336001600160a01b031614610f945760405162461bcd60e51b815260040161078990613547565b6000610fa38260800151612428565b9050803b6000819003610fb557505050565b6000826001600160a01b0316634e87ba1960e01b85604051602401610fda9190613908565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161101891906136b8565b6000604051808303816000865af19150503d8060008114611055576040519150601f19603f3d011682016040523d82523d6000602084013e61105a565b606091505b5050905080156110cd57600061106f85612569565b60008181526002602090815260409182902080546001600160a01b031916329081179091558251848152918201529192507fa73d58a0fd0647075f9f6b1d18358fcb27c8f8f164fd05c4f9d3e9d5c4f3b64d910160405180910390a1505b5050505b50565b600d546001600160a01b0316336001600160a01b0316146111375760405162461bcd60e51b815260206004820152601e60248201527f45766d486f73743a204f6e6c79204d616e6167657220636f6e747261637400006044820152606401610789565b600a546001600160a01b03168151602083015160405163a9059cbb60e01b81526001600160a01b039283166004820152602481019190915291169063a9059cbb906044016020604051808303816000875af115801561119a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111be91906136d4565b6110d15760405162461bcd60e51b815260206004820181905260248201527f486f73742068617320616e20696e73756666696369656e742062616c616e63656044820152606401610789565b60006112198260000151612569565b6000818152600260205260409020549091506001600160a01b03166112805760405162461bcd60e51b815260206004820152601860248201527f45766d486f73743a20556e6b6e6f776e207265717565737400000000000000006044820152606401610789565b815160800151339061129190612428565b6001600160a01b0316146112e75760405162461bcd60e51b815260206004820152601e60248201527f45766d486f73743a20556e617574686f72697a656420526573706f6e736500006044820152606401610789565b60008181526004602052604090205460ff16156113465760405162461bcd60e51b815260206004820152601b60248201527f45766d486f73743a204475706c696361746520526573706f6e736500000000006044820152606401610789565b60808201516020830151516009546000929161136191613948565b61136b9190613707565b905061137f600a546001600160a01b031690565b6001600160a01b03166323b872dd8460a0015130846040518463ffffffff1660e01b81526004016113b29392919061371a565b6020604051808303816000875af11580156113d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113f591906136d4565b6114115760405162461bcd60e51b81526004016107899061373e565b600083604001516001600160401b03166000146114b55761144460076000015485604001516001600160401b031661247d565b306001600160a01b031663b80777ea6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611482573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a69190613775565b6114b0919061378e565b6114b8565b60005b604080516080808201835287518252602080890151818401526001600160401b03808616848601526060808b015190911690840152835180850190945290880151835260a08801516001600160a01b031690830152919250806001600061151e85612582565b8152602080820192909252604090810160009081208451815593830151600194850180546001600160a01b0319166001600160a01b0390921691909117905588815260048352819020805460ff1916909317909255835180830151815182840151606084015160809094015195516001600160401b03909316957f5fd3db5b7eb37c4ba20c6fbaf45df3bc3c62b6c81d1550b60b9be791d735fc22959294919391926115ca92016136b8565b60408051601f19818403018152828252895160a081015160c082015160e09092015160208d0151948d015160608e01518d5161160f9b9a99989697949693949361395f565b60405180910390a2505050505050565b600c546001600160a01b0316336001600160a01b0316146116525760405162461bcd60e51b815260040161078990613547565b6000805b8360200151518110156116b4578360200151818151811061167957611679613a32565b602002602001015160200151516007600201546116969190613948565b6116a09083613707565b9150806116ac81613a48565b915050611656565b50600a5460208301516040516323b872dd60e01b81526001600160a01b03909216916323b872dd916116ec913090869060040161371a565b6020604051808303816000875af115801561170b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061172f91906136d4565b61177b5760405162461bcd60e51b815260206004820152601d60248201527f4f726967696e2068617320696e73756666696369656e742066756e64730000006044820152606401610789565b600061178e846000015160600151612428565b90506000816001600160a01b031663f370fdbb60e01b866040516024016117b59190613a61565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516117f391906136b8565b6000604051808303816000865af19150503d8060008114611830576040519150601f19603f3d011682016040523d82523d6000602084013e611835565b606091505b5050905080156108fe57600061184e8660000151612497565b604080518082018252600080825232602080840191825285835260039052929020905181559051600190910180546001600160a01b0319166001600160a01b0390921691909117905585519091501561196f57600a546001600160a01b0316855160405163a9059cbb60e01b815232600482015260248101919091526001600160a01b03919091169063a9059cbb906044016020604051808303816000875af11580156118ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061192391906136d4565b61196f5760405162461bcd60e51b815260206004820152601e60248201527f45766d486f73742068617320696e73756666696369656e742066756e647300006044820152606401610789565b604080518281523260208201527fee00e116b272a1610063bf2a37255152212aeea2d088118e22add5cbe3e9f418910160405180910390a1505050505050565b600c546001600160a01b0316336001600160a01b0316146119e25760405162461bcd60e51b815260040161078990613547565b60006119f5826000015160600151612428565b90506000816001600160a01b031663afb760ac60e01b84604051602401611a1c9190613b07565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051611a5a91906136b8565b6000604051808303816000865af19150503d8060008114611a97576040519150601f19603f3d011682016040523d82523d6000602084013e611a9c565b606091505b505090508015611b46576000611ab58460000151612569565b90506040518060400160405280611acb86612582565b81523260209182018190526000848152600383526040908190208451815593830151600190940180546001600160a01b0319166001600160a01b03909516949094179093558251848152918201527fee00e116b272a1610063bf2a37255152212aeea2d088118e22add5cbe3e9f418910160405180910390a1505b505050565b600c546001600160a01b0316336001600160a01b031614611b7e5760405162461bcd60e51b815260040161078990613547565b815160009081526005602090815260408083209482015183529381529083902082518155908201516001820155910151600290910155565b60a081015160408201515160095460009291611bd191613948565b611bdb9190613707565b9050611bef600a546001600160a01b031690565b6001600160a01b03166323b872dd8360c0015130846040518463ffffffff1660e01b8152600401611c229392919061371a565b6020604051808303816000875af1158015611c41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c6591906136d4565b611c815760405162461bcd60e51b81526004016107899061373e565b600082606001516001600160401b0316600014611d2557611cb460076000015484606001516001600160401b031661247d565b306001600160a01b031663b80777ea6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d169190613775565b611d20919061378e565b611d28565b60005b90506000604051806101000160405280611d40612400565b815285516020820152604001611d5d601580546001810190915590565b6001600160401b0316815260200133604051602001611d94919060609190911b6bffffffffffffffffffffffff1916815260140190565b604051602081830303815290604052815260200185602001518152602001836001600160401b031681526020018560400151815260200185608001516001600160401b0316815250905060405180604001604052808560a0015181526020018560c001516001600160a01b0316815250600080611e1084612569565b81526020019081526020016000206000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555090505080604001516001600160401b03167fb316d746c47c6db4dc6d2020087bb722f66e263e87370ea2ccab21dd0e9bdf2c8260000151836020015184606001518560800151604051602001611eab91906136b8565b6040516020818303038152906040528660a001518760c001518860e001518c60a00151604051610c52989796959493929190613b70565b600b546001600160a01b0316336001600160a01b031614611f155760405162461bcd60e51b81526004016107899061391b565b46600a03611f655760405162461bcd60e51b815260206004820152601c60248201527f43616e6e6f742073657420706172616d73206f6e206d61696e6e6574000000006044820152606401610789565b80516007908155602082015160085560408201516009556060820151600a80546001600160a01b03199081166001600160a01b03938416179091556080840151600b8054831691841691909117905560a0840151600c8054831691841691909117905560c0840151600d8054831691841691909117905560e0840151600e55610100840151600f556101208401516010805490921692169190911790556101408201518291906011906120189082613c41565b50610160820151600b820155610180820151600c8201556101a0820151600d8201906110cd9082613c41565b600c546001600160a01b0316336001600160a01b0316146120775760405162461bcd60e51b815260040161078990613547565b601355565b600b546001600160a01b0316336001600160a01b0316146120af5760405162461bcd60e51b81526004016107899061391b565b46600a146120be57600161216c565b6040805160008082526020820190925261216c9150601180546120e09061350d565b80601f016020809104026020016040519081016040528092919081815260200182805461210c9061350d565b80156121595780601f1061212e57610100808354040283529160200191612159565b820191906000526020600020905b81548152906001019060200180831161213c57829003601f168201915b50505050506125ed90919063ffffffff16565b6121ae5760405162461bcd60e51b81526020600482015260136024820152722ab730baba3437b934bd32b21030b1ba34b7b760691b6044820152606401610789565b600060135560116121bf8282613c41565b5050565b600c546001600160a01b0316336001600160a01b0316146121f65760405162461bcd60e51b815260040161078990613547565b60116121bf8282613c41565b60606007600a0180546106d39061350d565b600c546001600160a01b0316336001600160a01b0316146122475760405162461bcd60e51b815260040161078990613547565b601255565b600d546001600160a01b0316336001600160a01b031614611f655760405162461bcd60e51b815260206004820152601e60248201527f45766d486f73743a204f6e6c79204d616e6167657220636f6e747261637400006044820152606401610789565b600c546001600160a01b0316336001600160a01b0316146122e25760405162461bcd60e51b815260040161078990613547565b60006122f5846000015160800151612428565b90506000816001600160a01b03166312b2524f60e01b8660405160240161231c9190613b07565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161235a91906136b8565b6000604051808303816000865af19150503d8060008114612397576040519150601f19603f3d011682016040523d82523d6000602084013e61239c565b606091505b5050905080156108fe57600083815260016020819052604082208281550180546001600160a01b03191690558551600491906123d790612569565b81526020810191909152604001600020805460ff19169055600a546001600160a01b0316610881565b60606124236040805180820190915260048152634f50544960e01b602082015290565b905090565b60006014825110156124755760405162461bcd60e51b8152602060048201526016602482015275092dcecc2d8d2c840c2c8c8e4cae6e640d8cadccee8d60531b6044820152606401610789565b506014015190565b600081831161248c578161248e565b825b90505b92915050565b6040805160208101909152600080825260a083015151909190825b8181101561250e57828560a0015182815181106124d1576124d1613a32565b60200260200101516040516020016124ea929190613d00565b6040516020818303038152906040529250808061250690613a48565b9150506124b2565b508360000151846020015185604001518660c0015187608001518860600151878a60e0015160405160200161254a989796959493929190613d2f565b6040516020818303038152906040528051906020012092505050919050565b600061257482612617565b805190602001209050919050565b60006125918260000151612617565b8260200151836040015184606001516040516020016125b293929190613dcb565b60408051601f19818403018152908290526125d09291602001613d00565b604051602081830303815290604052805190602001209050919050565b6000815183511461260057506000612491565b508151602091820181902091909201919091201490565b60608160000151826020015183604001518460a00151856060015186608001518760c001518860e00151604051602001612658989796959493929190613e07565b6040516020818303038152906040529050919050565b60005b83811015612689578181015183820152602001612671565b50506000910152565b600081518084526126aa81602086016020860161266e565b601f01601f19169290920160200192915050565b60208152600061248e6020830184612692565b634e487b7160e01b600052604160045260246000fd5b60405161010081016001600160401b038111828210171561270a5761270a6126d1565b60405290565b604080519081016001600160401b038111828210171561270a5761270a6126d1565b60405160e081016001600160401b038111828210171561270a5761270a6126d1565b60405160c081016001600160401b038111828210171561270a5761270a6126d1565b6040516101c081016001600160401b038111828210171561270a5761270a6126d1565b604051601f8201601f191681016001600160401b03811182821017156127c1576127c16126d1565b604052919050565b600082601f8301126127da57600080fd5b81356001600160401b038111156127f3576127f36126d1565b612806601f8201601f1916602001612799565b81815284602083860101111561281b57600080fd5b816020850160208301376000918101602001919091529392505050565b80356001600160401b038116811461284f57600080fd5b919050565b60006001600160401b0382111561286d5761286d6126d1565b5060051b60200190565b600082601f83011261288857600080fd5b8135602061289d61289883612854565b612799565b82815260059290921b840181019181810190868411156128bc57600080fd5b8286015b848110156128fb5780356001600160401b038111156128df5760008081fd5b6128ed8986838b01016127c9565b8452509183019183016128c0565b509695505050505050565b6000610100828403121561291957600080fd5b6129216126e7565b905081356001600160401b038082111561293a57600080fd5b612946858386016127c9565b8352602084013591508082111561295c57600080fd5b612968858386016127c9565b602084015261297960408501612838565b6040840152606084013591508082111561299257600080fd5b61299e858386016127c9565b60608401526129af60808501612838565b608084015260a08401359150808211156129c857600080fd5b506129d584828501612877565b60a0830152506129e760c08301612838565b60c08201526129f860e08301612838565b60e082015292915050565b80356001600160a01b038116811461284f57600080fd5b600060408284031215612a2c57600080fd5b612a34612710565b905081358152612a4660208301612a03565b602082015292915050565b600080600060808486031215612a6657600080fd5b83356001600160401b03811115612a7c57600080fd5b612a8886828701612906565b935050612a988560208601612a1a565b9150606084013590509250925092565b600060408284031215612aba57600080fd5b612ac2612710565b9050813581526020820135602082015292915050565b60008060608385031215612aeb57600080fd5b612af58484612aa8565b946040939093013593505050565b600060208284031215612b1557600080fd5b81356001600160401b0380821115612b2c57600080fd5b9083019060e08286031215612b4057600080fd5b612b48612732565b823582811115612b5757600080fd5b612b63878286016127c9565b825250612b7260208401612838565b6020820152604083013582811115612b8957600080fd5b612b9587828601612877565b604083015250612ba760608401612838565b6060820152612bb860808401612838565b608082015260a083013560a0820152612bd360c08401612a03565b60c082015295945050505050565b60006101008284031215612bf457600080fd5b612bfc6126e7565b905081356001600160401b0380821115612c1557600080fd5b612c21858386016127c9565b83526020840135915080821115612c3757600080fd5b612c43858386016127c9565b6020840152612c5460408501612838565b60408401526060840135915080821115612c6d57600080fd5b612c79858386016127c9565b60608401526080840135915080821115612c9257600080fd5b612c9e858386016127c9565b6080840152612caf60a08501612838565b60a084015260c0840135915080821115612cc857600080fd5b50612cd5848285016127c9565b60c0830152506129f860e08301612838565b600080600060808486031215612cfc57600080fd5b83356001600160401b03811115612d1257600080fd5b612a8886828701612be1565b600060208284031215612d3057600080fd5b5035919050565b80151581146110d157600080fd5b600060208284031215612d5757600080fd5b8135612d6281612d37565b9392505050565b600060408284031215612d7b57600080fd5b61248e8383612aa8565b6020815281516020820152602082015160408201526040820151606082015260006060830151612dc060808401826001600160a01b03169052565b5060808301516001600160a01b03811660a08401525060a08301516001600160a01b03811660c08401525060c08301516001600160a01b03811660e08401525060e08301516101008381019190915283015161012080840191909152830151610140612e36818501836001600160a01b03169052565b808501519150506101c06101608181860152612e566101e0860184612692565b90860151610180868101919091528601516101a080870191909152860151858203601f190183870152909250612e8c8382612692565b9695505050505050565b600060208284031215612ea857600080fd5b81356001600160401b03811115612ebe57600080fd5b612eca84828501612be1565b949350505050565b600060408284031215612ee457600080fd5b604051604081018181106001600160401b0382111715612f0657612f066126d1565b604052612f1283612a03565b8152602083013560208201528091505092915050565b600060208284031215612f3a57600080fd5b81356001600160401b0380821115612f5157600080fd5b9083019060c08286031215612f6557600080fd5b612f6d612754565b823582811115612f7c57600080fd5b612f8887828601612be1565b825250602083013582811115612f9d57600080fd5b612fa9878286016127c9565b602083015250612fbb60408401612838565b6040820152612fcc60608401612838565b606082015260808301356080820152612fe760a08401612a03565b60a082015295945050505050565b6000806060838503121561300857600080fd5b82356001600160401b038082111561301f57600080fd5b908401906040828703121561303357600080fd5b61303b612710565b82358281111561304a57600080fd5b61305688828601612906565b8252506020808401358381111561306c57600080fd5b80850194505087601f85011261308157600080fd5b833561308f61289882612854565b81815260059190911b8501820190828101908a8311156130ae57600080fd5b8387015b83811015613140578035878111156130ca5760008081fd5b88016040818e03601f190112156130e15760008081fd5b6130e9612710565b86820135898111156130fb5760008081fd5b6131098f89838601016127c9565b82525060408201358981111561311f5760008081fd5b61312d8f89838601016127c9565b82890152508452509184019184016130b2565b50808486015250505081955061315888828901612a1a565b9450505050509250929050565b60006080828403121561317757600080fd5b604051608081016001600160401b03828210818311171561319a5761319a6126d1565b8160405282935084359150808211156131b257600080fd5b6131be86838701612be1565b835260208501359150808211156131d457600080fd5b506131e1858286016127c9565b6020830152506131f360408401612838565b604082015261320460608401612838565b60608201525092915050565b60006020828403121561322257600080fd5b81356001600160401b0381111561323857600080fd5b612eca84828501613165565b60008082840360a081121561325857600080fd5b6132628585612aa8565b92506060603f198201121561327657600080fd5b50604051606081018181106001600160401b0382111715613299576132996126d1565b8060405250604084013581526060840135602082015260808401356040820152809150509250929050565b6000602082840312156132d657600080fd5b81356001600160401b03808211156132ed57600080fd5b9083019060e0828603121561330157600080fd5b613309612732565b82358281111561331857600080fd5b613324878286016127c9565b82525060208301358281111561333957600080fd5b613345878286016127c9565b60208301525060408301358281111561335d57600080fd5b612b95878286016127c9565b60006020828403121561337b57600080fd5b81356001600160401b038082111561339257600080fd5b908301906101c082860312156133a757600080fd5b6133af612776565b8235815260208301356020820152604083013560408201526133d360608401612a03565b60608201526133e460808401612a03565b60808201526133f560a08401612a03565b60a082015261340660c08401612a03565b60c082015260e083013560e082015261010080840135818301525061012061342f818501612a03565b90820152610140838101358381111561344757600080fd5b613453888287016127c9565b8284015250506101608084013581830152506101808084013581830152506101a0808401358381111561348557600080fd5b613491888287016127c9565b918301919091525095945050505050565b6000602082840312156134b457600080fd5b81356001600160401b038111156134ca57600080fd5b612eca848285016127c9565b6000806000608084860312156134eb57600080fd5b83356001600160401b0381111561350157600080fd5b612a8886828701613165565b600181811c9082168061352157607f821691505b60208210810361354157634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526015908201527422bb36a437b9ba1d1027b7363c903430b7323632b960591b604082015260600190565b600081518084526020808501808196508360051b8101915082860160005b858110156135be5782840389526135ac848351612692565b98850198935090840190600101613594565b5091979650505050505050565b600061010082518185526135e182860182612692565b915050602083015184820360208601526135fb8282612692565b915050604083015161361860408601826001600160401b03169052565b50606083015184820360608601526136308282612692565b915050608083015161364d60808601826001600160401b03169052565b5060a083015184820360a08601526136658282613576565b91505060c083015161368260c08601826001600160401b03169052565b5060e083015161369d60e08601826001600160401b03169052565b509392505050565b60208152600061248e60208301846135cb565b600082516136ca81846020870161266e565b9190910192915050565b6000602082840312156136e657600080fd5b8151612d6281612d37565b634e487b7160e01b600052601160045260246000fd5b80820180821115612491576124916136f1565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6020808252601c908201527f50617965722068617320696e73756666696369656e742066756e647300000000604082015260600190565b60006020828403121561378757600080fd5b5051919050565b6001600160401b038181168382160190808211156137ae576137ae6136f1565b5092915050565b60006101008083526137c98184018c612692565b905082810360208401526137dd818b612692565b905082810360408401526137f1818a612692565b905082810360608401526138058189613576565b6001600160401b03978816608085015295871660a084015250509190931660c082015260e00191909152949350505050565b6000610100825181855261384d82860182612692565b915050602083015184820360208601526138678282612692565b915050604083015161388460408601826001600160401b03169052565b506060830151848203606086015261389c8282612692565b915050608083015184820360808601526138b68282612692565b91505060a08301516138d360a08601826001600160401b03169052565b5060c083015184820360c08601526138eb8282612692565b91505060e083015161369d60e08601826001600160401b03169052565b60208152600061248e6020830184613837565b60208082526013908201527222bb36a437b9ba1d1027b7363c9030b236b4b760691b604082015260600190565b8082028115828204841417612491576124916136f1565b60006101608083526139738184018f612692565b90508281036020840152613987818e612692565b9050828103604084015261399b818d612692565b905082810360608401526139af818c612692565b90506001600160401b038a16608084015282810360a08401526139d2818a612692565b6001600160401b03891660c0850152905082810360e08401526139f58188612692565b915050613a0e6101008301866001600160401b03169052565b6001600160401b039390931661012082015261014001529998505050505050505050565b634e487b7160e01b600052603260045260246000fd5b600060018201613a5a57613a5a6136f1565b5060010190565b60006020808352835160408083860152613a7e60608601836135cb565b83870151601f1987830381018489015281518084529294509085019184860190600581901b8601870160005b82811015613af8578488830301845285518051888452613acc89850182612692565b918b0151848303858d0152919050613ae48183612692565b978b0197958b019593505050600101613aaa565b509a9950505050505050505050565b602081526000825160806020840152613b2360a0840182613837565b90506020840151601f19848303016040850152613b408282612692565b91505060408401516001600160401b03808216606086015280606087015116608086015250508091505092915050565b6000610100808352613b848184018c612692565b90508281036020840152613b98818b612692565b90508281036040840152613bac818a612692565b90508281036060840152613bc08189612692565b90506001600160401b03808816608085015283820360a0850152613be48288612692565b951660c0840152505060e001529695505050505050565b601f821115611b4657600081815260208120601f850160051c81016020861015613c225750805b601f850160051c820191505b818110156108fc57828155600101613c2e565b81516001600160401b03811115613c5a57613c5a6126d1565b613c6e81613c68845461350d565b84613bfb565b602080601f831160018114613ca35760008415613c8b5750858301515b600019600386901b1c1916600185901b1785556108fc565b600085815260208120601f198616915b82811015613cd257888601518255948401946001909101908401613cb3565b5085821015613cf05787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60008351613d1281846020880161266e565b835190830190613d2681836020880161266e565b01949350505050565b60008951613d41818460208e0161266e565b895190830190613d55818360208e0161266e565b60c08a811b6001600160c01b03199081169390920192835289811b8216600884015288901b811660108301528651613d94816018850160208b0161266e565b8651920191613daa816018850160208a0161266e565b60c09590951b16930160188101939093525050602001979650505050505050565b60008451613ddd81846020890161266e565b6001600160c01b031960c095861b8116919093019081529290931b16600882015260100192915050565b60008951613e19818460208e0161266e565b895190830190613e2d818360208e0161266e565b60c08a811b6001600160c01b03199081169390920192835289901b811660088301528751613e62816010850160208c0161266e565b8751920191613e78816010850160208b0161266e565b8651920191613e8e816010850160208a0161266e565b60c09590951b1693016010810193909352505060180197965050505050505056fea264697066735822122069164b40a865a3d9d07f04cefed61beebfb8a50890e28acd3f00caff9a1f2d7064736f6c6343000811003300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001c2000000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000000000000000000000000000000aa87bee538000000000000000000000000000287c570f009b7d47c360618f12397acfa92c412a00000000000000000000000000046e40b355d40a5b3731e9fd584ff4c3446cd6000000000000000000000000d0a8c8fb78ace3628ba14ecb3f240b4fcf6c98bb00000000000000000000000024e8254124c5077b79623959308ac8819134efd600000000000000000000000000000000000000000000000000000000001baf800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e307cdf8f91a08740655d0df1d8bab9cd245e52900000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b4b5553414d412d34333734000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061025d5760003560e01c8063641d729d11610146578063b4974cf0116100c3578063e8ce045411610087578063e8ce045414610669578063e95c866c1461067c578063f3f480d91461068f578063f437bc5914610697578063f4b9fa751461069f578063f851a440146106b057600080fd5b8063b4974cf01461062d578063b80777ea14610640578063bbad99d414610646578063d40784c71461064e578063d860cb471461065657600080fd5b80639a8425bc1161010a5780639a8425bc146105705780639a8a059214610578578063a0756ecd1461057f578063a15f743114610592578063a70a8c47146105a557600080fd5b8063641d729d146104e55780636a79c915146104ed5780636ebff5461461050057806385e1f4d0146105135780638856337e1461051b57600080fd5b80632211f1dd116101df5780633c565417116101a35780633c5654171461047e5780633fac32c914610491578063446b0bed146104a45780634f5b258a146104b7578063559efe9e146104ca57806356b65597146104dd57600080fd5b80632211f1dd146103795780632215364d146103f25780632476132b14610407578063368bf464146104185780633b8c2bf71461046b57600080fd5b80631678619c116102265780631678619c146102d157806319667a3e146102e457806319e8faf1146103255780631a1d46a7146103385780631a880a931461034a57600080fd5b80625e763e14610262578063054f7d9c1461028057806309cc21c31461029657806314863dcb146102ab57806315750c19146102be575b600080fd5b61026a6106c1565b60405161027791906126be565b60405180910390f35b60165460ff166040519015158152602001610277565b6102a96102a4366004612a51565b610756565b005b6102a96102b9366004612ad8565b610905565b6102a96102cc366004612b03565b61095b565b6102a96102df366004612ce7565b610c60565b61030d6102f2366004612d1e565b6000908152600260205260409020546001600160a01b031690565b6040516001600160a01b039091168152602001610277565b6102a9610333366004612d45565b610cc9565b6008545b604051908152602001610277565b61033c610358366004612d69565b80516000908152600660209081526040808320938201518352929052205490565b6103ce610387366004612d1e565b604080518082019091526000808252602082015250600090815260016020818152604092839020835180850190945280548452909101546001600160a01b03169082015290565b60408051825181526020928301516001600160a01b03169281019290925201610277565b6103fa610d0f565b6040516102779190612d85565b6010546001600160a01b031661030d565b6103ce610426366004612d1e565b60408051808201909152600080825260208201525060009081526020818152604091829020825180840190935280548352600101546001600160a01b03169082015290565b6102a9610479366004612e96565b610f61565b6102a961048c366004612ed2565b6110d4565b6102a961049f366004612f28565b61120a565b6102a96104b2366004612ff5565b61161f565b6102a96104c5366004613210565b6119af565b6102a96104d8366004613244565b611b4b565b60135461033c565b60095461033c565b6102a96104fb3660046132c4565b611bb6565b6102a961050e366004613369565b611ee2565b61033c600a81565b6103ce610529366004612d1e565b604080518082019091526000808252602082015250600090815260036020908152604091829020825180840190935280548352600101546001600160a01b03169082015290565b60125461033c565b600a61033c565b6102a961058d366004612d1e565b612044565b6102a96105a03660046134a2565b61207c565b61060b6105b3366004612d69565b6040805160608082018352600080835260208084018290529284018190528451815260058352838120948301518152938252928290208251938401835280548452600181015491840191909152600201549082015290565b6040805182518152602080840151908201529181015190820152606001610277565b6102a961063b3660046134a2565b6121c3565b4261033c565b61026a612202565b600e5461033c565b6102a9610664366004612d1e565b612214565b6102a9610677366004613369565b61224c565b6102a961068a3660046134d6565b6122af565b600f5461033c565b61026a612400565b600a546001600160a01b031661030d565b600b546001600160a01b031661030d565b60606007600d0180546106d39061350d565b80601f01602080910402602001604051908101604052809291908181526020018280546106ff9061350d565b801561074c5780601f106107215761010080835404028352916020019161074c565b820191906000526020600020905b81548152906001019060200180831161072f57829003601f168201915b5050505050905090565b600c546001600160a01b0316336001600160a01b0316146107925760405162461bcd60e51b815260040161078990613547565b60405180910390fd5b60006107a18460600151612428565b90506000816001600160a01b0316634c46c03560e01b866040516024016107c891906136a5565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161080691906136b8565b6000604051808303816000865af19150503d8060008114610843576040519150601f19603f3d011682016040523d82523d6000602084013e610848565b606091505b5050905080156108fe57600083815260208190526040812090815560010180546001600160a01b0319169055600a546001600160a01b03165b6020850151855160405163a9059cbb60e01b81526001600160a01b039283166004820152602481019190915291169063a9059cbb906044016020604051808303816000875af11580156108d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108fc91906136d4565b505b5050505050565b600c546001600160a01b0316336001600160a01b0316146109385760405162461bcd60e51b815260040161078990613547565b815160009081526006602090815260408083209482015183529390529190912055565b60a081015160085460009161096f91613707565b9050610983600a546001600160a01b031690565b6001600160a01b03166323b872dd8360c0015130846040518463ffffffff1660e01b81526004016109b69392919061371a565b6020604051808303816000875af11580156109d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f991906136d4565b610a155760405162461bcd60e51b81526004016107899061373e565b600082606001516001600160401b0316600014610ab957610a4860076000015484606001516001600160401b031661247d565b306001600160a01b031663b80777ea6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aaa9190613775565b610ab4919061378e565b610abc565b60005b90506000604051806101000160405280610ad4612400565b815285516020820152604001610af1601580546001810190915590565b6001600160401b0316815260200133604051602001610b28919060609190911b6bffffffffffffffffffffffff1916815260140190565b6040516020818303038152906040528152602001836001600160401b031681526020018560400151815260200185602001516001600160401b0316815260200185608001516001600160401b0316815250905060405180604001604052808560a0015181526020018560c001516001600160a01b0316815250600080610bad84612497565b815260208082019290925260409081016000208351815592820151600190930180546001600160a01b0319166001600160a01b039094169390931790925582820151835191840151606085015160a08087015160c0880151608089015160e08a0151938d015198516001600160401b03909716987f26ee1c64b9f56f087f6ba8e297c9d216d301cfc56cbefd4a7ed5a61a73c39bb698610c52989097969591906137b5565b60405180910390a250505050565b600c546001600160a01b0316336001600160a01b031614610c935760405162461bcd60e51b815260040161078990613547565b6000610ca28460600151612428565b90506000816001600160a01b031663d63bcf1860e01b866040516024016107c89190613908565b600b546001600160a01b0316336001600160a01b031614610cfc5760405162461bcd60e51b81526004016107899061391b565b6016805460ff1916911515919091179055565b610dae604051806101c0016040528060008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b03168152602001600081526020016000815260200160006001600160a01b03168152602001606081526020016000815260200160008152602001606081525090565b604080516101c081018252600780548252600854602083015260095492820192909252600a546001600160a01b039081166060830152600b5481166080830152600c54811660a0830152600d54811660c0830152600e5460e0830152600f54610100830152601054166101208201526011805491929161014084019190610e349061350d565b80601f0160208091040260200160405190810160405280929190818152602001828054610e609061350d565b8015610ead5780601f10610e8257610100808354040283529160200191610ead565b820191906000526020600020905b815481529060010190602001808311610e9057829003601f168201915b50505050508152602001600b8201548152602001600c8201548152602001600d82018054610eda9061350d565b80601f0160208091040260200160405190810160405280929190818152602001828054610f069061350d565b8015610f535780601f10610f2857610100808354040283529160200191610f53565b820191906000526020600020905b815481529060010190602001808311610f3657829003601f168201915b505050505081525050905090565b600c546001600160a01b0316336001600160a01b031614610f945760405162461bcd60e51b815260040161078990613547565b6000610fa38260800151612428565b9050803b6000819003610fb557505050565b6000826001600160a01b0316634e87ba1960e01b85604051602401610fda9190613908565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161101891906136b8565b6000604051808303816000865af19150503d8060008114611055576040519150601f19603f3d011682016040523d82523d6000602084013e61105a565b606091505b5050905080156110cd57600061106f85612569565b60008181526002602090815260409182902080546001600160a01b031916329081179091558251848152918201529192507fa73d58a0fd0647075f9f6b1d18358fcb27c8f8f164fd05c4f9d3e9d5c4f3b64d910160405180910390a1505b5050505b50565b600d546001600160a01b0316336001600160a01b0316146111375760405162461bcd60e51b815260206004820152601e60248201527f45766d486f73743a204f6e6c79204d616e6167657220636f6e747261637400006044820152606401610789565b600a546001600160a01b03168151602083015160405163a9059cbb60e01b81526001600160a01b039283166004820152602481019190915291169063a9059cbb906044016020604051808303816000875af115801561119a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111be91906136d4565b6110d15760405162461bcd60e51b815260206004820181905260248201527f486f73742068617320616e20696e73756666696369656e742062616c616e63656044820152606401610789565b60006112198260000151612569565b6000818152600260205260409020549091506001600160a01b03166112805760405162461bcd60e51b815260206004820152601860248201527f45766d486f73743a20556e6b6e6f776e207265717565737400000000000000006044820152606401610789565b815160800151339061129190612428565b6001600160a01b0316146112e75760405162461bcd60e51b815260206004820152601e60248201527f45766d486f73743a20556e617574686f72697a656420526573706f6e736500006044820152606401610789565b60008181526004602052604090205460ff16156113465760405162461bcd60e51b815260206004820152601b60248201527f45766d486f73743a204475706c696361746520526573706f6e736500000000006044820152606401610789565b60808201516020830151516009546000929161136191613948565b61136b9190613707565b905061137f600a546001600160a01b031690565b6001600160a01b03166323b872dd8460a0015130846040518463ffffffff1660e01b81526004016113b29392919061371a565b6020604051808303816000875af11580156113d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113f591906136d4565b6114115760405162461bcd60e51b81526004016107899061373e565b600083604001516001600160401b03166000146114b55761144460076000015485604001516001600160401b031661247d565b306001600160a01b031663b80777ea6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611482573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a69190613775565b6114b0919061378e565b6114b8565b60005b604080516080808201835287518252602080890151818401526001600160401b03808616848601526060808b015190911690840152835180850190945290880151835260a08801516001600160a01b031690830152919250806001600061151e85612582565b8152602080820192909252604090810160009081208451815593830151600194850180546001600160a01b0319166001600160a01b0390921691909117905588815260048352819020805460ff1916909317909255835180830151815182840151606084015160809094015195516001600160401b03909316957f5fd3db5b7eb37c4ba20c6fbaf45df3bc3c62b6c81d1550b60b9be791d735fc22959294919391926115ca92016136b8565b60408051601f19818403018152828252895160a081015160c082015160e09092015160208d0151948d015160608e01518d5161160f9b9a99989697949693949361395f565b60405180910390a2505050505050565b600c546001600160a01b0316336001600160a01b0316146116525760405162461bcd60e51b815260040161078990613547565b6000805b8360200151518110156116b4578360200151818151811061167957611679613a32565b602002602001015160200151516007600201546116969190613948565b6116a09083613707565b9150806116ac81613a48565b915050611656565b50600a5460208301516040516323b872dd60e01b81526001600160a01b03909216916323b872dd916116ec913090869060040161371a565b6020604051808303816000875af115801561170b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061172f91906136d4565b61177b5760405162461bcd60e51b815260206004820152601d60248201527f4f726967696e2068617320696e73756666696369656e742066756e64730000006044820152606401610789565b600061178e846000015160600151612428565b90506000816001600160a01b031663f370fdbb60e01b866040516024016117b59190613a61565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516117f391906136b8565b6000604051808303816000865af19150503d8060008114611830576040519150601f19603f3d011682016040523d82523d6000602084013e611835565b606091505b5050905080156108fe57600061184e8660000151612497565b604080518082018252600080825232602080840191825285835260039052929020905181559051600190910180546001600160a01b0319166001600160a01b0390921691909117905585519091501561196f57600a546001600160a01b0316855160405163a9059cbb60e01b815232600482015260248101919091526001600160a01b03919091169063a9059cbb906044016020604051808303816000875af11580156118ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061192391906136d4565b61196f5760405162461bcd60e51b815260206004820152601e60248201527f45766d486f73742068617320696e73756666696369656e742066756e647300006044820152606401610789565b604080518281523260208201527fee00e116b272a1610063bf2a37255152212aeea2d088118e22add5cbe3e9f418910160405180910390a1505050505050565b600c546001600160a01b0316336001600160a01b0316146119e25760405162461bcd60e51b815260040161078990613547565b60006119f5826000015160600151612428565b90506000816001600160a01b031663afb760ac60e01b84604051602401611a1c9190613b07565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051611a5a91906136b8565b6000604051808303816000865af19150503d8060008114611a97576040519150601f19603f3d011682016040523d82523d6000602084013e611a9c565b606091505b505090508015611b46576000611ab58460000151612569565b90506040518060400160405280611acb86612582565b81523260209182018190526000848152600383526040908190208451815593830151600190940180546001600160a01b0319166001600160a01b03909516949094179093558251848152918201527fee00e116b272a1610063bf2a37255152212aeea2d088118e22add5cbe3e9f418910160405180910390a1505b505050565b600c546001600160a01b0316336001600160a01b031614611b7e5760405162461bcd60e51b815260040161078990613547565b815160009081526005602090815260408083209482015183529381529083902082518155908201516001820155910151600290910155565b60a081015160408201515160095460009291611bd191613948565b611bdb9190613707565b9050611bef600a546001600160a01b031690565b6001600160a01b03166323b872dd8360c0015130846040518463ffffffff1660e01b8152600401611c229392919061371a565b6020604051808303816000875af1158015611c41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c6591906136d4565b611c815760405162461bcd60e51b81526004016107899061373e565b600082606001516001600160401b0316600014611d2557611cb460076000015484606001516001600160401b031661247d565b306001600160a01b031663b80777ea6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d169190613775565b611d20919061378e565b611d28565b60005b90506000604051806101000160405280611d40612400565b815285516020820152604001611d5d601580546001810190915590565b6001600160401b0316815260200133604051602001611d94919060609190911b6bffffffffffffffffffffffff1916815260140190565b604051602081830303815290604052815260200185602001518152602001836001600160401b031681526020018560400151815260200185608001516001600160401b0316815250905060405180604001604052808560a0015181526020018560c001516001600160a01b0316815250600080611e1084612569565b81526020019081526020016000206000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555090505080604001516001600160401b03167fb316d746c47c6db4dc6d2020087bb722f66e263e87370ea2ccab21dd0e9bdf2c8260000151836020015184606001518560800151604051602001611eab91906136b8565b6040516020818303038152906040528660a001518760c001518860e001518c60a00151604051610c52989796959493929190613b70565b600b546001600160a01b0316336001600160a01b031614611f155760405162461bcd60e51b81526004016107899061391b565b46600a03611f655760405162461bcd60e51b815260206004820152601c60248201527f43616e6e6f742073657420706172616d73206f6e206d61696e6e6574000000006044820152606401610789565b80516007908155602082015160085560408201516009556060820151600a80546001600160a01b03199081166001600160a01b03938416179091556080840151600b8054831691841691909117905560a0840151600c8054831691841691909117905560c0840151600d8054831691841691909117905560e0840151600e55610100840151600f556101208401516010805490921692169190911790556101408201518291906011906120189082613c41565b50610160820151600b820155610180820151600c8201556101a0820151600d8201906110cd9082613c41565b600c546001600160a01b0316336001600160a01b0316146120775760405162461bcd60e51b815260040161078990613547565b601355565b600b546001600160a01b0316336001600160a01b0316146120af5760405162461bcd60e51b81526004016107899061391b565b46600a146120be57600161216c565b6040805160008082526020820190925261216c9150601180546120e09061350d565b80601f016020809104026020016040519081016040528092919081815260200182805461210c9061350d565b80156121595780601f1061212e57610100808354040283529160200191612159565b820191906000526020600020905b81548152906001019060200180831161213c57829003601f168201915b50505050506125ed90919063ffffffff16565b6121ae5760405162461bcd60e51b81526020600482015260136024820152722ab730baba3437b934bd32b21030b1ba34b7b760691b6044820152606401610789565b600060135560116121bf8282613c41565b5050565b600c546001600160a01b0316336001600160a01b0316146121f65760405162461bcd60e51b815260040161078990613547565b60116121bf8282613c41565b60606007600a0180546106d39061350d565b600c546001600160a01b0316336001600160a01b0316146122475760405162461bcd60e51b815260040161078990613547565b601255565b600d546001600160a01b0316336001600160a01b031614611f655760405162461bcd60e51b815260206004820152601e60248201527f45766d486f73743a204f6e6c79204d616e6167657220636f6e747261637400006044820152606401610789565b600c546001600160a01b0316336001600160a01b0316146122e25760405162461bcd60e51b815260040161078990613547565b60006122f5846000015160800151612428565b90506000816001600160a01b03166312b2524f60e01b8660405160240161231c9190613b07565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161235a91906136b8565b6000604051808303816000865af19150503d8060008114612397576040519150601f19603f3d011682016040523d82523d6000602084013e61239c565b606091505b5050905080156108fe57600083815260016020819052604082208281550180546001600160a01b03191690558551600491906123d790612569565b81526020810191909152604001600020805460ff19169055600a546001600160a01b0316610881565b60606124236040805180820190915260048152634f50544960e01b602082015290565b905090565b60006014825110156124755760405162461bcd60e51b8152602060048201526016602482015275092dcecc2d8d2c840c2c8c8e4cae6e640d8cadccee8d60531b6044820152606401610789565b506014015190565b600081831161248c578161248e565b825b90505b92915050565b6040805160208101909152600080825260a083015151909190825b8181101561250e57828560a0015182815181106124d1576124d1613a32565b60200260200101516040516020016124ea929190613d00565b6040516020818303038152906040529250808061250690613a48565b9150506124b2565b508360000151846020015185604001518660c0015187608001518860600151878a60e0015160405160200161254a989796959493929190613d2f565b6040516020818303038152906040528051906020012092505050919050565b600061257482612617565b805190602001209050919050565b60006125918260000151612617565b8260200151836040015184606001516040516020016125b293929190613dcb565b60408051601f19818403018152908290526125d09291602001613d00565b604051602081830303815290604052805190602001209050919050565b6000815183511461260057506000612491565b508151602091820181902091909201919091201490565b60608160000151826020015183604001518460a00151856060015186608001518760c001518860e00151604051602001612658989796959493929190613e07565b6040516020818303038152906040529050919050565b60005b83811015612689578181015183820152602001612671565b50506000910152565b600081518084526126aa81602086016020860161266e565b601f01601f19169290920160200192915050565b60208152600061248e6020830184612692565b634e487b7160e01b600052604160045260246000fd5b60405161010081016001600160401b038111828210171561270a5761270a6126d1565b60405290565b604080519081016001600160401b038111828210171561270a5761270a6126d1565b60405160e081016001600160401b038111828210171561270a5761270a6126d1565b60405160c081016001600160401b038111828210171561270a5761270a6126d1565b6040516101c081016001600160401b038111828210171561270a5761270a6126d1565b604051601f8201601f191681016001600160401b03811182821017156127c1576127c16126d1565b604052919050565b600082601f8301126127da57600080fd5b81356001600160401b038111156127f3576127f36126d1565b612806601f8201601f1916602001612799565b81815284602083860101111561281b57600080fd5b816020850160208301376000918101602001919091529392505050565b80356001600160401b038116811461284f57600080fd5b919050565b60006001600160401b0382111561286d5761286d6126d1565b5060051b60200190565b600082601f83011261288857600080fd5b8135602061289d61289883612854565b612799565b82815260059290921b840181019181810190868411156128bc57600080fd5b8286015b848110156128fb5780356001600160401b038111156128df5760008081fd5b6128ed8986838b01016127c9565b8452509183019183016128c0565b509695505050505050565b6000610100828403121561291957600080fd5b6129216126e7565b905081356001600160401b038082111561293a57600080fd5b612946858386016127c9565b8352602084013591508082111561295c57600080fd5b612968858386016127c9565b602084015261297960408501612838565b6040840152606084013591508082111561299257600080fd5b61299e858386016127c9565b60608401526129af60808501612838565b608084015260a08401359150808211156129c857600080fd5b506129d584828501612877565b60a0830152506129e760c08301612838565b60c08201526129f860e08301612838565b60e082015292915050565b80356001600160a01b038116811461284f57600080fd5b600060408284031215612a2c57600080fd5b612a34612710565b905081358152612a4660208301612a03565b602082015292915050565b600080600060808486031215612a6657600080fd5b83356001600160401b03811115612a7c57600080fd5b612a8886828701612906565b935050612a988560208601612a1a565b9150606084013590509250925092565b600060408284031215612aba57600080fd5b612ac2612710565b9050813581526020820135602082015292915050565b60008060608385031215612aeb57600080fd5b612af58484612aa8565b946040939093013593505050565b600060208284031215612b1557600080fd5b81356001600160401b0380821115612b2c57600080fd5b9083019060e08286031215612b4057600080fd5b612b48612732565b823582811115612b5757600080fd5b612b63878286016127c9565b825250612b7260208401612838565b6020820152604083013582811115612b8957600080fd5b612b9587828601612877565b604083015250612ba760608401612838565b6060820152612bb860808401612838565b608082015260a083013560a0820152612bd360c08401612a03565b60c082015295945050505050565b60006101008284031215612bf457600080fd5b612bfc6126e7565b905081356001600160401b0380821115612c1557600080fd5b612c21858386016127c9565b83526020840135915080821115612c3757600080fd5b612c43858386016127c9565b6020840152612c5460408501612838565b60408401526060840135915080821115612c6d57600080fd5b612c79858386016127c9565b60608401526080840135915080821115612c9257600080fd5b612c9e858386016127c9565b6080840152612caf60a08501612838565b60a084015260c0840135915080821115612cc857600080fd5b50612cd5848285016127c9565b60c0830152506129f860e08301612838565b600080600060808486031215612cfc57600080fd5b83356001600160401b03811115612d1257600080fd5b612a8886828701612be1565b600060208284031215612d3057600080fd5b5035919050565b80151581146110d157600080fd5b600060208284031215612d5757600080fd5b8135612d6281612d37565b9392505050565b600060408284031215612d7b57600080fd5b61248e8383612aa8565b6020815281516020820152602082015160408201526040820151606082015260006060830151612dc060808401826001600160a01b03169052565b5060808301516001600160a01b03811660a08401525060a08301516001600160a01b03811660c08401525060c08301516001600160a01b03811660e08401525060e08301516101008381019190915283015161012080840191909152830151610140612e36818501836001600160a01b03169052565b808501519150506101c06101608181860152612e566101e0860184612692565b90860151610180868101919091528601516101a080870191909152860151858203601f190183870152909250612e8c8382612692565b9695505050505050565b600060208284031215612ea857600080fd5b81356001600160401b03811115612ebe57600080fd5b612eca84828501612be1565b949350505050565b600060408284031215612ee457600080fd5b604051604081018181106001600160401b0382111715612f0657612f066126d1565b604052612f1283612a03565b8152602083013560208201528091505092915050565b600060208284031215612f3a57600080fd5b81356001600160401b0380821115612f5157600080fd5b9083019060c08286031215612f6557600080fd5b612f6d612754565b823582811115612f7c57600080fd5b612f8887828601612be1565b825250602083013582811115612f9d57600080fd5b612fa9878286016127c9565b602083015250612fbb60408401612838565b6040820152612fcc60608401612838565b606082015260808301356080820152612fe760a08401612a03565b60a082015295945050505050565b6000806060838503121561300857600080fd5b82356001600160401b038082111561301f57600080fd5b908401906040828703121561303357600080fd5b61303b612710565b82358281111561304a57600080fd5b61305688828601612906565b8252506020808401358381111561306c57600080fd5b80850194505087601f85011261308157600080fd5b833561308f61289882612854565b81815260059190911b8501820190828101908a8311156130ae57600080fd5b8387015b83811015613140578035878111156130ca5760008081fd5b88016040818e03601f190112156130e15760008081fd5b6130e9612710565b86820135898111156130fb5760008081fd5b6131098f89838601016127c9565b82525060408201358981111561311f5760008081fd5b61312d8f89838601016127c9565b82890152508452509184019184016130b2565b50808486015250505081955061315888828901612a1a565b9450505050509250929050565b60006080828403121561317757600080fd5b604051608081016001600160401b03828210818311171561319a5761319a6126d1565b8160405282935084359150808211156131b257600080fd5b6131be86838701612be1565b835260208501359150808211156131d457600080fd5b506131e1858286016127c9565b6020830152506131f360408401612838565b604082015261320460608401612838565b60608201525092915050565b60006020828403121561322257600080fd5b81356001600160401b0381111561323857600080fd5b612eca84828501613165565b60008082840360a081121561325857600080fd5b6132628585612aa8565b92506060603f198201121561327657600080fd5b50604051606081018181106001600160401b0382111715613299576132996126d1565b8060405250604084013581526060840135602082015260808401356040820152809150509250929050565b6000602082840312156132d657600080fd5b81356001600160401b03808211156132ed57600080fd5b9083019060e0828603121561330157600080fd5b613309612732565b82358281111561331857600080fd5b613324878286016127c9565b82525060208301358281111561333957600080fd5b613345878286016127c9565b60208301525060408301358281111561335d57600080fd5b612b95878286016127c9565b60006020828403121561337b57600080fd5b81356001600160401b038082111561339257600080fd5b908301906101c082860312156133a757600080fd5b6133af612776565b8235815260208301356020820152604083013560408201526133d360608401612a03565b60608201526133e460808401612a03565b60808201526133f560a08401612a03565b60a082015261340660c08401612a03565b60c082015260e083013560e082015261010080840135818301525061012061342f818501612a03565b90820152610140838101358381111561344757600080fd5b613453888287016127c9565b8284015250506101608084013581830152506101808084013581830152506101a0808401358381111561348557600080fd5b613491888287016127c9565b918301919091525095945050505050565b6000602082840312156134b457600080fd5b81356001600160401b038111156134ca57600080fd5b612eca848285016127c9565b6000806000608084860312156134eb57600080fd5b83356001600160401b0381111561350157600080fd5b612a8886828701613165565b600181811c9082168061352157607f821691505b60208210810361354157634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526015908201527422bb36a437b9ba1d1027b7363c903430b7323632b960591b604082015260600190565b600081518084526020808501808196508360051b8101915082860160005b858110156135be5782840389526135ac848351612692565b98850198935090840190600101613594565b5091979650505050505050565b600061010082518185526135e182860182612692565b915050602083015184820360208601526135fb8282612692565b915050604083015161361860408601826001600160401b03169052565b50606083015184820360608601526136308282612692565b915050608083015161364d60808601826001600160401b03169052565b5060a083015184820360a08601526136658282613576565b91505060c083015161368260c08601826001600160401b03169052565b5060e083015161369d60e08601826001600160401b03169052565b509392505050565b60208152600061248e60208301846135cb565b600082516136ca81846020870161266e565b9190910192915050565b6000602082840312156136e657600080fd5b8151612d6281612d37565b634e487b7160e01b600052601160045260246000fd5b80820180821115612491576124916136f1565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6020808252601c908201527f50617965722068617320696e73756666696369656e742066756e647300000000604082015260600190565b60006020828403121561378757600080fd5b5051919050565b6001600160401b038181168382160190808211156137ae576137ae6136f1565b5092915050565b60006101008083526137c98184018c612692565b905082810360208401526137dd818b612692565b905082810360408401526137f1818a612692565b905082810360608401526138058189613576565b6001600160401b03978816608085015295871660a084015250509190931660c082015260e00191909152949350505050565b6000610100825181855261384d82860182612692565b915050602083015184820360208601526138678282612692565b915050604083015161388460408601826001600160401b03169052565b506060830151848203606086015261389c8282612692565b915050608083015184820360808601526138b68282612692565b91505060a08301516138d360a08601826001600160401b03169052565b5060c083015184820360c08601526138eb8282612692565b91505060e083015161369d60e08601826001600160401b03169052565b60208152600061248e6020830184613837565b60208082526013908201527222bb36a437b9ba1d1027b7363c9030b236b4b760691b604082015260600190565b8082028115828204841417612491576124916136f1565b60006101608083526139738184018f612692565b90508281036020840152613987818e612692565b9050828103604084015261399b818d612692565b905082810360608401526139af818c612692565b90506001600160401b038a16608084015282810360a08401526139d2818a612692565b6001600160401b03891660c0850152905082810360e08401526139f58188612692565b915050613a0e6101008301866001600160401b03169052565b6001600160401b039390931661012082015261014001529998505050505050505050565b634e487b7160e01b600052603260045260246000fd5b600060018201613a5a57613a5a6136f1565b5060010190565b60006020808352835160408083860152613a7e60608601836135cb565b83870151601f1987830381018489015281518084529294509085019184860190600581901b8601870160005b82811015613af8578488830301845285518051888452613acc89850182612692565b918b0151848303858d0152919050613ae48183612692565b978b0197958b019593505050600101613aaa565b509a9950505050505050505050565b602081526000825160806020840152613b2360a0840182613837565b90506020840151601f19848303016040850152613b408282612692565b91505060408401516001600160401b03808216606086015280606087015116608086015250508091505092915050565b6000610100808352613b848184018c612692565b90508281036020840152613b98818b612692565b90508281036040840152613bac818a612692565b90508281036060840152613bc08189612692565b90506001600160401b03808816608085015283820360a0850152613be48288612692565b951660c0840152505060e001529695505050505050565b601f821115611b4657600081815260208120601f850160051c81016020861015613c225750805b601f850160051c820191505b818110156108fc57828155600101613c2e565b81516001600160401b03811115613c5a57613c5a6126d1565b613c6e81613c68845461350d565b84613bfb565b602080601f831160018114613ca35760008415613c8b5750858301515b600019600386901b1c1916600185901b1785556108fc565b600085815260208120601f198616915b82811015613cd257888601518255948401946001909101908401613cb3565b5085821015613cf05787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60008351613d1281846020880161266e565b835190830190613d2681836020880161266e565b01949350505050565b60008951613d41818460208e0161266e565b895190830190613d55818360208e0161266e565b60c08a811b6001600160c01b03199081169390920192835289811b8216600884015288901b811660108301528651613d94816018850160208b0161266e565b8651920191613daa816018850160208a0161266e565b60c09590951b16930160188101939093525050602001979650505050505050565b60008451613ddd81846020890161266e565b6001600160c01b031960c095861b8116919093019081529290931b16600882015260100192915050565b60008951613e19818460208e0161266e565b895190830190613e2d818360208e0161266e565b60c08a811b6001600160c01b03199081169390920192835289901b811660088301528751613e62816010850160208c0161266e565b8751920191613e78816010850160208b0161266e565b8651920191613e8e816010850160208a0161266e565b60c09590951b1693016010810193909352505060180197965050505050505056fea264697066735822122069164b40a865a3d9d07f04cefed61beebfb8a50890e28acd3f00caff9a1f2d7064736f6c63430008110033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001c2000000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000000000000000000000000000000aa87bee538000000000000000000000000000287c570f009b7d47c360618f12397acfa92c412a00000000000000000000000000046e40b355d40a5b3731e9fd584ff4c3446cd6000000000000000000000000d0a8c8fb78ace3628ba14ecb3f240b4fcf6c98bb00000000000000000000000024e8254124c5077b79623959308ac8819134efd600000000000000000000000000000000000000000000000000000000001baf800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e307cdf8f91a08740655d0df1d8bab9cd245e52900000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b4b5553414d412d34333734000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : params (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
-----Encoded View---------------
18 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [1] : 0000000000000000000000000000000000000000000000000000000000001c20
Arg [2] : 00000000000000000000000000000000000000000000000006f05b59d3b20000
Arg [3] : 000000000000000000000000000000000000000000000000000aa87bee538000
Arg [4] : 000000000000000000000000287c570f009b7d47c360618f12397acfa92c412a
Arg [5] : 00000000000000000000000000046e40b355d40a5b3731e9fd584ff4c3446cd6
Arg [6] : 000000000000000000000000d0a8c8fb78ace3628ba14ecb3f240b4fcf6c98bb
Arg [7] : 00000000000000000000000024e8254124c5077b79623959308ac8819134efd6
Arg [8] : 00000000000000000000000000000000000000000000000000000000001baf80
Arg [9] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [10] : 000000000000000000000000e307cdf8f91a08740655d0df1d8bab9cd245e529
Arg [11] : 00000000000000000000000000000000000000000000000000000000000001c0
Arg [12] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [14] : 00000000000000000000000000000000000000000000000000000000000001e0
Arg [15] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [16] : 000000000000000000000000000000000000000000000000000000000000000b
Arg [17] : 4b5553414d412d34333734000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.