@aztec/blob-lib 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107
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/dest/batched_blob.d.ts +26 -0
- package/dest/batched_blob.d.ts.map +1 -0
- package/dest/batched_blob.js +20 -0
- package/dest/blob.d.ts +50 -99
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +78 -169
- package/dest/blob_batching.d.ts +41 -123
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +129 -203
- package/dest/blob_utils.d.ts +40 -0
- package/dest/blob_utils.d.ts.map +1 -0
- package/dest/blob_utils.js +69 -0
- package/dest/circuit_types/blob_accumulator.d.ts +23 -0
- package/dest/circuit_types/blob_accumulator.d.ts.map +1 -0
- package/dest/circuit_types/blob_accumulator.js +62 -0
- package/dest/circuit_types/final_blob_accumulator.d.ts +23 -0
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -0
- package/dest/circuit_types/final_blob_accumulator.js +66 -0
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +16 -0
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -0
- package/dest/circuit_types/final_blob_batching_challenges.js +26 -0
- package/dest/circuit_types/index.d.ts +4 -0
- package/dest/circuit_types/index.d.ts.map +1 -0
- package/dest/circuit_types/index.js +4 -0
- package/dest/encoding/block_blob_data.d.ts +22 -0
- package/dest/encoding/block_blob_data.d.ts.map +1 -0
- package/dest/encoding/block_blob_data.js +65 -0
- package/dest/encoding/block_end_marker.d.ts +11 -0
- package/dest/encoding/block_end_marker.d.ts.map +1 -0
- package/dest/encoding/block_end_marker.js +41 -0
- package/dest/encoding/block_end_state_field.d.ts +12 -0
- package/dest/encoding/block_end_state_field.d.ts.map +1 -0
- package/dest/encoding/block_end_state_field.js +39 -0
- package/dest/encoding/checkpoint_blob_data.d.ts +15 -0
- package/dest/encoding/checkpoint_blob_data.d.ts.map +1 -0
- package/dest/encoding/checkpoint_blob_data.js +67 -0
- package/dest/encoding/checkpoint_end_marker.d.ts +8 -0
- package/dest/encoding/checkpoint_end_marker.d.ts.map +1 -0
- package/dest/encoding/checkpoint_end_marker.js +28 -0
- package/dest/encoding/fixtures.d.ts +41 -0
- package/dest/encoding/fixtures.d.ts.map +1 -0
- package/dest/encoding/fixtures.js +140 -0
- package/dest/encoding/index.d.ts +10 -0
- package/dest/encoding/index.d.ts.map +1 -0
- package/dest/encoding/index.js +9 -0
- package/dest/encoding/tx_blob_data.d.ts +19 -0
- package/dest/encoding/tx_blob_data.d.ts.map +1 -0
- package/dest/encoding/tx_blob_data.js +79 -0
- package/dest/encoding/tx_start_marker.d.ts +16 -0
- package/dest/encoding/tx_start_marker.d.ts.map +1 -0
- package/dest/encoding/tx_start_marker.js +77 -0
- package/dest/errors.d.ts +1 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/hash.d.ts +43 -0
- package/dest/hash.d.ts.map +1 -0
- package/dest/hash.js +80 -0
- package/dest/index.d.ts +7 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +6 -16
- package/dest/interface.d.ts +1 -2
- package/dest/interface.d.ts.map +1 -1
- package/dest/kzg_context.d.ts +8 -0
- package/dest/kzg_context.d.ts.map +1 -0
- package/dest/kzg_context.js +14 -0
- package/dest/sponge_blob.d.ts +12 -14
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +26 -30
- package/dest/testing.d.ts +10 -23
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +37 -53
- package/dest/types.d.ts +17 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +4 -0
- package/package.json +10 -7
- package/src/batched_blob.ts +26 -0
- package/src/blob.ts +81 -195
- package/src/blob_batching.ts +168 -231
- package/src/blob_utils.ts +82 -0
- package/src/circuit_types/blob_accumulator.ts +96 -0
- package/src/circuit_types/final_blob_accumulator.ts +76 -0
- package/src/circuit_types/final_blob_batching_challenges.ts +30 -0
- package/src/circuit_types/index.ts +4 -0
- package/src/encoding/block_blob_data.ts +102 -0
- package/src/encoding/block_end_marker.ts +55 -0
- package/src/encoding/block_end_state_field.ts +59 -0
- package/src/encoding/checkpoint_blob_data.ts +95 -0
- package/src/encoding/checkpoint_end_marker.ts +40 -0
- package/src/encoding/fixtures.ts +210 -0
- package/src/encoding/index.ts +9 -0
- package/src/encoding/tx_blob_data.ts +116 -0
- package/src/encoding/tx_start_marker.ts +97 -0
- package/src/hash.ts +89 -0
- package/src/index.ts +6 -19
- package/src/interface.ts +0 -1
- package/src/kzg_context.ts +16 -0
- package/src/sponge_blob.ts +28 -31
- package/src/testing.ts +48 -59
- package/src/types.ts +17 -0
- package/dest/blob_batching_public_inputs.d.ts +0 -71
- package/dest/blob_batching_public_inputs.d.ts.map +0 -1
- package/dest/blob_batching_public_inputs.js +0 -168
- package/dest/encoding.d.ts +0 -66
- package/dest/encoding.d.ts.map +0 -1
- package/dest/encoding.js +0 -113
- package/src/blob_batching_public_inputs.ts +0 -252
- package/src/encoding.ts +0 -138
package/src/encoding.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
-
|
|
4
|
-
import type { Blob as BlobBuffer } from 'c-kzg';
|
|
5
|
-
|
|
6
|
-
// Note duplicated from stdlib !
|
|
7
|
-
// This will appear as 0x74785f7374617274 in logs
|
|
8
|
-
export const TX_START_PREFIX = 8392562855083340404n;
|
|
9
|
-
// These are helper constants to decode tx effects from blob encoded fields
|
|
10
|
-
export const TX_START_PREFIX_BYTES_LENGTH = TX_START_PREFIX.toString(16).length / 2;
|
|
11
|
-
// 7 bytes for: | 0 | txlen[0] | txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revertCode |
|
|
12
|
-
export const TX_EFFECT_PREFIX_BYTE_LENGTH = TX_START_PREFIX_BYTES_LENGTH + 7;
|
|
13
|
-
export const REVERT_CODE_PREFIX = 1;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Deserializes a blob buffer into an array of field elements.
|
|
17
|
-
*
|
|
18
|
-
* Blobs are converted into BN254 fields to perform a poseidon2 hash on them (fieldHash).
|
|
19
|
-
* This method is sparse, meaning it does not include trailing zeros at the end of the blob.
|
|
20
|
-
*
|
|
21
|
-
* However, we cannot simply trim the zero's from the end of the blob, as some logs may include zero's
|
|
22
|
-
* within them.
|
|
23
|
-
* If we end on a set of zeros, such as the log below:
|
|
24
|
-
* length 7: [ a, b, c, d, e, 0, 0]
|
|
25
|
-
*
|
|
26
|
-
* we will end up with the incorrect hash if we trim the zeros from the end.
|
|
27
|
-
*
|
|
28
|
-
* Each transactions logs contains a TX start prefix, which includes a string followed
|
|
29
|
-
* by the length ( in field elements ) of the transaction's log.
|
|
30
|
-
*
|
|
31
|
-
* This function finds the end of the last transaction's logs, and returns the array up to this point.
|
|
32
|
-
*
|
|
33
|
-
* We search for a series of Tx Prefixes progressing the cursor in the field reader until we hit
|
|
34
|
-
* a field that is not a Tx Prefix, this indicates that we have reached the end of the last transaction's logs.
|
|
35
|
-
*
|
|
36
|
-
* +------------------+------------------+------------------+------------------+
|
|
37
|
-
* | TX1 Start Prefix | TX1 Log Fields | TX2 Start Prefix | Padded zeros |
|
|
38
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
39
|
-
* +------------------+------------------+------------------+------------------+
|
|
40
|
-
* ^
|
|
41
|
-
* |
|
|
42
|
-
* Function reads until here --------------------------------
|
|
43
|
-
*
|
|
44
|
-
* @param blob - The blob buffer to deserialize.
|
|
45
|
-
* @returns An array of field elements.
|
|
46
|
-
*/
|
|
47
|
-
export function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[] {
|
|
48
|
-
// Convert blob buffer to array of field elements
|
|
49
|
-
const reader = BufferReader.asReader(blob);
|
|
50
|
-
const array = reader.readArray(blob.length >> 5, Fr); // >> 5 = / 32 (bytes per field)
|
|
51
|
-
const fieldReader = FieldReader.asReader(array);
|
|
52
|
-
|
|
53
|
-
// Read fields until we hit zeros at the end
|
|
54
|
-
while (!fieldReader.isFinished()) {
|
|
55
|
-
const currentField = fieldReader.peekField();
|
|
56
|
-
|
|
57
|
-
// Stop when we hit a zero field
|
|
58
|
-
if (!currentField || currentField.isZero()) {
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Skip the remaining fields in this transaction
|
|
63
|
-
const len = getLengthFromFirstField(currentField);
|
|
64
|
-
fieldReader.skip(len);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Return array up to last non-zero field
|
|
68
|
-
return array.slice(0, fieldReader.cursor);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get the length of the transaction from the first field.
|
|
73
|
-
*
|
|
74
|
-
* @param firstField - The first field of the transaction.
|
|
75
|
-
* @returns The length of the transaction.
|
|
76
|
-
*
|
|
77
|
-
* @throws If the first field does not include the correct prefix - encoding invalid.
|
|
78
|
-
*/
|
|
79
|
-
export function getLengthFromFirstField(firstField: Fr): number {
|
|
80
|
-
// Check that the first field includes the correct prefix
|
|
81
|
-
if (!isValidFirstField(firstField)) {
|
|
82
|
-
throw new Error('Invalid prefix');
|
|
83
|
-
}
|
|
84
|
-
const buf = firstField.toBuffer().subarray(-TX_EFFECT_PREFIX_BYTE_LENGTH);
|
|
85
|
-
return new Fr(buf.subarray(TX_START_PREFIX_BYTES_LENGTH + 1, TX_START_PREFIX_BYTES_LENGTH + 3)).toNumber();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Determines whether a field is the first field of a tx effect
|
|
90
|
-
*/
|
|
91
|
-
export function isValidFirstField(field: Fr): boolean {
|
|
92
|
-
const buf = field.toBuffer();
|
|
93
|
-
if (
|
|
94
|
-
!buf
|
|
95
|
-
.subarray(0, field.size - TX_EFFECT_PREFIX_BYTE_LENGTH)
|
|
96
|
-
.equals(Buffer.alloc(field.size - TX_EFFECT_PREFIX_BYTE_LENGTH))
|
|
97
|
-
) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
const sliced = buf.subarray(-TX_EFFECT_PREFIX_BYTE_LENGTH);
|
|
101
|
-
if (
|
|
102
|
-
// Checking we start with the correct prefix...
|
|
103
|
-
!new Fr(sliced.subarray(0, TX_START_PREFIX_BYTES_LENGTH)).equals(new Fr(TX_START_PREFIX)) ||
|
|
104
|
-
// ...and include the revert code prefix..
|
|
105
|
-
sliced[sliced.length - 3] !== REVERT_CODE_PREFIX ||
|
|
106
|
-
// ...and the following revert code is valid.
|
|
107
|
-
sliced[sliced.length - 1] > 4
|
|
108
|
-
) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Extract the fields from a blob buffer, but do not take into account encoding
|
|
116
|
-
* that will include trailing zeros.
|
|
117
|
-
*
|
|
118
|
-
* +------------------+------------------+------------------+------------------+
|
|
119
|
-
* | | | | Padded zeros |
|
|
120
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
121
|
-
* +------------------+------------------+------------------+------------------+
|
|
122
|
-
* ^
|
|
123
|
-
* |
|
|
124
|
-
* Function reads until here ----------------------
|
|
125
|
-
*/
|
|
126
|
-
export function extractBlobFieldsFromBuffer(blob: BlobBuffer): Fr[] {
|
|
127
|
-
const reader = BufferReader.asReader(blob);
|
|
128
|
-
const array = reader.readArray(blob.length >> 5, Fr);
|
|
129
|
-
|
|
130
|
-
// Find the index of the last non-zero field
|
|
131
|
-
let lastNonZeroIndex = array.length - 1;
|
|
132
|
-
while (lastNonZeroIndex >= 0 && array[lastNonZeroIndex].isZero()) {
|
|
133
|
-
lastNonZeroIndex--;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Return the trimmed array
|
|
137
|
-
return array.slice(0, lastNonZeroIndex + 1);
|
|
138
|
-
}
|