@layerzerolabs/layerzero-v2-ton 3.0.27 → 3.0.29

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 (200) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/ActionsSerde.test.compiled.json +1 -0
  3. package/build/AllStorages.compiled.json +1 -1
  4. package/build/AllStorages.test.compiled.json +1 -1
  5. package/build/BaseContract.test.compiled.json +1 -1
  6. package/build/Channel.compiled.json +1 -1
  7. package/build/Channel.permissions.test.compiled.json +1 -1
  8. package/build/ChannelBurn.test.compiled.json +1 -1
  9. package/build/ChannelCommitPacket.test.compiled.json +1 -1
  10. package/build/ChannelConfig.test.compiled.json +1 -1
  11. package/build/ChannelInitialize.test.compiled.json +1 -1
  12. package/build/ChannelMsglibIntegration.test.compiled.json +1 -1
  13. package/build/ChannelMsglibSendCallback.test.compiled.json +1 -1
  14. package/build/ChannelNilify.test.compiled.json +1 -1
  15. package/build/ChannelReceive.test.compiled.json +1 -1
  16. package/build/ChannelReceiveCallback.test.compiled.json +1 -1
  17. package/build/ChannelReceiveView.test.compiled.json +1 -1
  18. package/build/ChannelSend.test.compiled.json +1 -1
  19. package/build/ChannelSerde.test.compiled.json +1 -0
  20. package/build/Classlib.test.compiled.json +1 -1
  21. package/build/ComputeDataSizeGas.test.compiled.json +1 -1
  22. package/build/Connection.compiled.json +1 -1
  23. package/build/Controller.assertions.test.compiled.json +1 -1
  24. package/build/Controller.compiled.json +1 -1
  25. package/build/Controller.permissions.test.compiled.json +1 -1
  26. package/build/Controller.test.compiled.json +1 -1
  27. package/build/Counter.compiled.json +1 -1
  28. package/build/Counter.permissions.test.compiled.json +1 -1
  29. package/build/Counter.setters.test.compiled.json +1 -1
  30. package/build/Counter.test.compiled.json +1 -1
  31. package/build/Dvn.compiled.json +1 -1
  32. package/build/Dvn.test.compiled.json +1 -1
  33. package/build/DvnFeeLib.compiled.json +1 -1
  34. package/build/DvnFeeLibSerde.test.compiled.json +1 -0
  35. package/build/DvnPermissions.test.compiled.json +1 -1
  36. package/build/DvnSerde.test.compiled.json +1 -0
  37. package/build/Endpoint.compiled.json +1 -1
  38. package/build/Endpoint.permissions.test.compiled.json +1 -1
  39. package/build/Endpoint.test.compiled.json +1 -1
  40. package/build/EndpointSerde.test.compiled.json +1 -0
  41. package/build/EndpointSetEpConfigDefaults.test.compiled.json +1 -1
  42. package/build/Executor.compiled.json +1 -1
  43. package/build/Executor.test.compiled.json +1 -1
  44. package/build/ExecutorFeeLib.compiled.json +1 -1
  45. package/build/ExecutorFeeLibSerde.test.compiled.json +1 -0
  46. package/build/ExecutorPermissions.test.compiled.json +1 -1
  47. package/build/ExecutorSerde.test.compiled.json +1 -0
  48. package/build/LzClasses.test.compiled.json +1 -1
  49. package/build/LzClassesSerde.test.compiled.json +1 -0
  50. package/build/LzUtil.test.compiled.json +1 -1
  51. package/build/MsgData.test.compiled.json +1 -1
  52. package/build/MsgDataSerde.test.compiled.json +1 -0
  53. package/build/MsglibPacketCodec.test.compiled.json +1 -1
  54. package/build/PipelinedOutOfOrder.test.compiled.json +1 -1
  55. package/build/PipelinedOutOfOrderSerde.test.compiled.json +1 -0
  56. package/build/PriceFeedCache.compiled.json +1 -1
  57. package/build/PriceFeedCache.test.compiled.json +1 -1
  58. package/build/PriceFeedCache.test.permissions.compiled.json +1 -1
  59. package/build/PriceFeedCacheSerde.test.compiled.json +1 -0
  60. package/build/PriceFeedFeeLibSerde.test.compiled.json +1 -0
  61. package/build/Proxy.compiled.json +1 -1
  62. package/build/Proxy.permissions.test.compiled.json +1 -1
  63. package/build/Proxy.test.compiled.json +1 -1
  64. package/build/SmlConnection.compiled.json +1 -1
  65. package/build/SmlConnection.permissions.test.compiled.json +1 -1
  66. package/build/SmlConnection.test.compiled.json +1 -1
  67. package/build/SmlManager.compiled.json +1 -1
  68. package/build/SmlManager.permissions.test.compiled.json +1 -1
  69. package/build/SmlManager.test.compiled.json +1 -1
  70. package/build/Uln.compiled.json +1 -1
  71. package/build/Uln.test.compiled.json +1 -1
  72. package/build/UlnConnection.compiled.json +1 -1
  73. package/build/UlnConnection.test.compiled.json +1 -1
  74. package/build/UlnConnectionPermissions.test.compiled.json +1 -1
  75. package/build/UlnConnectionSerde.test.compiled.json +1 -0
  76. package/build/UlnManagement.test.compiled.json +1 -1
  77. package/build/UlnManager.compiled.json +1 -1
  78. package/build/UlnManager.test.compiled.json +1 -1
  79. package/build/UlnManagerPermissions.test.compiled.json +1 -1
  80. package/build/UlnManagerUtil.test.compiled.json +1 -1
  81. package/build/UlnMsgDataSerde.test.compiled.json +1 -0
  82. package/build/UlnPermissions.test.compiled.json +1 -1
  83. package/build/UlnReceiveConfig.test.compiled.json +1 -1
  84. package/build/UlnSend.test.compiled.json +1 -1
  85. package/build/UlnSendConfig.test.compiled.json +1 -1
  86. package/build/UlnSendWithDvnFeeLib.test.compiled.json +1 -1
  87. package/build/UlnSendWithExecFeeLib.test.compiled.json +1 -1
  88. package/build/UlnSendWorkerFactory.test.compiled.json +1 -1
  89. package/build/UlnSerde.test.compiled.json +1 -0
  90. package/build/UlnUtil.test.compiled.json +1 -1
  91. package/build/WorkerCore.test.compiled.json +1 -1
  92. package/build/WorkerCoreMsgDataSerde.test.compiled.json +1 -0
  93. package/build/WorkerCoreSerde.test.compiled.json +1 -0
  94. package/build/badFeeLib1.test.compiled.json +1 -1
  95. package/build/badFeeLib10.test.compiled.json +1 -1
  96. package/build/badFeeLib11.test.compiled.json +1 -1
  97. package/build/badFeeLib12.test.compiled.json +1 -1
  98. package/build/badFeeLib2.test.compiled.json +1 -1
  99. package/build/badFeeLib3.test.compiled.json +1 -1
  100. package/build/badFeeLib4.test.compiled.json +1 -1
  101. package/build/badFeeLib5.test.compiled.json +1 -1
  102. package/build/badFeeLib6.test.compiled.json +1 -1
  103. package/build/badFeeLib7.test.compiled.json +1 -1
  104. package/build/badFeeLib8.test.compiled.json +1 -1
  105. package/build/badFeeLib9.test.compiled.json +1 -1
  106. package/package.json +2 -1
  107. package/src/classes/lz/EpConfig.fc +90 -23
  108. package/src/classes/lz/MsglibInfo.fc +32 -5
  109. package/src/classes/lz/Packet.fc +109 -48
  110. package/src/classes/lz/Path.fc +55 -4
  111. package/src/classes/lz/ReceiveEpConfig.fc +36 -5
  112. package/src/classes/lz/SendEpConfig.fc +55 -5
  113. package/src/classes/msgdata/AddMsglib.fc +11 -0
  114. package/src/classes/msgdata/ChannelNonceInfo.fc +20 -0
  115. package/src/classes/msgdata/CoinsAmount.fc +8 -0
  116. package/src/classes/msgdata/Deploy.fc +19 -0
  117. package/src/classes/msgdata/ExtendedMd.fc +52 -1
  118. package/src/classes/msgdata/LzReceivePrepare.fc +21 -1
  119. package/src/classes/msgdata/LzReceiveStatus.fc +72 -1
  120. package/src/classes/msgdata/LzSend.fc +143 -24
  121. package/src/classes/msgdata/MdAddress.fc +42 -0
  122. package/src/classes/msgdata/MdEid.fc +8 -0
  123. package/src/classes/msgdata/MdObj.fc +32 -0
  124. package/src/classes/msgdata/MessagingReceipt.fc +34 -1
  125. package/src/classes/msgdata/MsglibSendCallback.fc +82 -0
  126. package/src/classes/msgdata/Nonce.fc +30 -0
  127. package/src/classes/msgdata/OptionsV1.fc +21 -1
  128. package/src/classes/msgdata/OptionsV2.fc +27 -0
  129. package/src/classes/msgdata/PacketId.fc +24 -0
  130. package/src/classes/msgdata/PacketSent.fc +35 -1
  131. package/src/classes/msgdata/SetAddress.fc +7 -0
  132. package/src/classes/msgdata/SetEpConfig.fc +17 -0
  133. package/src/funC++/actions/event.fc +17 -2
  134. package/src/funC++/actions/utils.fc +2 -2
  135. package/src/funC++/classlib.fc +33 -43
  136. package/src/funC++/constants.fc +28 -28
  137. package/src/funC++/dataStructures/PipelinedOutOfOrder.fc +75 -59
  138. package/src/funC++/stdlib.fc +26 -11
  139. package/src/funC++/testutils.fc +2 -2
  140. package/src/funC++/txnContext.fc +14 -14
  141. package/src/funC++/utils.fc +97 -1
  142. package/src/protocol/channel/handler.fc +247 -189
  143. package/src/protocol/channel/storage.fc +206 -1
  144. package/src/protocol/controller/handler.fc +35 -17
  145. package/src/protocol/controller/main.fc +1 -1
  146. package/src/protocol/core/abstract/protocolHandler.fc +11 -21
  147. package/src/protocol/core/baseStorage.fc +24 -0
  148. package/src/protocol/endpoint/handler.fc +99 -57
  149. package/src/protocol/endpoint/storage.fc +69 -5
  150. package/src/protocol/msglibs/BytesEncoder.fc +11 -10
  151. package/src/protocol/msglibs/simpleMsglib/smlManager/handler.fc +1 -4
  152. package/src/protocol/msglibs/ultralightnode/feeLibInterface.fc +1 -0
  153. package/src/protocol/msglibs/ultralightnode/msgdata/Attestation.fc +7 -8
  154. package/src/protocol/msglibs/ultralightnode/msgdata/DvnFeesPaidEvent.fc +20 -0
  155. package/src/protocol/msglibs/ultralightnode/msgdata/ExecutorFeePaidEvent.fc +15 -0
  156. package/src/protocol/msglibs/ultralightnode/msgdata/InitUln.fc +1 -1
  157. package/src/protocol/msglibs/ultralightnode/msgdata/InitUlnConnection.fc +1 -1
  158. package/src/protocol/msglibs/ultralightnode/msgdata/SetAdminWorkerAddresses.fc +6 -0
  159. package/src/protocol/msglibs/ultralightnode/msgdata/UlnEvents.fc +20 -0
  160. package/src/protocol/msglibs/ultralightnode/msgdata/UlnReceiveConfig.fc +114 -28
  161. package/src/protocol/msglibs/ultralightnode/msgdata/UlnSend.fc +51 -1
  162. package/src/protocol/msglibs/ultralightnode/msgdata/UlnSendConfig.fc +1 -1
  163. package/src/protocol/msglibs/ultralightnode/msgdata/UlnVerification.fc +10 -0
  164. package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibBytecode.fc +6 -0
  165. package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibInfo.fc +51 -1
  166. package/src/protocol/msglibs/ultralightnode/msgdata/VerificationStatus.fc +15 -0
  167. package/src/protocol/msglibs/ultralightnode/uln/handler.fc +84 -107
  168. package/src/protocol/msglibs/ultralightnode/uln/storage.fc +77 -1
  169. package/src/protocol/msglibs/ultralightnode/ulnConnection/handler.fc +92 -66
  170. package/src/protocol/msglibs/ultralightnode/ulnConnection/storage.fc +113 -6
  171. package/src/protocol/msglibs/ultralightnode/ulnConnection/utils.fc +6 -91
  172. package/src/protocol/msglibs/ultralightnode/ulnManager/handler.fc +55 -31
  173. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/handler.fc +13 -9
  174. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/storage.fc +23 -0
  175. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/handler.fc +63 -27
  176. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/storage.fc +19 -0
  177. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/priceFeedFeeLib/storage.fc +55 -6
  178. package/src/workers/core/abstract/workerHandler.fc +20 -19
  179. package/src/workers/core/interface.fc +2 -1
  180. package/src/workers/core/workerCoreStorage.fc +16 -1
  181. package/src/workers/dvn/handler.fc +67 -26
  182. package/src/workers/dvn/storage.fc +15 -2
  183. package/src/workers/executor/handler.fc +18 -6
  184. package/src/workers/executor/interface.fc +1 -0
  185. package/src/workers/executor/storage.fc +8 -1
  186. package/src/workers/msgdata/DropEvent.fc +18 -0
  187. package/src/workers/msgdata/ExecuteParams.fc +66 -3
  188. package/src/workers/msgdata/NativeDrop.fc +4 -0
  189. package/src/workers/msgdata/SetDict.fc +6 -4
  190. package/src/workers/msgdata/SetQuorum.fc +4 -2
  191. package/src/workers/msgdata/SignedRequest.fc +8 -0
  192. package/src/workers/priceFeedCache/handler.fc +21 -27
  193. package/src/workers/priceFeedCache/storage.fc +16 -1
  194. package/src/workers/proxy/handler.fc +2 -1
  195. package/src/workers/proxy/storage.fc +1 -1
  196. package/tests/baseContractTest.fc +2 -6
  197. package/tests/baseSerdeTest.fc +117 -0
  198. package/tests/testMain.fc +2 -2
  199. package/src/classes/msgdata/Amount.fc +0 -16
  200. package/src/funC++/actions/destroy.fc +0 -27
