@layerzerolabs/lz-evm-sdk-v1 3.0.113 → 3.0.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/artifacts/verification/verification-data-4cacbc20c3ff94e1fab58d8d49589534.json +39 -0
- package/artifacts/verification/verification-data-5e6f8a9cc160013d3f2ed5cace5b3625.json +39 -0
- package/artifacts/verification/verification-data-7413301ee5ee573cec0ec95730482c21.json +39 -0
- package/artifacts/{verification-data.json → verification/verification-data-86687dceb611cadccbf9c44600d6dfef.json} +103 -171
- package/artifacts/verification/verification-data-b2be3b6b9aa4d482b239dd3c7b998b43.json +69 -0
- package/artifacts/verification/verification-data-b326d48ebf6e71f1e29ebf99156fbfff.json +39 -0
- package/artifacts/verification/verification-data-e7c1a5680ae8cae1ec9ffaf4cdbaed68.json +267 -0
- package/artifacts-tron/{verification-data.json → verification/verification-data-0c559044f5a1e91d85ee409c7cc0fc75.json} +29 -46
- package/artifacts-tron/verification/verification-data-1698b18cef59145feb6419b3eacba549.json +39 -0
- package/artifacts-tron/verification/verification-data-24492b3a86a1195fe1b202109347e27e.json +39 -0
- package/artifacts-tron/verification/verification-data-8a65080bfd6e652b21df7756fb5779c9.json +39 -0
- package/artifacts-tron/verification/verification-data-d25a40a50e55d137530e079a13031b48.json +39 -0
- package/artifacts-tron/verification/verification-data-edf0138b97898d26cfc0e872ce8b1c0b.json +69 -0
- package/artifacts-zk/{verification-data.json → verification/verification-data-c07ea489478e10846c028cfcb72e5b2e.json} +24 -1
- package/deployments/arbitrum-sandbox-local/DefaultProxyAdmin.json +10 -10
- package/deployments/arbitrum-sandbox-local/Endpoint.json +7 -7
- package/deployments/arbitrum-sandbox-local/FPValidator.json +4 -4
- package/deployments/arbitrum-sandbox-local/MPTValidator01.json +4 -4
- package/deployments/arbitrum-sandbox-local/NonceContract.json +4 -4
- package/deployments/arbitrum-sandbox-local/RelayerV2.json +16 -16
- package/deployments/arbitrum-sandbox-local/RelayerV2_Implementation.json +4 -4
- package/deployments/arbitrum-sandbox-local/RelayerV2_Proxy.json +16 -16
- package/deployments/arbitrum-sandbox-local/TreasuryV2.json +7 -7
- package/deployments/arbitrum-sandbox-local/UltraLightNode.json +7 -7
- package/deployments/arbitrum-sandbox-local/UltraLightNodeV2.json +7 -7
- package/deployments/bsc-sandbox-local/DefaultProxyAdmin.json +10 -10
- package/deployments/bsc-sandbox-local/Endpoint.json +7 -7
- package/deployments/bsc-sandbox-local/FPValidator.json +4 -4
- package/deployments/bsc-sandbox-local/MPTValidator01.json +4 -4
- package/deployments/bsc-sandbox-local/NonceContract.json +4 -4
- package/deployments/bsc-sandbox-local/RelayerV2.json +16 -16
- package/deployments/bsc-sandbox-local/RelayerV2_Implementation.json +4 -4
- package/deployments/bsc-sandbox-local/RelayerV2_Proxy.json +16 -16
- package/deployments/bsc-sandbox-local/TreasuryV2.json +7 -7
- package/deployments/bsc-sandbox-local/UltraLightNode.json +7 -7
- package/deployments/bsc-sandbox-local/UltraLightNodeV2.json +7 -7
- package/deployments/ethereum-sandbox-local/DefaultProxyAdmin.json +7 -7
- package/deployments/ethereum-sandbox-local/Endpoint.json +5 -5
- package/deployments/ethereum-sandbox-local/FPValidator.json +3 -3
- package/deployments/ethereum-sandbox-local/MPTValidator01.json +3 -3
- package/deployments/ethereum-sandbox-local/NonceContract.json +3 -3
- package/deployments/ethereum-sandbox-local/RelayerV2.json +11 -11
- package/deployments/ethereum-sandbox-local/RelayerV2_Implementation.json +3 -3
- package/deployments/ethereum-sandbox-local/RelayerV2_Proxy.json +11 -11
- package/deployments/ethereum-sandbox-local/TreasuryV2.json +5 -5
- package/deployments/ethereum-sandbox-local/UltraLightNode.json +5 -5
- package/deployments/ethereum-sandbox-local/UltraLightNodeV2.json +5 -5
- package/deployments/humanity-mainnet/DefaultProxyAdmin.json +273 -0
- package/deployments/humanity-mainnet/Endpoint.json +1282 -0
- package/deployments/humanity-mainnet/FPValidator.json +382 -0
- package/deployments/humanity-mainnet/MPTValidator01.json +395 -0
- package/deployments/humanity-mainnet/NonceContract.json +159 -0
- package/deployments/humanity-mainnet/RelayerV2.json +1415 -0
- package/deployments/humanity-mainnet/RelayerV2_Implementation.json +1612 -0
- package/deployments/humanity-mainnet/RelayerV2_Proxy.json +245 -0
- package/deployments/humanity-mainnet/TreasuryV2.json +458 -0
- package/deployments/humanity-mainnet/UltraLightNodeV2.json +1816 -0
- package/deployments/humanity-testnet/DefaultProxyAdmin.json +273 -0
- package/deployments/humanity-testnet/Endpoint.json +1282 -0
- package/deployments/humanity-testnet/FPValidator.json +382 -0
- package/deployments/humanity-testnet/MPTValidator01.json +395 -0
- package/deployments/humanity-testnet/NonceContract.json +159 -0
- package/deployments/humanity-testnet/RelayerV2.json +1415 -0
- package/deployments/humanity-testnet/RelayerV2_Implementation.json +1612 -0
- package/deployments/humanity-testnet/RelayerV2_Proxy.json +245 -0
- package/deployments/humanity-testnet/TreasuryV2.json +458 -0
- package/deployments/humanity-testnet/UltraLightNodeV2.json +1816 -0
- package/deployments/polygon-sandbox-local/DefaultProxyAdmin.json +10 -10
- package/deployments/polygon-sandbox-local/Endpoint.json +7 -7
- package/deployments/polygon-sandbox-local/FPValidator.json +4 -4
- package/deployments/polygon-sandbox-local/MPTValidator01.json +4 -4
- package/deployments/polygon-sandbox-local/NonceContract.json +4 -4
- package/deployments/polygon-sandbox-local/RelayerV2.json +16 -16
- package/deployments/polygon-sandbox-local/RelayerV2_Implementation.json +4 -4
- package/deployments/polygon-sandbox-local/RelayerV2_Proxy.json +16 -16
- package/deployments/polygon-sandbox-local/TreasuryV2.json +7 -7
- package/deployments/polygon-sandbox-local/UltraLightNode.json +7 -7
- package/deployments/polygon-sandbox-local/UltraLightNodeV2.json +7 -7
- package/deployments/tron-sandbox-local/DefaultProxyAdmin.json +14 -14
- package/deployments/tron-sandbox-local/Endpoint.json +10 -10
- package/deployments/tron-sandbox-local/FPValidator.json +6 -6
- package/deployments/tron-sandbox-local/MPTValidator01.json +6 -6
- package/deployments/tron-sandbox-local/NonceContract.json +7 -7
- package/deployments/tron-sandbox-local/RelayerV2.json +31 -31
- package/deployments/tron-sandbox-local/RelayerV2_Implementation.json +6 -6
- package/deployments/tron-sandbox-local/RelayerV2_Proxy.json +28 -28
- package/deployments/tron-sandbox-local/TreasuryV2.json +11 -11
- package/deployments/tron-sandbox-local/UltraLightNode.json +11 -11
- package/deployments/tron-sandbox-local/UltraLightNodeV2.json +12 -12
- package/package.json +10 -10
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"id": "0c559044f5a1e91d85ee409c7cc0fc75",
|
|
2
3
|
"solcLongVersion": "0.7.6+commit.d1802f25.Emscripten.clang",
|
|
3
4
|
"input": {
|
|
5
|
+
"language": "Solidity",
|
|
4
6
|
"sources": {
|
|
5
7
|
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
|
|
6
8
|
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/Initializable.sol\";\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal initializer {\n __Context_init_unchained();\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal initializer {\n address msgSender = _msgSender();\n _owner = msgSender;\n emit OwnershipTransferred(address(0), msgSender);\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n emit OwnershipTransferred(_owner, address(0));\n _owner = address(0);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n emit OwnershipTransferred(_owner, newOwner);\n _owner = newOwner;\n }\n uint256[49] private __gap;\n}\n"
|
|
@@ -232,53 +234,34 @@
|
|
|
232
234
|
},
|
|
233
235
|
"hardhat-deploy/solc_0.7/proxy/Proxied.sol": {
|
|
234
236
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.7.0;\n\nabstract contract Proxied {\n /// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them\n /// It also allows these functions to be called inside a contructor\n /// even if the contract is meant to be used without proxy\n modifier proxied() {\n address proxyAdminAddress = _proxyAdmin();\n // With hardhat-deploy proxies\n // the proxyAdminAddress is zero only for the implementation contract\n // if the implementation contract want to be used as a standalone/immutable contract\n // it simply has to execute the `proxied` function\n // This ensure the proxyAdminAddress is never zero post deployment\n // And allow you to keep the same code for both proxied contract and immutable contract\n if (proxyAdminAddress == address(0)) {\n // ensure can not be called twice when used outside of proxy : no admin\n // solhint-disable-next-line security/no-inline-assembly\n assembly {\n sstore(\n 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,\n 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n )\n }\n } else {\n require(msg.sender == proxyAdminAddress);\n }\n _;\n }\n\n modifier onlyProxyAdmin() {\n require(msg.sender == _proxyAdmin(), \"NOT_AUTHORIZED\");\n _;\n }\n\n function _proxyAdmin() internal view returns (address ownerAddress) {\n // solhint-disable-next-line security/no-inline-assembly\n assembly {\n ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)\n }\n }\n}\n"
|
|
235
|
-
},
|
|
236
|
-
"contracts/mocks/PacketData.sol": {
|
|
237
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\n\ncontract PacketData {\n event Packet(uint16 chainId, bytes payload);\n event Packet(bytes payload);\n\n function emitPacketV1(\n uint64 nonce,\n address ua,\n uint16 dstChainId,\n address dstAddress,\n bytes calldata payload\n ) public {\n bytes memory encodedPayload = abi.encodePacked(nonce, ua, dstAddress, payload);\n emit Packet(dstChainId, encodedPayload);\n }\n\n function emitPacketV2(\n uint64 nonce,\n uint16 localChainId,\n address ua,\n uint16 dstChainId,\n address dstAddress,\n bytes calldata payload\n ) public {\n bytes memory encodedPayload = abi.encodePacked(nonce, localChainId, ua, dstChainId, dstAddress, payload);\n emit Packet(encodedPayload);\n }\n}\n"
|
|
238
|
-
},
|
|
239
|
-
"contracts/mocks/IsContract.sol": {
|
|
240
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\n\ncontract IsContract {\n function isAddressContract(address addr) external view returns (bool) {\n // check if the toAddress is a contract. We are not concerned about addresses that pretend to be wallets. because worst case we just delete their payload if being malicious\n // we can guarantee that if a size > 0, then the contract is definitely a contract address in this context\n uint size;\n assembly {\n size := extcodesize(addr)\n }\n return size != 0;\n }\n}\n"
|
|
241
|
-
},
|
|
242
|
-
"contracts/arbitrum/interfaces/ArbSys.sol": {
|
|
243
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.4.21 <0.9.0;\n\n/**\n * @title Precompiled contract that exists in every Arbitrum chain at address(100), 0x0000000000000000000000000000000000000064. Exposes a variety of system-level functionality.\n */\ninterface ArbSys {\n /**\n * @notice Get internal version number identifying an ArbOS build\n * @return version number as int\n */\n function arbOSVersion() external pure returns (uint);\n\n function arbChainID() external view returns (uint);\n\n /**\n * @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)\n * @return block number as int\n */\n function arbBlockNumber() external view returns (uint);\n\n /**\n * @notice Send given amount of Eth to dest from sender.\n * This is a convenience function, which is equivalent to calling sendTxToL1 with empty calldataForL1.\n * @param destination recipient address on L1\n * @return unique identifier for this L2-to-L1 transaction.\n */\n function withdrawEth(address destination) external payable returns (uint);\n\n /**\n * @notice Send a transaction to L1\n * @param destination recipient address on L1\n * @param calldataForL1 (optional) calldata for L1 contract call\n * @return a unique identifier for this L2-to-L1 transaction.\n */\n function sendTxToL1(address destination, bytes calldata calldataForL1) external payable returns (uint);\n\n /**\n * @notice get the number of transactions issued by the given external account or the account sequence number of the given contract\n * @param account target account\n * @return the number of transactions issued by the given external account or the account sequence number of the given contract\n */\n function getTransactionCount(address account) external view returns (uint256);\n\n /**\n * @notice get the value of target L2 storage slot\n * This function is only callable from address 0 to prevent contracts from being able to call it\n * @param account target account\n * @param index target index of storage slot\n * @return stotage value for the given account at the given index\n */\n function getStorageAt(address account, uint256 index) external view returns (uint256);\n\n /**\n * @notice check if current call is coming from l1\n * @return true if the caller of this was called directly from L1\n */\n function isTopLevelCall() external view returns (bool);\n\n /**\n * @notice check if the caller (of this caller of this) is an aliased L1 contract address\n * @return true iff the caller's address is an alias for an L1 contract address\n */\n function wasMyCallersAddressAliased() external view returns (bool);\n\n /**\n * @notice return the address of the caller (of this caller of this), without applying L1 contract address aliasing\n * @return address of the caller's caller, without applying L1 contract address aliasing\n */\n function myCallersAddressWithoutAliasing() external view returns (address);\n\n /**\n * @notice map L1 sender contract address to its L2 alias\n * @param sender sender address\n * @param dest destination address\n * @return aliased sender address\n */\n function mapL1SenderContractAddressToL2Alias(address sender, address dest) external pure returns (address);\n\n /**\n * @notice get the caller's amount of available storage gas\n * @return amount of storage gas available to the caller\n */\n function getStorageGasAvailable() external view returns (uint);\n\n event L2ToL1Transaction(\n address caller,\n address indexed destination,\n uint indexed uniqueId,\n uint indexed batchNumber,\n uint indexInBatch,\n uint arbBlockNum,\n uint ethBlockNum,\n uint timestamp,\n uint callvalue,\n bytes data\n );\n}\n"
|
|
244
|
-
},
|
|
245
|
-
"contracts/mocks/ContractOne.sol": {
|
|
246
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\n\ncontract ContractOne {\n uint x;\n\n function setIt(uint _x) external {\n x = _x;\n }\n}\n"
|
|
247
|
-
},
|
|
248
|
-
"contracts/precrime/example/inherit/CounterI.sol": {
|
|
249
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport \"./CounterPrecrime.sol\";\n\ncontract CounterI is CounterPrecrime {\n // keep track of how many messages have been received from other chains\n uint public totalCount;\n mapping(uint32 => uint) public inboundCount;\n mapping(uint32 => uint) public outboundCount;\n\n event Send(uint16 dstChainId);\n event Receive(uint16 srcChainId);\n\n uint16 public chainId;\n\n constructor(uint16 _chainId) CounterPrecrime(_chainId) {\n chainId = _chainId;\n }\n\n function lzReceive(uint16 _srcChainId) public {\n inboundCount[_srcChainId]++;\n totalCount++;\n\n emit Receive(_srcChainId);\n }\n\n function increment(uint16 _dstChainId) external {\n outboundCount[_dstChainId]++;\n\n emit Send(_dstChainId);\n }\n\n function brokeIncrement(uint16 _dstChainId) external {\n emit Send(_dstChainId);\n }\n\n function brokeTotalCount() external {\n totalCount++;\n }\n\n function getInboundNonce(uint32 _chainId) public view returns (uint) {\n // in reality, this would be a call to the LayerZero endpoint\n return inboundCount[_chainId];\n }\n\n // ------------- precrime -----------------\n function _lzReceiveByPacket(Packet calldata _packet) internal virtual override {\n lzReceive(uint16(_packet.srcChainId));\n }\n\n function getCountState(uint16[] memory peers) public view virtual override returns (CountState memory) {\n ChainPathCount[] memory chainPathCounts = new ChainPathCount[](peers.length);\n for (uint i = 0; i < peers.length; i++) {\n uint16 peer = peers[i];\n chainPathCounts[i] = ChainPathCount({\n eid: peer,\n inboundCount: inboundCount[peer],\n outboundCount: outboundCount[peer]\n });\n }\n\n CountState memory countState = CountState({totalCount: totalCount, chainPathCounts: chainPathCounts});\n\n return countState;\n }\n\n function _getInboundNonce(Packet memory packet) internal view override returns (uint64) {\n // in reality, this would be a call to the LayerZero endpoint\n return uint64(inboundCount[packet.srcChainId]);\n }\n}\n"
|
|
250
|
-
},
|
|
251
|
-
"contracts/precrime/example/inherit/CounterPrecrime.sol": {
|
|
252
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport \"../../PreCrime.sol\";\n\nabstract contract CounterPrecrime is PreCrime {\n uint16[] public remoteChainIds;\n bytes32[] public remotePrecrimeAddresses;\n\n struct SimulationResult {\n uint16 chainId;\n CountState countState;\n }\n\n struct CountState {\n uint totalCount;\n ChainPathCount[] chainPathCounts;\n }\n\n struct ChainPathCount {\n uint16 eid;\n uint inboundCount;\n uint outboundCount;\n }\n\n constructor(uint16 _localChainId) PreCrime(_localChainId) {\n maxBatchSize = 10;\n }\n\n function setRemotePrecrimeAddresses(\n uint16[] memory _remoteChainIds,\n bytes32[] memory _remotePrecrimeAddresses\n ) public onlyPrecrimeAdmin {\n require(_remoteChainIds.length == _remotePrecrimeAddresses.length, \"Precrime: invalid size\");\n remoteChainIds = _remoteChainIds;\n remotePrecrimeAddresses = _remotePrecrimeAddresses;\n }\n\n function _simulate(Packet[] calldata _packets) internal override returns (uint16 code, bytes memory data) {\n // simulate\n for (uint256 i = 0; i < _packets.length; i++) {\n _lzReceiveByPacket(_packets[i]);\n }\n\n // return simulation result\n bytes memory result = abi.encode(\n SimulationResult({chainId: localChainId, countState: getCountState(remoteChainIds)})\n );\n return (CODE_SUCCESS, result);\n }\n\n function _precrime(\n bytes[] memory _simulation\n ) internal view virtual override returns (uint16 code, bytes memory reason) {\n (SimulationResult memory localResult, SimulationResult[] memory results) = _getLocalSimulateResult(_simulation);\n\n uint sumOutboundCount = 0;\n // for each chainPathCount, find the chainPathCount and check the counts\n for (uint256 j = 0; j < localResult.countState.chainPathCounts.length; j++) {\n ChainPathCount memory cpCount = localResult.countState.chainPathCounts[j];\n // find remote to local count state\n // should provide all peers simulated results\n ChainPathCount memory remoteCp = _getRemoteCpCount(results, cpCount.eid);\n (code, reason) = _assertChainPathCount(cpCount, remoteCp);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n sumOutboundCount += remoteCp.outboundCount; // remote to local outbound count\n }\n (code, reason) = _assertTotalCount(localResult.countState, sumOutboundCount);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n\n return (CODE_SUCCESS, \"\");\n }\n\n function _lzReceiveByPacket(Packet calldata _packet) internal virtual;\n\n /**\n * @notice Get the count states for a list of peers\n * @param peers - the list of remote chainId to get counts for\n * @return counts - the CountState with the total count and the chain path counts\n */\n function getCountState(uint16[] memory peers) public view virtual returns (CountState memory);\n\n function _getRemoteCpCount(\n SimulationResult[] memory _results,\n uint16 _remoteId\n ) internal view returns (ChainPathCount memory) {\n uint localEid = localChainId;\n for (uint256 i = 0; i < _results.length; i++) {\n SimulationResult memory remoteResult = _results[i];\n if (remoteResult.chainId == _remoteId) {\n for (uint256 j = 0; j < remoteResult.countState.chainPathCounts.length; j++) {\n ChainPathCount memory cpCount = remoteResult.countState.chainPathCounts[j];\n if (cpCount.eid == localEid) {\n // find to localEid path\n return cpCount;\n }\n }\n }\n }\n revert(\"Precrime: countState not found, are you missing a simulation?\");\n }\n\n function _getLocalSimulateResult(\n bytes[] memory _simulation\n ) internal view returns (SimulationResult memory localResult, SimulationResult[] memory results) {\n // decode results\n results = new SimulationResult[](_simulation.length);\n for (uint256 i = 0; i < _simulation.length; i++) {\n bytes memory result = _simulation[i];\n results[i] = abi.decode(result, (SimulationResult));\n if (results[i].chainId == localChainId) {\n localResult = results[i];\n }\n }\n }\n\n function _assertChainPathCount(\n ChainPathCount memory _localCpCount,\n ChainPathCount memory _remoteCpCount\n ) internal pure returns (uint16 code, bytes memory reason) {\n if (_localCpCount.inboundCount > _remoteCpCount.outboundCount) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: inboundCount > outboundCount\");\n }\n if (_localCpCount.outboundCount > _remoteCpCount.inboundCount) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: outboundCount > inboundCount\");\n }\n return (CODE_SUCCESS, \"\");\n }\n\n function _assertTotalCount(\n CountState memory _localCount,\n uint _sumOutbound\n ) internal pure returns (uint16 code, bytes memory reason) {\n if (_localCount.totalCount > _sumOutbound) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: totalCount > sum outboundCount\");\n }\n }\n\n function _remotePrecrimeAddress(\n Packet[] calldata _packets\n ) internal view override returns (uint16[] memory chainIds, bytes32[] memory precrimeAddresses) {\n if (_packets.length == 0) {\n return (remoteChainIds, remotePrecrimeAddresses);\n }\n\n // only return related remotes\n uint16 size = _getRelatedRemoteSize(_packets);\n if (size > 0) {\n chainIds = new uint16[](size);\n uint256 k = 0;\n precrimeAddresses = new bytes32[](size);\n for (uint16 i = 0; i < remoteChainIds.length; i++) {\n for (uint16 j = 0; j < _packets.length; j++) {\n uint16 srcChainId = _packets[j].srcChainId;\n if (remoteChainIds[i] == srcChainId) {\n chainIds[k] = srcChainId;\n precrimeAddresses[k] = remotePrecrimeAddresses[i];\n k++;\n break;\n }\n }\n }\n }\n }\n\n function _getRelatedRemoteSize(Packet[] memory _packets) internal view returns (uint16 size) {\n for (uint16 i = 0; i < remoteChainIds.length; i++) {\n for (uint16 j = 0; j < _packets.length; j++) {\n if (remoteChainIds[i] == _packets[j].srcChainId) {\n size++;\n break;\n }\n }\n }\n }\n}\n"
|
|
253
|
-
},
|
|
254
|
-
"contracts/precrime/example/view/CounterPrecrimeView.sol": {
|
|
255
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport \"../../PreCrimeView.sol\";\nimport \"./CounterView.sol\";\nimport \"./CounterV.sol\";\n\ncontract CounterPrecrimeView is PreCrimeView {\n CounterView public counterView;\n\n uint16[] public remoteChainIds;\n bytes32[] public remotePrecrimeAddresses;\n\n struct SimulationResult {\n uint16 chainId;\n CounterView.CountState countState;\n }\n\n constructor(uint16 _localChainId, address _counterView) PreCrimeView(_localChainId) {\n counterView = CounterView(_counterView);\n maxBatchSize = 10;\n }\n\n function setRemotePrecrimeAddresses(\n uint16[] memory _remoteChainIds,\n bytes32[] memory _remotePrecrimeAddresses\n ) public onlyPrecrimeAdmin {\n require(_remoteChainIds.length == _remotePrecrimeAddresses.length, \"Precrime: invalid size\");\n remoteChainIds = _remoteChainIds;\n remotePrecrimeAddresses = _remotePrecrimeAddresses;\n }\n\n function setCounterView(address _counterView) public onlyPrecrimeAdmin {\n counterView = CounterView(_counterView);\n }\n\n function _simulate(Packet[] calldata _packets) internal view override returns (uint16 code, bytes memory data) {\n // get state from counter\n CounterView.CountState memory countState = counterView.getCountState(remoteChainIds);\n\n // simulate\n for (uint256 i = 0; i < _packets.length; i++) {\n Packet memory packet = _packets[i];\n countState = counterView.lzReceive(countState, packet.srcChainId);\n }\n\n // return simulation result\n return (CODE_SUCCESS, abi.encode(SimulationResult({chainId: localChainId, countState: countState})));\n }\n\n function _precrime(\n bytes[] memory _simulation\n ) internal view virtual override returns (uint16 code, bytes memory reason) {\n (SimulationResult memory localResult, SimulationResult[] memory results) = _getLocalSimulateResult(_simulation);\n\n uint sumOutboundCount = 0;\n // for each chainPathCount, find the chainPathCount and check the counts\n for (uint256 j = 0; j < localResult.countState.chainPathCounts.length; j++) {\n CounterView.ChainPathCount memory cpCount = localResult.countState.chainPathCounts[j];\n // find remote to local count state\n // should provide all peers simulated results\n CounterView.ChainPathCount memory remoteCp = _getRemoteCpCount(results, cpCount.eid);\n (code, reason) = _assertChainPathCount(cpCount, remoteCp);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n sumOutboundCount += remoteCp.outboundCount; // remote to local outbound count\n }\n (code, reason) = _assertTotalCount(localResult.countState, sumOutboundCount);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n\n return (CODE_SUCCESS, \"\");\n }\n\n function _getRemoteCpCount(\n SimulationResult[] memory _results,\n uint16 _remoteId\n ) internal view returns (CounterView.ChainPathCount memory) {\n uint localEid = localChainId;\n for (uint256 i = 0; i < _results.length; i++) {\n SimulationResult memory remoteResult = _results[i];\n if (remoteResult.chainId == _remoteId) {\n for (uint256 j = 0; j < remoteResult.countState.chainPathCounts.length; j++) {\n CounterView.ChainPathCount memory cpCount = remoteResult.countState.chainPathCounts[j];\n if (cpCount.eid == localEid) {\n // find to localEid path\n return cpCount;\n }\n }\n }\n }\n revert(\"Precrime: count state not found\");\n }\n\n function _getLocalSimulateResult(\n bytes[] memory _simulation\n ) internal view returns (SimulationResult memory localResult, SimulationResult[] memory results) {\n // decode results\n results = new SimulationResult[](_simulation.length);\n for (uint256 i = 0; i < _simulation.length; i++) {\n results[i] = abi.decode(_simulation[i], (SimulationResult));\n if (results[i].chainId == localChainId) {\n localResult = results[i];\n }\n }\n }\n\n function _assertChainPathCount(\n CounterView.ChainPathCount memory _localCpCount,\n CounterView.ChainPathCount memory _remoteCpCount\n ) internal pure returns (uint16 code, bytes memory reason) {\n if (_localCpCount.inboundCount > _remoteCpCount.outboundCount) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: inboundCount > outboundCount\");\n }\n if (_localCpCount.outboundCount > _remoteCpCount.inboundCount) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: outboundCount > inboundCount\");\n }\n return (CODE_SUCCESS, \"\");\n }\n\n function _assertTotalCount(\n CounterView.CountState memory _localCount,\n uint _sumOutbound\n ) internal pure returns (uint16 code, bytes memory reason) {\n if (_localCount.totalCount > _sumOutbound) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: totalCount > sum outboundCount\");\n }\n return (CODE_SUCCESS, \"\");\n }\n\n function _remotePrecrimeAddress(\n Packet[] calldata _packets\n ) internal view override returns (uint16[] memory chainIds, bytes32[] memory precrimeAddresses) {\n if (_packets.length == 0) {\n return (remoteChainIds, remotePrecrimeAddresses);\n }\n\n // only return related remotes\n uint16 size = _getRelatedRemoteSize(_packets);\n if (size > 0) {\n chainIds = new uint16[](size);\n uint256 k = 0;\n precrimeAddresses = new bytes32[](size);\n for (uint16 i = 0; i < remoteChainIds.length; i++) {\n for (uint16 j = 0; j < _packets.length; j++) {\n uint16 srcChainId = _packets[j].srcChainId;\n if (remoteChainIds[i] == srcChainId) {\n chainIds[k] = srcChainId;\n precrimeAddresses[k] = remotePrecrimeAddresses[i];\n k++;\n break;\n }\n }\n }\n }\n }\n\n function _getRelatedRemoteSize(Packet[] memory _packets) internal view returns (uint16 size) {\n for (uint16 i = 0; i < remoteChainIds.length; i++) {\n for (uint16 j = 0; j < _packets.length; j++) {\n if (remoteChainIds[i] == _packets[j].srcChainId) {\n size++;\n break;\n }\n }\n }\n }\n\n function _getInboundNonce(Packet memory packet) internal view override returns (uint64) {\n CounterV counter = counterView.counter();\n return counter.getInboundNonce(packet.srcChainId);\n }\n}\n"
|
|
256
|
-
},
|
|
257
|
-
"contracts/precrime/example/view/CounterV.sol": {
|
|
258
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\ncontract CounterV {\n // keep track of how many messages have been received from other chains\n uint public totalCount;\n mapping(uint32 => uint) public inboundCount;\n mapping(uint32 => uint) public outboundCount;\n\n event Send(uint16 dstChainId);\n event Receive(uint16 srcChainId);\n\n uint16 public chainId;\n\n constructor(uint16 _chainId) {\n chainId = _chainId;\n }\n\n function lzReceive(uint16 _srcChainId) external {\n inboundCount[_srcChainId]++;\n totalCount++;\n\n emit Receive(_srcChainId);\n }\n\n function increment(uint16 _dstChainId) external {\n outboundCount[_dstChainId]++;\n\n emit Send(_dstChainId);\n }\n\n function brokeIncrement(uint16 _dstChainId) external {\n emit Send(_dstChainId);\n }\n\n function brokeTotalCount() external {\n totalCount++;\n }\n\n function getInboundNonce(uint16 _chainId) public view returns (uint64) {\n // in reality, this would be a call to the LayerZero endpoint\n return uint64(inboundCount[_chainId]);\n }\n}\n"
|
|
259
|
-
},
|
|
260
|
-
"contracts/precrime/example/view/CounterView.sol": {
|
|
261
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport \"./CounterV.sol\";\n\ncontract CounterView {\n struct CountState {\n uint totalCount;\n ChainPathCount[] chainPathCounts;\n }\n\n struct ChainPathCount {\n uint16 eid;\n uint inboundCount;\n uint outboundCount;\n }\n\n CounterV public counter;\n\n constructor(address _counter) {\n counter = CounterV(_counter);\n }\n\n function lzReceive(CountState memory countState, uint16 _srcChainId) public pure returns (CountState memory) {\n // do receive logic\n for (uint i = 0; i < countState.chainPathCounts.length; i++) {\n ChainPathCount memory chainPathCount = countState.chainPathCounts[i];\n if (chainPathCount.eid == _srcChainId) {\n countState.totalCount++;\n chainPathCount.inboundCount++;\n countState.chainPathCounts[i] = chainPathCount;\n break;\n }\n }\n return countState;\n }\n\n /**\n * @notice Get the count states for a list of peers\n * @param peers - the list of remote chainId to get counts for\n * @return counts - the CountState with the total count and the chain path counts\n */\n function getCountState(uint16[] calldata peers) public view returns (CountState memory) {\n ChainPathCount[] memory chainPathCounts = new ChainPathCount[](peers.length);\n\n for (uint i = 0; i < peers.length; i++) {\n uint16 peer = peers[i];\n chainPathCounts[i] = ChainPathCount({\n eid: peer,\n inboundCount: counter.inboundCount(peer),\n outboundCount: counter.outboundCount(peer)\n });\n }\n\n CountState memory countState = CountState({totalCount: counter.totalCount(), chainPathCounts: chainPathCounts});\n\n return countState;\n }\n}\n"
|
|
262
|
-
},
|
|
263
|
-
"contracts/precrime/interfaces/IPreCrime.sol": {
|
|
264
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.7.0;\npragma abicoder v2;\n\nimport \"./IPreCrimeBase.sol\";\n\ninterface IPreCrime is IPreCrimeBase {\n /**\n * @dev simulate run cross chain packets and get a simulation result for precrime later\n * @param _packets packets, the packets item should group by srcChainId, srcAddress, then sort by nonce\n * @return code simulation result code; see the error code defination\n * @return result the result is use for precrime params\n */\n function simulate(Packet[] calldata _packets) external returns (uint16 code, bytes memory result);\n}\n"
|
|
265
|
-
},
|
|
266
|
-
"contracts/precrime/interfaces/IPreCrimeBase.sol": {
|
|
267
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.7.0;\npragma abicoder v2;\n\ninterface IPreCrimeBase {\n struct Packet {\n uint16 srcChainId; // source chain id\n bytes32 srcAddress; // srouce UA address\n uint64 nonce;\n bytes payload;\n }\n\n /**\n * @dev get precrime config,\n * @param _packets packets\n * @return bytes of [maxBatchSize, remotePrecrimes]\n */\n function getConfig(Packet[] calldata _packets) external view returns (bytes memory);\n\n /**\n * @dev\n * @param _simulation all simulation results from difference chains\n * @return code precrime result code; check out the error code defination\n * @return reason error reason\n */\n function precrime(\n Packet[] calldata _packets,\n bytes[] calldata _simulation\n ) external view returns (uint16 code, bytes memory reason);\n\n /**\n * @dev protocol version\n */\n function version() external view returns (uint16);\n}\n"
|
|
268
|
-
},
|
|
269
|
-
"contracts/precrime/interfaces/IPreCrimeView.sol": {
|
|
270
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.7.0;\npragma abicoder v2;\n\nimport \"./IPreCrimeBase.sol\";\n\ninterface IPreCrimeView is IPreCrimeBase {\n /**\n * @dev simulate run cross chain packets and get a simulation result for precrime later\n * @param _packets packets, the packets item should group by srcChainId, srcAddress, then sort by nonce\n * @return code simulation result code; see the error code defination\n * @return result the result is use for precrime params\n */\n function simulate(Packet[] calldata _packets) external view returns (uint16 code, bytes memory result);\n}\n"
|
|
271
|
-
},
|
|
272
|
-
"contracts/precrime/PreCrime.sol": {
|
|
273
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"./interfaces/IPreCrime.sol\";\nimport \"./PreCrimeBase.sol\";\n\nabstract contract PreCrime is PreCrimeBase, IPreCrime {\n bytes4 private constant SIMULATE_REVERT_SELECTOR = bytes4(keccak256(\"SimulateRevert(uint16,bytes)\"));\n\n /**\n * @dev 10000 - 20000 is for view mode, 20000 - 30000 is for precrime inherit mode\n */\n uint16 public constant PRECRIME_VERSION = 20001;\n\n constructor(uint16 _localChainId) PreCrimeBase(_localChainId) {}\n\n /**\n * @dev simulate run cross chain packets and get a simulation result for precrime later\n * @param _packets packets, the packets item should group by srcChainId, srcAddress, then sort by nonce\n * @return code simulation result code; see the error code defination\n * @return data the result is use for precrime params\n */\n function simulate(Packet[] calldata _packets) external override returns (uint16 code, bytes memory data) {\n // params check\n (code, data) = _checkPacketsMaxSizeAndNonceOrder(_packets);\n if (code != CODE_SUCCESS) {\n return (code, data);\n }\n\n (bool success, bytes memory result) = address(this).call(\n abi.encodeWithSelector(this._simulateAndRevert.selector, _packets)\n );\n require(!success, \"simulate should never return success\");\n\n // parse code and data\n (code, data) = _parseRevertResult(result);\n if (code == CODE_SUCCESS) {\n data = abi.encode(localChainId, data); // add localChainId to the header\n }\n }\n\n function _parseRevertResult(bytes memory result) internal pure returns (uint16 code, bytes memory data) {\n // check revert selector\n bytes4 selector;\n assembly {\n selector := mload(add(result, 0x20)) // skip the length and get bytes4 selector\n }\n if (selector != SIMULATE_REVERT_SELECTOR) {\n // bubble up the internal error\n assembly {\n revert(add(result, 0x20), mload(result))\n }\n }\n\n // parse code and result\n assembly {\n // Slice the sighash. Remove the selector which is the first 4 bytes\n result := add(result, 0x04)\n }\n return abi.decode(result, (uint16, bytes));\n }\n\n /**\n * @dev internal function, no one should call\n * @param _packets packets\n */\n function _simulateAndRevert(Packet[] calldata _packets) external virtual {\n require(msg.sender == address(this));\n (uint16 code, bytes memory simulation) = _simulate(_packets);\n // equal to: revert SimulateRevert(code, result);\n bytes memory revertData = abi.encodePacked(SIMULATE_REVERT_SELECTOR, abi.encode(code, simulation));\n assembly {\n revert(add(revertData, 32), mload(revertData))\n }\n }\n\n /**\n * @dev UA execute the logic by _packets, and return simulation result for precrime. would revert state after returned result.\n * @param _packets packets\n * @return code\n * @return result\n */\n function _simulate(Packet[] calldata _packets) internal virtual returns (uint16 code, bytes memory result);\n\n function version() external pure override returns (uint16) {\n return PRECRIME_VERSION;\n }\n}\n"
|
|
274
|
-
},
|
|
275
|
-
"contracts/precrime/PreCrimeBase.sol": {
|
|
276
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"./interfaces/IPreCrime.sol\";\n\nabstract contract PreCrimeBase is IPreCrimeBase {\n uint16 public constant CONFIG_VERSION = 1;\n\n //---------------- error code ----------------------\n // --- UA scope code ---\n uint16 public constant CODE_SUCCESS = 0; // success\n uint16 public constant CODE_PRECRIME_FAILURE = 1; // !!! crimes found\n\n // --- protocol scope error code ---\n // simualte\n uint16 public constant CODE_PACKETS_OVERSIZE = 2; // packets number bigger then max size\n uint16 public constant CODE_PACKETS_UNSORTED = 3; // packets are unsorted, need backfill and keep order\n // precrime\n uint16 public constant CODE_MISS_SIMULATE_RESULT = 4; // miss simulation result\n\n uint16 public immutable localChainId;\n uint64 public maxBatchSize;\n address public precrimeAdmin;\n\n modifier onlyPrecrimeAdmin() {\n require(msg.sender == precrimeAdmin, \"only admin\");\n _;\n }\n\n constructor(uint16 _localChainId) {\n localChainId = _localChainId;\n precrimeAdmin = msg.sender;\n }\n\n function setPrecrimeAdmin(address _precrimeAdmin) external onlyPrecrimeAdmin {\n precrimeAdmin = _precrimeAdmin;\n }\n\n function setMaxBatchSize(uint64 _maxBatchSize) external onlyPrecrimeAdmin {\n maxBatchSize = _maxBatchSize;\n }\n\n /**\n * @dev get precrime config,\n * @param _packets packets\n * @return configation bytes\n */\n function getConfig(Packet[] calldata _packets) external view virtual override returns (bytes memory) {\n (uint16[] memory remoteChains, bytes32[] memory remoteAddresses) = _remotePrecrimeAddress(_packets);\n return\n abi.encodePacked(\n CONFIG_VERSION,\n //---- max packets size for simulate batch ---\n maxBatchSize,\n //------------- remote precrimes -------------\n remoteChains.length,\n remoteChains,\n remoteAddresses\n );\n }\n\n /**\n * @dev\n * @param _simulation all simulation results from difference chains\n * @return code precrime result code; check out the error code definition\n * @return reason error reason\n */\n function precrime(\n Packet[] calldata _packets,\n bytes[] calldata _simulation\n ) external view override returns (uint16 code, bytes memory reason) {\n bytes[] memory originSimulateResult = new bytes[](_simulation.length);\n uint16[] memory chainIds = new uint16[](_simulation.length);\n for (uint256 i = 0; i < _simulation.length; i++) {\n (uint16 chainId, bytes memory simulateResult) = abi.decode(_simulation[i], (uint16, bytes));\n chainIds[i] = chainId;\n originSimulateResult[i] = simulateResult;\n }\n\n (code, reason) = _checkResultsCompleteness(_packets, chainIds);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n\n (code, reason) = _precrime(originSimulateResult);\n }\n\n function _checkPacketsMaxSizeAndNonceOrder(\n Packet[] calldata _packets\n ) internal view returns (uint16 code, bytes memory reason) {\n if (_packets.length > maxBatchSize) {\n return (CODE_PACKETS_OVERSIZE, abi.encodePacked(\"packets size exceed limited\"));\n }\n\n // check packets nonce, sequence order\n // packets should group by srcChainId and srcAddress, then sort by nonce ascending\n if (_packets.length > 0) {\n uint16 srcChainId;\n bytes32 srcAddress;\n uint64 nonce;\n for (uint256 i = 0; i < _packets.length; i++) {\n Packet memory packet = _packets[i];\n // start from a new chain packet or a new source UA\n if (packet.srcChainId != srcChainId || packet.srcAddress != srcAddress) {\n srcChainId = packet.srcChainId;\n srcAddress = packet.srcAddress;\n nonce = packet.nonce;\n uint64 nextInboundNonce = _getInboundNonce(packet) + 1;\n // the first packet's nonce must equal to dst InboundNonce+1\n if (nonce != nextInboundNonce) {\n return (CODE_PACKETS_UNSORTED, abi.encodePacked(\"skipped inboundNonce forbidden\"));\n }\n } else {\n // the following packet's nonce add 1 in order\n if (packet.nonce != ++nonce) {\n return (CODE_PACKETS_UNSORTED, abi.encodePacked(\"unsorted packets\"));\n }\n }\n }\n }\n return (CODE_SUCCESS, \"\");\n }\n\n function _checkResultsCompleteness(\n Packet[] calldata _packets,\n uint16[] memory _resultChainIds\n ) internal view returns (uint16 code, bytes memory reason) {\n // check if all remote result included\n if (_packets.length > 0) {\n (uint16[] memory remoteChains, ) = _remotePrecrimeAddress(_packets);\n for (uint256 i = 0; i < remoteChains.length; i++) {\n bool resultChainIdChecked;\n for (uint256 j = 0; j < _resultChainIds.length; j++) {\n if (_resultChainIds[j] == remoteChains[i]) {\n resultChainIdChecked = true;\n break;\n }\n }\n if (!resultChainIdChecked) {\n return (CODE_MISS_SIMULATE_RESULT, \"missing remote simulation result\");\n }\n }\n }\n // check if local result included\n bool localChainIdResultChecked;\n for (uint256 j = 0; j < _resultChainIds.length; j++) {\n if (_resultChainIds[j] == localChainId) {\n localChainIdResultChecked = true;\n break;\n }\n }\n if (!localChainIdResultChecked) {\n return (CODE_MISS_SIMULATE_RESULT, \"missing local simulation result\");\n }\n\n return (CODE_SUCCESS, \"\");\n }\n\n /**\n * @dev\n * @param _simulation all simulation results from difference chains\n * @return code precrime result code; check out the error code defination\n * @return reason error reason\n */\n function _precrime(bytes[] memory _simulation) internal view virtual returns (uint16 code, bytes memory reason);\n\n /**\n * @dev UA return trusted remote precrimes by packets\n * @param _packets packets\n * @return\n */\n function _remotePrecrimeAddress(\n Packet[] calldata _packets\n ) internal view virtual returns (uint16[] memory, bytes32[] memory);\n\n /**\n * get srcChain & srcAddress InboundNonce by packet\n */\n function _getInboundNonce(Packet memory packet) internal view virtual returns (uint64 nonce);\n}\n"
|
|
277
|
-
},
|
|
278
|
-
"contracts/precrime/PreCrimeView.sol": {
|
|
279
|
-
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"./interfaces/IPreCrimeView.sol\";\nimport \"./PreCrimeBase.sol\";\n\nabstract contract PreCrimeView is PreCrimeBase, IPreCrimeView {\n /**\n * @dev 10000 - 20000 is for view mode, 20000 - 30000 is for precrime inherit mode\n */\n uint16 public constant PRECRIME_VERSION = 10001;\n\n constructor(uint16 _localChainId) PreCrimeBase(_localChainId) {}\n\n /**\n * @dev simulate run cross chain packets and get a simulation result for precrime later\n * @param _packets packets, the packets item should group by srcChainId, srcAddress, then sort by nonce\n * @return code simulation result code; see the error code defination\n * @return data the result is use for precrime params\n */\n function simulate(Packet[] calldata _packets) external view override returns (uint16 code, bytes memory data) {\n // params check\n (code, data) = _checkPacketsMaxSizeAndNonceOrder(_packets);\n if (code != CODE_SUCCESS) {\n return (code, data);\n }\n\n (code, data) = _simulate(_packets);\n if (code == CODE_SUCCESS) {\n data = abi.encode(localChainId, data); // add localChainId to the header\n }\n }\n\n /**\n * @dev UA execute the logic by _packets, and return simulation result for precrime. would revert state after returned result.\n * @param _packets packets\n * @return code\n * @return result\n */\n function _simulate(Packet[] calldata _packets) internal view virtual returns (uint16 code, bytes memory result);\n\n function version() external pure override returns (uint16) {\n return PRECRIME_VERSION;\n }\n}\n"
|
|
280
237
|
}
|
|
281
238
|
},
|
|
282
|
-
"
|
|
239
|
+
"settings": {
|
|
240
|
+
"optimizer": {
|
|
241
|
+
"enabled": true,
|
|
242
|
+
"runs": 10000
|
|
243
|
+
},
|
|
244
|
+
"outputSelection": {
|
|
245
|
+
"*": {
|
|
246
|
+
"*": [
|
|
247
|
+
"abi",
|
|
248
|
+
"evm.bytecode",
|
|
249
|
+
"evm.deployedBytecode",
|
|
250
|
+
"evm.methodIdentifiers",
|
|
251
|
+
"metadata",
|
|
252
|
+
"devdoc",
|
|
253
|
+
"userdoc",
|
|
254
|
+
"storageLayout",
|
|
255
|
+
"evm.gasEstimates"
|
|
256
|
+
],
|
|
257
|
+
"": [
|
|
258
|
+
"ast"
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
"metadata": {
|
|
263
|
+
"useLiteralContent": true
|
|
264
|
+
}
|
|
265
|
+
}
|
|
283
266
|
}
|
|
284
267
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "1698b18cef59145feb6419b3eacba549",
|
|
3
|
+
"solcLongVersion": "0.7.6+commit.d1802f25.Emscripten.clang",
|
|
4
|
+
"input": {
|
|
5
|
+
"language": "Solidity",
|
|
6
|
+
"sources": {
|
|
7
|
+
"contracts/mocks/PacketData.sol": {
|
|
8
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\n\ncontract PacketData {\n event Packet(uint16 chainId, bytes payload);\n event Packet(bytes payload);\n\n function emitPacketV1(\n uint64 nonce,\n address ua,\n uint16 dstChainId,\n address dstAddress,\n bytes calldata payload\n ) public {\n bytes memory encodedPayload = abi.encodePacked(nonce, ua, dstAddress, payload);\n emit Packet(dstChainId, encodedPayload);\n }\n\n function emitPacketV2(\n uint64 nonce,\n uint16 localChainId,\n address ua,\n uint16 dstChainId,\n address dstAddress,\n bytes calldata payload\n ) public {\n bytes memory encodedPayload = abi.encodePacked(nonce, localChainId, ua, dstChainId, dstAddress, payload);\n emit Packet(encodedPayload);\n }\n}\n"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"settings": {
|
|
12
|
+
"optimizer": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"runs": 10000
|
|
15
|
+
},
|
|
16
|
+
"outputSelection": {
|
|
17
|
+
"*": {
|
|
18
|
+
"*": [
|
|
19
|
+
"abi",
|
|
20
|
+
"evm.bytecode",
|
|
21
|
+
"evm.deployedBytecode",
|
|
22
|
+
"evm.methodIdentifiers",
|
|
23
|
+
"metadata",
|
|
24
|
+
"devdoc",
|
|
25
|
+
"userdoc",
|
|
26
|
+
"storageLayout",
|
|
27
|
+
"evm.gasEstimates"
|
|
28
|
+
],
|
|
29
|
+
"": [
|
|
30
|
+
"ast"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"metadata": {
|
|
35
|
+
"useLiteralContent": true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "24492b3a86a1195fe1b202109347e27e",
|
|
3
|
+
"solcLongVersion": "0.7.6+commit.d1802f25.Emscripten.clang",
|
|
4
|
+
"input": {
|
|
5
|
+
"language": "Solidity",
|
|
6
|
+
"sources": {
|
|
7
|
+
"contracts/mocks/IsContract.sol": {
|
|
8
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\n\ncontract IsContract {\n function isAddressContract(address addr) external view returns (bool) {\n // check if the toAddress is a contract. We are not concerned about addresses that pretend to be wallets. because worst case we just delete their payload if being malicious\n // we can guarantee that if a size > 0, then the contract is definitely a contract address in this context\n uint size;\n assembly {\n size := extcodesize(addr)\n }\n return size != 0;\n }\n}\n"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"settings": {
|
|
12
|
+
"optimizer": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"runs": 10000
|
|
15
|
+
},
|
|
16
|
+
"outputSelection": {
|
|
17
|
+
"*": {
|
|
18
|
+
"*": [
|
|
19
|
+
"abi",
|
|
20
|
+
"evm.bytecode",
|
|
21
|
+
"evm.deployedBytecode",
|
|
22
|
+
"evm.methodIdentifiers",
|
|
23
|
+
"metadata",
|
|
24
|
+
"devdoc",
|
|
25
|
+
"userdoc",
|
|
26
|
+
"storageLayout",
|
|
27
|
+
"evm.gasEstimates"
|
|
28
|
+
],
|
|
29
|
+
"": [
|
|
30
|
+
"ast"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"metadata": {
|
|
35
|
+
"useLiteralContent": true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "8a65080bfd6e652b21df7756fb5779c9",
|
|
3
|
+
"solcLongVersion": "0.7.6+commit.d1802f25.Emscripten.clang",
|
|
4
|
+
"input": {
|
|
5
|
+
"language": "Solidity",
|
|
6
|
+
"sources": {
|
|
7
|
+
"contracts/arbitrum/interfaces/ArbSys.sol": {
|
|
8
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.4.21 <0.9.0;\n\n/**\n * @title Precompiled contract that exists in every Arbitrum chain at address(100), 0x0000000000000000000000000000000000000064. Exposes a variety of system-level functionality.\n */\ninterface ArbSys {\n /**\n * @notice Get internal version number identifying an ArbOS build\n * @return version number as int\n */\n function arbOSVersion() external pure returns (uint);\n\n function arbChainID() external view returns (uint);\n\n /**\n * @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)\n * @return block number as int\n */\n function arbBlockNumber() external view returns (uint);\n\n /**\n * @notice Send given amount of Eth to dest from sender.\n * This is a convenience function, which is equivalent to calling sendTxToL1 with empty calldataForL1.\n * @param destination recipient address on L1\n * @return unique identifier for this L2-to-L1 transaction.\n */\n function withdrawEth(address destination) external payable returns (uint);\n\n /**\n * @notice Send a transaction to L1\n * @param destination recipient address on L1\n * @param calldataForL1 (optional) calldata for L1 contract call\n * @return a unique identifier for this L2-to-L1 transaction.\n */\n function sendTxToL1(address destination, bytes calldata calldataForL1) external payable returns (uint);\n\n /**\n * @notice get the number of transactions issued by the given external account or the account sequence number of the given contract\n * @param account target account\n * @return the number of transactions issued by the given external account or the account sequence number of the given contract\n */\n function getTransactionCount(address account) external view returns (uint256);\n\n /**\n * @notice get the value of target L2 storage slot\n * This function is only callable from address 0 to prevent contracts from being able to call it\n * @param account target account\n * @param index target index of storage slot\n * @return stotage value for the given account at the given index\n */\n function getStorageAt(address account, uint256 index) external view returns (uint256);\n\n /**\n * @notice check if current call is coming from l1\n * @return true if the caller of this was called directly from L1\n */\n function isTopLevelCall() external view returns (bool);\n\n /**\n * @notice check if the caller (of this caller of this) is an aliased L1 contract address\n * @return true iff the caller's address is an alias for an L1 contract address\n */\n function wasMyCallersAddressAliased() external view returns (bool);\n\n /**\n * @notice return the address of the caller (of this caller of this), without applying L1 contract address aliasing\n * @return address of the caller's caller, without applying L1 contract address aliasing\n */\n function myCallersAddressWithoutAliasing() external view returns (address);\n\n /**\n * @notice map L1 sender contract address to its L2 alias\n * @param sender sender address\n * @param dest destination address\n * @return aliased sender address\n */\n function mapL1SenderContractAddressToL2Alias(address sender, address dest) external pure returns (address);\n\n /**\n * @notice get the caller's amount of available storage gas\n * @return amount of storage gas available to the caller\n */\n function getStorageGasAvailable() external view returns (uint);\n\n event L2ToL1Transaction(\n address caller,\n address indexed destination,\n uint indexed uniqueId,\n uint indexed batchNumber,\n uint indexInBatch,\n uint arbBlockNum,\n uint ethBlockNum,\n uint timestamp,\n uint callvalue,\n bytes data\n );\n}\n"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"settings": {
|
|
12
|
+
"optimizer": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"runs": 10000
|
|
15
|
+
},
|
|
16
|
+
"outputSelection": {
|
|
17
|
+
"*": {
|
|
18
|
+
"*": [
|
|
19
|
+
"abi",
|
|
20
|
+
"evm.bytecode",
|
|
21
|
+
"evm.deployedBytecode",
|
|
22
|
+
"evm.methodIdentifiers",
|
|
23
|
+
"metadata",
|
|
24
|
+
"devdoc",
|
|
25
|
+
"userdoc",
|
|
26
|
+
"storageLayout",
|
|
27
|
+
"evm.gasEstimates"
|
|
28
|
+
],
|
|
29
|
+
"": [
|
|
30
|
+
"ast"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"metadata": {
|
|
35
|
+
"useLiteralContent": true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "d25a40a50e55d137530e079a13031b48",
|
|
3
|
+
"solcLongVersion": "0.7.6+commit.d1802f25.Emscripten.clang",
|
|
4
|
+
"input": {
|
|
5
|
+
"language": "Solidity",
|
|
6
|
+
"sources": {
|
|
7
|
+
"contracts/mocks/ContractOne.sol": {
|
|
8
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\n\ncontract ContractOne {\n uint x;\n\n function setIt(uint _x) external {\n x = _x;\n }\n}\n"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"settings": {
|
|
12
|
+
"optimizer": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"runs": 10000
|
|
15
|
+
},
|
|
16
|
+
"outputSelection": {
|
|
17
|
+
"*": {
|
|
18
|
+
"*": [
|
|
19
|
+
"abi",
|
|
20
|
+
"evm.bytecode",
|
|
21
|
+
"evm.deployedBytecode",
|
|
22
|
+
"evm.methodIdentifiers",
|
|
23
|
+
"metadata",
|
|
24
|
+
"devdoc",
|
|
25
|
+
"userdoc",
|
|
26
|
+
"storageLayout",
|
|
27
|
+
"evm.gasEstimates"
|
|
28
|
+
],
|
|
29
|
+
"": [
|
|
30
|
+
"ast"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"metadata": {
|
|
35
|
+
"useLiteralContent": true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "edf0138b97898d26cfc0e872ce8b1c0b",
|
|
3
|
+
"solcLongVersion": "0.7.6+commit.d1802f25.Emscripten.clang",
|
|
4
|
+
"input": {
|
|
5
|
+
"language": "Solidity",
|
|
6
|
+
"sources": {
|
|
7
|
+
"contracts/precrime/example/inherit/CounterI.sol": {
|
|
8
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport \"./CounterPrecrime.sol\";\n\ncontract CounterI is CounterPrecrime {\n // keep track of how many messages have been received from other chains\n uint public totalCount;\n mapping(uint32 => uint) public inboundCount;\n mapping(uint32 => uint) public outboundCount;\n\n event Send(uint16 dstChainId);\n event Receive(uint16 srcChainId);\n\n uint16 public chainId;\n\n constructor(uint16 _chainId) CounterPrecrime(_chainId) {\n chainId = _chainId;\n }\n\n function lzReceive(uint16 _srcChainId) public {\n inboundCount[_srcChainId]++;\n totalCount++;\n\n emit Receive(_srcChainId);\n }\n\n function increment(uint16 _dstChainId) external {\n outboundCount[_dstChainId]++;\n\n emit Send(_dstChainId);\n }\n\n function brokeIncrement(uint16 _dstChainId) external {\n emit Send(_dstChainId);\n }\n\n function brokeTotalCount() external {\n totalCount++;\n }\n\n function getInboundNonce(uint32 _chainId) public view returns (uint) {\n // in reality, this would be a call to the LayerZero endpoint\n return inboundCount[_chainId];\n }\n\n // ------------- precrime -----------------\n function _lzReceiveByPacket(Packet calldata _packet) internal virtual override {\n lzReceive(uint16(_packet.srcChainId));\n }\n\n function getCountState(uint16[] memory peers) public view virtual override returns (CountState memory) {\n ChainPathCount[] memory chainPathCounts = new ChainPathCount[](peers.length);\n for (uint i = 0; i < peers.length; i++) {\n uint16 peer = peers[i];\n chainPathCounts[i] = ChainPathCount({\n eid: peer,\n inboundCount: inboundCount[peer],\n outboundCount: outboundCount[peer]\n });\n }\n\n CountState memory countState = CountState({totalCount: totalCount, chainPathCounts: chainPathCounts});\n\n return countState;\n }\n\n function _getInboundNonce(Packet memory packet) internal view override returns (uint64) {\n // in reality, this would be a call to the LayerZero endpoint\n return uint64(inboundCount[packet.srcChainId]);\n }\n}\n"
|
|
9
|
+
},
|
|
10
|
+
"contracts/precrime/example/inherit/CounterPrecrime.sol": {
|
|
11
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport \"../../PreCrime.sol\";\n\nabstract contract CounterPrecrime is PreCrime {\n uint16[] public remoteChainIds;\n bytes32[] public remotePrecrimeAddresses;\n\n struct SimulationResult {\n uint16 chainId;\n CountState countState;\n }\n\n struct CountState {\n uint totalCount;\n ChainPathCount[] chainPathCounts;\n }\n\n struct ChainPathCount {\n uint16 eid;\n uint inboundCount;\n uint outboundCount;\n }\n\n constructor(uint16 _localChainId) PreCrime(_localChainId) {\n maxBatchSize = 10;\n }\n\n function setRemotePrecrimeAddresses(\n uint16[] memory _remoteChainIds,\n bytes32[] memory _remotePrecrimeAddresses\n ) public onlyPrecrimeAdmin {\n require(_remoteChainIds.length == _remotePrecrimeAddresses.length, \"Precrime: invalid size\");\n remoteChainIds = _remoteChainIds;\n remotePrecrimeAddresses = _remotePrecrimeAddresses;\n }\n\n function _simulate(Packet[] calldata _packets) internal override returns (uint16 code, bytes memory data) {\n // simulate\n for (uint256 i = 0; i < _packets.length; i++) {\n _lzReceiveByPacket(_packets[i]);\n }\n\n // return simulation result\n bytes memory result = abi.encode(\n SimulationResult({chainId: localChainId, countState: getCountState(remoteChainIds)})\n );\n return (CODE_SUCCESS, result);\n }\n\n function _precrime(\n bytes[] memory _simulation\n ) internal view virtual override returns (uint16 code, bytes memory reason) {\n (SimulationResult memory localResult, SimulationResult[] memory results) = _getLocalSimulateResult(_simulation);\n\n uint sumOutboundCount = 0;\n // for each chainPathCount, find the chainPathCount and check the counts\n for (uint256 j = 0; j < localResult.countState.chainPathCounts.length; j++) {\n ChainPathCount memory cpCount = localResult.countState.chainPathCounts[j];\n // find remote to local count state\n // should provide all peers simulated results\n ChainPathCount memory remoteCp = _getRemoteCpCount(results, cpCount.eid);\n (code, reason) = _assertChainPathCount(cpCount, remoteCp);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n sumOutboundCount += remoteCp.outboundCount; // remote to local outbound count\n }\n (code, reason) = _assertTotalCount(localResult.countState, sumOutboundCount);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n\n return (CODE_SUCCESS, \"\");\n }\n\n function _lzReceiveByPacket(Packet calldata _packet) internal virtual;\n\n /**\n * @notice Get the count states for a list of peers\n * @param peers - the list of remote chainId to get counts for\n * @return counts - the CountState with the total count and the chain path counts\n */\n function getCountState(uint16[] memory peers) public view virtual returns (CountState memory);\n\n function _getRemoteCpCount(\n SimulationResult[] memory _results,\n uint16 _remoteId\n ) internal view returns (ChainPathCount memory) {\n uint localEid = localChainId;\n for (uint256 i = 0; i < _results.length; i++) {\n SimulationResult memory remoteResult = _results[i];\n if (remoteResult.chainId == _remoteId) {\n for (uint256 j = 0; j < remoteResult.countState.chainPathCounts.length; j++) {\n ChainPathCount memory cpCount = remoteResult.countState.chainPathCounts[j];\n if (cpCount.eid == localEid) {\n // find to localEid path\n return cpCount;\n }\n }\n }\n }\n revert(\"Precrime: countState not found, are you missing a simulation?\");\n }\n\n function _getLocalSimulateResult(\n bytes[] memory _simulation\n ) internal view returns (SimulationResult memory localResult, SimulationResult[] memory results) {\n // decode results\n results = new SimulationResult[](_simulation.length);\n for (uint256 i = 0; i < _simulation.length; i++) {\n bytes memory result = _simulation[i];\n results[i] = abi.decode(result, (SimulationResult));\n if (results[i].chainId == localChainId) {\n localResult = results[i];\n }\n }\n }\n\n function _assertChainPathCount(\n ChainPathCount memory _localCpCount,\n ChainPathCount memory _remoteCpCount\n ) internal pure returns (uint16 code, bytes memory reason) {\n if (_localCpCount.inboundCount > _remoteCpCount.outboundCount) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: inboundCount > outboundCount\");\n }\n if (_localCpCount.outboundCount > _remoteCpCount.inboundCount) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: outboundCount > inboundCount\");\n }\n return (CODE_SUCCESS, \"\");\n }\n\n function _assertTotalCount(\n CountState memory _localCount,\n uint _sumOutbound\n ) internal pure returns (uint16 code, bytes memory reason) {\n if (_localCount.totalCount > _sumOutbound) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: totalCount > sum outboundCount\");\n }\n }\n\n function _remotePrecrimeAddress(\n Packet[] calldata _packets\n ) internal view override returns (uint16[] memory chainIds, bytes32[] memory precrimeAddresses) {\n if (_packets.length == 0) {\n return (remoteChainIds, remotePrecrimeAddresses);\n }\n\n // only return related remotes\n uint16 size = _getRelatedRemoteSize(_packets);\n if (size > 0) {\n chainIds = new uint16[](size);\n uint256 k = 0;\n precrimeAddresses = new bytes32[](size);\n for (uint16 i = 0; i < remoteChainIds.length; i++) {\n for (uint16 j = 0; j < _packets.length; j++) {\n uint16 srcChainId = _packets[j].srcChainId;\n if (remoteChainIds[i] == srcChainId) {\n chainIds[k] = srcChainId;\n precrimeAddresses[k] = remotePrecrimeAddresses[i];\n k++;\n break;\n }\n }\n }\n }\n }\n\n function _getRelatedRemoteSize(Packet[] memory _packets) internal view returns (uint16 size) {\n for (uint16 i = 0; i < remoteChainIds.length; i++) {\n for (uint16 j = 0; j < _packets.length; j++) {\n if (remoteChainIds[i] == _packets[j].srcChainId) {\n size++;\n break;\n }\n }\n }\n }\n}\n"
|
|
12
|
+
},
|
|
13
|
+
"contracts/precrime/example/view/CounterPrecrimeView.sol": {
|
|
14
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport \"../../PreCrimeView.sol\";\nimport \"./CounterView.sol\";\nimport \"./CounterV.sol\";\n\ncontract CounterPrecrimeView is PreCrimeView {\n CounterView public counterView;\n\n uint16[] public remoteChainIds;\n bytes32[] public remotePrecrimeAddresses;\n\n struct SimulationResult {\n uint16 chainId;\n CounterView.CountState countState;\n }\n\n constructor(uint16 _localChainId, address _counterView) PreCrimeView(_localChainId) {\n counterView = CounterView(_counterView);\n maxBatchSize = 10;\n }\n\n function setRemotePrecrimeAddresses(\n uint16[] memory _remoteChainIds,\n bytes32[] memory _remotePrecrimeAddresses\n ) public onlyPrecrimeAdmin {\n require(_remoteChainIds.length == _remotePrecrimeAddresses.length, \"Precrime: invalid size\");\n remoteChainIds = _remoteChainIds;\n remotePrecrimeAddresses = _remotePrecrimeAddresses;\n }\n\n function setCounterView(address _counterView) public onlyPrecrimeAdmin {\n counterView = CounterView(_counterView);\n }\n\n function _simulate(Packet[] calldata _packets) internal view override returns (uint16 code, bytes memory data) {\n // get state from counter\n CounterView.CountState memory countState = counterView.getCountState(remoteChainIds);\n\n // simulate\n for (uint256 i = 0; i < _packets.length; i++) {\n Packet memory packet = _packets[i];\n countState = counterView.lzReceive(countState, packet.srcChainId);\n }\n\n // return simulation result\n return (CODE_SUCCESS, abi.encode(SimulationResult({chainId: localChainId, countState: countState})));\n }\n\n function _precrime(\n bytes[] memory _simulation\n ) internal view virtual override returns (uint16 code, bytes memory reason) {\n (SimulationResult memory localResult, SimulationResult[] memory results) = _getLocalSimulateResult(_simulation);\n\n uint sumOutboundCount = 0;\n // for each chainPathCount, find the chainPathCount and check the counts\n for (uint256 j = 0; j < localResult.countState.chainPathCounts.length; j++) {\n CounterView.ChainPathCount memory cpCount = localResult.countState.chainPathCounts[j];\n // find remote to local count state\n // should provide all peers simulated results\n CounterView.ChainPathCount memory remoteCp = _getRemoteCpCount(results, cpCount.eid);\n (code, reason) = _assertChainPathCount(cpCount, remoteCp);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n sumOutboundCount += remoteCp.outboundCount; // remote to local outbound count\n }\n (code, reason) = _assertTotalCount(localResult.countState, sumOutboundCount);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n\n return (CODE_SUCCESS, \"\");\n }\n\n function _getRemoteCpCount(\n SimulationResult[] memory _results,\n uint16 _remoteId\n ) internal view returns (CounterView.ChainPathCount memory) {\n uint localEid = localChainId;\n for (uint256 i = 0; i < _results.length; i++) {\n SimulationResult memory remoteResult = _results[i];\n if (remoteResult.chainId == _remoteId) {\n for (uint256 j = 0; j < remoteResult.countState.chainPathCounts.length; j++) {\n CounterView.ChainPathCount memory cpCount = remoteResult.countState.chainPathCounts[j];\n if (cpCount.eid == localEid) {\n // find to localEid path\n return cpCount;\n }\n }\n }\n }\n revert(\"Precrime: count state not found\");\n }\n\n function _getLocalSimulateResult(\n bytes[] memory _simulation\n ) internal view returns (SimulationResult memory localResult, SimulationResult[] memory results) {\n // decode results\n results = new SimulationResult[](_simulation.length);\n for (uint256 i = 0; i < _simulation.length; i++) {\n results[i] = abi.decode(_simulation[i], (SimulationResult));\n if (results[i].chainId == localChainId) {\n localResult = results[i];\n }\n }\n }\n\n function _assertChainPathCount(\n CounterView.ChainPathCount memory _localCpCount,\n CounterView.ChainPathCount memory _remoteCpCount\n ) internal pure returns (uint16 code, bytes memory reason) {\n if (_localCpCount.inboundCount > _remoteCpCount.outboundCount) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: inboundCount > outboundCount\");\n }\n if (_localCpCount.outboundCount > _remoteCpCount.inboundCount) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: outboundCount > inboundCount\");\n }\n return (CODE_SUCCESS, \"\");\n }\n\n function _assertTotalCount(\n CounterView.CountState memory _localCount,\n uint _sumOutbound\n ) internal pure returns (uint16 code, bytes memory reason) {\n if (_localCount.totalCount > _sumOutbound) {\n return (CODE_PRECRIME_FAILURE, \"Precrime: totalCount > sum outboundCount\");\n }\n return (CODE_SUCCESS, \"\");\n }\n\n function _remotePrecrimeAddress(\n Packet[] calldata _packets\n ) internal view override returns (uint16[] memory chainIds, bytes32[] memory precrimeAddresses) {\n if (_packets.length == 0) {\n return (remoteChainIds, remotePrecrimeAddresses);\n }\n\n // only return related remotes\n uint16 size = _getRelatedRemoteSize(_packets);\n if (size > 0) {\n chainIds = new uint16[](size);\n uint256 k = 0;\n precrimeAddresses = new bytes32[](size);\n for (uint16 i = 0; i < remoteChainIds.length; i++) {\n for (uint16 j = 0; j < _packets.length; j++) {\n uint16 srcChainId = _packets[j].srcChainId;\n if (remoteChainIds[i] == srcChainId) {\n chainIds[k] = srcChainId;\n precrimeAddresses[k] = remotePrecrimeAddresses[i];\n k++;\n break;\n }\n }\n }\n }\n }\n\n function _getRelatedRemoteSize(Packet[] memory _packets) internal view returns (uint16 size) {\n for (uint16 i = 0; i < remoteChainIds.length; i++) {\n for (uint16 j = 0; j < _packets.length; j++) {\n if (remoteChainIds[i] == _packets[j].srcChainId) {\n size++;\n break;\n }\n }\n }\n }\n\n function _getInboundNonce(Packet memory packet) internal view override returns (uint64) {\n CounterV counter = counterView.counter();\n return counter.getInboundNonce(packet.srcChainId);\n }\n}\n"
|
|
15
|
+
},
|
|
16
|
+
"contracts/precrime/example/view/CounterV.sol": {
|
|
17
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\ncontract CounterV {\n // keep track of how many messages have been received from other chains\n uint public totalCount;\n mapping(uint32 => uint) public inboundCount;\n mapping(uint32 => uint) public outboundCount;\n\n event Send(uint16 dstChainId);\n event Receive(uint16 srcChainId);\n\n uint16 public chainId;\n\n constructor(uint16 _chainId) {\n chainId = _chainId;\n }\n\n function lzReceive(uint16 _srcChainId) external {\n inboundCount[_srcChainId]++;\n totalCount++;\n\n emit Receive(_srcChainId);\n }\n\n function increment(uint16 _dstChainId) external {\n outboundCount[_dstChainId]++;\n\n emit Send(_dstChainId);\n }\n\n function brokeIncrement(uint16 _dstChainId) external {\n emit Send(_dstChainId);\n }\n\n function brokeTotalCount() external {\n totalCount++;\n }\n\n function getInboundNonce(uint16 _chainId) public view returns (uint64) {\n // in reality, this would be a call to the LayerZero endpoint\n return uint64(inboundCount[_chainId]);\n }\n}\n"
|
|
18
|
+
},
|
|
19
|
+
"contracts/precrime/example/view/CounterView.sol": {
|
|
20
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport \"./CounterV.sol\";\n\ncontract CounterView {\n struct CountState {\n uint totalCount;\n ChainPathCount[] chainPathCounts;\n }\n\n struct ChainPathCount {\n uint16 eid;\n uint inboundCount;\n uint outboundCount;\n }\n\n CounterV public counter;\n\n constructor(address _counter) {\n counter = CounterV(_counter);\n }\n\n function lzReceive(CountState memory countState, uint16 _srcChainId) public pure returns (CountState memory) {\n // do receive logic\n for (uint i = 0; i < countState.chainPathCounts.length; i++) {\n ChainPathCount memory chainPathCount = countState.chainPathCounts[i];\n if (chainPathCount.eid == _srcChainId) {\n countState.totalCount++;\n chainPathCount.inboundCount++;\n countState.chainPathCounts[i] = chainPathCount;\n break;\n }\n }\n return countState;\n }\n\n /**\n * @notice Get the count states for a list of peers\n * @param peers - the list of remote chainId to get counts for\n * @return counts - the CountState with the total count and the chain path counts\n */\n function getCountState(uint16[] calldata peers) public view returns (CountState memory) {\n ChainPathCount[] memory chainPathCounts = new ChainPathCount[](peers.length);\n\n for (uint i = 0; i < peers.length; i++) {\n uint16 peer = peers[i];\n chainPathCounts[i] = ChainPathCount({\n eid: peer,\n inboundCount: counter.inboundCount(peer),\n outboundCount: counter.outboundCount(peer)\n });\n }\n\n CountState memory countState = CountState({totalCount: counter.totalCount(), chainPathCounts: chainPathCounts});\n\n return countState;\n }\n}\n"
|
|
21
|
+
},
|
|
22
|
+
"contracts/precrime/interfaces/IPreCrime.sol": {
|
|
23
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.7.0;\npragma abicoder v2;\n\nimport \"./IPreCrimeBase.sol\";\n\ninterface IPreCrime is IPreCrimeBase {\n /**\n * @dev simulate run cross chain packets and get a simulation result for precrime later\n * @param _packets packets, the packets item should group by srcChainId, srcAddress, then sort by nonce\n * @return code simulation result code; see the error code defination\n * @return result the result is use for precrime params\n */\n function simulate(Packet[] calldata _packets) external returns (uint16 code, bytes memory result);\n}\n"
|
|
24
|
+
},
|
|
25
|
+
"contracts/precrime/interfaces/IPreCrimeBase.sol": {
|
|
26
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.7.0;\npragma abicoder v2;\n\ninterface IPreCrimeBase {\n struct Packet {\n uint16 srcChainId; // source chain id\n bytes32 srcAddress; // srouce UA address\n uint64 nonce;\n bytes payload;\n }\n\n /**\n * @dev get precrime config,\n * @param _packets packets\n * @return bytes of [maxBatchSize, remotePrecrimes]\n */\n function getConfig(Packet[] calldata _packets) external view returns (bytes memory);\n\n /**\n * @dev\n * @param _simulation all simulation results from difference chains\n * @return code precrime result code; check out the error code defination\n * @return reason error reason\n */\n function precrime(\n Packet[] calldata _packets,\n bytes[] calldata _simulation\n ) external view returns (uint16 code, bytes memory reason);\n\n /**\n * @dev protocol version\n */\n function version() external view returns (uint16);\n}\n"
|
|
27
|
+
},
|
|
28
|
+
"contracts/precrime/interfaces/IPreCrimeView.sol": {
|
|
29
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.7.0;\npragma abicoder v2;\n\nimport \"./IPreCrimeBase.sol\";\n\ninterface IPreCrimeView is IPreCrimeBase {\n /**\n * @dev simulate run cross chain packets and get a simulation result for precrime later\n * @param _packets packets, the packets item should group by srcChainId, srcAddress, then sort by nonce\n * @return code simulation result code; see the error code defination\n * @return result the result is use for precrime params\n */\n function simulate(Packet[] calldata _packets) external view returns (uint16 code, bytes memory result);\n}\n"
|
|
30
|
+
},
|
|
31
|
+
"contracts/precrime/PreCrime.sol": {
|
|
32
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"./interfaces/IPreCrime.sol\";\nimport \"./PreCrimeBase.sol\";\n\nabstract contract PreCrime is PreCrimeBase, IPreCrime {\n bytes4 private constant SIMULATE_REVERT_SELECTOR = bytes4(keccak256(\"SimulateRevert(uint16,bytes)\"));\n\n /**\n * @dev 10000 - 20000 is for view mode, 20000 - 30000 is for precrime inherit mode\n */\n uint16 public constant PRECRIME_VERSION = 20001;\n\n constructor(uint16 _localChainId) PreCrimeBase(_localChainId) {}\n\n /**\n * @dev simulate run cross chain packets and get a simulation result for precrime later\n * @param _packets packets, the packets item should group by srcChainId, srcAddress, then sort by nonce\n * @return code simulation result code; see the error code defination\n * @return data the result is use for precrime params\n */\n function simulate(Packet[] calldata _packets) external override returns (uint16 code, bytes memory data) {\n // params check\n (code, data) = _checkPacketsMaxSizeAndNonceOrder(_packets);\n if (code != CODE_SUCCESS) {\n return (code, data);\n }\n\n (bool success, bytes memory result) = address(this).call(\n abi.encodeWithSelector(this._simulateAndRevert.selector, _packets)\n );\n require(!success, \"simulate should never return success\");\n\n // parse code and data\n (code, data) = _parseRevertResult(result);\n if (code == CODE_SUCCESS) {\n data = abi.encode(localChainId, data); // add localChainId to the header\n }\n }\n\n function _parseRevertResult(bytes memory result) internal pure returns (uint16 code, bytes memory data) {\n // check revert selector\n bytes4 selector;\n assembly {\n selector := mload(add(result, 0x20)) // skip the length and get bytes4 selector\n }\n if (selector != SIMULATE_REVERT_SELECTOR) {\n // bubble up the internal error\n assembly {\n revert(add(result, 0x20), mload(result))\n }\n }\n\n // parse code and result\n assembly {\n // Slice the sighash. Remove the selector which is the first 4 bytes\n result := add(result, 0x04)\n }\n return abi.decode(result, (uint16, bytes));\n }\n\n /**\n * @dev internal function, no one should call\n * @param _packets packets\n */\n function _simulateAndRevert(Packet[] calldata _packets) external virtual {\n require(msg.sender == address(this));\n (uint16 code, bytes memory simulation) = _simulate(_packets);\n // equal to: revert SimulateRevert(code, result);\n bytes memory revertData = abi.encodePacked(SIMULATE_REVERT_SELECTOR, abi.encode(code, simulation));\n assembly {\n revert(add(revertData, 32), mload(revertData))\n }\n }\n\n /**\n * @dev UA execute the logic by _packets, and return simulation result for precrime. would revert state after returned result.\n * @param _packets packets\n * @return code\n * @return result\n */\n function _simulate(Packet[] calldata _packets) internal virtual returns (uint16 code, bytes memory result);\n\n function version() external pure override returns (uint16) {\n return PRECRIME_VERSION;\n }\n}\n"
|
|
33
|
+
},
|
|
34
|
+
"contracts/precrime/PreCrimeBase.sol": {
|
|
35
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"./interfaces/IPreCrime.sol\";\n\nabstract contract PreCrimeBase is IPreCrimeBase {\n uint16 public constant CONFIG_VERSION = 1;\n\n //---------------- error code ----------------------\n // --- UA scope code ---\n uint16 public constant CODE_SUCCESS = 0; // success\n uint16 public constant CODE_PRECRIME_FAILURE = 1; // !!! crimes found\n\n // --- protocol scope error code ---\n // simualte\n uint16 public constant CODE_PACKETS_OVERSIZE = 2; // packets number bigger then max size\n uint16 public constant CODE_PACKETS_UNSORTED = 3; // packets are unsorted, need backfill and keep order\n // precrime\n uint16 public constant CODE_MISS_SIMULATE_RESULT = 4; // miss simulation result\n\n uint16 public immutable localChainId;\n uint64 public maxBatchSize;\n address public precrimeAdmin;\n\n modifier onlyPrecrimeAdmin() {\n require(msg.sender == precrimeAdmin, \"only admin\");\n _;\n }\n\n constructor(uint16 _localChainId) {\n localChainId = _localChainId;\n precrimeAdmin = msg.sender;\n }\n\n function setPrecrimeAdmin(address _precrimeAdmin) external onlyPrecrimeAdmin {\n precrimeAdmin = _precrimeAdmin;\n }\n\n function setMaxBatchSize(uint64 _maxBatchSize) external onlyPrecrimeAdmin {\n maxBatchSize = _maxBatchSize;\n }\n\n /**\n * @dev get precrime config,\n * @param _packets packets\n * @return configation bytes\n */\n function getConfig(Packet[] calldata _packets) external view virtual override returns (bytes memory) {\n (uint16[] memory remoteChains, bytes32[] memory remoteAddresses) = _remotePrecrimeAddress(_packets);\n return\n abi.encodePacked(\n CONFIG_VERSION,\n //---- max packets size for simulate batch ---\n maxBatchSize,\n //------------- remote precrimes -------------\n remoteChains.length,\n remoteChains,\n remoteAddresses\n );\n }\n\n /**\n * @dev\n * @param _simulation all simulation results from difference chains\n * @return code precrime result code; check out the error code definition\n * @return reason error reason\n */\n function precrime(\n Packet[] calldata _packets,\n bytes[] calldata _simulation\n ) external view override returns (uint16 code, bytes memory reason) {\n bytes[] memory originSimulateResult = new bytes[](_simulation.length);\n uint16[] memory chainIds = new uint16[](_simulation.length);\n for (uint256 i = 0; i < _simulation.length; i++) {\n (uint16 chainId, bytes memory simulateResult) = abi.decode(_simulation[i], (uint16, bytes));\n chainIds[i] = chainId;\n originSimulateResult[i] = simulateResult;\n }\n\n (code, reason) = _checkResultsCompleteness(_packets, chainIds);\n if (code != CODE_SUCCESS) {\n return (code, reason);\n }\n\n (code, reason) = _precrime(originSimulateResult);\n }\n\n function _checkPacketsMaxSizeAndNonceOrder(\n Packet[] calldata _packets\n ) internal view returns (uint16 code, bytes memory reason) {\n if (_packets.length > maxBatchSize) {\n return (CODE_PACKETS_OVERSIZE, abi.encodePacked(\"packets size exceed limited\"));\n }\n\n // check packets nonce, sequence order\n // packets should group by srcChainId and srcAddress, then sort by nonce ascending\n if (_packets.length > 0) {\n uint16 srcChainId;\n bytes32 srcAddress;\n uint64 nonce;\n for (uint256 i = 0; i < _packets.length; i++) {\n Packet memory packet = _packets[i];\n // start from a new chain packet or a new source UA\n if (packet.srcChainId != srcChainId || packet.srcAddress != srcAddress) {\n srcChainId = packet.srcChainId;\n srcAddress = packet.srcAddress;\n nonce = packet.nonce;\n uint64 nextInboundNonce = _getInboundNonce(packet) + 1;\n // the first packet's nonce must equal to dst InboundNonce+1\n if (nonce != nextInboundNonce) {\n return (CODE_PACKETS_UNSORTED, abi.encodePacked(\"skipped inboundNonce forbidden\"));\n }\n } else {\n // the following packet's nonce add 1 in order\n if (packet.nonce != ++nonce) {\n return (CODE_PACKETS_UNSORTED, abi.encodePacked(\"unsorted packets\"));\n }\n }\n }\n }\n return (CODE_SUCCESS, \"\");\n }\n\n function _checkResultsCompleteness(\n Packet[] calldata _packets,\n uint16[] memory _resultChainIds\n ) internal view returns (uint16 code, bytes memory reason) {\n // check if all remote result included\n if (_packets.length > 0) {\n (uint16[] memory remoteChains, ) = _remotePrecrimeAddress(_packets);\n for (uint256 i = 0; i < remoteChains.length; i++) {\n bool resultChainIdChecked;\n for (uint256 j = 0; j < _resultChainIds.length; j++) {\n if (_resultChainIds[j] == remoteChains[i]) {\n resultChainIdChecked = true;\n break;\n }\n }\n if (!resultChainIdChecked) {\n return (CODE_MISS_SIMULATE_RESULT, \"missing remote simulation result\");\n }\n }\n }\n // check if local result included\n bool localChainIdResultChecked;\n for (uint256 j = 0; j < _resultChainIds.length; j++) {\n if (_resultChainIds[j] == localChainId) {\n localChainIdResultChecked = true;\n break;\n }\n }\n if (!localChainIdResultChecked) {\n return (CODE_MISS_SIMULATE_RESULT, \"missing local simulation result\");\n }\n\n return (CODE_SUCCESS, \"\");\n }\n\n /**\n * @dev\n * @param _simulation all simulation results from difference chains\n * @return code precrime result code; check out the error code defination\n * @return reason error reason\n */\n function _precrime(bytes[] memory _simulation) internal view virtual returns (uint16 code, bytes memory reason);\n\n /**\n * @dev UA return trusted remote precrimes by packets\n * @param _packets packets\n * @return\n */\n function _remotePrecrimeAddress(\n Packet[] calldata _packets\n ) internal view virtual returns (uint16[] memory, bytes32[] memory);\n\n /**\n * get srcChain & srcAddress InboundNonce by packet\n */\n function _getInboundNonce(Packet memory packet) internal view virtual returns (uint64 nonce);\n}\n"
|
|
36
|
+
},
|
|
37
|
+
"contracts/precrime/PreCrimeView.sol": {
|
|
38
|
+
"content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"./interfaces/IPreCrimeView.sol\";\nimport \"./PreCrimeBase.sol\";\n\nabstract contract PreCrimeView is PreCrimeBase, IPreCrimeView {\n /**\n * @dev 10000 - 20000 is for view mode, 20000 - 30000 is for precrime inherit mode\n */\n uint16 public constant PRECRIME_VERSION = 10001;\n\n constructor(uint16 _localChainId) PreCrimeBase(_localChainId) {}\n\n /**\n * @dev simulate run cross chain packets and get a simulation result for precrime later\n * @param _packets packets, the packets item should group by srcChainId, srcAddress, then sort by nonce\n * @return code simulation result code; see the error code defination\n * @return data the result is use for precrime params\n */\n function simulate(Packet[] calldata _packets) external view override returns (uint16 code, bytes memory data) {\n // params check\n (code, data) = _checkPacketsMaxSizeAndNonceOrder(_packets);\n if (code != CODE_SUCCESS) {\n return (code, data);\n }\n\n (code, data) = _simulate(_packets);\n if (code == CODE_SUCCESS) {\n data = abi.encode(localChainId, data); // add localChainId to the header\n }\n }\n\n /**\n * @dev UA execute the logic by _packets, and return simulation result for precrime. would revert state after returned result.\n * @param _packets packets\n * @return code\n * @return result\n */\n function _simulate(Packet[] calldata _packets) internal view virtual returns (uint16 code, bytes memory result);\n\n function version() external pure override returns (uint16) {\n return PRECRIME_VERSION;\n }\n}\n"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"settings": {
|
|
42
|
+
"optimizer": {
|
|
43
|
+
"enabled": true,
|
|
44
|
+
"runs": 10000
|
|
45
|
+
},
|
|
46
|
+
"outputSelection": {
|
|
47
|
+
"*": {
|
|
48
|
+
"*": [
|
|
49
|
+
"abi",
|
|
50
|
+
"evm.bytecode",
|
|
51
|
+
"evm.deployedBytecode",
|
|
52
|
+
"evm.methodIdentifiers",
|
|
53
|
+
"metadata",
|
|
54
|
+
"devdoc",
|
|
55
|
+
"userdoc",
|
|
56
|
+
"storageLayout",
|
|
57
|
+
"evm.gasEstimates"
|
|
58
|
+
],
|
|
59
|
+
"": [
|
|
60
|
+
"ast"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"metadata": {
|
|
65
|
+
"useLiteralContent": true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"id": "c07ea489478e10846c028cfcb72e5b2e",
|
|
2
3
|
"solcLongVersion": "zkVM-0.8.17-1.0.1",
|
|
3
4
|
"input": {
|
|
5
|
+
"language": "Solidity",
|
|
4
6
|
"sources": {
|
|
5
7
|
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
|
|
6
8
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport {Initializable} from \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
@@ -228,6 +230,27 @@
|
|
|
228
230
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nabstract contract Proxied {\n /// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them\n /// It also allows these functions to be called inside a contructor\n /// even if the contract is meant to be used without proxy\n modifier proxied() {\n address proxyAdminAddress = _proxyAdmin();\n // With hardhat-deploy proxies\n // the proxyAdminAddress is zero only for the implementation contract\n // if the implementation contract want to be used as a standalone/immutable contract\n // it simply has to execute the `proxied` function\n // This ensure the proxyAdminAddress is never zero post deployment\n // And allow you to keep the same code for both proxied contract and immutable contract\n if (proxyAdminAddress == address(0)) {\n // ensure can not be called twice when used outside of proxy : no admin\n // solhint-disable-next-line security/no-inline-assembly\n assembly {\n sstore(\n 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,\n 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n )\n }\n } else {\n require(msg.sender == proxyAdminAddress);\n }\n _;\n }\n\n modifier onlyProxyAdmin() {\n require(msg.sender == _proxyAdmin(), \"NOT_AUTHORIZED\");\n _;\n }\n\n function _proxyAdmin() internal view returns (address ownerAddress) {\n // solhint-disable-next-line security/no-inline-assembly\n assembly {\n ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)\n }\n }\n}\n"
|
|
229
231
|
}
|
|
230
232
|
},
|
|
231
|
-
"
|
|
233
|
+
"settings": {
|
|
234
|
+
"optimizer": {
|
|
235
|
+
"enabled": true,
|
|
236
|
+
"mode": "3"
|
|
237
|
+
},
|
|
238
|
+
"outputSelection": {
|
|
239
|
+
"*": {
|
|
240
|
+
"*": [
|
|
241
|
+
"abi",
|
|
242
|
+
"evm.methodIdentifiers",
|
|
243
|
+
"metadata",
|
|
244
|
+
"devdoc",
|
|
245
|
+
"userdoc",
|
|
246
|
+
"storageLayout"
|
|
247
|
+
],
|
|
248
|
+
"": [
|
|
249
|
+
"ast"
|
|
250
|
+
]
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
"libraries": {}
|
|
254
|
+
}
|
|
232
255
|
}
|
|
233
256
|
}
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
"type": "function"
|
|
163
163
|
}
|
|
164
164
|
],
|
|
165
|
-
"transactionHash": "
|
|
165
|
+
"transactionHash": "0xb9cf61b42bacc44be759dba50519322b08c00187e6862c97ff519cafac7a23be",
|
|
166
166
|
"receipt": {
|
|
167
167
|
"to": null,
|
|
168
168
|
"from": "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
|
|
@@ -170,13 +170,13 @@
|
|
|
170
170
|
"transactionIndex": 0,
|
|
171
171
|
"gasUsed": "704429",
|
|
172
172
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000800000000000000000000000000000000000010000000000000000000000000000000000100000000000000000000000000000000000000001000000000000000000000000000000000000020000000000000000000800000800000000000000000000000000400000000000000000000000000000000000000000000000000400000000000000000000000000200000000000000000000000010000000000000000000000000000000000000000000000000000000000400000000000000000000000000020000000000000000000000010000000000000000000000000020000000000000000",
|
|
173
|
-
"blockHash": "
|
|
174
|
-
"transactionHash": "
|
|
173
|
+
"blockHash": "0xf57d5d94a5c0f7bb930ad12150dabbdc60cee780f3000e708e653d8ad9f5b1a6",
|
|
174
|
+
"transactionHash": "0xb9cf61b42bacc44be759dba50519322b08c00187e6862c97ff519cafac7a23be",
|
|
175
175
|
"logs": [
|
|
176
176
|
{
|
|
177
177
|
"transactionIndex": 0,
|
|
178
|
-
"blockNumber":
|
|
179
|
-
"transactionHash": "
|
|
178
|
+
"blockNumber": 12,
|
|
179
|
+
"transactionHash": "0xb9cf61b42bacc44be759dba50519322b08c00187e6862c97ff519cafac7a23be",
|
|
180
180
|
"address": "0xBC9129Dc0487fc2E169941C75aABC539f208fb01",
|
|
181
181
|
"topics": [
|
|
182
182
|
"0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
|
|
@@ -185,12 +185,12 @@
|
|
|
185
185
|
],
|
|
186
186
|
"data": "0x",
|
|
187
187
|
"logIndex": 0,
|
|
188
|
-
"blockHash": "
|
|
188
|
+
"blockHash": "0xf57d5d94a5c0f7bb930ad12150dabbdc60cee780f3000e708e653d8ad9f5b1a6"
|
|
189
189
|
},
|
|
190
190
|
{
|
|
191
191
|
"transactionIndex": 0,
|
|
192
|
-
"blockNumber":
|
|
193
|
-
"transactionHash": "
|
|
192
|
+
"blockNumber": 12,
|
|
193
|
+
"transactionHash": "0xb9cf61b42bacc44be759dba50519322b08c00187e6862c97ff519cafac7a23be",
|
|
194
194
|
"address": "0xBC9129Dc0487fc2E169941C75aABC539f208fb01",
|
|
195
195
|
"topics": [
|
|
196
196
|
"0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
|
|
@@ -199,10 +199,10 @@
|
|
|
199
199
|
],
|
|
200
200
|
"data": "0x",
|
|
201
201
|
"logIndex": 1,
|
|
202
|
-
"blockHash": "
|
|
202
|
+
"blockHash": "0xf57d5d94a5c0f7bb930ad12150dabbdc60cee780f3000e708e653d8ad9f5b1a6"
|
|
203
203
|
}
|
|
204
204
|
],
|
|
205
|
-
"blockNumber":
|
|
205
|
+
"blockNumber": 12,
|
|
206
206
|
"cumulativeGasUsed": "704429",
|
|
207
207
|
"status": 1,
|
|
208
208
|
"byzantium": true
|