@aztec/blob-lib 0.0.0-test.1 → 0.0.1-fake-ceab37513c
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 +31 -26
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +47 -53
- package/dest/blob_batching.d.ts +188 -0
- package/dest/blob_batching.d.ts.map +1 -0
- package/dest/blob_batching.js +299 -0
- package/dest/blob_batching_public_inputs.d.ts +71 -0
- package/dest/blob_batching_public_inputs.d.ts.map +1 -0
- package/dest/blob_batching_public_inputs.js +168 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -3
- package/dest/interface.d.ts +1 -2
- package/dest/interface.d.ts.map +1 -1
- package/dest/sponge_blob.d.ts +2 -4
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/testing.d.ts +6 -5
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +10 -9
- package/dest/types.d.ts +14 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +1 -0
- package/package.json +15 -12
- package/src/blob.ts +49 -66
- package/src/blob_batching.ts +363 -0
- package/src/blob_batching_public_inputs.ts +252 -0
- package/src/index.ts +3 -3
- package/src/interface.ts +1 -4
- package/src/testing.ts +21 -11
- package/src/trusted_setup_bit_reversed.json +4100 -0
- package/src/types.ts +16 -0
- package/dest/blob_public_inputs.d.ts +0 -50
- package/dest/blob_public_inputs.d.ts.map +0 -1
- package/dest/blob_public_inputs.js +0 -146
- package/src/blob_public_inputs.ts +0 -157
package/dest/blob.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
2
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
5
3
|
import cKzg from 'c-kzg';
|
|
6
4
|
import type { Blob as BlobBuffer } from 'c-kzg';
|
|
7
5
|
import type { BlobJson } from './interface.js';
|
|
8
6
|
export declare const VERSIONED_HASH_VERSION_KZG = 1;
|
|
7
|
+
/** Versioned blob hash for an empty blob */
|
|
8
|
+
export declare const EMPTY_BLOB_VERSIONED_HASH: Buffer<ArrayBuffer>;
|
|
9
9
|
/**
|
|
10
10
|
* A class to create, manage, and prove EVM blobs.
|
|
11
11
|
*/
|
|
@@ -14,27 +14,19 @@ export declare class Blob {
|
|
|
14
14
|
readonly data: BlobBuffer;
|
|
15
15
|
/** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */
|
|
16
16
|
readonly fieldsHash: Fr;
|
|
17
|
-
/** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y. */
|
|
17
|
+
/** 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
18
|
readonly challengeZ: Fr;
|
|
19
|
-
/** Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts. */
|
|
20
|
-
readonly evaluationY: Buffer;
|
|
21
19
|
/** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */
|
|
22
20
|
readonly commitment: Buffer;
|
|
23
|
-
/** KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes). */
|
|
24
|
-
readonly proof: Buffer;
|
|
25
21
|
constructor(
|
|
26
22
|
/** The blob to be broadcast on L1 in bytes form. */
|
|
27
23
|
data: BlobBuffer,
|
|
28
24
|
/** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */
|
|
29
25
|
fieldsHash: Fr,
|
|
30
|
-
/** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y. */
|
|
26
|
+
/** 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). */
|
|
31
27
|
challengeZ: Fr,
|
|
32
|
-
/** Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts. */
|
|
33
|
-
evaluationY: Buffer,
|
|
34
28
|
/** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */
|
|
35
|
-
commitment: Buffer
|
|
36
|
-
/** KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes). */
|
|
37
|
-
proof: Buffer);
|
|
29
|
+
commitment: Buffer);
|
|
38
30
|
/**
|
|
39
31
|
* The encoded version of the blob will determine the end of the blob based on the transaction encoding.
|
|
40
32
|
* This is required when the fieldsHash of a blob will contain trailing zeros.
|
|
@@ -77,7 +69,7 @@ export declare class Blob {
|
|
|
77
69
|
* @param index - optional - The index of the blob in the block.
|
|
78
70
|
* @returns The JSON representation of the blob.
|
|
79
71
|
*/
|
|
80
|
-
toJson(index
|
|
72
|
+
toJson(index: number): BlobJson;
|
|
81
73
|
/**
|
|
82
74
|
* Get the fields from the blob.
|
|
83
75
|
*
|
|
@@ -119,6 +111,19 @@ export declare class Blob {
|
|
|
119
111
|
commitmentToFields(): [Fr, Fr];
|
|
120
112
|
getEthVersionedBlobHash(): Buffer;
|
|
121
113
|
static getEthVersionedBlobHash(commitment: Buffer): Buffer;
|
|
114
|
+
/**
|
|
115
|
+
* Evaluate the blob at a given challenge and return the evaluation and KZG proof.
|
|
116
|
+
*
|
|
117
|
+
* @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.
|
|
118
|
+
*
|
|
119
|
+
* @returns -
|
|
120
|
+
* y: Buffer - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts
|
|
121
|
+
* proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
|
|
122
|
+
*/
|
|
123
|
+
evaluate(challengeZ?: Fr): {
|
|
124
|
+
y: Buffer<ArrayBuffer>;
|
|
125
|
+
proof: Buffer<ArrayBuffer>;
|
|
126
|
+
};
|
|
122
127
|
/**
|
|
123
128
|
* Get the buffer representation of the ENTIRE blob.
|
|
124
129
|
*
|
|
@@ -141,22 +146,22 @@ export declare class Blob {
|
|
|
141
146
|
*/
|
|
142
147
|
getSize(): number;
|
|
143
148
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* input[64:96] - y
|
|
149
|
-
* input[96:144] - commitment C
|
|
150
|
-
* input[144:192] - proof (a commitment to the quotient polynomial q(X))
|
|
151
|
-
*
|
|
152
|
-
* See https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile
|
|
149
|
+
* @param blobs - The blobs to emit
|
|
150
|
+
* @returns The blobs' compressed commitments in hex prefixed by the number of blobs
|
|
151
|
+
* @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs:
|
|
152
|
+
* One byte for the number blobs + 48 bytes per blob commitment
|
|
153
153
|
*/
|
|
154
|
-
|
|
155
|
-
static getEthBlobEvaluationInputs(blobs: Blob[]): `0x${string}`;
|
|
154
|
+
static getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${string}`;
|
|
156
155
|
static getViemKzgInstance(): {
|
|
157
156
|
blobToKzgCommitment: typeof cKzg.blobToKzgCommitment;
|
|
158
157
|
computeBlobKzgProof: typeof cKzg.computeBlobKzgProof;
|
|
158
|
+
computeCellsAndKzgProofs: typeof cKzg.computeCellsAndKzgProofs;
|
|
159
159
|
};
|
|
160
|
-
|
|
160
|
+
/**
|
|
161
|
+
* @param fields - Fields to broadcast in the blob(s)
|
|
162
|
+
* @returns As many blobs as we require to broadcast the given fields for a block
|
|
163
|
+
* @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.
|
|
164
|
+
*/
|
|
165
|
+
static getBlobsPerBlock(fields: Fr[]): Promise<Blob[]>;
|
|
161
166
|
}
|
|
162
167
|
//# 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":"
|
|
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,4CAA4C;AAC5C,eAAO,MAAM,yBAAyB,qBAGrC,CAAC;AAEF;;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;;;;;IAQzB;;;;OAIG;WACU,gBAAgB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;CAU7D"}
|
package/dest/blob.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import { poseidon2Hash, sha256 } from '@aztec/foundation/crypto';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
-
// Importing directly from 'c-kzg' does not work
|
|
4
|
+
// Importing directly from 'c-kzg' does not work:
|
|
5
5
|
import cKzg from 'c-kzg';
|
|
6
6
|
import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './encoding.js';
|
|
7
7
|
import { BlobDeserializationError } from './errors.js';
|
|
8
|
-
|
|
8
|
+
const { BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, blobToKzgCommitment, computeKzgProof, verifyKzgProof } = cKzg;
|
|
9
9
|
// The prefix to the EVM blobHash, defined here: https://eips.ethereum.org/EIPS/eip-4844#specification
|
|
10
10
|
export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
11
|
+
/** Versioned blob hash for an empty blob */ export const EMPTY_BLOB_VERSIONED_HASH = Buffer.from(`010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014`, 'hex');
|
|
11
12
|
/**
|
|
12
13
|
* A class to create, manage, and prove EVM blobs.
|
|
13
14
|
*/ export class Blob {
|
|
14
15
|
data;
|
|
15
16
|
fieldsHash;
|
|
16
17
|
challengeZ;
|
|
17
|
-
evaluationY;
|
|
18
18
|
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){
|
|
19
|
+
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
20
|
this.data = data;
|
|
22
21
|
this.fieldsHash = fieldsHash;
|
|
23
22
|
this.challengeZ = challengeZ;
|
|
24
|
-
this.evaluationY = evaluationY;
|
|
25
23
|
this.commitment = commitment;
|
|
26
|
-
this.proof = proof;
|
|
27
24
|
}
|
|
28
25
|
/**
|
|
29
26
|
* The encoded version of the blob will determine the end of the blob based on the transaction encoding.
|
|
@@ -41,7 +38,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
41
38
|
try {
|
|
42
39
|
const fields = deserializeEncodedBlobToFields(blob);
|
|
43
40
|
return Blob.fromFields(fields, multiBlobFieldsHash);
|
|
44
|
-
} catch
|
|
41
|
+
} catch {
|
|
45
42
|
throw new BlobDeserializationError(`Failed to create Blob from encoded blob buffer, this blob was likely not created by us`);
|
|
46
43
|
}
|
|
47
44
|
}
|
|
@@ -65,13 +62,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
65
62
|
fieldsHash,
|
|
66
63
|
...commitmentToFields(commitment)
|
|
67
64
|
]);
|
|
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);
|
|
65
|
+
return new Blob(data, fieldsHash, challengeZ, commitment);
|
|
75
66
|
}
|
|
76
67
|
/**
|
|
77
68
|
* Create a Blob from a JSON object.
|
|
@@ -103,11 +94,9 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
103
94
|
*/ toJson(index) {
|
|
104
95
|
return {
|
|
105
96
|
blob: `0x${Buffer.from(this.data).toString('hex')}`,
|
|
106
|
-
index,
|
|
97
|
+
index: index.toString(),
|
|
107
98
|
// 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')}`
|
|
99
|
+
kzg_commitment: `0x${this.commitment.toString('hex')}`
|
|
111
100
|
};
|
|
112
101
|
}
|
|
113
102
|
/**
|
|
@@ -130,7 +119,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
130
119
|
*/ toEncodedFields() {
|
|
131
120
|
try {
|
|
132
121
|
return deserializeEncodedBlobToFields(this.data);
|
|
133
|
-
} catch
|
|
122
|
+
} catch {
|
|
134
123
|
throw new BlobDeserializationError(`Failed to deserialize encoded blob fields, this blob was likely not created by us`);
|
|
135
124
|
}
|
|
136
125
|
}
|
|
@@ -143,7 +132,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
143
132
|
*/ static toEncodedFields(blobs) {
|
|
144
133
|
try {
|
|
145
134
|
return deserializeEncodedBlobToFields(Buffer.concat(blobs.map((b)=>b.data)));
|
|
146
|
-
} catch
|
|
135
|
+
} catch {
|
|
147
136
|
throw new BlobDeserializationError(`Failed to deserialize encoded blob fields, this blob was likely not created by us`);
|
|
148
137
|
}
|
|
149
138
|
}
|
|
@@ -173,13 +162,34 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
173
162
|
return hash;
|
|
174
163
|
}
|
|
175
164
|
/**
|
|
165
|
+
* Evaluate the blob at a given challenge and return the evaluation and KZG proof.
|
|
166
|
+
*
|
|
167
|
+
* @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.
|
|
168
|
+
*
|
|
169
|
+
* @returns -
|
|
170
|
+
* y: Buffer - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts
|
|
171
|
+
* proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
|
|
172
|
+
*/ evaluate(challengeZ) {
|
|
173
|
+
const z = challengeZ || this.challengeZ;
|
|
174
|
+
const res = computeKzgProof(this.data, z.toBuffer());
|
|
175
|
+
if (!verifyKzgProof(this.commitment, z.toBuffer(), res[1], res[0])) {
|
|
176
|
+
throw new Error(`KZG proof did not verify.`);
|
|
177
|
+
}
|
|
178
|
+
const proof = Buffer.from(res[0]);
|
|
179
|
+
const y = Buffer.from(res[1]);
|
|
180
|
+
return {
|
|
181
|
+
y,
|
|
182
|
+
proof
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
176
186
|
* Get the buffer representation of the ENTIRE blob.
|
|
177
187
|
*
|
|
178
188
|
* @dev WARNING: this buffer contains all metadata aswell as the data itself
|
|
179
189
|
*
|
|
180
190
|
* @returns The buffer representation of the blob.
|
|
181
191
|
*/ toBuffer() {
|
|
182
|
-
return Buffer.from(serializeToBuffer(this.data.length, this.data, this.fieldsHash, this.challengeZ, this.
|
|
192
|
+
return Buffer.from(serializeToBuffer(this.data.length, this.data, this.fieldsHash, this.challengeZ, this.commitment.length, this.commitment));
|
|
183
193
|
}
|
|
184
194
|
/**
|
|
185
195
|
* Create a Blob from a buffer.
|
|
@@ -190,7 +200,7 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
190
200
|
* @returns A Blob created from the buffer.
|
|
191
201
|
*/ static fromBuffer(buf) {
|
|
192
202
|
const reader = BufferReader.asReader(buf);
|
|
193
|
-
return new Blob(reader.readUint8Array(), reader.readObject(Fr), reader.readObject(Fr), reader.readBuffer()
|
|
203
|
+
return new Blob(reader.readUint8Array(), reader.readObject(Fr), reader.readObject(Fr), reader.readBuffer());
|
|
194
204
|
}
|
|
195
205
|
/**
|
|
196
206
|
* Get the size of the blob in bytes
|
|
@@ -198,38 +208,19 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
198
208
|
return this.data.length;
|
|
199
209
|
}
|
|
200
210
|
/**
|
|
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) {
|
|
211
|
+
* @param blobs - The blobs to emit
|
|
212
|
+
* @returns The blobs' compressed commitments in hex prefixed by the number of blobs
|
|
213
|
+
* @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs:
|
|
214
|
+
* One byte for the number blobs + 48 bytes per blob commitment
|
|
215
|
+
*/ static getPrefixedEthBlobCommitments(blobs) {
|
|
221
216
|
let buf = Buffer.alloc(0);
|
|
222
217
|
blobs.forEach((blob)=>{
|
|
223
218
|
buf = Buffer.concat([
|
|
224
219
|
buf,
|
|
225
|
-
blob.
|
|
226
|
-
blob.challengeZ.toBuffer(),
|
|
227
|
-
blob.evaluationY,
|
|
228
|
-
blob.commitment,
|
|
229
|
-
blob.proof
|
|
220
|
+
blob.commitment
|
|
230
221
|
]);
|
|
231
222
|
});
|
|
232
|
-
//
|
|
223
|
+
// We prefix the number of blobs:
|
|
233
224
|
const lenBuf = Buffer.alloc(1);
|
|
234
225
|
lenBuf.writeUint8(blobs.length);
|
|
235
226
|
buf = Buffer.concat([
|
|
@@ -241,12 +232,15 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
|
241
232
|
static getViemKzgInstance() {
|
|
242
233
|
return {
|
|
243
234
|
blobToKzgCommitment: cKzg.blobToKzgCommitment,
|
|
244
|
-
computeBlobKzgProof: cKzg.computeBlobKzgProof
|
|
235
|
+
computeBlobKzgProof: cKzg.computeBlobKzgProof,
|
|
236
|
+
computeCellsAndKzgProofs: cKzg.computeCellsAndKzgProofs
|
|
245
237
|
};
|
|
246
238
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
239
|
+
/**
|
|
240
|
+
* @param fields - Fields to broadcast in the blob(s)
|
|
241
|
+
* @returns As many blobs as we require to broadcast the given fields for a block
|
|
242
|
+
* @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.
|
|
243
|
+
*/ static async getBlobsPerBlock(fields) {
|
|
250
244
|
const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
|
|
251
245
|
const multiBlobFieldsHash = await poseidon2Hash(fields);
|
|
252
246
|
const res = [];
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { Blob } from './blob.js';
|
|
4
|
+
/**
|
|
5
|
+
* A class to create, manage, and prove batched EVM blobs.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BatchedBlob {
|
|
8
|
+
/** Hash of Cs (to link to L1 blob hashes). */
|
|
9
|
+
readonly blobCommitmentsHash: Fr;
|
|
10
|
+
/** Challenge point z such that p_i(z) = y_i. */
|
|
11
|
+
readonly z: Fr;
|
|
12
|
+
/** Evaluation y, linear combination of all evaluations y_i = p_i(z) with gamma. */
|
|
13
|
+
readonly y: BLS12Fr;
|
|
14
|
+
/** Commitment C, linear combination of all commitments C_i = [p_i] with gamma. */
|
|
15
|
+
readonly commitment: BLS12Point;
|
|
16
|
+
/** KZG opening 'proof' Q (commitment to the quotient poly.), linear combination of all blob kzg 'proofs' Q_i with gamma. */
|
|
17
|
+
readonly q: BLS12Point;
|
|
18
|
+
constructor(
|
|
19
|
+
/** Hash of Cs (to link to L1 blob hashes). */
|
|
20
|
+
blobCommitmentsHash: Fr,
|
|
21
|
+
/** Challenge point z such that p_i(z) = y_i. */
|
|
22
|
+
z: Fr,
|
|
23
|
+
/** Evaluation y, linear combination of all evaluations y_i = p_i(z) with gamma. */
|
|
24
|
+
y: BLS12Fr,
|
|
25
|
+
/** Commitment C, linear combination of all commitments C_i = [p_i] with gamma. */
|
|
26
|
+
commitment: BLS12Point,
|
|
27
|
+
/** KZG opening 'proof' Q (commitment to the quotient poly.), linear combination of all blob kzg 'proofs' Q_i with gamma. */
|
|
28
|
+
q: BLS12Point);
|
|
29
|
+
/**
|
|
30
|
+
* Get the final batched opening proof from multiple blobs.
|
|
31
|
+
* @dev MUST input all blobs to be broadcast. Does not work in multiple calls because z and gamma are calculated
|
|
32
|
+
* beforehand from ALL blobs.
|
|
33
|
+
*
|
|
34
|
+
* @returns A batched blob.
|
|
35
|
+
*/
|
|
36
|
+
static batch(blobs: Blob[]): Promise<BatchedBlob>;
|
|
37
|
+
/**
|
|
38
|
+
* Returns an empty BatchedBlobAccumulator with precomputed challenges from all blobs in the epoch.
|
|
39
|
+
* @dev MUST input all blobs to be broadcast. Does not work in multiple calls because z and gamma are calculated
|
|
40
|
+
* beforehand from ALL blobs.
|
|
41
|
+
*/
|
|
42
|
+
static newAccumulator(blobs: Blob[]): Promise<BatchedBlobAccumulator>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the final challenges based on all blobs and their elements to perform a multi opening proof.
|
|
45
|
+
* Used in BatchedBlobAccumulator as 'finalZ' and finalGamma':
|
|
46
|
+
* - z = H(...H(H(z_0, z_1) z_2)..z_n)
|
|
47
|
+
* - where z_i = H(H(fields of blob_i), C_i) = Blob.challengeZ,
|
|
48
|
+
* - used such that p_i(z) = y_i = Blob.evaluationY for all n blob polynomials p_i().
|
|
49
|
+
* - gamma = H(H(...H(H(y_0, y_1) y_2)..y_n), z)
|
|
50
|
+
* - 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.
|
|
51
|
+
* @returns Challenges z and gamma.
|
|
52
|
+
*/
|
|
53
|
+
static precomputeBatchedBlobChallenges(blobs: Blob[]): Promise<FinalBlobBatchingChallenges>;
|
|
54
|
+
static precomputeEmptyBatchedBlobChallenges(): Promise<FinalBlobBatchingChallenges>;
|
|
55
|
+
getEthVersionedBlobHash(): Buffer;
|
|
56
|
+
static getEthVersionedBlobHash(commitment: Buffer): Buffer;
|
|
57
|
+
/**
|
|
58
|
+
* Returns a proof of opening of the blobs to verify on L1 using the point evaluation precompile:
|
|
59
|
+
*
|
|
60
|
+
* input[:32] - versioned_hash
|
|
61
|
+
* input[32:64] - z
|
|
62
|
+
* input[64:96] - y
|
|
63
|
+
* input[96:144] - commitment C
|
|
64
|
+
* input[144:192] - commitment Q (a 'proof' committing to the quotient polynomial q(X))
|
|
65
|
+
*
|
|
66
|
+
* See https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile
|
|
67
|
+
*/
|
|
68
|
+
getEthBlobEvaluationInputs(): `0x${string}`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Final values z and gamma are injected into each block root circuit. We ensure they are correct by:
|
|
72
|
+
* - Checking equality in each block merge circuit and propagating up
|
|
73
|
+
* - Checking final z_acc == z in root circuit
|
|
74
|
+
* - Checking final gamma_acc == gamma in root circuit
|
|
75
|
+
*
|
|
76
|
+
* - z = H(...H(H(z_0, z_1) z_2)..z_n)
|
|
77
|
+
* - where z_i = H(H(fields of blob_i), C_i),
|
|
78
|
+
* - used such that p_i(z) = y_i = Blob.evaluationY for all n blob polynomials p_i().
|
|
79
|
+
* - gamma = H(H(...H(H(y_0, y_1) y_2)..y_n), z)
|
|
80
|
+
* - used such that y = sum_i { gamma^i * y_i }, and C = sum_i { gamma^i * C_i }
|
|
81
|
+
* for all blob evaluations y_i (see above) and commitments C_i.
|
|
82
|
+
*
|
|
83
|
+
* Iteratively calculated by BlobAccumulatorPublicInputs.accumulate() in nr. See also precomputeBatchedBlobChallenges() above.
|
|
84
|
+
*/
|
|
85
|
+
export declare class FinalBlobBatchingChallenges {
|
|
86
|
+
readonly z: Fr;
|
|
87
|
+
readonly gamma: BLS12Fr;
|
|
88
|
+
constructor(z: Fr, gamma: BLS12Fr);
|
|
89
|
+
equals(other: FinalBlobBatchingChallenges): boolean;
|
|
90
|
+
static empty(): FinalBlobBatchingChallenges;
|
|
91
|
+
static fromBuffer(buffer: Buffer | BufferReader): FinalBlobBatchingChallenges;
|
|
92
|
+
toBuffer(): Buffer<ArrayBufferLike>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* See noir-projects/noir-protocol-circuits/crates/blob/src/blob_batching_public_inputs.nr -> BlobAccumulatorPublicInputs
|
|
96
|
+
*/
|
|
97
|
+
export declare class BatchedBlobAccumulator {
|
|
98
|
+
/** Hash of Cs (to link to L1 blob hashes). */
|
|
99
|
+
readonly blobCommitmentsHashAcc: Fr;
|
|
100
|
+
/** Challenge point z_acc. Final value used such that p_i(z) = y_i. */
|
|
101
|
+
readonly zAcc: Fr;
|
|
102
|
+
/** Evaluation y_acc. Final value is is linear combination of all evaluations y_i = p_i(z) with gamma. */
|
|
103
|
+
readonly yAcc: BLS12Fr;
|
|
104
|
+
/** Commitment c_acc. Final value is linear combination of all commitments C_i = [p_i] with gamma. */
|
|
105
|
+
readonly cAcc: BLS12Point;
|
|
106
|
+
/** KZG opening q_acc. Final value is linear combination of all blob kzg 'proofs' Q_i with gamma. */
|
|
107
|
+
readonly qAcc: BLS12Point;
|
|
108
|
+
/**
|
|
109
|
+
* Challenge point gamma_acc for multi opening. Used with y, C, and kzg 'proof' Q above.
|
|
110
|
+
* TODO(#13608): We calculate this by hashing natively in the circuit (hence Fr representation), but it's actually used
|
|
111
|
+
* as a BLS12Fr field elt. Is this safe? Is there a skew?
|
|
112
|
+
*/
|
|
113
|
+
readonly gammaAcc: Fr;
|
|
114
|
+
/** Simply gamma^(i + 1) at blob i. Used for calculating the i'th element of the above linear comb.s */
|
|
115
|
+
readonly gammaPow: BLS12Fr;
|
|
116
|
+
/** Final challenge values used in evaluation. Optimistically input and checked in the final acc. */
|
|
117
|
+
readonly finalBlobChallenges: FinalBlobBatchingChallenges;
|
|
118
|
+
constructor(
|
|
119
|
+
/** Hash of Cs (to link to L1 blob hashes). */
|
|
120
|
+
blobCommitmentsHashAcc: Fr,
|
|
121
|
+
/** Challenge point z_acc. Final value used such that p_i(z) = y_i. */
|
|
122
|
+
zAcc: Fr,
|
|
123
|
+
/** Evaluation y_acc. Final value is is linear combination of all evaluations y_i = p_i(z) with gamma. */
|
|
124
|
+
yAcc: BLS12Fr,
|
|
125
|
+
/** Commitment c_acc. Final value is linear combination of all commitments C_i = [p_i] with gamma. */
|
|
126
|
+
cAcc: BLS12Point,
|
|
127
|
+
/** KZG opening q_acc. Final value is linear combination of all blob kzg 'proofs' Q_i with gamma. */
|
|
128
|
+
qAcc: BLS12Point,
|
|
129
|
+
/**
|
|
130
|
+
* Challenge point gamma_acc for multi opening. Used with y, C, and kzg 'proof' Q above.
|
|
131
|
+
* TODO(#13608): We calculate this by hashing natively in the circuit (hence Fr representation), but it's actually used
|
|
132
|
+
* as a BLS12Fr field elt. Is this safe? Is there a skew?
|
|
133
|
+
*/
|
|
134
|
+
gammaAcc: Fr,
|
|
135
|
+
/** Simply gamma^(i + 1) at blob i. Used for calculating the i'th element of the above linear comb.s */
|
|
136
|
+
gammaPow: BLS12Fr,
|
|
137
|
+
/** Final challenge values used in evaluation. Optimistically input and checked in the final acc. */
|
|
138
|
+
finalBlobChallenges: FinalBlobBatchingChallenges);
|
|
139
|
+
/**
|
|
140
|
+
* Init the first accumulation state of the epoch.
|
|
141
|
+
* We assume the input blob has not been evaluated at z.
|
|
142
|
+
*
|
|
143
|
+
* First state of the accumulator:
|
|
144
|
+
* - v_acc := sha256(C_0)
|
|
145
|
+
* - z_acc := z_0
|
|
146
|
+
* - y_acc := gamma^0 * y_0 = y_0
|
|
147
|
+
* - c_acc := gamma^0 * c_0 = c_0
|
|
148
|
+
* - gamma_acc := poseidon2(y_0.limbs)
|
|
149
|
+
* - gamma^(i + 1) = gamma^1 = gamma // denoted gamma_pow_acc
|
|
150
|
+
*
|
|
151
|
+
* @returns An initial blob accumulator.
|
|
152
|
+
*/
|
|
153
|
+
static initialize(blob: Blob, finalBlobChallenges: FinalBlobBatchingChallenges): Promise<BatchedBlobAccumulator>;
|
|
154
|
+
/**
|
|
155
|
+
* Create the empty accumulation state of the epoch.
|
|
156
|
+
* @returns An empty blob accumulator with challenges.
|
|
157
|
+
*/
|
|
158
|
+
static newWithChallenges(finalBlobChallenges: FinalBlobBatchingChallenges): BatchedBlobAccumulator;
|
|
159
|
+
/**
|
|
160
|
+
* Given blob i, accumulate all state.
|
|
161
|
+
* We assume the input blob has not been evaluated at z.
|
|
162
|
+
* @returns An updated blob accumulator.
|
|
163
|
+
*/
|
|
164
|
+
accumulate(blob: Blob): Promise<BatchedBlobAccumulator>;
|
|
165
|
+
/**
|
|
166
|
+
* Given blobs, accumulate all state.
|
|
167
|
+
* We assume the input blobs have not been evaluated at z.
|
|
168
|
+
* @returns An updated blob accumulator.
|
|
169
|
+
*/
|
|
170
|
+
accumulateBlobs(blobs: Blob[]): Promise<BatchedBlobAccumulator>;
|
|
171
|
+
/**
|
|
172
|
+
* Finalize accumulation state of the epoch.
|
|
173
|
+
* We assume ALL blobs in the epoch have been accumulated.
|
|
174
|
+
*
|
|
175
|
+
* Final accumulated values:
|
|
176
|
+
* - v := v_acc (hash of all commitments (C_i s) to be checked on L1)
|
|
177
|
+
* - z := z_acc (final challenge, at which all blobs are evaluated)
|
|
178
|
+
* - y := y_acc (final opening to be checked on L1)
|
|
179
|
+
* - c := c_acc (final commitment to be checked on L1)
|
|
180
|
+
* - gamma := poseidon2(gamma_acc, z) (challenge for linear combination of y and C, above)
|
|
181
|
+
*
|
|
182
|
+
* @returns A batched blob.
|
|
183
|
+
*/
|
|
184
|
+
finalize(): Promise<BatchedBlob>;
|
|
185
|
+
isEmptyState(): boolean;
|
|
186
|
+
clone(): BatchedBlobAccumulator;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=blob_batching.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob_batching.d.ts","sourceRoot":"","sources":["../src/blob_batching.ts"],"names":[],"mappings":"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"}
|