@@ -6,7 +6,7 @@
6
6
 
7
7
  ;; maximum concurrent sendable inflight send requests
8
8
  ;; must be low to avoid permanent bricking
9
- const Channel::MAX_SEND_SLOTS = MAX_CELL_BITS;
9
+ const int Channel::MAX_SEND_SLOTS = MAX_CELL_BITS;
10
10
 
11
11
  ;; required object name
12
12
  const int Channel::NAME = "channel"u;
@@ -52,4 +52,209 @@ cell Channel::New(int owner, cell $path, int endpointAddress) inline method_id {
52
52
  [cl::t::coins, 0] ;; Channel::zroBalance
53
53
  ])
54
54
  );
55
+ }
56
+
57
+ ;; ====================== Object Accessors =====================
58
+
59
+ const int Channel::_endpointAddressOffset = _HEADER_WIDTH;
60
+ const int Channel::_outboundNonceOffset = Channel::_endpointAddressOffset + 256;
61
+ const int Channel::_sendRequestIdOffset = Channel::_outboundNonceOffset + 64;
62
+ const int Channel::_zroBalanceOffset = Channel::_sendRequestIdOffset + 64;
63
+ const int Channel::_sliceBits = Channel::_zroBalanceOffset + 128;
64
+
65
+ cell Channel::getPath(cell $self) impure inline {
66
+ return $self.cellPreloadRefAt(1);
67
+ }
68
+
69
+ int Channel::getEndpointAddress(cell $self) impure inline {
70
+ return $self.cellPreloadAddressAt(Channel::_endpointAddressOffset);
71
+ }
72
+
73
+ cell Channel::getCommitPOOO(cell $self) impure inline {
74
+ return $self.cellPreloadRefAt(2).cellPreloadRefAt(2);
75
+ }
76
+
77
+ cell Channel::getExecutePOOO(cell $self) impure inline {
78
+ return $self.cellPreloadRefAt(2).cellPreloadRefAt(3);
79
+ }
80
+
81
+ cell Channel::getExecutionQueue(cell $self) impure inline {
82
+ return $self.cellPreloadRefAt(3).cellPreloadRefAt(0);
83
+ }
84
+
85
+ int Channel::getZroBalance(cell $self) impure inline {
86
+ return $self.cellPreloadCoinsAt(Channel::_zroBalanceOffset);
87
+ }
88
+
89
+ ;; (epConfigOApp, commitPOOO, ExecutePOOO, executionQueue)
90
+ (cell, cell, cell, cell) Channel::getCommitPacketInformation(cell $self) impure inline {
91
+ slice selfSlice = $self.begin_parse();
92
+ slice ref2 = selfSlice.preloadRefSliceAt(2);
93
+ return (
94
+ ref2.preloadRefAt(0),
95
+ ref2.preloadRefAt(2),
96
+ ref2.preloadRefAt(3),
97
+ selfSlice.preloadRefAt(3).cellPreloadRefAt(0)
98
+ );
99
+ }
100
+
101
+ ;; (executePOOO, executionQueue, path)
102
+ (cell, cell, cell) Channel::getExecutePOOOAndExecutionQueueAndPath(cell $self) impure inline {
103
+ slice selfSlice = $self.begin_parse();
104
+ return (
105
+ selfSlice.preloadRefAt(2).cellPreloadRefAt(3),
106
+ selfSlice.preloadRefAt(3).cellPreloadRefAt(0),
107
+ selfSlice.preloadRefAt(1)
108
+ );
109
+ }
110
+
111
+ ;; (epConfigOapp, path, sendRequestQueue, lastSendRequestId)
112
+ (cell, cell, cell, int) Channel::getSendInformation(cell $self) impure inline {
113
+ slice selfSlice = $self.begin_parse();
114
+ slice ref2 = selfSlice.preloadRefSliceAt(2);
115
+ return (
116
+ ref2.preloadRefAt(0),
117
+ selfSlice.preloadRefAt(1),
118
+ ref2.preloadRefAt(1),
119
+ selfSlice.preloadUint64At(Channel::_sendRequestIdOffset)
120
+ );
121
+ }
122
+
123
+ ;; (sendRequestQueue, zroBalance, path, outBoundNonce)
124
+ (cell, int, cell, int) Channel::getSendCallbackInformation(cell $self) impure inline {
125
+ slice selfSlice = $self.begin_parse();
126
+ return (
127
+ selfSlice.preloadRefAt(2).cellPreloadRefAt(1), ;; sendRequestQueue
128
+ selfSlice.preloadCoinsAt(Channel::_zroBalanceOffset), ;; zroBalance
129
+ selfSlice.preloadRefAt(1), ;; path
130
+ selfSlice.preloadUint64At(Channel::_outboundNonceOffset) ;; outboundNonce
131
+ );
132
+ }
133
+
134
+ ;; (executionQueue, commitPOOO, path)
135
+ (cell, cell, cell) Channel::getLzReceiveLockInformation(cell $self) impure inline {
136
+ slice selfSlice = $self.begin_parse();
137
+ return (
138
+ selfSlice.preloadRefAt(3).cellPreloadRefAt(0), ;; executionQueue
139
+ selfSlice.preloadRefAt(2).cellPreloadRefAt(2), ;; commitPOOO
140
+ selfSlice.preloadRefAt(1) ;; path
141
+ );
142
+ }
143
+
144
+ ;; ====================== Object Modifiers =====================
145
+
146
+ cell Channel::setSendRequestQueue(cell $self, cell $sendRequestQueue) impure inline {
147
+ slice selfSlice = $self.begin_parse();
148
+
149
+ slice ref2Slice = selfSlice.preloadRefSliceAt(2);
150
+ cell newRef2 = begin_cell()
151
+ .store_slice(ref2Slice.scutfirst(0, 1))
152
+ .store_ref($sendRequestQueue)
153
+ .store_slice(ref2Slice.scutlast(0, 2))
154
+ .end_cell();
155
+
156
+ return begin_cell()
157
+ .store_slice(selfSlice.scutfirst(Channel::_sliceBits, 2)) ;; store all the bits and the first 2 refs [0, 1]
158
+ .store_ref(newRef2) ;; store the new ref[2] which includes the new sendRequestQueue
159
+ .store_slice(selfSlice.scutlast(0, 1)) ;; store the last ref, ref[3]
160
+ .end_cell();
161
+ }
162
+
163
+ cell Channel::setExecutePOOO(cell $self, cell $executePOOO) impure inline {
164
+ slice selfSlice = $self.begin_parse();
165
+
166
+ slice ref2Slice = selfSlice.preloadRefSliceAt(2);
167
+ cell newRef2 = begin_cell()
168
+ .store_slice(ref2Slice.scutfirst(0, 3))
169
+ .store_ref($executePOOO)
170
+ .end_cell();
171
+
172
+ return begin_cell()
173
+ .store_slice(selfSlice.scutfirst(Channel::_sliceBits, 2)) ;; store all the bits and the first 2 refs [0, 1]
174
+ .store_ref(newRef2) ;; store the new ref[2] which includes the new executePOOO
175
+ .store_slice(selfSlice.scutlast(0, 1)) ;; store the last ref, ref[3]
176
+ .end_cell();
177
+ }
178
+
179
+ cell Channel::setExecutionQueue(cell $self, cell $executionQueue) impure inline {
180
+ slice selfSlice = $self.begin_parse();
181
+
182
+ cell newRef3 = begin_cell()
183
+ .store_ref($executionQueue)
184
+ .end_cell();
185
+
186
+ return begin_cell()
187
+ .store_slice(selfSlice.scutfirst(Channel::_sliceBits, 3)) ;; store all the bits and the first 3 refs [0, 1, 2]
188
+ .store_ref(newRef3) ;; store the new ref[3] which includes the new executionQueue
189
+ .end_cell();
190
+ }
191
+
192
+ ;; ====================== Object Composite Modifiers =====================
193
+
194
+ cell Channel::setSendRequestQueueAndLastSendRequestId(cell $self, int lastSendRequestId, cell $sendRequestQueue) impure inline {
195
+ slice selfSlice = $self.begin_parse();
196
+ slice ref2Slice = selfSlice.preloadRefSliceAt(2);
197
+
198
+ cell newRef2 = begin_cell()
199
+ .store_slice(ref2Slice.scutfirst(0, 1))
200
+ .store_ref($sendRequestQueue)
201
+ .store_slice(ref2Slice.scutlast(0, 2))
202
+ .end_cell();
203
+
204
+ return begin_cell()
205
+ .store_slice(selfSlice.scutfirst(Channel::_sendRequestIdOffset, 2)) ;; store all the bits before the lastSendRequestId and the first 2 refs [0, 1]
206
+ .store_uint64(lastSendRequestId) ;; store the new lastSendRequestId = ref[2]
207
+ .store_ref(newRef2) ;; store the new ref[2] which includes the new sendRequestQueue
208
+ .store_slice(selfSlice.sskipfirst(Channel::_sendRequestIdOffset + 64, 3)) ;; store the whatever was after the lastSendRequestId and the last ref, only giving back ref[3]
209
+ .end_cell();
210
+ }
211
+
212
+ cell Channel::setOutboundNonceAndZroBalance(cell $self, int outboundNonce, int zroBalance) impure inline {
213
+ slice selfSlice = $self.begin_parse();
214
+
215
+ return begin_cell()
216
+ .store_slice(
217
+ selfSlice.scutfirst(Channel::_outboundNonceOffset, 4)
218
+ ) ;; store whatever's behind the outbound nonce and all the refs
219
+ .store_uint64(outboundNonce)
220
+ .store_slice(
221
+ selfSlice.subslice(
222
+ Channel::_sendRequestIdOffset, ;; start bits
223
+ 0, ;; start refs
224
+ 64, ;; bits
225
+ 0 ;; refs
226
+ )
227
+ ) ;; store the next 64 bits = sendRequestId
228
+ .store_uint128(zroBalance)
229
+ .end_cell();
230
+ }
231
+
232
+ cell Channel::setCommitPOOOAndExecutionQueue(cell $self, cell $commitPOOO, cell $executionQueue) impure inline {
233
+ slice selfSlice = $self.begin_parse();
234
+
235
+ slice ref2Slice = selfSlice.preloadRefSliceAt(2);
236
+ cell newRef2 = begin_cell()
237
+ .store_slice(ref2Slice.scutfirst(0, 2)) ;; store the first 2 refs [0, 1]
238
+ .store_ref($commitPOOO) ;; store the new commitPOOO = ref[2]
239
+ .store_slice(ref2Slice.scutlast(0, 1)) ;; store the last ref, ref[3]
240
+ .end_cell();
241
+
242
+ cell newRef3 = begin_cell()
243
+ .store_ref($executionQueue) ;; store the new executionQueue = ref[0]
244
+ .end_cell();
245
+
246
+ return begin_cell()
247
+ .store_slice(selfSlice.scutfirst(Channel::_sliceBits, 2)) ;; store all the bits and the first 3 refs [0, 1]
248
+ .store_ref(newRef2) ;; store the new ref[2] which includes the new commitPOOO
249
+ .store_ref(newRef3) ;; store the new ref[3] which includes the new executionQueue
250
+ .end_cell();
251
+ }
252
+
253
+ cell Channel::setPath(cell $self, cell $path) impure inline {
254
+ slice selfSlice = $self.begin_parse();
255
+ return begin_cell()
256
+ .store_ref(selfSlice.preloadRefAt(0))
257
+ .store_ref($path) ;; change ref 1
258
+ .store_slice(sskipfirst(selfSlice, 0, 2)) ;; rest of it stays the same
259
+ .end_cell();
55
260
  }
