@crossecute/protocol 0.0.0-stage → 0.1.0

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 (118) hide show
  1. package/README.md +26 -2
  2. package/abi/Blake2b256.json +1 -0
  3. package/abi/Blake2bScheme.json +1 -0
  4. package/abi/ChainRegistry.json +1 -0
  5. package/abi/Commitment.json +1 -0
  6. package/abi/Conduits.json +1 -0
  7. package/abi/DivergentConduits.json +1 -0
  8. package/abi/DivergentTransceiver.json +1 -0
  9. package/abi/DivergentTransceiverExtension.json +1 -0
  10. package/abi/Envelope.json +1 -0
  11. package/abi/Erc7930.json +1 -0
  12. package/abi/Executor.json +1 -0
  13. package/abi/IBootstrapAllowlist.json +1 -0
  14. package/abi/ICancel.json +1 -0
  15. package/abi/IChainRegistryRefs.json +1 -0
  16. package/abi/ICommitFinalize.json +1 -0
  17. package/abi/ICommitmentScheme.json +1 -0
  18. package/abi/IConduitReceiverReport.json +1 -0
  19. package/abi/IConduitTransceiver.json +1 -0
  20. package/abi/IERC7786GatewaySource.json +1 -0
  21. package/abi/IERC7786Recipient.json +1 -0
  22. package/abi/IExecute.json +1 -0
  23. package/abi/ILzOftConduitFactory.json +1 -0
  24. package/abi/IProviderIdTable.json +1 -0
  25. package/abi/IProxy.json +1 -0
  26. package/abi/IReceiverInit.json +1 -0
  27. package/abi/IRefValidator.json +1 -0
  28. package/abi/IReportFloat.json +1 -0
  29. package/abi/ITransmitterInit.json +1 -0
  30. package/abi/IVmDeriver.json +1 -0
  31. package/abi/KeccakScheme.json +1 -0
  32. package/abi/Move.json +1 -0
  33. package/abi/MoveValidator.json +1 -0
  34. package/abi/OpStackTransmitterBase.json +1 -0
  35. package/abi/OutboundBase.json +1 -0
  36. package/abi/OwnableTransmitter.json +1 -0
  37. package/abi/ProviderAddress.json +1 -0
  38. package/abi/ProviderAttribute.json +1 -0
  39. package/abi/ProviderChainId.json +1 -0
  40. package/abi/ProviderReceiver.json +1 -0
  41. package/abi/ProviderTransceiver.json +1 -0
  42. package/abi/Proxy.json +1 -0
  43. package/abi/ProxyDeployer.json +1 -0
  44. package/abi/ProxyInitCode.json +1 -0
  45. package/abi/ReceiverBase.json +1 -0
  46. package/abi/Roles.json +1 -0
  47. package/abi/RolesEnumerable.json +1 -0
  48. package/abi/SchemeFold.json +1 -0
  49. package/abi/Sha256Scheme.json +1 -0
  50. package/abi/StarknetDerive.json +1 -0
  51. package/abi/StarknetValidator.json +1 -0
  52. package/abi/SuiDerive.json +1 -0
  53. package/abi/TransceiverBase.json +1 -0
  54. package/abi/TransceiverCore.json +1 -0
  55. package/abi/TransceiverExtension.json +1 -0
  56. package/abi/TransmitterBase.json +1 -0
  57. package/abi/Treasury.json +1 -0
  58. package/abi/TronConduits.json +1 -0
  59. package/abi/TronTransceiver.json +1 -0
  60. package/abi/TronTransceiverExtension.json +1 -0
  61. package/abi/VmDeriver.json +1 -0
  62. package/abi/ZkSyncConduits.json +1 -0
  63. package/abi/ZkSyncTransceiver.json +1 -0
  64. package/abi/ZkSyncTransceiverExtension.json +1 -0
  65. package/abi/index.d.ts +63 -0
  66. package/abi/index.js +63 -0
  67. package/contracts/addressing/ChainKey.sol +45 -0
  68. package/contracts/addressing/ChainType.sol +50 -0
  69. package/contracts/addressing/Erc7930.sol +209 -0
  70. package/contracts/addressing/Move.sol +212 -0
  71. package/contracts/conduit/Conduits.sol +43 -0
  72. package/contracts/conduit/Proxy.sol +144 -0
  73. package/contracts/conduit/ProxyDeployer.sol +42 -0
  74. package/contracts/conduit/ProxyInitCode.sol +47 -0
  75. package/contracts/derivation/AddressDerive.sol +326 -0
  76. package/contracts/derivation/BitcoinDerive.sol +33 -0
  77. package/contracts/derivation/Blake2b256.sol +122 -0
  78. package/contracts/derivation/IVmDeriver.sol +35 -0
  79. package/contracts/derivation/StarknetDerive.sol +93 -0
  80. package/contracts/derivation/SuiDerive.sol +102 -0
  81. package/contracts/derivation/VmDeriver.sol +291 -0
  82. package/contracts/messaging/Call.sol +43 -0
  83. package/contracts/messaging/Commitment.sol +131 -0
  84. package/contracts/messaging/DeliveryGas.sol +18 -0
  85. package/contracts/messaging/Envelope.sol +123 -0
  86. package/contracts/messaging/Executor.sol +52 -0
  87. package/contracts/messaging/IErc7786.sol +68 -0
  88. package/contracts/messaging/Payload.sol +90 -0
  89. package/contracts/messaging/Roles.sol +113 -0
  90. package/contracts/messaging/inbound/ReceiverBase.sol +359 -0
  91. package/contracts/messaging/outbound/OutboundBase.sol +221 -0
  92. package/contracts/messaging/outbound/OwnableTransmitter.sol +23 -0
  93. package/contracts/messaging/outbound/TransmitterBase.sol +604 -0
  94. package/contracts/messaging/transceiver/DivergentConduits.sol +92 -0
  95. package/contracts/messaging/transceiver/DivergentTransceiver.sol +97 -0
  96. package/contracts/messaging/transceiver/IBootstrapAllowlist.sol +8 -0
  97. package/contracts/messaging/transceiver/TransceiverBase.sol +541 -0
  98. package/contracts/messaging/transceiver/TransceiverCore.sol +307 -0
  99. package/contracts/messaging/transceiver/TransceiverExtension.sol +278 -0
  100. package/contracts/protocols/ProviderAddress.sol +32 -0
  101. package/contracts/protocols/ProviderAttribute.sol +65 -0
  102. package/contracts/protocols/ProviderChainId.sol +115 -0
  103. package/contracts/protocols/ProviderReceiver.sol +24 -0
  104. package/contracts/protocols/ProviderTransceiver.sol +48 -0
  105. package/contracts/protocols/layerzero/ILzOftConduitFactory.sol +10 -0
  106. package/contracts/protocols/op-stack/OpStackTransmitterBase.sol +11 -0
  107. package/contracts/registry/ChainRegistry.sol +667 -0
  108. package/contracts/registry/IChainRegistryRefs.sol +81 -0
  109. package/contracts/registry/ICommitmentScheme.sol +46 -0
  110. package/contracts/registry/IRefValidator.sol +13 -0
  111. package/contracts/registry/Provenance.sol +25 -0
  112. package/contracts/schemes/Blake2bScheme.sol +18 -0
  113. package/contracts/schemes/KeccakScheme.sol +19 -0
  114. package/contracts/schemes/Sha256Scheme.sol +15 -0
  115. package/contracts/treasury/Treasury.sol +76 -0
  116. package/contracts/validators/MoveValidator.sol +24 -0
  117. package/contracts/validators/StarknetValidator.sol +20 -0
  118. package/package.json +36 -4
