@aztec/blob-lib 1.0.0-nightly.20250611 → 1.0.0-nightly.20250613
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 +26 -23
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +37 -64
- package/dest/blob_batching.d.ts +1 -18
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +5 -22
- package/dest/blob_batching_public_inputs.d.ts +6 -1
- package/dest/blob_batching_public_inputs.d.ts.map +1 -1
- package/dest/blob_batching_public_inputs.js +11 -13
- package/dest/interface.d.ts +0 -1
- package/dest/interface.d.ts.map +1 -1
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +2 -2
- package/package.json +3 -3
- package/src/blob.ts +34 -71
- package/src/blob_batching.ts +15 -33
- package/src/blob_batching_public_inputs.ts +26 -15
- package/src/interface.ts +0 -3
- package/src/testing.ts +3 -3
package/dest/blob.d.ts
CHANGED
|
@@ -12,27 +12,19 @@ export declare class Blob {
|
|
|
12
12
|
readonly data: BlobBuffer;
|
|
13
13
|
/** 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
14
|
readonly fieldsHash: Fr;
|
|
15
|
-
/** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y. */
|
|
15
|
+
/** 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). */
|
|
16
16
|
readonly challengeZ: Fr;
|
|
17
|
-
/** Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts. */
|
|
18
|
-
readonly evaluationY: Buffer;
|
|
19
17
|
/** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */
|
|
20
18
|
readonly commitment: Buffer;
|
|
21
|
-
/** KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes). */
|
|
22
|
-
readonly proof: Buffer;
|
|
23
19
|
constructor(
|
|
24
20
|
/** The blob to be broadcast on L1 in bytes form. */
|
|
25
21
|
data: BlobBuffer,
|
|
26
22
|
/** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */
|
|
27
23
|
fieldsHash: Fr,
|
|
28
|
-
/** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y. */
|
|
24
|
+
/** 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). */
|
|
29
25
|
challengeZ: Fr,
|
|
30
|
-
/** Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts. */
|
|
31
|
-
evaluationY: Buffer,
|
|
32
26
|
/** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */
|
|
33
|
-
commitment: Buffer
|
|
34
|
-
/** KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes). */
|
|
35
|
-
proof: Buffer);
|
|
27
|
+
commitment: Buffer);
|
|
36
28
|
/**
|
|
37
29
|
* The encoded version of the blob will determine the end of the blob based on the transaction encoding.
|
|
38
30
|
* This is required when the fieldsHash of a blob will contain trailing zeros.
|
|
@@ -117,6 +109,19 @@ export declare class Blob {
|
|
|
117
109
|
commitmentToFields(): [Fr, Fr];
|
|
118
110
|
getEthVersionedBlobHash(): Buffer;
|
|
119
111
|
static getEthVersionedBlobHash(commitment: Buffer): Buffer;
|
|
112
|
+
/**
|
|
113
|
+
* Evaluate the blob at a given challenge and return the evaluation and KZG proof.
|
|
114
|
+
*
|
|
115
|
+
* @param challengeZ - The challenge z at which to evaluate the blob. If not given, assume we want to evaluate at the individual blob's z.
|
|
116
|
+
*
|
|
117
|
+
* @returns -
|
|
118
|
+
* y: Buffer - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts
|
|
119
|
+
* proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
|
|
120
|
+
*/
|
|
121
|
+
evaluate(challengeZ?: Fr): {
|
|
122
|
+
y: Buffer<ArrayBuffer>;
|
|
123
|
+
proof: Buffer<ArrayBuffer>;
|
|
124
|
+
};
|
|
120
125
|
/**
|
|
121
126
|
* Get the buffer representation of the ENTIRE blob.
|
|
122
127
|
*
|
|
@@ -139,23 +144,21 @@ export declare class Blob {
|
|
|
139
144
|
*/
|
|
140
145
|
getSize(): number;
|
|
141
146
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* input[64:96] - y
|
|
147
|
-
* input[96:144] - commitment C
|
|
148
|
-
* input[144:192] - proof (a commitment to the quotient polynomial q(X))
|
|
149
|
-
*
|
|
150
|
-
* See https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile
|
|
147
|
+
* @param blobs - The blobs to emit
|
|
148
|
+
* @returns The blobs' compressed commitments in hex prefixed by the number of blobs
|
|
149
|
+
* @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs:
|
|
150
|
+
* One byte for the number blobs + 48 bytes per blob commitment
|
|
151
151
|
*/
|
|
152
|
-
getEthBlobEvaluationInputs(): `0x${string}`;
|
|
153
|
-
static getEthBlobEvaluationInputs(blobs: Blob[]): `0x${string}`;
|
|
154
152
|
static getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${string}`;
|
|
155
153
|
static getViemKzgInstance(): {
|
|
156
154
|
blobToKzgCommitment: typeof cKzg.blobToKzgCommitment;
|
|
157
155
|
computeBlobKzgProof: typeof cKzg.computeBlobKzgProof;
|
|
158
156
|
};
|
|
159
|
-
|
|
157
|
+
/**
|
|
158
|
+
* @param fields - Fields to broadcast in the blob(s)
|
|
159
|
+
* @returns As many blobs as we require to broadcast the given fields for a block
|
|
160
|
+
* @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.
|
|
161
|
+
*/
|
|
162
|
+
static getBlobsPerBlock(fields: Fr[]): Promise<Blob[]>;
|
|
160
163
|
}
|
|
161
164
|
//# sourceMappingURL=blob.d.ts.map
|
package/dest/blob.d.ts.map
CHANGED
|
@@ -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,
|
|
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,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvF;;;;;;OAMG;WACU,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,mBAAmB,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB9E;;;;;;;;;;;OAWG;WACU,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAepD;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ;IAS/B;;;;;;OAMG;IACH,QAAQ,IAAI,EAAE,EAAE;IAIhB;;;;;;;;OAQG;IACH,eAAe,IAAI,EAAE,EAAE;IAUvB;;;;;;OAMG;IACH,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;IAU3C;;;;;;;;;;;OAWG;IACH,kBAAkB,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC;IAK9B,uBAAuB,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;;;;IAOzB;;;;OAIG;WACU,gBAAgB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;CAU7D"}
|
package/dest/blob.js
CHANGED
|
@@ -14,16 +14,12 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
14
14
|
data;
|
|
15
15
|
fieldsHash;
|
|
16
16
|
challengeZ;
|
|
17
|
-
evaluationY;
|
|
18
17
|
commitment;
|
|
19
|
-
|
|
20
|
-
constructor(/** The blob to be broadcast on L1 in bytes form. */ data, /** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */ fieldsHash, /** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y. */ challengeZ, /** Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts. */ evaluationY, /** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */ commitment, /** KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes). */ proof){
|
|
18
|
+
constructor(/** The blob to be broadcast on L1 in bytes form. */ data, /** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */ fieldsHash, /** 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). */ challengeZ, /** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */ commitment){
|
|
21
19
|
this.data = data;
|
|
22
20
|
this.fieldsHash = fieldsHash;
|
|
23
21
|
this.challengeZ = challengeZ;
|
|
24
|
-
this.evaluationY = evaluationY;
|
|
25
22
|
this.commitment = commitment;
|
|
26
|
-
this.proof = proof;
|
|
27
23
|
}
|
|
28
24
|
/**
|
|
29
25
|
* The encoded version of the blob will determine the end of the blob based on the transaction encoding.
|
|
@@ -65,13 +61,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
65
61
|
fieldsHash,
|
|
66
62
|
...commitmentToFields(commitment)
|
|
67
63
|
]);
|
|
68
|
-
|
|
69
|
-
if (!verifyKzgProof(commitment, challengeZ.toBuffer(), res[1], res[0])) {
|
|
70
|
-
throw new Error(`KZG proof did not verify.`);
|
|
71
|
-
}
|
|
72
|
-
const proof = Buffer.from(res[0]);
|
|
73
|
-
const evaluationY = Buffer.from(res[1]);
|
|
74
|
-
return new Blob(data, fieldsHash, challengeZ, evaluationY, commitment, proof);
|
|
64
|
+
return new Blob(data, fieldsHash, challengeZ, commitment);
|
|
75
65
|
}
|
|
76
66
|
/**
|
|
77
67
|
* Create a Blob from a JSON object.
|
|
@@ -105,9 +95,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
105
95
|
blob: `0x${Buffer.from(this.data).toString('hex')}`,
|
|
106
96
|
index: index.toString(),
|
|
107
97
|
// eslint-disable-next-line camelcase
|
|
108
|
-
kzg_commitment: `0x${this.commitment.toString('hex')}
|
|
109
|
-
// eslint-disable-next-line camelcase
|
|
110
|
-
kzg_proof: `0x${this.proof.toString('hex')}`
|
|
98
|
+
kzg_commitment: `0x${this.commitment.toString('hex')}`
|
|
111
99
|
};
|
|
112
100
|
}
|
|
113
101
|
/**
|
|
@@ -173,13 +161,34 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
173
161
|
return hash;
|
|
174
162
|
}
|
|
175
163
|
/**
|
|
164
|
+
* Evaluate the blob at a given challenge and return the evaluation and KZG proof.
|
|
165
|
+
*
|
|
166
|
+
* @param challengeZ - The challenge z at which to evaluate the blob. If not given, assume we want to evaluate at the individual blob's z.
|
|
167
|
+
*
|
|
168
|
+
* @returns -
|
|
169
|
+
* y: Buffer - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts
|
|
170
|
+
* proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
|
|
171
|
+
*/ evaluate(challengeZ) {
|
|
172
|
+
const z = challengeZ || this.challengeZ;
|
|
173
|
+
const res = computeKzgProof(this.data, z.toBuffer());
|
|
174
|
+
if (!verifyKzgProof(this.commitment, z.toBuffer(), res[1], res[0])) {
|
|
175
|
+
throw new Error(`KZG proof did not verify.`);
|
|
176
|
+
}
|
|
177
|
+
const proof = Buffer.from(res[0]);
|
|
178
|
+
const y = Buffer.from(res[1]);
|
|
179
|
+
return {
|
|
180
|
+
y,
|
|
181
|
+
proof
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
176
185
|
* Get the buffer representation of the ENTIRE blob.
|
|
177
186
|
*
|
|
178
187
|
* @dev WARNING: this buffer contains all metadata aswell as the data itself
|
|
179
188
|
*
|
|
180
189
|
* @returns The buffer representation of the blob.
|
|
181
190
|
*/ toBuffer() {
|
|
182
|
-
return Buffer.from(serializeToBuffer(this.data.length, this.data, this.fieldsHash, this.challengeZ, this.
|
|
191
|
+
return Buffer.from(serializeToBuffer(this.data.length, this.data, this.fieldsHash, this.challengeZ, this.commitment.length, this.commitment));
|
|
183
192
|
}
|
|
184
193
|
/**
|
|
185
194
|
* Create a Blob from a buffer.
|
|
@@ -190,7 +199,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
190
199
|
* @returns A Blob created from the buffer.
|
|
191
200
|
*/ static fromBuffer(buf) {
|
|
192
201
|
const reader = BufferReader.asReader(buf);
|
|
193
|
-
return new Blob(reader.readUint8Array(), reader.readObject(Fr), reader.readObject(Fr), reader.readBuffer()
|
|
202
|
+
return new Blob(reader.readUint8Array(), reader.readObject(Fr), reader.readObject(Fr), reader.readBuffer());
|
|
194
203
|
}
|
|
195
204
|
/**
|
|
196
205
|
* Get the size of the blob in bytes
|
|
@@ -198,47 +207,11 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
198
207
|
return this.data.length;
|
|
199
208
|
}
|
|
200
209
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
-
* input[96:144] - commitment C
|
|
207
|
-
* input[144:192] - proof (a commitment to the quotient polynomial q(X))
|
|
208
|
-
*
|
|
209
|
-
* See https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile
|
|
210
|
-
*/ getEthBlobEvaluationInputs() {
|
|
211
|
-
const buf = Buffer.concat([
|
|
212
|
-
this.getEthVersionedBlobHash(),
|
|
213
|
-
this.challengeZ.toBuffer(),
|
|
214
|
-
this.evaluationY,
|
|
215
|
-
this.commitment,
|
|
216
|
-
this.proof
|
|
217
|
-
]);
|
|
218
|
-
return `0x${buf.toString('hex')}`;
|
|
219
|
-
}
|
|
220
|
-
static getEthBlobEvaluationInputs(blobs) {
|
|
221
|
-
let buf = Buffer.alloc(0);
|
|
222
|
-
blobs.forEach((blob)=>{
|
|
223
|
-
buf = Buffer.concat([
|
|
224
|
-
buf,
|
|
225
|
-
blob.getEthVersionedBlobHash(),
|
|
226
|
-
blob.challengeZ.toBuffer(),
|
|
227
|
-
blob.evaluationY,
|
|
228
|
-
blob.commitment,
|
|
229
|
-
blob.proof
|
|
230
|
-
]);
|
|
231
|
-
});
|
|
232
|
-
// For multiple blobs, we prefix the number of blobs:
|
|
233
|
-
const lenBuf = Buffer.alloc(1);
|
|
234
|
-
lenBuf.writeUint8(blobs.length);
|
|
235
|
-
buf = Buffer.concat([
|
|
236
|
-
lenBuf,
|
|
237
|
-
buf
|
|
238
|
-
]);
|
|
239
|
-
return `0x${buf.toString('hex')}`;
|
|
240
|
-
}
|
|
241
|
-
static getPrefixedEthBlobCommitments(blobs) {
|
|
210
|
+
* @param blobs - The blobs to emit
|
|
211
|
+
* @returns The blobs' compressed commitments in hex prefixed by the number of blobs
|
|
212
|
+
* @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs:
|
|
213
|
+
* One byte for the number blobs + 48 bytes per blob commitment
|
|
214
|
+
*/ static getPrefixedEthBlobCommitments(blobs) {
|
|
242
215
|
let buf = Buffer.alloc(0);
|
|
243
216
|
blobs.forEach((blob)=>{
|
|
244
217
|
buf = Buffer.concat([
|
|
@@ -246,7 +219,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
246
219
|
blob.commitment
|
|
247
220
|
]);
|
|
248
221
|
});
|
|
249
|
-
//
|
|
222
|
+
// We prefix the number of blobs:
|
|
250
223
|
const lenBuf = Buffer.alloc(1);
|
|
251
224
|
lenBuf.writeUint8(blobs.length);
|
|
252
225
|
buf = Buffer.concat([
|
|
@@ -261,11 +234,11 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
261
234
|
computeBlobKzgProof: cKzg.computeBlobKzgProof
|
|
262
235
|
};
|
|
263
236
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
237
|
+
/**
|
|
238
|
+
* @param fields - Fields to broadcast in the blob(s)
|
|
239
|
+
* @returns As many blobs as we require to broadcast the given fields for a block
|
|
240
|
+
* @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
|
+
*/ static async getBlobsPerBlock(fields) {
|
|
269
242
|
const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
|
|
270
243
|
const multiBlobFieldsHash = await poseidon2Hash(fields);
|
|
271
244
|
const res = [];
|
package/dest/blob_batching.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
3
|
import { Blob } from './blob.js';
|
|
4
|
-
import { BlobAccumulatorPublicInputs, FinalBlobAccumulatorPublicInputs } from './blob_batching_public_inputs.js';
|
|
5
4
|
/**
|
|
6
5
|
* A class to create, manage, and prove batched EVM blobs.
|
|
7
6
|
*/
|
|
@@ -29,10 +28,6 @@ export declare class BatchedBlob {
|
|
|
29
28
|
q: BLS12Point);
|
|
30
29
|
/**
|
|
31
30
|
* Get the final batched opening proof from multiple blobs.
|
|
32
|
-
*
|
|
33
|
-
* TODO(MW): Using the old Blob struct means there are ignored values (e.g. blob.evaluationY, because we now evaluate at shared z).
|
|
34
|
-
* When switching to batching, create new class w/o useless values.
|
|
35
|
-
*
|
|
36
31
|
* @dev MUST input all blobs to be broadcast. Does not work in multiple calls because z and gamma are calculated
|
|
37
32
|
* beforehand from ALL blobs.
|
|
38
33
|
*
|
|
@@ -153,7 +148,6 @@ export declare class BatchedBlobAccumulator {
|
|
|
153
148
|
* - gamma_acc := poseidon2(y_0.limbs)
|
|
154
149
|
* - gamma^(i + 1) = gamma^1 = gamma // denoted gamma_pow_acc
|
|
155
150
|
*
|
|
156
|
-
* TODO(MW): When moved to batching, we should ONLY evaluate individual blobs at z => won't need finalZ input.
|
|
157
151
|
* @returns An initial blob accumulator.
|
|
158
152
|
*/
|
|
159
153
|
static initialize(blob: Blob, finalBlobChallenges: FinalBlobBatchingChallenges): Promise<BatchedBlobAccumulator>;
|
|
@@ -165,7 +159,6 @@ export declare class BatchedBlobAccumulator {
|
|
|
165
159
|
/**
|
|
166
160
|
* Given blob i, accumulate all state.
|
|
167
161
|
* We assume the input blob has not been evaluated at z.
|
|
168
|
-
* TODO(MW): Currently returning new accumulator. May be better to mutate in future?
|
|
169
162
|
* @returns An updated blob accumulator.
|
|
170
163
|
*/
|
|
171
164
|
accumulate(blob: Blob): Promise<BatchedBlobAccumulator>;
|
|
@@ -189,17 +182,7 @@ export declare class BatchedBlobAccumulator {
|
|
|
189
182
|
* @returns A batched blob.
|
|
190
183
|
*/
|
|
191
184
|
finalize(): Promise<BatchedBlob>;
|
|
192
|
-
/**
|
|
193
|
-
* Converts to a struct for the public inputs of our rollup circuits.
|
|
194
|
-
* @returns A BlobAccumulatorPublicInputs instance.
|
|
195
|
-
*/
|
|
196
|
-
toBlobAccumulatorPublicInputs(): BlobAccumulatorPublicInputs;
|
|
197
|
-
/**
|
|
198
|
-
* Converts to a struct for the public inputs of our root rollup circuit.
|
|
199
|
-
* Warning: MUST be final accumulator state.
|
|
200
|
-
* @returns A FinalBlobAccumulatorPublicInputs instance.
|
|
201
|
-
*/
|
|
202
|
-
toFinalBlobAccumulatorPublicInputs(): FinalBlobAccumulatorPublicInputs;
|
|
203
185
|
isEmptyState(): boolean;
|
|
186
|
+
clone(): BatchedBlobAccumulator;
|
|
204
187
|
}
|
|
205
188
|
//# sourceMappingURL=blob_batching.d.ts.map
|
|
@@ -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;
|
|
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,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAcvD;;;;OAIG;WACU,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAK3E;;;;;;;;;OASG;WACU,+BAA+B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,2BAA2B,CAAC;WAqBpF,oCAAoC,IAAI,OAAO,CAAC,2BAA2B,CAAC;IAezF,uBAAuB,IAAI,MAAM;IAMjC,MAAM,CAAC,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAM1D;;;;;;;;;;OAUG;IACH,0BAA0B,IAAI,KAAK,MAAM,EAAE;CAU5C;AAED;;;;;;;;;;;;;;GAcG;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;AAED;;GAEG;AACH,qBAAa,sBAAsB;IAE/B,8CAA8C;aAC9B,sBAAsB,EAAE,EAAE;IAC1C,sEAAsE;aACtD,IAAI,EAAE,EAAE;IACxB,yGAAyG;aACzF,IAAI,EAAE,OAAO;IAC7B,qGAAqG;aACrF,IAAI,EAAE,UAAU;IAChC,oGAAoG;aACpF,IAAI,EAAE,UAAU;IAChC;;;;OAIG;aACa,QAAQ,EAAE,EAAE;IAC5B,uGAAuG;aACvF,QAAQ,EAAE,OAAO;IACjC,oGAAoG;aACpF,mBAAmB,EAAE,2BAA2B;;IAnBhE,8CAA8C;IAC9B,sBAAsB,EAAE,EAAE;IAC1C,sEAAsE;IACtD,IAAI,EAAE,EAAE;IACxB,yGAAyG;IACzF,IAAI,EAAE,OAAO;IAC7B,qGAAqG;IACrF,IAAI,EAAE,UAAU;IAChC,oGAAoG;IACpF,IAAI,EAAE,UAAU;IAChC;;;;OAIG;IACa,QAAQ,EAAE,EAAE;IAC5B,uGAAuG;IACvF,QAAQ,EAAE,OAAO;IACjC,oGAAoG;IACpF,mBAAmB,EAAE,2BAA2B;IAGlE;;;;;;;;;;;;;OAaG;WACU,UAAU,CACrB,IAAI,EAAE,IAAI,EACV,mBAAmB,EAAE,2BAA2B,GAC/C,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
|
@@ -5,7 +5,6 @@ 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
7
|
import { Blob, VERSIONED_HASH_VERSION_KZG } from './blob.js';
|
|
8
|
-
import { BlobAccumulatorPublicInputs, FinalBlobAccumulatorPublicInputs } from './blob_batching_public_inputs.js';
|
|
9
8
|
const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
10
9
|
/**
|
|
11
10
|
* A class to create, manage, and prove batched EVM blobs.
|
|
@@ -24,10 +23,6 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
26
25
|
* Get the final batched opening proof from multiple blobs.
|
|
27
|
-
*
|
|
28
|
-
* TODO(MW): Using the old Blob struct means there are ignored values (e.g. blob.evaluationY, because we now evaluate at shared z).
|
|
29
|
-
* When switching to batching, create new class w/o useless values.
|
|
30
|
-
*
|
|
31
26
|
* @dev MUST input all blobs to be broadcast. Does not work in multiple calls because z and gamma are calculated
|
|
32
27
|
* beforehand from ALL blobs.
|
|
33
28
|
*
|
|
@@ -209,7 +204,6 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
|
209
204
|
* - gamma_acc := poseidon2(y_0.limbs)
|
|
210
205
|
* - gamma^(i + 1) = gamma^1 = gamma // denoted gamma_pow_acc
|
|
211
206
|
*
|
|
212
|
-
* TODO(MW): When moved to batching, we should ONLY evaluate individual blobs at z => won't need finalZ input.
|
|
213
207
|
* @returns An initial blob accumulator.
|
|
214
208
|
*/ static async initialize(blob, finalBlobChallenges) {
|
|
215
209
|
const [q, evaluation] = computeKzgProof(blob.data, finalBlobChallenges.z.toBuffer());
|
|
@@ -228,7 +222,6 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
|
228
222
|
/**
|
|
229
223
|
* Given blob i, accumulate all state.
|
|
230
224
|
* We assume the input blob has not been evaluated at z.
|
|
231
|
-
* TODO(MW): Currently returning new accumulator. May be better to mutate in future?
|
|
232
225
|
* @returns An updated blob accumulator.
|
|
233
226
|
*/ async accumulate(blob) {
|
|
234
227
|
if (this.isEmptyState()) {
|
|
@@ -254,8 +247,8 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
|
254
247
|
* We assume the input blobs have not been evaluated at z.
|
|
255
248
|
* @returns An updated blob accumulator.
|
|
256
249
|
*/ async accumulateBlobs(blobs) {
|
|
257
|
-
//
|
|
258
|
-
let acc = this
|
|
250
|
+
// Initialise the acc to iterate over:
|
|
251
|
+
let acc = this.clone();
|
|
259
252
|
for(let i = 0; i < blobs.length; i++){
|
|
260
253
|
acc = await acc.accumulate(blobs[i]);
|
|
261
254
|
}
|
|
@@ -291,22 +284,12 @@ const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
|
291
284
|
}
|
|
292
285
|
return new BatchedBlob(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.qAcc);
|
|
293
286
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Converts to a struct for the public inputs of our rollup circuits.
|
|
296
|
-
* @returns A BlobAccumulatorPublicInputs instance.
|
|
297
|
-
*/ toBlobAccumulatorPublicInputs() {
|
|
298
|
-
return new BlobAccumulatorPublicInputs(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.gammaAcc, this.gammaPow);
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Converts to a struct for the public inputs of our root rollup circuit.
|
|
302
|
-
* Warning: MUST be final accumulator state.
|
|
303
|
-
* @returns A FinalBlobAccumulatorPublicInputs instance.
|
|
304
|
-
*/ toFinalBlobAccumulatorPublicInputs() {
|
|
305
|
-
return new FinalBlobAccumulatorPublicInputs(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc);
|
|
306
|
-
}
|
|
307
287
|
isEmptyState() {
|
|
308
288
|
return this.blobCommitmentsHashAcc.isZero() && this.zAcc.isZero() && this.yAcc.isZero() && this.cAcc.isZero() && this.qAcc.isZero() && this.gammaAcc.isZero() && this.gammaPow.isZero();
|
|
309
289
|
}
|
|
290
|
+
clone() {
|
|
291
|
+
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()));
|
|
292
|
+
}
|
|
310
293
|
}
|
|
311
294
|
// To mimic the hash accumulation in the rollup circuits, here we hash
|
|
312
295
|
// each u128 limb of the noir bignum struct representing the BLS field.
|
|
@@ -28,6 +28,11 @@ export declare class BlobAccumulatorPublicInputs {
|
|
|
28
28
|
accumulateBlobs(blobs: Blob[], finalBlobChallenges: FinalBlobBatchingChallenges): Promise<BlobAccumulatorPublicInputs>;
|
|
29
29
|
toFields(): Fr[];
|
|
30
30
|
static fromFields(fields: Fr[] | FieldReader): BlobAccumulatorPublicInputs;
|
|
31
|
+
/**
|
|
32
|
+
* Converts from an accumulator to a struct for the public inputs of our rollup circuits.
|
|
33
|
+
* @returns A BlobAccumulatorPublicInputs instance.
|
|
34
|
+
*/
|
|
35
|
+
static fromBatchedBlobAccumulator(accumulator: BatchedBlobAccumulator): BlobAccumulatorPublicInputs;
|
|
31
36
|
}
|
|
32
37
|
/**
|
|
33
38
|
* See nr FinalBlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
@@ -46,6 +51,7 @@ export declare class FinalBlobAccumulatorPublicInputs {
|
|
|
46
51
|
toString(): string;
|
|
47
52
|
equals(other: FinalBlobAccumulatorPublicInputs): boolean;
|
|
48
53
|
static random(): FinalBlobAccumulatorPublicInputs;
|
|
54
|
+
static fromBatchedBlobAccumulator(accumulator: BatchedBlobAccumulator): FinalBlobAccumulatorPublicInputs;
|
|
49
55
|
[inspect.custom](): string;
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
@@ -61,6 +67,5 @@ export declare class BlockBlobPublicInputs {
|
|
|
61
67
|
static empty(): BlockBlobPublicInputs;
|
|
62
68
|
static fromBuffer(buffer: Buffer | BufferReader): BlockBlobPublicInputs;
|
|
63
69
|
toBuffer(): Buffer<ArrayBufferLike>;
|
|
64
|
-
static fromBlobs(startBlobAccumulator: BatchedBlobAccumulator, blobs: Blob[]): Promise<BlockBlobPublicInputs>;
|
|
65
70
|
}
|
|
66
71
|
//# sourceMappingURL=blob_batching_public_inputs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob_batching_public_inputs.d.ts","sourceRoot":"","sources":["../src/blob_batching_public_inputs.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,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEtG;;GAEG;AACH,qBAAa,2BAA2B;IAE7B,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,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;
|
|
1
|
+
{"version":3,"file":"blob_batching_public_inputs.d.ts","sourceRoot":"","sources":["../src/blob_batching_public_inputs.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,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEtG;;GAEG;AACH,qBAAa,2BAA2B;IAE7B,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,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;AAED;;;;GAIG;AACH,qBAAa,qBAAqB;IAEvB,oBAAoB,EAAE,2BAA2B;IACjD,kBAAkB,EAAE,2BAA2B;IAC/C,mBAAmB,EAAE,2BAA2B;gBAFhD,oBAAoB,EAAE,2BAA2B,EACjD,kBAAkB,EAAE,2BAA2B,EAC/C,mBAAmB,EAAE,2BAA2B;IAGzD,MAAM,CAAC,KAAK,IAAI,qBAAqB;IAQrC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,qBAAqB;IASvE,QAAQ;CAGT"}
|
|
@@ -68,6 +68,12 @@ import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batc
|
|
|
68
68
|
limbs: reader.readFieldArray(BLS12_FR_LIMBS).map((f)=>f.toString())
|
|
69
69
|
}));
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Converts from an accumulator to a struct for the public inputs of our rollup circuits.
|
|
73
|
+
* @returns A BlobAccumulatorPublicInputs instance.
|
|
74
|
+
*/ static fromBatchedBlobAccumulator(accumulator) {
|
|
75
|
+
return new BlobAccumulatorPublicInputs(accumulator.blobCommitmentsHashAcc, accumulator.zAcc, accumulator.yAcc, accumulator.cAcc, accumulator.gammaAcc, accumulator.gammaPow);
|
|
76
|
+
}
|
|
71
77
|
}
|
|
72
78
|
/**
|
|
73
79
|
* See nr FinalBlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
@@ -100,11 +106,7 @@ import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batc
|
|
|
100
106
|
this.blobCommitmentsHash,
|
|
101
107
|
this.z,
|
|
102
108
|
...this.y.toNoirBigNum().limbs.map(Fr.fromString),
|
|
103
|
-
|
|
104
|
-
...[
|
|
105
|
-
new Fr(this.c.compress().subarray(0, 31)),
|
|
106
|
-
new Fr(this.c.compress().subarray(31, 48))
|
|
107
|
-
]
|
|
109
|
+
...this.c.toBN254Fields()
|
|
108
110
|
];
|
|
109
111
|
}
|
|
110
112
|
// The below is used to send to L1 for proof verification
|
|
@@ -127,6 +129,10 @@ import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batc
|
|
|
127
129
|
static random() {
|
|
128
130
|
return new FinalBlobAccumulatorPublicInputs(Fr.random(), Fr.random(), BLS12Fr.random(), BLS12Point.random());
|
|
129
131
|
}
|
|
132
|
+
// Warning: MUST be final accumulator state.
|
|
133
|
+
static fromBatchedBlobAccumulator(accumulator) {
|
|
134
|
+
return new FinalBlobAccumulatorPublicInputs(accumulator.blobCommitmentsHashAcc, accumulator.zAcc, accumulator.yAcc, accumulator.cAcc);
|
|
135
|
+
}
|
|
130
136
|
[inspect.custom]() {
|
|
131
137
|
return `FinalBlobAccumulatorPublicInputs {
|
|
132
138
|
blobCommitmentsHash: ${inspect(this.blobCommitmentsHash)},
|
|
@@ -159,12 +165,4 @@ import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batc
|
|
|
159
165
|
toBuffer() {
|
|
160
166
|
return serializeToBuffer(this.startBlobAccumulator, this.endBlobAccumulator, this.finalBlobChallenges);
|
|
161
167
|
}
|
|
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
168
|
}
|
package/dest/interface.d.ts
CHANGED
package/dest/interface.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAA+B,MAAM,oBAAoB,CAAC;AACzF,OAAO,
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAA+B,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAA+B,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEtG,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;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,SAAI,GAAG,qBAAqB,CAOzE;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
|
@@ -3,7 +3,7 @@ import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
|
3
3
|
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import { Blob } from './blob.js';
|
|
5
5
|
import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
6
|
-
import { BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
|
|
6
|
+
import { BlobAccumulatorPublicInputs, 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
|
/**
|
|
@@ -29,7 +29,7 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
|
29
29
|
* @returns A block blob public inputs instance.
|
|
30
30
|
*/ export function makeBlockBlobPublicInputs(seed = 1) {
|
|
31
31
|
const startBlobAccumulator = makeBatchedBlobAccumulator(seed);
|
|
32
|
-
return new BlockBlobPublicInputs(
|
|
32
|
+
return new BlockBlobPublicInputs(BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(startBlobAccumulator), BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(makeBatchedBlobAccumulator(seed + 1)), startBlobAccumulator.finalBlobChallenges);
|
|
33
33
|
}
|
|
34
34
|
// TODO: copied form stdlib tx effect
|
|
35
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.
|
|
3
|
+
"version": "1.0.0-nightly.20250613",
|
|
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.
|
|
29
|
-
"@aztec/foundation": "1.0.0-nightly.
|
|
28
|
+
"@aztec/constants": "1.0.0-nightly.20250613",
|
|
29
|
+
"@aztec/foundation": "1.0.0-nightly.20250613",
|
|
30
30
|
"c-kzg": "4.0.0-alpha.1",
|
|
31
31
|
"tslib": "^2.4.0"
|
|
32
32
|
},
|
package/src/blob.ts
CHANGED
|
@@ -24,14 +24,10 @@ export class Blob {
|
|
|
24
24
|
public readonly data: BlobBuffer,
|
|
25
25
|
/** 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
26
|
public readonly fieldsHash: Fr,
|
|
27
|
-
/** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y. */
|
|
27
|
+
/** 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). */
|
|
28
28
|
public readonly challengeZ: Fr,
|
|
29
|
-
/** Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts. */
|
|
30
|
-
public readonly evaluationY: Buffer,
|
|
31
29
|
/** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */
|
|
32
30
|
public readonly commitment: Buffer,
|
|
33
|
-
/** KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes). */
|
|
34
|
-
public readonly proof: Buffer,
|
|
35
31
|
) {}
|
|
36
32
|
|
|
37
33
|
/**
|
|
@@ -78,14 +74,8 @@ export class Blob {
|
|
|
78
74
|
const fieldsHash = multiBlobFieldsHash ? multiBlobFieldsHash : await poseidon2Hash(fields);
|
|
79
75
|
const commitment = Buffer.from(blobToKzgCommitment(data));
|
|
80
76
|
const challengeZ = await poseidon2Hash([fieldsHash, ...commitmentToFields(commitment)]);
|
|
81
|
-
const res = computeKzgProof(data, challengeZ.toBuffer());
|
|
82
|
-
if (!verifyKzgProof(commitment, challengeZ.toBuffer(), res[1], res[0])) {
|
|
83
|
-
throw new Error(`KZG proof did not verify.`);
|
|
84
|
-
}
|
|
85
|
-
const proof = Buffer.from(res[0]);
|
|
86
|
-
const evaluationY = Buffer.from(res[1]);
|
|
87
77
|
|
|
88
|
-
return new Blob(data, fieldsHash, challengeZ,
|
|
78
|
+
return new Blob(data, fieldsHash, challengeZ, commitment);
|
|
89
79
|
}
|
|
90
80
|
|
|
91
81
|
/**
|
|
@@ -128,8 +118,6 @@ export class Blob {
|
|
|
128
118
|
index: index.toString(),
|
|
129
119
|
// eslint-disable-next-line camelcase
|
|
130
120
|
kzg_commitment: `0x${this.commitment.toString('hex')}`,
|
|
131
|
-
// eslint-disable-next-line camelcase
|
|
132
|
-
kzg_proof: `0x${this.proof.toString('hex')}`,
|
|
133
121
|
};
|
|
134
122
|
}
|
|
135
123
|
|
|
@@ -209,6 +197,26 @@ export class Blob {
|
|
|
209
197
|
return hash;
|
|
210
198
|
}
|
|
211
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Evaluate the blob at a given challenge and return the evaluation and KZG proof.
|
|
202
|
+
*
|
|
203
|
+
* @param challengeZ - The challenge z at which to evaluate the blob. If not given, assume we want to evaluate at the individual blob's z.
|
|
204
|
+
*
|
|
205
|
+
* @returns -
|
|
206
|
+
* y: Buffer - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts
|
|
207
|
+
* proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
|
|
208
|
+
*/
|
|
209
|
+
evaluate(challengeZ?: Fr) {
|
|
210
|
+
const z = challengeZ || this.challengeZ;
|
|
211
|
+
const res = computeKzgProof(this.data, z.toBuffer());
|
|
212
|
+
if (!verifyKzgProof(this.commitment, z.toBuffer(), res[1], res[0])) {
|
|
213
|
+
throw new Error(`KZG proof did not verify.`);
|
|
214
|
+
}
|
|
215
|
+
const proof = Buffer.from(res[0]);
|
|
216
|
+
const y = Buffer.from(res[1]);
|
|
217
|
+
return { y, proof };
|
|
218
|
+
}
|
|
219
|
+
|
|
212
220
|
/**
|
|
213
221
|
* Get the buffer representation of the ENTIRE blob.
|
|
214
222
|
*
|
|
@@ -223,12 +231,8 @@ export class Blob {
|
|
|
223
231
|
this.data,
|
|
224
232
|
this.fieldsHash,
|
|
225
233
|
this.challengeZ,
|
|
226
|
-
this.evaluationY.length,
|
|
227
|
-
this.evaluationY,
|
|
228
234
|
this.commitment.length,
|
|
229
235
|
this.commitment,
|
|
230
|
-
this.proof.length,
|
|
231
|
-
this.proof,
|
|
232
236
|
),
|
|
233
237
|
);
|
|
234
238
|
}
|
|
@@ -243,14 +247,7 @@ export class Blob {
|
|
|
243
247
|
*/
|
|
244
248
|
static fromBuffer(buf: Buffer | BufferReader): Blob {
|
|
245
249
|
const reader = BufferReader.asReader(buf);
|
|
246
|
-
return new Blob(
|
|
247
|
-
reader.readUint8Array(),
|
|
248
|
-
reader.readObject(Fr),
|
|
249
|
-
reader.readObject(Fr),
|
|
250
|
-
reader.readBuffer(),
|
|
251
|
-
reader.readBuffer(),
|
|
252
|
-
reader.readBuffer(),
|
|
253
|
-
);
|
|
250
|
+
return new Blob(reader.readUint8Array(), reader.readObject(Fr), reader.readObject(Fr), reader.readBuffer());
|
|
254
251
|
}
|
|
255
252
|
|
|
256
253
|
/**
|
|
@@ -261,52 +258,17 @@ export class Blob {
|
|
|
261
258
|
}
|
|
262
259
|
|
|
263
260
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* input[64:96] - y
|
|
269
|
-
* input[96:144] - commitment C
|
|
270
|
-
* input[144:192] - proof (a commitment to the quotient polynomial q(X))
|
|
271
|
-
*
|
|
272
|
-
* See https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile
|
|
261
|
+
* @param blobs - The blobs to emit
|
|
262
|
+
* @returns The blobs' compressed commitments in hex prefixed by the number of blobs
|
|
263
|
+
* @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs:
|
|
264
|
+
* One byte for the number blobs + 48 bytes per blob commitment
|
|
273
265
|
*/
|
|
274
|
-
getEthBlobEvaluationInputs(): `0x${string}` {
|
|
275
|
-
const buf = Buffer.concat([
|
|
276
|
-
this.getEthVersionedBlobHash(),
|
|
277
|
-
this.challengeZ.toBuffer(),
|
|
278
|
-
this.evaluationY,
|
|
279
|
-
this.commitment,
|
|
280
|
-
this.proof,
|
|
281
|
-
]);
|
|
282
|
-
return `0x${buf.toString('hex')}`;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
static getEthBlobEvaluationInputs(blobs: Blob[]): `0x${string}` {
|
|
286
|
-
let buf = Buffer.alloc(0);
|
|
287
|
-
blobs.forEach(blob => {
|
|
288
|
-
buf = Buffer.concat([
|
|
289
|
-
buf,
|
|
290
|
-
blob.getEthVersionedBlobHash(),
|
|
291
|
-
blob.challengeZ.toBuffer(),
|
|
292
|
-
blob.evaluationY,
|
|
293
|
-
blob.commitment,
|
|
294
|
-
blob.proof,
|
|
295
|
-
]);
|
|
296
|
-
});
|
|
297
|
-
// For multiple blobs, we prefix the number of blobs:
|
|
298
|
-
const lenBuf = Buffer.alloc(1);
|
|
299
|
-
lenBuf.writeUint8(blobs.length);
|
|
300
|
-
buf = Buffer.concat([lenBuf, buf]);
|
|
301
|
-
return `0x${buf.toString('hex')}`;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
266
|
static getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${string}` {
|
|
305
267
|
let buf = Buffer.alloc(0);
|
|
306
268
|
blobs.forEach(blob => {
|
|
307
269
|
buf = Buffer.concat([buf, blob.commitment]);
|
|
308
270
|
});
|
|
309
|
-
//
|
|
271
|
+
// We prefix the number of blobs:
|
|
310
272
|
const lenBuf = Buffer.alloc(1);
|
|
311
273
|
lenBuf.writeUint8(blobs.length);
|
|
312
274
|
buf = Buffer.concat([lenBuf, buf]);
|
|
@@ -320,11 +282,12 @@ export class Blob {
|
|
|
320
282
|
};
|
|
321
283
|
}
|
|
322
284
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
285
|
+
/**
|
|
286
|
+
* @param fields - Fields to broadcast in the blob(s)
|
|
287
|
+
* @returns As many blobs as we require to broadcast the given fields for a block
|
|
288
|
+
* @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
|
+
*/
|
|
290
|
+
static async getBlobsPerBlock(fields: Fr[]): Promise<Blob[]> {
|
|
328
291
|
const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
|
|
329
292
|
const multiBlobFieldsHash = await poseidon2Hash(fields);
|
|
330
293
|
const res = [];
|
package/src/blob_batching.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
|
7
7
|
import cKzg from 'c-kzg';
|
|
8
8
|
|
|
9
9
|
import { Blob, VERSIONED_HASH_VERSION_KZG } from './blob.js';
|
|
10
|
-
import { BlobAccumulatorPublicInputs, FinalBlobAccumulatorPublicInputs } from './blob_batching_public_inputs.js';
|
|
11
10
|
|
|
12
11
|
const { computeKzgProof, verifyKzgProof } = cKzg;
|
|
13
12
|
|
|
@@ -30,10 +29,6 @@ export class BatchedBlob {
|
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
31
|
* Get the final batched opening proof from multiple blobs.
|
|
33
|
-
*
|
|
34
|
-
* TODO(MW): Using the old Blob struct means there are ignored values (e.g. blob.evaluationY, because we now evaluate at shared z).
|
|
35
|
-
* When switching to batching, create new class w/o useless values.
|
|
36
|
-
*
|
|
37
32
|
* @dev MUST input all blobs to be broadcast. Does not work in multiple calls because z and gamma are calculated
|
|
38
33
|
* beforehand from ALL blobs.
|
|
39
34
|
*
|
|
@@ -222,7 +217,6 @@ export class BatchedBlobAccumulator {
|
|
|
222
217
|
* - gamma_acc := poseidon2(y_0.limbs)
|
|
223
218
|
* - gamma^(i + 1) = gamma^1 = gamma // denoted gamma_pow_acc
|
|
224
219
|
*
|
|
225
|
-
* TODO(MW): When moved to batching, we should ONLY evaluate individual blobs at z => won't need finalZ input.
|
|
226
220
|
* @returns An initial blob accumulator.
|
|
227
221
|
*/
|
|
228
222
|
static async initialize(
|
|
@@ -264,7 +258,6 @@ export class BatchedBlobAccumulator {
|
|
|
264
258
|
/**
|
|
265
259
|
* Given blob i, accumulate all state.
|
|
266
260
|
* We assume the input blob has not been evaluated at z.
|
|
267
|
-
* TODO(MW): Currently returning new accumulator. May be better to mutate in future?
|
|
268
261
|
* @returns An updated blob accumulator.
|
|
269
262
|
*/
|
|
270
263
|
async accumulate(blob: Blob) {
|
|
@@ -294,8 +287,8 @@ export class BatchedBlobAccumulator {
|
|
|
294
287
|
* @returns An updated blob accumulator.
|
|
295
288
|
*/
|
|
296
289
|
async accumulateBlobs(blobs: Blob[]) {
|
|
297
|
-
//
|
|
298
|
-
let acc: BatchedBlobAccumulator = this
|
|
290
|
+
// Initialise the acc to iterate over:
|
|
291
|
+
let acc: BatchedBlobAccumulator = this.clone();
|
|
299
292
|
for (let i = 0; i < blobs.length; i++) {
|
|
300
293
|
acc = await acc.accumulate(blobs[i]);
|
|
301
294
|
}
|
|
@@ -336,30 +329,6 @@ export class BatchedBlobAccumulator {
|
|
|
336
329
|
return new BatchedBlob(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.qAcc);
|
|
337
330
|
}
|
|
338
331
|
|
|
339
|
-
/**
|
|
340
|
-
* Converts to a struct for the public inputs of our rollup circuits.
|
|
341
|
-
* @returns A BlobAccumulatorPublicInputs instance.
|
|
342
|
-
*/
|
|
343
|
-
toBlobAccumulatorPublicInputs() {
|
|
344
|
-
return new BlobAccumulatorPublicInputs(
|
|
345
|
-
this.blobCommitmentsHashAcc,
|
|
346
|
-
this.zAcc,
|
|
347
|
-
this.yAcc,
|
|
348
|
-
this.cAcc,
|
|
349
|
-
this.gammaAcc,
|
|
350
|
-
this.gammaPow,
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Converts to a struct for the public inputs of our root rollup circuit.
|
|
356
|
-
* Warning: MUST be final accumulator state.
|
|
357
|
-
* @returns A FinalBlobAccumulatorPublicInputs instance.
|
|
358
|
-
*/
|
|
359
|
-
toFinalBlobAccumulatorPublicInputs() {
|
|
360
|
-
return new FinalBlobAccumulatorPublicInputs(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
332
|
isEmptyState() {
|
|
364
333
|
return (
|
|
365
334
|
this.blobCommitmentsHashAcc.isZero() &&
|
|
@@ -371,6 +340,19 @@ export class BatchedBlobAccumulator {
|
|
|
371
340
|
this.gammaPow.isZero()
|
|
372
341
|
);
|
|
373
342
|
}
|
|
343
|
+
|
|
344
|
+
clone() {
|
|
345
|
+
return new BatchedBlobAccumulator(
|
|
346
|
+
Fr.fromBuffer(this.blobCommitmentsHashAcc.toBuffer()),
|
|
347
|
+
Fr.fromBuffer(this.zAcc.toBuffer()),
|
|
348
|
+
BLS12Fr.fromBuffer(this.yAcc.toBuffer()),
|
|
349
|
+
BLS12Point.fromBuffer(this.cAcc.toBuffer()),
|
|
350
|
+
BLS12Point.fromBuffer(this.qAcc.toBuffer()),
|
|
351
|
+
Fr.fromBuffer(this.gammaAcc.toBuffer()),
|
|
352
|
+
BLS12Fr.fromBuffer(this.gammaPow.toBuffer()),
|
|
353
|
+
FinalBlobBatchingChallenges.fromBuffer(this.finalBlobChallenges.toBuffer()),
|
|
354
|
+
);
|
|
355
|
+
}
|
|
374
356
|
}
|
|
375
357
|
|
|
376
358
|
// To mimic the hash accumulation in the rollup circuits, here we hash
|
|
@@ -115,6 +115,21 @@ export class BlobAccumulatorPublicInputs {
|
|
|
115
115
|
BLS12Fr.fromNoirBigNum({ limbs: reader.readFieldArray(BLS12_FR_LIMBS).map(f => f.toString()) }),
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Converts from an accumulator to a struct for the public inputs of our rollup circuits.
|
|
121
|
+
* @returns A BlobAccumulatorPublicInputs instance.
|
|
122
|
+
*/
|
|
123
|
+
static fromBatchedBlobAccumulator(accumulator: BatchedBlobAccumulator) {
|
|
124
|
+
return new BlobAccumulatorPublicInputs(
|
|
125
|
+
accumulator.blobCommitmentsHashAcc,
|
|
126
|
+
accumulator.zAcc,
|
|
127
|
+
accumulator.yAcc,
|
|
128
|
+
accumulator.cAcc,
|
|
129
|
+
accumulator.gammaAcc,
|
|
130
|
+
accumulator.gammaPow,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
118
133
|
}
|
|
119
134
|
|
|
120
135
|
/**
|
|
@@ -155,8 +170,7 @@ export class FinalBlobAccumulatorPublicInputs {
|
|
|
155
170
|
this.blobCommitmentsHash,
|
|
156
171
|
this.z,
|
|
157
172
|
...this.y.toNoirBigNum().limbs.map(Fr.fromString),
|
|
158
|
-
|
|
159
|
-
...[new Fr(this.c.compress().subarray(0, 31)), new Fr(this.c.compress().subarray(31, 48))],
|
|
173
|
+
...this.c.toBN254Fields(),
|
|
160
174
|
];
|
|
161
175
|
}
|
|
162
176
|
|
|
@@ -183,6 +197,16 @@ export class FinalBlobAccumulatorPublicInputs {
|
|
|
183
197
|
return new FinalBlobAccumulatorPublicInputs(Fr.random(), Fr.random(), BLS12Fr.random(), BLS12Point.random());
|
|
184
198
|
}
|
|
185
199
|
|
|
200
|
+
// Warning: MUST be final accumulator state.
|
|
201
|
+
static fromBatchedBlobAccumulator(accumulator: BatchedBlobAccumulator) {
|
|
202
|
+
return new FinalBlobAccumulatorPublicInputs(
|
|
203
|
+
accumulator.blobCommitmentsHashAcc,
|
|
204
|
+
accumulator.zAcc,
|
|
205
|
+
accumulator.yAcc,
|
|
206
|
+
accumulator.cAcc,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
186
210
|
[inspect.custom]() {
|
|
187
211
|
return `FinalBlobAccumulatorPublicInputs {
|
|
188
212
|
blobCommitmentsHash: ${inspect(this.blobCommitmentsHash)},
|
|
@@ -225,17 +249,4 @@ export class BlockBlobPublicInputs {
|
|
|
225
249
|
toBuffer() {
|
|
226
250
|
return serializeToBuffer(this.startBlobAccumulator, this.endBlobAccumulator, this.finalBlobChallenges);
|
|
227
251
|
}
|
|
228
|
-
|
|
229
|
-
// Creates BlockBlobPublicInputs from the starting accumulator state and all blobs in the block.
|
|
230
|
-
// Assumes that startBlobAccumulator.finalChallenges have already been precomputed.
|
|
231
|
-
// Does not finalise challenge values (this is done in the final root rollup).
|
|
232
|
-
// TODO(MW): Integrate with BatchedBlob once old Blob classes removed
|
|
233
|
-
static async fromBlobs(startBlobAccumulator: BatchedBlobAccumulator, blobs: Blob[]): Promise<BlockBlobPublicInputs> {
|
|
234
|
-
const endBlobAccumulator = await startBlobAccumulator.accumulateBlobs(blobs);
|
|
235
|
-
return new BlockBlobPublicInputs(
|
|
236
|
-
startBlobAccumulator.toBlobAccumulatorPublicInputs(),
|
|
237
|
-
endBlobAccumulator.toBlobAccumulatorPublicInputs(),
|
|
238
|
-
startBlobAccumulator.finalBlobChallenges,
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
252
|
}
|
package/src/interface.ts
CHANGED
package/src/testing.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
|
4
4
|
|
|
5
5
|
import { Blob } from './blob.js';
|
|
6
6
|
import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
7
|
-
import { BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
|
|
7
|
+
import { BlobAccumulatorPublicInputs, BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
|
|
8
8
|
import { TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH } from './encoding.js';
|
|
9
9
|
import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
10
10
|
|
|
@@ -55,8 +55,8 @@ export function makeBatchedBlobAccumulator(seed = 1): BatchedBlobAccumulator {
|
|
|
55
55
|
export function makeBlockBlobPublicInputs(seed = 1): BlockBlobPublicInputs {
|
|
56
56
|
const startBlobAccumulator = makeBatchedBlobAccumulator(seed);
|
|
57
57
|
return new BlockBlobPublicInputs(
|
|
58
|
-
|
|
59
|
-
makeBatchedBlobAccumulator(seed + 1)
|
|
58
|
+
BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(startBlobAccumulator),
|
|
59
|
+
BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(makeBatchedBlobAccumulator(seed + 1)),
|
|
60
60
|
startBlobAccumulator.finalBlobChallenges,
|
|
61
61
|
);
|
|
62
62
|
}
|