@typeberry/jam 0.1.0-08a9db1 → 0.1.0-b2d0b72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/block-generator/index.js +200 -122
- package/block-generator/index.js.map +1 -1
- package/importer/index.js +207 -129
- package/importer/index.js.map +1 -1
- package/index.js +207 -129
- package/index.js.map +1 -1
- package/jam-network/index.js +127 -90
- package/jam-network/index.js.map +1 -1
- package/package.json +1 -1
package/importer/index.js
CHANGED
|
@@ -4334,29 +4334,17 @@ function isBrowser() {
|
|
|
4334
4334
|
* We avoid using `node:assert` to keep compatibility with a browser environment.
|
|
4335
4335
|
* Note the checks should not have any side effects, since we might decide
|
|
4336
4336
|
* to remove all of them in a post-processing step.
|
|
4337
|
-
*/
|
|
4338
|
-
function debug_check(condition, message) {
|
|
4339
|
-
if (!condition) {
|
|
4340
|
-
throw new Error(`Assertion failure: ${message ?? ""}`);
|
|
4341
|
-
}
|
|
4342
|
-
}
|
|
4343
|
-
function cast(_a, condition) {
|
|
4344
|
-
return condition;
|
|
4345
|
-
}
|
|
4346
|
-
/**
|
|
4347
|
-
* Yet another function to perform runtime assertions.
|
|
4348
|
-
* This function returns a new type to mark in the code that this value was checked and you don't have to do it again.
|
|
4349
4337
|
*
|
|
4350
|
-
*
|
|
4351
|
-
*
|
|
4352
|
-
* should be replaced with:
|
|
4353
|
-
* const x = y as CheckedNumber;
|
|
4338
|
+
* NOTE the function is intended to be used as tagged template string for the performance
|
|
4339
|
+
* reasons.
|
|
4354
4340
|
*/
|
|
4355
|
-
function
|
|
4356
|
-
if (
|
|
4357
|
-
|
|
4341
|
+
function debug_check(strings, condition, ...data) {
|
|
4342
|
+
if (!condition) {
|
|
4343
|
+
// add an empty value so that `data.length === strings.length`
|
|
4344
|
+
data.unshift("");
|
|
4345
|
+
const message = strings.map((v, index) => `${v}${data[index] ?? ""}`);
|
|
4346
|
+
throw new Error(`Assertion failure:${message.join("")}`);
|
|
4358
4347
|
}
|
|
4359
|
-
throw new Error(`Assertion failure: ${message ?? ""}`);
|
|
4360
4348
|
}
|
|
4361
4349
|
/**
|
|
4362
4350
|
* The function can be used to make sure that a particular type is `never`
|
|
@@ -4526,7 +4514,7 @@ function resultToString(res) {
|
|
|
4526
4514
|
const result_Result = {
|
|
4527
4515
|
/** Create new [`Result`] with `Ok` status. */
|
|
4528
4516
|
ok: (ok) => {
|
|
4529
|
-
debug_check
|
|
4517
|
+
debug_check `${ok !== undefined} 'ok' type cannot be undefined.`;
|
|
4530
4518
|
return {
|
|
4531
4519
|
isOk: true,
|
|
4532
4520
|
isError: false,
|
|
@@ -4535,7 +4523,7 @@ const result_Result = {
|
|
|
4535
4523
|
},
|
|
4536
4524
|
/** Create new [`Result`] with `Error` status. */
|
|
4537
4525
|
error: (error, details = "") => {
|
|
4538
|
-
debug_check
|
|
4526
|
+
debug_check `${error !== undefined} 'Error' type cannot be undefined.`;
|
|
4539
4527
|
return {
|
|
4540
4528
|
isOk: false,
|
|
4541
4529
|
isError: true,
|
|
@@ -4819,7 +4807,10 @@ class BitVec {
|
|
|
4819
4807
|
constructor(data, bitLength) {
|
|
4820
4808
|
this.data = data;
|
|
4821
4809
|
this.bitLength = bitLength;
|
|
4822
|
-
debug_check
|
|
4810
|
+
debug_check `
|
|
4811
|
+
${data.length * 8 >= bitLength}
|
|
4812
|
+
Not enough bytes in the data array. Need ${data.length * 8} has ${bitLength}.
|
|
4813
|
+
`;
|
|
4823
4814
|
this.byteLength = Math.ceil(bitLength / 8);
|
|
4824
4815
|
}
|
|
4825
4816
|
/** Return a raw in-memory representation of this [`BitVec`]. */
|
|
@@ -4828,7 +4819,10 @@ class BitVec {
|
|
|
4828
4819
|
}
|
|
4829
4820
|
/** Perform OR operation on all bits in place. */
|
|
4830
4821
|
sumWith(other) {
|
|
4831
|
-
debug_check
|
|
4822
|
+
debug_check `
|
|
4823
|
+
${other.bitLength === this.bitLength}
|
|
4824
|
+
Invalid bit length for sumWith: ${other.bitLength} vs ${this.bitLength}
|
|
4825
|
+
`;
|
|
4832
4826
|
const otherRaw = other.raw;
|
|
4833
4827
|
for (let i = 0; i < this.byteLength; i++) {
|
|
4834
4828
|
this.data[i] |= otherRaw[i];
|
|
@@ -4838,7 +4832,7 @@ class BitVec {
|
|
|
4838
4832
|
* Set the bit at index `idx` to value `val`.
|
|
4839
4833
|
*/
|
|
4840
4834
|
setBit(idx, val) {
|
|
4841
|
-
debug_check
|
|
4835
|
+
debug_check `${idx >= 0 && idx < this.bitLength} Index out of bounds. Need ${idx} has ${this.bitLength}.`;
|
|
4842
4836
|
const byteIndex = Math.floor(idx / 8);
|
|
4843
4837
|
const bitIndexInByte = idx % 8;
|
|
4844
4838
|
const mask = 1 << bitIndexInByte;
|
|
@@ -4853,7 +4847,7 @@ class BitVec {
|
|
|
4853
4847
|
* Return `true` if the bit at index `idx` is set.
|
|
4854
4848
|
*/
|
|
4855
4849
|
isSet(idx) {
|
|
4856
|
-
debug_check
|
|
4850
|
+
debug_check `${idx >= 0 && idx < this.bitLength} Index out of bounds. Need ${idx} has ${this.bitLength}.`;
|
|
4857
4851
|
const byteIndex = Math.floor(idx / 8);
|
|
4858
4852
|
const bitIndexInByte = idx % 8;
|
|
4859
4853
|
const mask = 1 << bitIndexInByte;
|
|
@@ -5020,7 +5014,7 @@ class bytes_BytesBlob {
|
|
|
5020
5014
|
}
|
|
5021
5015
|
/** Create a new [`BytesBlob`] from an array of bytes. */
|
|
5022
5016
|
static blobFromNumbers(v) {
|
|
5023
|
-
debug_check
|
|
5017
|
+
debug_check `${v.find((x) => (x & 0xff) !== x) === undefined} BytesBlob.blobFromNumbers used with non-byte number array.`;
|
|
5024
5018
|
const arr = new Uint8Array(v);
|
|
5025
5019
|
return new bytes_BytesBlob(arr);
|
|
5026
5020
|
}
|
|
@@ -5064,7 +5058,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
5064
5058
|
length;
|
|
5065
5059
|
constructor(raw, len) {
|
|
5066
5060
|
super(raw);
|
|
5067
|
-
debug_check
|
|
5061
|
+
debug_check `${raw.byteLength === len} Given buffer has incorrect size ${raw.byteLength} vs expected ${len}`;
|
|
5068
5062
|
this.length = len;
|
|
5069
5063
|
}
|
|
5070
5064
|
/** Create new [`Bytes<X>`] given a backing buffer and it's length. */
|
|
@@ -5073,7 +5067,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
5073
5067
|
}
|
|
5074
5068
|
/** Create new [`Bytes<X>`] given an array of bytes and it's length. */
|
|
5075
5069
|
static fromNumbers(v, len) {
|
|
5076
|
-
debug_check
|
|
5070
|
+
debug_check `${v.find((x) => (x & 0xff) !== x) === undefined} Bytes.fromNumbers used with non-byte number array.`;
|
|
5077
5071
|
const x = new Uint8Array(v);
|
|
5078
5072
|
return new bytes_Bytes(x, len);
|
|
5079
5073
|
}
|
|
@@ -5084,7 +5078,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
5084
5078
|
// TODO [ToDr] `fill` should have the argments swapped to align with the rest.
|
|
5085
5079
|
/** Create a [`Bytes<X>`] with all bytes filled with given input number. */
|
|
5086
5080
|
static fill(len, input) {
|
|
5087
|
-
debug_check(
|
|
5081
|
+
debug_check `${(input & 0xff) === input} Input has to be a byte.`;
|
|
5088
5082
|
const bytes = bytes_Bytes.zero(len);
|
|
5089
5083
|
bytes.raw.fill(input, 0, len);
|
|
5090
5084
|
return bytes;
|
|
@@ -5107,7 +5101,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
5107
5101
|
}
|
|
5108
5102
|
/** Compare the sequence to another one. */
|
|
5109
5103
|
isEqualTo(other) {
|
|
5110
|
-
debug_check
|
|
5104
|
+
debug_check `${this.length === other.length} Comparing incorrectly typed bytes!`;
|
|
5111
5105
|
return u8ArraySameLengthEqual(this.raw, other.raw);
|
|
5112
5106
|
}
|
|
5113
5107
|
/** Converts current type into some opaque extension. */
|
|
@@ -5116,7 +5110,7 @@ class bytes_Bytes extends bytes_BytesBlob {
|
|
|
5116
5110
|
}
|
|
5117
5111
|
}
|
|
5118
5112
|
function byteFromString(s) {
|
|
5119
|
-
debug_check
|
|
5113
|
+
debug_check `${s.length === 2} Two-character string expected`;
|
|
5120
5114
|
const a = numberFromCharCode(s.charCodeAt(0));
|
|
5121
5115
|
const b = numberFromCharCode(s.charCodeAt(1));
|
|
5122
5116
|
return (a << 4) | b;
|
|
@@ -5185,7 +5179,7 @@ const BLS_KEY_BYTES = 144;
|
|
|
5185
5179
|
/** Derive a Bandersnatch public key from a seed. */
|
|
5186
5180
|
function bandersnatch_publicKey(seed) {
|
|
5187
5181
|
const key = bandersnatch.derive_public_key(seed);
|
|
5188
|
-
check
|
|
5182
|
+
check `${key[0] === 0} Invalid Bandersnatch public key derived from seed`;
|
|
5189
5183
|
return Bytes.fromBlob(key.subarray(1), BANDERSNATCH_KEY_BYTES).asOpaque();
|
|
5190
5184
|
}
|
|
5191
5185
|
|
|
@@ -5673,7 +5667,7 @@ async function ed25519_verify(input) {
|
|
|
5673
5667
|
data.set(signature.raw, offset);
|
|
5674
5668
|
offset += ED25519_SIGNATURE_BYTES;
|
|
5675
5669
|
const messageLength = message.length;
|
|
5676
|
-
debug_check
|
|
5670
|
+
debug_check `${messageLength < 256} Message needs to be shorter than 256 bytes. Got: ${messageLength}`;
|
|
5677
5671
|
data[offset] = messageLength;
|
|
5678
5672
|
offset += 1;
|
|
5679
5673
|
data.set(message.raw, offset);
|
|
@@ -5757,7 +5751,7 @@ class PageAllocator {
|
|
|
5757
5751
|
// TODO [ToDr] Benchmark the performance!
|
|
5758
5752
|
constructor(hashesPerPage) {
|
|
5759
5753
|
this.hashesPerPage = hashesPerPage;
|
|
5760
|
-
check
|
|
5754
|
+
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
5761
5755
|
this.resetPage();
|
|
5762
5756
|
}
|
|
5763
5757
|
resetPage() {
|
|
@@ -5851,42 +5845,53 @@ function keccak_hashBlobs(hasher, blobs) {
|
|
|
5851
5845
|
|
|
5852
5846
|
;// CONCATENATED MODULE: ./packages/core/numbers/index.ts
|
|
5853
5847
|
|
|
5854
|
-
const
|
|
5848
|
+
const asTypedNumber = (v) => v;
|
|
5855
5849
|
const MAX_VALUE_U8 = 0xff;
|
|
5856
5850
|
const MAX_VALUE_U16 = 0xffff;
|
|
5857
5851
|
const MAX_VALUE_U32 = 0xffff_ffff;
|
|
5858
5852
|
const MAX_VALUE_U64 = 0xffffffffffffffffn;
|
|
5859
5853
|
/** Attempt to cast an input number into U8. */
|
|
5860
|
-
const numbers_tryAsU8 = (v) =>
|
|
5854
|
+
const numbers_tryAsU8 = (v) => {
|
|
5855
|
+
debug_check `${isU8(v)} input must have one-byte representation, got ${v}`;
|
|
5856
|
+
return asTypedNumber(v);
|
|
5857
|
+
};
|
|
5861
5858
|
/** Check if given number is a valid U8 number. */
|
|
5862
5859
|
const isU8 = (v) => (v & MAX_VALUE_U8) === v;
|
|
5863
5860
|
/** Attempt to cast an input number into U16. */
|
|
5864
|
-
const numbers_tryAsU16 = (v) =>
|
|
5861
|
+
const numbers_tryAsU16 = (v) => {
|
|
5862
|
+
debug_check `${isU16(v)} input must have two-byte representation, got ${v}`;
|
|
5863
|
+
return asTypedNumber(v);
|
|
5864
|
+
};
|
|
5865
5865
|
/** Check if given number is a valid U16 number. */
|
|
5866
5866
|
const isU16 = (v) => (v & MAX_VALUE_U16) === v;
|
|
5867
5867
|
/** Attempt to cast an input number into U32. */
|
|
5868
|
-
const numbers_tryAsU32 = (v) =>
|
|
5868
|
+
const numbers_tryAsU32 = (v) => {
|
|
5869
|
+
debug_check `${isU32(v)} input must have four-byte representation, got ${v}`;
|
|
5870
|
+
return asTypedNumber(v);
|
|
5871
|
+
};
|
|
5869
5872
|
/** Check if given number is a valid U32 number. */
|
|
5870
5873
|
const isU32 = (v) => (v & MAX_VALUE_U32) >>> 0 === v;
|
|
5871
5874
|
/** Attempt to cast an input number into U64. */
|
|
5872
5875
|
const numbers_tryAsU64 = (x) => {
|
|
5873
5876
|
const v = BigInt(x);
|
|
5874
|
-
|
|
5877
|
+
debug_check `${isU64(v)} input must have eight-byte representation, got ${x}`;
|
|
5878
|
+
return asTypedNumber(v);
|
|
5875
5879
|
};
|
|
5876
5880
|
/** Check if given number is a valid U64 number. */
|
|
5877
5881
|
const isU64 = (v) => (v & MAX_VALUE_U64) === v;
|
|
5878
5882
|
/** Collate two U32 parts into one U64. */
|
|
5879
5883
|
const u64FromParts = ({ lower, upper }) => {
|
|
5880
5884
|
const val = (BigInt(upper) << 32n) + BigInt(lower);
|
|
5881
|
-
return
|
|
5885
|
+
return asTypedNumber(val);
|
|
5882
5886
|
};
|
|
5883
5887
|
/** Split U64 into lower & upper parts. */
|
|
5884
5888
|
const u64IntoParts = (v) => {
|
|
5885
|
-
|
|
5886
|
-
const
|
|
5889
|
+
// Number(...) safe: both parts are <= 0xffffffff
|
|
5890
|
+
const lower = Number(v & (2n ** 32n - 1n));
|
|
5891
|
+
const upper = Number(v >> 32n);
|
|
5887
5892
|
return {
|
|
5888
|
-
lower:
|
|
5889
|
-
upper:
|
|
5893
|
+
lower: asTypedNumber(lower),
|
|
5894
|
+
upper: asTypedNumber(upper),
|
|
5890
5895
|
};
|
|
5891
5896
|
};
|
|
5892
5897
|
/**
|
|
@@ -5926,8 +5931,8 @@ function numbers_u32AsLeBytes(value) {
|
|
|
5926
5931
|
* Interpret 4-byte `Uint8Array` as U32 written as little endian.
|
|
5927
5932
|
*/
|
|
5928
5933
|
function leBytesAsU32(uint8Array) {
|
|
5929
|
-
debug_check
|
|
5930
|
-
return
|
|
5934
|
+
debug_check `${uint8Array.length === 4} Input must be a Uint8Array of length 4`;
|
|
5935
|
+
return asTypedNumber(uint8Array[0] | (uint8Array[1] << 8) | (uint8Array[2] << 16) | (uint8Array[3] << 24));
|
|
5931
5936
|
}
|
|
5932
5937
|
/** Get the smallest value between U64 a and values given as input parameters. */
|
|
5933
5938
|
const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? min : value), a);
|
|
@@ -6275,7 +6280,7 @@ class decoder_Decoder {
|
|
|
6275
6280
|
this.skip(newOffset - this.offset);
|
|
6276
6281
|
}
|
|
6277
6282
|
else {
|
|
6278
|
-
debug_check
|
|
6283
|
+
debug_check `${newOffset >= 0} The offset has to be positive`;
|
|
6279
6284
|
this.offset = newOffset;
|
|
6280
6285
|
}
|
|
6281
6286
|
}
|
|
@@ -6303,7 +6308,7 @@ class decoder_Decoder {
|
|
|
6303
6308
|
return num;
|
|
6304
6309
|
}
|
|
6305
6310
|
ensureHasBytes(bytes) {
|
|
6306
|
-
debug_check
|
|
6311
|
+
debug_check `${bytes >= 0} Negative number of bytes given.`;
|
|
6307
6312
|
if (this.offset + bytes > this.source.length) {
|
|
6308
6313
|
throw new Error(`Attempting to decode more data than there is left. Need ${bytes}, left: ${this.source.length - this.offset}.`);
|
|
6309
6314
|
}
|
|
@@ -6311,7 +6316,7 @@ class decoder_Decoder {
|
|
|
6311
6316
|
}
|
|
6312
6317
|
const MASKS = [0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80];
|
|
6313
6318
|
function decodeVariableLengthExtraBytes(firstByte) {
|
|
6314
|
-
debug_check
|
|
6319
|
+
debug_check `${firstByte >= 0 && firstByte < 256} Incorrect byte value: ${firstByte}`;
|
|
6315
6320
|
for (let i = 0; i < MASKS.length; i++) {
|
|
6316
6321
|
if (firstByte >= MASKS[i]) {
|
|
6317
6322
|
return 8 - i;
|
|
@@ -6466,7 +6471,7 @@ class descriptor_Descriptor {
|
|
|
6466
6471
|
|
|
6467
6472
|
|
|
6468
6473
|
function tryAsExactBytes(a) {
|
|
6469
|
-
debug_check
|
|
6474
|
+
debug_check `${a.isExact} The value is not exact size estimation!`;
|
|
6470
6475
|
return a.bytes;
|
|
6471
6476
|
}
|
|
6472
6477
|
function addSizeHints(a, b) {
|
|
@@ -6573,8 +6578,8 @@ class encoder_Encoder {
|
|
|
6573
6578
|
// we still allow positive numbers from `[maxNum / 2, maxNum)`.
|
|
6574
6579
|
// So it does not matter if the argument is a negative value,
|
|
6575
6580
|
// OR if someone just gave us two-complement already.
|
|
6576
|
-
debug_check
|
|
6577
|
-
debug_check
|
|
6581
|
+
debug_check `${num < maxNum} Only for numbers up to 2**64 - 1`;
|
|
6582
|
+
debug_check `${-num <= maxNum / 2n} Only for numbers down to -2**63`;
|
|
6578
6583
|
this.ensureBigEnough(8);
|
|
6579
6584
|
this.dataView.setBigInt64(this.offset, num, true);
|
|
6580
6585
|
this.offset += 8;
|
|
@@ -6638,8 +6643,8 @@ class encoder_Encoder {
|
|
|
6638
6643
|
// we still allow positive numbers from `[maxNum / 2, maxNum)`.
|
|
6639
6644
|
// So it does not matter if the argument is a negative value,
|
|
6640
6645
|
// OR if someone just gave us two-complement already.
|
|
6641
|
-
debug_check
|
|
6642
|
-
debug_check
|
|
6646
|
+
debug_check `${num < maxNum} Only for numbers up to 2**${BITS * bytesToEncode} - 1`;
|
|
6647
|
+
debug_check `${-num <= maxNum / 2} Only for numbers down to -2**${BITS * bytesToEncode - 1}`;
|
|
6643
6648
|
this.ensureBigEnough(bytesToEncode);
|
|
6644
6649
|
}
|
|
6645
6650
|
/**
|
|
@@ -6650,8 +6655,8 @@ class encoder_Encoder {
|
|
|
6650
6655
|
* https://graypaper.fluffylabs.dev/#/579bd12/365202365202
|
|
6651
6656
|
*/
|
|
6652
6657
|
varU32(num) {
|
|
6653
|
-
debug_check
|
|
6654
|
-
debug_check
|
|
6658
|
+
debug_check `${num >= 0} Only for natural numbers.`;
|
|
6659
|
+
debug_check `${num < 2 ** 32} Only for numbers up to 2**32`;
|
|
6655
6660
|
this.varU64(BigInt(num));
|
|
6656
6661
|
}
|
|
6657
6662
|
/**
|
|
@@ -6802,7 +6807,7 @@ class encoder_Encoder {
|
|
|
6802
6807
|
* https://graypaper.fluffylabs.dev/#/579bd12/374400374400
|
|
6803
6808
|
*/
|
|
6804
6809
|
sequenceVarLen(encode, elements) {
|
|
6805
|
-
debug_check
|
|
6810
|
+
debug_check `${elements.length <= 2 ** 32} Wow, that's a nice long sequence you've got here.`;
|
|
6806
6811
|
this.varU32(numbers_tryAsU32(elements.length));
|
|
6807
6812
|
this.sequenceFixLen(encode, elements);
|
|
6808
6813
|
}
|
|
@@ -6823,7 +6828,7 @@ class encoder_Encoder {
|
|
|
6823
6828
|
* anyway, so if we really should throw we will.
|
|
6824
6829
|
*/
|
|
6825
6830
|
ensureBigEnough(length, options = { silent: false }) {
|
|
6826
|
-
debug_check
|
|
6831
|
+
debug_check `${length >= 0} Negative length given`;
|
|
6827
6832
|
const newLength = this.offset + length;
|
|
6828
6833
|
if (newLength > MAX_LENGTH) {
|
|
6829
6834
|
if (options.silent) {
|
|
@@ -6959,10 +6964,12 @@ class ObjectView {
|
|
|
6959
6964
|
decodeUpTo(field) {
|
|
6960
6965
|
const index = this.descriptorsKeys.indexOf(field);
|
|
6961
6966
|
const lastField = this.descriptorsKeys[this.lastDecodedFieldIdx];
|
|
6962
|
-
debug_check
|
|
6967
|
+
debug_check `
|
|
6968
|
+
${this.lastDecodedFieldIdx < index}
|
|
6969
|
+
Unjustified call to 'decodeUpTo' -
|
|
6963
6970
|
the index ($Blobindex}, ${String(field)})
|
|
6964
6971
|
is already decoded (${this.lastDecodedFieldIdx}, ${String(lastField)}).
|
|
6965
|
-
|
|
6972
|
+
`;
|
|
6966
6973
|
let lastItem = this.cache.get(lastField);
|
|
6967
6974
|
const skipper = new Skipper(this.decoder);
|
|
6968
6975
|
// now skip all of the fields and further populate the cache.
|
|
@@ -6978,8 +6985,10 @@ class ObjectView {
|
|
|
6978
6985
|
this.cache.set(field, lastItem);
|
|
6979
6986
|
this.lastDecodedFieldIdx = i;
|
|
6980
6987
|
}
|
|
6981
|
-
|
|
6982
|
-
|
|
6988
|
+
if (lastItem === undefined) {
|
|
6989
|
+
throw new Error("Last item must be set, since the loop turns at least once.");
|
|
6990
|
+
}
|
|
6991
|
+
return lastItem;
|
|
6983
6992
|
}
|
|
6984
6993
|
}
|
|
6985
6994
|
/**
|
|
@@ -7012,8 +7021,10 @@ class SequenceView {
|
|
|
7012
7021
|
*[Symbol.iterator]() {
|
|
7013
7022
|
for (let i = 0; i < this.length; i++) {
|
|
7014
7023
|
const val = this.get(i);
|
|
7015
|
-
|
|
7016
|
-
|
|
7024
|
+
if (val === undefined) {
|
|
7025
|
+
throw new Error("We are within 0..this.length so all items are defined.");
|
|
7026
|
+
}
|
|
7027
|
+
yield val;
|
|
7017
7028
|
}
|
|
7018
7029
|
}
|
|
7019
7030
|
/** Create an array of all views mapped to some particular value. */
|
|
@@ -7056,7 +7067,10 @@ class SequenceView {
|
|
|
7056
7067
|
return bytes_BytesBlob.blobFrom(this.decoder.source.subarray(this.initialDecoderOffset, this.decoder.bytesRead()));
|
|
7057
7068
|
}
|
|
7058
7069
|
decodeUpTo(index) {
|
|
7059
|
-
debug_check
|
|
7070
|
+
debug_check `
|
|
7071
|
+
${this.lastDecodedIdx < index}
|
|
7072
|
+
Unjustified call to 'decodeUpTo' - the index (${index}) is already decoded (${this.lastDecodedIdx}).
|
|
7073
|
+
`;
|
|
7060
7074
|
let lastItem = this.cache.get(this.lastDecodedIdx);
|
|
7061
7075
|
const skipper = new Skipper(this.decoder);
|
|
7062
7076
|
// now skip all of the fields and further populate the cache.
|
|
@@ -7071,8 +7085,10 @@ class SequenceView {
|
|
|
7071
7085
|
this.cache.set(i, lastItem);
|
|
7072
7086
|
this.lastDecodedIdx = i;
|
|
7073
7087
|
}
|
|
7074
|
-
|
|
7075
|
-
|
|
7088
|
+
if (lastItem === undefined) {
|
|
7089
|
+
throw new Error("Last item must be set, since the loop turns at least once.");
|
|
7090
|
+
}
|
|
7091
|
+
return lastItem;
|
|
7076
7092
|
}
|
|
7077
7093
|
}
|
|
7078
7094
|
|
|
@@ -7105,7 +7121,10 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
|
|
|
7105
7121
|
*/
|
|
7106
7122
|
function readonlyArray(desc) {
|
|
7107
7123
|
return desc.convert((x) => {
|
|
7108
|
-
debug_check
|
|
7124
|
+
debug_check `
|
|
7125
|
+
${Array.isArray(x)}
|
|
7126
|
+
Non-arrays are not supported as 'readonly': got ${typeof x}, ${x}
|
|
7127
|
+
`;
|
|
7109
7128
|
// NOTE [ToDr] This assumption is incorrect in general, but it's documented
|
|
7110
7129
|
// in the general note. We avoid `.slice()` the array for performance reasons.
|
|
7111
7130
|
return x;
|
|
@@ -7553,8 +7572,8 @@ class MultiMap {
|
|
|
7553
7572
|
* if needed.
|
|
7554
7573
|
*/
|
|
7555
7574
|
constructor(keysLength, keyMappers) {
|
|
7556
|
-
check
|
|
7557
|
-
check
|
|
7575
|
+
check `${keysLength > 0} Keys cannot be empty.`;
|
|
7576
|
+
check `${keyMappers === undefined || keyMappers.length === keysLength} Incorrect number of key mappers given!`;
|
|
7558
7577
|
this.data = new Map();
|
|
7559
7578
|
this.keyMappers = keyMappers === undefined ? Array(keysLength).fill(null) : keyMappers;
|
|
7560
7579
|
}
|
|
@@ -7655,7 +7674,7 @@ class sized_array_FixedSizeArray extends Array {
|
|
|
7655
7674
|
this.fixedLength = this.length;
|
|
7656
7675
|
}
|
|
7657
7676
|
static new(data, len) {
|
|
7658
|
-
debug_check
|
|
7677
|
+
debug_check `${data.length === len} Expected an array of size: ${len}, got: ${data.length}`;
|
|
7659
7678
|
const arr = new sized_array_FixedSizeArray(len);
|
|
7660
7679
|
for (let i = 0; i < len; i++) {
|
|
7661
7680
|
arr[i] = data[i];
|
|
@@ -7789,7 +7808,7 @@ class SortedArray {
|
|
|
7789
7808
|
}
|
|
7790
7809
|
/** Create a new SortedSet from two sorted collections. */
|
|
7791
7810
|
static fromTwoSortedCollections(first, second) {
|
|
7792
|
-
debug_check
|
|
7811
|
+
debug_check `${first.comparator === second.comparator} Cannot merge arrays if they do not use the same comparator`;
|
|
7793
7812
|
const comparator = first.comparator;
|
|
7794
7813
|
const arr1 = first.array;
|
|
7795
7814
|
const arr1Length = arr1.length;
|
|
@@ -7909,7 +7928,7 @@ class SortedSet extends SortedArray {
|
|
|
7909
7928
|
}
|
|
7910
7929
|
/** Create a new SortedSet from two sorted collections. */
|
|
7911
7930
|
static fromTwoSortedCollections(first, second) {
|
|
7912
|
-
debug_check
|
|
7931
|
+
debug_check `${first.comparator === second.comparator} Cannot merge arrays if they do not use the same comparator`;
|
|
7913
7932
|
const comparator = first.comparator;
|
|
7914
7933
|
if (first.length === 0) {
|
|
7915
7934
|
return SortedSet.fromSortedArray(comparator, second.array);
|
|
@@ -8547,7 +8566,10 @@ const common_tryAsCoreIndex = (v) => opaque_asOpaqueType(numbers_tryAsU16(v));
|
|
|
8547
8566
|
/** Attempt to convert a number into `Epoch`. */
|
|
8548
8567
|
const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
|
|
8549
8568
|
function tryAsPerValidator(array, spec) {
|
|
8550
|
-
debug_check
|
|
8569
|
+
debug_check `
|
|
8570
|
+
${array.length === spec.validatorsCount}
|
|
8571
|
+
Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
|
|
8572
|
+
`;
|
|
8551
8573
|
return sized_array_asKnownSize(array);
|
|
8552
8574
|
}
|
|
8553
8575
|
const codecPerValidator = (val) => codecWithContext((context) => {
|
|
@@ -8556,7 +8578,10 @@ const codecPerValidator = (val) => codecWithContext((context) => {
|
|
|
8556
8578
|
});
|
|
8557
8579
|
});
|
|
8558
8580
|
function tryAsPerEpochBlock(array, spec) {
|
|
8559
|
-
debug_check
|
|
8581
|
+
debug_check `
|
|
8582
|
+
${array.length === spec.epochLength}
|
|
8583
|
+
Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
|
|
8584
|
+
`;
|
|
8560
8585
|
return sized_array_asKnownSize(array);
|
|
8561
8586
|
}
|
|
8562
8587
|
const codecPerEpochBlock = (val) => codecWithContext((context) => {
|
|
@@ -8827,9 +8852,14 @@ class WorkItem extends WithDebug {
|
|
|
8827
8852
|
|
|
8828
8853
|
|
|
8829
8854
|
|
|
8855
|
+
|
|
8830
8856
|
/** Verify the value is within the `WorkItemsCount` bounds. */
|
|
8831
8857
|
function work_package_tryAsWorkItemsCount(len) {
|
|
8832
|
-
|
|
8858
|
+
debug_check `
|
|
8859
|
+
${len >= MIN_NUMBER_OF_WORK_ITEMS && len <= work_package_MAX_NUMBER_OF_WORK_ITEMS}
|
|
8860
|
+
WorkItemsCount: Expected '${MIN_NUMBER_OF_WORK_ITEMS} <= count <= ${work_package_MAX_NUMBER_OF_WORK_ITEMS}' got ${len}
|
|
8861
|
+
`;
|
|
8862
|
+
return numbers_tryAsU8(len);
|
|
8833
8863
|
}
|
|
8834
8864
|
/** Minimal number of work items in the work package or results in work report. */
|
|
8835
8865
|
const MIN_NUMBER_OF_WORK_ITEMS = 1;
|
|
@@ -10072,7 +10102,10 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
10072
10102
|
|
|
10073
10103
|
/** Check if given array has correct length before casting to the opaque type. */
|
|
10074
10104
|
function tryAsPerCore(array, spec) {
|
|
10075
|
-
debug_check
|
|
10105
|
+
debug_check `
|
|
10106
|
+
${array.length === spec.coresCount}
|
|
10107
|
+
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
10108
|
+
`;
|
|
10076
10109
|
return opaque_asOpaqueType(array);
|
|
10077
10110
|
}
|
|
10078
10111
|
const codecPerCore = (val) => codecWithContext((context) => {
|
|
@@ -11323,7 +11356,7 @@ class InMemoryState extends WithDebug {
|
|
|
11323
11356
|
}
|
|
11324
11357
|
removeServices(servicesRemoved) {
|
|
11325
11358
|
for (const serviceId of servicesRemoved ?? []) {
|
|
11326
|
-
debug_check
|
|
11359
|
+
debug_check `${this.services.has(serviceId)} Attempting to remove non-existing service: ${serviceId}`;
|
|
11327
11360
|
this.services.delete(serviceId);
|
|
11328
11361
|
}
|
|
11329
11362
|
}
|
|
@@ -11340,7 +11373,10 @@ class InMemoryState extends WithDebug {
|
|
|
11340
11373
|
}
|
|
11341
11374
|
else if (kind === UpdateStorageKind.Remove) {
|
|
11342
11375
|
const { key } = action;
|
|
11343
|
-
debug_check
|
|
11376
|
+
debug_check `
|
|
11377
|
+
${service.data.storage.has(key.toString())}
|
|
11378
|
+
Attempting to remove non-existing storage item at ${serviceId}: ${action.key}
|
|
11379
|
+
`;
|
|
11344
11380
|
service.data.storage.delete(key.toString());
|
|
11345
11381
|
}
|
|
11346
11382
|
else {
|
|
@@ -12023,12 +12059,12 @@ class TrieNode {
|
|
|
12023
12059
|
}
|
|
12024
12060
|
/** View this node as a branch node */
|
|
12025
12061
|
asBranchNode() {
|
|
12026
|
-
debug_check
|
|
12062
|
+
debug_check `${this.getNodeType() === NodeType.Branch} not a branch!`;
|
|
12027
12063
|
return new BranchNode(this);
|
|
12028
12064
|
}
|
|
12029
12065
|
/** View this node as a leaf node */
|
|
12030
12066
|
asLeafNode() {
|
|
12031
|
-
debug_check
|
|
12067
|
+
debug_check `${this.getNodeType() !== NodeType.Branch} not a leaf!`;
|
|
12032
12068
|
return new LeafNode(this);
|
|
12033
12069
|
}
|
|
12034
12070
|
toString() {
|
|
@@ -12516,7 +12552,7 @@ function createSubtreeForBothLeaves(traversedPath, nodes, leafToReplace, leaf) {
|
|
|
12516
12552
|
* Return a single bit from `key` located at `bitIndex`.
|
|
12517
12553
|
*/
|
|
12518
12554
|
function getBit(key, bitIndex) {
|
|
12519
|
-
debug_check
|
|
12555
|
+
debug_check `${bitIndex < TRUNCATED_KEY_BITS} invalid bit index passed ${bitIndex}`;
|
|
12520
12556
|
const byte = bitIndex >>> 3;
|
|
12521
12557
|
const bit = bitIndex - (byte << 3);
|
|
12522
12558
|
const mask = 0b10_00_00_00 >>> bit;
|
|
@@ -13841,7 +13877,7 @@ class TypedPort {
|
|
|
13841
13877
|
* Send a response given the worker that has previously requested something.
|
|
13842
13878
|
*/
|
|
13843
13879
|
respond(localState, request, data, transferList) {
|
|
13844
|
-
debug_check
|
|
13880
|
+
debug_check `${request.kind === "request"}`;
|
|
13845
13881
|
this.postMessage({
|
|
13846
13882
|
kind: "response",
|
|
13847
13883
|
id: request.id,
|
|
@@ -13872,10 +13908,11 @@ class TypedPort {
|
|
|
13872
13908
|
throw new Error(`Invalid message: ${JSON.stringify(msg)}.`);
|
|
13873
13909
|
}
|
|
13874
13910
|
switch (msg.kind) {
|
|
13875
|
-
case "response":
|
|
13876
|
-
debug_check
|
|
13911
|
+
case "response": {
|
|
13912
|
+
debug_check `${this.responseListeners.eventNames().indexOf(reqEvent(msg.id)) !== -1}`;
|
|
13877
13913
|
this.responseListeners.emit(reqEvent(msg.id), null, msg.data, msg.name, msg.localState, msg);
|
|
13878
13914
|
break;
|
|
13915
|
+
}
|
|
13879
13916
|
case "signal":
|
|
13880
13917
|
this.listeners.emit("signal", msg.name, msg.data, msg.localState, msg);
|
|
13881
13918
|
break;
|
|
@@ -14090,9 +14127,9 @@ class channel_MessageChannelStateMachine {
|
|
|
14090
14127
|
const promise = new Promise((resolve, reject) => {
|
|
14091
14128
|
parentPort.once("message", (value) => {
|
|
14092
14129
|
try {
|
|
14093
|
-
debug_check
|
|
14094
|
-
debug_check
|
|
14095
|
-
debug_check
|
|
14130
|
+
debug_check `${value.kind === "request"} The initial message should be a request with channel.`;
|
|
14131
|
+
debug_check `${value.name === CHANNEL_MESSAGE}`;
|
|
14132
|
+
debug_check `${value.data instanceof external_node_worker_threads_namespaceObject.MessagePort}`;
|
|
14096
14133
|
const port = new TypedPort(value.data);
|
|
14097
14134
|
port.respond(machine.currentState().stateName, value, Ok);
|
|
14098
14135
|
resolve(port);
|
|
@@ -14172,7 +14209,7 @@ class machine_StateMachine {
|
|
|
14172
14209
|
/** Get state object by name. */
|
|
14173
14210
|
getState(name) {
|
|
14174
14211
|
const state = this.allStates.get(name);
|
|
14175
|
-
debug_check
|
|
14212
|
+
debug_check `${state !== undefined} Unable to retrieve state object for ${name}.`;
|
|
14176
14213
|
return state;
|
|
14177
14214
|
}
|
|
14178
14215
|
/** Get the currently active state object. */
|
|
@@ -14437,19 +14474,22 @@ class Preimages {
|
|
|
14437
14474
|
|
|
14438
14475
|
const NO_OF_REGISTERS = 13;
|
|
14439
14476
|
const REGISTER_SIZE_SHIFT = 3;
|
|
14440
|
-
const tryAsRegisterIndex = (index) =>
|
|
14477
|
+
const tryAsRegisterIndex = (index) => {
|
|
14478
|
+
debug_check `${index >= 0 && index < NO_OF_REGISTERS} Incorrect register index: ${index}!`;
|
|
14479
|
+
return opaque_asOpaqueType(index);
|
|
14480
|
+
};
|
|
14441
14481
|
class Registers {
|
|
14442
14482
|
bytes;
|
|
14443
14483
|
asSigned;
|
|
14444
14484
|
asUnsigned;
|
|
14445
14485
|
constructor(bytes = new Uint8Array(NO_OF_REGISTERS << REGISTER_SIZE_SHIFT)) {
|
|
14446
14486
|
this.bytes = bytes;
|
|
14447
|
-
debug_check
|
|
14487
|
+
debug_check `${bytes.length === NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
14448
14488
|
this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
|
|
14449
14489
|
this.asUnsigned = new BigUint64Array(bytes.buffer, bytes.byteOffset);
|
|
14450
14490
|
}
|
|
14451
14491
|
static fromBytes(bytes) {
|
|
14452
|
-
debug_check
|
|
14492
|
+
debug_check `${bytes.length === NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
14453
14493
|
return new Registers(bytes);
|
|
14454
14494
|
}
|
|
14455
14495
|
getBytesAsLittleEndian(index, len) {
|
|
@@ -14595,7 +14635,7 @@ class Mask {
|
|
|
14595
14635
|
return this.lookupTableForward[index] === 0;
|
|
14596
14636
|
}
|
|
14597
14637
|
getNoOfBytesToNextInstruction(index) {
|
|
14598
|
-
debug_check
|
|
14638
|
+
debug_check `${index >= 0} index (${index}) cannot be a negative number`;
|
|
14599
14639
|
return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
|
|
14600
14640
|
}
|
|
14601
14641
|
buildLookupTableForward(mask) {
|
|
@@ -15595,7 +15635,7 @@ const PAGE_SIZE_SHIFT = 12;
|
|
|
15595
15635
|
const PAGE_SIZE = 1 << PAGE_SIZE_SHIFT;
|
|
15596
15636
|
const MIN_ALLOCATION_SHIFT = (() => {
|
|
15597
15637
|
const MIN_ALLOCATION_SHIFT = 7;
|
|
15598
|
-
debug_check
|
|
15638
|
+
debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
|
|
15599
15639
|
return MIN_ALLOCATION_SHIFT;
|
|
15600
15640
|
})();
|
|
15601
15641
|
const MIN_ALLOCATION_LENGTH = PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
|
|
@@ -15608,16 +15648,28 @@ const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / PAGE_SIZE;
|
|
|
15608
15648
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
|
|
15609
15649
|
|
|
15610
15650
|
|
|
15611
|
-
const tryAsMemoryIndex = (index) =>
|
|
15612
|
-
|
|
15651
|
+
const tryAsMemoryIndex = (index) => {
|
|
15652
|
+
debug_check `${index >= 0 && index <= MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
|
|
15653
|
+
return opaque_asOpaqueType(index);
|
|
15654
|
+
};
|
|
15655
|
+
const tryAsSbrkIndex = (index) => {
|
|
15656
|
+
debug_check `${index >= 0 && index <= MAX_MEMORY_INDEX + 1} Incorrect sbrk index: ${index}!`;
|
|
15657
|
+
return opaque_asOpaqueType(index);
|
|
15658
|
+
};
|
|
15613
15659
|
|
|
15614
15660
|
;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
|
|
15615
15661
|
|
|
15616
15662
|
|
|
15617
15663
|
/** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
|
|
15618
|
-
const tryAsPageIndex = (index) =>
|
|
15664
|
+
const tryAsPageIndex = (index) => {
|
|
15665
|
+
debug_check `${index >= 0 && index < PAGE_SIZE}, Incorect page index: ${index}!`;
|
|
15666
|
+
return opaque_asOpaqueType(index);
|
|
15667
|
+
};
|
|
15619
15668
|
/** Ensure that given `index` represents an index of one of the pages. */
|
|
15620
|
-
const tryAsPageNumber = (index) =>
|
|
15669
|
+
const tryAsPageNumber = (index) => {
|
|
15670
|
+
debug_check `${index >= 0 && index <= LAST_PAGE_NUMBER}, Incorect page number: ${index}!`;
|
|
15671
|
+
return opaque_asOpaqueType(index);
|
|
15672
|
+
};
|
|
15621
15673
|
/**
|
|
15622
15674
|
* Get the next page number and wrap the result if it is bigger than LAST_PAGE_NUMBER
|
|
15623
15675
|
*
|
|
@@ -16149,10 +16201,10 @@ class MemoryBuilder {
|
|
|
16149
16201
|
*/
|
|
16150
16202
|
setReadablePages(start, end, data = new Uint8Array()) {
|
|
16151
16203
|
this.ensureNotFinalized();
|
|
16152
|
-
debug_check
|
|
16153
|
-
debug_check
|
|
16154
|
-
debug_check
|
|
16155
|
-
debug_check
|
|
16204
|
+
debug_check `${start < end} end has to be bigger than start`;
|
|
16205
|
+
debug_check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
|
|
16206
|
+
debug_check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
|
|
16207
|
+
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
16156
16208
|
const length = end - start;
|
|
16157
16209
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
16158
16210
|
this.ensureNoReservedMemoryUsage(range);
|
|
@@ -16177,10 +16229,10 @@ class MemoryBuilder {
|
|
|
16177
16229
|
*/
|
|
16178
16230
|
setWriteablePages(start, end, data = new Uint8Array()) {
|
|
16179
16231
|
this.ensureNotFinalized();
|
|
16180
|
-
debug_check
|
|
16181
|
-
debug_check
|
|
16182
|
-
debug_check
|
|
16183
|
-
debug_check
|
|
16232
|
+
debug_check `${start < end} end has to be bigger than start`;
|
|
16233
|
+
debug_check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
|
|
16234
|
+
debug_check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
|
|
16235
|
+
debug_check `${data.length <= end - start} the initial data is longer than address range`;
|
|
16184
16236
|
const length = end - start;
|
|
16185
16237
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
16186
16238
|
this.ensureNoReservedMemoryUsage(range);
|
|
@@ -16202,7 +16254,7 @@ class MemoryBuilder {
|
|
|
16202
16254
|
this.ensureNotFinalized();
|
|
16203
16255
|
const pageOffset = start % PAGE_SIZE;
|
|
16204
16256
|
const remainingSpaceOnPage = PAGE_SIZE - pageOffset;
|
|
16205
|
-
debug_check
|
|
16257
|
+
debug_check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
|
|
16206
16258
|
const length = data.length;
|
|
16207
16259
|
const range = MemoryRange.fromStartAndLength(start, length);
|
|
16208
16260
|
this.ensureNoReservedMemoryUsage(range);
|
|
@@ -16216,7 +16268,10 @@ class MemoryBuilder {
|
|
|
16216
16268
|
return this;
|
|
16217
16269
|
}
|
|
16218
16270
|
finalize(startHeapIndex, endHeapIndex) {
|
|
16219
|
-
debug_check
|
|
16271
|
+
debug_check `
|
|
16272
|
+
${startHeapIndex <= endHeapIndex}
|
|
16273
|
+
startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
|
|
16274
|
+
`;
|
|
16220
16275
|
this.ensureNotFinalized();
|
|
16221
16276
|
const range = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
|
|
16222
16277
|
const pages = PageRange.fromMemoryRange(range);
|
|
@@ -16454,7 +16509,7 @@ function mulU64(a, b) {
|
|
|
16454
16509
|
*
|
|
16455
16510
|
* The result of multiplication is a 64-bits number and we are only interested in the part that lands in the upper 32-bits.
|
|
16456
16511
|
* For example if we multiply `0xffffffff * 0xffffffff`, we get:
|
|
16457
|
-
|
|
16512
|
+
|
|
16458
16513
|
* | 64-bits | 64-bits |
|
|
16459
16514
|
* +--------------------+--------------------+
|
|
16460
16515
|
* | upper | lower |
|
|
@@ -16490,7 +16545,7 @@ function mulUpperSS(a, b) {
|
|
|
16490
16545
|
return interpretAsSigned(resultLimitedTo64Bits);
|
|
16491
16546
|
}
|
|
16492
16547
|
function unsignedRightShiftBigInt(value, shift) {
|
|
16493
|
-
debug_check
|
|
16548
|
+
debug_check `${shift >= 0} Shift count must be non-negative`;
|
|
16494
16549
|
const fillBit = value < 0 ? "1" : "0";
|
|
16495
16550
|
// Convert the BigInt to its binary representation
|
|
16496
16551
|
const binaryRepresentation = value.toString(2).padStart(64, fillBit);
|
|
@@ -17906,7 +17961,10 @@ class TwoRegsTwoImmsDispatcher {
|
|
|
17906
17961
|
class JumpTable {
|
|
17907
17962
|
indices;
|
|
17908
17963
|
constructor(itemByteLength, bytes) {
|
|
17909
|
-
debug_check
|
|
17964
|
+
debug_check `
|
|
17965
|
+
${itemByteLength === 0 || bytes.length % itemByteLength === 0}
|
|
17966
|
+
Length of jump table (${bytes.length}) should be a multiple of item lenght (${itemByteLength})!
|
|
17967
|
+
`;
|
|
17910
17968
|
const length = itemByteLength === 0 ? 0 : bytes.length / itemByteLength;
|
|
17911
17969
|
this.indices = new Uint32Array(length);
|
|
17912
17970
|
for (let i = 0; i < length; i++) {
|
|
@@ -18350,7 +18408,10 @@ class ReturnValue {
|
|
|
18350
18408
|
this.consumedGas = consumedGas;
|
|
18351
18409
|
this.status = status;
|
|
18352
18410
|
this.memorySlice = memorySlice;
|
|
18353
|
-
debug_check
|
|
18411
|
+
debug_check `
|
|
18412
|
+
${(status === null && memorySlice !== null) || (status !== null && memorySlice === null)}
|
|
18413
|
+
'status' and 'memorySlice' must not both be null or both be non-null — exactly one must be provided
|
|
18414
|
+
`;
|
|
18354
18415
|
}
|
|
18355
18416
|
static fromStatus(consumedGas, status) {
|
|
18356
18417
|
return new ReturnValue(consumedGas, status, null);
|
|
@@ -18399,7 +18460,10 @@ class HostCalls {
|
|
|
18399
18460
|
if (status !== status_Status.HOST) {
|
|
18400
18461
|
return this.getReturnValue(status, pvmInstance);
|
|
18401
18462
|
}
|
|
18402
|
-
debug_check
|
|
18463
|
+
debug_check `
|
|
18464
|
+
${pvmInstance.getExitParam() !== null}
|
|
18465
|
+
"We know that the exit param is not null, because the status is 'Status.HOST'
|
|
18466
|
+
`;
|
|
18403
18467
|
const hostCallIndex = pvmInstance.getExitParam() ?? -1;
|
|
18404
18468
|
const gas = pvmInstance.getGasCounter();
|
|
18405
18469
|
const regs = new HostCallRegisters(pvmInstance.getRegisters());
|
|
@@ -18459,7 +18523,7 @@ class host_calls_manager_HostCallsManager {
|
|
|
18459
18523
|
constructor({ missing, handlers = [], }) {
|
|
18460
18524
|
this.missing = missing;
|
|
18461
18525
|
for (const handler of handlers) {
|
|
18462
|
-
debug_check
|
|
18526
|
+
debug_check `${this.hostCalls.get(handler.index) === undefined} Overwriting host call handler at index ${handler.index}`;
|
|
18463
18527
|
this.hostCalls.set(handler.index, handler);
|
|
18464
18528
|
}
|
|
18465
18529
|
}
|
|
@@ -18582,7 +18646,7 @@ function getServiceId(serviceId) {
|
|
|
18582
18646
|
return null;
|
|
18583
18647
|
}
|
|
18584
18648
|
function writeServiceIdAsLeBytes(serviceId, destination) {
|
|
18585
|
-
debug_check
|
|
18649
|
+
debug_check `${destination.length >= SERVICE_ID_BYTES} Not enough space in the destination.`;
|
|
18586
18650
|
destination.set(numbers_u32AsLeBytes(serviceId));
|
|
18587
18651
|
}
|
|
18588
18652
|
/** Clamp a U64 to the maximum value of a 32-bit unsigned integer. */
|
|
@@ -18671,13 +18735,27 @@ class SpiProgram extends WithDebug {
|
|
|
18671
18735
|
this.registers = registers;
|
|
18672
18736
|
}
|
|
18673
18737
|
}
|
|
18738
|
+
/**
|
|
18739
|
+
* program = E_3(|o|) ++ E_3(|w|) ++ E_2(z) ++ E_3(s) ++ o ++ w ++ E_4(|c|) ++ c
|
|
18740
|
+
*
|
|
18741
|
+
* E_n - little endian encoding, n - length
|
|
18742
|
+
* o - initial read only data
|
|
18743
|
+
* w - initial heap
|
|
18744
|
+
* z - heap pages filled with zeros
|
|
18745
|
+
* s - stack size
|
|
18746
|
+
* c - program code
|
|
18747
|
+
*
|
|
18748
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/2b92022b9202
|
|
18749
|
+
*/
|
|
18674
18750
|
function decodeStandardProgram(program, args) {
|
|
18675
18751
|
const decoder = decoder_Decoder.fromBlob(program);
|
|
18676
18752
|
const oLength = decoder.u24();
|
|
18677
18753
|
const wLength = decoder.u24();
|
|
18678
|
-
|
|
18679
|
-
|
|
18680
|
-
const
|
|
18754
|
+
debug_check `${args.length <= DATA_LEGNTH} Incorrect arguments length`;
|
|
18755
|
+
debug_check `${oLength <= DATA_LEGNTH} Incorrect readonly segment length`;
|
|
18756
|
+
const readOnlyLength = oLength;
|
|
18757
|
+
debug_check `${wLength <= DATA_LEGNTH} Incorrect heap segment length`;
|
|
18758
|
+
const heapLength = wLength;
|
|
18681
18759
|
const noOfHeapZerosPages = decoder.u16();
|
|
18682
18760
|
const stackSize = decoder.u24();
|
|
18683
18761
|
const readOnlyMemory = decoder.bytes(readOnlyLength).raw;
|
|
@@ -18693,14 +18771,14 @@ function decodeStandardProgram(program, args) {
|
|
|
18693
18771
|
const stackStart = STACK_SEGMENT - memory_utils_alignToPageSize(stackSize);
|
|
18694
18772
|
const stackEnd = STACK_SEGMENT;
|
|
18695
18773
|
const argsStart = ARGS_SEGMENT;
|
|
18696
|
-
const argsEnd = argsStart + memory_utils_alignToPageSize(
|
|
18697
|
-
const argsZerosEnd = argsEnd + memory_utils_alignToPageSize(
|
|
18774
|
+
const argsEnd = argsStart + memory_utils_alignToPageSize(args.length);
|
|
18775
|
+
const argsZerosEnd = argsEnd + memory_utils_alignToPageSize(args.length);
|
|
18698
18776
|
function nonEmpty(s) {
|
|
18699
18777
|
return s !== false;
|
|
18700
18778
|
}
|
|
18701
18779
|
const readableMemory = [
|
|
18702
18780
|
readOnlyLength > 0 && getMemorySegment(readonlyDataStart, readonlyDataEnd, readOnlyMemory),
|
|
18703
|
-
|
|
18781
|
+
args.length > 0 && getMemorySegment(argsStart, argsEnd, args),
|
|
18704
18782
|
argsEnd < argsZerosEnd && getMemorySegment(argsEnd, argsZerosEnd),
|
|
18705
18783
|
].filter(nonEmpty);
|
|
18706
18784
|
const writeableMemory = [
|
|
@@ -20223,8 +20301,8 @@ class PartiallyUpdatedState {
|
|
|
20223
20301
|
this.stateUpdate.services.preimages.push(newUpdate);
|
|
20224
20302
|
}
|
|
20225
20303
|
updateServiceStorageUtilisation(serviceId, items, bytes, serviceInfo) {
|
|
20226
|
-
debug_check
|
|
20227
|
-
debug_check
|
|
20304
|
+
debug_check `${items >= 0} storageUtilisationCount has to be a positive number, got: ${items}`;
|
|
20305
|
+
debug_check `${bytes >= 0} storageUtilisationBytes has to be a positive number, got: ${bytes}`;
|
|
20228
20306
|
const overflowItems = !isU32(items);
|
|
20229
20307
|
const overflowBytes = !isU64(bytes);
|
|
20230
20308
|
// TODO [ToDr] this is not specified in GP, but it seems sensible.
|
|
@@ -20649,7 +20727,7 @@ class AccumulateExternalities {
|
|
|
20649
20727
|
}
|
|
20650
20728
|
// TODO [ToDr] Not sure if we should update the service info in that case,
|
|
20651
20729
|
// but for now we let that case fall-through.
|
|
20652
|
-
debug_check
|
|
20730
|
+
debug_check `${len === PreimageStatusKind.Unavailable} preimage is not unavailable`;
|
|
20653
20731
|
}
|
|
20654
20732
|
// make sure we have enough balance for this update
|
|
20655
20733
|
// https://graypaper.fluffylabs.dev/#/9a08063/381201381601?v=0.6.6
|
|
@@ -21145,7 +21223,7 @@ class Assurances {
|
|
|
21145
21223
|
return result_Result.error(AssurancesError.InvalidOrder, `order: expected: ${prevValidatorIndex + 1}, got: ${validatorIndex}`);
|
|
21146
21224
|
}
|
|
21147
21225
|
prevValidatorIndex = assurance.validatorIndex;
|
|
21148
|
-
debug_check
|
|
21226
|
+
debug_check `${bitfield.bitLength === coresCount} Invalid bitfield length of ${bitfield.bitLength}`;
|
|
21149
21227
|
const setBits = bitfield.indicesOfSetBits();
|
|
21150
21228
|
for (const idx of setBits) {
|
|
21151
21229
|
perCoreAssurances[idx] += 1;
|
|
@@ -23469,7 +23547,7 @@ class DeferredTransfers {
|
|
|
23469
23547
|
transferStatistics.set(serviceId, { count: numbers_tryAsU32(transfers.length), gasUsed: common_tryAsServiceGas(consumedGas) });
|
|
23470
23548
|
const [updatedState, checkpointedState] = partialState.getStateUpdates();
|
|
23471
23549
|
currentStateUpdate = updatedState;
|
|
23472
|
-
debug_check
|
|
23550
|
+
debug_check `${checkpointedState === null} On transfer cannot invoke checkpoint.`;
|
|
23473
23551
|
}
|
|
23474
23552
|
return result_Result.ok({
|
|
23475
23553
|
// NOTE: we return only services, since it's impossible to update
|
|
@@ -23807,7 +23885,7 @@ const ENTROPY_BYTES = 32;
|
|
|
23807
23885
|
* https://graypaper.fluffylabs.dev/#/579bd12/3b9a013b9a01
|
|
23808
23886
|
*/
|
|
23809
23887
|
function fisherYatesShuffle(arr, entropy) {
|
|
23810
|
-
debug_check
|
|
23888
|
+
debug_check `${entropy.length === ENTROPY_BYTES} Expected entropy of length ${ENTROPY_BYTES}, got ${entropy.length}`;
|
|
23811
23889
|
const n = arr.length;
|
|
23812
23890
|
const randomNumbers = hashToNumberSequence(entropy, arr.length);
|
|
23813
23891
|
const result = new Array(n);
|
|
@@ -24654,7 +24732,7 @@ class Statistics {
|
|
|
24654
24732
|
/** get statistics for the current epoch */
|
|
24655
24733
|
const statistics = this.getStatistics(slot);
|
|
24656
24734
|
const { current, cores, services } = statistics;
|
|
24657
|
-
debug_check
|
|
24735
|
+
debug_check `${current[authorIndex] !== undefined} authorIndex is out of bounds`;
|
|
24658
24736
|
/** One validator can produce maximal one block per timeslot */
|
|
24659
24737
|
const newBlocksCount = current[authorIndex].blocks + 1;
|
|
24660
24738
|
current[authorIndex].blocks = numbers_tryAsU32(newBlocksCount);
|