@aztec/blob-lib 3.0.0-nightly.20250916 → 3.0.0-nightly.20250918
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/blob.js +1 -1
- package/dest/blob_batching.d.ts +0 -1
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +1 -18
- package/dest/blob_batching_public_inputs.d.ts +0 -14
- package/dest/blob_batching_public_inputs.d.ts.map +1 -1
- package/dest/blob_batching_public_inputs.js +1 -25
- package/dest/deserialize.d.ts +49 -0
- package/dest/deserialize.d.ts.map +1 -0
- package/dest/deserialize.js +81 -0
- package/dest/encoding.d.ts +3 -52
- package/dest/encoding.d.ts.map +1 -1
- package/dest/encoding.js +13 -76
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/testing.d.ts +0 -8
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +2 -11
- package/dest/types.d.ts +2 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +1 -0
- package/package.json +5 -3
- package/src/blob.ts +1 -1
- package/src/blob_batching.ts +0 -14
- package/src/blob_batching_public_inputs.ts +0 -34
- package/src/deserialize.ts +95 -0
- package/src/encoding.ts +13 -85
- package/src/index.ts +1 -0
- package/src/testing.ts +2 -17
- package/src/types.ts +3 -0
package/dest/blob.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
3
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
4
|
// Importing directly from 'c-kzg' does not work:
|
|
5
5
|
import cKzg from 'c-kzg';
|
|
6
|
-
import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './
|
|
6
|
+
import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './deserialize.js';
|
|
7
7
|
import { BlobDeserializationError } from './errors.js';
|
|
8
8
|
const { BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, blobToKzgCommitment, computeKzgProof, verifyKzgProof } = cKzg;
|
|
9
9
|
// The prefix to the EVM blobHash, defined here: https://eips.ethereum.org/EIPS/eip-4844#specification
|
package/dest/blob_batching.d.ts
CHANGED
|
@@ -51,7 +51,6 @@ export declare class BatchedBlob {
|
|
|
51
51
|
* @returns Challenges z and gamma.
|
|
52
52
|
*/
|
|
53
53
|
static precomputeBatchedBlobChallenges(blobs: Blob[]): Promise<FinalBlobBatchingChallenges>;
|
|
54
|
-
static precomputeEmptyBatchedBlobChallenges(): Promise<FinalBlobBatchingChallenges>;
|
|
55
54
|
getEthVersionedBlobHash(): Buffer;
|
|
56
55
|
static getEthVersionedBlobHash(commitment: Buffer): Buffer;
|
|
57
56
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob_batching.d.ts","sourceRoot":"","sources":["../src/blob_batching.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAK9E,OAAO,EAAE,IAAI,EAA8B,MAAM,WAAW,CAAC;AAI7D;;GAEG;AACH,qBAAa,WAAW;IAEpB,8CAA8C;aAC9B,mBAAmB,EAAE,EAAE;IACvC,gDAAgD;aAChC,CAAC,EAAE,EAAE;IACrB,mFAAmF;aACnE,CAAC,EAAE,OAAO;IAC1B,kFAAkF;aAClE,UAAU,EAAE,UAAU;IACtC,4HAA4H;aAC5G,CAAC,EAAE,UAAU;;IAT7B,8CAA8C;IAC9B,mBAAmB,EAAE,EAAE;IACvC,gDAAgD;IAChC,CAAC,EAAE,EAAE;IACrB,mFAAmF;IACnE,CAAC,EAAE,OAAO;IAC1B,kFAAkF;IAClE,UAAU,EAAE,UAAU;IACtC,4HAA4H;IAC5G,CAAC,EAAE,UAAU;IAG/B;;;;;;OAMG;WACU,KAAK,CAAC,KAAK,E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,OAAO,CAAC,sBAAsB,CAAC;IAgBlC;;;OAGG;IACH,MAAM,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,2BAA2B,GAAG,sBAAsB;IAalG;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,IAAI;IAqB3B;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE;IASnC;;;;;;;;;;;;OAYG;IACG,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC;IAqBtC,YAAY;IAYZ,KAAK;CAYN"}
|
package/dest/blob_batching.js
CHANGED
|
@@ -4,7 +4,7 @@ import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
|
4
4
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
5
|
// Importing directly from 'c-kzg' does not work:
|
|
6
6
|
import cKzg from 'c-kzg';
|
|
7
|
-
import {
|
|
7
|
+
import { VERSIONED_HASH_VERSION_KZG } from './blob.js';
|
|
8
8
|
const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
9
9
|
/**
|
|
10
10
|
* A class to create, manage, and prove batched EVM blobs.
|
|
@@ -83,23 +83,6 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
|
83
83
|
]);
|
|
84
84
|
return new FinalBlobBatchingChallenges(z, BLS12Fr.fromBN254Fr(gamma));
|
|
85
85
|
}
|
|
86
|
-
static async precomputeEmptyBatchedBlobChallenges() {
|
|
87
|
-
const blobs = [
|
|
88
|
-
await Blob.fromFields([])
|
|
89
|
-
];
|
|
90
|
-
// We need to precompute the final challenge values to evaluate the blobs.
|
|
91
|
-
const z = blobs[0].challengeZ;
|
|
92
|
-
// Now we have a shared challenge for all blobs, evaluate them...
|
|
93
|
-
const proofObjects = blobs.map((b)=>computeKzgProof(b.data, z.toBuffer()));
|
|
94
|
-
const evaluations = proofObjects.map(([_, evaluation])=>BLS12Fr.fromBuffer(Buffer.from(evaluation)));
|
|
95
|
-
// ...and find the challenge for the linear combination of blobs.
|
|
96
|
-
let gamma = await hashNoirBigNumLimbs(evaluations[0]);
|
|
97
|
-
gamma = await poseidon2Hash([
|
|
98
|
-
gamma,
|
|
99
|
-
z
|
|
100
|
-
]);
|
|
101
|
-
return new FinalBlobBatchingChallenges(z, BLS12Fr.fromBN254Fr(gamma));
|
|
102
|
-
}
|
|
103
86
|
// Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
|
|
104
87
|
getEthVersionedBlobHash() {
|
|
105
88
|
const hash = sha256(this.commitment.compress());
|
|
@@ -54,18 +54,4 @@ export declare class FinalBlobAccumulatorPublicInputs {
|
|
|
54
54
|
static fromBatchedBlobAccumulator(accumulator: BatchedBlobAccumulator): FinalBlobAccumulatorPublicInputs;
|
|
55
55
|
[inspect.custom](): string;
|
|
56
56
|
}
|
|
57
|
-
/**
|
|
58
|
-
* startBlobAccumulator: Accumulated opening proofs for all blobs before this block range.
|
|
59
|
-
* endBlobAccumulator: Accumulated opening proofs for all blobs after adding this block range.
|
|
60
|
-
* finalBlobChallenges: Final values z and gamma, shared across the epoch.
|
|
61
|
-
*/
|
|
62
|
-
export declare class BlockBlobPublicInputs {
|
|
63
|
-
startBlobAccumulator: BlobAccumulatorPublicInputs;
|
|
64
|
-
endBlobAccumulator: BlobAccumulatorPublicInputs;
|
|
65
|
-
finalBlobChallenges: FinalBlobBatchingChallenges;
|
|
66
|
-
constructor(startBlobAccumulator: BlobAccumulatorPublicInputs, endBlobAccumulator: BlobAccumulatorPublicInputs, finalBlobChallenges: FinalBlobBatchingChallenges);
|
|
67
|
-
static empty(): BlockBlobPublicInputs;
|
|
68
|
-
static fromBuffer(buffer: Buffer | BufferReader): BlockBlobPublicInputs;
|
|
69
|
-
toBuffer(): Buffer<ArrayBufferLike>;
|
|
70
|
-
}
|
|
71
57
|
//# sourceMappingURL=blob_batching_public_inputs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob_batching_public_in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AE,OAAO;IAG7B,MAAM,CAAC,KAAK,IAAI,2BAA2B;IAI3C,MAAM,CAAC,KAAK,EAAE,2BAA2B;IAWzC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,2BAA2B;IAY7E,QAAQ;IAWR;;;;;;OAMG;IACG,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,mBAAmB,EAAE,2BAA2B;IAsBrF,QAAQ;IAaR,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,2BAA2B;IAgB1E;;;OAGG;IACH,MAAM,CAAC,0BAA0B,CAAC,WAAW,EAAE,sBAAsB;CAUtE;AAED;;GAEG;AACH,qBAAa,gCAAgC;IAElC,mBAAmB,EAAE,EAAE;IACvB,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,UAAU;gBAHb,mBAAmB,EAAE,EAAE,EACvB,CAAC,EAAE,EAAE,EACL,CAAC,EAAE,OAAO,EACV,CAAC,EAAE,UAAU;IAGtB,MAAM,CAAC,KAAK,IAAI,gCAAgC;IAIhD,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,gCAAgC;IAUlF,QAAQ;IAIR,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,WAAW;IAIxC,QAAQ;IAUR,QAAQ;IAQR,MAAM,CAAC,KAAK,EAAE,gCAAgC;IAU9C,MAAM,CAAC,MAAM;IAKb,MAAM,CAAC,0BAA0B,CAAC,WAAW,EAAE,sBAAsB;IASrE,CAAC,OAAO,CAAC,MAAM,CAAC;CAQjB"}
|
|
@@ -2,7 +2,7 @@ import { BLS12_FQ_LIMBS, BLS12_FR_LIMBS } from '@aztec/constants';
|
|
|
2
2
|
import { BLS12Fq, BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
4
|
import { inspect } from 'util';
|
|
5
|
-
import { BatchedBlobAccumulator
|
|
5
|
+
import { BatchedBlobAccumulator } from './blob_batching.js';
|
|
6
6
|
/**
|
|
7
7
|
* See nr BlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
8
8
|
*/ export class BlobAccumulatorPublicInputs {
|
|
@@ -142,27 +142,3 @@ import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batc
|
|
|
142
142
|
}`;
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
/**
|
|
146
|
-
* startBlobAccumulator: Accumulated opening proofs for all blobs before this block range.
|
|
147
|
-
* endBlobAccumulator: Accumulated opening proofs for all blobs after adding this block range.
|
|
148
|
-
* finalBlobChallenges: Final values z and gamma, shared across the epoch.
|
|
149
|
-
*/ export class BlockBlobPublicInputs {
|
|
150
|
-
startBlobAccumulator;
|
|
151
|
-
endBlobAccumulator;
|
|
152
|
-
finalBlobChallenges;
|
|
153
|
-
constructor(startBlobAccumulator, endBlobAccumulator, finalBlobChallenges){
|
|
154
|
-
this.startBlobAccumulator = startBlobAccumulator;
|
|
155
|
-
this.endBlobAccumulator = endBlobAccumulator;
|
|
156
|
-
this.finalBlobChallenges = finalBlobChallenges;
|
|
157
|
-
}
|
|
158
|
-
static empty() {
|
|
159
|
-
return new BlockBlobPublicInputs(BlobAccumulatorPublicInputs.empty(), BlobAccumulatorPublicInputs.empty(), FinalBlobBatchingChallenges.empty());
|
|
160
|
-
}
|
|
161
|
-
static fromBuffer(buffer) {
|
|
162
|
-
const reader = BufferReader.asReader(buffer);
|
|
163
|
-
return new BlockBlobPublicInputs(reader.readObject(BlobAccumulatorPublicInputs), reader.readObject(BlobAccumulatorPublicInputs), reader.readObject(FinalBlobBatchingChallenges));
|
|
164
|
-
}
|
|
165
|
-
toBuffer() {
|
|
166
|
-
return serializeToBuffer(this.startBlobAccumulator, this.endBlobAccumulator, this.finalBlobChallenges);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { Blob as BlobBuffer } from 'c-kzg';
|
|
3
|
+
/**
|
|
4
|
+
* Deserializes a blob buffer into an array of field elements.
|
|
5
|
+
*
|
|
6
|
+
* Blobs are converted into BN254 fields to perform a poseidon2 hash on them (fieldHash).
|
|
7
|
+
* This method is sparse, meaning it does not include trailing zeros at the end of the blob.
|
|
8
|
+
*
|
|
9
|
+
* However, we cannot simply trim the zero's from the end of the blob, as some logs may include zero's
|
|
10
|
+
* within them.
|
|
11
|
+
* If we end on a set of zeros, such as the log below:
|
|
12
|
+
* length 7: [ a, b, c, d, e, 0, 0]
|
|
13
|
+
*
|
|
14
|
+
* we will end up with the incorrect hash if we trim the zeros from the end.
|
|
15
|
+
*
|
|
16
|
+
* Each transactions logs contains a TX start prefix, which includes a string followed
|
|
17
|
+
* by the length ( in field elements ) of the transaction's log.
|
|
18
|
+
*
|
|
19
|
+
* This function finds the end of the last transaction's logs, and returns the array up to this point.
|
|
20
|
+
*
|
|
21
|
+
* We search for a series of Tx Prefixes progressing the cursor in the field reader until we hit
|
|
22
|
+
* a field that is not a Tx Prefix, this indicates that we have reached the end of the last transaction's logs.
|
|
23
|
+
*
|
|
24
|
+
* +------------------+------------------+------------------+------------------+
|
|
25
|
+
* | TX1 Start Prefix | TX1 Log Fields | TX2 Start Prefix | Padded zeros |
|
|
26
|
+
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
27
|
+
* +------------------+------------------+------------------+------------------+
|
|
28
|
+
* ^
|
|
29
|
+
* |
|
|
30
|
+
* Function reads until here --------------------------------
|
|
31
|
+
*
|
|
32
|
+
* @param blob - The blob buffer to deserialize.
|
|
33
|
+
* @returns An array of field elements.
|
|
34
|
+
*/
|
|
35
|
+
export declare function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[];
|
|
36
|
+
/**
|
|
37
|
+
* Extract the fields from a blob buffer, but do not take into account encoding
|
|
38
|
+
* that will include trailing zeros.
|
|
39
|
+
*
|
|
40
|
+
* +------------------+------------------+------------------+------------------+
|
|
41
|
+
* | | | | Padded zeros |
|
|
42
|
+
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
43
|
+
* +------------------+------------------+------------------+------------------+
|
|
44
|
+
* ^
|
|
45
|
+
* |
|
|
46
|
+
* Function reads until here ----------------------
|
|
47
|
+
*/
|
|
48
|
+
export declare function extractBlobFieldsFromBuffer(blob: BlobBuffer): Fr[];
|
|
49
|
+
//# sourceMappingURL=deserialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../src/deserialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAIhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,UAAU,GAAG,EAAE,EAAE,CA6BrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,UAAU,GAAG,EAAE,EAAE,CAYlE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { getLengthFromFirstField, isBlockEndMarker } from './encoding.js';
|
|
4
|
+
/**
|
|
5
|
+
* Deserializes a blob buffer into an array of field elements.
|
|
6
|
+
*
|
|
7
|
+
* Blobs are converted into BN254 fields to perform a poseidon2 hash on them (fieldHash).
|
|
8
|
+
* This method is sparse, meaning it does not include trailing zeros at the end of the blob.
|
|
9
|
+
*
|
|
10
|
+
* However, we cannot simply trim the zero's from the end of the blob, as some logs may include zero's
|
|
11
|
+
* within them.
|
|
12
|
+
* If we end on a set of zeros, such as the log below:
|
|
13
|
+
* length 7: [ a, b, c, d, e, 0, 0]
|
|
14
|
+
*
|
|
15
|
+
* we will end up with the incorrect hash if we trim the zeros from the end.
|
|
16
|
+
*
|
|
17
|
+
* Each transactions logs contains a TX start prefix, which includes a string followed
|
|
18
|
+
* by the length ( in field elements ) of the transaction's log.
|
|
19
|
+
*
|
|
20
|
+
* This function finds the end of the last transaction's logs, and returns the array up to this point.
|
|
21
|
+
*
|
|
22
|
+
* We search for a series of Tx Prefixes progressing the cursor in the field reader until we hit
|
|
23
|
+
* a field that is not a Tx Prefix, this indicates that we have reached the end of the last transaction's logs.
|
|
24
|
+
*
|
|
25
|
+
* +------------------+------------------+------------------+------------------+
|
|
26
|
+
* | TX1 Start Prefix | TX1 Log Fields | TX2 Start Prefix | Padded zeros |
|
|
27
|
+
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
28
|
+
* +------------------+------------------+------------------+------------------+
|
|
29
|
+
* ^
|
|
30
|
+
* |
|
|
31
|
+
* Function reads until here --------------------------------
|
|
32
|
+
*
|
|
33
|
+
* @param blob - The blob buffer to deserialize.
|
|
34
|
+
* @returns An array of field elements.
|
|
35
|
+
*/ export function deserializeEncodedBlobToFields(blob) {
|
|
36
|
+
// Convert blob buffer to array of field elements
|
|
37
|
+
const reader = BufferReader.asReader(blob);
|
|
38
|
+
const array = reader.readArray(blob.length >> 5, Fr); // >> 5 = / 32 (bytes per field)
|
|
39
|
+
const fieldReader = FieldReader.asReader(array);
|
|
40
|
+
// Read fields until we hit zeros at the end
|
|
41
|
+
while(!fieldReader.isFinished()){
|
|
42
|
+
const currentField = fieldReader.peekField();
|
|
43
|
+
// Stop when we hit a zero field
|
|
44
|
+
if (!currentField || currentField.isZero()) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
// This comes before `getLengthFromFirstField` because an empty block doesn't have fields for the tx effect.
|
|
48
|
+
if (isBlockEndMarker(currentField)) {
|
|
49
|
+
// Include the block end marker in the result
|
|
50
|
+
fieldReader.skip(1);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
// Skip the remaining fields in this transaction
|
|
54
|
+
const len = getLengthFromFirstField(currentField);
|
|
55
|
+
fieldReader.skip(len);
|
|
56
|
+
}
|
|
57
|
+
// Return array up to last non-zero field
|
|
58
|
+
return array.slice(0, fieldReader.cursor);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Extract the fields from a blob buffer, but do not take into account encoding
|
|
62
|
+
* that will include trailing zeros.
|
|
63
|
+
*
|
|
64
|
+
* +------------------+------------------+------------------+------------------+
|
|
65
|
+
* | | | | Padded zeros |
|
|
66
|
+
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
67
|
+
* +------------------+------------------+------------------+------------------+
|
|
68
|
+
* ^
|
|
69
|
+
* |
|
|
70
|
+
* Function reads until here ----------------------
|
|
71
|
+
*/ export function extractBlobFieldsFromBuffer(blob) {
|
|
72
|
+
const reader = BufferReader.asReader(blob);
|
|
73
|
+
const array = reader.readArray(blob.length >> 5, Fr);
|
|
74
|
+
// Find the index of the last non-zero field
|
|
75
|
+
let lastNonZeroIndex = array.length - 1;
|
|
76
|
+
while(lastNonZeroIndex >= 0 && array[lastNonZeroIndex].isZero()){
|
|
77
|
+
lastNonZeroIndex--;
|
|
78
|
+
}
|
|
79
|
+
// Return the trimmed array
|
|
80
|
+
return array.slice(0, lastNonZeroIndex + 1);
|
|
81
|
+
}
|
package/dest/encoding.d.ts
CHANGED
|
@@ -1,42 +1,7 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import type { Blob as BlobBuffer } from 'c-kzg';
|
|
3
|
-
export declare const TX_START_PREFIX = 8392562855083340404n;
|
|
4
2
|
export declare const TX_START_PREFIX_BYTES_LENGTH: number;
|
|
5
3
|
export declare const TX_EFFECT_PREFIX_BYTE_LENGTH: number;
|
|
6
4
|
export declare const REVERT_CODE_PREFIX = 1;
|
|
7
|
-
/**
|
|
8
|
-
* Deserializes a blob buffer into an array of field elements.
|
|
9
|
-
*
|
|
10
|
-
* Blobs are converted into BN254 fields to perform a poseidon2 hash on them (fieldHash).
|
|
11
|
-
* This method is sparse, meaning it does not include trailing zeros at the end of the blob.
|
|
12
|
-
*
|
|
13
|
-
* However, we cannot simply trim the zero's from the end of the blob, as some logs may include zero's
|
|
14
|
-
* within them.
|
|
15
|
-
* If we end on a set of zeros, such as the log below:
|
|
16
|
-
* length 7: [ a, b, c, d, e, 0, 0]
|
|
17
|
-
*
|
|
18
|
-
* we will end up with the incorrect hash if we trim the zeros from the end.
|
|
19
|
-
*
|
|
20
|
-
* Each transactions logs contains a TX start prefix, which includes a string followed
|
|
21
|
-
* by the length ( in field elements ) of the transaction's log.
|
|
22
|
-
*
|
|
23
|
-
* This function finds the end of the last transaction's logs, and returns the array up to this point.
|
|
24
|
-
*
|
|
25
|
-
* We search for a series of Tx Prefixes progressing the cursor in the field reader until we hit
|
|
26
|
-
* a field that is not a Tx Prefix, this indicates that we have reached the end of the last transaction's logs.
|
|
27
|
-
*
|
|
28
|
-
* +------------------+------------------+------------------+------------------+
|
|
29
|
-
* | TX1 Start Prefix | TX1 Log Fields | TX2 Start Prefix | Padded zeros |
|
|
30
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
31
|
-
* +------------------+------------------+------------------+------------------+
|
|
32
|
-
* ^
|
|
33
|
-
* |
|
|
34
|
-
* Function reads until here --------------------------------
|
|
35
|
-
*
|
|
36
|
-
* @param blob - The blob buffer to deserialize.
|
|
37
|
-
* @returns An array of field elements.
|
|
38
|
-
*/
|
|
39
|
-
export declare function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[];
|
|
40
5
|
/**
|
|
41
6
|
* Get the length of the transaction from the first field.
|
|
42
7
|
*
|
|
@@ -46,21 +11,7 @@ export declare function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[];
|
|
|
46
11
|
* @throws If the first field does not include the correct prefix - encoding invalid.
|
|
47
12
|
*/
|
|
48
13
|
export declare function getLengthFromFirstField(firstField: Fr): number;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export declare function isValidFirstField(field: Fr): boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Extract the fields from a blob buffer, but do not take into account encoding
|
|
55
|
-
* that will include trailing zeros.
|
|
56
|
-
*
|
|
57
|
-
* +------------------+------------------+------------------+------------------+
|
|
58
|
-
* | | | | Padded zeros |
|
|
59
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
60
|
-
* +------------------+------------------+------------------+------------------+
|
|
61
|
-
* ^
|
|
62
|
-
* |
|
|
63
|
-
* Function reads until here ----------------------
|
|
64
|
-
*/
|
|
65
|
-
export declare function extractBlobFieldsFromBuffer(blob: BlobBuffer): Fr[];
|
|
14
|
+
export declare function createBlockEndMarker(numTxs: number): Fr;
|
|
15
|
+
export declare function isBlockEndMarker(field: Fr): boolean;
|
|
16
|
+
export declare function getNumTxsFromBlockEndMarker(field: Fr): number;
|
|
66
17
|
//# sourceMappingURL=encoding.d.ts.map
|
package/dest/encoding.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,eAAO,MAAM,4BAA4B,QAA0C,CAAC;AAEpF,eAAO,MAAM,4BAA4B,QAAmC,CAAC;AAC7E,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,EAAE,GAAG,MAAM,CAO9D;AA4BD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,MAGlD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,EAAE,WAIzC;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,EAAE,UAEpD"}
|
package/dest/encoding.js
CHANGED
|
@@ -1,63 +1,10 @@
|
|
|
1
|
+
import { BLOCK_END_PREFIX, TX_START_PREFIX } from '@aztec/constants';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
-
// Note duplicated from stdlib !
|
|
4
|
-
// This will appear as 0x74785f7374617274 in logs
|
|
5
|
-
export const TX_START_PREFIX = 8392562855083340404n;
|
|
6
3
|
// These are helper constants to decode tx effects from blob encoded fields
|
|
7
4
|
export const TX_START_PREFIX_BYTES_LENGTH = TX_START_PREFIX.toString(16).length / 2;
|
|
8
5
|
// 7 bytes for: | 0 | txlen[0] | txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revertCode |
|
|
9
6
|
export const TX_EFFECT_PREFIX_BYTE_LENGTH = TX_START_PREFIX_BYTES_LENGTH + 7;
|
|
10
7
|
export const REVERT_CODE_PREFIX = 1;
|
|
11
|
-
/**
|
|
12
|
-
* Deserializes a blob buffer into an array of field elements.
|
|
13
|
-
*
|
|
14
|
-
* Blobs are converted into BN254 fields to perform a poseidon2 hash on them (fieldHash).
|
|
15
|
-
* This method is sparse, meaning it does not include trailing zeros at the end of the blob.
|
|
16
|
-
*
|
|
17
|
-
* However, we cannot simply trim the zero's from the end of the blob, as some logs may include zero's
|
|
18
|
-
* within them.
|
|
19
|
-
* If we end on a set of zeros, such as the log below:
|
|
20
|
-
* length 7: [ a, b, c, d, e, 0, 0]
|
|
21
|
-
*
|
|
22
|
-
* we will end up with the incorrect hash if we trim the zeros from the end.
|
|
23
|
-
*
|
|
24
|
-
* Each transactions logs contains a TX start prefix, which includes a string followed
|
|
25
|
-
* by the length ( in field elements ) of the transaction's log.
|
|
26
|
-
*
|
|
27
|
-
* This function finds the end of the last transaction's logs, and returns the array up to this point.
|
|
28
|
-
*
|
|
29
|
-
* We search for a series of Tx Prefixes progressing the cursor in the field reader until we hit
|
|
30
|
-
* a field that is not a Tx Prefix, this indicates that we have reached the end of the last transaction's logs.
|
|
31
|
-
*
|
|
32
|
-
* +------------------+------------------+------------------+------------------+
|
|
33
|
-
* | TX1 Start Prefix | TX1 Log Fields | TX2 Start Prefix | Padded zeros |
|
|
34
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
35
|
-
* +------------------+------------------+------------------+------------------+
|
|
36
|
-
* ^
|
|
37
|
-
* |
|
|
38
|
-
* Function reads until here --------------------------------
|
|
39
|
-
*
|
|
40
|
-
* @param blob - The blob buffer to deserialize.
|
|
41
|
-
* @returns An array of field elements.
|
|
42
|
-
*/ export function deserializeEncodedBlobToFields(blob) {
|
|
43
|
-
// Convert blob buffer to array of field elements
|
|
44
|
-
const reader = BufferReader.asReader(blob);
|
|
45
|
-
const array = reader.readArray(blob.length >> 5, Fr); // >> 5 = / 32 (bytes per field)
|
|
46
|
-
const fieldReader = FieldReader.asReader(array);
|
|
47
|
-
// Read fields until we hit zeros at the end
|
|
48
|
-
while(!fieldReader.isFinished()){
|
|
49
|
-
const currentField = fieldReader.peekField();
|
|
50
|
-
// Stop when we hit a zero field
|
|
51
|
-
if (!currentField || currentField.isZero()) {
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
// Skip the remaining fields in this transaction
|
|
55
|
-
const len = getLengthFromFirstField(currentField);
|
|
56
|
-
fieldReader.skip(len);
|
|
57
|
-
}
|
|
58
|
-
// Return array up to last non-zero field
|
|
59
|
-
return array.slice(0, fieldReader.cursor);
|
|
60
|
-
}
|
|
61
8
|
/**
|
|
62
9
|
* Get the length of the transaction from the first field.
|
|
63
10
|
*
|
|
@@ -75,7 +22,7 @@ export const REVERT_CODE_PREFIX = 1;
|
|
|
75
22
|
}
|
|
76
23
|
/**
|
|
77
24
|
* Determines whether a field is the first field of a tx effect
|
|
78
|
-
*/
|
|
25
|
+
*/ function isValidFirstField(field) {
|
|
79
26
|
const buf = field.toBuffer();
|
|
80
27
|
if (!buf.subarray(0, field.size - TX_EFFECT_PREFIX_BYTE_LENGTH).equals(Buffer.alloc(field.size - TX_EFFECT_PREFIX_BYTE_LENGTH))) {
|
|
81
28
|
return false;
|
|
@@ -89,25 +36,15 @@ export const REVERT_CODE_PREFIX = 1;
|
|
|
89
36
|
}
|
|
90
37
|
return true;
|
|
91
38
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*/ export function extractBlobFieldsFromBuffer(blob) {
|
|
104
|
-
const reader = BufferReader.asReader(blob);
|
|
105
|
-
const array = reader.readArray(blob.length >> 5, Fr);
|
|
106
|
-
// Find the index of the last non-zero field
|
|
107
|
-
let lastNonZeroIndex = array.length - 1;
|
|
108
|
-
while(lastNonZeroIndex >= 0 && array[lastNonZeroIndex].isZero()){
|
|
109
|
-
lastNonZeroIndex--;
|
|
110
|
-
}
|
|
111
|
-
// Return the trimmed array
|
|
112
|
-
return array.slice(0, lastNonZeroIndex + 1);
|
|
39
|
+
export function createBlockEndMarker(numTxs) {
|
|
40
|
+
// Should match the implementation in block_rollup_public_inputs_composer.nr > create_block_end_marker
|
|
41
|
+
return new Fr(BLOCK_END_PREFIX * 256n * 256n + BigInt(numTxs));
|
|
42
|
+
}
|
|
43
|
+
export function isBlockEndMarker(field) {
|
|
44
|
+
const value = field.toBigInt();
|
|
45
|
+
const numTxs = value & 0xffffn;
|
|
46
|
+
return value - numTxs === BLOCK_END_PREFIX * 256n * 256n;
|
|
47
|
+
}
|
|
48
|
+
export function getNumTxsFromBlockEndMarker(field) {
|
|
49
|
+
return Number(field.toBigInt() & 0xffffn);
|
|
113
50
|
}
|
package/dest/index.d.ts
CHANGED
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,kCAAkC,CAAC;AACjD,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,kCAAkC,CAAC;AACjD,cAAc,kBAAkB,CAAC"}
|
package/dest/index.js
CHANGED
package/dest/testing.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { Blob } from './blob.js';
|
|
3
3
|
import { BatchedBlobAccumulator } from './blob_batching.js';
|
|
4
|
-
import { BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
|
|
5
4
|
import { SpongeBlob } from './sponge_blob.js';
|
|
6
5
|
/**
|
|
7
6
|
* Makes arbitrary poseidon sponge for blob inputs.
|
|
@@ -17,13 +16,6 @@ export declare function makeSpongeBlob(seed?: number): SpongeBlob;
|
|
|
17
16
|
* @returns A blob accumulator instance.
|
|
18
17
|
*/
|
|
19
18
|
export declare function makeBatchedBlobAccumulator(seed?: number): BatchedBlobAccumulator;
|
|
20
|
-
/**
|
|
21
|
-
* Makes arbitrary block blob public inputs.
|
|
22
|
-
* Note: will not verify inside the circuit.
|
|
23
|
-
* @param seed - The seed to use for generating the blob inputs.
|
|
24
|
-
* @returns A block blob public inputs instance.
|
|
25
|
-
*/
|
|
26
|
-
export declare function makeBlockBlobPublicInputs(seed?: number): BlockBlobPublicInputs;
|
|
27
19
|
/**
|
|
28
20
|
* Make an encoded blob with the given length
|
|
29
21
|
*
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAA+B,MAAM,oBAAoB,CAAC;AAEzF,OAAO,EAAmB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,SAAI,GAAG,UAAU,CAWnD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,SAAI,GAAG,sBAAsB,CAW3E;AAmBD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/D;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjE"}
|
package/dest/testing.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { TX_START_PREFIX } from '@aztec/constants';
|
|
1
2
|
import { makeTuple } from '@aztec/foundation/array';
|
|
2
3
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
3
4
|
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
4
5
|
import { Blob } from './blob.js';
|
|
5
6
|
import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
6
|
-
import {
|
|
7
|
-
import { TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH } from './encoding.js';
|
|
7
|
+
import { TX_START_PREFIX_BYTES_LENGTH } from './encoding.js';
|
|
8
8
|
import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
9
9
|
/**
|
|
10
10
|
* Makes arbitrary poseidon sponge for blob inputs.
|
|
@@ -22,15 +22,6 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
|
22
22
|
*/ export function makeBatchedBlobAccumulator(seed = 1) {
|
|
23
23
|
return new BatchedBlobAccumulator(new Fr(seed), new Fr(seed + 1), new BLS12Fr(seed + 2), BLS12Point.random(), BLS12Point.random(), new Fr(seed + 3), new BLS12Fr(seed + 4), new FinalBlobBatchingChallenges(new Fr(seed + 5), new BLS12Fr(seed + 6)));
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Makes arbitrary block blob public inputs.
|
|
27
|
-
* Note: will not verify inside the circuit.
|
|
28
|
-
* @param seed - The seed to use for generating the blob inputs.
|
|
29
|
-
* @returns A block blob public inputs instance.
|
|
30
|
-
*/ export function makeBlockBlobPublicInputs(seed = 1) {
|
|
31
|
-
const startBlobAccumulator = makeBatchedBlobAccumulator(seed);
|
|
32
|
-
return new BlockBlobPublicInputs(BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(startBlobAccumulator), BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(makeBatchedBlobAccumulator(seed + 1)), startBlobAccumulator.finalBlobChallenges);
|
|
33
|
-
}
|
|
34
25
|
// TODO: copied form stdlib tx effect
|
|
35
26
|
function encodeFirstField(length) {
|
|
36
27
|
const lengthBuf = Buffer.alloc(2);
|
package/dest/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
package/dest/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sponge_blob.js'; // TODO: Separate functions that use c-kzg from classes and export those classes here.
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/blob-lib",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20250918",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
7
|
+
"./encoding": "./dest/encoding.js",
|
|
8
|
+
"./types": "./dest/types.js",
|
|
7
9
|
"./testing": "./dest/testing.js"
|
|
8
10
|
},
|
|
9
11
|
"typedocOptions": {
|
|
@@ -25,8 +27,8 @@
|
|
|
25
27
|
"../package.common.json"
|
|
26
28
|
],
|
|
27
29
|
"dependencies": {
|
|
28
|
-
"@aztec/constants": "3.0.0-nightly.
|
|
29
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
30
|
+
"@aztec/constants": "3.0.0-nightly.20250918",
|
|
31
|
+
"@aztec/foundation": "3.0.0-nightly.20250918",
|
|
30
32
|
"c-kzg": "4.0.0-alpha.1",
|
|
31
33
|
"tslib": "^2.4.0"
|
|
32
34
|
},
|
package/src/blob.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
|
6
6
|
import cKzg from 'c-kzg';
|
|
7
7
|
import type { Blob as BlobBuffer } from 'c-kzg';
|
|
8
8
|
|
|
9
|
-
import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './
|
|
9
|
+
import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './deserialize.js';
|
|
10
10
|
import { BlobDeserializationError } from './errors.js';
|
|
11
11
|
import type { BlobJson } from './interface.js';
|
|
12
12
|
|
package/src/blob_batching.ts
CHANGED
|
@@ -89,20 +89,6 @@ export class BatchedBlob {
|
|
|
89
89
|
return new FinalBlobBatchingChallenges(z, BLS12Fr.fromBN254Fr(gamma));
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
static async precomputeEmptyBatchedBlobChallenges(): Promise<FinalBlobBatchingChallenges> {
|
|
93
|
-
const blobs = [await Blob.fromFields([])];
|
|
94
|
-
// We need to precompute the final challenge values to evaluate the blobs.
|
|
95
|
-
const z = blobs[0].challengeZ;
|
|
96
|
-
// Now we have a shared challenge for all blobs, evaluate them...
|
|
97
|
-
const proofObjects = blobs.map(b => computeKzgProof(b.data, z.toBuffer()));
|
|
98
|
-
const evaluations = proofObjects.map(([_, evaluation]) => BLS12Fr.fromBuffer(Buffer.from(evaluation)));
|
|
99
|
-
// ...and find the challenge for the linear combination of blobs.
|
|
100
|
-
let gamma = await hashNoirBigNumLimbs(evaluations[0]);
|
|
101
|
-
gamma = await poseidon2Hash([gamma, z]);
|
|
102
|
-
|
|
103
|
-
return new FinalBlobBatchingChallenges(z, BLS12Fr.fromBN254Fr(gamma));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
92
|
// Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
|
|
107
93
|
getEthVersionedBlobHash(): Buffer {
|
|
108
94
|
const hash = sha256(this.commitment.compress());
|
|
@@ -216,37 +216,3 @@ export class FinalBlobAccumulatorPublicInputs {
|
|
|
216
216
|
}`;
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* startBlobAccumulator: Accumulated opening proofs for all blobs before this block range.
|
|
222
|
-
* endBlobAccumulator: Accumulated opening proofs for all blobs after adding this block range.
|
|
223
|
-
* finalBlobChallenges: Final values z and gamma, shared across the epoch.
|
|
224
|
-
*/
|
|
225
|
-
export class BlockBlobPublicInputs {
|
|
226
|
-
constructor(
|
|
227
|
-
public startBlobAccumulator: BlobAccumulatorPublicInputs,
|
|
228
|
-
public endBlobAccumulator: BlobAccumulatorPublicInputs,
|
|
229
|
-
public finalBlobChallenges: FinalBlobBatchingChallenges,
|
|
230
|
-
) {}
|
|
231
|
-
|
|
232
|
-
static empty(): BlockBlobPublicInputs {
|
|
233
|
-
return new BlockBlobPublicInputs(
|
|
234
|
-
BlobAccumulatorPublicInputs.empty(),
|
|
235
|
-
BlobAccumulatorPublicInputs.empty(),
|
|
236
|
-
FinalBlobBatchingChallenges.empty(),
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
static fromBuffer(buffer: Buffer | BufferReader): BlockBlobPublicInputs {
|
|
241
|
-
const reader = BufferReader.asReader(buffer);
|
|
242
|
-
return new BlockBlobPublicInputs(
|
|
243
|
-
reader.readObject(BlobAccumulatorPublicInputs),
|
|
244
|
-
reader.readObject(BlobAccumulatorPublicInputs),
|
|
245
|
-
reader.readObject(FinalBlobBatchingChallenges),
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
toBuffer() {
|
|
250
|
-
return serializeToBuffer(this.startBlobAccumulator, this.endBlobAccumulator, this.finalBlobChallenges);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
import { getLengthFromFirstField, isBlockEndMarker } from './encoding.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Deserializes a blob buffer into an array of field elements.
|
|
10
|
+
*
|
|
11
|
+
* Blobs are converted into BN254 fields to perform a poseidon2 hash on them (fieldHash).
|
|
12
|
+
* This method is sparse, meaning it does not include trailing zeros at the end of the blob.
|
|
13
|
+
*
|
|
14
|
+
* However, we cannot simply trim the zero's from the end of the blob, as some logs may include zero's
|
|
15
|
+
* within them.
|
|
16
|
+
* If we end on a set of zeros, such as the log below:
|
|
17
|
+
* length 7: [ a, b, c, d, e, 0, 0]
|
|
18
|
+
*
|
|
19
|
+
* we will end up with the incorrect hash if we trim the zeros from the end.
|
|
20
|
+
*
|
|
21
|
+
* Each transactions logs contains a TX start prefix, which includes a string followed
|
|
22
|
+
* by the length ( in field elements ) of the transaction's log.
|
|
23
|
+
*
|
|
24
|
+
* This function finds the end of the last transaction's logs, and returns the array up to this point.
|
|
25
|
+
*
|
|
26
|
+
* We search for a series of Tx Prefixes progressing the cursor in the field reader until we hit
|
|
27
|
+
* a field that is not a Tx Prefix, this indicates that we have reached the end of the last transaction's logs.
|
|
28
|
+
*
|
|
29
|
+
* +------------------+------------------+------------------+------------------+
|
|
30
|
+
* | TX1 Start Prefix | TX1 Log Fields | TX2 Start Prefix | Padded zeros |
|
|
31
|
+
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
32
|
+
* +------------------+------------------+------------------+------------------+
|
|
33
|
+
* ^
|
|
34
|
+
* |
|
|
35
|
+
* Function reads until here --------------------------------
|
|
36
|
+
*
|
|
37
|
+
* @param blob - The blob buffer to deserialize.
|
|
38
|
+
* @returns An array of field elements.
|
|
39
|
+
*/
|
|
40
|
+
export function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[] {
|
|
41
|
+
// Convert blob buffer to array of field elements
|
|
42
|
+
const reader = BufferReader.asReader(blob);
|
|
43
|
+
const array = reader.readArray(blob.length >> 5, Fr); // >> 5 = / 32 (bytes per field)
|
|
44
|
+
const fieldReader = FieldReader.asReader(array);
|
|
45
|
+
|
|
46
|
+
// Read fields until we hit zeros at the end
|
|
47
|
+
while (!fieldReader.isFinished()) {
|
|
48
|
+
const currentField = fieldReader.peekField();
|
|
49
|
+
|
|
50
|
+
// Stop when we hit a zero field
|
|
51
|
+
if (!currentField || currentField.isZero()) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// This comes before `getLengthFromFirstField` because an empty block doesn't have fields for the tx effect.
|
|
56
|
+
if (isBlockEndMarker(currentField)) {
|
|
57
|
+
// Include the block end marker in the result
|
|
58
|
+
fieldReader.skip(1);
|
|
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
|
+
* Extract the fields from a blob buffer, but do not take into account encoding
|
|
73
|
+
* that will include trailing zeros.
|
|
74
|
+
*
|
|
75
|
+
* +------------------+------------------+------------------+------------------+
|
|
76
|
+
* | | | | Padded zeros |
|
|
77
|
+
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
78
|
+
* +------------------+------------------+------------------+------------------+
|
|
79
|
+
* ^
|
|
80
|
+
* |
|
|
81
|
+
* Function reads until here ----------------------
|
|
82
|
+
*/
|
|
83
|
+
export function extractBlobFieldsFromBuffer(blob: BlobBuffer): Fr[] {
|
|
84
|
+
const reader = BufferReader.asReader(blob);
|
|
85
|
+
const array = reader.readArray(blob.length >> 5, Fr);
|
|
86
|
+
|
|
87
|
+
// Find the index of the last non-zero field
|
|
88
|
+
let lastNonZeroIndex = array.length - 1;
|
|
89
|
+
while (lastNonZeroIndex >= 0 && array[lastNonZeroIndex].isZero()) {
|
|
90
|
+
lastNonZeroIndex--;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Return the trimmed array
|
|
94
|
+
return array.slice(0, lastNonZeroIndex + 1);
|
|
95
|
+
}
|
package/src/encoding.ts
CHANGED
|
@@ -1,73 +1,12 @@
|
|
|
1
|
+
import { BLOCK_END_PREFIX, TX_START_PREFIX } from '@aztec/constants';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
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
4
|
// These are helper constants to decode tx effects from blob encoded fields
|
|
10
5
|
export const TX_START_PREFIX_BYTES_LENGTH = TX_START_PREFIX.toString(16).length / 2;
|
|
11
6
|
// 7 bytes for: | 0 | txlen[0] | txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revertCode |
|
|
12
7
|
export const TX_EFFECT_PREFIX_BYTE_LENGTH = TX_START_PREFIX_BYTES_LENGTH + 7;
|
|
13
8
|
export const REVERT_CODE_PREFIX = 1;
|
|
14
9
|
|
|
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
10
|
/**
|
|
72
11
|
* Get the length of the transaction from the first field.
|
|
73
12
|
*
|
|
@@ -88,7 +27,7 @@ export function getLengthFromFirstField(firstField: Fr): number {
|
|
|
88
27
|
/**
|
|
89
28
|
* Determines whether a field is the first field of a tx effect
|
|
90
29
|
*/
|
|
91
|
-
|
|
30
|
+
function isValidFirstField(field: Fr): boolean {
|
|
92
31
|
const buf = field.toBuffer();
|
|
93
32
|
if (
|
|
94
33
|
!buf
|
|
@@ -111,28 +50,17 @@ export function isValidFirstField(field: Fr): boolean {
|
|
|
111
50
|
return true;
|
|
112
51
|
}
|
|
113
52
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
*
|
|
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);
|
|
53
|
+
export function createBlockEndMarker(numTxs: number) {
|
|
54
|
+
// Should match the implementation in block_rollup_public_inputs_composer.nr > create_block_end_marker
|
|
55
|
+
return new Fr(BLOCK_END_PREFIX * 256n * 256n + BigInt(numTxs));
|
|
56
|
+
}
|
|
129
57
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
58
|
+
export function isBlockEndMarker(field: Fr) {
|
|
59
|
+
const value = field.toBigInt();
|
|
60
|
+
const numTxs = value & 0xffffn;
|
|
61
|
+
return value - numTxs === BLOCK_END_PREFIX * 256n * 256n;
|
|
62
|
+
}
|
|
135
63
|
|
|
136
|
-
|
|
137
|
-
return
|
|
64
|
+
export function getNumTxsFromBlockEndMarker(field: Fr) {
|
|
65
|
+
return Number(field.toBigInt() & 0xffffn);
|
|
138
66
|
}
|
package/src/index.ts
CHANGED
package/src/testing.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { TX_START_PREFIX } from '@aztec/constants';
|
|
1
2
|
import { makeTuple } from '@aztec/foundation/array';
|
|
2
3
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
3
4
|
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
4
5
|
|
|
5
6
|
import { Blob } from './blob.js';
|
|
6
7
|
import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
7
|
-
import {
|
|
8
|
-
import { TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH } from './encoding.js';
|
|
8
|
+
import { TX_START_PREFIX_BYTES_LENGTH } from './encoding.js';
|
|
9
9
|
import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -46,21 +46,6 @@ export function makeBatchedBlobAccumulator(seed = 1): BatchedBlobAccumulator {
|
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* Makes arbitrary block blob public inputs.
|
|
51
|
-
* Note: will not verify inside the circuit.
|
|
52
|
-
* @param seed - The seed to use for generating the blob inputs.
|
|
53
|
-
* @returns A block blob public inputs instance.
|
|
54
|
-
*/
|
|
55
|
-
export function makeBlockBlobPublicInputs(seed = 1): BlockBlobPublicInputs {
|
|
56
|
-
const startBlobAccumulator = makeBatchedBlobAccumulator(seed);
|
|
57
|
-
return new BlockBlobPublicInputs(
|
|
58
|
-
BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(startBlobAccumulator),
|
|
59
|
-
BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(makeBatchedBlobAccumulator(seed + 1)),
|
|
60
|
-
startBlobAccumulator.finalBlobChallenges,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
49
|
// TODO: copied form stdlib tx effect
|
|
65
50
|
function encodeFirstField(length: number): Fr {
|
|
66
51
|
const lengthBuf = Buffer.alloc(2);
|
package/src/types.ts
ADDED