@aztec/blob-lib 0.0.0-test.1 → 0.0.1-fake-c83136db25
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 +58 -99
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +83 -183
- package/dest/blob_batching.d.ts +155 -0
- package/dest/blob_batching.d.ts.map +1 -0
- package/dest/blob_batching.js +260 -0
- package/dest/blob_utils.d.ts +30 -0
- package/dest/blob_utils.d.ts.map +1 -0
- package/dest/blob_utils.js +60 -0
- package/dest/circuit_types/blob_accumulator.d.ts +21 -0
- package/dest/circuit_types/blob_accumulator.d.ts.map +1 -0
- package/dest/circuit_types/blob_accumulator.js +58 -0
- package/dest/circuit_types/final_blob_accumulator.d.ts +22 -0
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -0
- package/dest/circuit_types/final_blob_accumulator.js +63 -0
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +15 -0
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -0
- package/dest/circuit_types/final_blob_batching_challenges.js +25 -0
- package/dest/circuit_types/index.d.ts +4 -0
- package/dest/circuit_types/index.d.ts.map +1 -0
- package/dest/circuit_types/index.js +4 -0
- package/dest/deserialize.d.ts +14 -0
- package/dest/deserialize.d.ts.map +1 -0
- package/dest/deserialize.js +33 -0
- package/dest/encoding.d.ts +22 -62
- package/dest/encoding.d.ts.map +1 -1
- package/dest/encoding.js +114 -104
- package/dest/hash.d.ts +35 -0
- package/dest/hash.d.ts.map +1 -0
- package/dest/hash.js +69 -0
- package/dest/index.d.ts +6 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +6 -15
- package/dest/interface.d.ts +1 -2
- package/dest/interface.d.ts.map +1 -1
- package/dest/kzg_context.d.ts +4 -0
- package/dest/kzg_context.d.ts.map +1 -0
- package/dest/kzg_context.js +5 -0
- package/dest/sponge_blob.d.ts +15 -13
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +28 -17
- package/dest/testing.d.ts +12 -16
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +60 -46
- package/dest/types.d.ts +16 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +3 -0
- package/package.json +16 -12
- package/src/blob.ts +82 -221
- package/src/blob_batching.ts +335 -0
- package/src/blob_utils.ts +71 -0
- package/src/circuit_types/blob_accumulator.ts +84 -0
- package/src/circuit_types/final_blob_accumulator.ts +75 -0
- package/src/circuit_types/final_blob_batching_challenges.ts +29 -0
- package/src/circuit_types/index.ts +4 -0
- package/src/deserialize.ts +38 -0
- package/src/encoding.ts +136 -120
- package/src/hash.ts +77 -0
- package/src/index.ts +6 -19
- package/src/interface.ts +1 -4
- package/src/kzg_context.ts +5 -0
- package/src/sponge_blob.ts +24 -14
- package/src/testing.ts +68 -43
- 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/src/blob.ts
CHANGED
|
@@ -1,92 +1,80 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
1
|
+
import { FIELDS_PER_BLOB } from '@aztec/constants';
|
|
2
|
+
import { BLS12Fr, Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
import cKzg from 'c-kzg';
|
|
7
|
-
import type { Blob as BlobBuffer } from 'c-kzg';
|
|
8
|
-
|
|
9
|
-
import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './encoding.js';
|
|
10
|
-
import { BlobDeserializationError } from './errors.js';
|
|
5
|
+
import { computeBlobCommitment, computeChallengeZ, computeEthVersionedBlobHash } from './hash.js';
|
|
11
6
|
import type { BlobJson } from './interface.js';
|
|
7
|
+
import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, kzg } from './kzg_context.js';
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
const { BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, blobToKzgCommitment, computeKzgProof, verifyKzgProof } = cKzg;
|
|
15
|
-
|
|
16
|
-
// The prefix to the EVM blobHash, defined here: https://eips.ethereum.org/EIPS/eip-4844#specification
|
|
17
|
-
export const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
9
|
+
export { FIELDS_PER_BLOB };
|
|
18
10
|
|
|
19
11
|
/**
|
|
20
12
|
* A class to create, manage, and prove EVM blobs.
|
|
13
|
+
*
|
|
14
|
+
* @dev Note: All methods in this class do not check the encoding of the given data. It's the responsibility of other
|
|
15
|
+
* components to ensure that the blob data (which might spread across multiple blobs) was created following the protocol
|
|
16
|
+
* and is correctly encoded.
|
|
21
17
|
*/
|
|
22
18
|
export class Blob {
|
|
23
19
|
constructor(
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
public readonly
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
public readonly evaluationY: Buffer,
|
|
32
|
-
/** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */
|
|
20
|
+
/**
|
|
21
|
+
* The data to be broadcast on L1 in bytes form.
|
|
22
|
+
*/
|
|
23
|
+
public readonly data: Uint8Array,
|
|
24
|
+
/**
|
|
25
|
+
* Commitment to the blob data. Used in compressed BLS12 point format (48 bytes).
|
|
26
|
+
*/
|
|
33
27
|
public readonly commitment: Buffer,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
) {
|
|
29
|
+
if (data.length !== BYTES_PER_BLOB) {
|
|
30
|
+
throw new Error(`Blob data must be ${BYTES_PER_BLOB} bytes. Got ${data.length}.`);
|
|
31
|
+
}
|
|
32
|
+
if (commitment.length !== BYTES_PER_COMMITMENT) {
|
|
33
|
+
throw new Error(`Blob commitment must be ${BYTES_PER_COMMITMENT} bytes. Got ${commitment.length}.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
37
36
|
|
|
38
37
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* See `./encoding.ts` for more details.
|
|
43
|
-
*
|
|
44
|
-
* This method is used to create a Blob from a buffer.
|
|
45
|
-
* @param blob - The buffer to create the Blob from.
|
|
46
|
-
* @param multiBlobFieldsHash - The fields hash to use for the Blob.
|
|
38
|
+
* Create a Blob from a buffer.
|
|
39
|
+
* @param data - The buffer of the Blob.
|
|
47
40
|
* @returns A Blob created from the buffer.
|
|
48
41
|
*
|
|
49
|
-
* @throws If
|
|
42
|
+
* @throws If data does not match the expected length (BYTES_PER_BLOB).
|
|
50
43
|
*/
|
|
51
|
-
static
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return Blob.fromFields(fields, multiBlobFieldsHash);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
throw new BlobDeserializationError(
|
|
57
|
-
`Failed to create Blob from encoded blob buffer, this blob was likely not created by us`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
44
|
+
static fromBlobBuffer(data: Uint8Array): Blob {
|
|
45
|
+
const commitment = computeBlobCommitment(data);
|
|
46
|
+
return new Blob(data, commitment);
|
|
60
47
|
}
|
|
61
48
|
|
|
62
49
|
/**
|
|
63
50
|
* Create a Blob from an array of fields.
|
|
64
51
|
*
|
|
52
|
+
* @dev This method pads 0s to the data, extending it to the size of a full blob.
|
|
53
|
+
*
|
|
65
54
|
* @param fields - The array of fields to create the Blob from.
|
|
66
|
-
* @param multiBlobFieldsHash - The fields hash to use for the Blob.
|
|
67
55
|
* @returns A Blob created from the array of fields.
|
|
68
56
|
*/
|
|
69
|
-
static
|
|
70
|
-
if (fields.length >
|
|
71
|
-
throw new Error(
|
|
72
|
-
`Attempted to overfill blob with ${fields.length} elements. The maximum is ${FIELD_ELEMENTS_PER_BLOB}`,
|
|
73
|
-
);
|
|
57
|
+
static fromFields(fields: Fr[]): Blob {
|
|
58
|
+
if (fields.length > FIELDS_PER_BLOB) {
|
|
59
|
+
throw new Error(`Attempted to overfill blob with ${fields.length} fields. The maximum is ${FIELDS_PER_BLOB}.`);
|
|
74
60
|
}
|
|
75
61
|
|
|
76
62
|
const data = Buffer.concat([serializeToBuffer(fields)], BYTES_PER_BLOB);
|
|
63
|
+
const commitment = computeBlobCommitment(data);
|
|
64
|
+
return new Blob(data, commitment);
|
|
65
|
+
}
|
|
77
66
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
return new Blob(data, fieldsHash, challengeZ, evaluationY, commitment, proof);
|
|
67
|
+
/**
|
|
68
|
+
* Get the fields from the blob data.
|
|
69
|
+
*
|
|
70
|
+
* @dev WARNING: this method returns all fields
|
|
71
|
+
*
|
|
72
|
+
* @returns The fields from the blob.
|
|
73
|
+
*/
|
|
74
|
+
toFields(): Fr[] {
|
|
75
|
+
const reader = BufferReader.asReader(this.data);
|
|
76
|
+
const numTotalFields = this.data.length / Fr.SIZE_IN_BYTES;
|
|
77
|
+
return reader.readArray(numTotalFields, Fr);
|
|
90
78
|
}
|
|
91
79
|
|
|
92
80
|
/**
|
|
@@ -96,162 +84,90 @@ export class Blob {
|
|
|
96
84
|
* the beacon chain via `getBlobSidecars`
|
|
97
85
|
* https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getBlobSidecars
|
|
98
86
|
*
|
|
99
|
-
* @dev WARNING: by default json deals with encoded buffers
|
|
100
|
-
*
|
|
101
87
|
* @param json - The JSON object to create the Blob from.
|
|
102
88
|
* @returns A Blob created from the JSON object.
|
|
103
89
|
*/
|
|
104
|
-
static
|
|
90
|
+
static fromJson(json: BlobJson): Blob {
|
|
105
91
|
const blobBuffer = Buffer.from(json.blob.slice(2), 'hex');
|
|
106
|
-
|
|
107
|
-
const blob = await Blob.fromEncodedBlobBuffer(blobBuffer);
|
|
92
|
+
const blob = Blob.fromBlobBuffer(blobBuffer);
|
|
108
93
|
|
|
109
94
|
if (blob.commitment.toString('hex') !== json.kzg_commitment.slice(2)) {
|
|
110
95
|
throw new Error('KZG commitment does not match');
|
|
111
96
|
}
|
|
112
97
|
|
|
113
|
-
// We do not check the proof, as it will be different if the challenge is shared
|
|
114
|
-
// across multiple blobs
|
|
115
|
-
|
|
116
98
|
return blob;
|
|
117
99
|
}
|
|
118
100
|
|
|
119
101
|
/**
|
|
120
102
|
* Get the JSON representation of the blob.
|
|
121
103
|
*
|
|
122
|
-
* @dev WARNING: by default json deals with encoded buffers
|
|
123
104
|
* @param index - optional - The index of the blob in the block.
|
|
124
105
|
* @returns The JSON representation of the blob.
|
|
125
106
|
*/
|
|
126
|
-
toJson(index
|
|
107
|
+
toJson(index: number): BlobJson {
|
|
127
108
|
return {
|
|
128
109
|
blob: `0x${Buffer.from(this.data).toString('hex')}`,
|
|
129
|
-
index,
|
|
110
|
+
index: index.toString(),
|
|
130
111
|
// eslint-disable-next-line camelcase
|
|
131
112
|
kzg_commitment: `0x${this.commitment.toString('hex')}`,
|
|
132
|
-
// eslint-disable-next-line camelcase
|
|
133
|
-
kzg_proof: `0x${this.proof.toString('hex')}`,
|
|
134
113
|
};
|
|
135
114
|
}
|
|
136
115
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*
|
|
140
|
-
* @dev WARNING: this method does not take into account trailing zeros
|
|
141
|
-
*
|
|
142
|
-
* @returns The fields from the blob.
|
|
143
|
-
*/
|
|
144
|
-
toFields(): Fr[] {
|
|
145
|
-
return extractBlobFieldsFromBuffer(this.data);
|
|
116
|
+
getEthVersionedBlobHash(): Buffer {
|
|
117
|
+
return computeEthVersionedBlobHash(this.commitment);
|
|
146
118
|
}
|
|
147
119
|
|
|
148
120
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* @dev This method takes into account trailing zeros
|
|
152
|
-
*
|
|
153
|
-
* @returns The encoded fields from the blob.
|
|
154
|
-
*
|
|
155
|
-
* @throws If unable to deserialize the blob.
|
|
121
|
+
* Challenge point z (= H(H(tx_effects), kzgCommitment)).
|
|
122
|
+
* Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts).
|
|
156
123
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return deserializeEncodedBlobToFields(this.data);
|
|
160
|
-
} catch (err) {
|
|
161
|
-
throw new BlobDeserializationError(
|
|
162
|
-
`Failed to deserialize encoded blob fields, this blob was likely not created by us`,
|
|
163
|
-
);
|
|
164
|
-
}
|
|
124
|
+
async computeChallengeZ(blobFieldsHash: Fr): Promise<Fr> {
|
|
125
|
+
return await computeChallengeZ(blobFieldsHash, this.commitment);
|
|
165
126
|
}
|
|
166
127
|
|
|
167
128
|
/**
|
|
168
|
-
*
|
|
129
|
+
* Evaluate the blob at a given challenge and return the evaluation and KZG proof.
|
|
169
130
|
*
|
|
170
|
-
* @
|
|
131
|
+
* @param challengeZ - The challenge z at which to evaluate the blob.
|
|
132
|
+
* @param verifyProof - Whether to verify the KZG proof.
|
|
171
133
|
*
|
|
172
|
-
* @returns
|
|
134
|
+
* @returns
|
|
135
|
+
* y: BLS12Fr - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts.
|
|
136
|
+
* proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
|
|
173
137
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
throw new BlobDeserializationError(
|
|
179
|
-
`Failed to deserialize encoded blob fields, this blob was likely not created by us`,
|
|
180
|
-
);
|
|
138
|
+
evaluate(challengeZ: Fr, verifyProof = false) {
|
|
139
|
+
const res = kzg.computeKzgProof(this.data, challengeZ.toBuffer());
|
|
140
|
+
if (verifyProof && !kzg.verifyKzgProof(this.commitment, challengeZ.toBuffer(), res[1], res[0])) {
|
|
141
|
+
throw new Error(`KZG proof did not verify.`);
|
|
181
142
|
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Get the commitment fields from the blob.
|
|
186
|
-
*
|
|
187
|
-
* The 48-byte commitment is encoded into two field elements:
|
|
188
|
-
* +------------------+------------------+
|
|
189
|
-
* | Field Element 1 | Field Element 2 |
|
|
190
|
-
* | [bytes 0-31] | [bytes 32-47] |
|
|
191
|
-
* +------------------+------------------+
|
|
192
|
-
* | 32 bytes | 16 bytes |
|
|
193
|
-
* +------------------+------------------+
|
|
194
|
-
* @returns The commitment fields from the blob.
|
|
195
|
-
*/
|
|
196
|
-
commitmentToFields(): [Fr, Fr] {
|
|
197
|
-
return commitmentToFields(this.commitment);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
|
|
201
|
-
getEthVersionedBlobHash(): Buffer {
|
|
202
|
-
const hash = sha256(this.commitment);
|
|
203
|
-
hash[0] = VERSIONED_HASH_VERSION_KZG;
|
|
204
|
-
return hash;
|
|
205
|
-
}
|
|
206
143
|
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
return hash;
|
|
144
|
+
const proof = Buffer.from(res[0]);
|
|
145
|
+
const y = BLS12Fr.fromBuffer(Buffer.from(res[1]));
|
|
146
|
+
return { y, proof };
|
|
211
147
|
}
|
|
212
148
|
|
|
213
149
|
/**
|
|
214
150
|
* Get the buffer representation of the ENTIRE blob.
|
|
215
151
|
*
|
|
216
|
-
* @dev WARNING: this buffer contains all metadata
|
|
152
|
+
* @dev WARNING: this buffer contains all metadata as well as the data itself.
|
|
217
153
|
*
|
|
218
154
|
* @returns The buffer representation of the blob.
|
|
219
155
|
*/
|
|
220
156
|
toBuffer(): Buffer {
|
|
221
|
-
return Buffer.from(
|
|
222
|
-
serializeToBuffer(
|
|
223
|
-
this.data.length,
|
|
224
|
-
this.data,
|
|
225
|
-
this.fieldsHash,
|
|
226
|
-
this.challengeZ,
|
|
227
|
-
this.evaluationY.length,
|
|
228
|
-
this.evaluationY,
|
|
229
|
-
this.commitment.length,
|
|
230
|
-
this.commitment,
|
|
231
|
-
this.proof.length,
|
|
232
|
-
this.proof,
|
|
233
|
-
),
|
|
234
|
-
);
|
|
157
|
+
return Buffer.from(serializeToBuffer(this.data.length, this.data, this.commitment.length, this.commitment));
|
|
235
158
|
}
|
|
236
159
|
|
|
237
160
|
/**
|
|
238
161
|
* Create a Blob from a buffer.
|
|
239
162
|
*
|
|
240
|
-
* @dev WARNING: this method contains all metadata
|
|
163
|
+
* @dev WARNING: this method contains all metadata as well as the data itself.
|
|
241
164
|
*
|
|
242
165
|
* @param buf - The buffer to create the Blob from.
|
|
243
166
|
* @returns A Blob created from the buffer.
|
|
244
167
|
*/
|
|
245
168
|
static fromBuffer(buf: Buffer | BufferReader): Blob {
|
|
246
169
|
const reader = BufferReader.asReader(buf);
|
|
247
|
-
return new Blob(
|
|
248
|
-
reader.readUint8Array(),
|
|
249
|
-
reader.readObject(Fr),
|
|
250
|
-
reader.readObject(Fr),
|
|
251
|
-
reader.readBuffer(),
|
|
252
|
-
reader.readBuffer(),
|
|
253
|
-
reader.readBuffer(),
|
|
254
|
-
);
|
|
170
|
+
return new Blob(reader.readUint8Array(), reader.readBuffer());
|
|
255
171
|
}
|
|
256
172
|
|
|
257
173
|
/**
|
|
@@ -261,69 +177,14 @@ export class Blob {
|
|
|
261
177
|
return this.data.length;
|
|
262
178
|
}
|
|
263
179
|
|
|
264
|
-
/**
|
|
265
|
-
* Returns a proof of opening of the blob to verify on L1 using the point evaluation precompile:
|
|
266
|
-
*
|
|
267
|
-
* input[:32] - versioned_hash
|
|
268
|
-
* input[32:64] - z
|
|
269
|
-
* input[64:96] - y
|
|
270
|
-
* input[96:144] - commitment C
|
|
271
|
-
* input[144:192] - proof (a commitment to the quotient polynomial q(X))
|
|
272
|
-
*
|
|
273
|
-
* See https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile
|
|
274
|
-
*/
|
|
275
|
-
getEthBlobEvaluationInputs(): `0x${string}` {
|
|
276
|
-
const buf = Buffer.concat([
|
|
277
|
-
this.getEthVersionedBlobHash(),
|
|
278
|
-
this.challengeZ.toBuffer(),
|
|
279
|
-
this.evaluationY,
|
|
280
|
-
this.commitment,
|
|
281
|
-
this.proof,
|
|
282
|
-
]);
|
|
283
|
-
return `0x${buf.toString('hex')}`;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
static getEthBlobEvaluationInputs(blobs: Blob[]): `0x${string}` {
|
|
287
|
-
let buf = Buffer.alloc(0);
|
|
288
|
-
blobs.forEach(blob => {
|
|
289
|
-
buf = Buffer.concat([
|
|
290
|
-
buf,
|
|
291
|
-
blob.getEthVersionedBlobHash(),
|
|
292
|
-
blob.challengeZ.toBuffer(),
|
|
293
|
-
blob.evaluationY,
|
|
294
|
-
blob.commitment,
|
|
295
|
-
blob.proof,
|
|
296
|
-
]);
|
|
297
|
-
});
|
|
298
|
-
// For multiple blobs, we prefix the number of blobs:
|
|
299
|
-
const lenBuf = Buffer.alloc(1);
|
|
300
|
-
lenBuf.writeUint8(blobs.length);
|
|
301
|
-
buf = Buffer.concat([lenBuf, buf]);
|
|
302
|
-
return `0x${buf.toString('hex')}`;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
180
|
static getViemKzgInstance() {
|
|
306
181
|
return {
|
|
307
|
-
blobToKzgCommitment:
|
|
308
|
-
computeBlobKzgProof:
|
|
182
|
+
blobToKzgCommitment: kzg.blobToKzgCommitment.bind(kzg),
|
|
183
|
+
computeBlobKzgProof: kzg.computeBlobKzgProof.bind(kzg),
|
|
184
|
+
computeCellsAndKzgProofs: (b: Uint8Array): [Uint8Array[], Uint8Array[]] => {
|
|
185
|
+
const result = kzg.computeCellsAndKzgProofs(b);
|
|
186
|
+
return [result.cells, result.proofs];
|
|
187
|
+
},
|
|
309
188
|
};
|
|
310
189
|
}
|
|
311
|
-
|
|
312
|
-
// Returns as many blobs as we require to broadcast the given fields
|
|
313
|
-
// Assumes we share the fields hash between all blobs
|
|
314
|
-
static async getBlobs(fields: Fr[]): Promise<Blob[]> {
|
|
315
|
-
const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
|
|
316
|
-
const multiBlobFieldsHash = await poseidon2Hash(fields);
|
|
317
|
-
const res = [];
|
|
318
|
-
for (let i = 0; i < numBlobs; i++) {
|
|
319
|
-
const end = fields.length < (i + 1) * FIELD_ELEMENTS_PER_BLOB ? fields.length : (i + 1) * FIELD_ELEMENTS_PER_BLOB;
|
|
320
|
-
res.push(await Blob.fromFields(fields.slice(i * FIELD_ELEMENTS_PER_BLOB, end), multiBlobFieldsHash));
|
|
321
|
-
}
|
|
322
|
-
return res;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// 48 bytes encoded in fields as [Fr, Fr] = [0->31, 31->48]
|
|
327
|
-
function commitmentToFields(commitment: Buffer): [Fr, Fr] {
|
|
328
|
-
return [new Fr(commitment.subarray(0, 31)), new Fr(commitment.subarray(31, 48))];
|
|
329
190
|
}
|