@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.
Files changed (91) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/artifacts/verification/verification-data-4cacbc20c3ff94e1fab58d8d49589534.json +39 -0
  3. package/artifacts/verification/verification-data-5e6f8a9cc160013d3f2ed5cace5b3625.json +39 -0
  4. package/artifacts/verification/verification-data-7413301ee5ee573cec0ec95730482c21.json +39 -0
  5. package/artifacts/{verification-data.json → verification/verification-data-86687dceb611cadccbf9c44600d6dfef.json} +103 -171
  6. package/artifacts/verification/verification-data-b2be3b6b9aa4d482b239dd3c7b998b43.json +69 -0
  7. package/artifacts/verification/verification-data-b326d48ebf6e71f1e29ebf99156fbfff.json +39 -0
  8. package/artifacts/verification/verification-data-e7c1a5680ae8cae1ec9ffaf4cdbaed68.json +267 -0
  9. package/artifacts-tron/{verification-data.json → verification/verification-data-0c559044f5a1e91d85ee409c7cc0fc75.json} +29 -46
  10. package/artifacts-tron/verification/verification-data-1698b18cef59145feb6419b3eacba549.json +39 -0
  11. package/artifacts-tron/verification/verification-data-24492b3a86a1195fe1b202109347e27e.json +39 -0
  12. package/artifacts-tron/verification/verification-data-8a65080bfd6e652b21df7756fb5779c9.json +39 -0
  13. package/artifacts-tron/verification/verification-data-d25a40a50e55d137530e079a13031b48.json +39 -0
  14. package/artifacts-tron/verification/verification-data-edf0138b97898d26cfc0e872ce8b1c0b.json +69 -0
  15. package/artifacts-zk/{verification-data.json → verification/verification-data-c07ea489478e10846c028cfcb72e5b2e.json} +24 -1
  16. package/deployments/arbitrum-sandbox-local/DefaultProxyAdmin.json +10 -10
  17. package/deployments/arbitrum-sandbox-local/Endpoint.json +7 -7
  18. package/deployments/arbitrum-sandbox-local/FPValidator.json +4 -4
  19. package/deployments/arbitrum-sandbox-local/MPTValidator01.json +4 -4
  20. package/deployments/arbitrum-sandbox-local/NonceContract.json +4 -4
  21. package/deployments/arbitrum-sandbox-local/RelayerV2.json +16 -16
  22. package/deployments/arbitrum-sandbox-local/RelayerV2_Implementation.json +4 -4
  23. package/deployments/arbitrum-sandbox-local/RelayerV2_Proxy.json +16 -16
  24. package/deployments/arbitrum-sandbox-local/TreasuryV2.json +7 -7
  25. package/deployments/arbitrum-sandbox-local/UltraLightNode.json +7 -7
  26. package/deployments/arbitrum-sandbox-local/UltraLightNodeV2.json +7 -7
  27. package/deployments/bsc-sandbox-local/DefaultProxyAdmin.json +10 -10
  28. package/deployments/bsc-sandbox-local/Endpoint.json +7 -7
  29. package/deployments/bsc-sandbox-local/FPValidator.json +4 -4
  30. package/deployments/bsc-sandbox-local/MPTValidator01.json +4 -4
  31. package/deployments/bsc-sandbox-local/NonceContract.json +4 -4
  32. package/deployments/bsc-sandbox-local/RelayerV2.json +16 -16
  33. package/deployments/bsc-sandbox-local/RelayerV2_Implementation.json +4 -4
  34. package/deployments/bsc-sandbox-local/RelayerV2_Proxy.json +16 -16
  35. package/deployments/bsc-sandbox-local/TreasuryV2.json +7 -7
  36. package/deployments/bsc-sandbox-local/UltraLightNode.json +7 -7
  37. package/deployments/bsc-sandbox-local/UltraLightNodeV2.json +7 -7
  38. package/deployments/ethereum-sandbox-local/DefaultProxyAdmin.json +7 -7
  39. package/deployments/ethereum-sandbox-local/Endpoint.json +5 -5
  40. package/deployments/ethereum-sandbox-local/FPValidator.json +3 -3
  41. package/deployments/ethereum-sandbox-local/MPTValidator01.json +3 -3
  42. package/deployments/ethereum-sandbox-local/NonceContract.json +3 -3
  43. package/deployments/ethereum-sandbox-local/RelayerV2.json +11 -11
  44. package/deployments/ethereum-sandbox-local/RelayerV2_Implementation.json +3 -3
  45. package/deployments/ethereum-sandbox-local/RelayerV2_Proxy.json +11 -11
  46. package/deployments/ethereum-sandbox-local/TreasuryV2.json +5 -5
  47. package/deployments/ethereum-sandbox-local/UltraLightNode.json +5 -5
  48. package/deployments/ethereum-sandbox-local/UltraLightNodeV2.json +5 -5
  49. package/deployments/humanity-mainnet/DefaultProxyAdmin.json +273 -0
  50. package/deployments/humanity-mainnet/Endpoint.json +1282 -0
  51. package/deployments/humanity-mainnet/FPValidator.json +382 -0
  52. package/deployments/humanity-mainnet/MPTValidator01.json +395 -0
  53. package/deployments/humanity-mainnet/NonceContract.json +159 -0
  54. package/deployments/humanity-mainnet/RelayerV2.json +1415 -0
  55. package/deployments/humanity-mainnet/RelayerV2_Implementation.json +1612 -0
  56. package/deployments/humanity-mainnet/RelayerV2_Proxy.json +245 -0
  57. package/deployments/humanity-mainnet/TreasuryV2.json +458 -0
  58. package/deployments/humanity-mainnet/UltraLightNodeV2.json +1816 -0
  59. package/deployments/humanity-testnet/DefaultProxyAdmin.json +273 -0
  60. package/deployments/humanity-testnet/Endpoint.json +1282 -0
  61. package/deployments/humanity-testnet/FPValidator.json +382 -0
  62. package/deployments/humanity-testnet/MPTValidator01.json +395 -0
  63. package/deployments/humanity-testnet/NonceContract.json +159 -0
  64. package/deployments/humanity-testnet/RelayerV2.json +1415 -0
  65. package/deployments/humanity-testnet/RelayerV2_Implementation.json +1612 -0
  66. package/deployments/humanity-testnet/RelayerV2_Proxy.json +245 -0
  67. package/deployments/humanity-testnet/TreasuryV2.json +458 -0
  68. package/deployments/humanity-testnet/UltraLightNodeV2.json +1816 -0
  69. package/deployments/polygon-sandbox-local/DefaultProxyAdmin.json +10 -10
  70. package/deployments/polygon-sandbox-local/Endpoint.json +7 -7
  71. package/deployments/polygon-sandbox-local/FPValidator.json +4 -4
  72. package/deployments/polygon-sandbox-local/MPTValidator01.json +4 -4
  73. package/deployments/polygon-sandbox-local/NonceContract.json +4 -4
  74. package/deployments/polygon-sandbox-local/RelayerV2.json +16 -16
  75. package/deployments/polygon-sandbox-local/RelayerV2_Implementation.json +4 -4
  76. package/deployments/polygon-sandbox-local/RelayerV2_Proxy.json +16 -16
  77. package/deployments/polygon-sandbox-local/TreasuryV2.json +7 -7
  78. package/deployments/polygon-sandbox-local/UltraLightNode.json +7 -7
  79. package/deployments/polygon-sandbox-local/UltraLightNodeV2.json +7 -7
  80. package/deployments/tron-sandbox-local/DefaultProxyAdmin.json +14 -14
  81. package/deployments/tron-sandbox-local/Endpoint.json +10 -10
  82. package/deployments/tron-sandbox-local/FPValidator.json +6 -6
  83. package/deployments/tron-sandbox-local/MPTValidator01.json +6 -6
  84. package/deployments/tron-sandbox-local/NonceContract.json +7 -7
  85. package/deployments/tron-sandbox-local/RelayerV2.json +31 -31
  86. package/deployments/tron-sandbox-local/RelayerV2_Implementation.json +6 -6
  87. package/deployments/tron-sandbox-local/RelayerV2_Proxy.json +28 -28
  88. package/deployments/tron-sandbox-local/TreasuryV2.json +11 -11
  89. package/deployments/tron-sandbox-local/UltraLightNode.json +11 -11
  90. package/deployments/tron-sandbox-local/UltraLightNodeV2.json +12 -12
  91. package/package.json +10 -10
@@ -0,0 +1,69 @@
1
+ {
2
+ "id": "b2be3b6b9aa4d482b239dd3c7b998b43",
3
+ "solcLongVersion": "0.7.6+commit.7338295f",
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": 30000
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
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "id": "b326d48ebf6e71f1e29ebf99156fbfff",
3
+ "solcLongVersion": "0.7.6+commit.7338295f",
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": 30000
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
+ }