@aztec/blob-lib 1.0.0-nightly.20250608 → 1.0.0-nightly.20250611

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.
@@ -0,0 +1,170 @@
1
+ import { BLS12_FQ_LIMBS, BLS12_FR_LIMBS } from '@aztec/constants';
2
+ import { BLS12Fq, BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
3
+ import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
+ import { inspect } from 'util';
5
+ import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
6
+ /**
7
+ * See nr BlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
8
+ */ export class BlobAccumulatorPublicInputs {
9
+ blobCommitmentsHashAcc;
10
+ zAcc;
11
+ yAcc;
12
+ cAcc;
13
+ gammaAcc;
14
+ gammaPowAcc;
15
+ constructor(blobCommitmentsHashAcc, zAcc, yAcc, cAcc, gammaAcc, gammaPowAcc){
16
+ this.blobCommitmentsHashAcc = blobCommitmentsHashAcc;
17
+ this.zAcc = zAcc;
18
+ this.yAcc = yAcc;
19
+ this.cAcc = cAcc;
20
+ this.gammaAcc = gammaAcc;
21
+ this.gammaPowAcc = gammaPowAcc;
22
+ }
23
+ static empty() {
24
+ return new BlobAccumulatorPublicInputs(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO, Fr.ZERO, BLS12Fr.ZERO);
25
+ }
26
+ equals(other) {
27
+ return this.blobCommitmentsHashAcc.equals(other.blobCommitmentsHashAcc) && this.zAcc.equals(other.zAcc) && this.yAcc.equals(other.yAcc) && this.cAcc.equals(other.cAcc) && this.gammaAcc.equals(other.gammaAcc) && this.gammaPowAcc.equals(other.gammaPowAcc);
28
+ }
29
+ static fromBuffer(buffer) {
30
+ const reader = BufferReader.asReader(buffer);
31
+ return new BlobAccumulatorPublicInputs(Fr.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader), BLS12Point.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader));
32
+ }
33
+ toBuffer() {
34
+ return serializeToBuffer(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.gammaAcc, this.gammaPowAcc);
35
+ }
36
+ /**
37
+ * Given blobs, accumulate all public inputs state.
38
+ * We assume the input blobs have not been evaluated at z.
39
+ * NOTE: Does NOT accumulate non circuit values including Q. This exists to simulate/check exactly what the circuit is doing
40
+ * and is unsafe for other use. For that reason, a toBatchedBlobAccumulator does not exist. See evaluateBlobs() oracle for usage.
41
+ * @returns An updated blob accumulator.
42
+ */ async accumulateBlobs(blobs, finalBlobChallenges) {
43
+ let acc = new BatchedBlobAccumulator(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, BLS12Point.ZERO, this.gammaAcc, this.gammaPowAcc, finalBlobChallenges);
44
+ acc = await acc.accumulateBlobs(blobs);
45
+ return new BlobAccumulatorPublicInputs(acc.blobCommitmentsHashAcc, acc.zAcc, acc.yAcc, acc.cAcc, acc.gammaAcc, acc.gammaPow);
46
+ }
47
+ toFields() {
48
+ return [
49
+ this.blobCommitmentsHashAcc,
50
+ this.zAcc,
51
+ ...this.yAcc.toNoirBigNum().limbs.map(Fr.fromString),
52
+ ...this.cAcc.x.toNoirBigNum().limbs.map(Fr.fromString),
53
+ ...this.cAcc.y.toNoirBigNum().limbs.map(Fr.fromString),
54
+ new Fr(this.cAcc.isInfinite),
55
+ this.gammaAcc,
56
+ ...this.gammaPowAcc.toNoirBigNum().limbs.map(Fr.fromString)
57
+ ];
58
+ }
59
+ static fromFields(fields) {
60
+ const reader = FieldReader.asReader(fields);
61
+ return new BlobAccumulatorPublicInputs(reader.readField(), reader.readField(), BLS12Fr.fromNoirBigNum({
62
+ limbs: reader.readFieldArray(BLS12_FR_LIMBS).map((f)=>f.toString())
63
+ }), new BLS12Point(BLS12Fq.fromNoirBigNum({
64
+ limbs: reader.readFieldArray(BLS12_FQ_LIMBS).map((f)=>f.toString())
65
+ }), BLS12Fq.fromNoirBigNum({
66
+ limbs: reader.readFieldArray(BLS12_FQ_LIMBS).map((f)=>f.toString())
67
+ }), reader.readBoolean()), reader.readField(), BLS12Fr.fromNoirBigNum({
68
+ limbs: reader.readFieldArray(BLS12_FR_LIMBS).map((f)=>f.toString())
69
+ }));
70
+ }
71
+ }
72
+ /**
73
+ * See nr FinalBlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
74
+ */ export class FinalBlobAccumulatorPublicInputs {
75
+ blobCommitmentsHash;
76
+ z;
77
+ y;
78
+ c;
79
+ constructor(blobCommitmentsHash, z, y, c){
80
+ this.blobCommitmentsHash = blobCommitmentsHash;
81
+ this.z = z;
82
+ this.y = y;
83
+ this.c = c;
84
+ }
85
+ static empty() {
86
+ return new FinalBlobAccumulatorPublicInputs(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO);
87
+ }
88
+ static fromBuffer(buffer) {
89
+ const reader = BufferReader.asReader(buffer);
90
+ return new FinalBlobAccumulatorPublicInputs(Fr.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader), BLS12Point.fromBuffer(reader));
91
+ }
92
+ toBuffer() {
93
+ return serializeToBuffer(this.blobCommitmentsHash, this.z, this.y, this.c);
94
+ }
95
+ static fromBatchedBlob(blob) {
96
+ return new FinalBlobAccumulatorPublicInputs(blob.blobCommitmentsHash, blob.z, blob.y, blob.commitment);
97
+ }
98
+ toFields() {
99
+ return [
100
+ this.blobCommitmentsHash,
101
+ this.z,
102
+ ...this.y.toNoirBigNum().limbs.map(Fr.fromString),
103
+ // TODO(MW): add conversion when public inputs finalised
104
+ ...[
105
+ new Fr(this.c.compress().subarray(0, 31)),
106
+ new Fr(this.c.compress().subarray(31, 48))
107
+ ]
108
+ ];
109
+ }
110
+ // The below is used to send to L1 for proof verification
111
+ toString() {
112
+ // We prepend 32 bytes for the (unused) 'blobHash' slot. This is not read or required by getEpochProofPublicInputs() on L1, but
113
+ // is expected since we usually pass the full precompile inputs via verifyEpochRootProof() to getEpochProofPublicInputs() to ensure
114
+ // we use calldata rather than a slice in memory:
115
+ const buf = Buffer.concat([
116
+ Buffer.alloc(32),
117
+ this.z.toBuffer(),
118
+ this.y.toBuffer(),
119
+ this.c.compress()
120
+ ]);
121
+ return buf.toString('hex');
122
+ }
123
+ equals(other) {
124
+ return this.blobCommitmentsHash.equals(other.blobCommitmentsHash) && this.z.equals(other.z) && this.y.equals(other.y) && this.c.equals(other.c);
125
+ }
126
+ // Creates a random instance. Used for testing only - will not prove/verify.
127
+ static random() {
128
+ return new FinalBlobAccumulatorPublicInputs(Fr.random(), Fr.random(), BLS12Fr.random(), BLS12Point.random());
129
+ }
130
+ [inspect.custom]() {
131
+ return `FinalBlobAccumulatorPublicInputs {
132
+ blobCommitmentsHash: ${inspect(this.blobCommitmentsHash)},
133
+ z: ${inspect(this.z)},
134
+ y: ${inspect(this.y)},
135
+ c: ${inspect(this.c)},
136
+ }`;
137
+ }
138
+ }
139
+ /**
140
+ * startBlobAccumulator: Accumulated opening proofs for all blobs before this block range.
141
+ * endBlobAccumulator: Accumulated opening proofs for all blobs after adding this block range.
142
+ * finalBlobChallenges: Final values z and gamma, shared across the epoch.
143
+ */ export class BlockBlobPublicInputs {
144
+ startBlobAccumulator;
145
+ endBlobAccumulator;
146
+ finalBlobChallenges;
147
+ constructor(startBlobAccumulator, endBlobAccumulator, finalBlobChallenges){
148
+ this.startBlobAccumulator = startBlobAccumulator;
149
+ this.endBlobAccumulator = endBlobAccumulator;
150
+ this.finalBlobChallenges = finalBlobChallenges;
151
+ }
152
+ static empty() {
153
+ return new BlockBlobPublicInputs(BlobAccumulatorPublicInputs.empty(), BlobAccumulatorPublicInputs.empty(), FinalBlobBatchingChallenges.empty());
154
+ }
155
+ static fromBuffer(buffer) {
156
+ const reader = BufferReader.asReader(buffer);
157
+ return new BlockBlobPublicInputs(reader.readObject(BlobAccumulatorPublicInputs), reader.readObject(BlobAccumulatorPublicInputs), reader.readObject(FinalBlobBatchingChallenges));
158
+ }
159
+ toBuffer() {
160
+ return serializeToBuffer(this.startBlobAccumulator, this.endBlobAccumulator, this.finalBlobChallenges);
161
+ }
162
+ // Creates BlockBlobPublicInputs from the starting accumulator state and all blobs in the block.
163
+ // Assumes that startBlobAccumulator.finalChallenges have already been precomputed.
164
+ // Does not finalise challenge values (this is done in the final root rollup).
165
+ // TODO(MW): Integrate with BatchedBlob once old Blob classes removed
166
+ static async fromBlobs(startBlobAccumulator, blobs) {
167
+ const endBlobAccumulator = await startBlobAccumulator.accumulateBlobs(blobs);
168
+ return new BlockBlobPublicInputs(startBlobAccumulator.toBlobAccumulatorPublicInputs(), endBlobAccumulator.toBlobAccumulatorPublicInputs(), startBlobAccumulator.finalBlobChallenges);
169
+ }
170
+ }
package/dest/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export * from './blob.js';
2
+ export * from './blob_batching.js';
2
3
  export * from './encoding.js';
