@aztec/blob-lib 1.0.0-nightly.20250608 → 1.0.0-nightly.20250610
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 +1 -0
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +20 -1
- package/dest/blob_batching.d.ts +205 -0
- package/dest/blob_batching.d.ts.map +1 -0
- package/dest/blob_batching.js +316 -0
- package/dest/blob_batching_public_inputs.d.ts +66 -0
- package/dest/blob_batching_public_inputs.d.ts.map +1 -0
- package/dest/blob_batching_public_inputs.js +170 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/testing.d.ts +6 -5
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +10 -9
- package/package.json +3 -3
- package/src/blob.ts +15 -1
- package/src/blob_batching.ts +381 -0
- package/src/blob_batching_public_inputs.ts +241 -0
- package/src/index.ts +2 -1
- package/src/testing.ts +21 -11
- package/src/trusted_setup_bit_reversed.json +4100 -0
- package/dest/blob_public_inputs.d.ts +0 -48
- 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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { BLS12_FQ_LIMBS, BLS12_FR_LIMBS } from '@aztec/constants';
|
|
2
|
+
import { BLS12Fq, BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
+
import { inspect } from 'util';
|
|
5
|
+
import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
6
|
+
/**
|
|
7
|
+
* See nr BlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
8
|
+
*/ export class BlobAccumulatorPublicInputs {
|
|
9
|
+
blobCommitmentsHashAcc;
|
|
10
|
+
zAcc;
|
|
11
|
+
yAcc;
|
|
12
|
+
cAcc;
|
|
13
|
+
gammaAcc;
|
|
14
|
+
gammaPowAcc;
|
|
15
|
+
constructor(blobCommitmentsHashAcc, zAcc, yAcc, cAcc, gammaAcc, gammaPowAcc){
|
|
16
|
+
this.blobCommitmentsHashAcc = blobCommitmentsHashAcc;
|
|
17
|
+
this.zAcc = zAcc;
|
|
18
|
+
this.yAcc = yAcc;
|
|
19
|
+
this.cAcc = cAcc;
|
|
20
|
+
this.gammaAcc = gammaAcc;
|
|
21
|
+
this.gammaPowAcc = gammaPowAcc;
|
|
22
|
+
}
|
|
23
|
+
static empty() {
|
|
24
|
+
return new BlobAccumulatorPublicInputs(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO, Fr.ZERO, BLS12Fr.ZERO);
|
|
25
|
+
}
|
|
26
|
+
equals(other) {
|
|
27
|
+
return this.blobCommitmentsHashAcc.equals(other.blobCommitmentsHashAcc) && this.zAcc.equals(other.zAcc) && this.yAcc.equals(other.yAcc) && this.cAcc.equals(other.cAcc) && this.gammaAcc.equals(other.gammaAcc) && this.gammaPowAcc.equals(other.gammaPowAcc);
|
|
28
|
+
}
|
|
29
|
+
static fromBuffer(buffer) {
|
|
30
|
+
const reader = BufferReader.asReader(buffer);
|
|
31
|
+
return new BlobAccumulatorPublicInputs(Fr.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader), BLS12Point.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader));
|
|
32
|
+
}
|
|
33
|
+
toBuffer() {
|
|
34
|
+
return serializeToBuffer(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, this.gammaAcc, this.gammaPowAcc);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Given blobs, accumulate all public inputs state.
|
|
38
|
+
* We assume the input blobs have not been evaluated at z.
|
|
39
|
+
* NOTE: Does NOT accumulate non circuit values including Q. This exists to simulate/check exactly what the circuit is doing
|
|
40
|
+
* and is unsafe for other use. For that reason, a toBatchedBlobAccumulator does not exist. See evaluateBlobs() oracle for usage.
|
|
41
|
+
* @returns An updated blob accumulator.
|
|
42
|
+
*/ async accumulateBlobs(blobs, finalBlobChallenges) {
|
|
43
|
+
let acc = new BatchedBlobAccumulator(this.blobCommitmentsHashAcc, this.zAcc, this.yAcc, this.cAcc, BLS12Point.ZERO, this.gammaAcc, this.gammaPowAcc, finalBlobChallenges);
|
|
44
|
+
acc = await acc.accumulateBlobs(blobs);
|
|
45
|
+
return new BlobAccumulatorPublicInputs(acc.blobCommitmentsHashAcc, acc.zAcc, acc.yAcc, acc.cAcc, acc.gammaAcc, acc.gammaPow);
|
|
46
|
+
}
|
|
47
|
+
toFields() {
|
|
48
|
+
return [
|
|
49
|
+
this.blobCommitmentsHashAcc,
|
|
50
|
+
this.zAcc,
|
|
51
|
+
...this.yAcc.toNoirBigNum().limbs.map(Fr.fromString),
|
|
52
|
+
...this.cAcc.x.toNoirBigNum().limbs.map(Fr.fromString),
|
|
53
|
+
...this.cAcc.y.toNoirBigNum().limbs.map(Fr.fromString),
|
|
54
|
+
new Fr(this.cAcc.isInfinite),
|
|
55
|
+
this.gammaAcc,
|
|
56
|
+
...this.gammaPowAcc.toNoirBigNum().limbs.map(Fr.fromString)
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
static fromFields(fields) {
|
|
60
|
+
const reader = FieldReader.asReader(fields);
|
|
61
|
+
return new BlobAccumulatorPublicInputs(reader.readField(), reader.readField(), BLS12Fr.fromNoirBigNum({
|
|
62
|
+
limbs: reader.readFieldArray(BLS12_FR_LIMBS).map((f)=>f.toString())
|
|
63
|
+
}), new BLS12Point(BLS12Fq.fromNoirBigNum({
|
|
64
|
+
limbs: reader.readFieldArray(BLS12_FQ_LIMBS).map((f)=>f.toString())
|
|
65
|
+
}), BLS12Fq.fromNoirBigNum({
|
|
66
|
+
limbs: reader.readFieldArray(BLS12_FQ_LIMBS).map((f)=>f.toString())
|
|
67
|
+
}), reader.readBoolean()), reader.readField(), BLS12Fr.fromNoirBigNum({
|
|
68
|
+
limbs: reader.readFieldArray(BLS12_FR_LIMBS).map((f)=>f.toString())
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* See nr FinalBlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
74
|
+
*/ export class FinalBlobAccumulatorPublicInputs {
|
|
75
|
+
blobCommitmentsHash;
|
|
76
|
+
z;
|
|
77
|
+
y;
|
|
78
|
+
c;
|
|
79
|
+
constructor(blobCommitmentsHash, z, y, c){
|
|
80
|
+
this.blobCommitmentsHash = blobCommitmentsHash;
|
|
81
|
+
this.z = z;
|
|
82
|
+
this.y = y;
|
|
83
|
+
this.c = c;
|
|
84
|
+
}
|
|
85
|
+
static empty() {
|
|
86
|
+
return new FinalBlobAccumulatorPublicInputs(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO);
|
|
87
|
+
}
|
|
88
|
+
static fromBuffer(buffer) {
|
|
89
|
+
const reader = BufferReader.asReader(buffer);
|
|
90
|
+
return new FinalBlobAccumulatorPublicInputs(Fr.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader), BLS12Point.fromBuffer(reader));
|
|
91
|
+
}
|
|
92
|
+
toBuffer() {
|
|
93
|
+
return serializeToBuffer(this.blobCommitmentsHash, this.z, this.y, this.c);
|
|
94
|
+
}
|
|
95
|
+
static fromBatchedBlob(blob) {
|
|
96
|
+
return new FinalBlobAccumulatorPublicInputs(blob.blobCommitmentsHash, blob.z, blob.y, blob.commitment);
|
|
97
|
+
}
|
|
98
|
+
toFields() {
|
|
99
|
+
return [
|
|
100
|
+
this.blobCommitmentsHash,
|
|
101
|
+
this.z,
|
|
102
|
+
...this.y.toNoirBigNum().limbs.map(Fr.fromString),
|
|
103
|
+
// TODO(MW): add conversion when public inputs finalised
|
|
104
|
+
...[
|
|
105
|
+
new Fr(this.c.compress().subarray(0, 31)),
|
|
106
|
+
new Fr(this.c.compress().subarray(31, 48))
|
|
107
|
+
]
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
// The below is used to send to L1 for proof verification
|
|
111
|
+
toString() {
|
|
112
|
+
// We prepend 32 bytes for the (unused) 'blobHash' slot. This is not read or required by getEpochProofPublicInputs() on L1, but
|
|
113
|
+
// is expected since we usually pass the full precompile inputs via verifyEpochRootProof() to getEpochProofPublicInputs() to ensure
|
|
114
|
+
// we use calldata rather than a slice in memory:
|
|
115
|
+
const buf = Buffer.concat([
|
|
116
|
+
Buffer.alloc(32),
|
|
117
|
+
this.z.toBuffer(),
|
|
118
|
+
this.y.toBuffer(),
|
|
119
|
+
this.c.compress()
|
|
120
|
+
]);
|
|
121
|
+
return buf.toString('hex');
|
|
122
|
+
}
|
|
123
|
+
equals(other) {
|
|
124
|
+
return this.blobCommitmentsHash.equals(other.blobCommitmentsHash) && this.z.equals(other.z) && this.y.equals(other.y) && this.c.equals(other.c);
|
|
125
|
+
}
|
|
126
|
+
// Creates a random instance. Used for testing only - will not prove/verify.
|
|
127
|
+
static random() {
|
|
128
|
+
return new FinalBlobAccumulatorPublicInputs(Fr.random(), Fr.random(), BLS12Fr.random(), BLS12Point.random());
|
|
129
|
+
}
|
|
130
|
+
[inspect.custom]() {
|
|
131
|
+
return `FinalBlobAccumulatorPublicInputs {
|
|
132
|
+
blobCommitmentsHash: ${inspect(this.blobCommitmentsHash)},
|
|
133
|
+
z: ${inspect(this.z)},
|
|
134
|
+
y: ${inspect(this.y)},
|
|
135
|
+
c: ${inspect(this.c)},
|
|
136
|
+
}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* startBlobAccumulator: Accumulated opening proofs for all blobs before this block range.
|
|
141
|
+
* endBlobAccumulator: Accumulated opening proofs for all blobs after adding this block range.
|
|
142
|
+
* finalBlobChallenges: Final values z and gamma, shared across the epoch.
|
|
143
|
+
*/ export class BlockBlobPublicInputs {
|
|
144
|
+
startBlobAccumulator;
|
|
145
|
+
endBlobAccumulator;
|
|
146
|
+
finalBlobChallenges;
|
|
147
|
+
constructor(startBlobAccumulator, endBlobAccumulator, finalBlobChallenges){
|
|
148
|
+
this.startBlobAccumulator = startBlobAccumulator;
|
|
149
|
+
this.endBlobAccumulator = endBlobAccumulator;
|
|
150
|
+
this.finalBlobChallenges = finalBlobChallenges;
|
|
151
|
+
}
|
|
152
|
+
static empty() {
|
|
153
|
+
return new BlockBlobPublicInputs(BlobAccumulatorPublicInputs.empty(), BlobAccumulatorPublicInputs.empty(), FinalBlobBatchingChallenges.empty());
|
|
154
|
+
}
|
|
155
|
+
static fromBuffer(buffer) {
|
|
156
|
+
const reader = BufferReader.asReader(buffer);
|
|
157
|
+
return new BlockBlobPublicInputs(reader.readObject(BlobAccumulatorPublicInputs), reader.readObject(BlobAccumulatorPublicInputs), reader.readObject(FinalBlobBatchingChallenges));
|
|
158
|
+
}
|
|
159
|
+
toBuffer() {
|
|
160
|
+
return serializeToBuffer(this.startBlobAccumulator, this.endBlobAccumulator, this.finalBlobChallenges);
|
|
161
|
+
}
|
|
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
|
+
}
|
package/dest/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './blob.js';
|
|
2
|
+
export * from './blob_batching.js';
|
|
2
3
|
export * from './encoding.js';
|
|
3
4
|
export * from './interface.js';
|
|
4
5
|
export * from './errors.js';
|
|
5
|
-
export * from './
|
|
6
|
+
export * from './blob_batching_public_inputs.js';
|
|
6
7
|
export * from './sponge_blob.js';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,kCAAkC,CAAC;AACjD,cAAc,kBAAkB,CAAC"}
|
package/dest/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import cKzg from 'c-kzg';
|
|
2
2
|
const { loadTrustedSetup } = cKzg;
|
|
3
3
|
export * from './blob.js';
|
|
4
|
+
export * from './blob_batching.js';
|
|
4
5
|
export * from './encoding.js';
|
|
5
6
|
export * from './interface.js';
|
|
6
7
|
export * from './errors.js';
|
|
7
|
-
export * from './
|
|
8
|
+
export * from './blob_batching_public_inputs.js';
|
|
8
9
|
export * from './sponge_blob.js';
|
|
9
10
|
try {
|
|
10
11
|
loadTrustedSetup();
|
package/dest/testing.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { Blob } from './blob.js';
|
|
3
|
-
import {
|
|
3
|
+
import { BatchedBlobAccumulator } from './blob_batching.js';
|
|
4
|
+
import { BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
|
|
4
5
|
import { SpongeBlob } from './sponge_blob.js';
|
|
5
6
|
/**
|
|
6
7
|
* Makes arbitrary poseidon sponge for blob inputs.
|
|
@@ -10,12 +11,12 @@ import { SpongeBlob } from './sponge_blob.js';
|
|
|
10
11
|
*/
|
|
11
12
|
export declare function makeSpongeBlob(seed?: number): SpongeBlob;
|
|
12
13
|
/**
|
|
13
|
-
* Makes arbitrary blob public
|
|
14
|
+
* Makes arbitrary blob public accumulator.
|
|
14
15
|
* Note: will not verify inside the circuit.
|
|
15
|
-
* @param seed - The seed to use for generating the blob
|
|
16
|
-
* @returns A blob
|
|
16
|
+
* @param seed - The seed to use for generating the blob accumulator.
|
|
17
|
+
* @returns A blob accumulator instance.
|
|
17
18
|
*/
|
|
18
|
-
export declare function
|
|
19
|
+
export declare function makeBatchedBlobAccumulator(seed?: number): BatchedBlobAccumulator;
|
|
19
20
|
/**
|
|
20
21
|
* Makes arbitrary block blob public inputs.
|
|
21
22
|
* Note: will not verify inside the circuit.
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"
|
|
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,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEzE,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
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BLOBS_PER_BLOCK } from '@aztec/constants';
|
|
2
1
|
import { makeTuple } from '@aztec/foundation/array';
|
|
3
2
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
5
4
|
import { Blob } from './blob.js';
|
|
6
|
-
import {
|
|
5
|
+
import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
6
|
+
import { 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
|
/**
|
|
@@ -15,12 +15,12 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
|
15
15
|
return new SpongeBlob(new Poseidon2Sponge(makeTuple(3, (i)=>new Fr(i)), makeTuple(4, (i)=>new Fr(i)), 1, false), seed, seed + 1);
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Makes arbitrary blob public
|
|
18
|
+
* Makes arbitrary blob public accumulator.
|
|
19
19
|
* Note: will not verify inside the circuit.
|
|
20
|
-
* @param seed - The seed to use for generating the blob
|
|
21
|
-
* @returns A blob
|
|
22
|
-
*/ export function
|
|
23
|
-
return new
|
|
20
|
+
* @param seed - The seed to use for generating the blob accumulator.
|
|
21
|
+
* @returns A blob accumulator instance.
|
|
22
|
+
*/ export function makeBatchedBlobAccumulator(seed = 1) {
|
|
23
|
+
return new BatchedBlobAccumulator(new Fr(seed), new Fr(seed + 1), new BLS12Fr(seed + 2), BLS12Point.random(), BLS12Point.random(), new Fr(seed + 3), new BLS12Fr(seed + 4), new FinalBlobBatchingChallenges(new Fr(seed + 5), new BLS12Fr(seed + 6)));
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Makes arbitrary block blob public inputs.
|
|
@@ -28,7 +28,8 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
|
28
28
|
* @param seed - The seed to use for generating the blob inputs.
|
|
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(startBlobAccumulator.toBlobAccumulatorPublicInputs(), makeBatchedBlobAccumulator(seed + 1).toBlobAccumulatorPublicInputs(), startBlobAccumulator.finalBlobChallenges);
|
|
32
33
|
}
|
|
33
34
|
// TODO: copied form stdlib tx effect
|
|
34
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.20250610",
|
|
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.20250610",
|
|
29
|
+
"@aztec/foundation": "1.0.0-nightly.20250610",
|
|
30
30
|
"c-kzg": "4.0.0-alpha.1",
|
|
31
31
|
"tslib": "^2.4.0"
|
|
32
32
|
},
|
package/src/blob.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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
4
|
|
|
5
|
-
// Importing directly from 'c-kzg' does not work
|
|
5
|
+
// Importing directly from 'c-kzg' does not work:
|
|
6
6
|
import cKzg from 'c-kzg';
|
|
7
7
|
import type { Blob as BlobBuffer } from 'c-kzg';
|
|
8
8
|
|
|
@@ -301,6 +301,18 @@ export class Blob {
|
|
|
301
301
|
return `0x${buf.toString('hex')}`;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
+
static getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${string}` {
|
|
305
|
+
let buf = Buffer.alloc(0);
|
|
306
|
+
blobs.forEach(blob => {
|
|
307
|
+
buf = Buffer.concat([buf, blob.commitment]);
|
|
308
|
+
});
|
|
309
|
+
// For multiple blobs, we prefix the number of blobs:
|
|
310
|
+
const lenBuf = Buffer.alloc(1);
|
|
311
|
+
lenBuf.writeUint8(blobs.length);
|
|
312
|
+
buf = Buffer.concat([lenBuf, buf]);
|
|
313
|
+
return `0x${buf.toString('hex')}`;
|
|
314
|
+
}
|
|
315
|
+
|
|
304
316
|
static getViemKzgInstance() {
|
|
305
317
|
return {
|
|
306
318
|
blobToKzgCommitment: cKzg.blobToKzgCommitment,
|
|
@@ -310,6 +322,8 @@ export class Blob {
|
|
|
310
322
|
|
|
311
323
|
// Returns as many blobs as we require to broadcast the given fields
|
|
312
324
|
// Assumes we share the fields hash between all blobs
|
|
325
|
+
// TODO(MW): Rename to more accurate getBlobsPerBlock() - the items here share a fields hash,
|
|
326
|
+
// which can only be done for one block because the hash is calculated in block root.
|
|
313
327
|
static async getBlobs(fields: Fr[]): Promise<Blob[]> {
|
|
314
328
|
const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
|
|
315
329
|
const multiBlobFieldsHash = await poseidon2Hash(fields);
|