@@ -0,0 +1,92 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
5
+ import {AddressDerive} from "../../derivation/AddressDerive.sol";
6
+ import {Proxy} from "../../conduit/Proxy.sol";
7
+
8
+ /// @title DivergentConduits
9
+ /// @notice Conduit derivation for the chains whose CREATE2 differs from Ethereum's: zkSync Era
10
+ /// and Tron. Shared by every transceiver deployed there.
11
+ ///
12
+ /// @dev Both are `eip155`, so only the transceiver's own bytecode can know its chain's formula.
13
+ ///
14
+ /// @dev Forge runs Ethereum's EVM, so the suite pins only that each override reproduces
15
+ /// `AddressDerive`'s formula, that the bytecode hash is write-once, and that a mismatch
16
+ /// is refused by `_createConduit`. Deploying one conduit on Era and on Shasta is
17
+ /// still open: see [todo](../../../../../docs/todo.md#2-chain-checks-before-mainnet).
18
+ ///
19
+ /// @dev zksolc 1.5.17 over era-solc 0.8.28-1.0.2 builds `Proxy` and every contract a
20
+ /// transceiver needs. `BitcoinDerive` is split from `AddressDerive` for this: EraVM has no
21
+ /// `ripemd160`, and zksolc rejects a compilation unit that contains it at all.
22
+ ///
23
+ /// @dev Not a `TransceiverBase`: a mixin that did inherit it would meet every transceiver base's
24
+ /// own overrides in a diamond. Each transceiver overrides `_predictConduit`, in both
25
+ /// its `TransceiverBase` and its extension, and `_deployConduit` with a one-line call into the
26
+ /// helpers below.
27
+ abstract contract DivergentConduits is Initializable {
28
+ /// The hash this chain's deployer keys a conduit address by, in that chain's own form.
29
+ /// @dev Write-once. Not `PROXY_INIT_CODE_HASH`, which hashes the local compiler's
30
+ /// `creationCode` and is not what either deployer keys by: zkSync hashes a zksolc
31
+ /// artifact into an EraVM versioned hash, and Tron uses TRON-solc's initcode.
32
+ bytes32 public conduitBytecodeHash;
33
+
34
+ event ConduitBytecodeHashSet(bytes32 conduitBytecodeHash);
35
+
36
+ error ZeroConduitBytecodeHash();
37
+
38
+ /// @param conduitBytecodeHash_ For zkSync, `AddressDerive.hashL2Bytecode` over the
39
+ /// zksolc artifact for `Proxy`. For Tron, `keccak256` of Tron-solc's
40
+ /// `Proxy` initcode. Getting it wrong does not misdeliver: every conduit
41
+ /// creation reverts `ConduitAddressMismatch` until it is right.
42
+ function __DivergentConduits_init(bytes32 conduitBytecodeHash_) internal onlyInitializing {
43
+ if (conduitBytecodeHash_ == bytes32(0)) revert ZeroConduitBytecodeHash();
44
+ conduitBytecodeHash = conduitBytecodeHash_;
45
+ emit ConduitBytecodeHashSet(conduitBytecodeHash_);
46
+ }
47
+ }
48
+
49
+ /// @title ZkSyncConduits
50
+ /// @notice zkSync Era, which diverges in both seams.
51
+ ///
52
+ /// @dev The address: `zksyncCreate2` folds `keccak256("zksyncCreate2")`, the padded sender,
53
+ /// the salt, the EraVM versioned bytecode hash, and the constructor-input hash, which is
54
+ /// the constant `keccak256("")` for the argument-free `Proxy`.
55
+ ///
56
+ /// @dev The deployment: EraVM cannot deploy raw initcode; `new Proxy{salt: s}()` is what
57
+ /// zksolc lowers into the `ContractDeployer` system call. zksolc only warns on the base's
58
+ /// `Create2.deploy`, so a transceiver missing this override would build and fail on its
59
+ /// first conduit.
60
+ ///
61
+ /// @dev Under solc, `new ... {salt:}` is ordinary CREATE2, so in this repo's build the
62
+ /// deployment lands at Ethereum's address and the guard refuses: it fails closed.
63
+ abstract contract ZkSyncConduits is DivergentConduits {
64
+ /// @dev `Proxy` takes no constructor arguments, so the input is empty.
65
+ bytes32 internal constant EMPTY_CONSTRUCTOR_INPUT_HASH = keccak256("");
66
+
67
+ /// @notice Where this contract deploys a conduit at `conduitSalt` on Era.
68
+ function _zkSyncConduit(bytes32 conduitSalt) internal view returns (address) {
69
+ return
70
+ AddressDerive.zksyncCreate2(address(this), conduitSalt, conduitBytecodeHash, EMPTY_CONSTRUCTOR_INPUT_HASH);
71
+ }
72
+
73
+ /// @notice Deploy a conduit the way Era can: through the `ContractDeployer` system call.
74
+ function _zkSyncDeploy(bytes32 conduitSalt) internal returns (address) {
75
+ return address(new Proxy{salt: conduitSalt}());
76
+ }
77
+ }
78
+
79
+ /// @title TronConduits
80
+ /// @notice Tron, which diverges in the formula only.
81
+ ///
82
+ /// @dev EIP-1014's preimage with `0x41` in place of `0xff`, as java-tron computes it (see
83
+ /// `AddressDerive.tronCreate2`). The TRON-solc bytecode hash is unverified until one
84
+ /// conduit is deployed on Shasta and compared.
85
+ ///
86
+ /// @dev Tron runs raw-initcode CREATE2, so the base's `_deployConduit` stands.
87
+ abstract contract TronConduits is DivergentConduits {
88
+ /// @notice Where this contract deploys a conduit at `conduitSalt` on Tron.
89
+ function _tronConduit(bytes32 conduitSalt) internal view returns (address) {
90
+ return AddressDerive.tronCreate2(address(this), conduitSalt, conduitBytecodeHash);
91
+ }
92
+ }
@@ -0,0 +1,97 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {TransceiverBase, TransceiverConfig} from "./TransceiverBase.sol";
5
+ import {TransceiverExtension} from "./TransceiverExtension.sol";
6
+ import {DivergentConduits, ZkSyncConduits, TronConduits} from "./DivergentConduits.sol";
7
+
8
+ /// @title DivergentTransceiver
9
+ /// @notice The combined transceiver on zkSync Era and Tron, whose conduit addresses differ
10
+ /// from Ethereum's CREATE2. The derivation is `DivergentConduits`'.
11
+ ///
12
+ /// @dev Every receiver created here is reported to its home, which cannot derive it, so
13
+ /// `addressesDiverge` is set here rather than taken from the caller.
14
+ ///
15
+ /// @dev This transceiver does not sit at its provider's address on other chains, so its default
16
+ /// counterpart on a `Predetermined` chain is derived from the registry's record of the
17
+ /// provider's deployment, not taken from `address(this)` or typed in.
18
+ ///
19
+ /// @dev Each variant below has an extension variant beside it that overrides the same seams with
20
+ /// the same helper; `TransceiverBase.__TransceiverBase_init` refuses a pair whose owner
21
+ /// derivations differ.
22
+ abstract contract DivergentTransceiver is TransceiverBase, DivergentConduits {
23
+ /// @dev Sets the derivation inputs first: the extension derives the owner with them.
24
+ function __DivergentTransceiver_init(TransceiverConfig memory c, bytes32 conduitBytecodeHash_)
25
+ internal
26
+ onlyInitializing
27
+ {
28
+ __DivergentConduits_init(conduitBytecodeHash_);
29
+ __TransceiverBase_init(c, true);
30
+ }
31
+ }
32
+
33
+ /// @title ZkSyncTransceiver
34
+ /// @notice The combined transceiver on zkSync Era. See `ZkSyncConduits`.
35
+ abstract contract ZkSyncTransceiver is DivergentTransceiver, ZkSyncConduits {
36
+ function _predictConduit(address owner, bytes32 salt, bytes32 homeChainKey)
37
+ internal
38
+ view
39
+ virtual
40
+ override
41
+ returns (address)
42
+ {
43
+ return _zkSyncConduit(_conduitSalt(owner, salt, homeChainKey));
44
+ }
45
+
46
+ function _deployConduit(bytes32 salt) internal virtual override returns (address) {
47
+ return _zkSyncDeploy(salt);
48
+ }
49
+
50
+ /// @dev EraVM cannot deploy raw initcode, and `_deployConduit` here reads none.
51
+ function _storeProxyInitCode() internal virtual override returns (address) {
52
+ return address(0);
53
+ }
54
+ }
55
+
56
+ /// @title TronTransceiver
57
+ /// @notice The combined transceiver on Tron. See `TronConduits`.
58
+ abstract contract TronTransceiver is DivergentTransceiver, TronConduits {
59
+ function _predictConduit(address owner, bytes32 salt, bytes32 homeChainKey)
60
+ internal
61
+ view
62
+ virtual
63
+ override
64
+ returns (address)
65
+ {
66
+ return _tronConduit(_conduitSalt(owner, salt, homeChainKey));
67
+ }
68
+ }
69
+
70
+ /// @notice `TransceiverExtension` for a `DivergentTransceiver`.
71
+ abstract contract DivergentTransceiverExtension is TransceiverExtension, DivergentConduits {}
72
+
73
+ /// @notice The extension every `ZkSyncTransceiver` on a chain names.
74
+ contract ZkSyncTransceiverExtension is DivergentTransceiverExtension, ZkSyncConduits {
75
+ function _predictConduit(address owner, bytes32 salt, bytes32 homeChainKey)
76
+ internal
77
+ view
78
+ virtual
79
+ override
80
+ returns (address)
81
+ {
82
+ return _zkSyncConduit(_conduitSalt(owner, salt, homeChainKey));
83
+ }
84
+ }
85
+
86
+ /// @notice The extension every `TronTransceiver` on a chain names.
87
+ contract TronTransceiverExtension is DivergentTransceiverExtension, TronConduits {
88
+ function _predictConduit(address owner, bytes32 salt, bytes32 homeChainKey)
89
+ internal
90
+ view
91
+ virtual
92
+ override
93
+ returns (address)
94
+ {
95
+ return _tronConduit(_conduitSalt(owner, salt, homeChainKey));
96
+ }
97
+ }
@@ -0,0 +1,8 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.20;
3
+
4
+ /// @notice Decides which conduits a transceiver lets bootstrap, where its owner has named one.
5
+ interface IBootstrapAllowlist {
6
+ /// @param conduit The transmitter bootstrapping: `msg.sender` of `bootstrap`.
7
+ function isAllowed(address conduit) external view returns (bool);
8
+ }