@layerzerolabs/layerzero-v2-ton 3.0.19-ton.0 → 3.0.19-ton.1

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 (206) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/AllStorages.compiled.json +1 -1
  3. package/build/AllStorages.test.compiled.json +1 -1
  4. package/build/BaseContract.test.compiled.json +1 -1
  5. package/build/Channel.compiled.json +1 -1
  6. package/build/Channel.permissions.test.compiled.json +1 -1
  7. package/build/ChannelBurn.test.compiled.json +1 -1
  8. package/build/ChannelCommitPacket.test.compiled.json +1 -1
  9. package/build/ChannelConfig.test.compiled.json +1 -1
  10. package/build/ChannelInitialize.test.compiled.json +1 -1
  11. package/build/ChannelMsglibIntegration.test.compiled.json +1 -1
  12. package/build/ChannelMsglibSendCallback.test.compiled.json +1 -1
  13. package/build/ChannelNilify.test.compiled.json +1 -1
  14. package/build/ChannelReceive.test.compiled.json +1 -1
  15. package/build/ChannelReceiveCallback.test.compiled.json +1 -1
  16. package/build/ChannelReceiveView.test.compiled.json +1 -1
  17. package/build/ChannelSend.test.compiled.json +1 -1
  18. package/build/Classlib.test.compiled.json +1 -1
  19. package/build/ComputeDataSizeGas.test.compiled.json +1 -1
  20. package/build/Connection.compiled.json +1 -1
  21. package/build/Controller.assertions.test.compiled.json +1 -1
  22. package/build/Controller.compiled.json +1 -1
  23. package/build/Controller.permissions.test.compiled.json +1 -1
  24. package/build/Controller.test.compiled.json +1 -1
  25. package/build/Counter.compiled.json +1 -1
  26. package/build/Counter.permissions.test.compiled.json +1 -1
  27. package/build/Counter.setters.test.compiled.json +1 -1
  28. package/build/Counter.test.compiled.json +1 -1
  29. package/build/Dvn.compiled.json +1 -1
  30. package/build/Dvn.test.compiled.json +1 -1
  31. package/build/DvnFeeLib.compiled.json +1 -1
  32. package/build/DvnPermissions.test.compiled.json +1 -1
  33. package/build/Endpoint.compiled.json +1 -1
  34. package/build/Endpoint.permissions.test.compiled.json +1 -1
  35. package/build/Endpoint.test.compiled.json +1 -1
  36. package/build/EndpointSetEpConfigDefaults.test.compiled.json +1 -1
  37. package/build/Executor.compiled.json +1 -1
  38. package/build/Executor.test.compiled.json +1 -1
  39. package/build/ExecutorFeeLib.compiled.json +1 -1
  40. package/build/ExecutorPermissions.test.compiled.json +1 -1
  41. package/build/LzClasses.test.compiled.json +1 -1
  42. package/build/LzUtil.test.compiled.json +1 -1
  43. package/build/MsgData.test.compiled.json +1 -1
  44. package/build/MsglibPacketCodec.test.compiled.json +1 -1
  45. package/build/PipelinedOutOfOrder.test.compiled.json +1 -1
  46. package/build/PriceFeedCache.compiled.json +1 -1
  47. package/build/PriceFeedCache.permissions.test.compiled.json +1 -1
  48. package/build/PriceFeedCache.test.compiled.json +1 -1
  49. package/build/Proxy.compiled.json +1 -1
  50. package/build/Proxy.permissions.test.compiled.json +1 -1
  51. package/build/Proxy.test.compiled.json +1 -1
  52. package/build/SmlConnection.compiled.json +1 -1
  53. package/build/SmlConnection.permissions.test.compiled.json +1 -1
  54. package/build/SmlConnection.test.compiled.json +1 -1
  55. package/build/SmlManager.compiled.json +1 -1
  56. package/build/SmlManager.permissions.test.compiled.json +1 -1
  57. package/build/SmlManager.test.compiled.json +1 -1
  58. package/build/Uln.compiled.json +1 -1
  59. package/build/Uln.test.compiled.json +1 -1
  60. package/build/UlnConnection.compiled.json +1 -1
  61. package/build/UlnConnection.test.compiled.json +1 -1
  62. package/build/UlnConnectionPermissions.test.compiled.json +1 -1
  63. package/build/UlnManagement.test.compiled.json +1 -1
  64. package/build/UlnManager.compiled.json +1 -1
  65. package/build/UlnManager.test.compiled.json +1 -1
  66. package/build/UlnManagerPermissions.test.compiled.json +1 -1
  67. package/build/UlnManagerUtil.test.compiled.json +1 -1
  68. package/build/UlnPermissions.test.compiled.json +1 -1
  69. package/build/UlnReceiveConfig.test.compiled.json +1 -1
  70. package/build/UlnSend.test.compiled.json +1 -1
  71. package/build/UlnSendConfig.test.compiled.json +1 -1
  72. package/build/UlnSendWithDvnFeeLib.test.compiled.json +1 -1
  73. package/build/UlnSendWithExecFeeLib.test.compiled.json +1 -1
  74. package/build/UlnSendWorkerFactory.test.compiled.json +1 -1
  75. package/build/UlnUtil.test.compiled.json +1 -1
  76. package/build/WorkerCore.test.compiled.json +1 -1
  77. package/build/badFeeLib1.test.compiled.json +1 -1
  78. package/build/badFeeLib10.test.compiled.json +1 -1
  79. package/build/badFeeLib11.test.compiled.json +1 -1
  80. package/build/badFeeLib12.test.compiled.json +1 -1
  81. package/build/badFeeLib2.test.compiled.json +1 -1
  82. package/build/badFeeLib3.test.compiled.json +1 -1
  83. package/build/badFeeLib4.test.compiled.json +1 -1
  84. package/build/badFeeLib5.test.compiled.json +1 -1
  85. package/build/badFeeLib6.test.compiled.json +1 -1
  86. package/build/badFeeLib7.test.compiled.json +1 -1
  87. package/build/badFeeLib8.test.compiled.json +1 -1
  88. package/build/badFeeLib9.test.compiled.json +1 -1
  89. package/package.json +5 -5
  90. package/src/classes/msgdata/LzReceiveStatus.fc +0 -1
  91. package/src/funC++/actions/call.fc +1 -0
  92. package/src/funC++/actions/deploy.fc +0 -1
  93. package/src/funC++/actions/destroy.fc +0 -1
  94. package/src/funC++/actions/dispatch.fc +0 -1
  95. package/src/funC++/actions/event.fc +0 -1
  96. package/src/funC++/actions/payment.fc +0 -1
  97. package/src/funC++/actions/sendJettons.fc +0 -1
  98. package/src/funC++/actions/utils.fc +0 -2
  99. package/src/funC++/baseInterface.fc +0 -2
  100. package/src/funC++/classlib.fc +0 -36
  101. package/src/funC++/contractMain.fc +2 -8
  102. package/src/funC++/dataStructures/DeterministicInsertionCircularQueue.fc +0 -1
  103. package/src/funC++/dataStructures/PipelinedOutOfOrder.fc +0 -1
  104. package/src/funC++/handlerCore.fc +2 -6
  105. package/src/funC++/stringlib.fc +0 -2
  106. package/src/funC++/testutils.fc +0 -1
  107. package/src/funC++/txnContext.fc +1 -1
  108. package/src/funC++/utils.fc +35 -0
  109. package/src/protocol/channel/callbackOpcodes.fc +10 -0
  110. package/src/protocol/channel/handler.fc +1032 -0
  111. package/src/protocol/channel/interface.fc +60 -0
  112. package/src/protocol/channel/main.fc +39 -0
  113. package/src/protocol/channel/storage.fc +55 -0
  114. package/src/protocol/controller/handler.fc +347 -0
  115. package/src/protocol/controller/interface.fc +25 -0
  116. package/src/protocol/controller/main.fc +29 -0
  117. package/src/protocol/controller/storage.fc +31 -0
  118. package/src/protocol/core/abstract/protocolHandler.fc +110 -0
  119. package/src/protocol/core/abstract/protocolMain.fc +30 -0
  120. package/src/protocol/core/baseStorage.fc +1 -2
  121. package/src/protocol/endpoint/handler.fc +426 -0
  122. package/src/protocol/endpoint/interface.fc +20 -0
  123. package/src/protocol/endpoint/main.fc +23 -0
  124. package/src/protocol/interfaces.fc +4 -0
  125. package/src/protocol/msglibs/BytesDecoder.fc +135 -0
  126. package/src/protocol/msglibs/BytesEncoder.fc +150 -0
  127. package/src/protocol/msglibs/interface.fc +16 -0
  128. package/src/protocol/msglibs/simpleMsglib/smlConnection/handler.fc +125 -0
  129. package/src/protocol/msglibs/simpleMsglib/smlConnection/interface.fc +3 -0
  130. package/src/protocol/msglibs/simpleMsglib/smlConnection/main.fc +19 -0
  131. package/src/protocol/msglibs/simpleMsglib/smlConnection/storage.fc +20 -0
  132. package/src/protocol/msglibs/simpleMsglib/smlManager/handler.fc +281 -0
  133. package/src/protocol/msglibs/simpleMsglib/smlManager/interface.fc +14 -0
  134. package/src/protocol/msglibs/simpleMsglib/smlManager/main.fc +24 -0
  135. package/src/protocol/msglibs/simpleMsglib/smlManager/storage.fc +38 -0
  136. package/src/protocol/msglibs/ultralightnode/callbackOpcodes.fc +1 -0
  137. package/src/protocol/msglibs/ultralightnode/feeLibInterface.fc +10 -0
  138. package/src/protocol/msglibs/ultralightnode/feeLibUtils.fc +51 -0
  139. package/src/protocol/msglibs/ultralightnode/msgdata/Attestation.fc +49 -0
  140. package/src/protocol/msglibs/ultralightnode/msgdata/DvnFeesPaidEvent.fc +26 -0
  141. package/src/protocol/msglibs/ultralightnode/msgdata/ExecutorFeePaidEvent.fc +23 -0
  142. package/src/protocol/msglibs/ultralightnode/msgdata/InitUln.fc +18 -0
  143. package/src/protocol/msglibs/ultralightnode/msgdata/InitUlnConnection.fc +62 -0
  144. package/src/protocol/msglibs/ultralightnode/msgdata/InitUlnManager.fc +18 -0
  145. package/src/protocol/msglibs/ultralightnode/msgdata/RentRefill.fc +18 -0
  146. package/src/protocol/msglibs/ultralightnode/msgdata/SetAdminWorkerAddresses.fc +18 -0
  147. package/src/protocol/msglibs/ultralightnode/msgdata/TreasuryFeeBps.fc +16 -0
  148. package/src/protocol/msglibs/ultralightnode/msgdata/UlnEvents.fc +26 -0
  149. package/src/protocol/msglibs/ultralightnode/msgdata/UlnReceiveConfig.fc +249 -0
  150. package/src/protocol/msglibs/ultralightnode/msgdata/UlnSend.fc +27 -0
  151. package/src/protocol/msglibs/ultralightnode/msgdata/UlnSendConfig.fc +170 -0
  152. package/src/protocol/msglibs/ultralightnode/msgdata/UlnVerification.fc +21 -0
  153. package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibBytecode.fc +16 -0
  154. package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibEvents.fc +58 -0
  155. package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibInfo.fc +56 -0
  156. package/src/protocol/msglibs/ultralightnode/msgdata/VerificationStatus.fc +18 -0
  157. package/src/protocol/msglibs/ultralightnode/uln/handler.fc +803 -0
  158. package/src/protocol/msglibs/ultralightnode/uln/interface.fc +63 -0
  159. package/src/protocol/msglibs/ultralightnode/uln/main.fc +37 -0
  160. package/src/protocol/msglibs/ultralightnode/uln/storage.fc +43 -0
  161. package/src/protocol/msglibs/ultralightnode/ulnConnection/handler.fc +600 -0
  162. package/src/protocol/msglibs/ultralightnode/ulnConnection/interface.fc +36 -0
  163. package/src/protocol/msglibs/ultralightnode/ulnConnection/main.fc +32 -0
  164. package/src/protocol/msglibs/ultralightnode/ulnConnection/storage.fc +49 -0
  165. package/src/protocol/msglibs/ultralightnode/ulnConnection/utils.fc +141 -0
  166. package/src/protocol/msglibs/ultralightnode/ulnManager/handler.fc +495 -0
  167. package/src/protocol/msglibs/ultralightnode/ulnManager/interface.fc +59 -0
  168. package/src/protocol/msglibs/ultralightnode/ulnManager/main.fc +40 -0
  169. package/src/protocol/msglibs/ultralightnode/ulnManager/storage.fc +44 -0
  170. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/common.fc +27 -0
  171. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/handler.fc +80 -0
  172. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/main.fc +4 -0
  173. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/storage.fc +26 -0
  174. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/handler.fc +123 -0
  175. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/main.fc +4 -0
  176. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/storage.fc +29 -0
  177. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/main.fc +3 -0
  178. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/priceFeedFeeLib/main.fc +1 -0
  179. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/priceFeedFeeLib/storage.fc +39 -0
  180. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/ulnSendWorkerV1.fc +363 -0
  181. package/src/workers/core/abstract/workerHandler.fc +150 -0
  182. package/src/workers/core/interface.fc +25 -0
  183. package/src/workers/core/workerCoreStorage.fc +44 -0
  184. package/src/workers/dvn/handler.fc +332 -0
  185. package/src/workers/dvn/interface.fc +25 -0
  186. package/src/workers/dvn/main.fc +36 -0
  187. package/src/workers/dvn/storage.fc +27 -0
  188. package/src/workers/executor/handler.fc +110 -0
  189. package/src/workers/executor/interface.fc +19 -0
  190. package/src/workers/executor/main.fc +26 -0
  191. package/src/workers/executor/storage.fc +19 -0
  192. package/src/workers/msgdata/ExecuteParams.fc +29 -0
  193. package/src/workers/msgdata/NativeDrop.fc +16 -0
  194. package/src/workers/msgdata/ProxyMessage.fc +20 -0
  195. package/src/workers/msgdata/SetDict.fc +20 -0
  196. package/src/workers/msgdata/SetQuorum.fc +20 -0
  197. package/src/workers/msgdata/SignedRequest.fc +18 -0
  198. package/src/workers/priceFeedCache/handler.fc +114 -0
  199. package/src/workers/priceFeedCache/interface.fc +4 -0
  200. package/src/workers/priceFeedCache/main.fc +25 -0
  201. package/src/workers/priceFeedCache/storage.fc +21 -0
  202. package/src/workers/proxy/handler.fc +81 -0
  203. package/src/workers/proxy/interface.fc +11 -0
  204. package/src/workers/proxy/main.fc +17 -0
  205. package/src/workers/proxy/storage.fc +21 -0
  206. package/tests/testMain.fc +0 -1
