@aztec/blob-lib 3.0.0-nightly.20251026 → 3.0.0-nightly.20251031

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.
Files changed (61) hide show
  1. package/dest/blob.d.ts +47 -89
  2. package/dest/blob.d.ts.map +1 -1
  3. package/dest/blob.js +62 -160
  4. package/dest/blob_batching.d.ts +14 -46
  5. package/dest/blob_batching.d.ts.map +1 -1
  6. package/dest/blob_batching.js +80 -100
  7. package/dest/blob_utils.d.ts +30 -0
  8. package/dest/blob_utils.d.ts.map +1 -0
  9. package/dest/blob_utils.js +60 -0
  10. package/dest/circuit_types/blob_accumulator.d.ts +21 -0
  11. package/dest/circuit_types/blob_accumulator.d.ts.map +1 -0
  12. package/dest/circuit_types/blob_accumulator.js +58 -0
  13. package/dest/circuit_types/final_blob_accumulator.d.ts +22 -0
  14. package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -0
  15. package/dest/circuit_types/final_blob_accumulator.js +63 -0
  16. package/dest/circuit_types/final_blob_batching_challenges.d.ts +15 -0
  17. package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -0
  18. package/dest/circuit_types/final_blob_batching_challenges.js +25 -0
  19. package/dest/circuit_types/index.d.ts +4 -0
  20. package/dest/circuit_types/index.d.ts.map +1 -0
  21. package/dest/circuit_types/index.js +4 -0
  22. package/dest/deserialize.d.ts +7 -41
  23. package/dest/deserialize.d.ts.map +1 -1
  24. package/dest/deserialize.js +25 -73
  25. package/dest/encoding.d.ts +5 -0
  26. package/dest/encoding.d.ts.map +1 -1
  27. package/dest/encoding.js +35 -0
  28. package/dest/hash.d.ts +35 -0
  29. package/dest/hash.d.ts.map +1 -0
  30. package/dest/hash.js +69 -0
  31. package/dest/index.d.ts +4 -2
  32. package/dest/index.d.ts.map +1 -1
  33. package/dest/index.js +4 -2
  34. package/dest/sponge_blob.d.ts +13 -9
  35. package/dest/sponge_blob.d.ts.map +1 -1
  36. package/dest/sponge_blob.js +28 -17
  37. package/dest/testing.d.ts +7 -2
  38. package/dest/testing.d.ts.map +1 -1
  39. package/dest/testing.js +47 -14
  40. package/dest/types.d.ts +2 -0
  41. package/dest/types.d.ts.map +1 -1
  42. package/dest/types.js +2 -0
  43. package/package.json +4 -4
  44. package/src/blob.ts +67 -180
  45. package/src/blob_batching.ts +109 -119
  46. package/src/blob_utils.ts +71 -0
  47. package/src/circuit_types/blob_accumulator.ts +84 -0
  48. package/src/circuit_types/final_blob_accumulator.ts +75 -0
  49. package/src/circuit_types/final_blob_batching_challenges.ts +29 -0
  50. package/src/circuit_types/index.ts +4 -0
  51. package/src/deserialize.ts +24 -79
  52. package/src/encoding.ts +45 -0
  53. package/src/hash.ts +77 -0
  54. package/src/index.ts +4 -2
  55. package/src/sponge_blob.ts +24 -14
  56. package/src/testing.ts +53 -16
  57. package/src/types.ts +2 -2
  58. package/dest/blob_batching_public_inputs.d.ts +0 -57
  59. package/dest/blob_batching_public_inputs.d.ts.map +0 -1
  60. package/dest/blob_batching_public_inputs.js +0 -144
  61. package/src/blob_batching_public_inputs.ts +0 -211
@@ -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;AAE9E,OAAO,EAAE,IAAI,EAA8B,MAAM,WAAW,CAAC;AAG7D;;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,g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AAE,UAAU;IAChC;;;;OAIG;IACa,QAAQ,EAAE,EAAE;IAC5B,uGAAuG;IACvF,QAAQ,EAAE,OAAO;IACjC,oGAAoG;IACpF,mBAAmB,EAAE,2BAA2B;IAGlE;;;OAGG;IACH,MAAM,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,2BAA2B,GAAG,sBAAsB;IAalG;;;;OAIG;YACW,UAAU;IAyCxB;;;;;OAKG;IACG,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE;IAkBnC;;;;;;;;;;;;;OAaG;IACG,QAAQ,CAAC,WAAW,UAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBzD,YAAY;IAYZ,KAAK;IAaL,iBAAiB;IAWjB,sBAAsB;CAGvB"}
@@ -1,8 +1,9 @@
1
1
  import { AZTEC_MAX_EPOCH_DURATION, BLOBS_PER_BLOCK } from '@aztec/constants';
2
- import { poseidon2Hash, sha256, sha256ToField } from '@aztec/foundation/crypto';
2
+ import { poseidon2Hash, sha256ToField } from '@aztec/foundation/crypto';
3
3
  import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