3
4
  export * from './interface.js';
4
5
  export * from './errors.js';
5
- export * from './blob_public_inputs.js';
6
+ export * from './blob_batching_public_inputs.js';
6
7
  export * from './sponge_blob.js';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,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,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,kCAAkC,CAAC;AACjD,cAAc,kBAAkB,CAAC"}
package/dest/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import cKzg from 'c-kzg';
2
2
  const { loadTrustedSetup } = cKzg;
3
3
  export * from './blob.js';
4
+ export * from './blob_batching.js';
4
5
  export * from './encoding.js';
5
6
  export * from './interface.js';
6
7
  export * from './errors.js';
7
- export * from './blob_public_inputs.js';
8
+ export * from './blob_batching_public_inputs.js';
8
9
  export * from './sponge_blob.js';
9
10
  try {
10
11
  loadTrustedSetup();
package/dest/testing.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Fr } from '@aztec/foundation/fields';
2
2
  import { Blob } from './blob.js';
3
- import { BlobPublicInputs, BlockBlobPublicInputs } from './blob_public_inputs.js';
3
+ import { BatchedBlobAccumulator } from './blob_batching.js';
4
+ import { BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
4
5
  import { SpongeBlob } from './sponge_blob.js';
5
6
  /**
6
7
  * Makes arbitrary poseidon sponge for blob inputs.
@@ -10,12 +11,12 @@ import { SpongeBlob } from './sponge_blob.js';
10
11
  */
11
12
  export declare function makeSpongeBlob(seed?: number): SpongeBlob;
12
13
  /**
13
- * Makes arbitrary blob public inputs.
14
+ * Makes arbitrary blob public accumulator.
14
15
  * Note: will not verify inside the circuit.
15
- * @param seed - The seed to use for generating the blob inputs.
16
- * @returns A blob public inputs instance.
16
+ * @param seed - The seed to use for generating the blob accumulator.
17
+ * @returns A blob accumulator instance.
17
18
  */
18
- export declare function makeBlobPublicInputs(seed?: number): BlobPublicInputs;
19
+ export declare function makeBatchedBlobAccumulator(seed?: number): BatchedBlobAccumulator;
19
20
  /**
20
21
  * Makes arbitrary block blob public inputs.
21
22
  * Note: will not verify inside the circuit.
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAE,IAAI,EA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AMG;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,9 +1,9 @@
1
- import { BLOBS_PER_BLOCK } from '@aztec/constants';
2
1
  import { makeTuple } from '@aztec/foundation/array';
3
2
  import { toBufferBE } from '@aztec/foundation/bigint-buffer';
4
- import { Fr } from '@aztec/foundation/fields';
3
+ import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
5
4
  import { Blob } from './blob.js';
6
- import { BlobPublicInputs, BlockBlobPublicInputs } from './blob_public_inputs.js';
5
+ import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
6
+ import { BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
7
7
  import { TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH } from './encoding.js';
8
8
  import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
9
9
  /**
@@ -15,12 +15,12 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
15
15
  return new SpongeBlob(new Poseidon2Sponge(makeTuple(3, (i)=>new Fr(i)), makeTuple(4, (i)=>new Fr(i)), 1, false), seed, seed + 1);
16
16
  }
17
17
  /**
18
- * Makes arbitrary blob public inputs.
18
+ * Makes arbitrary blob public accumulator.
19
19
  * Note: will not verify inside the circuit.
20
- * @param seed - The seed to use for generating the blob inputs.
21
- * @returns A blob public inputs instance.
22
- */ export function makeBlobPublicInputs(seed = 1) {
23
- return new BlobPublicInputs(new Fr(seed), BigInt(seed + 1), makeTuple(2, (i)=>new Fr(i)));
20
+ * @param seed - The seed to use for generating the blob accumulator.
21
+ * @returns A blob accumulator instance.
22
+ */ export function makeBatchedBlobAccumulator(seed = 1) {
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
25
  /**
26
26
  * Makes arbitrary block blob public inputs.
@@ -28,7 +28,8 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
28
28
  * @param seed - The seed to use for generating the blob inputs.
29
29
  * @returns A block blob public inputs instance.
30
30
  */ export function makeBlockBlobPublicInputs(seed = 1) {
31
- return new BlockBlobPublicInputs(makeTuple(BLOBS_PER_BLOCK, ()=>makeBlobPublicInputs(seed)));
31
+ const startBlobAccumulator = makeBatchedBlobAccumulator(seed);
32
+ return new BlockBlobPublicInputs(startBlobAccumulator.toBlobAccumulatorPublicInputs(), makeBatchedBlobAccumulator(seed + 1).toBlobAccumulatorPublicInputs(), startBlobAccumulator.finalBlobChallenges);
32
33
  }
33
34
  // TODO: copied form stdlib tx effect
34
35
  function encodeFirstField(length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/blob-lib",
3
- "version": "1.0.0-nightly.20250608",
3
+ "version": "1.0.0-nightly.20250611",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -25,8 +25,8 @@
25
25
  "../package.common.json"
26
26
  ],
27
27
  "dependencies": {
28
- "@aztec/constants": "1.0.0-nightly.20250608",
29
- "@aztec/foundation": "1.0.0-nightly.20250608",
28
+ "@aztec/constants": "1.0.0-nightly.20250611",
29
+ "@aztec/foundation": "1.0.0-nightly.20250611",
30
30
  "c-kzg": "4.0.0-alpha.1",
31
31
  "tslib": "^2.4.0"
32
32
  },
@@ -76,7 +76,8 @@
76
76
  "testTimeout": 120000,
77
77
  "setupFiles": [
78
78
  "../../foundation/src/jest/setup.mjs"
79
- ]
79
+ ],
80
+ "testEnvironment": "../../foundation/src/jest/env.mjs"
80
81
  },
81
82
  "engines": {
82
83
  "node": ">=20.10"
package/src/blob.ts CHANGED
@@ -2,7 +2,7 @@ import { poseidon2Hash, sha256 } from '@aztec/foundation/crypto';
2
2
  import { Fr } from '@aztec/foundation/fields';
3
3
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
4
 
5
- // Importing directly from 'c-kzg' does not work, ignoring import/no-named-as-default-member err:
5
+ // Importing directly from 'c-kzg' does not work:
6
6
  import cKzg from 'c-kzg';
7
7
  import type { Blob as BlobBuffer } from 'c-kzg';
8
8
 
@@ -301,6 +301,18 @@ export class Blob {
301
301
  return `0x${buf.toString('hex')}`;
302
302
  }
303
303
 
304
+ static getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${string}` {
305
+ let buf = Buffer.alloc(0);
306
+ blobs.forEach(blob => {
307
+ buf = Buffer.concat([buf, blob.commitment]);
308
+ });
309
+ // For multiple blobs, we prefix the number of blobs:
310
+ const lenBuf = Buffer.alloc(1);
311
+ lenBuf.writeUint8(blobs.length);
312
+ buf = Buffer.concat([lenBuf, buf]);
313
+ return `0x${buf.toString('hex')}`;
314
+ }
315
+
304
316
  static getViemKzgInstance() {
305
317
  return {
306
318
  blobToKzgCommitment: cKzg.blobToKzgCommitment,
@@ -310,6 +322,8 @@ export class Blob {
310
322
 
311
323
  // Returns as many blobs as we require to broadcast the given fields
312
324
  // Assumes we share the fields hash between all blobs
325
+ // TODO(MW): Rename to more accurate getBlobsPerBlock() - the items here share a fields hash,
326
+ // which can only be done for one block because the hash is calculated in block root.
313
327
  static async getBlobs(fields: Fr[]): Promise<Blob[]> {
314
328
  const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
315
329
  const multiBlobFieldsHash = await poseidon2Hash(fields);