@layerzerolabs/layerzero-v2-ton 3.0.27 → 3.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/build/ActionsSerde.test.compiled.json +1 -0
- package/build/AllStorages.compiled.json +1 -1
- package/build/AllStorages.test.compiled.json +1 -1
- package/build/BaseContract.test.compiled.json +1 -1
- package/build/Channel.compiled.json +1 -1
- package/build/Channel.permissions.test.compiled.json +1 -1
- package/build/ChannelBurn.test.compiled.json +1 -1
- package/build/ChannelCommitPacket.test.compiled.json +1 -1
- package/build/ChannelConfig.test.compiled.json +1 -1
- package/build/ChannelInitialize.test.compiled.json +1 -1
- package/build/ChannelMsglibIntegration.test.compiled.json +1 -1
- package/build/ChannelMsglibSendCallback.test.compiled.json +1 -1
- package/build/ChannelNilify.test.compiled.json +1 -1
- package/build/ChannelReceive.test.compiled.json +1 -1
- package/build/ChannelReceiveCallback.test.compiled.json +1 -1
- package/build/ChannelReceiveView.test.compiled.json +1 -1
- package/build/ChannelSend.test.compiled.json +1 -1
- package/build/ChannelSerde.test.compiled.json +1 -0
- package/build/Classlib.test.compiled.json +1 -1
- package/build/ComputeDataSizeGas.test.compiled.json +1 -1
- package/build/Connection.compiled.json +1 -1
- package/build/Controller.assertions.test.compiled.json +1 -1
- package/build/Controller.compiled.json +1 -1
- package/build/Controller.permissions.test.compiled.json +1 -1
- package/build/Controller.test.compiled.json +1 -1
- package/build/Counter.compiled.json +1 -1
- package/build/Counter.permissions.test.compiled.json +1 -1
- package/build/Counter.setters.test.compiled.json +1 -1
- package/build/Counter.test.compiled.json +1 -1
- package/build/Dvn.compiled.json +1 -1
- package/build/Dvn.test.compiled.json +1 -1
- package/build/DvnFeeLib.compiled.json +1 -1
- package/build/DvnFeeLibSerde.test.compiled.json +1 -0
- package/build/DvnPermissions.test.compiled.json +1 -1
- package/build/DvnSerde.test.compiled.json +1 -0
- package/build/Endpoint.compiled.json +1 -1
- package/build/Endpoint.permissions.test.compiled.json +1 -1
- package/build/Endpoint.test.compiled.json +1 -1
- package/build/EndpointSerde.test.compiled.json +1 -0
- package/build/EndpointSetEpConfigDefaults.test.compiled.json +1 -1
- package/build/Executor.compiled.json +1 -1
- package/build/Executor.test.compiled.json +1 -1
- package/build/ExecutorFeeLib.compiled.json +1 -1
- package/build/ExecutorFeeLibSerde.test.compiled.json +1 -0
- package/build/ExecutorPermissions.test.compiled.json +1 -1
- package/build/ExecutorSerde.test.compiled.json +1 -0
- package/build/LzClasses.test.compiled.json +1 -1
- package/build/LzClassesSerde.test.compiled.json +1 -0
- package/build/LzUtil.test.compiled.json +1 -1
- package/build/MsgData.test.compiled.json +1 -1
- package/build/MsgDataSerde.test.compiled.json +1 -0
- package/build/MsglibPacketCodec.test.compiled.json +1 -1
- package/build/PipelinedOutOfOrder.test.compiled.json +1 -1
- package/build/PipelinedOutOfOrderSerde.test.compiled.json +1 -0
- package/build/PriceFeedCache.compiled.json +1 -1
- package/build/PriceFeedCache.test.compiled.json +1 -1
- package/build/PriceFeedCache.test.permissions.compiled.json +1 -1
- package/build/PriceFeedCacheSerde.test.compiled.json +1 -0
- package/build/PriceFeedFeeLibSerde.test.compiled.json +1 -0
- package/build/Proxy.compiled.json +1 -1
- package/build/Proxy.permissions.test.compiled.json +1 -1
- package/build/Proxy.test.compiled.json +1 -1
- package/build/SmlConnection.compiled.json +1 -1
- package/build/SmlConnection.permissions.test.compiled.json +1 -1
- package/build/SmlConnection.test.compiled.json +1 -1
- package/build/SmlManager.compiled.json +1 -1
- package/build/SmlManager.permissions.test.compiled.json +1 -1
- package/build/SmlManager.test.compiled.json +1 -1
- package/build/Uln.compiled.json +1 -1
- package/build/Uln.test.compiled.json +1 -1
- package/build/UlnConnection.compiled.json +1 -1
- package/build/UlnConnection.test.compiled.json +1 -1
- package/build/UlnConnectionPermissions.test.compiled.json +1 -1
- package/build/UlnConnectionSerde.test.compiled.json +1 -0
- package/build/UlnManagement.test.compiled.json +1 -1
- package/build/UlnManager.compiled.json +1 -1
- package/build/UlnManager.test.compiled.json +1 -1
- package/build/UlnManagerPermissions.test.compiled.json +1 -1
- package/build/UlnManagerUtil.test.compiled.json +1 -1
- package/build/UlnMsgDataSerde.test.compiled.json +1 -0
- package/build/UlnPermissions.test.compiled.json +1 -1
- package/build/UlnReceiveConfig.test.compiled.json +1 -1
- package/build/UlnSend.test.compiled.json +1 -1
- package/build/UlnSendConfig.test.compiled.json +1 -1
- package/build/UlnSendWithDvnFeeLib.test.compiled.json +1 -1
- package/build/UlnSendWithExecFeeLib.test.compiled.json +1 -1
- package/build/UlnSendWorkerFactory.test.compiled.json +1 -1
- package/build/UlnSerde.test.compiled.json +1 -0
- package/build/UlnUtil.test.compiled.json +1 -1
- package/build/WorkerCore.test.compiled.json +1 -1
- package/build/WorkerCoreMsgDataSerde.test.compiled.json +1 -0
- package/build/WorkerCoreSerde.test.compiled.json +1 -0
- package/build/badFeeLib1.test.compiled.json +1 -1
- package/build/badFeeLib10.test.compiled.json +1 -1
- package/build/badFeeLib11.test.compiled.json +1 -1
- package/build/badFeeLib12.test.compiled.json +1 -1
- package/build/badFeeLib2.test.compiled.json +1 -1
- package/build/badFeeLib3.test.compiled.json +1 -1
- package/build/badFeeLib4.test.compiled.json +1 -1
- package/build/badFeeLib5.test.compiled.json +1 -1
- package/build/badFeeLib6.test.compiled.json +1 -1
- package/build/badFeeLib7.test.compiled.json +1 -1
- package/build/badFeeLib8.test.compiled.json +1 -1
- package/build/badFeeLib9.test.compiled.json +1 -1
- package/package.json +1 -1
- package/src/classes/lz/EpConfig.fc +90 -23
- package/src/classes/lz/MsglibInfo.fc +32 -5
- package/src/classes/lz/Packet.fc +109 -48
- package/src/classes/lz/Path.fc +55 -4
- package/src/classes/lz/ReceiveEpConfig.fc +36 -5
- package/src/classes/lz/SendEpConfig.fc +55 -5
- package/src/classes/msgdata/AddMsglib.fc +11 -0
- package/src/classes/msgdata/ChannelNonceInfo.fc +20 -0
- package/src/classes/msgdata/CoinsAmount.fc +8 -0
- package/src/classes/msgdata/Deploy.fc +19 -0
- package/src/classes/msgdata/ExtendedMd.fc +52 -1
- package/src/classes/msgdata/LzReceivePrepare.fc +21 -1
- package/src/classes/msgdata/LzReceiveStatus.fc +72 -1
- package/src/classes/msgdata/LzSend.fc +143 -24
- package/src/classes/msgdata/MdAddress.fc +42 -0
- package/src/classes/msgdata/MdEid.fc +8 -0
- package/src/classes/msgdata/MdObj.fc +32 -0
- package/src/classes/msgdata/MessagingReceipt.fc +34 -1
- package/src/classes/msgdata/MsglibSendCallback.fc +82 -0
- package/src/classes/msgdata/Nonce.fc +30 -0
- package/src/classes/msgdata/OptionsV1.fc +21 -1
- package/src/classes/msgdata/OptionsV2.fc +27 -0
- package/src/classes/msgdata/PacketId.fc +24 -0
- package/src/classes/msgdata/PacketSent.fc +35 -1
- package/src/classes/msgdata/SetAddress.fc +7 -0
- package/src/classes/msgdata/SetEpConfig.fc +17 -0
- package/src/funC++/actions/event.fc +17 -2
- package/src/funC++/actions/utils.fc +2 -2
- package/src/funC++/classlib.fc +33 -43
- package/src/funC++/constants.fc +28 -28
- package/src/funC++/dataStructures/PipelinedOutOfOrder.fc +75 -59
- package/src/funC++/stdlib.fc +26 -11
- package/src/funC++/testutils.fc +2 -2
- package/src/funC++/txnContext.fc +14 -14
- package/src/funC++/utils.fc +97 -1
- package/src/protocol/channel/handler.fc +247 -189
- package/src/protocol/channel/storage.fc +206 -1
- package/src/protocol/controller/handler.fc +35 -17
- package/src/protocol/controller/main.fc +1 -1
- package/src/protocol/core/abstract/protocolHandler.fc +11 -21
- package/src/protocol/core/baseStorage.fc +24 -0
- package/src/protocol/endpoint/handler.fc +99 -57
- package/src/protocol/endpoint/storage.fc +69 -5
- package/src/protocol/msglibs/BytesEncoder.fc +11 -10
- package/src/protocol/msglibs/simpleMsglib/smlManager/handler.fc +1 -4
- package/src/protocol/msglibs/ultralightnode/feeLibInterface.fc +1 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/Attestation.fc +7 -8
- package/src/protocol/msglibs/ultralightnode/msgdata/DvnFeesPaidEvent.fc +20 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/ExecutorFeePaidEvent.fc +15 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/InitUln.fc +1 -1
- package/src/protocol/msglibs/ultralightnode/msgdata/InitUlnConnection.fc +1 -1
- package/src/protocol/msglibs/ultralightnode/msgdata/SetAdminWorkerAddresses.fc +6 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnEvents.fc +20 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnReceiveConfig.fc +114 -28
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnSend.fc +51 -1
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnSendConfig.fc +1 -1
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnVerification.fc +10 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibBytecode.fc +6 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibInfo.fc +51 -1
- package/src/protocol/msglibs/ultralightnode/msgdata/VerificationStatus.fc +15 -0
- package/src/protocol/msglibs/ultralightnode/uln/handler.fc +84 -107
- package/src/protocol/msglibs/ultralightnode/uln/storage.fc +77 -1
- package/src/protocol/msglibs/ultralightnode/ulnConnection/handler.fc +92 -66
- package/src/protocol/msglibs/ultralightnode/ulnConnection/storage.fc +113 -6
- package/src/protocol/msglibs/ultralightnode/ulnConnection/utils.fc +6 -91
- package/src/protocol/msglibs/ultralightnode/ulnManager/handler.fc +55 -31
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/handler.fc +13 -9
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/storage.fc +23 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/handler.fc +63 -27
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/storage.fc +19 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/priceFeedFeeLib/storage.fc +55 -6
- package/src/workers/core/abstract/workerHandler.fc +20 -19
- package/src/workers/core/interface.fc +2 -1
- package/src/workers/core/workerCoreStorage.fc +16 -1
- package/src/workers/dvn/handler.fc +67 -26
- package/src/workers/dvn/storage.fc +15 -2
- package/src/workers/executor/handler.fc +18 -6
- package/src/workers/executor/interface.fc +1 -0
- package/src/workers/executor/storage.fc +8 -1
- package/src/workers/msgdata/DropEvent.fc +18 -0
- package/src/workers/msgdata/ExecuteParams.fc +66 -3
- package/src/workers/msgdata/NativeDrop.fc +4 -0
- package/src/workers/msgdata/SetDict.fc +6 -4
- package/src/workers/msgdata/SetQuorum.fc +4 -2
- package/src/workers/msgdata/SignedRequest.fc +8 -0
- package/src/workers/priceFeedCache/handler.fc +21 -27
- package/src/workers/priceFeedCache/storage.fc +16 -1
- package/src/workers/proxy/handler.fc +2 -1
- package/src/workers/proxy/storage.fc +1 -1
- package/tests/baseContractTest.fc +2 -6
- package/tests/testMain.fc +2 -2
- package/src/classes/msgdata/Amount.fc +0 -16
- package/src/funC++/actions/destroy.fc +0 -27
|
@@ -38,9 +38,7 @@
|
|
|
38
38
|
;;; ================INTERFACE FUNCTIONS=====================
|
|
39
39
|
|
|
40
40
|
int _getEventSink() inline {
|
|
41
|
-
return
|
|
42
|
-
.cl::get<objRef>(Channel::baseStorage)
|
|
43
|
-
.cl::get<address>(BaseStorage::owner);
|
|
41
|
+
return getOwner();
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
;;; ==========================HELPER FUNCTIONS=====================================
|
|
@@ -72,11 +70,11 @@ int _readSendRequestQueueEntry(cell contents) inline method_id {
|
|
|
72
70
|
|
|
73
71
|
cell $storage = getContractStorage();
|
|
74
72
|
|
|
75
|
-
cell $executePOOO = $storage.
|
|
76
|
-
int firstUnexecutedNonce = $executePOOO.
|
|
73
|
+
cell $executePOOO = $storage.Channel::getExecutePOOO();
|
|
74
|
+
int firstUnexecutedNonce = $executePOOO.POOO::getNextEmpty();
|
|
77
75
|
|
|
78
76
|
(int actualKey, cell $packet, int status, int exists) = DeterministicInsertionCircularQueue::get(
|
|
79
|
-
$storage.
|
|
77
|
+
$storage.Channel::getExecutionQueue(),
|
|
80
78
|
incomingNonce
|
|
81
79
|
);
|
|
82
80
|
|
|
@@ -106,11 +104,48 @@ int _readSendRequestQueueEntry(cell contents) inline method_id {
|
|
|
106
104
|
return (false, null());
|
|
107
105
|
}
|
|
108
106
|
|
|
107
|
+
;; returns boolean committable
|
|
108
|
+
int _optimizedNonceCommittable(cell $executePOOO, cell executionQueue, int incomingNonce) impure inline {
|
|
109
|
+
throw_if(Channel::ERROR::invalidNonce, incomingNonce <= 0);
|
|
110
|
+
|
|
111
|
+
int firstUnexecutedNonce = $executePOOO.POOO::getNextEmpty();
|
|
112
|
+
|
|
113
|
+
(int actualKey, _, int status, int exists) = DeterministicInsertionCircularQueue::get(
|
|
114
|
+
executionQueue,
|
|
115
|
+
incomingNonce
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (
|
|
119
|
+
(incomingNonce == firstUnexecutedNonce)
|
|
120
|
+
& (actualKey == incomingNonce)
|
|
121
|
+
& (status != ExecutionQueue::executing)
|
|
122
|
+
) {
|
|
123
|
+
;; short-circuit for efficiency in the common case
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
;; condition 1 & 2: must be within the window
|
|
128
|
+
;; condition 3: must not be executing
|
|
129
|
+
if (
|
|
130
|
+
(incomingNonce >= firstUnexecutedNonce)
|
|
131
|
+
& (incomingNonce <= POOO::maxSettableBit($executePOOO))
|
|
132
|
+
& (status != ExecutionQueue::executing)
|
|
133
|
+
) {
|
|
134
|
+
;; this is nested because funC doesn't support short-circuiting boolean/bitwise ops
|
|
135
|
+
;; condition 4: must not be executed
|
|
136
|
+
ifnot (POOO::isBitSet($executePOOO, incomingNonce)) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
109
144
|
cell _getExecutablePacket(int incomingNonce) impure inline method_id {
|
|
110
145
|
(int isCommittable, cell $packet) = _nonceCommittable(incomingNonce);
|
|
111
146
|
int firstUncommittedNonce = getContractStorage()
|
|
112
|
-
.
|
|
113
|
-
.
|
|
147
|
+
.Channel::getCommitPOOO()
|
|
148
|
+
.POOO::getNextEmpty();
|
|
114
149
|
|
|
115
150
|
throw_if(
|
|
116
151
|
Channel::ERROR::notExecutable,
|
|
@@ -134,8 +169,8 @@ cell _getExecutablePacket(int incomingNonce) impure inline method_id {
|
|
|
134
169
|
|
|
135
170
|
int _viewInboundNonce() impure method_id {
|
|
136
171
|
return getContractStorage()
|
|
137
|
-
.
|
|
138
|
-
.
|
|
172
|
+
.Channel::getCommitPOOO()
|
|
173
|
+
.POOO::getNextEmpty() - 1;
|
|
139
174
|
}
|
|
140
175
|
|
|
141
176
|
int _viewExecutionStatus(int incomingNonce) impure method_id {
|
|
@@ -202,22 +237,19 @@ int _viewExecutionStatus(int incomingNonce) impure method_id {
|
|
|
202
237
|
() _assertEndpoint() impure inline {
|
|
203
238
|
throw_unless(
|
|
204
239
|
Channel::ERROR::onlyEndpoint,
|
|
205
|
-
getCaller() == getContractStorage().
|
|
240
|
+
getCaller() == getContractStorage().Channel::getEndpointAddress()
|
|
206
241
|
);
|
|
207
242
|
}
|
|
208
243
|
|
|
209
244
|
;; this function is purposely designed to be maximally efficient when using a
|
|
210
245
|
;; custom configuration and less efficient when using a default configuration
|
|
211
|
-
() _assertSendMsglib(cell $
|
|
212
|
-
cell epConfigOApp = getContractStorage().cl::get<objRef>(Channel::epConfigOApp);
|
|
213
|
-
|
|
246
|
+
() _assertSendMsglib(cell $mdMsglibSendCallback) impure inline {
|
|
214
247
|
;; Resolve the actual sendMsglib address at the time of request.
|
|
215
248
|
;; This function assumes the messagelib is not malicious or man-in-the-middle attacking,
|
|
216
249
|
;; as those cases are asserted in the handler itself.
|
|
217
|
-
int sendMsglibAddress = $
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
.cl::get<address>(md::LzSend::sendMsglib);
|
|
250
|
+
int sendMsglibAddress = $mdMsglibSendCallback
|
|
251
|
+
.md::MsglibSendCallback::getLzSend()
|
|
252
|
+
.md::LzSend::getSendMsglib();
|
|
221
253
|
|
|
222
254
|
throw_unless(Channel::ERROR::onlyApprovedSendMsglib, getCaller() == sendMsglibAddress);
|
|
223
255
|
}
|
|
@@ -226,8 +258,8 @@ int _viewExecutionStatus(int incomingNonce) impure method_id {
|
|
|
226
258
|
throw_unless(
|
|
227
259
|
Channel::ERROR::onlyOApp,
|
|
228
260
|
getCaller() == getContractStorage()
|
|
229
|
-
.
|
|
230
|
-
.
|
|
261
|
+
.Channel::getPath()
|
|
262
|
+
.lz::Path::getSrcOApp()
|
|
231
263
|
);
|
|
232
264
|
}
|
|
233
265
|
|
|
@@ -280,10 +312,9 @@ int _viewExecutionStatus(int incomingNonce) impure method_id {
|
|
|
280
312
|
tuple setEpConfigOApp(cell $epConfigOApp) impure inline method_id {
|
|
281
313
|
(cell $storage, tuple actions) = preamble();
|
|
282
314
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
setContractStorage($storage.cl::set(Channel::epConfigOApp, $epConfigOApp));
|
|
315
|
+
setContractStorage(
|
|
316
|
+
$storage.cl::set(Channel::epConfigOApp, $epConfigOApp.lz::EpConfig::sanitize())
|
|
317
|
+
);
|
|
287
318
|
|
|
288
319
|
actions~pushAction<event>(Channel::event::EP_CFG_OAPP_SET, $epConfigOApp);
|
|
289
320
|
return actions;
|
|
@@ -298,28 +329,38 @@ tuple setEpConfigOApp(cell $epConfigOApp) impure inline method_id {
|
|
|
298
329
|
tuple channelSend(cell $mdObj) impure inline method_id {
|
|
299
330
|
(cell $storage, tuple actions) = preamble();
|
|
300
331
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
;; Resolve the desired send msglib and send msglib connection
|
|
306
|
-
cell $epConfigOApp = $storage.cl::get<objRef>(Channel::epConfigOApp);
|
|
307
|
-
int sendMsglib = $epConfigOApp.cl::get<address>(lz::EpConfig::sendMsglib);
|
|
308
|
-
int sendMsglibConnection = $epConfigOApp.cl::get<address>(lz::EpConfig::sendMsglibConnection);
|
|
309
|
-
cell $sendPath = $storage.cl::get<objRef>(Channel::path);
|
|
332
|
+
(
|
|
333
|
+
cell $lzSend,
|
|
334
|
+
cell $defaultSendEpConfig
|
|
335
|
+
) = $mdObj.md::MdObj::deserialize();
|
|
310
336
|
|
|
311
|
-
|
|
312
|
-
|
|
337
|
+
;; assert the size and structure of the incoming lzSend message
|
|
338
|
+
lz::Packet::assertValidSendMessage(
|
|
339
|
+
$lzSend.md::LzSend::getPacket()
|
|
340
|
+
);
|
|
313
341
|
|
|
314
|
-
|
|
342
|
+
(
|
|
343
|
+
cell $epConfigOApp,
|
|
344
|
+
cell $sendPath,
|
|
345
|
+
cell sendRequestQueue,
|
|
346
|
+
int lastSendRequestId
|
|
347
|
+
) = $storage.Channel::getSendInformation();
|
|
315
348
|
|
|
316
|
-
|
|
317
|
-
|
|
349
|
+
;; Resolve the desired send msglib and send msglib connection
|
|
350
|
+
(
|
|
351
|
+
int isEpConfigNull,
|
|
352
|
+
int sendMsglibManager,
|
|
353
|
+
int sendMsglib,
|
|
354
|
+
int sendMsglibConnection
|
|
355
|
+
) = $epConfigOApp.lz::EpConfig::deserializeSendConfig();
|
|
356
|
+
|
|
357
|
+
if (isEpConfigNull) {
|
|
358
|
+
(sendMsglibManager, sendMsglib, sendMsglibConnection) = $defaultSendEpConfig.lz::SendEpConfig::deserialize();
|
|
318
359
|
}
|
|
319
360
|
|
|
320
|
-
if ((sendMsglib == NULLADDRESS) | (sendMsglibConnection == NULLADDRESS)) {
|
|
361
|
+
if ((sendMsglibManager == NULLADDRESS) | (sendMsglib == NULLADDRESS) | (sendMsglibConnection == NULLADDRESS)) {
|
|
321
362
|
actions~pushAction<call>(
|
|
322
|
-
$sendPath.
|
|
363
|
+
$sendPath.lz::Path::getSrcOApp(),
|
|
323
364
|
Layerzero::OP::CHANNEL_SEND_CALLBACK,
|
|
324
365
|
md::MdObj::New(
|
|
325
366
|
md::MessagingReceipt::New(
|
|
@@ -336,26 +377,23 @@ tuple channelSend(cell $mdObj) impure inline method_id {
|
|
|
336
377
|
|
|
337
378
|
;; Each send request is assigned a unique request ID, which is also used as the key into
|
|
338
379
|
;; the sendRequestQueue
|
|
339
|
-
int curRequestId =
|
|
380
|
+
int curRequestId = lastSendRequestId + 1;
|
|
340
381
|
|
|
341
|
-
$lzSend = md::
|
|
382
|
+
$lzSend = md::LzSend::fillRequestInfo($lzSend, curRequestId, sendMsglibManager, sendMsglib, sendMsglibConnection);
|
|
342
383
|
|
|
343
|
-
cell sendRequestQueue = $storage.cl::get<cellRef>(Channel::sendRequestQueue);
|
|
344
384
|
(_, _, _, int exists) = DeterministicInsertionCircularQueue::get(sendRequestQueue, curRequestId);
|
|
345
385
|
ifnot (exists) {
|
|
346
386
|
;; submit to the msglib
|
|
347
387
|
setContractStorage(
|
|
348
|
-
$storage
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
_buildSendRequestQueueEntry($lzSend),
|
|
356
|
-
SendRequestQueue::sending
|
|
357
|
-
)
|
|
388
|
+
$storage.Channel::setSendRequestQueueAndLastSendRequestId(
|
|
389
|
+
curRequestId,
|
|
390
|
+
DeterministicInsertionCircularQueue::set(
|
|
391
|
+
sendRequestQueue,
|
|
392
|
+
curRequestId,
|
|
393
|
+
_buildSendRequestQueueEntry($lzSend),
|
|
394
|
+
SendRequestQueue::sending
|
|
358
395
|
)
|
|
396
|
+
)
|
|
359
397
|
);
|
|
360
398
|
|
|
361
399
|
actions~pushAction<call>(
|
|
@@ -367,7 +405,7 @@ tuple channelSend(cell $mdObj) impure inline method_id {
|
|
|
367
405
|
;; callback to the oApp with a failure and emit an event
|
|
368
406
|
actions~pushAction<event>(Channel::ERROR::sendQueueCongested, $lzSend);
|
|
369
407
|
actions~pushAction<call>(
|
|
370
|
-
$
|
|
408
|
+
$sendPath.lz::Path::getSrcOApp(),
|
|
371
409
|
Layerzero::OP::CHANNEL_SEND_CALLBACK,
|
|
372
410
|
md::MdObj::New(
|
|
373
411
|
md::MessagingReceipt::New($lzSend, 0, 0, Channel::ERROR::sendQueueCongested),
|
|
@@ -382,17 +420,37 @@ tuple channelSend(cell $mdObj) impure inline method_id {
|
|
|
382
420
|
;; in: msglib/handler.fc/msglibSend
|
|
383
421
|
;; in_md: MsglibSendCallback
|
|
384
422
|
;; out: OApp/handler.fc/sendCallback
|
|
385
|
-
tuple msglibSendCallback(cell $
|
|
423
|
+
tuple msglibSendCallback(cell $mdMsglibSendCallback) impure inline method_id {
|
|
386
424
|
(cell $storage, tuple actions) = preamble();
|
|
387
425
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
426
|
+
(
|
|
427
|
+
int errorCode,
|
|
428
|
+
int nativeQuote,
|
|
429
|
+
int zroQuote,
|
|
430
|
+
cell $lzSend,
|
|
431
|
+
cell serializedPayees,
|
|
432
|
+
cell encodedPacket,
|
|
433
|
+
int nonceByteOffset,
|
|
434
|
+
int nonceBytes,
|
|
435
|
+
int guidByteOffset,
|
|
436
|
+
int guidBytes,
|
|
437
|
+
cell $sendEvents
|
|
438
|
+
) = $mdMsglibSendCallback.md::MsglibSendCallback::deserialize();
|
|
391
439
|
|
|
392
|
-
|
|
393
|
-
|
|
440
|
+
(
|
|
441
|
+
int requestId,
|
|
442
|
+
int lzSendNativeFee,
|
|
443
|
+
int lzSendZroFee,
|
|
444
|
+
cell $extraOptions,
|
|
445
|
+
cell $enforceOptions
|
|
446
|
+
) = $lzSend.md::LzSend::deserializeSendCallback();
|
|
394
447
|
|
|
395
|
-
|
|
448
|
+
(
|
|
449
|
+
cell sendRequestQueue,
|
|
450
|
+
int zroBalance,
|
|
451
|
+
cell $sendPath,
|
|
452
|
+
int outboundNonce
|
|
453
|
+
) = $storage.Channel::getSendCallbackInformation();
|
|
396
454
|
|
|
397
455
|
;; Read the requestId from the sendRequestQueue to ensure this send request is genuine
|
|
398
456
|
;; and is not being double-executed
|
|
@@ -403,8 +461,7 @@ tuple msglibSendCallback(cell $mdAddress) impure inline method_id {
|
|
|
403
461
|
|
|
404
462
|
if (exists) {
|
|
405
463
|
if (_readSendRequestQueueEntry(contents) == $lzSend.cl::hash()) {
|
|
406
|
-
$storage = $storage.
|
|
407
|
-
Channel::sendRequestQueue,
|
|
464
|
+
$storage = $storage.Channel::setSendRequestQueue(
|
|
408
465
|
DeterministicInsertionCircularQueue::delete(sendRequestQueue, requestId)
|
|
409
466
|
);
|
|
410
467
|
} else {
|
|
@@ -425,36 +482,29 @@ tuple msglibSendCallback(cell $mdAddress) impure inline method_id {
|
|
|
425
482
|
}
|
|
426
483
|
|
|
427
484
|
;; verify that cumulative fees quoted by the msglib <= the fee cap specified by the user/app
|
|
428
|
-
|
|
429
|
-
int nativeQuote = $mdMsglibSendCallback.cl::get<coins>(md::MsglibSendCallback::nativeFee);
|
|
430
|
-
|
|
431
|
-
if ($lzSend.cl::get<coins>(md::LzSend::nativeFee) < nativeQuote) {
|
|
485
|
+
if (lzSendNativeFee < nativeQuote) {
|
|
432
486
|
errorCode = Channel::ERROR::notEnoughNative;
|
|
433
487
|
}
|
|
434
|
-
if (
|
|
488
|
+
if (lzSendZroFee < zroQuote) {
|
|
435
489
|
errorCode = Channel::ERROR::notEnoughZroToken;
|
|
436
490
|
}
|
|
437
491
|
|
|
438
492
|
;; Verify that the ZRO token credits in the Channel is sufficient to cover the
|
|
439
493
|
;; quoted ZRO cost of the message.
|
|
440
|
-
int zroBalance = $storage.cl::get<coins>(Channel::zroBalance);
|
|
441
494
|
if (zroBalance < zroQuote) {
|
|
442
495
|
errorCode = Channel::ERROR::notEnoughZroTokenBalance;
|
|
443
496
|
}
|
|
444
497
|
|
|
445
|
-
cell $sendPath = $storage.cl::get<objRef>(Channel::path);
|
|
446
|
-
|
|
447
|
-
int packetNonce = 0;
|
|
448
498
|
int packetGuid = 0;
|
|
499
|
+
int packetNonce = 0;
|
|
500
|
+
|
|
449
501
|
if (errorCode == Channel::NO_ERROR) {
|
|
450
502
|
;; Assign a nonce to the packet and calculate the resulting GUID
|
|
451
|
-
packetNonce =
|
|
503
|
+
packetNonce = outboundNonce + 1;
|
|
452
504
|
packetGuid = lz::Packet::calculateGuid($sendPath, packetNonce);
|
|
453
505
|
|
|
454
506
|
;; native payments
|
|
455
|
-
tuple payees = deserializePayees(
|
|
456
|
-
$mdMsglibSendCallback.cl::get<cellRef>(md::MsglibSendCallback::payees)
|
|
457
|
-
);
|
|
507
|
+
tuple payees = deserializePayees(serializedPayees);
|
|
458
508
|
|
|
459
509
|
;; If the TON message does not contain sufficient value to perform the payments,
|
|
460
510
|
;; the transaction will revert and the send channel will eventually get blocked.
|
|
@@ -466,20 +516,7 @@ tuple msglibSendCallback(cell $mdAddress) impure inline method_id {
|
|
|
466
516
|
}
|
|
467
517
|
|
|
468
518
|
;; Due to asynchrony between the Msglib and the Channel, the nonce and guid
|
|
469
|
-
;; cannot be
|
|
470
|
-
cell encodedPacket = $mdMsglibSendCallback
|
|
471
|
-
.cl::get<cellRef>(md::MsglibSendCallback::packetEncoded);
|
|
472
|
-
|
|
473
|
-
int nonceByteOffset = $mdMsglibSendCallback
|
|
474
|
-
.cl::get<uint16>(md::MsglibSendCallback::nonceByteOffset);
|
|
475
|
-
|
|
476
|
-
int nonceBytes = $mdMsglibSendCallback
|
|
477
|
-
.cl::get<uint8>(md::MsglibSendCallback::nonceBytes);
|
|
478
|
-
|
|
479
|
-
int guidByteOffset = $mdMsglibSendCallback
|
|
480
|
-
.cl::get<uint16>(md::MsglibSendCallback::guidByteOffset);
|
|
481
|
-
|
|
482
|
-
int guidBytes = $mdMsglibSendCallback.cl::get<uint8>(md::MsglibSendCallback::guidBytes);
|
|
519
|
+
;; cannot be ... ?
|
|
483
520
|
|
|
484
521
|
cell completedEncodedPacket = null();
|
|
485
522
|
|
|
@@ -507,21 +544,22 @@ tuple msglibSendCallback(cell $mdAddress) impure inline method_id {
|
|
|
507
544
|
|
|
508
545
|
actions~pushAction<event>(
|
|
509
546
|
Channel::event::PACKET_SENT,
|
|
510
|
-
md::PacketSent::
|
|
547
|
+
md::PacketSent::build(
|
|
511
548
|
nativeQuote,
|
|
512
549
|
zroQuote,
|
|
513
|
-
$
|
|
514
|
-
$
|
|
550
|
+
$extraOptions,
|
|
551
|
+
$enforceOptions,
|
|
515
552
|
completedEncodedPacket,
|
|
516
553
|
packetNonce,
|
|
517
|
-
$
|
|
518
|
-
$
|
|
554
|
+
$lzSend.md::LzSend::getSendMsglibManager(),
|
|
555
|
+
$sendEvents
|
|
519
556
|
)
|
|
520
557
|
);
|
|
521
558
|
|
|
522
|
-
$storage = $storage
|
|
523
|
-
|
|
524
|
-
|
|
559
|
+
$storage = $storage.Channel::setOutboundNonceAndZroBalance(
|
|
560
|
+
packetNonce,
|
|
561
|
+
zroBalance - zroQuote
|
|
562
|
+
);
|
|
525
563
|
}
|
|
526
564
|
|
|
527
565
|
;; If the quote was unsuccessful, delete the hash from storage to prevent hol blocking
|
|
@@ -529,17 +567,11 @@ tuple msglibSendCallback(cell $mdAddress) impure inline method_id {
|
|
|
529
567
|
setContractStorage($storage);
|
|
530
568
|
|
|
531
569
|
actions~pushAction<call>(
|
|
532
|
-
$sendPath.
|
|
570
|
+
$sendPath.lz::Path::getSrcOApp(),
|
|
533
571
|
Layerzero::OP::CHANNEL_SEND_CALLBACK,
|
|
534
|
-
md::MdObj::
|
|
535
|
-
md::MessagingReceipt::
|
|
536
|
-
$lzSend.
|
|
537
|
-
md::LzSend::packet,
|
|
538
|
-
$lzSend
|
|
539
|
-
.cl::get<objRef>(md::LzSend::packet)
|
|
540
|
-
.cl::set(lz::Packet::nonce, packetNonce)
|
|
541
|
-
.cl::set(lz::Packet::guid, packetGuid)
|
|
542
|
-
),
|
|
572
|
+
md::MdObj::build(
|
|
573
|
+
md::MessagingReceipt::build(
|
|
574
|
+
$lzSend.md::LzSend::setPacketNonceAndGuid(packetNonce, packetGuid),
|
|
543
575
|
nativeQuote,
|
|
544
576
|
zroQuote,
|
|
545
577
|
errorCode
|
|
@@ -561,33 +593,38 @@ tuple msglibSendCallback(cell $mdAddress) impure inline method_id {
|
|
|
561
593
|
tuple channelCommitPacket(cell $mdExtended) impure inline method_id {
|
|
562
594
|
(cell $storage, tuple actions) = preamble();
|
|
563
595
|
|
|
564
|
-
cell $
|
|
596
|
+
cell $sanitizeMdExtended = $mdExtended.md::ExtendedMd::sanitize();
|
|
597
|
+
|
|
598
|
+
(
|
|
599
|
+
cell $packet,
|
|
600
|
+
int callerMsglibConnectionAddress
|
|
601
|
+
) = $sanitizeMdExtended.md::ExtendedMd::getMdAndForwardingAddress();
|
|
565
602
|
;; assert the size of the incoming packet
|
|
566
603
|
lz::Packet::assertValidReceiveMessage($packet);
|
|
567
604
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
605
|
+
(
|
|
606
|
+
cell $epConfigOApp,
|
|
607
|
+
cell $commitPOOO,
|
|
608
|
+
cell $executePOOO,
|
|
609
|
+
cell executionQueue
|
|
610
|
+
) = $storage.Channel::getCommitPacketInformation();
|
|
572
611
|
|
|
573
|
-
|
|
612
|
+
(
|
|
613
|
+
int useDefaults,
|
|
614
|
+
int receiveMsglibConnection
|
|
615
|
+
) = $epConfigOApp.lz::EpConfig::deserializeReceiveConfig();
|
|
574
616
|
|
|
575
617
|
if (useDefaults) {
|
|
576
|
-
cell $defaultConfig = $
|
|
577
|
-
receiveMsglibConnection = $defaultConfig
|
|
578
|
-
.cl::get<address>(lz::ReceiveEpConfig::receiveMsglibConnectionAddress);
|
|
618
|
+
cell $defaultConfig = $sanitizeMdExtended.md::ExtendedMd::getObj();
|
|
619
|
+
receiveMsglibConnection = $defaultConfig.lz::ReceiveEpConfig::getReceiveMsglibConnection();
|
|
579
620
|
}
|
|
580
621
|
|
|
581
|
-
int callerMsglibConnectionAddress = $mdExtended
|
|
582
|
-
.cl::get<address>(md::ExtendedMd::forwardingAddress);
|
|
583
|
-
|
|
584
622
|
if (receiveMsglibConnection != callerMsglibConnectionAddress) {
|
|
585
623
|
;; grossly inefficient, but this will (almost) never happen
|
|
586
624
|
;; so we can optimize the happy path by isolating this logic into this block
|
|
587
|
-
cell $defaultConfig = $
|
|
625
|
+
cell $defaultConfig = $sanitizeMdExtended.cl::get<objRef>(md::MdObj::obj);
|
|
588
626
|
int timeoutReceiveMsglibConnection = useDefaults
|
|
589
|
-
? $defaultConfig
|
|
590
|
-
.cl::get<address>(lz::ReceiveEpConfig::timeoutReceiveMsglibConnectionAddress)
|
|
627
|
+
? $defaultConfig.cl::get<address>(lz::ReceiveEpConfig::timeoutReceiveMsglibConnection)
|
|
591
628
|
: $epConfigOApp.cl::get<address>(lz::EpConfig::timeoutReceiveMsglibConnection);
|
|
592
629
|
|
|
593
630
|
int expiry = useDefaults
|
|
@@ -599,21 +636,21 @@ tuple channelCommitPacket(cell $mdExtended) impure inline method_id {
|
|
|
599
636
|
}
|
|
600
637
|
}
|
|
601
638
|
|
|
602
|
-
int incomingNonce = $packet.
|
|
603
|
-
cell $commitPOOO = $storage.cl::get<objRef>(Channel::commitPOOO);
|
|
639
|
+
int incomingNonce = $packet.lz::Packet::getNonce();
|
|
604
640
|
|
|
605
|
-
(
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
641
|
+
int isCommittable = _optimizedNonceCommittable(
|
|
642
|
+
$executePOOO,
|
|
643
|
+
executionQueue,
|
|
644
|
+
incomingNonce
|
|
645
|
+
);
|
|
609
646
|
|
|
610
647
|
if (isCommittable) {
|
|
611
648
|
setContractStorage(
|
|
612
649
|
$storage
|
|
613
|
-
.
|
|
614
|
-
|
|
650
|
+
.Channel::setCommitPOOOAndExecutionQueue(
|
|
651
|
+
POOO::set($commitPOOO, incomingNonce),
|
|
615
652
|
DeterministicInsertionCircularQueue::set(
|
|
616
|
-
|
|
653
|
+
executionQueue,
|
|
617
654
|
incomingNonce,
|
|
618
655
|
$packet,
|
|
619
656
|
ExecutionQueue::committed
|
|
@@ -623,7 +660,7 @@ tuple channelCommitPacket(cell $mdExtended) impure inline method_id {
|
|
|
623
660
|
actions~pushAction<event>(Channel::event::PACKET_COMMITTED, $packet);
|
|
624
661
|
}
|
|
625
662
|
|
|
626
|
-
if (incomingNonce <= POOO::maxSettableBit($
|
|
663
|
+
if (incomingNonce <= POOO::maxSettableBit($executePOOO)) {
|
|
627
664
|
;; Cannot respond back to msglib if the packet is not currently committable but
|
|
628
665
|
;; will be committable in the future
|
|
629
666
|
;; Caveat: if the packet is currently executing, we treat it as uncommittable.
|
|
@@ -636,12 +673,11 @@ tuple channelCommitPacket(cell $mdExtended) impure inline method_id {
|
|
|
636
673
|
MsglibConnection::OP::MSGLIB_CONNECTION_COMMIT_PACKET_CALLBACK,
|
|
637
674
|
md::ChannelNonceInfo::New(
|
|
638
675
|
incomingNonce,
|
|
639
|
-
$storage.
|
|
676
|
+
$storage.Channel::getExecutePOOO().POOO::getNextEmpty()
|
|
640
677
|
)
|
|
641
678
|
);
|
|
642
679
|
}
|
|
643
680
|
|
|
644
|
-
|
|
645
681
|
return actions;
|
|
646
682
|
}
|
|
647
683
|
|
|
@@ -656,12 +692,12 @@ tuple channelCommitPacket(cell $mdExtended) impure inline method_id {
|
|
|
656
692
|
;; @permissions: permissonless
|
|
657
693
|
tuple lzReceivePrepare(cell $lzReceivePrepareMd) impure inline method_id {
|
|
658
694
|
(cell $storage, tuple actions) = preamble();
|
|
659
|
-
|
|
660
|
-
int nanotons = $lzReceivePrepareMd.
|
|
695
|
+
|
|
696
|
+
(int nonce, int nanotons) = $lzReceivePrepareMd.md::LzReceivePrepare::deserialize();
|
|
661
697
|
|
|
662
698
|
;; extract oApp from path
|
|
663
699
|
actions~pushAction<dispatch>(
|
|
664
|
-
$storage.
|
|
700
|
+
$storage.Channel::getPath().lz::Path::getSrcOApp(),
|
|
665
701
|
Layerzero::OP::LZ_RECEIVE_PREPARE,
|
|
666
702
|
;; Throws if the Packet is not executable
|
|
667
703
|
_getExecutablePacket(nonce),
|
|
@@ -681,19 +717,21 @@ tuple lzReceivePrepare(cell $lzReceivePrepareMd) impure inline method_id {
|
|
|
681
717
|
tuple lzReceiveLock(cell $nonceMd) impure inline method_id {
|
|
682
718
|
(cell $storage, tuple actions) = preamble();
|
|
683
719
|
|
|
684
|
-
int incomingNonce = $nonceMd.
|
|
685
|
-
|
|
720
|
+
int incomingNonce = $nonceMd.md::Nonce::getNonce();
|
|
686
721
|
throw_if(Channel::ERROR::invalidNonce, incomingNonce <= 0);
|
|
687
|
-
|
|
722
|
+
|
|
723
|
+
(
|
|
724
|
+
cell executionQueue,
|
|
725
|
+
cell $commitPOOO,
|
|
726
|
+
cell $path
|
|
727
|
+
) = $storage.Channel::getLzReceiveLockInformation();
|
|
688
728
|
|
|
689
729
|
(int actualKey, cell $packet, int status, _) = DeterministicInsertionCircularQueue::get(
|
|
690
730
|
executionQueue,
|
|
691
731
|
incomingNonce
|
|
692
732
|
);
|
|
693
733
|
|
|
694
|
-
int firstUncommittedNonce =
|
|
695
|
-
.cl::get<objRef>(Channel::commitPOOO)
|
|
696
|
-
.cl::get<uint64>(POOO::nextEmpty);
|
|
734
|
+
int firstUncommittedNonce = $commitPOOO.POOO::getNextEmpty();
|
|
697
735
|
|
|
698
736
|
;; executable if present and all preceding nonces are committed, executing, or executed
|
|
699
737
|
if (
|
|
@@ -703,8 +741,7 @@ tuple lzReceiveLock(cell $nonceMd) impure inline method_id {
|
|
|
703
741
|
) {
|
|
704
742
|
;; set state to executing
|
|
705
743
|
setContractStorage(
|
|
706
|
-
$storage.
|
|
707
|
-
Channel::executionQueue,
|
|
744
|
+
$storage.Channel::setExecutionQueue(
|
|
708
745
|
DeterministicInsertionCircularQueue::set(
|
|
709
746
|
executionQueue,
|
|
710
747
|
incomingNonce,
|
|
@@ -715,14 +752,14 @@ tuple lzReceiveLock(cell $nonceMd) impure inline method_id {
|
|
|
715
752
|
);
|
|
716
753
|
|
|
717
754
|
actions~pushAction<call>(
|
|
718
|
-
$
|
|
755
|
+
$path.lz::Path::getSrcOApp(),
|
|
719
756
|
Layerzero::OP::LZ_RECEIVE_EXECUTE,
|
|
720
|
-
md::MdObj::
|
|
757
|
+
md::MdObj::build($packet, getInitialStorage())
|
|
721
758
|
);
|
|
722
759
|
} else {
|
|
723
760
|
actions~pushAction<event>(
|
|
724
761
|
Channel::event::NOT_EXECUTABLE,
|
|
725
|
-
md::PacketId::New($storage.
|
|
762
|
+
md::PacketId::New($storage.Channel::getPath(), incomingNonce)
|
|
726
763
|
);
|
|
727
764
|
}
|
|
728
765
|
|
|
@@ -741,8 +778,10 @@ tuple lzReceiveLock(cell $nonceMd) impure inline method_id {
|
|
|
741
778
|
tuple lzReceiveExecuteCallback(cell $lzReceiveStatus) impure inline method_id {
|
|
742
779
|
(cell $storage, tuple actions) = preamble();
|
|
743
780
|
|
|
744
|
-
int packetNonce = $lzReceiveStatus
|
|
745
|
-
|
|
781
|
+
(int lzReceiveSuccess, int packetNonce) = $lzReceiveStatus
|
|
782
|
+
.md::LzReceiveStatus::getSuccessAndNonce();
|
|
783
|
+
(cell $executePOOO, cell executionQueue, cell $path) = $storage
|
|
784
|
+
.Channel::getExecutePOOOAndExecutionQueueAndPath();
|
|
746
785
|
|
|
747
786
|
(int actualKey, cell $packet, int status, _) = DeterministicInsertionCircularQueue::get(
|
|
748
787
|
executionQueue,
|
|
@@ -755,18 +794,17 @@ tuple lzReceiveExecuteCallback(cell $lzReceiveStatus) impure inline method_id {
|
|
|
755
794
|
);
|
|
756
795
|
|
|
757
796
|
;; check for success/failure
|
|
758
|
-
if (
|
|
797
|
+
if (lzReceiveSuccess) {
|
|
759
798
|
executionQueue = DeterministicInsertionCircularQueue::delete(executionQueue, packetNonce);
|
|
760
799
|
|
|
761
|
-
$storage = $storage.
|
|
762
|
-
|
|
763
|
-
POOO::set($storage.cl::get<objRef>(Channel::executePOOO), packetNonce)
|
|
800
|
+
$storage = $storage.Channel::setExecutePOOO(
|
|
801
|
+
POOO::set($executePOOO, packetNonce)
|
|
764
802
|
);
|
|
765
803
|
|
|
766
804
|
;; emit Packet in the manager
|
|
767
805
|
actions~pushAction<event>(
|
|
768
806
|
Channel::event::DELIVERED,
|
|
769
|
-
md::PacketId::
|
|
807
|
+
md::PacketId::build($path, packetNonce)
|
|
770
808
|
);
|
|
771
809
|
} else {
|
|
772
810
|
executionQueue = DeterministicInsertionCircularQueue::set(
|
|
@@ -781,18 +819,18 @@ tuple lzReceiveExecuteCallback(cell $lzReceiveStatus) impure inline method_id {
|
|
|
781
819
|
Channel::event::LZ_RECEIVE_ALERT,
|
|
782
820
|
md::LzReceiveStatus::NewFull(
|
|
783
821
|
false,
|
|
784
|
-
packetNonce,
|
|
785
|
-
$lzReceiveStatus.cl::get<coins>(md::LzReceiveStatus::value),
|
|
786
|
-
$lzReceiveStatus.cl::get<cellRef>(md::LzReceiveStatus::extraData),
|
|
787
|
-
$lzReceiveStatus.cl::get<cellRef>(md::LzReceiveStatus::reason),
|
|
788
|
-
getOrigin(),
|
|
789
|
-
$packet,
|
|
822
|
+
packetNonce, ;; unforgeable
|
|
823
|
+
$lzReceiveStatus.cl::get<coins>(md::LzReceiveStatus::value), ;; can be arbitrary/unsafe
|
|
824
|
+
$lzReceiveStatus.cl::get<cellRef>(md::LzReceiveStatus::extraData), ;; can be arbitrary/unsafe
|
|
825
|
+
$lzReceiveStatus.cl::get<cellRef>(md::LzReceiveStatus::reason), ;; can be arbitrary/unsafe
|
|
826
|
+
getOrigin(), ;; unforgeable
|
|
827
|
+
$packet, ;; unforgeable
|
|
790
828
|
ExecutionStatus::executable
|
|
791
829
|
)
|
|
792
830
|
);
|
|
793
831
|
}
|
|
794
832
|
|
|
795
|
-
setContractStorage($storage.
|
|
833
|
+
setContractStorage($storage.Channel::setExecutionQueue(executionQueue));
|
|
796
834
|
|
|
797
835
|
return actions;
|
|
798
836
|
}
|
|
@@ -829,10 +867,13 @@ tuple lzReceiveExecuteCallback(cell $lzReceiveStatus) impure inline method_id {
|
|
|
829
867
|
tuple nilify(cell $packetId) impure inline method_id {
|
|
830
868
|
(cell $storage, tuple actions) = preamble();
|
|
831
869
|
|
|
832
|
-
cell $
|
|
833
|
-
|
|
870
|
+
cell $sanitizedPacketId = $packetId.md::PacketId::sanitize();
|
|
871
|
+
|
|
872
|
+
;; reverse the path because this is from a receive perspective
|
|
873
|
+
cell $receivePath = $storage.Channel::getPath().lz::Path::optimizedReverse();
|
|
874
|
+
_assertEqualPaths($receivePath, $sanitizedPacketId.cl::get<objRef>(md::PacketId::path));
|
|
834
875
|
|
|
835
|
-
int incomingNonce = $
|
|
876
|
+
int incomingNonce = $sanitizedPacketId.cl::get<uint64>(md::PacketId::nonce);
|
|
836
877
|
_assertNonceCommittable(incomingNonce);
|
|
837
878
|
|
|
838
879
|
(_, cell $previousPacket) = _nonceCommittable(incomingNonce);
|
|
@@ -843,7 +884,7 @@ tuple nilify(cell $packetId) impure inline method_id {
|
|
|
843
884
|
getContractStorage().cl::set(
|
|
844
885
|
Channel::executionQueue,
|
|
845
886
|
DeterministicInsertionCircularQueue::delete(
|
|
846
|
-
$storage.
|
|
887
|
+
$storage.Channel::getExecutionQueue(),
|
|
847
888
|
incomingNonce
|
|
848
889
|
)
|
|
849
890
|
)
|
|
@@ -857,7 +898,7 @@ tuple nilify(cell $packetId) impure inline method_id {
|
|
|
857
898
|
actions~pushAction<call>(
|
|
858
899
|
$receivePath.cl::get<address>(lz::Path::dstOApp),
|
|
859
900
|
Layerzero::OP::NILIFY_CALLBACK,
|
|
860
|
-
md::MdObj::
|
|
901
|
+
md::MdObj::build($sanitizedPacketId, getInitialStorage())
|
|
861
902
|
);
|
|
862
903
|
|
|
863
904
|
return actions;
|
|
@@ -866,11 +907,13 @@ tuple nilify(cell $packetId) impure inline method_id {
|
|
|
866
907
|
tuple burn(cell $packetId) impure inline method_id {
|
|
867
908
|
(cell $storage, tuple actions) = preamble();
|
|
868
909
|
|
|
910
|
+
cell $sanitizedPacketId = $packetId.md::PacketId::sanitize();
|
|
911
|
+
|
|
869
912
|
;; reverse the path because this is from a receive perspective
|
|
870
|
-
cell $receivePath = lz::Path::reverse($storage.
|
|
871
|
-
_assertEqualPaths($receivePath, $
|
|
913
|
+
cell $receivePath = lz::Path::reverse($storage.Channel::getPath());
|
|
914
|
+
_assertEqualPaths($receivePath, $sanitizedPacketId.cl::get<objRef>(md::PacketId::path));
|
|
872
915
|
|
|
873
|
-
int nonce = $
|
|
916
|
+
int nonce = $sanitizedPacketId.cl::get<uint64>(md::PacketId::nonce);
|
|
874
917
|
|
|
875
918
|
cell $nonceMd = md::Nonce::New(nonce);
|
|
876
919
|
|
|
@@ -895,11 +938,13 @@ tuple burn(cell $packetId) impure inline method_id {
|
|
|
895
938
|
$previousPacket
|
|
896
939
|
);
|
|
897
940
|
|
|
898
|
-
cell $packetId = md::PacketId::New($receivePath, nonce);
|
|
899
941
|
actions~pushAction<call>(
|
|
900
942
|
$receivePath.cl::get<address>(lz::Path::dstOApp),
|
|
901
943
|
Layerzero::OP::BURN_CALLBACK,
|
|
902
|
-
md::MdObj::
|
|
944
|
+
md::MdObj::build(
|
|
945
|
+
md::PacketId::New($receivePath, nonce),
|
|
946
|
+
getInitialStorage()
|
|
947
|
+
)
|
|
903
948
|
);
|
|
904
949
|
|
|
905
950
|
return actions;
|
|
@@ -911,15 +956,17 @@ tuple burn(cell $packetId) impure inline method_id {
|
|
|
911
956
|
tuple depositZro(cell $coinsAmount) impure inline method_id {
|
|
912
957
|
(cell $storage, tuple actions) = preamble();
|
|
913
958
|
|
|
959
|
+
cell $sanitizedCoinsAmount = $coinsAmount.md::CoinsAmount::sanitize();
|
|
960
|
+
|
|
914
961
|
setContractStorage(
|
|
915
962
|
$storage.cl::set(
|
|
916
963
|
Channel::zroBalance,
|
|
917
|
-
$storage.
|
|
918
|
-
+ $
|
|
964
|
+
$storage.Channel::getZroBalance()
|
|
965
|
+
+ $sanitizedCoinsAmount.cl::get<coins>(md::CoinsAmount::amount)
|
|
919
966
|
)
|
|
920
967
|
);
|
|
921
968
|
|
|
922
|
-
actions~pushAction<event>(Channel::event::ZRO_DEPOSITED, $
|
|
969
|
+
actions~pushAction<event>(Channel::event::ZRO_DEPOSITED, $sanitizedCoinsAmount);
|
|
923
970
|
|
|
924
971
|
return actions;
|
|
925
972
|
}
|
|
@@ -936,6 +983,8 @@ tuple forceAbort(cell $lzSend) impure inline method_id {
|
|
|
936
983
|
(cell $storage, tuple actions) = preamble();
|
|
937
984
|
|
|
938
985
|
cell $path = $storage.cl::get<objRef>(Channel::path);
|
|
986
|
+
;; $lzSend does not need to be sanitized, as it must be correct to match
|
|
987
|
+
;; the stored hash
|
|
939
988
|
_assertEqualPaths(
|
|
940
989
|
$path,
|
|
941
990
|
$lzSend
|
|
@@ -981,8 +1030,10 @@ tuple forceAbort(cell $lzSend) impure inline method_id {
|
|
|
981
1030
|
tuple syncMsglibConnection(cell $mdAddress) impure inline method_id {
|
|
982
1031
|
(cell $storage, tuple actions) = preamble();
|
|
983
1032
|
|
|
1033
|
+
cell $sanitizedMdAddress = $mdAddress.md::MdAddress::sanitize();
|
|
1034
|
+
|
|
984
1035
|
actions~pushAction<call>(
|
|
985
|
-
$
|
|
1036
|
+
$sanitizedMdAddress.cl::get<address>(md::MdAddress::address), ;; msglibConnectionAddress
|
|
986
1037
|
MsglibConnection::OP::MSGLIB_CONNECTION_SYNC_CHANNEL_STATE,
|
|
987
1038
|
md::MdObj::New(
|
|
988
1039
|
md::ChannelNonceInfo::New(
|
|
@@ -1003,32 +1054,39 @@ tuple syncMsglibConnection(cell $mdAddress) impure inline method_id {
|
|
|
1003
1054
|
tuple notifyPacketExecuted(cell $mdAddress) impure inline method_id {
|
|
1004
1055
|
(cell $storage, tuple actions) = preamble();
|
|
1005
1056
|
|
|
1006
|
-
cell $
|
|
1057
|
+
cell $sanitizedMdAddress = $mdAddress.md::MdAddress::sanitize();
|
|
1058
|
+
cell $sanitizedNonceMd = $sanitizedMdAddress
|
|
1059
|
+
.cl::get<objRef>(md::MdAddress::md)
|
|
1060
|
+
.md::Nonce::sanitize();
|
|
1007
1061
|
|
|
1008
|
-
int executionStatus = _viewExecutionStatus($
|
|
1062
|
+
int executionStatus = _viewExecutionStatus($sanitizedNonceMd.cl::get<uint64>(md::Nonce::nonce));
|
|
1009
1063
|
|
|
1010
1064
|
if (executionStatus != ExecutionStatus::executed) {
|
|
1011
1065
|
return actions;
|
|
1012
1066
|
}
|
|
1013
1067
|
|
|
1014
1068
|
actions~pushAction<call>(
|
|
1015
|
-
$
|
|
1069
|
+
$sanitizedMdAddress.cl::get<address>(md::MdAddress::address),
|
|
1016
1070
|
MsglibConnection::OP::MSGLIB_CONNECTION_COMMIT_PACKET_CALLBACK,
|
|
1017
1071
|
md::ChannelNonceInfo::New(
|
|
1018
|
-
$
|
|
1072
|
+
$sanitizedNonceMd.cl::get<uint64>(md::Nonce::nonce),
|
|
1019
1073
|
$storage.cl::get<objRef>(Channel::executePOOO).cl::get<uint64>(POOO::nextEmpty)
|
|
1020
1074
|
)
|
|
1021
1075
|
);
|
|
1076
|
+
|
|
1022
1077
|
return actions;
|
|
1023
1078
|
}
|
|
1024
1079
|
|
|
1025
1080
|
tuple emitLzReceiveAlert(cell $lzReceiveStatus) impure inline method_id {
|
|
1026
1081
|
(cell $storage, tuple actions) = preamble();
|
|
1027
|
-
|
|
1082
|
+
|
|
1083
|
+
cell $saniztizedLzReceiveStatus = $lzReceiveStatus.md::LzReceiveStatus::NewFull::sanitize();
|
|
1084
|
+
|
|
1085
|
+
int nonce = $saniztizedLzReceiveStatus.cl::get<uint64>(md::LzReceiveStatus::nonce);
|
|
1028
1086
|
throw_if(Channel::ERROR::invalidNonce, nonce == 0);
|
|
1029
|
-
|
|
1087
|
+
|
|
1030
1088
|
(int actualNonce, cell $packet, _, int exists) = DeterministicInsertionCircularQueue::get(
|
|
1031
|
-
$storage.
|
|
1089
|
+
$storage.Channel::getExecutionQueue(),
|
|
1032
1090
|
nonce
|
|
1033
1091
|
);
|
|
1034
1092
|
|
|
@@ -1040,14 +1098,14 @@ tuple emitLzReceiveAlert(cell $lzReceiveStatus) impure inline method_id {
|
|
|
1040
1098
|
actions~pushAction<event>(
|
|
1041
1099
|
Channel::event::LZ_RECEIVE_ALERT,
|
|
1042
1100
|
md::LzReceiveStatus::NewFull(
|
|
1043
|
-
$
|
|
1101
|
+
$saniztizedLzReceiveStatus.cl::get<bool>(md::LzReceiveStatus::success),
|
|
1044
1102
|
nonce,
|
|
1045
|
-
$
|
|
1046
|
-
$
|
|
1047
|
-
$
|
|
1103
|
+
$saniztizedLzReceiveStatus.cl::get<coins>(md::LzReceiveStatus::value),
|
|
1104
|
+
$saniztizedLzReceiveStatus.cl::get<cellRef>(md::LzReceiveStatus::extraData),
|
|
1105
|
+
$saniztizedLzReceiveStatus.cl::get<cellRef>(md::LzReceiveStatus::reason),
|
|
1048
1106
|
getCaller(),
|
|
1049
1107
|
$packet,
|
|
1050
|
-
|
|
1108
|
+
_viewExecutionStatus(nonce)
|
|
1051
1109
|
)
|
|
1052
1110
|
);
|
|
1053
1111
|
return actions;
|