4
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
- import { VERSIONED_HASH_VERSION_KZG } from './blob.js';
4
+ import { computeBlobFieldsHashFromBlobs } from './blob_utils.js';
5
+ import { BlobAccumulator, FinalBlobAccumulator, FinalBlobBatchingChallenges } from './circuit_types/index.js';
6
+ import { computeEthVersionedBlobHash, hashNoirBigNumLimbs } from './hash.js';
6
7
  import { kzg } from './kzg_context.js';
7
8
  /**
8
9
  * A class to create, manage, and prove batched EVM blobs.
@@ -26,14 +27,15 @@ import { kzg } from './kzg_context.js';
26
27
  *
27
28
  * @returns A batched blob.
28
29
  */ static async batch(blobs) {
29
- const numBlobs = blobs.length;
30
- if (numBlobs > BLOBS_PER_BLOCK * AZTEC_MAX_EPOCH_DURATION) {
31
- throw new Error(`Too many blobs (${numBlobs}) sent to batch(). The maximum is ${BLOBS_PER_BLOCK * AZTEC_MAX_EPOCH_DURATION}.`);
30
+ if (blobs.length > AZTEC_MAX_EPOCH_DURATION) {
31
+ throw new Error(`Too many blocks sent to batch(). The maximum is ${AZTEC_MAX_EPOCH_DURATION}. Got ${blobs.length}.`);
32
32
  }
33
33
  // Precalculate the values (z and gamma) and initialize the accumulator:
34
34
  let acc = await this.newAccumulator(blobs);
35
35
  // Now we can create a multi opening proof of all input blobs:
36
- acc = await acc.accumulateBlobs(blobs);
36
+ for (const blockBlobs of blobs){
37
+ acc = await acc.accumulateBlobs(blockBlobs);
38
+ }
37
39
  return await acc.finalize();
38
40
  }
39
41
  /**
@@ -52,27 +54,42 @@ import { kzg } from './kzg_context.js';
52
54
  * - used such that p_i(z) = y_i = Blob.evaluationY for all n blob polynomials p_i().
53
55
  * - gamma = H(H(...H(H(y_0, y_1) y_2)..y_n), z)
54
56
  * - used such that y = sum_i { gamma^i * y_i }, and C = sum_i { gamma^i * C_i }, for all blob evaluations y_i (see above) and commitments C_i.
57
+ *
58
+ * @param blobs - The blobs to precompute the challenges for. Each sub-array is the blobs for an L1 block.
55
59
  * @returns Challenges z and gamma.
56
60
  */ static async precomputeBatchedBlobChallenges(blobs) {
57
- // We need to precompute the final challenge values to evaluate the blobs.
58
- let z = blobs[0].challengeZ;
59
- // We start at i = 1, because z is initialized as the first blob's challenge.
60
- for(let i = 1; i < blobs.length; i++){
61
- z = await poseidon2Hash([
62
- z,
63
- blobs[i].challengeZ
64
- ]);
61
+ // Compute the final challenge z to evaluate the blobs.
62
+ let z;
63
+ for (const blockBlobs of blobs){
64
+ // Compute the hash of all the fields in the block.
65
+ const blobFieldsHash = await computeBlobFieldsHashFromBlobs(blockBlobs);
66
+ for (const blob of blockBlobs){
67
+ // Compute the challenge z for each blob and accumulate it.
68
+ const challengeZ = await blob.computeChallengeZ(blobFieldsHash);
69
+ if (!z) {
70
+ z = challengeZ;
71
+ } else {
72
+ z = await poseidon2Hash([
73
+ z,
74
+ challengeZ
75
+ ]);
76
+ }
77
+ }
78
+ }
79
+ if (!z) {
80
+ throw new Error('No blobs to precompute challenges for.');
65
81
  }
66
82
  // Now we have a shared challenge for all blobs, evaluate them...
67
- const proofObjects = blobs.map((b)=>kzg.computeKzgProof(b.data, z.toBuffer()));
68
- const evaluations = proofObjects.map(([_, evaluation])=>BLS12Fr.fromBuffer(Buffer.from(evaluation)));
83
+ const allBlobs = blobs.flat();
84
+ const proofObjects = allBlobs.map((b)=>b.evaluate(z));
85
+ const evaluations = await Promise.all(proofObjects.map(({ y })=>hashNoirBigNumLimbs(y)));
69
86
  // ...and find the challenge for the linear combination of blobs.
70
- let gamma = await hashNoirBigNumLimbs(evaluations[0]);
87
+ let gamma = evaluations[0];
71
88
  // We start at i = 1, because gamma is initialized as the first blob's evaluation.
72
- for(let i = 1; i < blobs.length; i++){
89
+ for(let i = 1; i < allBlobs.length; i++){
73
90
  gamma = await poseidon2Hash([
74
91
  gamma,
75
- await hashNoirBigNumLimbs(evaluations[i])
92
+ evaluations[i]
76
93
  ]);
77
94
  }
78
95
  gamma = await poseidon2Hash([
@@ -81,16 +98,12 @@ import { kzg } from './kzg_context.js';
81
98
  ]);
82
99
  return new FinalBlobBatchingChallenges(z, BLS12Fr.fromBN254Fr(gamma));
83
100
  }
101
+ verify() {
102
+ return kzg.verifyKzgProof(this.commitment.compress(), this.z.toBuffer(), this.y.toBuffer(), this.q.compress());
103
+ }
84
104
  // Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
85
105
  getEthVersionedBlobHash() {
86
- const hash = sha256(this.commitment.compress());
87
- hash[0] = VERSIONED_HASH_VERSION_KZG;
88
- return hash;
89
- }
90
- static getEthVersionedBlobHash(commitment) {
91
- const hash = sha256(commitment);
92
- hash[0] = VERSIONED_HASH_VERSION_KZG;
93
- return hash;
106
+ return computeEthVersionedBlobHash(this.commitment.compress());
94
107
  }
95
108
  /**
96
109
  * Returns a proof of opening of the blobs to verify on L1 using the point evaluation precompile:
@@ -112,40 +125,8 @@ import { kzg } from './kzg_context.js';
112
125
  ]);
113
126
  return `0x${buf.toString('hex')}`;
114
127
  }
115
- }
116
- /**
117
- * Final values z and gamma are injected into each block root circuit. We ensure they are correct by:
118
- * - Checking equality in each block merge circuit and propagating up
119
- * - Checking final z_acc == z in root circuit
120
- * - Checking final gamma_acc == gamma in root circuit
121
- *
122
- * - z = H(...H(H(z_0, z_1) z_2)..z_n)
123
- * - where z_i = H(H(fields of blob_i), C_i),
124
- * - used such that p_i(z) = y_i = Blob.evaluationY for all n blob polynomials p_i().
125
- * - gamma = H(H(...H(H(y_0, y_1) y_2)..y_n), z)
126
- * - used such that y = sum_i { gamma^i * y_i }, and C = sum_i { gamma^i * C_i }
127
- * for all blob evaluations y_i (see above) and commitments C_i.
128
- *
129
- * Iteratively calculated by BlobAccumulator.accumulate() in nr. See also precomputeBatchedBlobChallenges() above.
130
- */ export class FinalBlobBatchingChallenges {
131
- z;
132
- gamma;
133
- constructor(z, gamma){
134
- this.z = z;
135
- this.gamma = gamma;
136
- }
137
- equals(other) {
138
- return this.z.equals(other.z) && this.gamma.equals(other.gamma);
139
- }
140
- static empty() {
141
- return new FinalBlobBatchingChallenges(Fr.ZERO, BLS12Fr.ZERO);
142
- }
143
- static fromBuffer(buffer) {
144
- const reader = BufferReader.asReader(buffer);
145
- return new FinalBlobBatchingChallenges(Fr.fromBuffer(reader), reader.readObject(BLS12Fr));
146
- }
147
- toBuffer() {
148
- return serializeToBuffer(this.z, this.gamma);
128
+ toFinalBlobAccumulator() {
129
+ return new FinalBlobAccumulator(this.blobCommitmentsHash, this.z, this.y, this.commitment);
149
130
  }
150
131
  }
151
132
  /**
@@ -174,27 +155,6 @@ import { kzg } from './kzg_context.js';
174
155
  this.finalBlobChallenges = finalBlobChallenges;
175
156
  }
176
157
  /**
177
- * Init the first accumulation state of the epoch.
178
- * We assume the input blob has not been evaluated at z.
179
- *
180
- * First state of the accumulator:
181
- * - v_acc := sha256(C_0)
182
- * - z_acc := z_0
183
- * - y_acc := gamma^0 * y_0 = y_0
184
- * - c_acc := gamma^0 * c_0 = c_0
185
- * - gamma_acc := poseidon2(y_0.limbs)
186
- * - gamma^(i + 1) = gamma^1 = gamma // denoted gamma_pow_acc
187
- *
188
- * @returns An initial blob accumulator.
189
- */ static async initialize(blob, finalBlobChallenges) {
190
- const [q, evaluation] = kzg.computeKzgProof(blob.data, finalBlobChallenges.z.toBuffer());
191
- const firstY = BLS12Fr.fromBuffer(Buffer.from(evaluation));
192
- // Here, i = 0, so:
193
- return new BatchedBlobAccumulator(sha256ToField([
194
- blob.commitment
195
- ]), blob.challengeZ, firstY, BLS12Point.decompress(blob.commitment), BLS12Point.decompress(Buffer.from(q)), await hashNoirBigNumLimbs(firstY), finalBlobChallenges.gamma, finalBlobChallenges);
196
- }
197
- /**
198
158
  * Create the empty accumulation state of the epoch.
199
159
  * @returns An empty blob accumulator with challenges.
200
160
  */ static newWithChallenges(finalBlobChallenges) {
@@ -204,20 +164,32 @@ import { kzg } from './kzg_context.js';
204
164
  * Given blob i, accumulate all state.
205
165
  * We assume the input blob has not been evaluated at z.
206
166
  * @returns An updated blob accumulator.
207
- */ async accumulate(blob) {
167
+ */ async accumulate(blob, blobFieldsHash) {
168
+ const { proof, y: thisY } = blob.evaluate(this.finalBlobChallenges.z);
169
+ const thisC = BLS12Point.decompress(blob.commitment);
170
+ const thisQ = BLS12Point.decompress(proof);
171
+ const blobChallengeZ = await blob.computeChallengeZ(blobFieldsHash);
208
172
  if (this.isEmptyState()) {
209
- return BatchedBlobAccumulator.initialize(blob, this.finalBlobChallenges);
173
+ /**
174
+ * Init the first accumulation state of the epoch.
175
+ * - v_acc := sha256(C_0)
176
+ * - z_acc := z_0
177
+ * - y_acc := gamma^0 * y_0 = y_0
178
+ * - c_acc := gamma^0 * c_0 = c_0
179
+ * - gamma_acc := poseidon2(y_0.limbs)
180
+ * - gamma^(i + 1) = gamma^1 = gamma // denoted gamma_pow_acc
181
+ */ return new BatchedBlobAccumulator(sha256ToField([
182
+ blob.commitment
183
+ ]), blobChallengeZ, thisY, thisC, thisQ, await hashNoirBigNumLimbs(thisY), this.finalBlobChallenges.gamma, this.finalBlobChallenges);
210
184
  } else {
211
- const [q, evaluation] = kzg.computeKzgProof(blob.data, this.finalBlobChallenges.z.toBuffer());
212
- const thisY = BLS12Fr.fromBuffer(Buffer.from(evaluation));
213
185
  // Moving from i - 1 to i, so:
214
186
  return new BatchedBlobAccumulator(sha256ToField([
215
187
  this.blobCommitmentsHashAcc,
216
188
  blob.commitment
217
189
  ]), await poseidon2Hash([
218
190
  this.zAcc,
219
- blob.challengeZ
220
- ]), this.yAcc.add(thisY.mul(this.gammaPow)), this.cAcc.add(BLS12Point.decompress(blob.commitment).mul(this.gammaPow)), this.qAcc.add(BLS12Point.decompress(Buffer.from(q)).mul(this.gammaPow)), await poseidon2Hash([
191
+ blobChallengeZ
192
+ ]), this.yAcc.add(thisY.mul(this.gammaPow)), this.cAcc.add(thisC.mul(this.gammaPow)), this.qAcc.add(thisQ.mul(this.gammaPow)), await poseidon2Hash([
221
193
  this.gammaAcc,
222
194
  await hashNoirBigNumLimbs(thisY)
223
195
  ]), this.gammaPow.mul(this.finalBlobChallenges.gamma), this.finalBlobChallenges);
@@ -226,12 +198,18 @@ import { kzg } from './kzg_context.js';
226
198
  /**
227
199
  * Given blobs, accumulate all state.
228
200
  * We assume the input blobs have not been evaluated at z.
201
+ * @param blobs - The blobs to accumulate. They should be in the same L1 block.
229
202
  * @returns An updated blob accumulator.
230
203
  */ async accumulateBlobs(blobs) {
204
+ if (blobs.length > BLOBS_PER_BLOCK) {
205
+ throw new Error(`Too many blobs to accumulate. The maximum is ${BLOBS_PER_BLOCK} per block. Got ${blobs.length}.`);
206
+ }
207
+ // Compute the hash of all the fields in the block.
208
+ const blobFieldsHash = await computeBlobFieldsHashFromBlobs(blobs);
231
209
  // Initialize the acc to iterate over:
232
210
  let acc = this.clone();
233
- for(let i = 0; i < blobs.length; i++){
234
- acc = await acc.accumulate(blobs[i]);
211
+ for (const blob of blobs){
212
+ acc = await acc.accumulate(blob, blobFieldsHash);
235
213
  }
236
214
  return acc;
237
215
  }
@@ -246,8 +224,9 @@ import { kzg } from './kzg_context.js';
246
224
  * - c := c_acc (final commitment to be checked on L1)
247
225
  * - gamma := poseidon2(gamma_acc, z) (challenge for linear combination of y and C, above)
248
226
  *
227
+ * @param verifyProof - Whether to verify the KZG proof.
249
228
  * @returns A batched blob.
250
- */ async finalize() {
229
+ */ async finalize(verifyProof = false) {
251
230
  // All values in acc are final, apart from gamma := poseidon2(gammaAcc, z):
252
231
  const calculatedGamma = await poseidon2Hash([
253
232
  this.gammaAcc,
@@ -260,10 +239,11 @@ import { kzg } from './kzg_context.js';
260
239
  if (!calculatedGamma.equals(this.finalBlobChallenges.gamma.toBN254Fr())) {
261
240
  throw new Error(`Blob batching mismatch: accumulated gamma ${calculatedGamma} does not equal injected gamma ${this.finalBlobChallenges.gamma.toBN254Fr()}`);
262
241
  }
263
- if (!kzg.verifyKzgProof(this.cAcc.compress(), this.zAcc.toBuffer(), this.yAcc.toBuffer(), this.qAcc.compress())) {
242
+ const batchedBlob = new BatchedBlob(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.qAcc);
243
+ if (verifyProof && !batchedBlob.verify()) {
264
244
  throw new Error(`KZG proof did not verify.`);
265
245
  }
266
- return new BatchedBlob(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.qAcc);
246
+ return batchedBlob;
267
247
  }
268
248
  isEmptyState() {
269
249
  return this.blobCommitmentsHashAcc.isZero() && this.zAcc.isZero() && this.yAcc.isZero() && this.cAcc.isZero() && this.qAcc.isZero() && this.gammaAcc.isZero() && this.gammaPow.isZero();
@@ -271,10 +251,10 @@ import { kzg } from './kzg_context.js';
271
251
  clone() {
272
252
  return new BatchedBlobAccumulator(Fr.fromBuffer(this.blobCommitmentsHashAcc.toBuffer()), Fr.fromBuffer(this.zAcc.toBuffer()), BLS12Fr.fromBuffer(this.yAcc.toBuffer()), BLS12Point.fromBuffer(this.cAcc.toBuffer()), BLS12Point.fromBuffer(this.qAcc.toBuffer()), Fr.fromBuffer(this.gammaAcc.toBuffer()), BLS12Fr.fromBuffer(this.gammaPow.toBuffer()), FinalBlobBatchingChallenges.fromBuffer(this.finalBlobChallenges.toBuffer()));
273
253
  }
274
- }
275
- // To mimic the hash accumulation in the rollup circuits, here we hash
276
- // each u128 limb of the noir bignum struct representing the BLS field.
277
- async function hashNoirBigNumLimbs(field) {
278
- const num = field.toNoirBigNum();
279
- return await poseidon2Hash(num.limbs.map(Fr.fromHexString));
254
+ toBlobAccumulator() {
255
+ return new BlobAccumulator(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.gammaAcc, this.gammaPow);
256
+ }
257
+ toFinalBlobAccumulator() {
258
+ return new FinalBlobAccumulator(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc);
259
+ }
280
260
  }
@@ -0,0 +1,30 @@
1
+ import { BLS12Point, Fr } from '@aztec/foundation/fields';
2
+ import { Blob } from './blob.js';
3
+ /**
4
+ * @param blobs - The blobs to emit.
5
+ * @returns The blobs' compressed commitments in hex prefixed by the number of blobs. 1 byte for the prefix, 48 bytes
6
+ * per blob commitment.
7
+ * @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs.
8
+ */
9
+ export declare function getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${string}`;
10
+ /**
11
+ * @param fields - Fields to broadcast in the blob(s)
12
+ * @returns As many blobs as required to broadcast the given fields to an L1 block.
13
+ *
14
+ * @throws If the number of fields does not match what's indicated by the checkpoint prefix.
15
+ */
16
+ export declare function getBlobsPerL1Block(fields: Fr[]): Blob[];
17
+ /**
18
+ * Get the fields from all blobs in the checkpoint. Ignoring the fields beyond the length specified by the
19
+ * checkpoint prefix (the first field).
20
+ *
21
+ * @param blobs - The blobs to read fields from. Should be all the blobs in the L1 block proposing the checkpoint.
22
+ * @param checkEncoding - Whether to check if the entire encoded blob fields are valid. If false, it will still check
23
+ * the checkpoint prefix and throw if there's not enough fields.
24
+ * @returns The fields added throughout the checkpoint.
25
+ */
26
+ export declare function getBlobFieldsInCheckpoint(blobs: Blob[], checkEncoding?: boolean): Fr[];
27
+ export declare function computeBlobFieldsHashFromBlobs(blobs: Blob[]): Promise<Fr>;
28
+ export declare function computeBlobsHashFromBlobs(blobs: Blob[]): Fr;
29
+ export declare function getBlobCommitmentsFromBlobs(blobs: Blob[]): BLS12Point[];
30
+ //# sourceMappingURL=blob_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob_utils.d.ts","sourceRoot":"","sources":["../src/blob_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,MAAM,EAAE,CAS1E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CASvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,aAAa,UAAQ,GAAG,EAAE,EAAE,CAEpF;AAED,wBAAsB,8BAA8B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAQ/E;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAE3D;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,CAEvE"}
@@ -0,0 +1,60 @@
1
+ import { FIELDS_PER_BLOB } from '@aztec/constants';
2
+ import { BLS12Point } from '@aztec/foundation/fields';
3
+ import { Blob } from './blob.js';
4
+ import { deserializeEncodedBlobToFields } from './deserialize.js';
5
+ import { computeBlobFieldsHash, computeBlobsHash } from './hash.js';
6
+ /**
7
+ * @param blobs - The blobs to emit.
8
+ * @returns The blobs' compressed commitments in hex prefixed by the number of blobs. 1 byte for the prefix, 48 bytes
9
+ * per blob commitment.
10
+ * @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs.
11
+ */ export function getPrefixedEthBlobCommitments(blobs) {
12
+ // Prefix the number of blobs.
13
+ const lenBuf = Buffer.alloc(1);
14
+ lenBuf.writeUint8(blobs.length);
15
+ const blobBuf = Buffer.concat(blobs.map((blob)=>blob.commitment));
16
+ const buf = Buffer.concat([
17
+ lenBuf,
18
+ blobBuf
19
+ ]);
20
+ return `0x${buf.toString('hex')}`;
21
+ }
22
+ /**
23
+ * @param fields - Fields to broadcast in the blob(s)
24
+ * @returns As many blobs as required to broadcast the given fields to an L1 block.
25
+ *
26
+ * @throws If the number of fields does not match what's indicated by the checkpoint prefix.
27
+ */ export function getBlobsPerL1Block(fields) {
28
+ if (!fields.length) {
29
+ throw new Error('Cannot create blobs from empty fields.');
30
+ }
31
+ const numBlobs = Math.ceil(fields.length / FIELDS_PER_BLOB);
32
+ return Array.from({
33
+ length: numBlobs
34
+ }, (_, i)=>Blob.fromFields(fields.slice(i * FIELDS_PER_BLOB, (i + 1) * FIELDS_PER_BLOB)));
35
+ }
36
+ /**
37
+ * Get the fields from all blobs in the checkpoint. Ignoring the fields beyond the length specified by the
38
+ * checkpoint prefix (the first field).
39
+ *
40
+ * @param blobs - The blobs to read fields from. Should be all the blobs in the L1 block proposing the checkpoint.
41
+ * @param checkEncoding - Whether to check if the entire encoded blob fields are valid. If false, it will still check
42
+ * the checkpoint prefix and throw if there's not enough fields.
43
+ * @returns The fields added throughout the checkpoint.
44
+ */ export function getBlobFieldsInCheckpoint(blobs, checkEncoding = false) {
45
+ return deserializeEncodedBlobToFields(Buffer.concat(blobs.map((b)=>b.data)), checkEncoding);
46
+ }
47
+ export async function computeBlobFieldsHashFromBlobs(blobs) {
48
+ const fields = blobs.map((b)=>b.toFields()).flat();
49
+ const numBlobFields = fields[0].toNumber();
50
+ if (numBlobFields > fields.length) {
51
+ throw new Error(`The prefix indicates ${numBlobFields} fields. Got ${fields.length}.`);
52
+ }
53
+ return await computeBlobFieldsHash(fields.slice(0, numBlobFields));
54
+ }
55
+ export function computeBlobsHashFromBlobs(blobs) {
56
+ return computeBlobsHash(blobs.map((b)=>b.getEthVersionedBlobHash()));
57
+ }
58
+ export function getBlobCommitmentsFromBlobs(blobs) {
59
+ return blobs.map((b)=>BLS12Point.decompress(b.commitment));
60
+ }
@@ -0,0 +1,21 @@
1
+ import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
2
+ import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
3
+ /**
4
+ * See `noir-projects/noir-protocol-circuits/crates/blob/src/abis/blob_accumulator.nr` for documentation.
5
+ */
6
+ export declare class BlobAccumulator {
7
+ blobCommitmentsHashAcc: Fr;
8
+ zAcc: Fr;
9
+ yAcc: BLS12Fr;
10
+ cAcc: BLS12Point;
11
+ gammaAcc: Fr;
12
+ gammaPowAcc: BLS12Fr;
13
+ constructor(blobCommitmentsHashAcc: Fr, zAcc: Fr, yAcc: BLS12Fr, cAcc: BLS12Point, gammaAcc: Fr, gammaPowAcc: BLS12Fr);
14
+ static empty(): BlobAccumulator;
15
+ equals(other: BlobAccumulator): boolean;
16
+ static fromBuffer(buffer: Buffer | BufferReader): BlobAccumulator;
17
+ toBuffer(): Buffer<ArrayBufferLike>;
18
+ toFields(): Fr[];
19
+ static fromFields(fields: Fr[] | FieldReader): BlobAccumulator;
20
+ }
21
+ //# sourceMappingURL=blob_accumulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob_accumulator.d.ts","sourceRoot":"","sources":["../../src/circuit_types/blob_accumulator.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAqB,MAAM,6BAA6B,CAAC;AAE3F;;GAEG;AACH,qBAAa,eAAe;IAEjB,sBAAsB,EAAE,EAAE;IAC1B,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,EAAE;IACZ,WAAW,EAAE,OAAO;gBALpB,sBAAsB,EAAE,EAAE,EAC1B,IAAI,EAAE,EAAE,EACR,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,EAAE,EACZ,WAAW,EAAE,OAAO;IAG7B,MAAM,CAAC,KAAK,IAAI,eAAe;IAI/B,MAAM,CAAC,KAAK,EAAE,eAAe;IAW7B,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,eAAe;IAYjE,QAAQ;IAWR,QAAQ;IAaR,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,eAAe;CAe/D"}
@@ -0,0 +1,58 @@
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
+ /**
5
+ * See `noir-projects/noir-protocol-circuits/crates/blob/src/abis/blob_accumulator.nr` for documentation.
6
+ */ export class BlobAccumulator {
7
+ blobCommitmentsHashAcc;
8
+ zAcc;
9
+ yAcc;
10
+ cAcc;
11
+ gammaAcc;
12
+ gammaPowAcc;
13
+ constructor(blobCommitmentsHashAcc, zAcc, yAcc, cAcc, gammaAcc, gammaPowAcc){
14
+ this.blobCommitmentsHashAcc = blobCommitmentsHashAcc;
15
+ this.zAcc = zAcc;
16
+ this.yAcc = yAcc;
17
+ this.cAcc = cAcc;
18
+ this.gammaAcc = gammaAcc;
19
+ this.gammaPowAcc = gammaPowAcc;
20
+ }
21
+ static empty() {
22
+ return new BlobAccumulator(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO, Fr.ZERO, BLS12Fr.ZERO);
23
+ }
24
+ equals(other) {
25
+ 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);
26
+ }
27
+ static fromBuffer(buffer) {
28
+ const reader = BufferReader.asReader(buffer);
29
+ return new BlobAccumulator(Fr.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader), BLS12Point.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader));
30
+ }
31
+ toBuffer() {
32
+ return serializeToBuffer(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.gammaAcc, this.gammaPowAcc);
33
+ }
34
+ toFields() {
35
+ return [
36
+ this.blobCommitmentsHashAcc,
37
+ this.zAcc,
38
+ ...this.yAcc.toNoirBigNum().limbs.map(Fr.fromString),
39
+ ...this.cAcc.x.toNoirBigNum().limbs.map(Fr.fromString),
40
+ ...this.cAcc.y.toNoirBigNum().limbs.map(Fr.fromString),
41
+ new Fr(this.cAcc.isInfinite),
42
+ this.gammaAcc,
43
+ ...this.gammaPowAcc.toNoirBigNum().limbs.map(Fr.fromString)
44
+ ];
45
+ }
46
+ static fromFields(fields) {
47
+ const reader = FieldReader.asReader(fields);
48
+ return new BlobAccumulator(reader.readField(), reader.readField(), BLS12Fr.fromNoirBigNum({
49
+ limbs: reader.readFieldArray(BLS12_FR_LIMBS).map((f)=>f.toString())
50
+ }), new BLS12Point(BLS12Fq.fromNoirBigNum({
51
+ limbs: reader.readFieldArray(BLS12_FQ_LIMBS).map((f)=>f.toString())
52
+ }), BLS12Fq.fromNoirBigNum({
53
+ limbs: reader.readFieldArray(BLS12_FQ_LIMBS).map((f)=>f.toString())
54
+ }), reader.readBoolean()), reader.readField(), BLS12Fr.fromNoirBigNum({
55
+ limbs: reader.readFieldArray(BLS12_FR_LIMBS).map((f)=>f.toString())
56
+ }));
57
+ }
58
+ }
@@ -0,0 +1,22 @@
1
+ import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
2
+ import { BufferReader } from '@aztec/foundation/serialize';
3
+ import { inspect } from 'util';
4
+ /**
5
+ * See `noir-projects/noir-protocol-circuits/crates/blob/src/abis/final_blob_accumulator.nr` for documentation.
6
+ */
7
+ export declare class FinalBlobAccumulator {
8
+ blobCommitmentsHash: Fr;
9
+ z: Fr;
10
+ y: BLS12Fr;
11
+ c: BLS12Point;
12
+ constructor(blobCommitmentsHash: Fr, z: Fr, y: BLS12Fr, c: BLS12Point);
13
+ static empty(): FinalBlobAccumulator;
14
+ static fromBuffer(buffer: Buffer | BufferReader): FinalBlobAccumulator;
15
+ toBuffer(): Buffer<ArrayBufferLike>;
16
+ toFields(): Fr[];
17
+ toString(): string;
18
+ equals(other: FinalBlobAccumulator): boolean;
19
+ static random(): FinalBlobAccumulator;
20
+ [inspect.custom](): string;
21
+ }
22
+ //# sourceMappingURL=final_blob_accumulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"final_blob_accumulator.d.ts","sourceRoot":"","sources":["../../src/circuit_types/final_blob_accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B;;GAEG;AACH,qBAAa,oBAAoB;IAEtB,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,oBAAoB;IAIpC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,oBAAoB;IAUtE,QAAQ;IAIR,QAAQ;IAUR,QAAQ;IAQR,MAAM,CAAC,KAAK,EAAE,oBAAoB;IAUlC,MAAM,CAAC,MAAM;IAIb,CAAC,OAAO,CAAC,MAAM,CAAC;CAQjB"}
@@ -0,0 +1,63 @@
1
+ import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
2
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ import { inspect } from 'util';
4
+ /**
5
+ * See `noir-projects/noir-protocol-circuits/crates/blob/src/abis/final_blob_accumulator.nr` for documentation.
6
+ */ export class FinalBlobAccumulator {
7
+ blobCommitmentsHash;
8
+ z;
9
+ y;
10
+ c;
11
+ constructor(blobCommitmentsHash, z, y, c){
12
+ this.blobCommitmentsHash = blobCommitmentsHash;
13
+ this.z = z;
14
+ this.y = y;
15
+ this.c = c;
16
+ }
17
+ static empty() {
18
+ return new FinalBlobAccumulator(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO);
19
+ }
20
+ static fromBuffer(buffer) {
21
+ const reader = BufferReader.asReader(buffer);
22
+ return new FinalBlobAccumulator(Fr.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader), BLS12Point.fromBuffer(reader));
23
+ }
24
+ toBuffer() {
25
+ return serializeToBuffer(this.blobCommitmentsHash, this.z, this.y, this.c);
26
+ }
27
+ toFields() {
28
+ return [
29
+ this.blobCommitmentsHash,
30
+ this.z,
31
+ ...this.y.toNoirBigNum().limbs.map(Fr.fromString),
32
+ ...this.c.toBN254Fields()
33
+ ];
34
+ }
35
+ // The below is used to send to L1 for proof verification
36
+ toString() {
37
+ // We prepend 32 bytes for the (unused) 'blobHash' slot. This is not read or required by getEpochProofPublicInputs() on L1, but
38
+ // is expected since we usually pass the full precompile inputs via verifyEpochRootProof() to getEpochProofPublicInputs() to ensure
39
+ // we use calldata rather than a slice in memory:
40
+ const buf = Buffer.concat([
41
+ Buffer.alloc(32),
42
+ this.z.toBuffer(),
43
+ this.y.toBuffer(),
44
+ this.c.compress()
45
+ ]);
46
+ return buf.toString('hex');
47
+ }
48
+ equals(other) {
49
+ return this.blobCommitmentsHash.equals(other.blobCommitmentsHash) && this.z.equals(other.z) && this.y.equals(other.y) && this.c.equals(other.c);
50
+ }
51
+ // Creates a random instance. Used for testing only - will not prove/verify.
52
+ static random() {
53
+ return new FinalBlobAccumulator(Fr.random(), Fr.random(), BLS12Fr.random(), BLS12Point.random());
54
+ }
55
+ [inspect.custom]() {
56
+ return `FinalBlobAccumulator {
57
+ blobCommitmentsHash: ${inspect(this.blobCommitmentsHash)},
58
+ z: ${inspect(this.z)},
59
+ y: ${inspect(this.y)},
60
+ c: ${inspect(this.c)},
61
+ }`;
62
+ }
63
+ }
@@ -0,0 +1,15 @@
1
+ import { BLS12Fr, Fr } from '@aztec/foundation/fields';
2
+ import { BufferReader } from '@aztec/foundation/serialize';
3
+ /**
4
+ * See `noir-projects/noir-protocol-circuits/crates/blob/src/abis/final_blob_batching_challenges.nr` for documentation.
5
+ */
6
+ export declare class FinalBlobBatchingChallenges {
7
+ readonly z: Fr;
8
+ readonly gamma: BLS12Fr;
9
+ constructor(z: Fr, gamma: BLS12Fr);
10
+ equals(other: FinalBlobBatchingChallenges): boolean;
11
+ static empty(): FinalBlobBatchingChallenges;
12
+ static fromBuffer(buffer: Buffer | BufferReader): FinalBlobBatchingChallenges;
13
+ toBuffer(): Buffer<ArrayBufferLike>;
14
+ }
15
+ //# sourceMappingURL=final_blob_batching_challenges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"final_blob_batching_challenges.d.ts","sourceRoot":"","sources":["../../src/circuit_types/final_blob_batching_challenges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E;;GAEG;AACH,qBAAa,2BAA2B;aAEpB,CAAC,EAAE,EAAE;aACL,KAAK,EAAE,OAAO;gBADd,CAAC,EAAE,EAAE,EACL,KAAK,EAAE,OAAO;IAGhC,MAAM,CAAC,KAAK,EAAE,2BAA2B;IAIzC,MAAM,CAAC,KAAK,IAAI,2BAA2B;IAI3C,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,2BAA2B;IAK7E,QAAQ;CAGT"}
@@ -0,0 +1,25 @@
1
+ import { BLS12Fr, Fr } from '@aztec/foundation/fields';
2
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ /**
4
+ * See `noir-projects/noir-protocol-circuits/crates/blob/src/abis/final_blob_batching_challenges.nr` for documentation.
5
+ */ export class FinalBlobBatchingChallenges {
6
+ z;
7
+ gamma;
8
+ constructor(z, gamma){
9
+ this.z = z;
10
+ this.gamma = gamma;
11
+ }
12
+ equals(other) {
13
+ return this.z.equals(other.z) && this.gamma.equals(other.gamma);
14
+ }
15
+ static empty() {
16
+ return new FinalBlobBatchingChallenges(Fr.ZERO, BLS12Fr.ZERO);
17
+ }
18
+ static fromBuffer(buffer) {
19
+ const reader = BufferReader.asReader(buffer);
20
+ return new FinalBlobBatchingChallenges(Fr.fromBuffer(reader), reader.readObject(BLS12Fr));
21
+ }
22
+ toBuffer() {
23
+ return serializeToBuffer(this.z, this.gamma);
24
+ }
25
+ }
@@ -0,0 +1,4 @@
1
+ export * from './blob_accumulator.js';
2
+ export * from './final_blob_accumulator.js';
3
+ export * from './final_blob_batching_challenges.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/circuit_types/index.ts"],"names":[],"mappings":"AACA,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /// Types used in the protocol circuits.
2
+ export * from './blob_accumulator.js';
3
+ export * from './final_blob_accumulator.js';
4
+ export * from './final_blob_batching_challenges.js';