@@ -0,0 +1,332 @@
1
+ #include "../core/interface.fc";
2
+
3
+ #include "../../funC++/actions/call.fc";
4
+ #include "../../funC++/actions/event.fc";
5
+
6
+ #include "../../classes/msgdata/SetAddress.fc";
7
+
8
+ #include "../msgdata/SignedRequest.fc";
9
+ #include "../msgdata/SetQuorum.fc";
10
+ #include "../msgdata/SetDict.fc";
11
+ #include "../msgdata/ExecuteParams.fc";
12
+
13
+ #include "../core/abstract/workerHandler.fc";
14
+ #include "../../classes/msgdata/MdAddress.fc";
15
+ #include "../proxy/interface.fc";
16
+ #include "../../protocol/msglibs/ultralightnode/callbackOpcodes.fc";
17
+ #include "../../protocol/msglibs/ultralightnode/msgdata/UlnVerification.fc";
18
+ #include "../../protocol/msglibs/ultralightnode/uln/interface.fc";
19
+
20
+ #include "interface.fc";
21
+ #include "storage.fc";
22
+
23
+ ;;; Recovers public key from signature, identical to Bitcoin/Ethereum operations.
24
+ ;;; Takes 32-byte hash as uint256 hash; 65-byte signature as [uint1 v, uint256 r, uint256 s].
25
+ ;;; Returns (null, null, null, 0) on failure, (publickey, -1) on success. public key is returned as [uint8 h, uint256 x1, uint256 x2].
26
+ ;;; In the SEC (Standards for Efficient Cryptography) format, uncompressed public keys start with 0x04,
27
+ ;;; followed by the x and y coordinates of the point on the elliptic curve.
28
+ ;;; This prefix distinguishes uncompressed keys from compressed ones (which use 0x02 or 0x03).
29
+ (int, int, int, int) ecrecover(int hash, int v, int r, int s) asm "ECRECOVER NULLSWAPIFNOT NULLSWAPIFNOT2";
30
+
31
+ ;;; Decodes a 65-byte signature into uint8 v, uint256 r, uint256 s
32
+ (int, int, int) decodeSignature(cell signature) impure inline method_id {
33
+ slice signatureSlice = signature.begin_parse();
34
+
35
+ ;; Load r (first 32 bytes / 256 bits) = the x-coordinate of a point on the elliptic curve.
36
+ int r = signatureSlice~load_uint(256);
37
+
38
+ ;; Load s (next 32 bytes / 256 bits) = the y-coordinate of a point on the elliptic curve.
39
+ int s = signatureSlice~load_uint(256);
40
+
41
+ ;; Load v (last byte / 8 bits) = the recovery ID.
42
+ int v = signatureSlice~load_uint(8);
43
+
44
+ ;; Adjust the 'v' value from 27/28 to 0/1 for passing to ecrecover.
45
+ return (v >= 27 ? v - 27 : v, r, s);
46
+ }
47
+
48
+ ;;; Encodes [uint256 x1, uint256 x2] into a cell which represents the 64-byte public key
49
+ cell encodePublicKey(int x1, int x2) inline method_id {
50
+ return begin_cell()
51
+ .store_uint256(x1)
52
+ .store_uint256(x2)
53
+ .end_cell();
54
+ }
55
+
56
+ ;;; Verifies signatures on a dict256 of signatures
57
+ ;;; Signatures: Dict[publicKeyHash, signature]
58
+ tuple _verifySignatures(tuple actions, int hash, cell signatures, cell verifiers, int quorum) impure inline {
59
+ int indexedPublicKeyHash = -1;
60
+ int validSignatures = 0;
61
+ ;; iterate over the signatures dict
62
+ do {
63
+ (indexedPublicKeyHash, cell signature) = signatures.cl::dict256::getNext<cellRef>(indexedPublicKeyHash);
64
+ if (indexedPublicKeyHash != -1) {
65
+ (int v, int r, int s) = decodeSignature(signature);
66
+ ;; recover the public key from the signature
67
+ (_, int x1, int x2, int signatureValid) = ecrecover(hash, v, r, s);
68
+ if (signatureValid) {
69
+ ;; encode the public key and hash it
70
+ int recoveredPublicKeyHash = encodePublicKey(x1, x2).cl::hash();
71
+ ;; check if the recovered public key is in the verifiers dict
72
+ ;; and matches the signature in the dict
73
+ (_, int verifierExists) = verifiers.cl::dict256::get(recoveredPublicKeyHash);
74
+ if ((verifierExists) & (recoveredPublicKeyHash == indexedPublicKeyHash)) {
75
+ validSignatures += 1;
76
+ }
77
+ } else {
78
+ actions~pushAction<event>(
79
+ Dvn::event::INVALID_SIGNATURE,
80
+ begin_cell().store_uint256(indexedPublicKeyHash).end_cell()
81
+ );
82
+ }
83
+ }
84
+ } until (indexedPublicKeyHash == -1);
85
+
86
+ throw_if(Dvn::ERROR::notEnoughSignatures, validSignatures < quorum);
87
+
88
+ return actions;
89
+ }
90
+
91
+ ;;; ================PERMISSION FUNCTIONS=====================
92
+
93
+ () _checkPermissions(int op, cell $md) impure inline {
94
+ if (op == Dvn::OP::VERIFY) {
95
+ return assertAdmin();
96
+ } elseif (
97
+ (op == UltraLightNode::OP::ULN_CONNECTION_VERIFY_CALLBACK)
98
+ | (op == Dvn::OP::SET_ADMINS_BY_QUORUM)
99
+ ) {
100
+ ;; NOP, so no need to check permissions
101
+ return ();
102
+ } elseif (
103
+ (op == Dvn::OP::SET_VERIFIERS)
104
+ | (op == Dvn::OP::SET_QUORUM)
105
+ | (op == Worker::OP::SET_ADMINS)
106
+ | (op == Worker::OP::SET_PROXY)
107
+ | (op == Worker::OP::CLAIM_TON)
108
+ | (op == Worker::OP::CALL_VIA_PROXY)
109
+ ) {
110
+ return assertAdmin();
111
+ } elseif (op == Proxy::OP::HANDLE_CALLBACK) {
112
+ return ();
113
+ }
114
+ throw(BaseInterface::ERROR::invalidOpcode);
115
+ }
116
+
117
+ ;;; ==========================HANDLERS=====================================
118
+
119
+ tuple setVerifiers(cell $signedRequest) impure {
120
+ (cell $storage, tuple actions) = preamble();
121
+
122
+ cell $setDict = $signedRequest.cl::get<objRef>(md::SignedRequest::request);
123
+
124
+ int incomingNonce = $setDict.cl::get<uint64>(md::SetDict::nonce);
125
+
126
+ throw_if(
127
+ Dvn::ERROR::invalidsetVerifiersNonce,
128
+ incomingNonce != $storage.cl::get<uint64>(Dvn::setVerifiersNonce)
129
+ );
130
+
131
+ int opcode = $setDict.cl::get<uint64>(md::SetDict::opcode);
132
+ throw_if(
133
+ Dvn::ERROR::invalidSignedOpcode,
134
+ opcode != Dvn::OP::SET_VERIFIERS
135
+ );
136
+
137
+ actions = _verifySignatures(
138
+ actions,
139
+ $setDict.cl::hash(),
140
+ $signedRequest.cl::get<dict256>(md::SignedRequest::signatures),
141
+ $storage.cl::get<dict256>(Dvn::verifiers),
142
+ $storage.cl::get<uint64>(Dvn::quorum)
143
+ );
144
+
145
+ setContractStorage(
146
+ $storage
147
+ .cl::set(
148
+ Dvn::verifiers,
149
+ $setDict.cl::get<dict256>(md::SetDict::dict)
150
+ )
151
+ .cl::set(Dvn::setVerifiersNonce, incomingNonce + 1)
152
+ );
153
+
154
+ actions~pushAction<event>(Dvn::event::SET_VERIFIERS, $setDict);
155
+
156
+ return actions;
157
+ }
158
+
159
+ tuple setQuorum(cell $signedRequest) impure {
160
+ (cell $storage, tuple actions) = preamble();
161
+
162
+ cell $setQuorum = $signedRequest.cl::get<objRef>(md::SignedRequest::request);
163
+
164
+ int incomingNonce = $setQuorum.cl::get<uint64>(md::SetQuorum::nonce);
165
+
166
+ throw_if(
167
+ Dvn::ERROR::invalidsetQuorumNonce,
168
+ incomingNonce != $storage.cl::get<uint64>(Dvn::setQuorumNonce)
169
+ );
170
+
171
+ int opcode = $setQuorum.cl::get<uint64>(md::SetQuorum::opcode);
172
+ throw_if(
173
+ Dvn::ERROR::invalidSignedOpcode,
174
+ opcode != Dvn::OP::SET_QUORUM
175
+ );
176
+
177
+ int newQuorum = $setQuorum.cl::get<uint64>(md::SetQuorum::quorum);
178
+
179
+ throw_if(
180
+ Dvn::ERROR::invalidQuorum,
181
+ newQuorum < 1
182
+ );
183
+
184
+ actions = _verifySignatures(
185
+ actions,
186
+ $setQuorum.cl::hash(),
187
+ $signedRequest.cl::get<dict256>(md::SignedRequest::signatures),
188
+ $storage.cl::get<dict256>(Dvn::verifiers),
189
+ $storage.cl::get<uint64>(Dvn::quorum)
190
+ );
191
+
192
+ setContractStorage(
193
+ $storage
194
+ .cl::set(Dvn::quorum, newQuorum)
195
+ .cl::set(Dvn::setQuorumNonce, incomingNonce + 1)
196
+ );
197
+
198
+ actions~pushAction<event>(Dvn::event::SET_QUORUM, $setQuorum);
199
+
200
+ return actions;
201
+ }
202
+
203
+ tuple setAdminsByQuorum(cell $signedRequest) impure {
204
+ (cell $storage, tuple actions) = preamble();
205
+
206
+ cell $setDict = $signedRequest.cl::get<objRef>(md::SignedRequest::request);
207
+
208
+ int incomingNonce = $setDict.cl::get<uint64>(md::SetDict::nonce);
209
+
210
+ throw_if(
211
+ Dvn::ERROR::invalidsetAdminsByQuorumNonce,
212
+ incomingNonce != $storage.cl::get<uint64>(Dvn::setAdminsByQuorumNonce)
213
+ );
214
+
215
+ int opcode = $setDict.cl::get<uint64>(md::SetDict::opcode);
216
+ throw_if(
217
+ Dvn::ERROR::invalidSignedOpcode,
218
+ opcode != Dvn::OP::SET_ADMINS_BY_QUORUM
219
+ );
220
+
221
+ actions = _verifySignatures(
222
+ actions,
223
+ $setDict.cl::hash(),
224
+ $signedRequest.cl::get<dict256>(md::SignedRequest::signatures),
225
+ $storage.cl::get<dict256>(Dvn::verifiers),
226
+ $storage.cl::get<uint64>(Dvn::quorum)
227
+ );
228
+
229
+ actions~pushAction<event>(Dvn::event::SET_ADMINS_BY_QUORUM, $setDict);
230
+
231
+ setContractStorage(
232
+ $storage
233
+ .setCoreStorage(
234
+ getCoreStorage().cl::set(
235
+ WorkerCoreStorage::admins,
236
+ $setDict.cl::get<dict256>(md::SetDict::dict)
237
+ )
238
+ )
239
+ .cl::set(Dvn::setAdminsByQuorumNonce, incomingNonce + 1)
240
+ );
241
+
242
+ return actions;
243
+ }
244
+
245
+ ;; Calldata = mdAddress(verification, ulnConnectionAddress)
246
+ tuple verify(cell $signedRequest) impure inline {
247
+ (cell $storage, tuple actions) = preamble();
248
+
249
+ cell $executeParams = $signedRequest.cl::get<objRef>(md::SignedRequest::request);
250
+
251
+ throw_if(
252
+ Dvn::ERROR::expired,
253
+ ;; now() counts as expired, per the EVM spec
254
+ $executeParams.cl::get<uint64>(md::ExecuteParams::expiration) <= now()
255
+ );
256
+
257
+ int opcode = $executeParams.cl::get<uint32>(md::ExecuteParams::opcode);
258
+ throw_if(
259
+ Dvn::ERROR::invalidSignedOpcode,
260
+ opcode != Uln::OP::ULN_VERIFY
261
+ );
262
+
263
+ actions = _verifySignatures(
264
+ actions,
265
+ $executeParams.cl::hash(),
266
+ $signedRequest.cl::get<dict256>(md::SignedRequest::signatures),
267
+ $storage.cl::get<dict256>(Dvn::verifiers),
268
+ $storage.cl::get<uint64>(Dvn::quorum)
269
+ );
270
+
271
+ return _callContract(
272
+ actions,
273
+ md::ExecuteParams::New(
274
+ getProxyAddress(),
275
+ $executeParams,
276
+ 0,
277
+ Proxy::OP::CALL_CONTRACT
278
+ )
279
+ );
280
+ }
281
+
282
+ tuple verifyCallback(cell $verifyStatus) impure inline {
283
+ (cell $storage, tuple actions) = preamble();
284
+ return actions;
285
+ }
286
+
287
+ tuple setProxyAdmins(cell $signedRequest) impure inline {
288
+ (cell $storage, tuple actions) = preamble();
289
+
290
+ cell $executeParams = $signedRequest.cl::get<objRef>(md::SignedRequest::request);
291
+
292
+ throw_if(
293
+ Dvn::ERROR::expired,
294
+ ;; now() counts as expired, per the EVM spec
295
+ $executeParams.cl::get<uint64>(md::ExecuteParams::expiration) <= now()
296
+ );
297
+
298
+ int opcode = $executeParams.cl::get<uint32>(md::ExecuteParams::opcode);
299
+ throw_if(
300
+ Dvn::ERROR::invalidSignedOpcode,
301
+ opcode != Worker::OP::SET_ADMINS
302
+ );
303
+
304
+ actions = _verifySignatures(
305
+ actions,
306
+ $executeParams.cl::hash(),
307
+ $signedRequest.cl::get<dict256>(md::SignedRequest::signatures),
308
+ $storage.cl::get<dict256>(Dvn::verifiers),
309
+ $storage.cl::get<uint64>(Dvn::quorum)
310
+ );
311
+
312
+ return _callContract(actions, $executeParams);
313
+ }
314
+
315
+ tuple setAdmins(cell $addressList) impure inline {
316
+ return _setAdmins(emptyActions(), $addressList);
317
+ }
318
+
319
+ tuple claimTon(cell $coinsAmount) impure inline {
320
+ return _claimTon(emptyActions(), $coinsAmount);
321
+ }
322
+
323
+ tuple setProxy(cell $setAddress) impure inline {
324
+ return _setProxyAddress(
325
+ emptyActions(),
326
+ $setAddress.cl::get<address>(md::SetAddress::address)
327
+ );
328
+ }
329
+
330
+ tuple callViaProxy(cell $executeParams) impure inline {
331
+ return _callViaProxy(emptyActions(), $executeParams);
332
+ }
@@ -0,0 +1,25 @@
1
+ ;;; ==========================OPCODES=====================================
2
+
3
+ const int Dvn::OP::SET_VERIFIERS = "Dvn::OP::SET_VERIFIERS"c;
4
+ const int Dvn::OP::SET_QUORUM = "Dvn::OP::SET_QUORUM"c;
5
+ const int Dvn::OP::VERIFY = "Dvn::OP::VERIFY"c;
6
+ const int Dvn::OP::SET_ADMINS_BY_QUORUM = "Dvn::OP::SET_ADMINS_BY_QUORUM"c;
7
+ const int Dvn::OP::SET_PROXY_ADMINS = "Dvn::OP::SET_PROXY_ADMINS"c;
8
+
9
+ ;;; ==========================ERRORS=====================================
10
+ const int Dvn::ERROR::expired = 1983;
11
+ const int Dvn::ERROR::quorumNotMet = 1982;
12
+ const int Dvn::ERROR::notEnoughSignatures = 1981;
13
+ const int Dvn::ERROR::invalidsetQuorumNonce = 1980;
14
+ const int Dvn::ERROR::invalidQuorum = 1979;
15
+ const int Dvn::ERROR::invalidsetAdminsByQuorumNonce = 1978;
16
+
17
+ const int Dvn::ERROR::invalidsetVerifiersNonce = 1977;
18
+ const int Dvn::ERROR::invalidSignedOpcode = 1976;
19
+
20
+ ;;; ==========================EVENTS=====================================
21
+ const int Dvn::event::INVALID_SIGNATURE = "Dvn::event::INVALID_SIGNATURE"u;
22
+ const int Dvn::event::SET_VERIFIERS = "Dvn::event::SET_VERIFIERS"u;
23
+ const int Dvn::event::SET_QUORUM = "Dvn::event::SET_QUORUM"u;
24
+ const int Dvn::event::SET_ADMINS_BY_QUORUM = "Dvn::event::SET_ADMINS_BY_QUORUM"u;
25
+ const int Dvn::event::VERIFY = "Dvn::event::VERIFY"u;
@@ -0,0 +1,36 @@
1
+ #include "../proxy/interface.fc";
2
+
3
+ #include "../../protocol/msglibs/ultralightnode/callbackOpcodes.fc";
4
+
5
+ #include "../../protocol/core/abstract/protocolMain.fc";
6
+
7
+ #include "handler.fc";
8
+ #include "interface.fc";
9
+
10
+ tuple _executeOpcode(int op, cell $md) impure inline {
11
+ if (op == Dvn::OP::VERIFY) {
12
+ return verify($md);
13
+ } elseif (op == UltraLightNode::OP::ULN_CONNECTION_VERIFY_CALLBACK) {
14
+ return verifyCallback($md);
15
+ } elseif (op == Dvn::OP::SET_VERIFIERS) {
16
+ return setVerifiers($md);
17
+ } elseif (op == Dvn::OP::SET_QUORUM) {
18
+ return setQuorum($md);
19
+ } elseif (op == Dvn::OP::SET_ADMINS_BY_QUORUM) {
20
+ return setAdminsByQuorum($md);
21
+ } elseif (op == Worker::OP::SET_ADMINS) {
22
+ return setAdmins($md);
23
+ } elseif (op == Worker::OP::SET_PROXY) {
24
+ return setProxy($md);
25
+ } elseif (op == Worker::OP::CLAIM_TON) {
26
+ return claimTon($md);
27
+ } elseif (op == Dvn::OP::SET_PROXY_ADMINS) {
28
+ return setProxyAdmins($md);
29
+ } elseif (op == Worker::OP::CALL_VIA_PROXY) {
30
+ return callViaProxy($md);
31
+ } elseif (op == Proxy::OP::HANDLE_CALLBACK) {
32
+ return emptyActions();
33
+ }
34
+ throw(BaseInterface::ERROR::invalidOpcode);
35
+ return empty_tuple();
36
+ }
@@ -0,0 +1,27 @@
1
+ #include "../core/workerCoreStorage.fc";
2
+
3
+ ;; required object name
4
+ const int Dvn::NAME = "dvn"u;
5
+
6
+ ;; field names
7
+ const int Dvn::workerCoreStorage = 0; ;; = WORKER_CORE_STORAGE_IDX;
8
+ const int Dvn::quorum = 1;
9
+ const int Dvn::verifiers = 2;
10
+ const int Dvn::setQuorumNonce = 3;
11
+ const int Dvn::setVerifiersNonce = 4;
12
+ const int Dvn::setAdminsByQuorumNonce = 5;
13
+
14
+ ;; @owner manager
15
+ cell Dvn::New(cell admins, int version, int quorum, cell verifiers) method_id {
16
+ return cl::declare(
17
+ Dvn::NAME,
18
+ unsafeTuple([
19
+ [cl::t::objRef, WorkerCoreStorage::New(admins, NULLADDRESS, version)], ;; Dvn::workerCoreStorage
20
+ [cl::t::uint64, quorum], ;; Dvn::quorum
21
+ [cl::t::dict256, verifiers], ;; Dvn::verifiers
22
+ [cl::t::uint64, 1], ;; Dvn::setQuorumNonce
23
+ [cl::t::uint64, 1], ;; Dvn::setVerifiersNonce
24
+ [cl::t::uint64, 1] ;; Dvn::setAdminsByQuorumNonce
25
+ ])
26
+ );
27
+ }
@@ -0,0 +1,110 @@
1
+ #include "../core/abstract/workerHandler.fc";
2
+ #include "../core/interface.fc";
3
+
4
+ #include "../../classes/msgdata/MdAddress.fc";
5
+ #include "../../classes/msgdata/MdObj.fc";
6
+ #include "../../classes/msgdata/MsglibSendCallback.fc";
7
+ #include "../../classes/msgdata/Nonce.fc";
8
+
9
+ #include "../../protocol/msglibs/interface.fc";
10
+ #include "../../protocol/msglibs/ultralightnode/uln/interface.fc";
11
+ #include "../../protocol/channel/interface.fc";
12
+ #include "../proxy/interface.fc";
13
+
14
+ #include "../msgdata/NativeDrop.fc";
15
+
16
+
17
+ #include "interface.fc";
18
+ #include "storage.fc";
19
+
20
+ ;;; ================PERMISSION FUNCTIONS=====================
21
+
22
+ () _checkPermissions(int op, cell $md) impure inline {
23
+ if (op == Proxy::OP::HANDLE_CALLBACK) {
24
+ return ();
25
+ }
26
+ return assertAdmin();
27
+ }
28
+
29
+ ;;; ==========================HANDLERS=====================================
30
+
31
+ tuple _executorNativeDrop(tuple actions, cell $mdNativeDrop) impure inline {
32
+ cell $storage = getContractStorage();
33
+
34
+ int totalAmount = 0;
35
+ tuple payees = deserializePayees($mdNativeDrop.cl::get<cellRef>(md::NativeDrop::payees));
36
+
37
+ repeat (payees.tlen()) {
38
+ [int payeeAddress, int nativeAmount] = payees~tpopPayee();
39
+ actions~pushAction<payment>(
40
+ payeeAddress,
41
+ nativeAmount,
42
+ 0
43
+ );
44
+ totalAmount += nativeAmount;
45
+ }
46
+
47
+ throw_if(
48
+ Executor::ERROR::nativeDropTotalCapExceeded,
49
+ totalAmount > $storage.cl::get<coins>(Executor::nativeDropTotalCap)
50
+ );
51
+
52
+ return actions;
53
+ }
54
+
55
+ tuple _executorLzReceivePrepare(tuple actions, cell $executeParams) impure inline {
56
+ int opcode = $executeParams.cl::get<uint32>(md::ExecuteParams::opcode);
57
+ throw_unless(
58
+ Worker::ERROR::DISALLOWED_INNER_OPCODE,
59
+ opcode == Channel::OP::LZ_RECEIVE_PREPARE
60
+ );
61
+
62
+ return _callContract(actions, $executeParams);
63
+ }
64
+
65
+ tuple executorNativeDrop(cell $mdNativeDrop) impure inline {
66
+ return _executorNativeDrop(emptyActions(), $mdNativeDrop);
67
+ }
68
+
69
+ tuple executorLzReceivePrepare(cell $executeParams) impure inline {
70
+ return _executorLzReceivePrepare(emptyActions(), $executeParams);
71
+ }
72
+
73
+ ;; md: $mdNativeDrop
74
+ ;; obj: $executeParams for lzReceivePrepare
75
+ tuple executorNativeDropAndLzReceivePrepare(cell $mdObj) impure inline {
76
+ return emptyActions()
77
+ ._executorNativeDrop($mdObj.cl::get<objRef>(md::MdObj::obj))
78
+ ._executorLzReceivePrepare($mdObj.cl::get<objRef>(md::MdObj::md));
79
+ }
80
+
81
+ tuple executorLzReceiveAlert(cell $executeParams) impure inline {
82
+ tuple actions = emptyActions();
83
+
84
+ int opcode = $executeParams.cl::get<uint32>(md::ExecuteParams::opcode);
85
+ throw_unless(
86
+ Worker::ERROR::DISALLOWED_INNER_OPCODE,
87
+ opcode == Channel::OP::EMIT_LZ_RECEIVE_ALERT
88
+ );
89
+
90
+ return _callContract(actions, $executeParams);
91
+ }
92
+
93
+ tuple setAdmins(cell $addressList) impure inline {
94
+ return _setAdmins(emptyActions(), $addressList);
95
+ }
96
+
97
+ tuple claimTon(cell $coinsAmount) impure inline {
98
+ return _claimTon(emptyActions(), $coinsAmount);
99
+ }
100
+
101
+ tuple setProxy(cell $setAddress) impure inline {
102
+ return _setProxyAddress(
103
+ emptyActions(),
104
+ $setAddress.cl::get<address>(md::SetAddress::address)
105
+ );
106
+ }
107
+
108
+ tuple callViaProxy(cell $executeParams) impure inline {
109
+ return _callViaProxy(emptyActions(), $executeParams);
110
+ }
@@ -0,0 +1,19 @@
1
+ ;; --------- Opcodes ---------
2
+
3
+
4
+ ;; Native drop a batch of native tokens
5
+ const int Executor::OP::NATIVE_DROP = "Executor::OP::NATIVE_DROP"c;
6
+
7
+ const int Executor::OP::LZ_RECEIVE_PREPARE = "Executor::OP::LZ_RECEIVE_PREPARE"c;
8
+
9
+
10
+ ;; Native drop a batch of native tokens and execute a packet
11
+ const int Executor::OP::NATIVE_DROP_AND_LZ_RECEIVE_PREPARE = "Executor::OP::NATIVE_DROP_AND_LZ_RECEIVE_PREPARE"c;
12
+
13
+ const int Executor::OP::LZ_RECEIVE_ALERT = "Executor::OP::LZ_RECEIVE_ALERT"c;
14
+
15
+ ;; --------- Events ---------
16
+ const int Executor::event::LZ_RECEIVE_ALERT = "Executor::event::LZ_RCV_ALERT"u;
17
+
18
+ ;; --------- Errors ---------
19
+ const int Executor::ERROR::nativeDropTotalCapExceeded = 1951;
@@ -0,0 +1,26 @@
1
+ #include "../../protocol/core/abstract/protocolMain.fc";
2
+
3
+ #include "handler.fc";
4
+ #include "interface.fc";
5
+
6
+ tuple _executeOpcode(int op, cell $md) impure inline {
7
+ if (op == Executor::OP::NATIVE_DROP) {
8
+ return executorNativeDrop($md);
9
+ } elseif (op == Executor::OP::NATIVE_DROP_AND_LZ_RECEIVE_PREPARE) {
10
+ return executorNativeDropAndLzReceivePrepare($md);
11
+ } elseif (op == Executor::OP::LZ_RECEIVE_ALERT) {
12
+ return executorLzReceiveAlert($md);
13
+ } elseif (op == Worker::OP::SET_ADMINS) {
14
+ return setAdmins($md);
15
+ } elseif (op == Worker::OP::CLAIM_TON) {
16
+ return claimTon($md);
17
+ } elseif (op == Worker::OP::CALL_VIA_PROXY) {
18
+ return callViaProxy($md);
19
+ } elseif (op == Worker::OP::SET_PROXY) {
20
+ return setProxy($md);
21
+ } elseif (op == Proxy::OP::HANDLE_CALLBACK) {
22
+ return emptyActions();
23
+ }
24
+ throw(BaseInterface::ERROR::invalidOpcode);
25
+ return empty_tuple();
26
+ }
@@ -0,0 +1,19 @@
1
+ #include "../core/workerCoreStorage.fc";
2
+
3
+ ;; required object name
4
+ const int Executor::NAME = "executor"u;
5
+
6
+ ;; field names
7
+ const int Executor::workerCoreStorage = 0; ;; = WORKER_CORE_STORAGE_IDX
8
+ const int Executor::nativeDropTotalCap = 1;
9
+
10
+ ;; @owner manager
11
+ cell Executor::New(cell admins, int version, int nativeDropTotalCap) method_id {
12
+ return cl::declare(
13
+ Executor::NAME,
14
+ unsafeTuple([
15
+ [cl::t::objRef, WorkerCoreStorage::New(admins, NULLADDRESS, version)], ;; Executor::workerCoreStorage
16
+ [cl::t::coins, nativeDropTotalCap] ;; Executor::nativeDropTotalCap
17
+ ])
18
+ );
19
+ }
@@ -0,0 +1,29 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int md::ExecuteParams::NAME = "execParams"u;
5
+
6
+ ;; struct ExecuteParam {
7
+ ;; uint32 vid; // no vid?
8
+ ;; address target;
9
+ ;; bytes callData;
10
+ ;; uint256 expiration;
11
+ ;; }
12
+
13
+ ;; field names
14
+ const int md::ExecuteParams::target = 0;
15
+ const int md::ExecuteParams::callData = 1;
16
+ const int md::ExecuteParams::expiration = 2;
17
+ const int md::ExecuteParams::opcode = 3;
18
+
19
+ cell md::ExecuteParams::New(int target, cell callData, int expiration, int opcode) method_id {
20
+ return cl::declare(
21
+ md::ExecuteParams::NAME,
22
+ unsafeTuple([
23
+ [cl::t::address, target], ;; md::ExecuteParams::target
24
+ [cl::t::objRef, callData], ;; md::ExecuteParams::callData
25
+ [cl::t::uint64, expiration], ;; md::ExecuteParams::expiration
26
+ [cl::t::uint32, opcode] ;; md::ExecuteParams::opcode
27
+ ])
28
+ );
29
+ }
@@ -0,0 +1,16 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int md::NativeDrop::NAME = "NativeDrop"u;
5
+
6
+ ;; field names
7
+ const int md::NativeDrop::payees = 0;
8
+
9
+ cell md::NativeDrop::New(cell payees) inline method_id {
10
+ return cl::declare(
11
+ md::NativeDrop::NAME,
12
+ unsafeTuple([
13
+ [cl::t::cellRef, payees] ;; md::NativeDrop::payees
14
+ ])
15
+ );
16
+ }
@@ -0,0 +1,20 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int md::ProxyMessage::NAME = "ProxyMsg"u;
5
+
6
+ ;; field names
7
+ const int md::ProxyMessage::destination = 0;
8
+ const int md::ProxyMessage::opcode = 1;
9
+ const int md::ProxyMessage::data = 2;
10
+
11
+ cell md::ProxyMessage::New(int destination, int opcode, cell data) method_id {
12
+ return cl::declare(
13
+ md::ProxyMessage::NAME,
14
+ unsafeTuple([
15
+ [cl::t::address, destination], ;; md::ProxyMessage::destination
16
+ [cl::t::uint32, opcode], ;; md::ProxyMessage::opcode
17
+ [cl::t::dict256, data] ;; md::ProxyMessage::data
18
+ ])
19
+ );
20
+ }
@@ -0,0 +1,20 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int md::SetDict::NAME = "setDct"u;
5
+
6
+ ;; field names
7
+ const int md::SetDict::nonce = 0;
8
+ const int md::SetDict::opcode = 1;
9
+ const int md::SetDict::dict = 2;
10
+
11
+ cell md::SetDict::New(int nonce, int opcode, cell _dict) inline method_id {
12
+ return cl::declare(
13
+ md::SetDict::NAME,
14
+ unsafeTuple([
15
+ [cl::t::uint64, nonce], ;; md::SetDict::nonce
16
+ [cl::t::uint64, opcode], ;; md::SetDict::opcode
17
+ [cl::t::dict256, _dict] ;; md::SetDict::dict
18
+ ])
19
+ );
20
+ }