@@ -28,6 +28,7 @@
28
28
 
29
29
  #include "interface.fc";
30
30
  #include "storage.fc";
31
+ #include "../../classes/msgdata/SetEpConfig.fc";
31
32
 
32
33
  ;;; ================INTERFACE FUNCTIONS=====================
33
34
 
@@ -60,7 +61,7 @@ int _getEventSink() inline {
60
61
  ;; safe for open and public calls
61
62
  return ();
62
63
  } elseif (op == Controller::OP::SET_EP_CONFIG_OAPP) {
63
- cell $path = $md.cl::get<objRef>(md::ExtendedMd::obj);
64
+ cell $path = $md.cl::get<objRef>(md::ExtendedMd::obj).lz::Path::sanitize();
64
65
  throw_unless(
65
66
  Controller::ERROR::onlyOApp,
66
67
  getCaller() == $path.cl::get<address>(lz::Path::srcOApp)
@@ -153,7 +154,8 @@ int _verifyEventSender(int sender, cell $senderStorageInit) impure method_id {
153
154
  tuple deployEndpoint(cell $deploy) impure inline method_id {
154
155
  (cell $storage, tuple actions) = preamble();
155
156
 
156
- int dstEid = $deploy.cl::get<uint32>(md::Deploy::dstEid);
157
+ cell $sanitizedDeploy = $deploy.md::Deploy::sanitize();
158
+ int dstEid = $sanitizedDeploy.cl::get<uint32>(md::Deploy::dstEid);
157
159
  throw_if(Controller::ERROR::invalidEid, dstEid == 0);
158
160
 
159
161
  int eid = $storage.cl::get<uint32>(Controller::eid);
@@ -161,7 +163,7 @@ tuple deployEndpoint(cell $deploy) impure inline method_id {
161
163
  actions~pushAction<deployAndCall>(
162
164
  $storage.cl::get<cellRef>(Controller::endpointCode),
163
165
  Endpoint::New(eid, dstEid, getContractAddress()),
164
- $deploy.cl::get<coins>(md::Deploy::initialDeposit),
166
+ $sanitizedDeploy.cl::get<coins>(md::Deploy::initialDeposit),
165
167
  BaseInterface::OP::INITIALIZE,
166
168
  md::InitEndpoint::New($storage.cl::get<cellRef>(Controller::channelCode)),
167
169
  0
@@ -179,14 +181,15 @@ tuple deployEndpoint(cell $deploy) impure inline method_id {
179
181
  tuple deployChannel(cell $deploy) impure inline method_id {
180
182
  (cell $storage, tuple actions) = preamble();
181
183
 
182
- int dstEid = $deploy.cl::get<uint32>(md::Deploy::dstEid);
184
+ cell $sanitizedDeploy = $deploy.md::Deploy::sanitize();
185
+ int dstEid = $sanitizedDeploy.cl::get<uint32>(md::Deploy::dstEid);
183
186
 
184
187
  ;; create the path object
185
188
  cell $path = lz::Path::New(
186
189
  $storage.cl::get<uint32>(Controller::eid), ;; srcEid
187
190
  getCaller(), ;; srcOApp
188
191
  dstEid, ;; dstEid
189
- $deploy.cl::get<uint256>(md::Deploy::dstOApp) ;; dstOApp
192
+ $sanitizedDeploy.cl::get<uint256>(md::Deploy::dstOApp) ;; dstOApp
190
193
  );
191
194
 
192
195
  ;; get the endpoint address
@@ -195,7 +198,7 @@ tuple deployChannel(cell $deploy) impure inline method_id {
195
198
  actions~pushAction<deployAndCall>(
196
199
  $storage.cl::get<cellRef>(Controller::channelCode),
197
200
  Channel::New(getContractAddress(), $path, endpointAddress),
198
- $deploy.cl::get<coins>(md::Deploy::initialDeposit),
201
+ $sanitizedDeploy.cl::get<coins>(md::Deploy::initialDeposit),
199
202
  BaseInterface::OP::INITIALIZE,
200
203
  cl::nullObject(),
201
204
  0
@@ -213,11 +216,12 @@ tuple setEpConfigDefaults(cell $mdEid) impure inline method_id {
213
216
  (_, tuple actions) = preamble();
214
217
 
215
218
  int dstEid = $mdEid.cl::get<uint32>(md::MdEid::eid);
219
+ cell $sanitizedSetEpConfig = $mdEid.cl::get<objRef>(md::MdEid::md).md::SetEpConfig::sanitize();
216
220
 
217
221
  actions~pushAction<call>(
218
222
  _calculateEndpointAddress(dstEid),
219
223
  Endpoint::OP::SET_EP_CONFIG_DEFAULTS,
220
- $mdEid.cl::get<objRef>(md::MdEid::md)
224
+ $sanitizedSetEpConfig
221
225
  );
222
226
 
223
227
  return actions;
@@ -234,10 +238,16 @@ tuple setEpConfigOApp(cell $mdObj) impure inline method_id {
234
238
  (_, tuple actions) = preamble();
235
239
 
236
240
  ;; get the path and setEpConfigMd from the md
237
- cell $path = $mdObj.cl::get<objRef>(md::MdObj::obj);
241
+ cell $sanitizedPath = $mdObj.cl::get<objRef>(md::MdObj::obj).lz::Path::sanitize();
242
+
243
+ ;; create a sanitized mdObj with the sanitized setEpConfig
244
+ $mdObj = md::MdObj::New(
245
+ $mdObj.cl::get<objRef>(md::MdObj::md).md::SetEpConfig::sanitize(),
246
+ $sanitizedPath
247
+ );
238
248
 
239
249
  actions~pushAction<call>(
240
- _calculateEndpointAddress($path.cl::get<uint32>(lz::Path::dstEid)),
250
+ _calculateEndpointAddress($sanitizedPath.cl::get<uint32>(lz::Path::dstEid)),
241
251
  Endpoint::OP::SET_EP_CONFIG_OAPP,
242
252
  $mdObj
243
253
  );
@@ -248,12 +258,14 @@ tuple setEpConfigOApp(cell $mdObj) impure inline method_id {
248
258
  tuple addMsglib(cell $addMsglibMd) impure inline method_id {
249
259
  (_, tuple actions) = preamble();
250
260
 
261
+ cell $sanitizedAddMsglibMd = $addMsglibMd.md::AddMsglib::sanitize();
262
+
251
263
  actions~pushAction<call>(
252
264
  _calculateEndpointAddress(
253
- $addMsglibMd.cl::get<uint32>(md::AddMsglib::dstEid)
265
+ $sanitizedAddMsglibMd.cl::get<uint32>(md::AddMsglib::dstEid)
254
266
  ),
255
267
  Endpoint::OP::ADD_MSGLIB,
256
- $addMsglibMd
268
+ $sanitizedAddMsglibMd
257
269
  );
258
270
 
259
271
  return actions;
@@ -263,16 +275,18 @@ tuple addMsglib(cell $addMsglibMd) impure inline method_id {
263
275
  tuple depositZro(cell $path) impure inline method_id {
264
276
  (cell $storage, tuple actions) = preamble();
265
277
 
278
+ cell $sanitizedPath = $path.lz::Path::sanitize();
279
+
266
280
  ;; The message format of jetton happens to align with funC++
267
281
  ;; but the jetton token amount is aliased as donationNanos
268
282
  int tokenAmount = getDonationNanos();
269
283
  setDonationNanos(0);
270
284
 
271
285
  ;; get the endpoint address
272
- int endpointAddress = _calculateEndpointAddress($path.cl::get<uint32>(lz::Path::dstEid));
286
+ int endpointAddress = _calculateEndpointAddress($sanitizedPath.cl::get<uint32>(lz::Path::dstEid));
273
287
 
274
288
  int channelAddress = computeContractAddress(
275
- Channel::New(getContractAddress(), $path, endpointAddress),
289
+ Channel::New(getContractAddress(), $sanitizedPath, endpointAddress),
276
290
  $storage.cl::get<cellRef>(Controller::channelCode)
277
291
  );
278
292
 
@@ -288,14 +302,16 @@ tuple depositZro(cell $path) impure inline method_id {
288
302
  tuple setZroWallet(cell $setAddress) impure inline method_id {
289
303
  (cell $storage, tuple actions) = preamble();
290
304
 
305
+ cell $sanitizedSetAddress = $setAddress.md::SetAddress::sanitize();
306
+
291
307
  setContractStorage(
292
308
  $storage.cl::set(
293
309
  Controller::zroWallet,
294
- $setAddress.cl::get<address>(md::SetAddress::address)
310
+ $sanitizedSetAddress.cl::get<address>(md::SetAddress::address)
295
311
  )
296
312
  );
297
313
 
298
- actions~pushAction<event>(Controller::event::ZRO_WALLET_SET, $setAddress);
314
+ actions~pushAction<event>(Controller::event::ZRO_WALLET_SET, $sanitizedSetAddress);
299
315
  return actions;
300
316
  }
301
317
 
@@ -306,16 +322,18 @@ tuple setZroWallet(cell $setAddress) impure inline method_id {
306
322
  tuple transferOwnership(cell $setAddress) impure inline {
307
323
  (cell $storage, tuple actions) = preamble();
308
324
 
325
+ cell $sanitizedSetAddress = $setAddress.md::SetAddress::sanitize();
326
+
309
327
  setContractStorage(
310
328
  $storage.cl::set(
311
329
  Controller::tentativeOwner,
312
- $setAddress.cl::get<address>(md::SetAddress::address)
330
+ $sanitizedSetAddress.cl::get<address>(md::SetAddress::address)
313
331
  )
314
332
  );
315
333
 
316
334
  actions~pushAction<event>(
317
335
  Controller::event::OWNER_SET_TENTATIVE,
318
- $setAddress
336
+ $sanitizedSetAddress
319
337
  );
320
338
 
321
339
  return actions;
@@ -26,4 +26,4 @@ tuple _executeOpcode(int op, cell $md) impure inline {
26
26
  throw(BaseInterface::ERROR::invalidOpcode);
27
27
  }
28
28
  return empty_tuple();
29
- }
29
+ }
@@ -7,48 +7,45 @@
7
7
  #include "../baseStorage.fc";
8
8
 
9
9
  int getOwner() impure inline {
10
- return getContractStorage()
11
- .cl::get<objRef>(BASE_STORAGE_INDEX)
12
- .cl::get<address>(BaseStorage::owner);
10
+ return getBaseStorage().BaseStorage::getOwner();
13
11
  }
14
12
 
15
13
  cell getInitialStorage() impure inline {
16
- return getContractStorage()
17
- .cl::get<objRef>(BASE_STORAGE_INDEX)
18
- .cl::get<objRef>(BaseStorage::initialStorage);
14
+ return getBaseStorage().BaseStorage::getInitialStorage();
19
15
  }
20
16
 
21
17
  ;;; ==========================================
22
18
  ;; Modifiers
23
19
  () assertAuthenticated() impure inline {
24
- cell $baseStorage = getContractStorage().cl::get<objRef>(BASE_STORAGE_INDEX);
25
20
  throw_unless(
26
21
  BaseInterface::ERROR::notAuthenticated,
27
- $baseStorage.cl::get<bool>(BaseStorage::authenticated)
22
+ getBaseStorage().BaseStorage::getAuthenticated()
28
23
  );
29
24
  }
30
25
 
31
26
  () assertInitialized() impure inline {
32
- cell $baseStorage = getContractStorage().cl::get<objRef>(BASE_STORAGE_INDEX);
33
27
  throw_unless(
34
28
  BaseInterface::ERROR::notInitialized,
35
- $baseStorage.cl::get<bool>(BaseStorage::initialized)
29
+ getBaseStorage().BaseStorage::getInitialized()
36
30
  );
37
31
  }
38
32
 
39
33
  ;; assert the ctx sender is the owner of this contract
40
34
  ;; expects the ctx to be populated. Does not require storage to be loaded
41
35
  () assertOwner() impure inline {
42
- cell $baseStorage = getContractStorage().cl::get<objRef>(BASE_STORAGE_INDEX);
43
36
  throw_unless(
44
37
  BaseInterface::ERROR::onlyOwner,
45
- getCaller() == $baseStorage.cl::get<address>(BaseStorage::owner)
38
+ getCaller() == getOwner()
46
39
  );
47
40
  }
48
41
 
49
42
  ;; Step 1: authenticate
50
43
  () authenticate() impure {
51
44
  assertOwner();
45
+ throw_if(
46
+ BaseInterface::ERROR::alreadyInitialized,
47
+ getBaseStorage().BaseStorage::getInitialized()
48
+ );
52
49
  cell $storage = getContractStorage();
53
50
 
54
51
  setContractStorage(
@@ -67,10 +64,7 @@ cell getInitialStorage() impure inline {
67
64
  }
68
65
 
69
66
  () authenticateIfNecessary() impure inline {
70
- if (getContractStorage()
71
- .cl::get<objRef>(BASE_STORAGE_INDEX)
72
- .cl::get<bool>(BaseStorage::authenticated) == false
73
- ) {
67
+ if (getBaseStorage().BaseStorage::getAuthenticated() == false) {
74
68
  authenticate();
75
69
  }
76
70
  }
@@ -80,11 +74,7 @@ cell getInitialStorage() impure inline {
80
74
  ;; Step 2: initialize
81
75
  tuple initialize(cell $md) impure inline {
82
76
  assertAuthenticated();
83
- if (
84
- getContractStorage()
85
- .cl::get<objRef>(BASE_STORAGE_INDEX)
86
- .cl::get<bool>(BaseStorage::initialized)
87
- ) {
77
+ if (getBaseStorage().BaseStorage::getInitialized()) {
88
78
  return emptyActions();
89
79
  }
90
80
 
@@ -30,4 +30,28 @@ cell BaseStorage::New(int owner) inline method_id {
30
30
  [cl::t::objRef, cl::nullObject()] ;; BaseStorage::initialStorage
31
31
  ])
32
32
  );
33
+ }
34
+
35
+ const int BaseStorage::_ownerOffset = _HEADER_WIDTH;
36
+ const int BaseStorage::_authenticatedOffset = BaseStorage::_ownerOffset + 256;
37
+ const int BaseStorage::_initializedOffset = BaseStorage::_authenticatedOffset + 1;
38
+
39
+ int BaseStorage::getOwner(cell $self) impure inline {
40
+ return $self.cellPreloadAddressAt(BaseStorage::_ownerOffset);
41
+ }
42
+
43
+ int BaseStorage::getAuthenticated(cell $self) impure inline {
44
+ return $self.cellPreloadBoolAt(BaseStorage::_authenticatedOffset);
45
+ }
46
+
47
+ int BaseStorage::getInitialized(cell $self) impure inline {
48
+ return $self.cellPreloadBoolAt(BaseStorage::_initializedOffset);
49
+ }
50
+
51
+ cell BaseStorage::getInitialStorage(cell $self) impure inline {
52
+ return $self.cellPreloadRefAt(0);
53
+ }
54
+
55
+ cell getBaseStorage() impure inline method_id {
56
+ return getContractStorage().cellPreloadRefAt(BASE_STORAGE_INDEX);
33
57
  }