@aztec/blob-lib 3.0.0-nightly.20251016 → 3.0.0-nightly.20251023

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.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { Fr } from '@aztec/foundation/fields';
2
2
  import { BufferReader } from '@aztec/foundation/serialize';
3
- import cKzg from 'c-kzg';
4
- import type { Blob as BlobBuffer } from 'c-kzg';
5
3
  import type { BlobJson } from './interface.js';
6
4
  export declare const VERSIONED_HASH_VERSION_KZG = 1;
7
5
  /**
@@ -9,7 +7,7 @@ export declare const VERSIONED_HASH_VERSION_KZG = 1;
9
7
  */
10
8
  export declare class Blob {
11
9
  /** The blob to be broadcast on L1 in bytes form. */
12
- readonly data: BlobBuffer;
10
+ readonly data: Uint8Array;
13
11
  /** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */
14
12
  readonly fieldsHash: Fr;
15
13
  /** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts). */
@@ -18,7 +16,7 @@ export declare class Blob {
18
16
  readonly commitment: Buffer;
19
17
  constructor(
20
18
  /** The blob to be broadcast on L1 in bytes form. */
21
- data: BlobBuffer,
19
+ data: Uint8Array,
22
20
  /** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */
23
21
  fieldsHash: Fr,
24
22
  /** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts). */
@@ -38,7 +36,7 @@ export declare class Blob {
38
36
  *
39
37
  * @throws If unable to deserialize the blob.
40
38
  */
41
- static fromEncodedBlobBuffer(blob: BlobBuffer, multiBlobFieldsHash?: Fr): Promise<Blob>;
39
+ static fromEncodedBlobBuffer(blob: Uint8Array, multiBlobFieldsHash?: Fr): Promise<Blob>;
42
40
  /**
43
41
  * Create a Blob from an array of fields.
44
42
  *
@@ -151,8 +149,9 @@ export declare class Blob {
151
149
  */
152
150
  static getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${string}`;
153
151
  static getViemKzgInstance(): {
154
- blobToKzgCommitment: typeof cKzg.blobToKzgCommitment;
155
- computeBlobKzgProof: typeof cKzg.computeBlobKzgProof;
152
+ blobToKzgCommitment: (blob: Uint8Array) => Uint8Array;
153
+ computeBlobKzgProof: (blob: Uint8Array, commitment: Uint8Array) => Uint8Array;
154
+ computeCellsAndKzgProofs: (b: Uint8Array) => [Uint8Array[], Uint8Array[]];
156
155
  };
157
156
  /**
158
157
  * @param fields - Fields to broadcast in the blob(s)
@@ -1 +1 @@
1
- {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAG9E,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAIhD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK/C,eAAO,MAAM,0BAA0B,IAAO,CAAC;AAE/C;;GAEG;AACH,qBAAa,IAAI;IAEb,oDAAoD;aACpC,IAAI,EAAE,UAAU;IAChC,6IAA6I;aAC7H,UAAU,EAAE,EAAE;IAC9B,0JAA0J;aAC1I,UAAU,EAAE,EAAE;IAC9B,kFAAkF;aAClE,UAAU,EAAE,MAAM;;IAPlC,oDAAoD;IACpC,IAAI,EAAE,UAAU;IAChC,6IAA6I;IAC7H,UAAU,EAAE,EAAE;IAC9B,0JAA0J;IAC1I,UAAU,EAAE,EAAE;IAC9B,kFAAkF;IAClE,UAAU,EAAE,MAAM;IAGpC;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE,mBAAmB,CA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B,IAAI,MAAM;IAMjC,MAAM,CAAC,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAM1D;;;;;;;;OAQG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE;;;;IAWxB;;;;;;OAMG;IACH,QAAQ,IAAI,MAAM;IAalB;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAKnD;;OAEG;IACH,OAAO;IAIP;;;;;OAKG;IACH,MAAM,CAAC,6BAA6B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,MAAM,EAAE;IAYlE,MAAM,CAAC,kBAAkB;;;sCAIS,UAAU,KAAG,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC;;IAO3E;;;;OAIG;WACU,gBAAgB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;CAU7D"}
package/dest/blob.js CHANGED
@@ -1,11 +1,10 @@
1
+ import { FIELDS_PER_BLOB } from '@aztec/constants';
1
2
  import { poseidon2Hash, sha256 } from '@aztec/foundation/crypto';
2
3
  import { Fr } from '@aztec/foundation/fields';
3
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
- // Importing directly from 'c-kzg' does not work:
5
- import cKzg from 'c-kzg';
6
5
  import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './deserialize.js';
7
6
  import { BlobDeserializationError } from './errors.js';
8
- const { BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, blobToKzgCommitment, computeKzgProof, verifyKzgProof } = cKzg;
7
+ import { BYTES_PER_BLOB, kzg } from './kzg_context.js';
9
8
  // The prefix to the EVM blobHash, defined here: https://eips.ethereum.org/EIPS/eip-4844#specification
10
9
  export const VERSIONED_HASH_VERSION_KZG = 0x01;
11
10
  /**
@@ -48,15 +47,15 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
48
47
  * @param multiBlobFieldsHash - The fields hash to use for the Blob.
49
48
  * @returns A Blob created from the array of fields.
50
49
  */ static async fromFields(fields, multiBlobFieldsHash) {
51
- if (fields.length > FIELD_ELEMENTS_PER_BLOB) {
52
- throw new Error(`Attempted to overfill blob with ${fields.length} elements. The maximum is ${FIELD_ELEMENTS_PER_BLOB}`);
50
+ if (fields.length > FIELDS_PER_BLOB) {
51
+ throw new Error(`Attempted to overfill blob with ${fields.length} elements. The maximum is ${FIELDS_PER_BLOB}`);
53
52
  }
54
53
  const data = Buffer.concat([
55
54
  serializeToBuffer(fields)
56
55
  ], BYTES_PER_BLOB);
57
56
  // This matches the output of SpongeBlob.squeeze() in the blob circuit
58
57
  const fieldsHash = multiBlobFieldsHash ? multiBlobFieldsHash : await poseidon2Hash(fields);
59
- const commitment = Buffer.from(blobToKzgCommitment(data));
58
+ const commitment = Buffer.from(kzg.blobToKzgCommitment(data));
60
59
  const challengeZ = await poseidon2Hash([
61
60
  fieldsHash,
62
61
  ...commitmentToFields(commitment)
@@ -170,8 +169,8 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
170
169
  * proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
171
170
  */ evaluate(challengeZ) {
172
171
  const z = challengeZ || this.challengeZ;
173
- const res = computeKzgProof(this.data, z.toBuffer());
174
- if (!verifyKzgProof(this.commitment, z.toBuffer(), res[1], res[0])) {
172
+ const res = kzg.computeKzgProof(this.data, z.toBuffer());
173
+ if (!kzg.verifyKzgProof(this.commitment, z.toBuffer(), res[1], res[0])) {
175
174
  throw new Error(`KZG proof did not verify.`);
176
175
  }
177
176
  const proof = Buffer.from(res[0]);
@@ -230,8 +229,15 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
230
229
  }
231
230
  static getViemKzgInstance() {
232
231
  return {
233
- blobToKzgCommitment: cKzg.blobToKzgCommitment,
234
- computeBlobKzgProof: cKzg.computeBlobKzgProof
232
+ blobToKzgCommitment: kzg.blobToKzgCommitment.bind(kzg),
233
+ computeBlobKzgProof: kzg.computeBlobKzgProof.bind(kzg),
234
+ computeCellsAndKzgProofs: (b)=>{
235
+ const result = kzg.computeCellsAndKzgProofs(b);
236
+ return [
237
+ result.cells,
238
+ result.proofs
239
+ ];
240
+ }
235
241
  };
236
242
  }
237
243
  /**
@@ -239,12 +245,12 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
239
245
  * @returns As many blobs as we require to broadcast the given fields for a block
240
246
  * @dev Assumes we share the fields hash between all blobs which can only be done for ONE BLOCK because the hash is calculated in block root.
241
247
  */ static async getBlobsPerBlock(fields) {
242
- const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
248
+ const numBlobs = Math.max(Math.ceil(fields.length / FIELDS_PER_BLOB), 1);
243
249
  const multiBlobFieldsHash = await poseidon2Hash(fields);
244
250
  const res = [];
245
251
  for(let i = 0; i < numBlobs; i++){
246
- const end = fields.length < (i + 1) * FIELD_ELEMENTS_PER_BLOB ? fields.length : (i + 1) * FIELD_ELEMENTS_PER_BLOB;
247
- res.push(await Blob.fromFields(fields.slice(i * FIELD_ELEMENTS_PER_BLOB, end), multiBlobFieldsHash));
252
+ const end = fields.length < (i + 1) * FIELDS_PER_BLOB ? fields.length : (i + 1) * FIELDS_PER_BLOB;
253
+ res.push(await Blob.fromFields(fields.slice(i * FIELDS_PER_BLOB, end), multiBlobFieldsHash));
248
254
  }
249
255
  return res;
250
256
  }
@@ -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;IAEp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crypto';
3
3
  import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
4
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
- // Importing directly from 'c-kzg' does not work:
6
- import cKzg from 'c-kzg';
7
5
  import { VERSIONED_HASH_VERSION_KZG } from './blob.js';
8
- const { computeKzgProof, verifyKzgProof } = cKzg;
6
+ import { kzg } from './kzg_context.js';
9
7
  /**
10
8
  * A class to create, manage, and prove batched EVM blobs.
11
9
  */ export class BatchedBlob {
@@ -66,7 +64,7 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
66
64
  ]);
67
65
  }
68
66
  // Now we have a shared challenge for all blobs, evaluate them...
69
- const proofObjects = blobs.map((b)=>computeKzgProof(b.data, z.toBuffer()));
67
+ const proofObjects = blobs.map((b)=>kzg.computeKzgProof(b.data, z.toBuffer()));
70
68
  const evaluations = proofObjects.map(([_, evaluation])=>BLS12Fr.fromBuffer(Buffer.from(evaluation)));
71
69
  // ...and find the challenge for the linear combination of blobs.
72
70
  let gamma = await hashNoirBigNumLimbs(evaluations[0]);
@@ -189,7 +187,7 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
189
187
  *
190
188
  * @returns An initial blob accumulator.
191
189
  */ static async initialize(blob, finalBlobChallenges) {
192
- const [q, evaluation] = computeKzgProof(blob.data, finalBlobChallenges.z.toBuffer());
190
+ const [q, evaluation] = kzg.computeKzgProof(blob.data, finalBlobChallenges.z.toBuffer());
193
191
  const firstY = BLS12Fr.fromBuffer(Buffer.from(evaluation));
194
192
  // Here, i = 0, so:
195
193
  return new BatchedBlobAccumulator(sha256ToField([
@@ -210,7 +208,7 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
210
208
  if (this.isEmptyState()) {
211
209
  return BatchedBlobAccumulator.initialize(blob, this.finalBlobChallenges);
212
210
  } else {
213
- const [q, evaluation] = computeKzgProof(blob.data, this.finalBlobChallenges.z.toBuffer());
211
+ const [q, evaluation] = kzg.computeKzgProof(blob.data, this.finalBlobChallenges.z.toBuffer());
214
212
  const thisY = BLS12Fr.fromBuffer(Buffer.from(evaluation));
215
213
  // Moving from i - 1 to i, so:
216
214
  return new BatchedBlobAccumulator(sha256ToField([
@@ -262,7 +260,7 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
262
260
  if (!calculatedGamma.equals(this.finalBlobChallenges.gamma.toBN254Fr())) {
263
261
  throw new Error(`Blob batching mismatch: accumulated gamma ${calculatedGamma} does not equal injected gamma ${this.finalBlobChallenges.gamma.toBN254Fr()}`);
264
262
  }
265
- if (!verifyKzgProof(this.cAcc.compress(), this.zAcc.toBuffer(), this.yAcc.toBuffer(), this.qAcc.compress())) {
263
+ if (!kzg.verifyKzgProof(this.cAcc.compress(), this.zAcc.toBuffer(), this.yAcc.toBuffer(), this.qAcc.compress())) {
266
264
  throw new Error(`KZG proof did not verify.`);
267
265
  }
268
266
  return new BatchedBlob(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.qAcc);
@@ -1,5 +1,4 @@
1
1
  import { Fr } from '@aztec/foundation/fields';
2
- import type { Blob as BlobBuffer } from 'c-kzg';
3
2
  /**
4
3
  * Deserializes a blob buffer into an array of field elements.
5
4
  *
@@ -32,7 +31,7 @@ import type { Blob as BlobBuffer } from 'c-kzg';
32
31
  * @param blob - The blob buffer to deserialize.
33
32
  * @returns An array of field elements.
34
33
  */
35
- export declare function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[];
34
+ export declare function deserializeEncodedBlobToFields(blob: Uint8Array): Fr[];
36
35
  /**
37
36
  * Extract the fields from a blob buffer, but do not take into account encoding
38
37
  * that will include trailing zeros.
@@ -45,5 +44,5 @@ export declare function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[];
45
44
  * |
46
45
  * Function reads until here ----------------------
47
46
  */
48
- export declare function extractBlobFieldsFromBuffer(blob: BlobBuffer): Fr[];
47
+ export declare function extractBlobFieldsFromBuffer(blob: Uint8Array): Fr[];
49
48
  //# sourceMappingURL=deserialize.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../src/deserialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAK9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -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,kBAAkB,CAAC;AACjC,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":"AAAA,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
@@ -1,5 +1,3 @@
1
- import cKzg from 'c-kzg';
2
- const { loadTrustedSetup } = cKzg;
3
1
  export * from './blob.js';
4
2
  export * from './blob_batching.js';
5
3
  export * from './deserialize.js';
@@ -8,14 +6,3 @@ export * from './interface.js';
8
6
  export * from './errors.js';
9
7
  export * from './blob_batching_public_inputs.js';
10
8
  export * from './sponge_blob.js';
11
- try {
12
- loadTrustedSetup();
13
- } catch (error) {
14
- if (error.message.includes('trusted setup is already loaded')) {
15
- // NB: The c-kzg lib has no way of checking whether the setup is loaded or not,
16
- // and it throws an error if it's already loaded, even though nothing is wrong.
17
- // This is a rudimentary way of ensuring we load the trusted setup if we need it.
18
- } else {
19
- throw new Error(error);
20
- }
21
- }
@@ -0,0 +1,4 @@
1
+ import { DasContextJs } from '@crate-crypto/node-eth-kzg';
2
+ export * from '@crate-crypto/node-eth-kzg';
3
+ export declare const kzg: DasContextJs;
4
+ //# sourceMappingURL=kzg_context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kzg_context.d.ts","sourceRoot":"","sources":["../src/kzg_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,cAAc,4BAA4B,CAAC;AAE3C,eAAO,MAAM,GAAG,cAA4C,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { DasContextJs } from '@crate-crypto/node-eth-kzg';
2
+ export * from '@crate-crypto/node-eth-kzg';
3
+ export const kzg = DasContextJs.create({
4
+ usePrecomp: true
5
+ });
package/dest/types.d.ts CHANGED
@@ -8,5 +8,7 @@ export interface BlobKzgInstance {
8
8
  blobToKzgCommitment(blob: Uint8Array): Uint8Array;
9
9
  /** Function to compute KZG proof for blob data */
10
10
  computeBlobKzgProof(blob: Uint8Array, commitment: Uint8Array): Uint8Array;
11
+ /** Function to compute both blob data cells and their corresponding KZG proofs for EIP7594 */
12
+ computeCellsAndKzgProofs(blob: Uint8Array): [Uint8Array[], Uint8Array[]];
11
13
  }
12
14
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAIjC;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAClD,kDAAkD;IAClD,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CAC3E"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAIjC;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAClD,kDAAkD;IAClD,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;IAC1E,8FAA8F;IAC9F,wBAAwB,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;CAC1E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/blob-lib",
3
- "version": "3.0.0-nightly.20251016",
3
+ "version": "3.0.0-nightly.20251023",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -27,9 +27,9 @@
27
27
  "../package.common.json"
28
28
  ],
29
29
  "dependencies": {
30
- "@aztec/constants": "3.0.0-nightly.20251016",
31
- "@aztec/foundation": "3.0.0-nightly.20251016",
32
- "c-kzg": "4.0.0-alpha.1",
30
+ "@aztec/constants": "3.0.0-nightly.20251023",
31
+ "@aztec/foundation": "3.0.0-nightly.20251023",
32
+ "@crate-crypto/node-eth-kzg": "^0.9.1",
33
33
  "tslib": "^2.4.0"
34
34
  },
35
35
  "devDependencies": {
package/src/blob.ts CHANGED
@@ -1,16 +1,12 @@
1
+ import { FIELDS_PER_BLOB } from '@aztec/constants';
1
2
  import { poseidon2Hash, sha256 } from '@aztec/foundation/crypto';
2
3
  import { Fr } from '@aztec/foundation/fields';
3
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
5
 
5
- // Importing directly from 'c-kzg' does not work:
6
- import cKzg from 'c-kzg';
7
- import type { Blob as BlobBuffer } from 'c-kzg';
8
-
9
6
  import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './deserialize.js';
10
7
  import { BlobDeserializationError } from './errors.js';
11
8
  import type { BlobJson } from './interface.js';
12
-
13
- const { BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, blobToKzgCommitment, computeKzgProof, verifyKzgProof } = cKzg;
9
+ import { BYTES_PER_BLOB, kzg } from './kzg_context.js';
14
10
 
15
11
  // The prefix to the EVM blobHash, defined here: https://eips.ethereum.org/EIPS/eip-4844#specification
16
12
  export const VERSIONED_HASH_VERSION_KZG = 0x01;
@@ -21,7 +17,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
21
17
  export class Blob {
22
18
  constructor(
23
19
  /** The blob to be broadcast on L1 in bytes form. */
24
- public readonly data: BlobBuffer,
20
+ public readonly data: Uint8Array,
25
21
  /** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */
26
22
  public readonly fieldsHash: Fr,
27
23
  /** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts). */
@@ -43,7 +39,7 @@ export class Blob {
43
39
  *
44
40
  * @throws If unable to deserialize the blob.
45
41
  */
46
- static fromEncodedBlobBuffer(blob: BlobBuffer, multiBlobFieldsHash?: Fr): Promise<Blob> {
42
+ static fromEncodedBlobBuffer(blob: Uint8Array, multiBlobFieldsHash?: Fr): Promise<Blob> {
47
43
  try {
48
44
  const fields: Fr[] = deserializeEncodedBlobToFields(blob);
49
45
  return Blob.fromFields(fields, multiBlobFieldsHash);
@@ -62,17 +58,15 @@ export class Blob {
62
58
  * @returns A Blob created from the array of fields.
63
59
  */
64
60
  static async fromFields(fields: Fr[], multiBlobFieldsHash?: Fr): Promise<Blob> {
65
- if (fields.length > FIELD_ELEMENTS_PER_BLOB) {
66
- throw new Error(
67
- `Attempted to overfill blob with ${fields.length} elements. The maximum is ${FIELD_ELEMENTS_PER_BLOB}`,
68
- );
61
+ if (fields.length > FIELDS_PER_BLOB) {
62
+ throw new Error(`Attempted to overfill blob with ${fields.length} elements. The maximum is ${FIELDS_PER_BLOB}`);
69
63
  }
70
64
 
71
65
  const data = Buffer.concat([serializeToBuffer(fields)], BYTES_PER_BLOB);
72
66
 
73
67
  // This matches the output of SpongeBlob.squeeze() in the blob circuit
74
68
  const fieldsHash = multiBlobFieldsHash ? multiBlobFieldsHash : await poseidon2Hash(fields);
75
- const commitment = Buffer.from(blobToKzgCommitment(data));
69
+ const commitment = Buffer.from(kzg.blobToKzgCommitment(data));
76
70
  const challengeZ = await poseidon2Hash([fieldsHash, ...commitmentToFields(commitment)]);
77
71
 
78
72
  return new Blob(data, fieldsHash, challengeZ, commitment);
@@ -208,8 +202,8 @@ export class Blob {
208
202
  */
209
203
  evaluate(challengeZ?: Fr) {
210
204
  const z = challengeZ || this.challengeZ;
211
- const res = computeKzgProof(this.data, z.toBuffer());
212
- if (!verifyKzgProof(this.commitment, z.toBuffer(), res[1], res[0])) {
205
+ const res = kzg.computeKzgProof(this.data, z.toBuffer());
206
+ if (!kzg.verifyKzgProof(this.commitment, z.toBuffer(), res[1], res[0])) {
213
207
  throw new Error(`KZG proof did not verify.`);
214
208
  }
215
209
  const proof = Buffer.from(res[0]);
@@ -277,8 +271,12 @@ export class Blob {
277
271
 
278
272
  static getViemKzgInstance() {
279
273
  return {
280
- blobToKzgCommitment: cKzg.blobToKzgCommitment,
281
- computeBlobKzgProof: cKzg.computeBlobKzgProof,
274
+ blobToKzgCommitment: kzg.blobToKzgCommitment.bind(kzg),
275
+ computeBlobKzgProof: kzg.computeBlobKzgProof.bind(kzg),
276
+ computeCellsAndKzgProofs: (b: Uint8Array): [Uint8Array[], Uint8Array[]] => {
277
+ const result = kzg.computeCellsAndKzgProofs(b);
278
+ return [result.cells, result.proofs];
279
+ },
282
280
  };
283
281
  }
284
282
 
@@ -288,12 +286,12 @@ export class Blob {
288
286
  * @dev Assumes we share the fields hash between all blobs which can only be done for ONE BLOCK because the hash is calculated in block root.
289
287
  */
290
288
  static async getBlobsPerBlock(fields: Fr[]): Promise<Blob[]> {
291
- const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
289
+ const numBlobs = Math.max(Math.ceil(fields.length / FIELDS_PER_BLOB), 1);
292
290
  const multiBlobFieldsHash = await poseidon2Hash(fields);
293
291
  const res = [];
294
292
  for (let i = 0; i < numBlobs; i++) {
295
- const end = fields.length < (i + 1) * FIELD_ELEMENTS_PER_BLOB ? fields.length : (i + 1) * FIELD_ELEMENTS_PER_BLOB;
296
- res.push(await Blob.fromFields(fields.slice(i * FIELD_ELEMENTS_PER_BLOB, end), multiBlobFieldsHash));
293
+ const end = fields.length < (i + 1) * FIELDS_PER_BLOB ? fields.length : (i + 1) * FIELDS_PER_BLOB;
294
+ res.push(await Blob.fromFields(fields.slice(i * FIELDS_PER_BLOB, end), multiBlobFieldsHash));
297
295
  }
298
296
  return res;
299
297
  }
@@ -3,12 +3,8 @@ import { poseidon2Hash, sha256, sha256ToField } from '@aztec/foundation/crypto';
3
3
  import { BLS12Field, BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
4
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
5
 
6
- // Importing directly from 'c-kzg' does not work:
7
- import cKzg from 'c-kzg';
8
-
9
6
  import { Blob, VERSIONED_HASH_VERSION_KZG } from './blob.js';
10
-
11
- const { computeKzgProof, verifyKzgProof } = cKzg;
7
+ import { kzg } from './kzg_context.js';
12
8
 
13
9
  /**
14
10
  * A class to create, manage, and prove batched EVM blobs.
@@ -76,7 +72,7 @@ export class BatchedBlob {
76
72
  z = await poseidon2Hash([z, blobs[i].challengeZ]);
77
73
  }
78
74
  // Now we have a shared challenge for all blobs, evaluate them...
79
- const proofObjects = blobs.map(b => computeKzgProof(b.data, z.toBuffer()));
75
+ const proofObjects = blobs.map(b => kzg.computeKzgProof(b.data, z.toBuffer()));
80
76
  const evaluations = proofObjects.map(([_, evaluation]) => BLS12Fr.fromBuffer(Buffer.from(evaluation)));
81
77
  // ...and find the challenge for the linear combination of blobs.
82
78
  let gamma = await hashNoirBigNumLimbs(evaluations[0]);
@@ -209,7 +205,7 @@ export class BatchedBlobAccumulator {
209
205
  blob: Blob,
210
206
  finalBlobChallenges: FinalBlobBatchingChallenges,
211
207
  ): Promise<BatchedBlobAccumulator> {
212
- const [q, evaluation] = computeKzgProof(blob.data, finalBlobChallenges.z.toBuffer());
208
+ const [q, evaluation] = kzg.computeKzgProof(blob.data, finalBlobChallenges.z.toBuffer());
213
209
  const firstY = BLS12Fr.fromBuffer(Buffer.from(evaluation));
214
210
  // Here, i = 0, so:
215
211
  return new BatchedBlobAccumulator(
@@ -250,7 +246,7 @@ export class BatchedBlobAccumulator {
250
246
  if (this.isEmptyState()) {
251
247
  return BatchedBlobAccumulator.initialize(blob, this.finalBlobChallenges);
252
248
  } else {
253
- const [q, evaluation] = computeKzgProof(blob.data, this.finalBlobChallenges.z.toBuffer());
249
+ const [q, evaluation] = kzg.computeKzgProof(blob.data, this.finalBlobChallenges.z.toBuffer());
254
250
  const thisY = BLS12Fr.fromBuffer(Buffer.from(evaluation));
255
251
 
256
252
  // Moving from i - 1 to i, so:
@@ -308,7 +304,7 @@ export class BatchedBlobAccumulator {
308
304
  `Blob batching mismatch: accumulated gamma ${calculatedGamma} does not equal injected gamma ${this.finalBlobChallenges.gamma.toBN254Fr()}`,
309
305
  );
310
306
  }
311
- if (!verifyKzgProof(this.cAcc.compress(), this.zAcc.toBuffer(), this.yAcc.toBuffer(), this.qAcc.compress())) {
307
+ if (!kzg.verifyKzgProof(this.cAcc.compress(), this.zAcc.toBuffer(), this.yAcc.toBuffer(), this.qAcc.compress())) {
312
308
  throw new Error(`KZG proof did not verify.`);
313
309
  }
314
310
 
@@ -1,8 +1,6 @@
1
1
  import { Fr } from '@aztec/foundation/fields';
2
2
  import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
3
3
 
4
- import type { Blob as BlobBuffer } from 'c-kzg';
5
-
6
4
  import { getNumBlobFieldsFromTxStartMarker, isBlockEndMarker } from './encoding.js';
7
5
 
8
6
  /**
@@ -37,7 +35,7 @@ import { getNumBlobFieldsFromTxStartMarker, isBlockEndMarker } from './encoding.
37
35
  * @param blob - The blob buffer to deserialize.
38
36
  * @returns An array of field elements.
39
37
  */
40
- export function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[] {
38
+ export function deserializeEncodedBlobToFields(blob: Uint8Array): Fr[] {
41
39
  // Convert blob buffer to array of field elements
42
40
  const reader = BufferReader.asReader(blob);
43
41
  const array = reader.readArray(blob.length >> 5, Fr); // >> 5 = / 32 (bytes per field)
@@ -80,7 +78,7 @@ export function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[] {
80
78
  * |
81
79
  * Function reads until here ----------------------
82
80
  */
83
- export function extractBlobFieldsFromBuffer(blob: BlobBuffer): Fr[] {
81
+ export function extractBlobFieldsFromBuffer(blob: Uint8Array): Fr[] {
84
82
  const reader = BufferReader.asReader(blob);
85
83
  const array = reader.readArray(blob.length >> 5, Fr);
86
84
 
package/src/index.ts CHANGED
@@ -1,7 +1,3 @@
1
- import cKzg from 'c-kzg';
2
-
3
- const { loadTrustedSetup } = cKzg;
4
-
5
1
  export * from './blob.js';
6
2
  export * from './blob_batching.js';
7
3
  export * from './deserialize.js';
@@ -10,15 +6,3 @@ export * from './interface.js';
10
6
  export * from './errors.js';
11
7
  export * from './blob_batching_public_inputs.js';
12
8
  export * from './sponge_blob.js';
13
-
14
- try {
15
- loadTrustedSetup();
16
- } catch (error: any) {
17
- if (error.message.includes('trusted setup is already loaded')) {
18
- // NB: The c-kzg lib has no way of checking whether the setup is loaded or not,
19
- // and it throws an error if it's already loaded, even though nothing is wrong.
20
- // This is a rudimentary way of ensuring we load the trusted setup if we need it.
21
- } else {
22
- throw new Error(error);
23
- }
24
- }
@@ -0,0 +1,5 @@
1
+ import { DasContextJs } from '@crate-crypto/node-eth-kzg';
2
+
3
+ export * from '@crate-crypto/node-eth-kzg';
4
+
5
+ export const kzg = DasContextJs.create({ usePrecomp: true });
package/src/types.ts CHANGED
@@ -11,4 +11,6 @@ export interface BlobKzgInstance {
11
11
  blobToKzgCommitment(blob: Uint8Array): Uint8Array;
12
12
  /** Function to compute KZG proof for blob data */
13
13
  computeBlobKzgProof(blob: Uint8Array, commitment: Uint8Array): Uint8Array;
14
+ /** Function to compute both blob data cells and their corresponding KZG proofs for EIP7594 */
15
+ computeCellsAndKzgProofs(blob: Uint8Array): [Uint8Array[], Uint8Array[]];
14
16
  }