@wormhole-foundation/wormhole-solidity-sdk 1.0.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 (56) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +78 -0
  3. package/contracts/Executor/Integration.sol +180 -0
  4. package/contracts/Executor/RelayInstruction.sol +108 -0
  5. package/contracts/Executor/Request.sol +43 -0
  6. package/contracts/RawDispatcher.sol +29 -0
  7. package/contracts/Utils.sol +27 -0
  8. package/contracts/WormholeRelayer/AdditionalMessages.sol +37 -0
  9. package/contracts/WormholeRelayer/Keys.sol +198 -0
  10. package/contracts/WormholeRelayer/Receiver.sol +44 -0
  11. package/contracts/WormholeRelayer/Sender.sol +264 -0
  12. package/contracts/WormholeRelayer.sol +7 -0
  13. package/contracts/constants/CctpDomainMapping.sol +72 -0
  14. package/contracts/constants/CctpDomains.sol +21 -0
  15. package/contracts/constants/Chains.sol +66 -0
  16. package/contracts/constants/Common.sol +17 -0
  17. package/contracts/constants/ConsistencyLevel.sol +9 -0
  18. package/contracts/interfaces/ICoreBridge.sol +80 -0
  19. package/contracts/interfaces/ICustomConsistencyLevel.sol +12 -0
  20. package/contracts/interfaces/IDeliveryProvider.sol +84 -0
  21. package/contracts/interfaces/IExecutor.sol +32 -0
  22. package/contracts/interfaces/ITokenBridge.sol +81 -0
  23. package/contracts/interfaces/IWormholeRelayer.sol +658 -0
  24. package/contracts/interfaces/cctp/IMessageTransmitter.sol +76 -0
  25. package/contracts/interfaces/cctp/ITokenMessenger.sol +72 -0
  26. package/contracts/interfaces/cctp/ITokenMinter.sol +40 -0
  27. package/contracts/interfaces/cctp/shared/IOwnable2Step.sol +18 -0
  28. package/contracts/interfaces/cctp/shared/IPausable.sol +20 -0
  29. package/contracts/interfaces/token/IERC20.sol +16 -0
  30. package/contracts/interfaces/token/IERC20Metadata.sol +11 -0
  31. package/contracts/interfaces/token/IERC20Permit.sol +19 -0
  32. package/contracts/interfaces/token/IWETH.sol +12 -0
  33. package/contracts/libraries/BytesParsing.sol +2848 -0
  34. package/contracts/libraries/CctpMessages.sol +755 -0
  35. package/contracts/libraries/CoreBridge.sol +365 -0
  36. package/contracts/libraries/CustomConsistency.sol +60 -0
  37. package/contracts/libraries/Percentage.sol +99 -0
  38. package/contracts/libraries/PermitParsing.sol +580 -0
  39. package/contracts/libraries/QueryResponse.sol +741 -0
  40. package/contracts/libraries/ReplayProtection.sol +106 -0
  41. package/contracts/libraries/SafeERC20.sol +67 -0
  42. package/contracts/libraries/TokenBridgeMessages.sol +742 -0
  43. package/contracts/libraries/TypedUnits.sol +304 -0
  44. package/contracts/libraries/UncheckedIndexing.sol +99 -0
  45. package/contracts/libraries/VaaLib.sol +1385 -0
  46. package/contracts/proxy/Eip1967Admin.sol +20 -0
  47. package/contracts/proxy/Eip1967Implementation.sol +15 -0
  48. package/contracts/proxy/Proxy.sol +43 -0
  49. package/contracts/proxy/ProxyBase.sol +80 -0
  50. package/contracts/utils/DecimalNormalization.sol +18 -0
  51. package/contracts/utils/EagerOps.sol +18 -0
  52. package/contracts/utils/Keccak.sol +39 -0
  53. package/contracts/utils/Revert.sol +11 -0
  54. package/contracts/utils/Transfer.sol +23 -0
  55. package/contracts/utils/UniversalAddress.sol +17 -0
  56. package/package.json +23 -0
