@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,600 @@
1
+ #include "../../../core/abstract/protocolHandler.fc";
2
+
3
+ #include "../callbackOpcodes.fc";
4
+
5
+ #include "../msgdata/InitUlnConnection.fc";
6
+ #include "../msgdata/UlnSend.fc";
7
+ #include "../msgdata/UlnReceiveConfig.fc";
8
+ #include "../msgdata/UlnSendConfig.fc";
9
+ #include "../msgdata/UlnVerification.fc";
10
+ #include "../msgdata/VerificationStatus.fc";
11
+ #include "../msgdata/Attestation.fc";
12
+
13
+ #include "../uln/interface.fc";
14
+ #include "../../interface.fc";
15
+
16
+ #include "../../../interfaces.fc";
17
+
18
+ #include "../../../../protocol/endpoint/interface.fc";
19
+
20
+ #include "../../../../classes/lz/Packet.fc";
21
+ #include "../../../../classes/msgdata/ChannelNonceInfo.fc";
22
+ #include "../../../../classes/msgdata/ExtendedMd.fc";
23
+ #include "../../../../classes/msgdata/MdAddress.fc";
24
+ #include "../../../../classes/msgdata/MdObj.fc";
25
+ #include "../../../../classes/msgdata/Nonce.fc";
26
+ #include "../../../../classes/msgdata/SetAddress.fc";
27
+
28
+ #include "../../../../funC++/dataStructures/AddressList.fc";
29
+ #include "../../../../funC++/dataStructures/PipelinedOutOfOrder.fc";
30
+
31
+ #include "interface.fc";
32
+ #include "storage.fc";
33
+ #include "utils.fc";
34
+
35
+ ;;; ================INTERFACE FUNCTIONS=====================
36
+ (cell, tuple) _initialize(cell $initUlnConnection) impure inline {
37
+ (cell $storage, tuple actions) = preamble();
38
+
39
+ ;; sanitized by the ULN Manager
40
+ cell $ulnSendConfigOApp = $initUlnConnection.cl::get<objRef>(
41
+ md::InitUlnConnection::ulnSendConfigOApp
42
+ );
43
+
44
+ ;; sanitized by the ULN Manager
45
+ cell $UlnReceiveConfigOApp = $initUlnConnection.cl::get<objRef>(
46
+ md::InitUlnConnection::ulnReceiveConfigOApp
47
+ );
48
+
49
+ int endpointAddress = $initUlnConnection.cl::get<address>(md::InitUlnConnection::endpointAddress);
50
+ int channelAddress = $initUlnConnection.cl::get<address>(md::InitUlnConnection::channelAddress);
51
+
52
+ return (
53
+ $storage
54
+ .cl::set(UlnConnection::UlnSendConfigOApp, $ulnSendConfigOApp)
55
+ .cl::set(UlnConnection::UlnReceiveConfigOApp, $UlnReceiveConfigOApp)
56
+ .cl::set(UlnConnection::endpointAddress, endpointAddress)
57
+ .cl::set(UlnConnection::channelAddress, channelAddress)
58
+ .cl::set(UlnConnection::commitPOOO, POOO::New()),
59
+ actions
60
+ );
61
+ }
62
+
63
+ int _getEventSink() impure inline {
64
+ return getOwner();
65
+ }
66
+
67
+ () assertChannel(cell $md) impure inline {
68
+ throw_unless(
69
+ UlnConnection::ERROR::onlyChannel,
70
+ getCaller() == getContractStorage().cl::get<address>(UlnConnection::channelAddress)
71
+ );
72
+ }
73
+
74
+ () assertUln() impure inline {
75
+ throw_unless(
76
+ UlnConnection::ERROR::onlyUln,
77
+ getCaller() == getContractStorage().cl::get<address>(UlnConnection::ulnAddress)
78
+ );
79
+ }
80
+
81
+ int _committable(
82
+ int nonce,
83
+ int packetHash,
84
+ cell requiredDVNs,
85
+ cell optionalDVNs,
86
+ int optionalDVNThreshold,
87
+ int requiredConfirmations
88
+ ) impure inline {
89
+ cell $storage = getContractStorage();
90
+
91
+ slice requiredDVNsSlice = requiredDVNs.begin_parse();
92
+ ;; iterate through each of the required DVNs
93
+
94
+ int dvnAddress = requiredDVNsSlice~AddressList::next();
95
+
96
+ while (dvnAddress > NULLADDRESS) {
97
+ cell $attestation = UlnConnection::utils::getHashLookup(
98
+ $storage,
99
+ nonce,
100
+ dvnAddress
101
+ );
102
+ if ($attestation.cl::isNull()) {
103
+ return false;
104
+ }
105
+ if (
106
+ ($attestation.cl::get<uint64>(lz::Attestation::confirmations) < requiredConfirmations)
107
+ | ($attestation.cl::get<uint256>(lz::Attestation::hash) != packetHash)
108
+ ) {
109
+ return false;
110
+ }
111
+ dvnAddress = requiredDVNsSlice~AddressList::next();
112
+ }
113
+
114
+ int optionalDVNAttestations = 0;
115
+
116
+ slice optionalDVNsSlice = optionalDVNs.begin_parse();
117
+ dvnAddress = optionalDVNsSlice~AddressList::next();
118
+ while ((dvnAddress > NULLADDRESS) & (optionalDVNAttestations < optionalDVNThreshold)) {
119
+ cell $attestation = UlnConnection::utils::getHashLookup(
120
+ $storage,
121
+ nonce,
122
+ dvnAddress
123
+ );
124
+
125
+ ;; Nested if, else case is simply to do nothing
126
+ ifnot ($attestation.cl::isNull()) {
127
+ if (
128
+ ($attestation.cl::get<uint64>(lz::Attestation::confirmations) >= requiredConfirmations)
129
+ & ($attestation.cl::get<uint256>(lz::Attestation::hash) == packetHash)
130
+ ) {
131
+ optionalDVNAttestations += 1;
132
+ }
133
+ }
134
+ dvnAddress = optionalDVNsSlice~AddressList::next();
135
+ }
136
+
137
+ if (
138
+ (optionalDVNAttestations < optionalDVNThreshold)
139
+ ) {
140
+ ;; If not enough dvn attestations, return false
141
+ return false;
142
+ }
143
+ return true;
144
+ }
145
+
146
+ int committableView(int nonce, cell $packet, cell $defaultUlnReceiveConfig) impure method_id {
147
+ int firstUnexecutedNonce = getContractStorage()
148
+ .cl::get<uint64>(UlnConnection::firstUnexecutedNonce);
149
+ if (nonce < firstUnexecutedNonce) {
150
+ return UlnConnection::verificationStatus::EXECUTED;
151
+ }
152
+ cell $commitPOOO = getContractStorage().cl::get<objRef>(UlnConnection::commitPOOO);
153
+ int firstUncommittedNonce = $commitPOOO.cl::get<uint64>(POOO::nextEmpty);
154
+
155
+ if (nonce < firstUncommittedNonce) {
156
+ return UlnConnection::verificationStatus::COMMITTED;
157
+ } elseif (nonce > $commitPOOO.POOO::maxSettableBit()) {
158
+ return UlnConnection::verificationStatus::VERIFYING;
159
+ } elseif ($commitPOOO.POOO::isBitSet(nonce)) {
160
+ return UlnConnection::verificationStatus::COMMITTED;
161
+ }
162
+
163
+ (
164
+ cell requiredDVNs,
165
+ cell optionalDVNs,
166
+ int optionalDVNThreshold,
167
+ int requiredConfirmations,
168
+ _,
169
+ int isValid
170
+ ) = UlnReceiveConfig::utils::getCommitConfig(
171
+ getContractStorage().cl::get<objRef>(UlnConnection::UlnReceiveConfigOApp),
172
+ $defaultUlnReceiveConfig
173
+ );
174
+
175
+ ifnot (isValid) {
176
+ return UlnConnection::verificationStatus::CONFIGURATION_ERROR;
177
+ }
178
+
179
+ if (_committable(
180
+ nonce,
181
+ $packet.cl::hash(),
182
+ requiredDVNs,
183
+ optionalDVNs,
184
+ optionalDVNThreshold,
185
+ requiredConfirmations
186
+ )) {
187
+ return UlnConnection::verificationStatus::COMMITTABLE;
188
+ }
189
+ return UlnConnection::verificationStatus::VERIFYING;
190
+ }
191
+
192
+ int verifiedView(int dvnAddress, int nonce, int packetHash, int requiredConfirmations) impure method_id {
193
+ cell $attestation = UlnConnection::utils::getHashLookup(
194
+ getContractStorage(),
195
+ nonce,
196
+ dvnAddress
197
+ );
198
+
199
+ if ($attestation.cl::isNull()) {
200
+ return false;
201
+ }
202
+
203
+ int confirmations = $attestation.cl::get<uint64>(lz::Attestation::confirmations);
204
+ int storedHash = $attestation.cl::get<uint256>(lz::Attestation::hash);
205
+ return (confirmations >= requiredConfirmations) & (storedHash == packetHash);
206
+ }
207
+
208
+ int _dvnIsRequiredOrOptional(slice requiredDVNsSlice, slice optionalDVNsSlice, int dvnAddress) impure inline {
209
+ if (AddressList::includes(dvnAddress, requiredDVNsSlice)) {
210
+ ;; Most configurations will only use required DVNs, so short-circuit return if it is required
211
+ return true;
212
+ }
213
+
214
+ return AddressList::includes(dvnAddress, optionalDVNsSlice);
215
+ }
216
+
217
+ int _isDvnConfigured(int dvnAddress, cell $defaultUlnReceiveConfigOApp) impure inline {
218
+ cell $customUlnReceiveConfigOApp = getContractStorage()
219
+ .cl::get<objRef>(UlnConnection::UlnReceiveConfigOApp);
220
+
221
+ (cell requiredDVNs, cell optionalDVNs, int isValid) = UlnReceiveConfig::utils::getVerifyConfig(
222
+ $customUlnReceiveConfigOApp,
223
+ $defaultUlnReceiveConfigOApp
224
+ );
225
+
226
+ if (isValid) {
227
+ return _dvnIsRequiredOrOptional(
228
+ requiredDVNs.begin_parse(),
229
+ optionalDVNs.begin_parse(),
230
+ dvnAddress
231
+ );
232
+ }
233
+ return false;
234
+ }
235
+
236
+ ;;; ================PERMISSION FUNCTIONS=====================
237
+
238
+ () _checkPermissions(int op, cell $md) impure inline {
239
+ if (
240
+ (op == MsglibConnection::OP::MSGLIB_CONNECTION_SEND)
241
+ | (op == MsglibConnection::OP::MSGLIB_CONNECTION_COMMIT_PACKET_CALLBACK)
242
+ ) {
243
+ return assertChannel($md);
244
+ } elseif (
245
+ (op == UlnConnection::OP::ULN_CONNECTION_VERIFY)
246
+ | (op == UlnConnection::OP::ULN_CONNECTION_COMMIT_PACKET)
247
+ ) {
248
+ return assertUln();
249
+ } elseif (
250
+ (op == MsglibConnection::OP::MSGLIB_CONNECTION_QUOTE)
251
+ ) {
252
+ return ();
253
+ } elseif (op == UlnConnection::OP::GARBAGE_COLLECT_INVALID_ATTESTATIONS){
254
+ return assertUln();
255
+ } elseif (op == MsglibConnection::OP::MSGLIB_CONNECTION_SYNC_CHANNEL_STATE) {
256
+ return assertChannel($md);
257
+ } elseif (
258
+ (op == UlnConnection::OP::SET_OAPP_ULN_SEND_CONFIG)
259
+ | (op == UlnConnection::OP::SET_OAPP_ULN_RECEIVE_CONFIG)
260
+ ) {
261
+ return assertOwner();
262
+ } elseif (op == UlnConnection::OP::GARBAGE_COLLECT_EXECUTED_NONCES) {
263
+ return ();
264
+ } else {
265
+ ;; we must put a check for all opcodes to make sure we don't
266
+ ;; mistakenly miss an opp code's permissions
267
+ throw(BaseInterface::ERROR::invalidOpcode);
268
+ }
269
+ }
270
+
271
+ ;;; ==========================HANDLERS=====================================
272
+
273
+ ;; permissionless
274
+ tuple msglibConnectionQuote(cell $lzSend) impure inline method_id {
275
+ (cell $storage, tuple actions) = preamble();
276
+
277
+ actions~pushAction<call>(
278
+ $storage.cl::get<address>(UlnConnection::ulnAddress),
279
+ Uln::OP::ULN_QUOTE,
280
+ md::UlnSend::New(
281
+ $lzSend,
282
+ $storage.cl::get<objRef>(UlnConnection::UlnSendConfigOApp),
283
+ getInitialStorage(),
284
+ getCaller()
285
+ )
286
+ );
287
+
288
+ return actions;
289
+ }
290
+
291
+ ;; only uln
292
+ tuple msglibConnectionSend(cell $lzSend) impure inline method_id {
293
+ (cell $storage, tuple actions) = preamble();
294
+
295
+ actions~pushAction<call>(
296
+ $storage.cl::get<address>(UlnConnection::ulnAddress),
297
+ Uln::OP::ULN_SEND,
298
+ md::UlnSend::New(
299
+ $lzSend,
300
+ $storage.cl::get<objRef>(UlnConnection::UlnSendConfigOApp),
301
+ getInitialStorage(),
302
+ $storage.cl::get<address>(UlnConnection::channelAddress)
303
+ )
304
+ );
305
+
306
+ return actions;
307
+ }
308
+
309
+ ;; permissionless
310
+ ;; @in $extendedMd { md: Verification, obj: defaultUlnReceiveConfig, address: dvnAddress }
311
+ tuple ulnConnectionVerify(cell $extendedMd) impure inline method_id {
312
+ (cell $storage, tuple actions) = preamble();
313
+
314
+ int dvnAddress = $extendedMd.cl::get<address>(md::ExtendedMd::forwardingAddress);
315
+ cell $defaultUlnReceiveConfigOApp = $extendedMd.cl::get<objRef>(md::ExtendedMd::obj);
316
+ cell $ulnVerification = $extendedMd.cl::get<objRef>(md::ExtendedMd::md);
317
+
318
+ int nonce = $ulnVerification.cl::get<uint64>(md::UlnVerification::nonce);
319
+
320
+ int firstUnexecutedNonce = $storage.cl::get<uint64>(UlnConnection::firstUnexecutedNonce);
321
+
322
+ ;; assume success unless something fails in the verification logic
323
+ int statusCode = UlnConnection::ULN_CONNECTION_VERIFY_SUCCEEDED;
324
+
325
+ if (
326
+ (nonce < firstUnexecutedNonce)
327
+ | (nonce >= (firstUnexecutedNonce + UlnConnection::MAX_HASH_LOOKUPS))
328
+ ) {
329
+ ;; if the nonce has already been executed, or if it is invalid (== 0),
330
+ ;; do not allow verification of the packet
331
+ statusCode = UlnConnection::ULN_CONNECTION_VERIFY_FAILED::NONCE_OUT_OF_RANGE;
332
+ } elseifnot (_isDvnConfigured(dvnAddress, $defaultUlnReceiveConfigOApp)) {
333
+ statusCode = UlnConnection::ULN_CONNECTION_VERIFY_FAILED::DVN_NOT_CONFIGURED;
334
+ } else {
335
+ cell $attestation = $ulnVerification.cl::get<objRef>(md::UlnVerification::attestation);
336
+ ;; Ensure the DVN is not passing a malicious attestation that is bigger than expected
337
+ lz::Attestation::validate($attestation);
338
+
339
+ setContractStorage(
340
+ UlnConnection::utils::setHashLookup(
341
+ $storage,
342
+ nonce,
343
+ dvnAddress,
344
+ $attestation
345
+ )
346
+ );
347
+ actions~pushAction<event>(
348
+ UlnConnection::event::PACKET_VERIFIED,
349
+ $ulnVerification
350
+ );
351
+ }
352
+
353
+ actions~pushAction<call>(
354
+ dvnAddress,
355
+ UltraLightNode::OP::ULN_CONNECTION_VERIFY_CALLBACK,
356
+ md::MdObj::New(
357
+ md::VerificationStatus::New(nonce, statusCode),
358
+ getInitialStorage()
359
+ )
360
+ );
361
+
362
+ return actions;
363
+ }
364
+
365
+ ;; removes all attestations for all dvns that are not in the current configuration
366
+ tuple garbageCollectInvalidAttestations(cell $mdObj) impure inline method_id {
367
+ (cell $storage, tuple actions) = preamble();
368
+
369
+ cell $mdNonce = $mdObj.cl::get<objRef>(md::MdObj::md);
370
+ int nonce = $mdNonce.cl::get<uint64>(md::Nonce::nonce);
371
+
372
+ cell $defaultUlnReceiveConfigOApp = $mdObj.cl::get<objRef>(md::MdObj::obj);
373
+
374
+ cell $customUlnReceiveConfigOApp = $storage.cl::get<objRef>(UlnConnection::UlnReceiveConfigOApp);
375
+ (cell requiredDVNs, cell optionalDVNs, int isValid) = UlnReceiveConfig::utils::getVerifyConfig(
376
+ $customUlnReceiveConfigOApp,
377
+ $defaultUlnReceiveConfigOApp
378
+ );
379
+ slice requiredDVNsSlice = requiredDVNs.begin_parse();
380
+ slice optionalDVNsSlice = optionalDVNs.begin_parse();
381
+
382
+ ifnot (isValid) {
383
+ return actions;
384
+ }
385
+
386
+ actions~pushAction<event>(
387
+ UlnConnection::event::ATTESTATIONS_EVICTED,
388
+ $mdNonce
389
+ );
390
+
391
+ cell $newStorage = UlnConnection::utils::deleteNonceAttestations($storage, nonce);
392
+
393
+ ;; iterate the required DVNs
394
+
395
+ int requiredDVNAddress = requiredDVNsSlice~AddressList::next();
396
+ while (requiredDVNAddress > NULLADDRESS) {
397
+ cell $attestation = UlnConnection::utils::getHashLookup($storage, nonce, requiredDVNAddress);
398
+ ifnot ($attestation.cl::isNull()) {
399
+ $newStorage = UlnConnection::utils::setHashLookup(
400
+ $newStorage,
401
+ nonce,
402
+ requiredDVNAddress,
403
+ $attestation
404
+ );
405
+ }
406
+ requiredDVNAddress = requiredDVNsSlice~AddressList::next();
407
+ }
408
+
409
+ int optionalDVNAddress = optionalDVNsSlice~AddressList::next();
410
+ while (optionalDVNAddress > NULLADDRESS) {
411
+ cell $attestation = UlnConnection::utils::getHashLookup($storage, nonce, optionalDVNAddress);
412
+ ifnot ($attestation.cl::isNull()) {
413
+ $newStorage = UlnConnection::utils::setHashLookup(
414
+ $newStorage,
415
+ nonce,
416
+ optionalDVNAddress,
417
+ $attestation
418
+ );
419
+ }
420
+ optionalDVNAddress = optionalDVNsSlice~AddressList::next();
421
+ }
422
+
423
+ setContractStorage($newStorage);
424
+
425
+ return actions;
426
+ }
427
+
428
+ tuple garbageCollectExecutedNonces(cell $empty) impure inline method_id {
429
+ (cell $storage, tuple actions) = preamble();
430
+
431
+ int firstUnexecutedNonce = $storage.cl::get<uint64>(UlnConnection::firstUnexecutedNonce);
432
+ cell hashLookups = $storage.cl::get<dict256>(UlnConnection::hashLookups);
433
+
434
+ (int minNonce, _) = cl::dict256::getMin<cellRef>(hashLookups);
435
+
436
+ if ((minNonce > 0) & (minNonce < firstUnexecutedNonce)) {
437
+ setContractStorage(
438
+ UlnConnection::utils::deleteNonceAttestations($storage, minNonce)
439
+ );
440
+ actions~pushAction<call>(
441
+ getContractAddress(),
442
+ UlnConnection::OP::GARBAGE_COLLECT_EXECUTED_NONCES,
443
+ $empty
444
+ );
445
+ }
446
+
447
+ return actions;
448
+ }
449
+
450
+ ;; (uln -> ulnConnection -> channel)
451
+ ;; @in_md { Packet }
452
+ tuple ulnConnectionCommitPacket(cell $mdObj) impure inline method_id {
453
+ (cell $storage, tuple actions) = preamble();
454
+
455
+ cell $packet = $mdObj.cl::get<objRef>(md::MdObj::md);
456
+ int packetHash = $packet.cl::hash();
457
+ int nonce = $packet.cl::get<uint64>(lz::Packet::nonce);
458
+
459
+ cell $defaultUlnReceiveConfig = $mdObj.cl::get<objRef>(md::MdObj::obj);
460
+
461
+ (
462
+ cell requiredDVNs,
463
+ cell optionalDVNs,
464
+ int optionalDVNThreshold,
465
+ int requiredConfirmations,
466
+ int commitPacketGas,
467
+ int isValid
468
+ ) = UlnReceiveConfig::utils::getCommitConfig(
469
+ $storage.cl::get<objRef>(UlnConnection::UlnReceiveConfigOApp),
470
+ $defaultUlnReceiveConfig
471
+ );
472
+
473
+ ifnot (isValid) {
474
+ return actions;
475
+ }
476
+
477
+ ifnot (
478
+ _committable(nonce,packetHash, requiredDVNs, optionalDVNs, optionalDVNThreshold, requiredConfirmations)
479
+ & ((getMsgValue() - _gasToNanoton(get_gas_consumed())) >= _gasToNanoton(commitPacketGas))
480
+ ) {
481
+ return actions;
482
+ }
483
+
484
+ ;; If all above checks pass (no early return)
485
+ ;; commit the packet to the endpoint
486
+ actions~pushAction<call>(
487
+ $storage.cl::get<address>(UlnConnection::endpointAddress),
488
+ Endpoint::OP::ENDPOINT_COMMIT_PACKET,
489
+ $packet
490
+ );
491
+
492
+ return actions;
493
+ }
494
+
495
+ ;; only channel
496
+ tuple msglibConnectionCommitPacketCallback(cell $channelNonceInfo) impure inline method_id {
497
+ (cell $storage, tuple actions) = preamble();
498
+
499
+ int committedNonce = $channelNonceInfo.cl::get<uint64>(md::ChannelNonceInfo::nonce);
500
+ ;; invariant:
501
+ ;; firstUnexecutedNonce >= $storage.cl::get<uint64>(UlnConnection::firstUnexecutedNonce)
502
+ int firstUnexecutedNonce = $channelNonceInfo
503
+ .cl::get<uint64>(md::ChannelNonceInfo::firstUnexecutedNonce);
504
+
505
+ cell $commitPOOO = $storage.cl::get<objRef>(UlnConnection::commitPOOO);
506
+ if (committedNonce <= POOO::maxSettableBit($commitPOOO)) {
507
+ $commitPOOO = POOO::set($commitPOOO, committedNonce);
508
+ }
509
+ setContractStorage(
510
+ $storage
511
+ .UlnConnection::utils::deleteNonceAttestations(committedNonce)
512
+ .cl::set(
513
+ UlnConnection::firstUnexecutedNonce,
514
+ firstUnexecutedNonce
515
+ )
516
+ .cl::set(
517
+ UlnConnection::commitPOOO,
518
+ $commitPOOO
519
+ )
520
+ );
521
+
522
+ return actions;
523
+ }
524
+
525
+ ;; only channel
526
+ tuple msglibConnectionSyncChannelState(cell $channelNonceInfo) impure inline method_id {
527
+ (cell $storage, tuple actions) = preamble();
528
+ ;; invariant:
529
+ ;; firstUnexecutedNonce >= $storage.cl::get<uint64>(UlnConnection::firstUnexecutedNonce)
530
+ int firstUnexecutedNonce = $channelNonceInfo
531
+ .cl::get<uint64>(md::ChannelNonceInfo::firstUnexecutedNonce);
532
+ int firstUncommittedNonce = $channelNonceInfo.cl::get<uint64>(md::ChannelNonceInfo::nonce);
533
+ cell $commitPOOO = $storage.cl::get<objRef>(UlnConnection::commitPOOO);
534
+ int maxNonce = POOO::maxSettableBit($commitPOOO);
535
+
536
+ if (firstUncommittedNonce > (maxNonce + MAX_CELL_BIT_INDEX)) {
537
+ $commitPOOO = POOO::New().cl::set(POOO::nextEmpty, firstUncommittedNonce);
538
+ } elseif (firstUncommittedNonce > maxNonce) {
539
+ int nextEmpty = $commitPOOO.cl::get<uint64>(POOO::nextEmpty);
540
+ $commitPOOO = POOO::unsafeSetBits($commitPOOO, nextEmpty, maxNonce);
541
+ }
542
+
543
+ int nextEmpty = $commitPOOO.cl::get<uint64>(POOO::nextEmpty);
544
+ $commitPOOO = POOO::unsafeSetBits($commitPOOO, nextEmpty, firstUncommittedNonce);
545
+
546
+ setContractStorage(
547
+ $storage
548
+ .cl::set(
549
+ UlnConnection::firstUnexecutedNonce,
550
+ firstUnexecutedNonce
551
+ )
552
+ .cl::set(UlnConnection::commitPOOO, $commitPOOO)
553
+ );
554
+
555
+ return actions;
556
+ }
557
+
558
+ tuple setOAppUlnSendConfig(cell $ulnSendConfig) impure inline method_id {
559
+ (cell $storage, tuple actions) = preamble();
560
+
561
+ cell $sanitizedUlnSendConfig = UlnSendConfig::sanitize($ulnSendConfig);
562
+
563
+ setContractStorage(
564
+ $storage.cl::set(
565
+ UlnConnection::UlnSendConfigOApp,
566
+ $sanitizedUlnSendConfig
567
+ )
568
+ );
569
+
570
+ actions~pushAction<event>(
571
+ UlnConnection::event::ULN_SEND_CONFIG_SET,
572
+ $sanitizedUlnSendConfig
573
+ );
574
+
575
+ return actions;
576
+ }
577
+
578
+ tuple setOAppUlnReceiveConfig(cell $ulnReceiveConfig) impure inline method_id {
579
+ (cell $storage, tuple actions) = preamble();
580
+
581
+ cell $sanitizedUlnReceiveConfig = UlnReceiveConfig::sanitize($ulnReceiveConfig);
582
+
583
+ setContractStorage(
584
+ $storage.cl::set(
585
+ UlnConnection::UlnReceiveConfigOApp,
586
+ $sanitizedUlnReceiveConfig
587
+ )
588
+ );
589
+
590
+ actions~pushAction<event>(
591
+ UlnConnection::event::ULN_RECEIVE_CONFIG_SET,
592
+ $sanitizedUlnReceiveConfig
593
+ );
594
+
595
+ return actions;
596
+ }
597
+
598
+ (int, int, int) version() impure method_id {
599
+ return (3, 0, 2);
600
+ }
@@ -0,0 +1,36 @@
1
+ #include "storage.fc";
2
+
3
+ ;; authenticated against the config
4
+ const int UlnConnection::OP::ULN_CONNECTION_VERIFY = "UlnConnection::OP::ULN_CONNECTION_VERIFY"c;
5
+
6
+ ;; permissionless
7
+ const int UlnConnection::OP::ULN_CONNECTION_COMMIT_PACKET = "UlnConnection::OP::ULN_CONNECTION_COMMIT_PACKET"c;
8
+
9
+ const int UlnConnection::OP::SET_OAPP_ULN_RECEIVE_CONFIG = "UlnConnection::OP::SET_OAPP_ULN_RECEIVE_CONFIG"c;
10
+ const int UlnConnection::OP::SET_OAPP_ULN_SEND_CONFIG = "UlnConnection::OP::SET_OAPP_ULN_SEND_CONFIG"c;
11
+
12
+ const int UlnConnection::OP::GARBAGE_COLLECT_INVALID_ATTESTATIONS = "UlnConnection::OP::GARBAGE_COLLECT_INVALID_ATTESTATIONS"c;
13
+
14
+ const int UlnConnection::OP::GARBAGE_COLLECT_EXECUTED_NONCES = "UlnConnection::OP::GARBAGE_COLLECT_EXECUTED_NONCES"c;
15
+
16
+ ;; ERRORS
17
+ const int UlnConnection::ERROR::onlyUln = 193;
18
+ const int UlnConnection::ERROR::onlyChannel = 194;
19
+ const int UlnConnection::ERROR::invalidUlnSendConfig = 195;
20
+ const int UlnConnection::ERROR::onlyConfiguredDvn = 196;
21
+
22
+ const int UlnConnection::event::ULN_SEND_CONFIG_SET = "UlnConn::event::ULN_SEND_CFG_SET"u;
23
+ const int UlnConnection::event::ULN_RECEIVE_CONFIG_SET = "UlnConn::event::ULN_REC_CFG_SET"u;
24
+ const int UlnConnection::event::ATTESTATIONS_EVICTED = "UlnConn::event::ATTESTS_EVCTD"u;
25
+ const int UlnConnection::event::PACKET_VERIFIED = "UlnConn::event::PACKET_VERIFIED"u;
26
+ const int UlnConnection::event::PACKET_VERIFIED = "UlnConn::event::PACKET_VERIFIED"u;
27
+
28
+ const int UlnConnection::ULN_CONNECTION_VERIFY_FAILED::DVN_NOT_CONFIGURED = "UlnConnection::ULN_CONNECTION_VERIFY_FAILED::DVN_NOT_CONFIGURED"c;
29
+ const int UlnConnection::ULN_CONNECTION_VERIFY_FAILED::NONCE_OUT_OF_RANGE = "UlnConnection::ULN_CONNECTION_VERIFY_FAILED::NONCE_OUT_OF_RANGE"c;
30
+ const int UlnConnection::ULN_CONNECTION_VERIFY_SUCCEEDED = "UlnConnection::ULN_CONNECTION_VERIFY_SUCCEEDED"c;
31
+
32
+ const int UlnConnection::verificationStatus::VERIFYING = 0;
33
+ const int UlnConnection::verificationStatus::COMMITTABLE = 1;
34
+ const int UlnConnection::verificationStatus::COMMITTED = 2;
35
+ const int UlnConnection::verificationStatus::EXECUTED = 3;
36
+ const int UlnConnection::verificationStatus::CONFIGURATION_ERROR = 4;
@@ -0,0 +1,32 @@
1
+ #include "../../../core/abstract/protocolMain.fc";
2
+
3
+ #include "../../interface.fc";
4
+
5
+ #include "handler.fc";
6
+ #include "interface.fc";
7
+
8
+ tuple _executeOpcode(int op, cell $md) impure inline {
9
+ if (op == MsglibConnection::OP::MSGLIB_CONNECTION_QUOTE) {
10
+ return msglibConnectionQuote($md);
11
+ } elseif (op == MsglibConnection::OP::MSGLIB_CONNECTION_SEND) {
12
+ return msglibConnectionSend($md);
13
+ } elseif (op == UlnConnection::OP::ULN_CONNECTION_VERIFY) {
14
+ return ulnConnectionVerify($md);
15
+ } elseif (op == UlnConnection::OP::ULN_CONNECTION_COMMIT_PACKET) {
16
+ return ulnConnectionCommitPacket($md);
17
+ } elseif (op == MsglibConnection::OP::MSGLIB_CONNECTION_COMMIT_PACKET_CALLBACK) {
18
+ return msglibConnectionCommitPacketCallback($md);
19
+ } elseif (op == MsglibConnection::OP::MSGLIB_CONNECTION_SYNC_CHANNEL_STATE) {
20
+ return msglibConnectionSyncChannelState($md);
21
+ } elseif (op == UlnConnection::OP::SET_OAPP_ULN_SEND_CONFIG) {
22
+ return setOAppUlnSendConfig($md);
23
+ } elseif (op == UlnConnection::OP::SET_OAPP_ULN_RECEIVE_CONFIG) {
24
+ return setOAppUlnReceiveConfig($md);
25
+ } elseif (op == UlnConnection::OP::GARBAGE_COLLECT_INVALID_ATTESTATIONS) {
26
+ return garbageCollectInvalidAttestations($md);
27
+ } elseif (op == UlnConnection::OP::GARBAGE_COLLECT_EXECUTED_NONCES) {
28
+ return garbageCollectExecutedNonces($md);
29
+ }
30
+ throw(BaseInterface::ERROR::invalidOpcode);
31
+ return null();
32
+ }