@@ -0,0 +1,2848 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.4;
3
+
4
+ import "../constants/Common.sol";
5
+
6
+ //This file appears comically large, but all unused functions are removed by the compiler.
7
+ library BytesParsing {
8
+ error OutOfBounds(uint256 offset, uint256 length);
9
+ error LengthMismatch(uint256 encodedLength, uint256 expectedLength);
10
+ error InvalidBoolVal(uint8 val);
11
+
12
+ function checkBound(uint offset, uint length) internal pure {
13
+ if (offset > length)
14
+ revert OutOfBounds(offset, length);
15
+ }
16
+
17
+ function checkLength(uint encodedLength, uint expectedLength) internal pure {
18
+ if (encodedLength != expectedLength)
19
+ revert LengthMismatch(encodedLength, expectedLength);
20
+ }
21
+
22
+ //Summary of all remaining functions:
23
+ //
24
+ //Each function has 2*2=4 versions:
25
+ // 1. unchecked - no bounds checking (uses suffix `Unchecked`)
26
+ // 2. checked (no suffix)
27
+ //and (since Solidity does not allow overloading based on data location)
28
+ // 1. calldata input (uses tag `Cd` )
29
+ // 2. memory input (uses tag `Mem`)
30
+ //
31
+ //The canoncial/recommended way of parsing data to be maximally gas efficient is to prefer the
32
+ // calldata variants over the memory variants and to use the unchecked variants with a manual
33
+ // length check at the end using `checkLength` to ensure that encoded data was consumed exactly.
34
+ //
35
+ // ╭────────────────────────────────── WARNING ──────────────────────────────────╮
36
+ // │ Neither function variant (vanilla or unchecked) uses safe math! │
37
+ // │ │
38
+ // │ In the context of the BytesParsing library, checking only ever refers to │
39
+ // │ out of bound reads of the given buffer, never arithmetic overflows! │
40
+ // ╰─────────────────────────────────────────────────────────────────────────────╯
41
+ //
42
+ //In other words:
43
+ // It is up to the dev to ensure that offset and length values are sensibly bounded, even
44
+ // for the vanilla variants.
45
+ // Critically, this includes verifying user inputs before passing them on and preferably,
46
+ // using a format that does not allow for any such overflows in the first place,
47
+ // e.g. one that encodes lengths using at most 4 bytes, etc.
48
+ //
49
+ //Functions:
50
+ // Unless stated otherwise, all functions take an `encoded` bytes calldata/memory and an `offset`
51
+ // as input and return the parsed value and the next offset (i.e. the offset pointing to the
52
+ // next, unparsed byte).
53
+ //
54
+ // * slice(encoded, offset, length)
55
+ // * sliceUint<n>Prefixed - n in {8, 16, 32} - parses n bytes of length prefix followed by data
56
+ // * asAddress
57
+ // * asBool
58
+ // * asUint<8*n> - n in {1, ..., 32}, i.e. asUint8, asUint16, ..., asUint256
59
+ // * asBytes<n> - n in {1, ..., 32}, i.e. asBytes1, asBytes2, ..., asBytes32
60
+
61
+ function sliceCdUnchecked(
62
+ bytes calldata encoded,
63
+ uint offset,
64
+ uint length
65
+ ) internal pure returns (bytes calldata ret, uint nextOffset) {
66
+ /// @solidity memory-safe-assembly
67
+ assembly {
68
+ ret.offset := add(encoded.offset, offset)
69
+ ret.length := length
70
+ nextOffset := add(offset, length)
71
+ }
72
+ }
73
+
74
+ function sliceMemUnchecked(
75
+ bytes memory encoded,
76
+ uint offset,
77
+ uint length
78
+ ) internal pure returns (bytes memory ret, uint nextOffset) {
79
+ /// @solidity memory-safe-assembly
80
+ assembly {
81
+ nextOffset := add(offset, length)
82
+ ret := mload(FREE_MEMORY_PTR)
83
+
84
+ //Explanation on how we copy data here:
85
+ // The bytes type has the following layout in memory:
86
+ // [length: 32 bytes, data: length bytes]
87
+ // So if we allocate `bytes memory foo = new bytes(1);` then `foo` will be a pointer to 33
88
+ // bytes where the first 32 bytes contain the length and the last byte is the actual data.
89
+ // Since mload always loads 32 bytes of memory at once, we use our shift variable to align
90
+ // our reads so that our last read lines up exactly with the last 32 bytes of `encoded`.
91
+ // However this also means that if the length of `encoded` is not a multiple of 32 bytes, our
92
+ // first read will necessarily partly contain bytes from `encoded`'s 32 length bytes that
93
+ // will be written into the length part of our `ret` slice.
94
+ // We remedy this issue by writing the length of our `ret` slice at the end, thus
95
+ // overwritting those garbage bytes.
96
+
97
+ //and(length, 31) is equivalent to `mod(length, 32)`, but 2 gas cheaper
98
+ let shift := and(length, WORD_SIZE_MINUS_ONE)
99
+ if iszero(shift) {
100
+ shift := WORD_SIZE
101
+ }
102
+
103
+ let dest := add(ret, shift)
104
+ let end := add(dest, length)
105
+ for {
106
+ let src := add(add(encoded, shift), offset)
107
+ } lt(dest, end) {
108
+ src := add(src, WORD_SIZE)
109
+ dest := add(dest, WORD_SIZE)
110
+ } {
111
+ mstore(dest, mload(src))
112
+ }
113
+
114
+ mstore(ret, length)
115
+ //When compiling with --via-ir then normally allocated memory (i.e. via new) will have 32 byte
116
+ // memory alignment and so we enforce the same memory alignment here.
117
+ mstore(
118
+ FREE_MEMORY_PTR,
119
+ and(add(dest, WORD_SIZE_MINUS_ONE), not(WORD_SIZE_MINUS_ONE))
120
+ )
121
+ }
122
+ }
123
+
124
+ /* -------------------------------------------------------------------------------------------------
125
+ Remaining library code below was auto-generated via the following js/node code:
126
+
127
+ const dlTag = dl => dl ? "Cd" : "Mem";
128
+ const dlType = dl =>dl ? "calldata" : "memory";
129
+
130
+ const funcs = [
131
+ ...[8,16,32].map(n => [
132
+ `sliceUint${n}Prefixed`,
133
+ dl => [
134
+ `uint${n} len;`,
135
+ `(len, nextOffset) = asUint${n}${dlTag(dl)}Unchecked(encoded, offset);`,
136
+ `(ret, nextOffset) = slice${dlTag(dl)}Unchecked(encoded, nextOffset, uint(len));`
137
+ ],
138
+ dl => `bytes ${dlType(dl)}`,
139
+ ]), [
140
+ `asAddress`,
141
+ dl => [
142
+ `uint160 tmp;`,
143
+ `(tmp, nextOffset) = asUint160${dlTag(dl)}Unchecked(encoded, offset);`,
144
+ `ret = address(tmp);`
145
+ ],
146
+ _ => `address`
147
+ ], [
148
+ `asBool`,
149
+ dl => [
150
+ `uint8 val;`,
151
+ `(val, nextOffset) = asUint8${dlTag(dl)}Unchecked(encoded, offset);`,
152
+ `uint cleanedVal = uint(val);`,
153
+ `if (cleanedVal & 0xfe != 0)`,
154
+ ` revert InvalidBoolVal(val);`,
155
+ `//skip 2x iszero opcode`,
156
+ `/// @solidity memory-safe-assembly`,
157
+ `assembly { ret := cleanedVal }`
158
+ ],
159
+ _ => `bool`
160
+ ],
161
+ ...Array.from({length: 32}, (_, i) => [
162
+ `asUint${(i+1)*8}`,
163
+ dl => [
164
+ `/// @solidity memory-safe-assembly`,
165
+ `assembly {`,
166
+ ` nextOffset := add(offset, ${i+1})`,
167
+ dl ? ` ret := shr(${256-(i+1)*8}, calldataload(add(encoded.offset, offset)))`
168
+ : ` ret := mload(add(encoded, nextOffset))`,
169
+ `}`
170
+ ],
171
+ _ => `uint${(i+1)*8}`
172
+ ]),
173
+ ...Array.from({length: 32}, (_, i) => [
174
+ `asBytes${i+1}`,
175
+ dl => [
176
+ `/// @solidity memory-safe-assembly`,
177
+ `assembly {`,
178
+ ` ret := ${dl ? "calldataload" : "mload"}(add(encoded${dl ? ".offset" :""}, ${dl ? "offset" : "add(offset, WORD_SIZE)"}))`,
179
+ ` nextOffset := add(offset, ${i+1})`,
180
+ `}`
181
+ ],
182
+ _ => `bytes${i+1}`
183
+ ]),
184
+ ];
185
+
186
+ for (const dl of [true, false])
187
+ console.log(
188
+ `function slice${dlTag(dl)}(
189
+ bytes ${dlType(dl)} encoded,
190
+ uint offset,
191
+ uint length
192
+ ) internal pure returns (bytes ${dlType(dl)} ret, uint nextOffset) {
193
+ (ret, nextOffset) = slice${dlTag(dl)}Unchecked(encoded, offset, length);
194
+ checkBound(nextOffset, encoded.length);
195
+ }
196
+ `);
197
+
198
+ for (const [name, code, ret] of funcs) {
199
+ for (const dl of [true, false])
200
+ console.log(
201
+ `function ${name}${dlTag(dl)}Unchecked(
202
+ bytes ${dlType(dl)} encoded,
203
+ uint offset
204
+ ) internal pure returns (${ret(dl)} ret, uint nextOffset) {
205
+ ${code(dl).join("\n ")}
206
+ }
207
+
208
+ function ${name}${dlTag(dl)}(
209
+ bytes ${dlType(dl)} encoded,
210
+ uint offset
211
+ ) internal pure returns (${ret(dl)} ret, uint nextOffset) {
212
+ (ret, nextOffset) = ${name}${dlTag(dl)}Unchecked(encoded, offset);
213
+ checkBound(nextOffset, encoded.length);
214
+ }
215
+ `);
216
+ }
217
+ ------------------------------------------------------------------------------------------------- */
218
+
219
+ function sliceCd(
220
+ bytes calldata encoded,
221
+ uint offset,
222
+ uint length
223
+ ) internal pure returns (bytes calldata ret, uint nextOffset) {
224
+ (ret, nextOffset) = sliceCdUnchecked(encoded, offset, length);
225
+ checkBound(nextOffset, encoded.length);
226
+ }
227
+
228
+ function sliceMem(
229
+ bytes memory encoded,
230
+ uint offset,
231
+ uint length
232
+ ) internal pure returns (bytes memory ret, uint nextOffset) {
233
+ (ret, nextOffset) = sliceMemUnchecked(encoded, offset, length);
234
+ checkBound(nextOffset, encoded.length);
235
+ }
236
+
237
+ function sliceUint8PrefixedCdUnchecked(
238
+ bytes calldata encoded,
239
+ uint offset
240
+ ) internal pure returns (bytes calldata ret, uint nextOffset) {
241
+ uint8 len;
242
+ (len, nextOffset) = asUint8CdUnchecked(encoded, offset);
243
+ (ret, nextOffset) = sliceCdUnchecked(encoded, nextOffset, uint(len));
244
+ }
245
+
246
+ function sliceUint8PrefixedCd(
247
+ bytes calldata encoded,
248
+ uint offset
249
+ ) internal pure returns (bytes calldata ret, uint nextOffset) {
250
+ (ret, nextOffset) = sliceUint8PrefixedCdUnchecked(encoded, offset);
251
+ checkBound(nextOffset, encoded.length);
252
+ }
253
+
254
+ function sliceUint8PrefixedMemUnchecked(
255
+ bytes memory encoded,
256
+ uint offset
257
+ ) internal pure returns (bytes memory ret, uint nextOffset) {
258
+ uint8 len;
259
+ (len, nextOffset) = asUint8MemUnchecked(encoded, offset);
260
+ (ret, nextOffset) = sliceMemUnchecked(encoded, nextOffset, uint(len));
261
+ }
262
+
263
+ function sliceUint8PrefixedMem(
264
+ bytes memory encoded,
265
+ uint offset
266
+ ) internal pure returns (bytes memory ret, uint nextOffset) {
267
+ (ret, nextOffset) = sliceUint8PrefixedMemUnchecked(encoded, offset);
268
+ checkBound(nextOffset, encoded.length);
269
+ }
270
+
271
+ function sliceUint16PrefixedCdUnchecked(
272
+ bytes calldata encoded,
273
+ uint offset
274
+ ) internal pure returns (bytes calldata ret, uint nextOffset) {
275
+ uint16 len;
276
+ (len, nextOffset) = asUint16CdUnchecked(encoded, offset);
277
+ (ret, nextOffset) = sliceCdUnchecked(encoded, nextOffset, uint(len));
278
+ }
279
+
280
+ function sliceUint16PrefixedCd(
281
+ bytes calldata encoded,
282
+ uint offset
283
+ ) internal pure returns (bytes calldata ret, uint nextOffset) {
284
+ (ret, nextOffset) = sliceUint16PrefixedCdUnchecked(encoded, offset);
285
+ checkBound(nextOffset, encoded.length);
286
+ }
287
+
288
+ function sliceUint16PrefixedMemUnchecked(
289
+ bytes memory encoded,
290
+ uint offset
291
+ ) internal pure returns (bytes memory ret, uint nextOffset) {
292
+ uint16 len;
293
+ (len, nextOffset) = asUint16MemUnchecked(encoded, offset);
294
+ (ret, nextOffset) = sliceMemUnchecked(encoded, nextOffset, uint(len));
295
+ }
296
+
297
+ function sliceUint16PrefixedMem(
298
+ bytes memory encoded,
299
+ uint offset
300
+ ) internal pure returns (bytes memory ret, uint nextOffset) {
301
+ (ret, nextOffset) = sliceUint16PrefixedMemUnchecked(encoded, offset);
302
+ checkBound(nextOffset, encoded.length);
303
+ }
304
+
305
+ function sliceUint32PrefixedCdUnchecked(
306
+ bytes calldata encoded,
307
+ uint offset
308
+ ) internal pure returns (bytes calldata ret, uint nextOffset) {
309
+ uint32 len;
310
+ (len, nextOffset) = asUint32CdUnchecked(encoded, offset);
311
+ (ret, nextOffset) = sliceCdUnchecked(encoded, nextOffset, uint(len));
312
+ }
313
+
314
+ function sliceUint32PrefixedCd(
315
+ bytes calldata encoded,
316
+ uint offset
317
+ ) internal pure returns (bytes calldata ret, uint nextOffset) {
318
+ (ret, nextOffset) = sliceUint32PrefixedCdUnchecked(encoded, offset);
319
+ checkBound(nextOffset, encoded.length);
320
+ }
321
+
322
+ function sliceUint32PrefixedMemUnchecked(
323
+ bytes memory encoded,
324
+ uint offset
325
+ ) internal pure returns (bytes memory ret, uint nextOffset) {
326
+ uint32 len;
327
+ (len, nextOffset) = asUint32MemUnchecked(encoded, offset);
328
+ (ret, nextOffset) = sliceMemUnchecked(encoded, nextOffset, uint(len));
329
+ }
330
+
331
+ function sliceUint32PrefixedMem(
332
+ bytes memory encoded,
333
+ uint offset
334
+ ) internal pure returns (bytes memory ret, uint nextOffset) {
335
+ (ret, nextOffset) = sliceUint32PrefixedMemUnchecked(encoded, offset);
336
+ checkBound(nextOffset, encoded.length);
337
+ }
338
+
339
+ function asAddressCdUnchecked(
340
+ bytes calldata encoded,
341
+ uint offset
342
+ ) internal pure returns (address ret, uint nextOffset) {
343
+ uint160 tmp;
344
+ (tmp, nextOffset) = asUint160CdUnchecked(encoded, offset);
345
+ ret = address(tmp);
346
+ }
347
+
348
+ function asAddressCd(
349
+ bytes calldata encoded,
350
+ uint offset
351
+ ) internal pure returns (address ret, uint nextOffset) {
352
+ (ret, nextOffset) = asAddressCdUnchecked(encoded, offset);
353
+ checkBound(nextOffset, encoded.length);
354
+ }
355
+
356
+ function asAddressMemUnchecked(
357
+ bytes memory encoded,
358
+ uint offset
359
+ ) internal pure returns (address ret, uint nextOffset) {
360
+ uint160 tmp;
361
+ (tmp, nextOffset) = asUint160MemUnchecked(encoded, offset);
362
+ ret = address(tmp);
363
+ }
364
+
365
+ function asAddressMem(
366
+ bytes memory encoded,
367
+ uint offset
368
+ ) internal pure returns (address ret, uint nextOffset) {
369
+ (ret, nextOffset) = asAddressMemUnchecked(encoded, offset);
370
+ checkBound(nextOffset, encoded.length);
371
+ }
372
+
373
+ function asBoolCdUnchecked(
374
+ bytes calldata encoded,
375
+ uint offset
376
+ ) internal pure returns (bool ret, uint nextOffset) {
377
+ uint8 val;
378
+ (val, nextOffset) = asUint8CdUnchecked(encoded, offset);
379
+ uint cleanedVal = uint(val); //clean up upper 31 bytes
380
+ if (cleanedVal & 0xfe != 0)
381
+ revert InvalidBoolVal(val);
382
+ //skip 2x iszero opcode
383
+ /// @solidity memory-safe-assembly
384
+ assembly { ret := cleanedVal }
385
+ }
386
+
387
+ function asBoolCd(
388
+ bytes calldata encoded,
389
+ uint offset
390
+ ) internal pure returns (bool ret, uint nextOffset) {
391
+ (ret, nextOffset) = asBoolCdUnchecked(encoded, offset);
392
+ checkBound(nextOffset, encoded.length);
393
+ }
394
+
395
+ function asBoolMemUnchecked(
396
+ bytes memory encoded,
397
+ uint offset
398
+ ) internal pure returns (bool ret, uint nextOffset) {
399
+ uint8 val;
400
+ (val, nextOffset) = asUint8MemUnchecked(encoded, offset);
401
+ uint cleanedVal = uint(val); //clean up upper 31 bytes
402
+ if (cleanedVal & 0xfe != 0)
403
+ revert InvalidBoolVal(val);
404
+ //skip 2x iszero opcode
405
+ /// @solidity memory-safe-assembly
406
+ assembly { ret := cleanedVal }
407
+ }
408
+
409
+ function asBoolMem(
410
+ bytes memory encoded,
411
+ uint offset
412
+ ) internal pure returns (bool ret, uint nextOffset) {
413
+ (ret, nextOffset) = asBoolMemUnchecked(encoded, offset);
414
+ checkBound(nextOffset, encoded.length);
415
+ }
416
+
417
+ function asUint8CdUnchecked(
418
+ bytes calldata encoded,
419
+ uint offset
420
+ ) internal pure returns (uint8 ret, uint nextOffset) {
421
+ /// @solidity memory-safe-assembly
422
+ assembly {
423
+ nextOffset := add(offset, 1)
424
+ ret := shr(248, calldataload(add(encoded.offset, offset)))
425
+ }
426
+ }
427
+
428
+ function asUint8Cd(
429
+ bytes calldata encoded,
430
+ uint offset
431
+ ) internal pure returns (uint8 ret, uint nextOffset) {
432
+ (ret, nextOffset) = asUint8CdUnchecked(encoded, offset);
433
+ checkBound(nextOffset, encoded.length);
434
+ }
435
+
436
+ function asUint8MemUnchecked(
437
+ bytes memory encoded,
438
+ uint offset
439
+ ) internal pure returns (uint8 ret, uint nextOffset) {
440
+ /// @solidity memory-safe-assembly
441
+ assembly {
442
+ nextOffset := add(offset, 1)
443
+ ret := mload(add(encoded, nextOffset))
444
+ }
445
+ }
446
+
447
+ function asUint8Mem(
448
+ bytes memory encoded,
449
+ uint offset
450
+ ) internal pure returns (uint8 ret, uint nextOffset) {
451
+ (ret, nextOffset) = asUint8MemUnchecked(encoded, offset);
452
+ checkBound(nextOffset, encoded.length);
453
+ }
454
+
455
+ function asUint16CdUnchecked(
456
+ bytes calldata encoded,
457
+ uint offset
458
+ ) internal pure returns (uint16 ret, uint nextOffset) {
459
+ /// @solidity memory-safe-assembly
460
+ assembly {
461
+ nextOffset := add(offset, 2)
462
+ ret := shr(240, calldataload(add(encoded.offset, offset)))
463
+ }
464
+ }
465
+
466
+ function asUint16Cd(
467
+ bytes calldata encoded,
468
+ uint offset
469
+ ) internal pure returns (uint16 ret, uint nextOffset) {
470
+ (ret, nextOffset) = asUint16CdUnchecked(encoded, offset);
471
+ checkBound(nextOffset, encoded.length);
472
+ }
473
+
474
+ function asUint16MemUnchecked(
475
+ bytes memory encoded,
476
+ uint offset
477
+ ) internal pure returns (uint16 ret, uint nextOffset) {
478
+ /// @solidity memory-safe-assembly
479
+ assembly {
480
+ nextOffset := add(offset, 2)
481
+ ret := mload(add(encoded, nextOffset))
482
+ }
483
+ }
484
+
485
+ function asUint16Mem(
486
+ bytes memory encoded,
487
+ uint offset
488
+ ) internal pure returns (uint16 ret, uint nextOffset) {
489
+ (ret, nextOffset) = asUint16MemUnchecked(encoded, offset);
490
+ checkBound(nextOffset, encoded.length);
491
+ }
492
+
493
+ function asUint24CdUnchecked(
494
+ bytes calldata encoded,
495
+ uint offset
496
+ ) internal pure returns (uint24 ret, uint nextOffset) {
497
+ /// @solidity memory-safe-assembly
498
+ assembly {
499
+ nextOffset := add(offset, 3)
500
+ ret := shr(232, calldataload(add(encoded.offset, offset)))
501
+ }
502
+ }
503
+
504
+ function asUint24Cd(
505
+ bytes calldata encoded,
506
+ uint offset
507
+ ) internal pure returns (uint24 ret, uint nextOffset) {
508
+ (ret, nextOffset) = asUint24CdUnchecked(encoded, offset);
509
+ checkBound(nextOffset, encoded.length);
510
+ }
511
+
512
+ function asUint24MemUnchecked(
513
+ bytes memory encoded,
514
+ uint offset
515
+ ) internal pure returns (uint24 ret, uint nextOffset) {
516
+ /// @solidity memory-safe-assembly
517
+ assembly {
518
+ nextOffset := add(offset, 3)
519
+ ret := mload(add(encoded, nextOffset))
520
+ }
521
+ }
522
+
523
+ function asUint24Mem(
524
+ bytes memory encoded,
525
+ uint offset
526
+ ) internal pure returns (uint24 ret, uint nextOffset) {
527
+ (ret, nextOffset) = asUint24MemUnchecked(encoded, offset);
528
+ checkBound(nextOffset, encoded.length);
529
+ }
530
+
531
+ function asUint32CdUnchecked(
532
+ bytes calldata encoded,
533
+ uint offset
534
+ ) internal pure returns (uint32 ret, uint nextOffset) {
535
+ /// @solidity memory-safe-assembly
536
+ assembly {
537
+ nextOffset := add(offset, 4)
538
+ ret := shr(224, calldataload(add(encoded.offset, offset)))
539
+ }
540
+ }
541
+
542
+ function asUint32Cd(
543
+ bytes calldata encoded,
544
+ uint offset
545
+ ) internal pure returns (uint32 ret, uint nextOffset) {
546
+ (ret, nextOffset) = asUint32CdUnchecked(encoded, offset);
547
+ checkBound(nextOffset, encoded.length);
548
+ }
549
+
550
+ function asUint32MemUnchecked(
551
+ bytes memory encoded,
552
+ uint offset
553
+ ) internal pure returns (uint32 ret, uint nextOffset) {
554
+ /// @solidity memory-safe-assembly
555
+ assembly {
556
+ nextOffset := add(offset, 4)
557
+ ret := mload(add(encoded, nextOffset))
558
+ }
559
+ }
560
+
561
+ function asUint32Mem(
562
+ bytes memory encoded,
563
+ uint offset
564
+ ) internal pure returns (uint32 ret, uint nextOffset) {
565
+ (ret, nextOffset) = asUint32MemUnchecked(encoded, offset);
566
+ checkBound(nextOffset, encoded.length);
567
+ }
568
+
569
+ function asUint40CdUnchecked(
570
+ bytes calldata encoded,
571
+ uint offset
572
+ ) internal pure returns (uint40 ret, uint nextOffset) {
573
+ /// @solidity memory-safe-assembly
574
+ assembly {
575
+ nextOffset := add(offset, 5)
576
+ ret := shr(216, calldataload(add(encoded.offset, offset)))
577
+ }
578
+ }
579
+
580
+ function asUint40Cd(
581
+ bytes calldata encoded,
582
+ uint offset
583
+ ) internal pure returns (uint40 ret, uint nextOffset) {
584
+ (ret, nextOffset) = asUint40CdUnchecked(encoded, offset);
585
+ checkBound(nextOffset, encoded.length);
586
+ }
587
+
588
+ function asUint40MemUnchecked(
589
+ bytes memory encoded,
590
+ uint offset
591
+ ) internal pure returns (uint40 ret, uint nextOffset) {
592
+ /// @solidity memory-safe-assembly
593
+ assembly {
594
+ nextOffset := add(offset, 5)
595
+ ret := mload(add(encoded, nextOffset))
596
+ }
597
+ }
598
+
599
+ function asUint40Mem(
600
+ bytes memory encoded,
601
+ uint offset
602
+ ) internal pure returns (uint40 ret, uint nextOffset) {
603
+ (ret, nextOffset) = asUint40MemUnchecked(encoded, offset);
604
+ checkBound(nextOffset, encoded.length);
605
+ }
606
+
607
+ function asUint48CdUnchecked(
608
+ bytes calldata encoded,
609
+ uint offset
610
+ ) internal pure returns (uint48 ret, uint nextOffset) {
611
+ /// @solidity memory-safe-assembly
612
+ assembly {
613
+ nextOffset := add(offset, 6)
614
+ ret := shr(208, calldataload(add(encoded.offset, offset)))
615
+ }
616
+ }
617
+
618
+ function asUint48Cd(
619
+ bytes calldata encoded,
620
+ uint offset
621
+ ) internal pure returns (uint48 ret, uint nextOffset) {
622
+ (ret, nextOffset) = asUint48CdUnchecked(encoded, offset);
623
+ checkBound(nextOffset, encoded.length);
624
+ }
625
+
626
+ function asUint48MemUnchecked(
627
+ bytes memory encoded,
628
+ uint offset
629
+ ) internal pure returns (uint48 ret, uint nextOffset) {
630
+ /// @solidity memory-safe-assembly
631
+ assembly {
632
+ nextOffset := add(offset, 6)
633
+ ret := mload(add(encoded, nextOffset))
634
+ }
635
+ }
636
+
637
+ function asUint48Mem(
638
+ bytes memory encoded,
639
+ uint offset
640
+ ) internal pure returns (uint48 ret, uint nextOffset) {
641
+ (ret, nextOffset) = asUint48MemUnchecked(encoded, offset);
642
+ checkBound(nextOffset, encoded.length);
643
+ }
644
+
645
+ function asUint56CdUnchecked(
646
+ bytes calldata encoded,
647
+ uint offset
648
+ ) internal pure returns (uint56 ret, uint nextOffset) {
649
+ /// @solidity memory-safe-assembly
650
+ assembly {
651
+ nextOffset := add(offset, 7)
652
+ ret := shr(200, calldataload(add(encoded.offset, offset)))
653
+ }
654
+ }
655
+
656
+ function asUint56Cd(
657
+ bytes calldata encoded,
658
+ uint offset
659
+ ) internal pure returns (uint56 ret, uint nextOffset) {
660
+ (ret, nextOffset) = asUint56CdUnchecked(encoded, offset);
661
+ checkBound(nextOffset, encoded.length);
662
+ }
663
+
664
+ function asUint56MemUnchecked(
665
+ bytes memory encoded,
666
+ uint offset
667
+ ) internal pure returns (uint56 ret, uint nextOffset) {
668
+ /// @solidity memory-safe-assembly
669
+ assembly {
670
+ nextOffset := add(offset, 7)
671
+ ret := mload(add(encoded, nextOffset))
672
+ }
673
+ }
674
+
675
+ function asUint56Mem(
676
+ bytes memory encoded,
677
+ uint offset
678
+ ) internal pure returns (uint56 ret, uint nextOffset) {
679
+ (ret, nextOffset) = asUint56MemUnchecked(encoded, offset);
680
+ checkBound(nextOffset, encoded.length);
681
+ }
682
+
683
+ function asUint64CdUnchecked(
684
+ bytes calldata encoded,
685
+ uint offset
686
+ ) internal pure returns (uint64 ret, uint nextOffset) {
687
+ /// @solidity memory-safe-assembly
688
+ assembly {
689
+ nextOffset := add(offset, 8)
690
+ ret := shr(192, calldataload(add(encoded.offset, offset)))
691
+ }
692
+ }
693
+
694
+ function asUint64Cd(
695
+ bytes calldata encoded,
696
+ uint offset
697
+ ) internal pure returns (uint64 ret, uint nextOffset) {
698
+ (ret, nextOffset) = asUint64CdUnchecked(encoded, offset);
699
+ checkBound(nextOffset, encoded.length);
700
+ }
701
+
702
+ function asUint64MemUnchecked(
703
+ bytes memory encoded,
704
+ uint offset
705
+ ) internal pure returns (uint64 ret, uint nextOffset) {
706
+ /// @solidity memory-safe-assembly
707
+ assembly {
708
+ nextOffset := add(offset, 8)
709
+ ret := mload(add(encoded, nextOffset))
710
+ }
711
+ }
712
+
713
+ function asUint64Mem(
714
+ bytes memory encoded,
715
+ uint offset
716
+ ) internal pure returns (uint64 ret, uint nextOffset) {
717
+ (ret, nextOffset) = asUint64MemUnchecked(encoded, offset);
718
+ checkBound(nextOffset, encoded.length);
719
+ }
720
+
721
+ function asUint72CdUnchecked(
722
+ bytes calldata encoded,
723
+ uint offset
724
+ ) internal pure returns (uint72 ret, uint nextOffset) {
725
+ /// @solidity memory-safe-assembly
726
+ assembly {
727
+ nextOffset := add(offset, 9)
728
+ ret := shr(184, calldataload(add(encoded.offset, offset)))
729
+ }
730
+ }
731
+
732
+ function asUint72Cd(
733
+ bytes calldata encoded,
734
+ uint offset
735
+ ) internal pure returns (uint72 ret, uint nextOffset) {
736
+ (ret, nextOffset) = asUint72CdUnchecked(encoded, offset);
737
+ checkBound(nextOffset, encoded.length);
738
+ }
739
+
740
+ function asUint72MemUnchecked(
741
+ bytes memory encoded,
742
+ uint offset
743
+ ) internal pure returns (uint72 ret, uint nextOffset) {
744
+ /// @solidity memory-safe-assembly
745
+ assembly {
746
+ nextOffset := add(offset, 9)
747
+ ret := mload(add(encoded, nextOffset))
748
+ }
749
+ }
750
+
751
+ function asUint72Mem(
752
+ bytes memory encoded,
753
+ uint offset
754
+ ) internal pure returns (uint72 ret, uint nextOffset) {
755
+ (ret, nextOffset) = asUint72MemUnchecked(encoded, offset);
756
+ checkBound(nextOffset, encoded.length);
757
+ }
758
+
759
+ function asUint80CdUnchecked(
760
+ bytes calldata encoded,
761
+ uint offset
762
+ ) internal pure returns (uint80 ret, uint nextOffset) {
763
+ /// @solidity memory-safe-assembly
764
+ assembly {
765
+ nextOffset := add(offset, 10)
766
+ ret := shr(176, calldataload(add(encoded.offset, offset)))
767
+ }
768
+ }
769
+
770
+ function asUint80Cd(
771
+ bytes calldata encoded,
772
+ uint offset
773
+ ) internal pure returns (uint80 ret, uint nextOffset) {
774
+ (ret, nextOffset) = asUint80CdUnchecked(encoded, offset);
775
+ checkBound(nextOffset, encoded.length);
776
+ }
777
+
778
+ function asUint80MemUnchecked(
779
+ bytes memory encoded,
780
+ uint offset
781
+ ) internal pure returns (uint80 ret, uint nextOffset) {
782
+ /// @solidity memory-safe-assembly
783
+ assembly {
784
+ nextOffset := add(offset, 10)
785
+ ret := mload(add(encoded, nextOffset))
786
+ }
787
+ }
788
+
789
+ function asUint80Mem(
790
+ bytes memory encoded,
791
+ uint offset
792
+ ) internal pure returns (uint80 ret, uint nextOffset) {
793
+ (ret, nextOffset) = asUint80MemUnchecked(encoded, offset);
794
+ checkBound(nextOffset, encoded.length);
795
+ }
796
+
797
+ function asUint88CdUnchecked(
798
+ bytes calldata encoded,
799
+ uint offset
800
+ ) internal pure returns (uint88 ret, uint nextOffset) {
801
+ /// @solidity memory-safe-assembly
802
+ assembly {
803
+ nextOffset := add(offset, 11)
804
+ ret := shr(168, calldataload(add(encoded.offset, offset)))
805
+ }
806
+ }
807
+
808
+ function asUint88Cd(
809
+ bytes calldata encoded,
810
+ uint offset
811
+ ) internal pure returns (uint88 ret, uint nextOffset) {
812
+ (ret, nextOffset) = asUint88CdUnchecked(encoded, offset);
813
+ checkBound(nextOffset, encoded.length);
814
+ }
815
+
816
+ function asUint88MemUnchecked(
817
+ bytes memory encoded,
818
+ uint offset
819
+ ) internal pure returns (uint88 ret, uint nextOffset) {
820
+ /// @solidity memory-safe-assembly
821
+ assembly {
822
+ nextOffset := add(offset, 11)
823
+ ret := mload(add(encoded, nextOffset))
824
+ }
825
+ }
826
+
827
+ function asUint88Mem(
828
+ bytes memory encoded,
829
+ uint offset
830
+ ) internal pure returns (uint88 ret, uint nextOffset) {
831
+ (ret, nextOffset) = asUint88MemUnchecked(encoded, offset);
832
+ checkBound(nextOffset, encoded.length);
833
+ }
834
+
835
+ function asUint96CdUnchecked(
836
+ bytes calldata encoded,
837
+ uint offset
838
+ ) internal pure returns (uint96 ret, uint nextOffset) {
839
+ /// @solidity memory-safe-assembly
840
+ assembly {
841
+ nextOffset := add(offset, 12)
842
+ ret := shr(160, calldataload(add(encoded.offset, offset)))
843
+ }
844
+ }
845
+
846
+ function asUint96Cd(
847
+ bytes calldata encoded,
848
+ uint offset
849
+ ) internal pure returns (uint96 ret, uint nextOffset) {
850
+ (ret, nextOffset) = asUint96CdUnchecked(encoded, offset);
851
+ checkBound(nextOffset, encoded.length);
852
+ }
853
+
854
+ function asUint96MemUnchecked(
855
+ bytes memory encoded,
856
+ uint offset
857
+ ) internal pure returns (uint96 ret, uint nextOffset) {
858
+ /// @solidity memory-safe-assembly
859
+ assembly {
860
+ nextOffset := add(offset, 12)
861
+ ret := mload(add(encoded, nextOffset))
862
+ }
863
+ }
864
+
865
+ function asUint96Mem(
866
+ bytes memory encoded,
867
+ uint offset
868
+ ) internal pure returns (uint96 ret, uint nextOffset) {
869
+ (ret, nextOffset) = asUint96MemUnchecked(encoded, offset);
870
+ checkBound(nextOffset, encoded.length);
871
+ }
872
+
873
+ function asUint104CdUnchecked(
874
+ bytes calldata encoded,
875
+ uint offset
876
+ ) internal pure returns (uint104 ret, uint nextOffset) {
877
+ /// @solidity memory-safe-assembly
878
+ assembly {
879
+ nextOffset := add(offset, 13)
880
+ ret := shr(152, calldataload(add(encoded.offset, offset)))
881
+ }
882
+ }
883
+
884
+ function asUint104Cd(
885
+ bytes calldata encoded,
886
+ uint offset
887
+ ) internal pure returns (uint104 ret, uint nextOffset) {
888
+ (ret, nextOffset) = asUint104CdUnchecked(encoded, offset);
889
+ checkBound(nextOffset, encoded.length);
890
+ }
891
+
892
+ function asUint104MemUnchecked(
893
+ bytes memory encoded,
894
+ uint offset
895
+ ) internal pure returns (uint104 ret, uint nextOffset) {
896
+ /// @solidity memory-safe-assembly
897
+ assembly {
898
+ nextOffset := add(offset, 13)
899
+ ret := mload(add(encoded, nextOffset))
900
+ }
901
+ }
902
+
903
+ function asUint104Mem(
904
+ bytes memory encoded,
905
+ uint offset
906
+ ) internal pure returns (uint104 ret, uint nextOffset) {
907
+ (ret, nextOffset) = asUint104MemUnchecked(encoded, offset);
908
+ checkBound(nextOffset, encoded.length);
909
+ }
910
+
911
+ function asUint112CdUnchecked(
912
+ bytes calldata encoded,
913
+ uint offset
914
+ ) internal pure returns (uint112 ret, uint nextOffset) {
915
+ /// @solidity memory-safe-assembly
916
+ assembly {
917
+ nextOffset := add(offset, 14)
918
+ ret := shr(144, calldataload(add(encoded.offset, offset)))
919
+ }
920
+ }
921
+
922
+ function asUint112Cd(
923
+ bytes calldata encoded,
924
+ uint offset
925
+ ) internal pure returns (uint112 ret, uint nextOffset) {
926
+ (ret, nextOffset) = asUint112CdUnchecked(encoded, offset);
927
+ checkBound(nextOffset, encoded.length);
928
+ }
929
+
930
+ function asUint112MemUnchecked(
931
+ bytes memory encoded,
932
+ uint offset
933
+ ) internal pure returns (uint112 ret, uint nextOffset) {
934
+ /// @solidity memory-safe-assembly
935
+ assembly {
936
+ nextOffset := add(offset, 14)
937
+ ret := mload(add(encoded, nextOffset))
938
+ }
939
+ }
940
+
941
+ function asUint112Mem(
942
+ bytes memory encoded,
943
+ uint offset
944
+ ) internal pure returns (uint112 ret, uint nextOffset) {
945
+ (ret, nextOffset) = asUint112MemUnchecked(encoded, offset);
946
+ checkBound(nextOffset, encoded.length);
947
+ }
948
+
949
+ function asUint120CdUnchecked(
950
+ bytes calldata encoded,
951
+ uint offset
952
+ ) internal pure returns (uint120 ret, uint nextOffset) {
953
+ /// @solidity memory-safe-assembly
954
+ assembly {
955
+ nextOffset := add(offset, 15)
956
+ ret := shr(136, calldataload(add(encoded.offset, offset)))
957
+ }
958
+ }
959
+
960
+ function asUint120Cd(
961
+ bytes calldata encoded,
962
+ uint offset
963
+ ) internal pure returns (uint120 ret, uint nextOffset) {
964
+ (ret, nextOffset) = asUint120CdUnchecked(encoded, offset);
965
+ checkBound(nextOffset, encoded.length);
966
+ }
967
+
968
+ function asUint120MemUnchecked(
969
+ bytes memory encoded,
970
+ uint offset
971
+ ) internal pure returns (uint120 ret, uint nextOffset) {
972
+ /// @solidity memory-safe-assembly
973
+ assembly {
974
+ nextOffset := add(offset, 15)
975
+ ret := mload(add(encoded, nextOffset))
976
+ }
977
+ }
978
+
979
+ function asUint120Mem(
980
+ bytes memory encoded,
981
+ uint offset
982
+ ) internal pure returns (uint120 ret, uint nextOffset) {
983
+ (ret, nextOffset) = asUint120MemUnchecked(encoded, offset);
984
+ checkBound(nextOffset, encoded.length);
985
+ }
986
+
987
+ function asUint128CdUnchecked(
988
+ bytes calldata encoded,
989
+ uint offset
990
+ ) internal pure returns (uint128 ret, uint nextOffset) {
991
+ /// @solidity memory-safe-assembly
992
+ assembly {
993
+ nextOffset := add(offset, 16)
994
+ ret := shr(128, calldataload(add(encoded.offset, offset)))
995
+ }
996
+ }
997
+
998
+ function asUint128Cd(
999
+ bytes calldata encoded,
1000
+ uint offset
1001
+ ) internal pure returns (uint128 ret, uint nextOffset) {
1002
+ (ret, nextOffset) = asUint128CdUnchecked(encoded, offset);
1003
+ checkBound(nextOffset, encoded.length);
1004
+ }
1005
+
1006
+ function asUint128MemUnchecked(
1007
+ bytes memory encoded,
1008
+ uint offset
1009
+ ) internal pure returns (uint128 ret, uint nextOffset) {
1010
+ /// @solidity memory-safe-assembly
1011
+ assembly {
1012
+ nextOffset := add(offset, 16)
1013
+ ret := mload(add(encoded, nextOffset))
1014
+ }
1015
+ }
1016
+
1017
+ function asUint128Mem(
1018
+ bytes memory encoded,
1019
+ uint offset
1020
+ ) internal pure returns (uint128 ret, uint nextOffset) {
1021
+ (ret, nextOffset) = asUint128MemUnchecked(encoded, offset);
1022
+ checkBound(nextOffset, encoded.length);
1023
+ }
1024
+
1025
+ function asUint136CdUnchecked(
1026
+ bytes calldata encoded,
1027
+ uint offset
1028
+ ) internal pure returns (uint136 ret, uint nextOffset) {
1029
+ /// @solidity memory-safe-assembly
1030
+ assembly {
1031
+ nextOffset := add(offset, 17)
1032
+ ret := shr(120, calldataload(add(encoded.offset, offset)))
1033
+ }
1034
+ }
1035
+
1036
+ function asUint136Cd(
1037
+ bytes calldata encoded,
1038
+ uint offset
1039
+ ) internal pure returns (uint136 ret, uint nextOffset) {
1040
+ (ret, nextOffset) = asUint136CdUnchecked(encoded, offset);
1041
+ checkBound(nextOffset, encoded.length);
1042
+ }
1043
+
1044
+ function asUint136MemUnchecked(
1045
+ bytes memory encoded,
1046
+ uint offset
1047
+ ) internal pure returns (uint136 ret, uint nextOffset) {
1048
+ /// @solidity memory-safe-assembly
1049
+ assembly {
1050
+ nextOffset := add(offset, 17)
1051
+ ret := mload(add(encoded, nextOffset))
1052
+ }
1053
+ }
1054
+
1055
+ function asUint136Mem(
1056
+ bytes memory encoded,
1057
+ uint offset
1058
+ ) internal pure returns (uint136 ret, uint nextOffset) {
1059
+ (ret, nextOffset) = asUint136MemUnchecked(encoded, offset);
1060
+ checkBound(nextOffset, encoded.length);
1061
+ }
1062
+
1063
+ function asUint144CdUnchecked(
1064
+ bytes calldata encoded,
1065
+ uint offset
1066
+ ) internal pure returns (uint144 ret, uint nextOffset) {
1067
+ /// @solidity memory-safe-assembly
1068
+ assembly {
1069
+ nextOffset := add(offset, 18)
1070
+ ret := shr(112, calldataload(add(encoded.offset, offset)))
1071
+ }
1072
+ }
1073
+
1074
+ function asUint144Cd(
1075
+ bytes calldata encoded,
1076
+ uint offset
1077
+ ) internal pure returns (uint144 ret, uint nextOffset) {
1078
+ (ret, nextOffset) = asUint144CdUnchecked(encoded, offset);
1079
+ checkBound(nextOffset, encoded.length);
1080
+ }
1081
+
1082
+ function asUint144MemUnchecked(
1083
+ bytes memory encoded,
1084
+ uint offset
1085
+ ) internal pure returns (uint144 ret, uint nextOffset) {
1086
+ /// @solidity memory-safe-assembly
1087
+ assembly {
1088
+ nextOffset := add(offset, 18)
1089
+ ret := mload(add(encoded, nextOffset))
1090
+ }
1091
+ }
1092
+
1093
+ function asUint144Mem(
1094
+ bytes memory encoded,
1095
+ uint offset
1096
+ ) internal pure returns (uint144 ret, uint nextOffset) {
1097
+ (ret, nextOffset) = asUint144MemUnchecked(encoded, offset);
1098
+ checkBound(nextOffset, encoded.length);
1099
+ }
1100
+
1101
+ function asUint152CdUnchecked(
1102
+ bytes calldata encoded,
1103
+ uint offset
1104
+ ) internal pure returns (uint152 ret, uint nextOffset) {
1105
+ /// @solidity memory-safe-assembly
1106
+ assembly {
1107
+ nextOffset := add(offset, 19)
1108
+ ret := shr(104, calldataload(add(encoded.offset, offset)))
1109
+ }
1110
+ }
1111
+
1112
+ function asUint152Cd(
1113
+ bytes calldata encoded,
1114
+ uint offset
1115
+ ) internal pure returns (uint152 ret, uint nextOffset) {
1116
+ (ret, nextOffset) = asUint152CdUnchecked(encoded, offset);
1117
+ checkBound(nextOffset, encoded.length);
1118
+ }
1119
+
1120
+ function asUint152MemUnchecked(
1121
+ bytes memory encoded,
1122
+ uint offset
1123
+ ) internal pure returns (uint152 ret, uint nextOffset) {
1124
+ /// @solidity memory-safe-assembly
1125
+ assembly {
1126
+ nextOffset := add(offset, 19)
1127
+ ret := mload(add(encoded, nextOffset))
1128
+ }
1129
+ }
1130
+
1131
+ function asUint152Mem(
1132
+ bytes memory encoded,
1133
+ uint offset
1134
+ ) internal pure returns (uint152 ret, uint nextOffset) {
1135
+ (ret, nextOffset) = asUint152MemUnchecked(encoded, offset);
1136
+ checkBound(nextOffset, encoded.length);
1137
+ }
1138
+
1139
+ function asUint160CdUnchecked(
1140
+ bytes calldata encoded,
1141
+ uint offset
1142
+ ) internal pure returns (uint160 ret, uint nextOffset) {
1143
+ /// @solidity memory-safe-assembly
1144
+ assembly {
1145
+ nextOffset := add(offset, 20)
1146
+ ret := shr(96, calldataload(add(encoded.offset, offset)))
1147
+ }
1148
+ }
1149
+
1150
+ function asUint160Cd(
1151
+ bytes calldata encoded,
1152
+ uint offset
1153
+ ) internal pure returns (uint160 ret, uint nextOffset) {
1154
+ (ret, nextOffset) = asUint160CdUnchecked(encoded, offset);
1155
+ checkBound(nextOffset, encoded.length);
1156
+ }
1157
+
1158
+ function asUint160MemUnchecked(
1159
+ bytes memory encoded,
1160
+ uint offset
1161
+ ) internal pure returns (uint160 ret, uint nextOffset) {
1162
+ /// @solidity memory-safe-assembly
1163
+ assembly {
1164
+ nextOffset := add(offset, 20)
1165
+ ret := mload(add(encoded, nextOffset))
1166
+ }
1167
+ }
1168
+
1169
+ function asUint160Mem(
1170
+ bytes memory encoded,
1171
+ uint offset
1172
+ ) internal pure returns (uint160 ret, uint nextOffset) {
1173
+ (ret, nextOffset) = asUint160MemUnchecked(encoded, offset);
1174
+ checkBound(nextOffset, encoded.length);
1175
+ }
1176
+
1177
+ function asUint168CdUnchecked(
1178
+ bytes calldata encoded,
1179
+ uint offset
1180
+ ) internal pure returns (uint168 ret, uint nextOffset) {
1181
+ /// @solidity memory-safe-assembly
1182
+ assembly {
1183
+ nextOffset := add(offset, 21)
1184
+ ret := shr(88, calldataload(add(encoded.offset, offset)))
1185
+ }
1186
+ }
1187
+
1188
+ function asUint168Cd(
1189
+ bytes calldata encoded,
1190
+ uint offset
1191
+ ) internal pure returns (uint168 ret, uint nextOffset) {
1192
+ (ret, nextOffset) = asUint168CdUnchecked(encoded, offset);
1193
+ checkBound(nextOffset, encoded.length);
1194
+ }
1195
+
1196
+ function asUint168MemUnchecked(
1197
+ bytes memory encoded,
1198
+ uint offset
1199
+ ) internal pure returns (uint168 ret, uint nextOffset) {
1200
+ /// @solidity memory-safe-assembly
1201
+ assembly {
1202
+ nextOffset := add(offset, 21)
1203
+ ret := mload(add(encoded, nextOffset))
1204
+ }
1205
+ }
1206
+
1207
+ function asUint168Mem(
1208
+ bytes memory encoded,
1209
+ uint offset
1210
+ ) internal pure returns (uint168 ret, uint nextOffset) {
1211
+ (ret, nextOffset) = asUint168MemUnchecked(encoded, offset);
1212
+ checkBound(nextOffset, encoded.length);
1213
+ }
1214
+
1215
+ function asUint176CdUnchecked(
1216
+ bytes calldata encoded,
1217
+ uint offset
1218
+ ) internal pure returns (uint176 ret, uint nextOffset) {
1219
+ /// @solidity memory-safe-assembly
1220
+ assembly {
1221
+ nextOffset := add(offset, 22)
1222
+ ret := shr(80, calldataload(add(encoded.offset, offset)))
1223
+ }
1224
+ }
1225
+
1226
+ function asUint176Cd(
1227
+ bytes calldata encoded,
1228
+ uint offset
1229
+ ) internal pure returns (uint176 ret, uint nextOffset) {
1230
+ (ret, nextOffset) = asUint176CdUnchecked(encoded, offset);
1231
+ checkBound(nextOffset, encoded.length);
1232
+ }
1233
+
1234
+ function asUint176MemUnchecked(
1235
+ bytes memory encoded,
1236
+ uint offset
1237
+ ) internal pure returns (uint176 ret, uint nextOffset) {
1238
+ /// @solidity memory-safe-assembly
1239
+ assembly {
1240
+ nextOffset := add(offset, 22)
1241
+ ret := mload(add(encoded, nextOffset))
1242
+ }
1243
+ }
1244
+
1245
+ function asUint176Mem(
1246
+ bytes memory encoded,
1247
+ uint offset
1248
+ ) internal pure returns (uint176 ret, uint nextOffset) {
1249
+ (ret, nextOffset) = asUint176MemUnchecked(encoded, offset);
1250
+ checkBound(nextOffset, encoded.length);
1251
+ }
1252
+
1253
+ function asUint184CdUnchecked(
1254
+ bytes calldata encoded,
1255
+ uint offset
1256
+ ) internal pure returns (uint184 ret, uint nextOffset) {
1257
+ /// @solidity memory-safe-assembly
1258
+ assembly {
1259
+ nextOffset := add(offset, 23)
1260
+ ret := shr(72, calldataload(add(encoded.offset, offset)))
1261
+ }
1262
+ }
1263
+
1264
+ function asUint184Cd(
1265
+ bytes calldata encoded,
1266
+ uint offset
1267
+ ) internal pure returns (uint184 ret, uint nextOffset) {
1268
+ (ret, nextOffset) = asUint184CdUnchecked(encoded, offset);
1269
+ checkBound(nextOffset, encoded.length);
1270
+ }
1271
+
1272
+ function asUint184MemUnchecked(
1273
+ bytes memory encoded,
1274
+ uint offset
1275
+ ) internal pure returns (uint184 ret, uint nextOffset) {
1276
+ /// @solidity memory-safe-assembly
1277
+ assembly {
1278
+ nextOffset := add(offset, 23)
1279
+ ret := mload(add(encoded, nextOffset))
1280
+ }
1281
+ }
1282
+
1283
+ function asUint184Mem(
1284
+ bytes memory encoded,
1285
+ uint offset
1286
+ ) internal pure returns (uint184 ret, uint nextOffset) {
1287
+ (ret, nextOffset) = asUint184MemUnchecked(encoded, offset);
1288
+ checkBound(nextOffset, encoded.length);
1289
+ }
1290
+
1291
+ function asUint192CdUnchecked(
1292
+ bytes calldata encoded,
1293
+ uint offset
1294
+ ) internal pure returns (uint192 ret, uint nextOffset) {
1295
+ /// @solidity memory-safe-assembly
1296
+ assembly {
1297
+ nextOffset := add(offset, 24)
1298
+ ret := shr(64, calldataload(add(encoded.offset, offset)))
1299
+ }
1300
+ }
1301
+
1302
+ function asUint192Cd(
1303
+ bytes calldata encoded,
1304
+ uint offset
1305
+ ) internal pure returns (uint192 ret, uint nextOffset) {
1306
+ (ret, nextOffset) = asUint192CdUnchecked(encoded, offset);
1307
+ checkBound(nextOffset, encoded.length);
1308
+ }
1309
+
1310
+ function asUint192MemUnchecked(
1311
+ bytes memory encoded,
1312
+ uint offset
1313
+ ) internal pure returns (uint192 ret, uint nextOffset) {
1314
+ /// @solidity memory-safe-assembly
1315
+ assembly {
1316
+ nextOffset := add(offset, 24)
1317
+ ret := mload(add(encoded, nextOffset))
1318
+ }
1319
+ }
1320
+
1321
+ function asUint192Mem(
1322
+ bytes memory encoded,
1323
+ uint offset
1324
+ ) internal pure returns (uint192 ret, uint nextOffset) {
1325
+ (ret, nextOffset) = asUint192MemUnchecked(encoded, offset);
1326
+ checkBound(nextOffset, encoded.length);
1327
+ }
1328
+
1329
+ function asUint200CdUnchecked(
1330
+ bytes calldata encoded,
1331
+ uint offset
1332
+ ) internal pure returns (uint200 ret, uint nextOffset) {
1333
+ /// @solidity memory-safe-assembly
1334
+ assembly {
1335
+ nextOffset := add(offset, 25)
1336
+ ret := shr(56, calldataload(add(encoded.offset, offset)))
1337
+ }
1338
+ }
1339
+
1340
+ function asUint200Cd(
1341
+ bytes calldata encoded,
1342
+ uint offset
1343
+ ) internal pure returns (uint200 ret, uint nextOffset) {
1344
+ (ret, nextOffset) = asUint200CdUnchecked(encoded, offset);
1345
+ checkBound(nextOffset, encoded.length);
1346
+ }
1347
+
1348
+ function asUint200MemUnchecked(
1349
+ bytes memory encoded,
1350
+ uint offset
1351
+ ) internal pure returns (uint200 ret, uint nextOffset) {
1352
+ /// @solidity memory-safe-assembly
1353
+ assembly {
1354
+ nextOffset := add(offset, 25)
1355
+ ret := mload(add(encoded, nextOffset))
1356
+ }
1357
+ }
1358
+
1359
+ function asUint200Mem(
1360
+ bytes memory encoded,
1361
+ uint offset
1362
+ ) internal pure returns (uint200 ret, uint nextOffset) {
1363
+ (ret, nextOffset) = asUint200MemUnchecked(encoded, offset);
1364
+ checkBound(nextOffset, encoded.length);
1365
+ }
1366
+
1367
+ function asUint208CdUnchecked(
1368
+ bytes calldata encoded,
1369
+ uint offset
1370
+ ) internal pure returns (uint208 ret, uint nextOffset) {
1371
+ /// @solidity memory-safe-assembly
1372
+ assembly {
1373
+ nextOffset := add(offset, 26)
1374
+ ret := shr(48, calldataload(add(encoded.offset, offset)))
1375
+ }
1376
+ }
1377
+
1378
+ function asUint208Cd(
1379
+ bytes calldata encoded,
1380
+ uint offset
1381
+ ) internal pure returns (uint208 ret, uint nextOffset) {
1382
+ (ret, nextOffset) = asUint208CdUnchecked(encoded, offset);
1383
+ checkBound(nextOffset, encoded.length);
1384
+ }
1385
+
1386
+ function asUint208MemUnchecked(
1387
+ bytes memory encoded,
1388
+ uint offset
1389
+ ) internal pure returns (uint208 ret, uint nextOffset) {
1390
+ /// @solidity memory-safe-assembly
1391
+ assembly {
1392
+ nextOffset := add(offset, 26)
1393
+ ret := mload(add(encoded, nextOffset))
1394
+ }
1395
+ }
1396
+
1397
+ function asUint208Mem(
1398
+ bytes memory encoded,
1399
+ uint offset
1400
+ ) internal pure returns (uint208 ret, uint nextOffset) {
1401
+ (ret, nextOffset) = asUint208MemUnchecked(encoded, offset);
1402
+ checkBound(nextOffset, encoded.length);
1403
+ }
1404
+
1405
+ function asUint216CdUnchecked(
1406
+ bytes calldata encoded,
1407
+ uint offset
1408
+ ) internal pure returns (uint216 ret, uint nextOffset) {
1409
+ /// @solidity memory-safe-assembly
1410
+ assembly {
1411
+ nextOffset := add(offset, 27)
1412
+ ret := shr(40, calldataload(add(encoded.offset, offset)))
1413
+ }
1414
+ }
1415
+
1416
+ function asUint216Cd(
1417
+ bytes calldata encoded,
1418
+ uint offset
1419
+ ) internal pure returns (uint216 ret, uint nextOffset) {
1420
+ (ret, nextOffset) = asUint216CdUnchecked(encoded, offset);
1421
+ checkBound(nextOffset, encoded.length);
1422
+ }
1423
+
1424
+ function asUint216MemUnchecked(
1425
+ bytes memory encoded,
1426
+ uint offset
1427
+ ) internal pure returns (uint216 ret, uint nextOffset) {
1428
+ /// @solidity memory-safe-assembly
1429
+ assembly {
1430
+ nextOffset := add(offset, 27)
1431
+ ret := mload(add(encoded, nextOffset))
1432
+ }
1433
+ }
1434
+
1435
+ function asUint216Mem(
1436
+ bytes memory encoded,
1437
+ uint offset
1438
+ ) internal pure returns (uint216 ret, uint nextOffset) {
1439
+ (ret, nextOffset) = asUint216MemUnchecked(encoded, offset);
1440
+ checkBound(nextOffset, encoded.length);
1441
+ }
1442
+
1443
+ function asUint224CdUnchecked(
1444
+ bytes calldata encoded,
1445
+ uint offset
1446
+ ) internal pure returns (uint224 ret, uint nextOffset) {
1447
+ /// @solidity memory-safe-assembly
1448
+ assembly {
1449
+ nextOffset := add(offset, 28)
1450
+ ret := shr(32, calldataload(add(encoded.offset, offset)))
1451
+ }
1452
+ }
1453
+
1454
+ function asUint224Cd(
1455
+ bytes calldata encoded,
1456
+ uint offset
1457
+ ) internal pure returns (uint224 ret, uint nextOffset) {
1458
+ (ret, nextOffset) = asUint224CdUnchecked(encoded, offset);
1459
+ checkBound(nextOffset, encoded.length);
1460
+ }
1461
+
1462
+ function asUint224MemUnchecked(
1463
+ bytes memory encoded,
1464
+ uint offset
1465
+ ) internal pure returns (uint224 ret, uint nextOffset) {
1466
+ /// @solidity memory-safe-assembly
1467
+ assembly {
1468
+ nextOffset := add(offset, 28)
1469
+ ret := mload(add(encoded, nextOffset))
1470
+ }
1471
+ }
1472
+
1473
+ function asUint224Mem(
1474
+ bytes memory encoded,
1475
+ uint offset
1476
+ ) internal pure returns (uint224 ret, uint nextOffset) {
1477
+ (ret, nextOffset) = asUint224MemUnchecked(encoded, offset);
1478
+ checkBound(nextOffset, encoded.length);
1479
+ }
1480
+
1481
+ function asUint232CdUnchecked(
1482
+ bytes calldata encoded,
1483
+ uint offset
1484
+ ) internal pure returns (uint232 ret, uint nextOffset) {
1485
+ /// @solidity memory-safe-assembly
1486
+ assembly {
1487
+ nextOffset := add(offset, 29)
1488
+ ret := shr(24, calldataload(add(encoded.offset, offset)))
1489
+ }
1490
+ }
1491
+
1492
+ function asUint232Cd(
1493
+ bytes calldata encoded,
1494
+ uint offset
1495
+ ) internal pure returns (uint232 ret, uint nextOffset) {
1496
+ (ret, nextOffset) = asUint232CdUnchecked(encoded, offset);
1497
+ checkBound(nextOffset, encoded.length);
1498
+ }
1499
+
1500
+ function asUint232MemUnchecked(
1501
+ bytes memory encoded,
1502
+ uint offset
1503
+ ) internal pure returns (uint232 ret, uint nextOffset) {
1504
+ /// @solidity memory-safe-assembly
1505
+ assembly {
1506
+ nextOffset := add(offset, 29)
1507
+ ret := mload(add(encoded, nextOffset))
1508
+ }
1509
+ }
1510
+
1511
+ function asUint232Mem(
1512
+ bytes memory encoded,
1513
+ uint offset
1514
+ ) internal pure returns (uint232 ret, uint nextOffset) {
1515
+ (ret, nextOffset) = asUint232MemUnchecked(encoded, offset);
1516
+ checkBound(nextOffset, encoded.length);
1517
+ }
1518
+
1519
+ function asUint240CdUnchecked(
1520
+ bytes calldata encoded,
1521
+ uint offset
1522
+ ) internal pure returns (uint240 ret, uint nextOffset) {
1523
+ /// @solidity memory-safe-assembly
1524
+ assembly {
1525
+ nextOffset := add(offset, 30)
1526
+ ret := shr(16, calldataload(add(encoded.offset, offset)))
1527
+ }
1528
+ }
1529
+
1530
+ function asUint240Cd(
1531
+ bytes calldata encoded,
1532
+ uint offset
1533
+ ) internal pure returns (uint240 ret, uint nextOffset) {
1534
+ (ret, nextOffset) = asUint240CdUnchecked(encoded, offset);
1535
+ checkBound(nextOffset, encoded.length);
1536
+ }
1537
+
1538
+ function asUint240MemUnchecked(
1539
+ bytes memory encoded,
1540
+ uint offset
1541
+ ) internal pure returns (uint240 ret, uint nextOffset) {
1542
+ /// @solidity memory-safe-assembly
1543
+ assembly {
1544
+ nextOffset := add(offset, 30)
1545
+ ret := mload(add(encoded, nextOffset))
1546
+ }
1547
+ }
1548
+
1549
+ function asUint240Mem(
1550
+ bytes memory encoded,
1551
+ uint offset
1552
+ ) internal pure returns (uint240 ret, uint nextOffset) {
1553
+ (ret, nextOffset) = asUint240MemUnchecked(encoded, offset);
1554
+ checkBound(nextOffset, encoded.length);
1555
+ }
1556
+
1557
+ function asUint248CdUnchecked(
1558
+ bytes calldata encoded,
1559
+ uint offset
1560
+ ) internal pure returns (uint248 ret, uint nextOffset) {
1561
+ /// @solidity memory-safe-assembly
1562
+ assembly {
1563
+ nextOffset := add(offset, 31)
1564
+ ret := shr(8, calldataload(add(encoded.offset, offset)))
1565
+ }
1566
+ }
1567
+
1568
+ function asUint248Cd(
1569
+ bytes calldata encoded,
1570
+ uint offset
1571
+ ) internal pure returns (uint248 ret, uint nextOffset) {
1572
+ (ret, nextOffset) = asUint248CdUnchecked(encoded, offset);
1573
+ checkBound(nextOffset, encoded.length);
1574
+ }
1575
+
1576
+ function asUint248MemUnchecked(
1577
+ bytes memory encoded,
1578
+ uint offset
1579
+ ) internal pure returns (uint248 ret, uint nextOffset) {
1580
+ /// @solidity memory-safe-assembly
1581
+ assembly {
1582
+ nextOffset := add(offset, 31)
1583
+ ret := mload(add(encoded, nextOffset))
1584
+ }
1585
+ }
1586
+
1587
+ function asUint248Mem(
1588
+ bytes memory encoded,
1589
+ uint offset
1590
+ ) internal pure returns (uint248 ret, uint nextOffset) {
1591
+ (ret, nextOffset) = asUint248MemUnchecked(encoded, offset);
1592
+ checkBound(nextOffset, encoded.length);
1593
+ }
1594
+
1595
+ function asUint256CdUnchecked(
1596
+ bytes calldata encoded,
1597
+ uint offset
1598
+ ) internal pure returns (uint256 ret, uint nextOffset) {
1599
+ /// @solidity memory-safe-assembly
1600
+ assembly {
1601
+ nextOffset := add(offset, 32)
1602
+ ret := shr(0, calldataload(add(encoded.offset, offset)))
1603
+ }
1604
+ }
1605
+
1606
+ function asUint256Cd(
1607
+ bytes calldata encoded,
1608
+ uint offset
1609
+ ) internal pure returns (uint256 ret, uint nextOffset) {
1610
+ (ret, nextOffset) = asUint256CdUnchecked(encoded, offset);
1611
+ checkBound(nextOffset, encoded.length);
1612
+ }
1613
+
1614
+ function asUint256MemUnchecked(
1615
+ bytes memory encoded,
1616
+ uint offset
1617
+ ) internal pure returns (uint256 ret, uint nextOffset) {
1618
+ /// @solidity memory-safe-assembly
1619
+ assembly {
1620
+ nextOffset := add(offset, 32)
1621
+ ret := mload(add(encoded, nextOffset))
1622
+ }
1623
+ }
1624
+
1625
+ function asUint256Mem(
1626
+ bytes memory encoded,
1627
+ uint offset
1628
+ ) internal pure returns (uint256 ret, uint nextOffset) {
1629
+ (ret, nextOffset) = asUint256MemUnchecked(encoded, offset);
1630
+ checkBound(nextOffset, encoded.length);
1631
+ }
1632
+
1633
+ function asBytes1CdUnchecked(
1634
+ bytes calldata encoded,
1635
+ uint offset
1636
+ ) internal pure returns (bytes1 ret, uint nextOffset) {
1637
+ /// @solidity memory-safe-assembly
1638
+ assembly {
1639
+ ret := calldataload(add(encoded.offset, offset))
1640
+ nextOffset := add(offset, 1)
1641
+ }
1642
+ }
1643
+
1644
+ function asBytes1Cd(
1645
+ bytes calldata encoded,
1646
+ uint offset
1647
+ ) internal pure returns (bytes1 ret, uint nextOffset) {
1648
+ (ret, nextOffset) = asBytes1CdUnchecked(encoded, offset);
1649
+ checkBound(nextOffset, encoded.length);
1650
+ }
1651
+
1652
+ function asBytes1MemUnchecked(
1653
+ bytes memory encoded,
1654
+ uint offset
1655
+ ) internal pure returns (bytes1 ret, uint nextOffset) {
1656
+ /// @solidity memory-safe-assembly
1657
+ assembly {
1658
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1659
+ nextOffset := add(offset, 1)
1660
+ }
1661
+ }
1662
+
1663
+ function asBytes1Mem(
1664
+ bytes memory encoded,
1665
+ uint offset
1666
+ ) internal pure returns (bytes1 ret, uint nextOffset) {
1667
+ (ret, nextOffset) = asBytes1MemUnchecked(encoded, offset);
1668
+ checkBound(nextOffset, encoded.length);
1669
+ }
1670
+
1671
+ function asBytes2CdUnchecked(
1672
+ bytes calldata encoded,
1673
+ uint offset
1674
+ ) internal pure returns (bytes2 ret, uint nextOffset) {
1675
+ /// @solidity memory-safe-assembly
1676
+ assembly {
1677
+ ret := calldataload(add(encoded.offset, offset))
1678
+ nextOffset := add(offset, 2)
1679
+ }
1680
+ }
1681
+
1682
+ function asBytes2Cd(
1683
+ bytes calldata encoded,
1684
+ uint offset
1685
+ ) internal pure returns (bytes2 ret, uint nextOffset) {
1686
+ (ret, nextOffset) = asBytes2CdUnchecked(encoded, offset);
1687
+ checkBound(nextOffset, encoded.length);
1688
+ }
1689
+
1690
+ function asBytes2MemUnchecked(
1691
+ bytes memory encoded,
1692
+ uint offset
1693
+ ) internal pure returns (bytes2 ret, uint nextOffset) {
1694
+ /// @solidity memory-safe-assembly
1695
+ assembly {
1696
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1697
+ nextOffset := add(offset, 2)
1698
+ }
1699
+ }
1700
+
1701
+ function asBytes2Mem(
1702
+ bytes memory encoded,
1703
+ uint offset
1704
+ ) internal pure returns (bytes2 ret, uint nextOffset) {
1705
+ (ret, nextOffset) = asBytes2MemUnchecked(encoded, offset);
1706
+ checkBound(nextOffset, encoded.length);
1707
+ }
1708
+
1709
+ function asBytes3CdUnchecked(
1710
+ bytes calldata encoded,
1711
+ uint offset
1712
+ ) internal pure returns (bytes3 ret, uint nextOffset) {
1713
+ /// @solidity memory-safe-assembly
1714
+ assembly {
1715
+ ret := calldataload(add(encoded.offset, offset))
1716
+ nextOffset := add(offset, 3)
1717
+ }
1718
+ }
1719
+
1720
+ function asBytes3Cd(
1721
+ bytes calldata encoded,
1722
+ uint offset
1723
+ ) internal pure returns (bytes3 ret, uint nextOffset) {
1724
+ (ret, nextOffset) = asBytes3CdUnchecked(encoded, offset);
1725
+ checkBound(nextOffset, encoded.length);
1726
+ }
1727
+
1728
+ function asBytes3MemUnchecked(
1729
+ bytes memory encoded,
1730
+ uint offset
1731
+ ) internal pure returns (bytes3 ret, uint nextOffset) {
1732
+ /// @solidity memory-safe-assembly
1733
+ assembly {
1734
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1735
+ nextOffset := add(offset, 3)
1736
+ }
1737
+ }
1738
+
1739
+ function asBytes3Mem(
1740
+ bytes memory encoded,
1741
+ uint offset
1742
+ ) internal pure returns (bytes3 ret, uint nextOffset) {
1743
+ (ret, nextOffset) = asBytes3MemUnchecked(encoded, offset);
1744
+ checkBound(nextOffset, encoded.length);
1745
+ }
1746
+
1747
+ function asBytes4CdUnchecked(
1748
+ bytes calldata encoded,
1749
+ uint offset
1750
+ ) internal pure returns (bytes4 ret, uint nextOffset) {
1751
+ /// @solidity memory-safe-assembly
1752
+ assembly {
1753
+ ret := calldataload(add(encoded.offset, offset))
1754
+ nextOffset := add(offset, 4)
1755
+ }
1756
+ }
1757
+
1758
+ function asBytes4Cd(
1759
+ bytes calldata encoded,
1760
+ uint offset
1761
+ ) internal pure returns (bytes4 ret, uint nextOffset) {
1762
+ (ret, nextOffset) = asBytes4CdUnchecked(encoded, offset);
1763
+ checkBound(nextOffset, encoded.length);
1764
+ }
1765
+
1766
+ function asBytes4MemUnchecked(
1767
+ bytes memory encoded,
1768
+ uint offset
1769
+ ) internal pure returns (bytes4 ret, uint nextOffset) {
1770
+ /// @solidity memory-safe-assembly
1771
+ assembly {
1772
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1773
+ nextOffset := add(offset, 4)
1774
+ }
1775
+ }
1776
+
1777
+ function asBytes4Mem(
1778
+ bytes memory encoded,
1779
+ uint offset
1780
+ ) internal pure returns (bytes4 ret, uint nextOffset) {
1781
+ (ret, nextOffset) = asBytes4MemUnchecked(encoded, offset);
1782
+ checkBound(nextOffset, encoded.length);
1783
+ }
1784
+
1785
+ function asBytes5CdUnchecked(
1786
+ bytes calldata encoded,
1787
+ uint offset
1788
+ ) internal pure returns (bytes5 ret, uint nextOffset) {
1789
+ /// @solidity memory-safe-assembly
1790
+ assembly {
1791
+ ret := calldataload(add(encoded.offset, offset))
1792
+ nextOffset := add(offset, 5)
1793
+ }
1794
+ }
1795
+
1796
+ function asBytes5Cd(
1797
+ bytes calldata encoded,
1798
+ uint offset
1799
+ ) internal pure returns (bytes5 ret, uint nextOffset) {
1800
+ (ret, nextOffset) = asBytes5CdUnchecked(encoded, offset);
1801
+ checkBound(nextOffset, encoded.length);
1802
+ }
1803
+
1804
+ function asBytes5MemUnchecked(
1805
+ bytes memory encoded,
1806
+ uint offset
1807
+ ) internal pure returns (bytes5 ret, uint nextOffset) {
1808
+ /// @solidity memory-safe-assembly
1809
+ assembly {
1810
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1811
+ nextOffset := add(offset, 5)
1812
+ }
1813
+ }
1814
+
1815
+ function asBytes5Mem(
1816
+ bytes memory encoded,
1817
+ uint offset
1818
+ ) internal pure returns (bytes5 ret, uint nextOffset) {
1819
+ (ret, nextOffset) = asBytes5MemUnchecked(encoded, offset);
1820
+ checkBound(nextOffset, encoded.length);
1821
+ }
1822
+
1823
+ function asBytes6CdUnchecked(
1824
+ bytes calldata encoded,
1825
+ uint offset
1826
+ ) internal pure returns (bytes6 ret, uint nextOffset) {
1827
+ /// @solidity memory-safe-assembly
1828
+ assembly {
1829
+ ret := calldataload(add(encoded.offset, offset))
1830
+ nextOffset := add(offset, 6)
1831
+ }
1832
+ }
1833
+
1834
+ function asBytes6Cd(
1835
+ bytes calldata encoded,
1836
+ uint offset
1837
+ ) internal pure returns (bytes6 ret, uint nextOffset) {
1838
+ (ret, nextOffset) = asBytes6CdUnchecked(encoded, offset);
1839
+ checkBound(nextOffset, encoded.length);
1840
+ }
1841
+
1842
+ function asBytes6MemUnchecked(
1843
+ bytes memory encoded,
1844
+ uint offset
1845
+ ) internal pure returns (bytes6 ret, uint nextOffset) {
1846
+ /// @solidity memory-safe-assembly
1847
+ assembly {
1848
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1849
+ nextOffset := add(offset, 6)
1850
+ }
1851
+ }
1852
+
1853
+ function asBytes6Mem(
1854
+ bytes memory encoded,
1855
+ uint offset
1856
+ ) internal pure returns (bytes6 ret, uint nextOffset) {
1857
+ (ret, nextOffset) = asBytes6MemUnchecked(encoded, offset);
1858
+ checkBound(nextOffset, encoded.length);
1859
+ }
1860
+
1861
+ function asBytes7CdUnchecked(
1862
+ bytes calldata encoded,
1863
+ uint offset
1864
+ ) internal pure returns (bytes7 ret, uint nextOffset) {
1865
+ /// @solidity memory-safe-assembly
1866
+ assembly {
1867
+ ret := calldataload(add(encoded.offset, offset))
1868
+ nextOffset := add(offset, 7)
1869
+ }
1870
+ }
1871
+
1872
+ function asBytes7Cd(
1873
+ bytes calldata encoded,
1874
+ uint offset
1875
+ ) internal pure returns (bytes7 ret, uint nextOffset) {
1876
+ (ret, nextOffset) = asBytes7CdUnchecked(encoded, offset);
1877
+ checkBound(nextOffset, encoded.length);
1878
+ }
1879
+
1880
+ function asBytes7MemUnchecked(
1881
+ bytes memory encoded,
1882
+ uint offset
1883
+ ) internal pure returns (bytes7 ret, uint nextOffset) {
1884
+ /// @solidity memory-safe-assembly
1885
+ assembly {
1886
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1887
+ nextOffset := add(offset, 7)
1888
+ }
1889
+ }
1890
+
1891
+ function asBytes7Mem(
1892
+ bytes memory encoded,
1893
+ uint offset
1894
+ ) internal pure returns (bytes7 ret, uint nextOffset) {
1895
+ (ret, nextOffset) = asBytes7MemUnchecked(encoded, offset);
1896
+ checkBound(nextOffset, encoded.length);
1897
+ }
1898
+
1899
+ function asBytes8CdUnchecked(
1900
+ bytes calldata encoded,
1901
+ uint offset
1902
+ ) internal pure returns (bytes8 ret, uint nextOffset) {
1903
+ /// @solidity memory-safe-assembly
1904
+ assembly {
1905
+ ret := calldataload(add(encoded.offset, offset))
1906
+ nextOffset := add(offset, 8)
1907
+ }
1908
+ }
1909
+
1910
+ function asBytes8Cd(
1911
+ bytes calldata encoded,
1912
+ uint offset
1913
+ ) internal pure returns (bytes8 ret, uint nextOffset) {
1914
+ (ret, nextOffset) = asBytes8CdUnchecked(encoded, offset);
1915
+ checkBound(nextOffset, encoded.length);
1916
+ }
1917
+
1918
+ function asBytes8MemUnchecked(
1919
+ bytes memory encoded,
1920
+ uint offset
1921
+ ) internal pure returns (bytes8 ret, uint nextOffset) {
1922
+ /// @solidity memory-safe-assembly
1923
+ assembly {
1924
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1925
+ nextOffset := add(offset, 8)
1926
+ }
1927
+ }
1928
+
1929
+ function asBytes8Mem(
1930
+ bytes memory encoded,
1931
+ uint offset
1932
+ ) internal pure returns (bytes8 ret, uint nextOffset) {
1933
+ (ret, nextOffset) = asBytes8MemUnchecked(encoded, offset);
1934
+ checkBound(nextOffset, encoded.length);
1935
+ }
1936
+
1937
+ function asBytes9CdUnchecked(
1938
+ bytes calldata encoded,
1939
+ uint offset
1940
+ ) internal pure returns (bytes9 ret, uint nextOffset) {
1941
+ /// @solidity memory-safe-assembly
1942
+ assembly {
1943
+ ret := calldataload(add(encoded.offset, offset))
1944
+ nextOffset := add(offset, 9)
1945
+ }
1946
+ }
1947
+
1948
+ function asBytes9Cd(
1949
+ bytes calldata encoded,
1950
+ uint offset
1951
+ ) internal pure returns (bytes9 ret, uint nextOffset) {
1952
+ (ret, nextOffset) = asBytes9CdUnchecked(encoded, offset);
1953
+ checkBound(nextOffset, encoded.length);
1954
+ }
1955
+
1956
+ function asBytes9MemUnchecked(
1957
+ bytes memory encoded,
1958
+ uint offset
1959
+ ) internal pure returns (bytes9 ret, uint nextOffset) {
1960
+ /// @solidity memory-safe-assembly
1961
+ assembly {
1962
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
1963
+ nextOffset := add(offset, 9)
1964
+ }
1965
+ }
1966
+
1967
+ function asBytes9Mem(
1968
+ bytes memory encoded,
1969
+ uint offset
1970
+ ) internal pure returns (bytes9 ret, uint nextOffset) {
1971
+ (ret, nextOffset) = asBytes9MemUnchecked(encoded, offset);
1972
+ checkBound(nextOffset, encoded.length);
1973
+ }
1974
+
1975
+ function asBytes10CdUnchecked(
1976
+ bytes calldata encoded,
1977
+ uint offset
1978
+ ) internal pure returns (bytes10 ret, uint nextOffset) {
1979
+ /// @solidity memory-safe-assembly
1980
+ assembly {
1981
+ ret := calldataload(add(encoded.offset, offset))
1982
+ nextOffset := add(offset, 10)
1983
+ }
1984
+ }
1985
+
1986
+ function asBytes10Cd(
1987
+ bytes calldata encoded,
1988
+ uint offset
1989
+ ) internal pure returns (bytes10 ret, uint nextOffset) {
1990
+ (ret, nextOffset) = asBytes10CdUnchecked(encoded, offset);
1991
+ checkBound(nextOffset, encoded.length);
1992
+ }
1993
+
1994
+ function asBytes10MemUnchecked(
1995
+ bytes memory encoded,
1996
+ uint offset
1997
+ ) internal pure returns (bytes10 ret, uint nextOffset) {
1998
+ /// @solidity memory-safe-assembly
1999
+ assembly {
2000
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2001
+ nextOffset := add(offset, 10)
2002
+ }
2003
+ }
2004
+
2005
+ function asBytes10Mem(
2006
+ bytes memory encoded,
2007
+ uint offset
2008
+ ) internal pure returns (bytes10 ret, uint nextOffset) {
2009
+ (ret, nextOffset) = asBytes10MemUnchecked(encoded, offset);
2010
+ checkBound(nextOffset, encoded.length);
2011
+ }
2012
+
2013
+ function asBytes11CdUnchecked(
2014
+ bytes calldata encoded,
2015
+ uint offset
2016
+ ) internal pure returns (bytes11 ret, uint nextOffset) {
2017
+ /// @solidity memory-safe-assembly
2018
+ assembly {
2019
+ ret := calldataload(add(encoded.offset, offset))
2020
+ nextOffset := add(offset, 11)
2021
+ }
2022
+ }
2023
+
2024
+ function asBytes11Cd(
2025
+ bytes calldata encoded,
2026
+ uint offset
2027
+ ) internal pure returns (bytes11 ret, uint nextOffset) {
2028
+ (ret, nextOffset) = asBytes11CdUnchecked(encoded, offset);
2029
+ checkBound(nextOffset, encoded.length);
2030
+ }
2031
+
2032
+ function asBytes11MemUnchecked(
2033
+ bytes memory encoded,
2034
+ uint offset
2035
+ ) internal pure returns (bytes11 ret, uint nextOffset) {
2036
+ /// @solidity memory-safe-assembly
2037
+ assembly {
2038
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2039
+ nextOffset := add(offset, 11)
2040
+ }
2041
+ }
2042
+
2043
+ function asBytes11Mem(
2044
+ bytes memory encoded,
2045
+ uint offset
2046
+ ) internal pure returns (bytes11 ret, uint nextOffset) {
2047
+ (ret, nextOffset) = asBytes11MemUnchecked(encoded, offset);
2048
+ checkBound(nextOffset, encoded.length);
2049
+ }
2050
+
2051
+ function asBytes12CdUnchecked(
2052
+ bytes calldata encoded,
2053
+ uint offset
2054
+ ) internal pure returns (bytes12 ret, uint nextOffset) {
2055
+ /// @solidity memory-safe-assembly
2056
+ assembly {
2057
+ ret := calldataload(add(encoded.offset, offset))
2058
+ nextOffset := add(offset, 12)
2059
+ }
2060
+ }
2061
+
2062
+ function asBytes12Cd(
2063
+ bytes calldata encoded,
2064
+ uint offset
2065
+ ) internal pure returns (bytes12 ret, uint nextOffset) {
2066
+ (ret, nextOffset) = asBytes12CdUnchecked(encoded, offset);
2067
+ checkBound(nextOffset, encoded.length);
2068
+ }
2069
+
2070
+ function asBytes12MemUnchecked(
2071
+ bytes memory encoded,
2072
+ uint offset
2073
+ ) internal pure returns (bytes12 ret, uint nextOffset) {
2074
+ /// @solidity memory-safe-assembly
2075
+ assembly {
2076
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2077
+ nextOffset := add(offset, 12)
2078
+ }
2079
+ }
2080
+
2081
+ function asBytes12Mem(
2082
+ bytes memory encoded,
2083
+ uint offset
2084
+ ) internal pure returns (bytes12 ret, uint nextOffset) {
2085
+ (ret, nextOffset) = asBytes12MemUnchecked(encoded, offset);
2086
+ checkBound(nextOffset, encoded.length);
2087
+ }
2088
+
2089
+ function asBytes13CdUnchecked(
2090
+ bytes calldata encoded,
2091
+ uint offset
2092
+ ) internal pure returns (bytes13 ret, uint nextOffset) {
2093
+ /// @solidity memory-safe-assembly
2094
+ assembly {
2095
+ ret := calldataload(add(encoded.offset, offset))
2096
+ nextOffset := add(offset, 13)
2097
+ }
2098
+ }
2099
+
2100
+ function asBytes13Cd(
2101
+ bytes calldata encoded,
2102
+ uint offset
2103
+ ) internal pure returns (bytes13 ret, uint nextOffset) {
2104
+ (ret, nextOffset) = asBytes13CdUnchecked(encoded, offset);
2105
+ checkBound(nextOffset, encoded.length);
2106
+ }
2107
+
2108
+ function asBytes13MemUnchecked(
2109
+ bytes memory encoded,
2110
+ uint offset
2111
+ ) internal pure returns (bytes13 ret, uint nextOffset) {
2112
+ /// @solidity memory-safe-assembly
2113
+ assembly {
2114
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2115
+ nextOffset := add(offset, 13)
2116
+ }
2117
+ }
2118
+
2119
+ function asBytes13Mem(
2120
+ bytes memory encoded,
2121
+ uint offset
2122
+ ) internal pure returns (bytes13 ret, uint nextOffset) {
2123
+ (ret, nextOffset) = asBytes13MemUnchecked(encoded, offset);
2124
+ checkBound(nextOffset, encoded.length);
2125
+ }
2126
+
2127
+ function asBytes14CdUnchecked(
2128
+ bytes calldata encoded,
2129
+ uint offset
2130
+ ) internal pure returns (bytes14 ret, uint nextOffset) {
2131
+ /// @solidity memory-safe-assembly
2132
+ assembly {
2133
+ ret := calldataload(add(encoded.offset, offset))
2134
+ nextOffset := add(offset, 14)
2135
+ }
2136
+ }
2137
+
2138
+ function asBytes14Cd(
2139
+ bytes calldata encoded,
2140
+ uint offset
2141
+ ) internal pure returns (bytes14 ret, uint nextOffset) {
2142
+ (ret, nextOffset) = asBytes14CdUnchecked(encoded, offset);
2143
+ checkBound(nextOffset, encoded.length);
2144
+ }
2145
+
2146
+ function asBytes14MemUnchecked(
2147
+ bytes memory encoded,
2148
+ uint offset
2149
+ ) internal pure returns (bytes14 ret, uint nextOffset) {
2150
+ /// @solidity memory-safe-assembly
2151
+ assembly {
2152
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2153
+ nextOffset := add(offset, 14)
2154
+ }
2155
+ }
2156
+
2157
+ function asBytes14Mem(
2158
+ bytes memory encoded,
2159
+ uint offset
2160
+ ) internal pure returns (bytes14 ret, uint nextOffset) {
2161
+ (ret, nextOffset) = asBytes14MemUnchecked(encoded, offset);
2162
+ checkBound(nextOffset, encoded.length);
2163
+ }
2164
+
2165
+ function asBytes15CdUnchecked(
2166
+ bytes calldata encoded,
2167
+ uint offset
2168
+ ) internal pure returns (bytes15 ret, uint nextOffset) {
2169
+ /// @solidity memory-safe-assembly
2170
+ assembly {
2171
+ ret := calldataload(add(encoded.offset, offset))
2172
+ nextOffset := add(offset, 15)
2173
+ }
2174
+ }
2175
+
2176
+ function asBytes15Cd(
2177
+ bytes calldata encoded,
2178
+ uint offset
2179
+ ) internal pure returns (bytes15 ret, uint nextOffset) {
2180
+ (ret, nextOffset) = asBytes15CdUnchecked(encoded, offset);
2181
+ checkBound(nextOffset, encoded.length);
2182
+ }
2183
+
2184
+ function asBytes15MemUnchecked(
2185
+ bytes memory encoded,
2186
+ uint offset
2187
+ ) internal pure returns (bytes15 ret, uint nextOffset) {
2188
+ /// @solidity memory-safe-assembly
2189
+ assembly {
2190
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2191
+ nextOffset := add(offset, 15)
2192
+ }
2193
+ }
2194
+
2195
+ function asBytes15Mem(
2196
+ bytes memory encoded,
2197
+ uint offset
2198
+ ) internal pure returns (bytes15 ret, uint nextOffset) {
2199
+ (ret, nextOffset) = asBytes15MemUnchecked(encoded, offset);
2200
+ checkBound(nextOffset, encoded.length);
2201
+ }
2202
+
2203
+ function asBytes16CdUnchecked(
2204
+ bytes calldata encoded,
2205
+ uint offset
2206
+ ) internal pure returns (bytes16 ret, uint nextOffset) {
2207
+ /// @solidity memory-safe-assembly
2208
+ assembly {
2209
+ ret := calldataload(add(encoded.offset, offset))
2210
+ nextOffset := add(offset, 16)
2211
+ }
2212
+ }
2213
+
2214
+ function asBytes16Cd(
2215
+ bytes calldata encoded,
2216
+ uint offset
2217
+ ) internal pure returns (bytes16 ret, uint nextOffset) {
2218
+ (ret, nextOffset) = asBytes16CdUnchecked(encoded, offset);
2219
+ checkBound(nextOffset, encoded.length);
2220
+ }
2221
+
2222
+ function asBytes16MemUnchecked(
2223
+ bytes memory encoded,
2224
+ uint offset
2225
+ ) internal pure returns (bytes16 ret, uint nextOffset) {
2226
+ /// @solidity memory-safe-assembly
2227
+ assembly {
2228
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2229
+ nextOffset := add(offset, 16)
2230
+ }
2231
+ }
2232
+
2233
+ function asBytes16Mem(
2234
+ bytes memory encoded,
2235
+ uint offset
2236
+ ) internal pure returns (bytes16 ret, uint nextOffset) {
2237
+ (ret, nextOffset) = asBytes16MemUnchecked(encoded, offset);
2238
+ checkBound(nextOffset, encoded.length);
2239
+ }
2240
+
2241
+ function asBytes17CdUnchecked(
2242
+ bytes calldata encoded,
2243
+ uint offset
2244
+ ) internal pure returns (bytes17 ret, uint nextOffset) {
2245
+ /// @solidity memory-safe-assembly
2246
+ assembly {
2247
+ ret := calldataload(add(encoded.offset, offset))
2248
+ nextOffset := add(offset, 17)
2249
+ }
2250
+ }
2251
+
2252
+ function asBytes17Cd(
2253
+ bytes calldata encoded,
2254
+ uint offset
2255
+ ) internal pure returns (bytes17 ret, uint nextOffset) {
2256
+ (ret, nextOffset) = asBytes17CdUnchecked(encoded, offset);
2257
+ checkBound(nextOffset, encoded.length);
2258
+ }
2259
+
2260
+ function asBytes17MemUnchecked(
2261
+ bytes memory encoded,
2262
+ uint offset
2263
+ ) internal pure returns (bytes17 ret, uint nextOffset) {
2264
+ /// @solidity memory-safe-assembly
2265
+ assembly {
2266
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2267
+ nextOffset := add(offset, 17)
2268
+ }
2269
+ }
2270
+
2271
+ function asBytes17Mem(
2272
+ bytes memory encoded,
2273
+ uint offset
2274
+ ) internal pure returns (bytes17 ret, uint nextOffset) {
2275
+ (ret, nextOffset) = asBytes17MemUnchecked(encoded, offset);
2276
+ checkBound(nextOffset, encoded.length);
2277
+ }
2278
+
2279
+ function asBytes18CdUnchecked(
2280
+ bytes calldata encoded,
2281
+ uint offset
2282
+ ) internal pure returns (bytes18 ret, uint nextOffset) {
2283
+ /// @solidity memory-safe-assembly
2284
+ assembly {
2285
+ ret := calldataload(add(encoded.offset, offset))
2286
+ nextOffset := add(offset, 18)
2287
+ }
2288
+ }
2289
+
2290
+ function asBytes18Cd(
2291
+ bytes calldata encoded,
2292
+ uint offset
2293
+ ) internal pure returns (bytes18 ret, uint nextOffset) {
2294
+ (ret, nextOffset) = asBytes18CdUnchecked(encoded, offset);
2295
+ checkBound(nextOffset, encoded.length);
2296
+ }
2297
+
2298
+ function asBytes18MemUnchecked(
2299
+ bytes memory encoded,
2300
+ uint offset
2301
+ ) internal pure returns (bytes18 ret, uint nextOffset) {
2302
+ /// @solidity memory-safe-assembly
2303
+ assembly {
2304
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2305
+ nextOffset := add(offset, 18)
2306
+ }
2307
+ }
2308
+
2309
+ function asBytes18Mem(
2310
+ bytes memory encoded,
2311
+ uint offset
2312
+ ) internal pure returns (bytes18 ret, uint nextOffset) {
2313
+ (ret, nextOffset) = asBytes18MemUnchecked(encoded, offset);
2314
+ checkBound(nextOffset, encoded.length);
2315
+ }
2316
+
2317
+ function asBytes19CdUnchecked(
2318
+ bytes calldata encoded,
2319
+ uint offset
2320
+ ) internal pure returns (bytes19 ret, uint nextOffset) {
2321
+ /// @solidity memory-safe-assembly
2322
+ assembly {
2323
+ ret := calldataload(add(encoded.offset, offset))
2324
+ nextOffset := add(offset, 19)
2325
+ }
2326
+ }
2327
+
2328
+ function asBytes19Cd(
2329
+ bytes calldata encoded,
2330
+ uint offset
2331
+ ) internal pure returns (bytes19 ret, uint nextOffset) {
2332
+ (ret, nextOffset) = asBytes19CdUnchecked(encoded, offset);
2333
+ checkBound(nextOffset, encoded.length);
2334
+ }
2335
+
2336
+ function asBytes19MemUnchecked(
2337
+ bytes memory encoded,
2338
+ uint offset
2339
+ ) internal pure returns (bytes19 ret, uint nextOffset) {
2340
+ /// @solidity memory-safe-assembly
2341
+ assembly {
2342
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2343
+ nextOffset := add(offset, 19)
2344
+ }
2345
+ }
2346
+
2347
+ function asBytes19Mem(
2348
+ bytes memory encoded,
2349
+ uint offset
2350
+ ) internal pure returns (bytes19 ret, uint nextOffset) {
2351
+ (ret, nextOffset) = asBytes19MemUnchecked(encoded, offset);
2352
+ checkBound(nextOffset, encoded.length);
2353
+ }
2354
+
2355
+ function asBytes20CdUnchecked(
2356
+ bytes calldata encoded,
2357
+ uint offset
2358
+ ) internal pure returns (bytes20 ret, uint nextOffset) {
2359
+ /// @solidity memory-safe-assembly
2360
+ assembly {
2361
+ ret := calldataload(add(encoded.offset, offset))
2362
+ nextOffset := add(offset, 20)
2363
+ }
2364
+ }
2365
+
2366
+ function asBytes20Cd(
2367
+ bytes calldata encoded,
2368
+ uint offset
2369
+ ) internal pure returns (bytes20 ret, uint nextOffset) {
2370
+ (ret, nextOffset) = asBytes20CdUnchecked(encoded, offset);
2371
+ checkBound(nextOffset, encoded.length);
2372
+ }
2373
+
2374
+ function asBytes20MemUnchecked(
2375
+ bytes memory encoded,
2376
+ uint offset
2377
+ ) internal pure returns (bytes20 ret, uint nextOffset) {
2378
+ /// @solidity memory-safe-assembly
2379
+ assembly {
2380
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2381
+ nextOffset := add(offset, 20)
2382
+ }
2383
+ }
2384
+
2385
+ function asBytes20Mem(
2386
+ bytes memory encoded,
2387
+ uint offset
2388
+ ) internal pure returns (bytes20 ret, uint nextOffset) {
2389
+ (ret, nextOffset) = asBytes20MemUnchecked(encoded, offset);
2390
+ checkBound(nextOffset, encoded.length);
2391
+ }
2392
+
2393
+ function asBytes21CdUnchecked(
2394
+ bytes calldata encoded,
2395
+ uint offset
2396
+ ) internal pure returns (bytes21 ret, uint nextOffset) {
2397
+ /// @solidity memory-safe-assembly
2398
+ assembly {
2399
+ ret := calldataload(add(encoded.offset, offset))
2400
+ nextOffset := add(offset, 21)
2401
+ }
2402
+ }
2403
+
2404
+ function asBytes21Cd(
2405
+ bytes calldata encoded,
2406
+ uint offset
2407
+ ) internal pure returns (bytes21 ret, uint nextOffset) {
2408
+ (ret, nextOffset) = asBytes21CdUnchecked(encoded, offset);
2409
+ checkBound(nextOffset, encoded.length);
2410
+ }
2411
+
2412
+ function asBytes21MemUnchecked(
2413
+ bytes memory encoded,
2414
+ uint offset
2415
+ ) internal pure returns (bytes21 ret, uint nextOffset) {
2416
+ /// @solidity memory-safe-assembly
2417
+ assembly {
2418
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2419
+ nextOffset := add(offset, 21)
2420
+ }
2421
+ }
2422
+
2423
+ function asBytes21Mem(
2424
+ bytes memory encoded,
2425
+ uint offset
2426
+ ) internal pure returns (bytes21 ret, uint nextOffset) {
2427
+ (ret, nextOffset) = asBytes21MemUnchecked(encoded, offset);
2428
+ checkBound(nextOffset, encoded.length);
2429
+ }
2430
+
2431
+ function asBytes22CdUnchecked(
2432
+ bytes calldata encoded,
2433
+ uint offset
2434
+ ) internal pure returns (bytes22 ret, uint nextOffset) {
2435
+ /// @solidity memory-safe-assembly
2436
+ assembly {
2437
+ ret := calldataload(add(encoded.offset, offset))
2438
+ nextOffset := add(offset, 22)
2439
+ }
2440
+ }
2441
+
2442
+ function asBytes22Cd(
2443
+ bytes calldata encoded,
2444
+ uint offset
2445
+ ) internal pure returns (bytes22 ret, uint nextOffset) {
2446
+ (ret, nextOffset) = asBytes22CdUnchecked(encoded, offset);
2447
+ checkBound(nextOffset, encoded.length);
2448
+ }
2449
+
2450
+ function asBytes22MemUnchecked(
2451
+ bytes memory encoded,
2452
+ uint offset
2453
+ ) internal pure returns (bytes22 ret, uint nextOffset) {
2454
+ /// @solidity memory-safe-assembly
2455
+ assembly {
2456
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2457
+ nextOffset := add(offset, 22)
2458
+ }
2459
+ }
2460
+
2461
+ function asBytes22Mem(
2462
+ bytes memory encoded,
2463
+ uint offset
2464
+ ) internal pure returns (bytes22 ret, uint nextOffset) {
2465
+ (ret, nextOffset) = asBytes22MemUnchecked(encoded, offset);
2466
+ checkBound(nextOffset, encoded.length);
2467
+ }
2468
+
2469
+ function asBytes23CdUnchecked(
2470
+ bytes calldata encoded,
2471
+ uint offset
2472
+ ) internal pure returns (bytes23 ret, uint nextOffset) {
2473
+ /// @solidity memory-safe-assembly
2474
+ assembly {
2475
+ ret := calldataload(add(encoded.offset, offset))
2476
+ nextOffset := add(offset, 23)
2477
+ }
2478
+ }
2479
+
2480
+ function asBytes23Cd(
2481
+ bytes calldata encoded,
2482
+ uint offset
2483
+ ) internal pure returns (bytes23 ret, uint nextOffset) {
2484
+ (ret, nextOffset) = asBytes23CdUnchecked(encoded, offset);
2485
+ checkBound(nextOffset, encoded.length);
2486
+ }
2487
+
2488
+ function asBytes23MemUnchecked(
2489
+ bytes memory encoded,
2490
+ uint offset
2491
+ ) internal pure returns (bytes23 ret, uint nextOffset) {
2492
+ /// @solidity memory-safe-assembly
2493
+ assembly {
2494
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2495
+ nextOffset := add(offset, 23)
2496
+ }
2497
+ }
2498
+
2499
+ function asBytes23Mem(
2500
+ bytes memory encoded,
2501
+ uint offset
2502
+ ) internal pure returns (bytes23 ret, uint nextOffset) {
2503
+ (ret, nextOffset) = asBytes23MemUnchecked(encoded, offset);
2504
+ checkBound(nextOffset, encoded.length);
2505
+ }
2506
+
2507
+ function asBytes24CdUnchecked(
2508
+ bytes calldata encoded,
2509
+ uint offset
2510
+ ) internal pure returns (bytes24 ret, uint nextOffset) {
2511
+ /// @solidity memory-safe-assembly
2512
+ assembly {
2513
+ ret := calldataload(add(encoded.offset, offset))
2514
+ nextOffset := add(offset, 24)
2515
+ }
2516
+ }
2517
+
2518
+ function asBytes24Cd(
2519
+ bytes calldata encoded,
2520
+ uint offset
2521
+ ) internal pure returns (bytes24 ret, uint nextOffset) {
2522
+ (ret, nextOffset) = asBytes24CdUnchecked(encoded, offset);
2523
+ checkBound(nextOffset, encoded.length);
2524
+ }
2525
+
2526
+ function asBytes24MemUnchecked(
2527
+ bytes memory encoded,
2528
+ uint offset
2529
+ ) internal pure returns (bytes24 ret, uint nextOffset) {
2530
+ /// @solidity memory-safe-assembly
2531
+ assembly {
2532
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2533
+ nextOffset := add(offset, 24)
2534
+ }
2535
+ }
2536
+
2537
+ function asBytes24Mem(
2538
+ bytes memory encoded,
2539
+ uint offset
2540
+ ) internal pure returns (bytes24 ret, uint nextOffset) {
2541
+ (ret, nextOffset) = asBytes24MemUnchecked(encoded, offset);
2542
+ checkBound(nextOffset, encoded.length);
2543
+ }
2544
+
2545
+ function asBytes25CdUnchecked(
2546
+ bytes calldata encoded,
2547
+ uint offset
2548
+ ) internal pure returns (bytes25 ret, uint nextOffset) {
2549
+ /// @solidity memory-safe-assembly
2550
+ assembly {
2551
+ ret := calldataload(add(encoded.offset, offset))
2552
+ nextOffset := add(offset, 25)
2553
+ }
2554
+ }
2555
+
2556
+ function asBytes25Cd(
2557
+ bytes calldata encoded,
2558
+ uint offset
2559
+ ) internal pure returns (bytes25 ret, uint nextOffset) {
2560
+ (ret, nextOffset) = asBytes25CdUnchecked(encoded, offset);
2561
+ checkBound(nextOffset, encoded.length);
2562
+ }
2563
+
2564
+ function asBytes25MemUnchecked(
2565
+ bytes memory encoded,
2566
+ uint offset
2567
+ ) internal pure returns (bytes25 ret, uint nextOffset) {
2568
+ /// @solidity memory-safe-assembly
2569
+ assembly {
2570
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2571
+ nextOffset := add(offset, 25)
2572
+ }
2573
+ }
2574
+
2575
+ function asBytes25Mem(
2576
+ bytes memory encoded,
2577
+ uint offset
2578
+ ) internal pure returns (bytes25 ret, uint nextOffset) {
2579
+ (ret, nextOffset) = asBytes25MemUnchecked(encoded, offset);
2580
+ checkBound(nextOffset, encoded.length);
2581
+ }
2582
+
2583
+ function asBytes26CdUnchecked(
2584
+ bytes calldata encoded,
2585
+ uint offset
2586
+ ) internal pure returns (bytes26 ret, uint nextOffset) {
2587
+ /// @solidity memory-safe-assembly
2588
+ assembly {
2589
+ ret := calldataload(add(encoded.offset, offset))
2590
+ nextOffset := add(offset, 26)
2591
+ }
2592
+ }
2593
+
2594
+ function asBytes26Cd(
2595
+ bytes calldata encoded,
2596
+ uint offset
2597
+ ) internal pure returns (bytes26 ret, uint nextOffset) {
2598
+ (ret, nextOffset) = asBytes26CdUnchecked(encoded, offset);
2599
+ checkBound(nextOffset, encoded.length);
2600
+ }
2601
+
2602
+ function asBytes26MemUnchecked(
2603
+ bytes memory encoded,
2604
+ uint offset
2605
+ ) internal pure returns (bytes26 ret, uint nextOffset) {
2606
+ /// @solidity memory-safe-assembly
2607
+ assembly {
2608
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2609
+ nextOffset := add(offset, 26)
2610
+ }
2611
+ }
2612
+
2613
+ function asBytes26Mem(
2614
+ bytes memory encoded,
2615
+ uint offset
2616
+ ) internal pure returns (bytes26 ret, uint nextOffset) {
2617
+ (ret, nextOffset) = asBytes26MemUnchecked(encoded, offset);
2618
+ checkBound(nextOffset, encoded.length);
2619
+ }
2620
+
2621
+ function asBytes27CdUnchecked(
2622
+ bytes calldata encoded,
2623
+ uint offset
2624
+ ) internal pure returns (bytes27 ret, uint nextOffset) {
2625
+ /// @solidity memory-safe-assembly
2626
+ assembly {
2627
+ ret := calldataload(add(encoded.offset, offset))
2628
+ nextOffset := add(offset, 27)
2629
+ }
2630
+ }
2631
+
2632
+ function asBytes27Cd(
2633
+ bytes calldata encoded,
2634
+ uint offset
2635
+ ) internal pure returns (bytes27 ret, uint nextOffset) {
2636
+ (ret, nextOffset) = asBytes27CdUnchecked(encoded, offset);
2637
+ checkBound(nextOffset, encoded.length);
2638
+ }
2639
+
2640
+ function asBytes27MemUnchecked(
2641
+ bytes memory encoded,
2642
+ uint offset
2643
+ ) internal pure returns (bytes27 ret, uint nextOffset) {
2644
+ /// @solidity memory-safe-assembly
2645
+ assembly {
2646
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2647
+ nextOffset := add(offset, 27)
2648
+ }
2649
+ }
2650
+
2651
+ function asBytes27Mem(
2652
+ bytes memory encoded,
2653
+ uint offset
2654
+ ) internal pure returns (bytes27 ret, uint nextOffset) {
2655
+ (ret, nextOffset) = asBytes27MemUnchecked(encoded, offset);
2656
+ checkBound(nextOffset, encoded.length);
2657
+ }
2658
+
2659
+ function asBytes28CdUnchecked(
2660
+ bytes calldata encoded,
2661
+ uint offset
2662
+ ) internal pure returns (bytes28 ret, uint nextOffset) {
2663
+ /// @solidity memory-safe-assembly
2664
+ assembly {
2665
+ ret := calldataload(add(encoded.offset, offset))
2666
+ nextOffset := add(offset, 28)
2667
+ }
2668
+ }
2669
+
2670
+ function asBytes28Cd(
2671
+ bytes calldata encoded,
2672
+ uint offset
2673
+ ) internal pure returns (bytes28 ret, uint nextOffset) {
2674
+ (ret, nextOffset) = asBytes28CdUnchecked(encoded, offset);
2675
+ checkBound(nextOffset, encoded.length);
2676
+ }
2677
+
2678
+ function asBytes28MemUnchecked(
2679
+ bytes memory encoded,
2680
+ uint offset
2681
+ ) internal pure returns (bytes28 ret, uint nextOffset) {
2682
+ /// @solidity memory-safe-assembly
2683
+ assembly {
2684
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2685
+ nextOffset := add(offset, 28)
2686
+ }
2687
+ }
2688
+
2689
+ function asBytes28Mem(
2690
+ bytes memory encoded,
2691
+ uint offset
2692
+ ) internal pure returns (bytes28 ret, uint nextOffset) {
2693
+ (ret, nextOffset) = asBytes28MemUnchecked(encoded, offset);
2694
+ checkBound(nextOffset, encoded.length);
2695
+ }
2696
+
2697
+ function asBytes29CdUnchecked(
2698
+ bytes calldata encoded,
2699
+ uint offset
2700
+ ) internal pure returns (bytes29 ret, uint nextOffset) {
2701
+ /// @solidity memory-safe-assembly
2702
+ assembly {
2703
+ ret := calldataload(add(encoded.offset, offset))
2704
+ nextOffset := add(offset, 29)
2705
+ }
2706
+ }
2707
+
2708
+ function asBytes29Cd(
2709
+ bytes calldata encoded,
2710
+ uint offset
2711
+ ) internal pure returns (bytes29 ret, uint nextOffset) {
2712
+ (ret, nextOffset) = asBytes29CdUnchecked(encoded, offset);
2713
+ checkBound(nextOffset, encoded.length);
2714
+ }
2715
+
2716
+ function asBytes29MemUnchecked(
2717
+ bytes memory encoded,
2718
+ uint offset
2719
+ ) internal pure returns (bytes29 ret, uint nextOffset) {
2720
+ /// @solidity memory-safe-assembly
2721
+ assembly {
2722
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2723
+ nextOffset := add(offset, 29)
2724
+ }
2725
+ }
2726
+
2727
+ function asBytes29Mem(
2728
+ bytes memory encoded,
2729
+ uint offset
2730
+ ) internal pure returns (bytes29 ret, uint nextOffset) {
2731
+ (ret, nextOffset) = asBytes29MemUnchecked(encoded, offset);
2732
+ checkBound(nextOffset, encoded.length);
2733
+ }
2734
+
2735
+ function asBytes30CdUnchecked(
2736
+ bytes calldata encoded,
2737
+ uint offset
2738
+ ) internal pure returns (bytes30 ret, uint nextOffset) {
2739
+ /// @solidity memory-safe-assembly
2740
+ assembly {
2741
+ ret := calldataload(add(encoded.offset, offset))
2742
+ nextOffset := add(offset, 30)
2743
+ }
2744
+ }
2745
+
2746
+ function asBytes30Cd(
2747
+ bytes calldata encoded,
2748
+ uint offset
2749
+ ) internal pure returns (bytes30 ret, uint nextOffset) {
2750
+ (ret, nextOffset) = asBytes30CdUnchecked(encoded, offset);
2751
+ checkBound(nextOffset, encoded.length);
2752
+ }
2753
+
2754
+ function asBytes30MemUnchecked(
2755
+ bytes memory encoded,
2756
+ uint offset
2757
+ ) internal pure returns (bytes30 ret, uint nextOffset) {
2758
+ /// @solidity memory-safe-assembly
2759
+ assembly {
2760
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2761
+ nextOffset := add(offset, 30)
2762
+ }
2763
+ }
2764
+
2765
+ function asBytes30Mem(
2766
+ bytes memory encoded,
2767
+ uint offset
2768
+ ) internal pure returns (bytes30 ret, uint nextOffset) {
2769
+ (ret, nextOffset) = asBytes30MemUnchecked(encoded, offset);
2770
+ checkBound(nextOffset, encoded.length);
2771
+ }
2772
+
2773
+ function asBytes31CdUnchecked(
2774
+ bytes calldata encoded,
2775
+ uint offset
2776
+ ) internal pure returns (bytes31 ret, uint nextOffset) {
2777
+ /// @solidity memory-safe-assembly
2778
+ assembly {
2779
+ ret := calldataload(add(encoded.offset, offset))
2780
+ nextOffset := add(offset, 31)
2781
+ }
2782
+ }
2783
+
2784
+ function asBytes31Cd(
2785
+ bytes calldata encoded,
2786
+ uint offset
2787
+ ) internal pure returns (bytes31 ret, uint nextOffset) {
2788
+ (ret, nextOffset) = asBytes31CdUnchecked(encoded, offset);
2789
+ checkBound(nextOffset, encoded.length);
2790
+ }
2791
+
2792
+ function asBytes31MemUnchecked(
2793
+ bytes memory encoded,
2794
+ uint offset
2795
+ ) internal pure returns (bytes31 ret, uint nextOffset) {
2796
+ /// @solidity memory-safe-assembly
2797
+ assembly {
2798
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2799
+ nextOffset := add(offset, 31)
2800
+ }
2801
+ }
2802
+
2803
+ function asBytes31Mem(
2804
+ bytes memory encoded,
2805
+ uint offset
2806
+ ) internal pure returns (bytes31 ret, uint nextOffset) {
2807
+ (ret, nextOffset) = asBytes31MemUnchecked(encoded, offset);
2808
+ checkBound(nextOffset, encoded.length);
2809
+ }
2810
+
2811
+ function asBytes32CdUnchecked(
2812
+ bytes calldata encoded,
2813
+ uint offset
2814
+ ) internal pure returns (bytes32 ret, uint nextOffset) {
2815
+ /// @solidity memory-safe-assembly
2816
+ assembly {
2817
+ ret := calldataload(add(encoded.offset, offset))
2818
+ nextOffset := add(offset, 32)
2819
+ }
2820
+ }
2821
+
2822
+ function asBytes32Cd(
2823
+ bytes calldata encoded,
2824
+ uint offset
2825
+ ) internal pure returns (bytes32 ret, uint nextOffset) {
2826
+ (ret, nextOffset) = asBytes32CdUnchecked(encoded, offset);
2827
+ checkBound(nextOffset, encoded.length);
2828
+ }
2829
+
2830
+ function asBytes32MemUnchecked(
2831
+ bytes memory encoded,
2832
+ uint offset
2833
+ ) internal pure returns (bytes32 ret, uint nextOffset) {
2834
+ /// @solidity memory-safe-assembly
2835
+ assembly {
2836
+ ret := mload(add(encoded, add(offset, WORD_SIZE)))
2837
+ nextOffset := add(offset, 32)
2838
+ }
2839
+ }
2840
+
2841
+ function asBytes32Mem(
2842
+ bytes memory encoded,
2843
+ uint offset
2844
+ ) internal pure returns (bytes32 ret, uint nextOffset) {
2845
+ (ret, nextOffset) = asBytes32MemUnchecked(encoded, offset);
2846
+ checkBound(nextOffset, encoded.length);
2847
+ }
2848
+ }