@aztec/blob-lib 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
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/batched_blob.d.ts +26 -0
- package/dest/batched_blob.d.ts.map +1 -0
- package/dest/batched_blob.js +20 -0
- package/dest/blob.d.ts +50 -99
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +78 -169
- package/dest/blob_batching.d.ts +41 -123
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +129 -203
- package/dest/blob_utils.d.ts +40 -0
- package/dest/blob_utils.d.ts.map +1 -0
- package/dest/blob_utils.js +69 -0
- package/dest/circuit_types/blob_accumulator.d.ts +23 -0
- package/dest/circuit_types/blob_accumulator.d.ts.map +1 -0
- package/dest/circuit_types/blob_accumulator.js +62 -0
- package/dest/circuit_types/final_blob_accumulator.d.ts +23 -0
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -0
- package/dest/circuit_types/final_blob_accumulator.js +66 -0
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +16 -0
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -0
- package/dest/circuit_types/final_blob_batching_challenges.js +26 -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/encoding/block_blob_data.d.ts +22 -0
- package/dest/encoding/block_blob_data.d.ts.map +1 -0
- package/dest/encoding/block_blob_data.js +65 -0
- package/dest/encoding/block_end_marker.d.ts +11 -0
- package/dest/encoding/block_end_marker.d.ts.map +1 -0
- package/dest/encoding/block_end_marker.js +41 -0
- package/dest/encoding/block_end_state_field.d.ts +12 -0
- package/dest/encoding/block_end_state_field.d.ts.map +1 -0
- package/dest/encoding/block_end_state_field.js +39 -0
- package/dest/encoding/checkpoint_blob_data.d.ts +15 -0
- package/dest/encoding/checkpoint_blob_data.d.ts.map +1 -0
- package/dest/encoding/checkpoint_blob_data.js +67 -0
- package/dest/encoding/checkpoint_end_marker.d.ts +8 -0
- package/dest/encoding/checkpoint_end_marker.d.ts.map +1 -0
- package/dest/encoding/checkpoint_end_marker.js +28 -0
- package/dest/encoding/fixtures.d.ts +41 -0
- package/dest/encoding/fixtures.d.ts.map +1 -0
- package/dest/encoding/fixtures.js +140 -0
- package/dest/encoding/index.d.ts +10 -0
- package/dest/encoding/index.d.ts.map +1 -0
- package/dest/encoding/index.js +9 -0
- package/dest/encoding/tx_blob_data.d.ts +19 -0
- package/dest/encoding/tx_blob_data.d.ts.map +1 -0
- package/dest/encoding/tx_blob_data.js +79 -0
- package/dest/encoding/tx_start_marker.d.ts +16 -0
- package/dest/encoding/tx_start_marker.d.ts.map +1 -0
- package/dest/encoding/tx_start_marker.js +77 -0
- package/dest/errors.d.ts +1 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/hash.d.ts +43 -0
- package/dest/hash.d.ts.map +1 -0
- package/dest/hash.js +80 -0
- package/dest/index.d.ts +7 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +6 -16
- package/dest/interface.d.ts +1 -2
- package/dest/interface.d.ts.map +1 -1
- package/dest/kzg_context.d.ts +8 -0
- package/dest/kzg_context.d.ts.map +1 -0
- package/dest/kzg_context.js +14 -0
- package/dest/sponge_blob.d.ts +12 -14
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +26 -30
- package/dest/testing.d.ts +10 -23
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +37 -53
- package/dest/types.d.ts +17 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +4 -0
- package/package.json +10 -7
- package/src/batched_blob.ts +26 -0
- package/src/blob.ts +81 -195
- package/src/blob_batching.ts +168 -231
- package/src/blob_utils.ts +82 -0
- package/src/circuit_types/blob_accumulator.ts +96 -0
- package/src/circuit_types/final_blob_accumulator.ts +76 -0
- package/src/circuit_types/final_blob_batching_challenges.ts +30 -0
- package/src/circuit_types/index.ts +4 -0
- package/src/encoding/block_blob_data.ts +102 -0
- package/src/encoding/block_end_marker.ts +55 -0
- package/src/encoding/block_end_state_field.ts +59 -0
- package/src/encoding/checkpoint_blob_data.ts +95 -0
- package/src/encoding/checkpoint_end_marker.ts +40 -0
- package/src/encoding/fixtures.ts +210 -0
- package/src/encoding/index.ts +9 -0
- package/src/encoding/tx_blob_data.ts +116 -0
- package/src/encoding/tx_start_marker.ts +97 -0
- package/src/hash.ts +89 -0
- package/src/index.ts +6 -19
- package/src/interface.ts +0 -1
- package/src/kzg_context.ts +16 -0
- package/src/sponge_blob.ts +28 -31
- package/src/testing.ts +48 -59
- package/src/types.ts +17 -0
- package/dest/blob_batching_public_inputs.d.ts +0 -71
- package/dest/blob_batching_public_inputs.d.ts.map +0 -1
- package/dest/blob_batching_public_inputs.js +0 -168
- package/dest/encoding.d.ts +0 -66
- package/dest/encoding.d.ts.map +0 -1
- package/dest/encoding.js +0 -113
- package/src/blob_batching_public_inputs.ts +0 -252
- package/src/encoding.ts +0 -138
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
-
import { inspect } from 'util';
|
|
4
|
-
import { Blob } from './blob.js';
|
|
5
|
-
import { BatchedBlob, BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
6
|
-
/**
|
|
7
|
-
* See nr BlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
8
|
-
*/
|
|
9
|
-
export declare class BlobAccumulatorPublicInputs {
|
|
10
|
-
blobCommitmentsHashAcc: Fr;
|
|
11
|
-
zAcc: Fr;
|
|
12
|
-
yAcc: BLS12Fr;
|
|
13
|
-
cAcc: BLS12Point;
|
|
14
|
-
gammaAcc: Fr;
|
|
15
|
-
gammaPowAcc: BLS12Fr;
|
|
16
|
-
constructor(blobCommitmentsHashAcc: Fr, zAcc: Fr, yAcc: BLS12Fr, cAcc: BLS12Point, gammaAcc: Fr, gammaPowAcc: BLS12Fr);
|
|
17
|
-
static empty(): BlobAccumulatorPublicInputs;
|
|
18
|
-
equals(other: BlobAccumulatorPublicInputs): boolean;
|
|
19
|
-
static fromBuffer(buffer: Buffer | BufferReader): BlobAccumulatorPublicInputs;
|
|
20
|
-
toBuffer(): Buffer<ArrayBufferLike>;
|
|
21
|
-
/**
|
|
22
|
-
* Given blobs, accumulate all public inputs state.
|
|
23
|
-
* We assume the input blobs have not been evaluated at z.
|
|
24
|
-
* NOTE: Does NOT accumulate non circuit values including Q. This exists to simulate/check exactly what the circuit is doing
|
|
25
|
-
* and is unsafe for other use. For that reason, a toBatchedBlobAccumulator does not exist. See evaluateBlobs() oracle for usage.
|
|
26
|
-
* @returns An updated blob accumulator.
|
|
27
|
-
*/
|
|
28
|
-
accumulateBlobs(blobs: Blob[], finalBlobChallenges: FinalBlobBatchingChallenges): Promise<BlobAccumulatorPublicInputs>;
|
|
29
|
-
toFields(): Fr[];
|
|
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;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* See nr FinalBlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
39
|
-
*/
|
|
40
|
-
export declare class FinalBlobAccumulatorPublicInputs {
|
|
41
|
-
blobCommitmentsHash: Fr;
|
|
42
|
-
z: Fr;
|
|
43
|
-
y: BLS12Fr;
|
|
44
|
-
c: BLS12Point;
|
|
45
|
-
constructor(blobCommitmentsHash: Fr, z: Fr, y: BLS12Fr, c: BLS12Point);
|
|
46
|
-
static empty(): FinalBlobAccumulatorPublicInputs;
|
|
47
|
-
static fromBuffer(buffer: Buffer | BufferReader): FinalBlobAccumulatorPublicInputs;
|
|
48
|
-
toBuffer(): Buffer<ArrayBufferLike>;
|
|
49
|
-
static fromBatchedBlob(blob: BatchedBlob): FinalBlobAccumulatorPublicInputs;
|
|
50
|
-
toFields(): Fr[];
|
|
51
|
-
toString(): string;
|
|
52
|
-
equals(other: FinalBlobAccumulatorPublicInputs): boolean;
|
|
53
|
-
static random(): FinalBlobAccumulatorPublicInputs;
|
|
54
|
-
static fromBatchedBlobAccumulator(accumulator: BatchedBlobAccumulator): FinalBlobAccumulatorPublicInputs;
|
|
55
|
-
[inspect.custom](): string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* startBlobAccumulator: Accumulated opening proofs for all blobs before this block range.
|
|
59
|
-
* endBlobAccumulator: Accumulated opening proofs for all blobs after adding this block range.
|
|
60
|
-
* finalBlobChallenges: Final values z and gamma, shared across the epoch.
|
|
61
|
-
*/
|
|
62
|
-
export declare class BlockBlobPublicInputs {
|
|
63
|
-
startBlobAccumulator: BlobAccumulatorPublicInputs;
|
|
64
|
-
endBlobAccumulator: BlobAccumulatorPublicInputs;
|
|
65
|
-
finalBlobChallenges: FinalBlobBatchingChallenges;
|
|
66
|
-
constructor(startBlobAccumulator: BlobAccumulatorPublicInputs, endBlobAccumulator: BlobAccumulatorPublicInputs, finalBlobChallenges: FinalBlobBatchingChallenges);
|
|
67
|
-
static empty(): BlockBlobPublicInputs;
|
|
68
|
-
static fromBuffer(buffer: Buffer | BufferReader): BlockBlobPublicInputs;
|
|
69
|
-
toBuffer(): Buffer<ArrayBufferLike>;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=blob_batching_public_inputs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,168 +0,0 @@
|
|
|
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
|
-
* 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
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* See nr FinalBlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
80
|
-
*/ export class FinalBlobAccumulatorPublicInputs {
|
|
81
|
-
blobCommitmentsHash;
|
|
82
|
-
z;
|
|
83
|
-
y;
|
|
84
|
-
c;
|
|
85
|
-
constructor(blobCommitmentsHash, z, y, c){
|
|
86
|
-
this.blobCommitmentsHash = blobCommitmentsHash;
|
|
87
|
-
this.z = z;
|
|
88
|
-
this.y = y;
|
|
89
|
-
this.c = c;
|
|
90
|
-
}
|
|
91
|
-
static empty() {
|
|
92
|
-
return new FinalBlobAccumulatorPublicInputs(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO);
|
|
93
|
-
}
|
|
94
|
-
static fromBuffer(buffer) {
|
|
95
|
-
const reader = BufferReader.asReader(buffer);
|
|
96
|
-
return new FinalBlobAccumulatorPublicInputs(Fr.fromBuffer(reader), Fr.fromBuffer(reader), BLS12Fr.fromBuffer(reader), BLS12Point.fromBuffer(reader));
|
|
97
|
-
}
|
|
98
|
-
toBuffer() {
|
|
99
|
-
return serializeToBuffer(this.blobCommitmentsHash, this.z, this.y, this.c);
|
|
100
|
-
}
|
|
101
|
-
static fromBatchedBlob(blob) {
|
|
102
|
-
return new FinalBlobAccumulatorPublicInputs(blob.blobCommitmentsHash, blob.z, blob.y, blob.commitment);
|
|
103
|
-
}
|
|
104
|
-
toFields() {
|
|
105
|
-
return [
|
|
106
|
-
this.blobCommitmentsHash,
|
|
107
|
-
this.z,
|
|
108
|
-
...this.y.toNoirBigNum().limbs.map(Fr.fromString),
|
|
109
|
-
...this.c.toBN254Fields()
|
|
110
|
-
];
|
|
111
|
-
}
|
|
112
|
-
// The below is used to send to L1 for proof verification
|
|
113
|
-
toString() {
|
|
114
|
-
// We prepend 32 bytes for the (unused) 'blobHash' slot. This is not read or required by getEpochProofPublicInputs() on L1, but
|
|
115
|
-
// is expected since we usually pass the full precompile inputs via verifyEpochRootProof() to getEpochProofPublicInputs() to ensure
|
|
116
|
-
// we use calldata rather than a slice in memory:
|
|
117
|
-
const buf = Buffer.concat([
|
|
118
|
-
Buffer.alloc(32),
|
|
119
|
-
this.z.toBuffer(),
|
|
120
|
-
this.y.toBuffer(),
|
|
121
|
-
this.c.compress()
|
|
122
|
-
]);
|
|
123
|
-
return buf.toString('hex');
|
|
124
|
-
}
|
|
125
|
-
equals(other) {
|
|
126
|
-
return this.blobCommitmentsHash.equals(other.blobCommitmentsHash) && this.z.equals(other.z) && this.y.equals(other.y) && this.c.equals(other.c);
|
|
127
|
-
}
|
|
128
|
-
// Creates a random instance. Used for testing only - will not prove/verify.
|
|
129
|
-
static random() {
|
|
130
|
-
return new FinalBlobAccumulatorPublicInputs(Fr.random(), Fr.random(), BLS12Fr.random(), BLS12Point.random());
|
|
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
|
-
}
|
|
136
|
-
[inspect.custom]() {
|
|
137
|
-
return `FinalBlobAccumulatorPublicInputs {
|
|
138
|
-
blobCommitmentsHash: ${inspect(this.blobCommitmentsHash)},
|
|
139
|
-
z: ${inspect(this.z)},
|
|
140
|
-
y: ${inspect(this.y)},
|
|
141
|
-
c: ${inspect(this.c)},
|
|
142
|
-
}`;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* startBlobAccumulator: Accumulated opening proofs for all blobs before this block range.
|
|
147
|
-
* endBlobAccumulator: Accumulated opening proofs for all blobs after adding this block range.
|
|
148
|
-
* finalBlobChallenges: Final values z and gamma, shared across the epoch.
|
|
149
|
-
*/ export class BlockBlobPublicInputs {
|
|
150
|
-
startBlobAccumulator;
|
|
151
|
-
endBlobAccumulator;
|
|
152
|
-
finalBlobChallenges;
|
|
153
|
-
constructor(startBlobAccumulator, endBlobAccumulator, finalBlobChallenges){
|
|
154
|
-
this.startBlobAccumulator = startBlobAccumulator;
|
|
155
|
-
this.endBlobAccumulator = endBlobAccumulator;
|
|
156
|
-
this.finalBlobChallenges = finalBlobChallenges;
|
|
157
|
-
}
|
|
158
|
-
static empty() {
|
|
159
|
-
return new BlockBlobPublicInputs(BlobAccumulatorPublicInputs.empty(), BlobAccumulatorPublicInputs.empty(), FinalBlobBatchingChallenges.empty());
|
|
160
|
-
}
|
|
161
|
-
static fromBuffer(buffer) {
|
|
162
|
-
const reader = BufferReader.asReader(buffer);
|
|
163
|
-
return new BlockBlobPublicInputs(reader.readObject(BlobAccumulatorPublicInputs), reader.readObject(BlobAccumulatorPublicInputs), reader.readObject(FinalBlobBatchingChallenges));
|
|
164
|
-
}
|
|
165
|
-
toBuffer() {
|
|
166
|
-
return serializeToBuffer(this.startBlobAccumulator, this.endBlobAccumulator, this.finalBlobChallenges);
|
|
167
|
-
}
|
|
168
|
-
}
|
package/dest/encoding.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import type { Blob as BlobBuffer } from 'c-kzg';
|
|
3
|
-
export declare const TX_START_PREFIX = 8392562855083340404n;
|
|
4
|
-
export declare const TX_START_PREFIX_BYTES_LENGTH: number;
|
|
5
|
-
export declare const TX_EFFECT_PREFIX_BYTE_LENGTH: number;
|
|
6
|
-
export declare const REVERT_CODE_PREFIX = 1;
|
|
7
|
-
/**
|
|
8
|
-
* Deserializes a blob buffer into an array of field elements.
|
|
9
|
-
*
|
|
10
|
-
* Blobs are converted into BN254 fields to perform a poseidon2 hash on them (fieldHash).
|
|
11
|
-
* This method is sparse, meaning it does not include trailing zeros at the end of the blob.
|
|
12
|
-
*
|
|
13
|
-
* However, we cannot simply trim the zero's from the end of the blob, as some logs may include zero's
|
|
14
|
-
* within them.
|
|
15
|
-
* If we end on a set of zeros, such as the log below:
|
|
16
|
-
* length 7: [ a, b, c, d, e, 0, 0]
|
|
17
|
-
*
|
|
18
|
-
* we will end up with the incorrect hash if we trim the zeros from the end.
|
|
19
|
-
*
|
|
20
|
-
* Each transactions logs contains a TX start prefix, which includes a string followed
|
|
21
|
-
* by the length ( in field elements ) of the transaction's log.
|
|
22
|
-
*
|
|
23
|
-
* This function finds the end of the last transaction's logs, and returns the array up to this point.
|
|
24
|
-
*
|
|
25
|
-
* We search for a series of Tx Prefixes progressing the cursor in the field reader until we hit
|
|
26
|
-
* a field that is not a Tx Prefix, this indicates that we have reached the end of the last transaction's logs.
|
|
27
|
-
*
|
|
28
|
-
* +------------------+------------------+------------------+------------------+
|
|
29
|
-
* | TX1 Start Prefix | TX1 Log Fields | TX2 Start Prefix | Padded zeros |
|
|
30
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
31
|
-
* +------------------+------------------+------------------+------------------+
|
|
32
|
-
* ^
|
|
33
|
-
* |
|
|
34
|
-
* Function reads until here --------------------------------
|
|
35
|
-
*
|
|
36
|
-
* @param blob - The blob buffer to deserialize.
|
|
37
|
-
* @returns An array of field elements.
|
|
38
|
-
*/
|
|
39
|
-
export declare function deserializeEncodedBlobToFields(blob: BlobBuffer): Fr[];
|
|
40
|
-
/**
|
|
41
|
-
* Get the length of the transaction from the first field.
|
|
42
|
-
*
|
|
43
|
-
* @param firstField - The first field of the transaction.
|
|
44
|
-
* @returns The length of the transaction.
|
|
45
|
-
*
|
|
46
|
-
* @throws If the first field does not include the correct prefix - encoding invalid.
|
|
47
|
-
*/
|
|
48
|
-
export declare function getLengthFromFirstField(firstField: Fr): number;
|
|
49
|
-
/**
|
|
50
|
-
* Determines whether a field is the first field of a tx effect
|
|
51
|
-
*/
|
|
52
|
-
export declare function isValidFirstField(field: Fr): boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Extract the fields from a blob buffer, but do not take into account encoding
|
|
55
|
-
* that will include trailing zeros.
|
|
56
|
-
*
|
|
57
|
-
* +------------------+------------------+------------------+------------------+
|
|
58
|
-
* | | | | Padded zeros |
|
|
59
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
60
|
-
* +------------------+------------------+------------------+------------------+
|
|
61
|
-
* ^
|
|
62
|
-
* |
|
|
63
|
-
* Function reads until here ----------------------
|
|
64
|
-
*/
|
|
65
|
-
export declare function extractBlobFieldsFromBuffer(blob: BlobBuffer): Fr[];
|
|
66
|
-
//# sourceMappingURL=encoding.d.ts.map
|
package/dest/encoding.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAIhD,eAAO,MAAM,eAAe,uBAAuB,CAAC;AAEpD,eAAO,MAAM,4BAA4B,QAA0C,CAAC;AAEpF,eAAO,MAAM,4BAA4B,QAAmC,CAAC;AAC7E,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,UAAU,GAAG,EAAE,EAAE,CAsBrE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,EAAE,GAAG,MAAM,CAO9D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,EAAE,GAAG,OAAO,CAqBpD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,UAAU,GAAG,EAAE,EAAE,CAYlE"}
|
package/dest/encoding.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
-
// Note duplicated from stdlib !
|
|
4
|
-
// This will appear as 0x74785f7374617274 in logs
|
|
5
|
-
export const TX_START_PREFIX = 8392562855083340404n;
|
|
6
|
-
// These are helper constants to decode tx effects from blob encoded fields
|
|
7
|
-
export const TX_START_PREFIX_BYTES_LENGTH = TX_START_PREFIX.toString(16).length / 2;
|
|
8
|
-
// 7 bytes for: | 0 | txlen[0] | txlen[1] | 0 | REVERT_CODE_PREFIX | 0 | revertCode |
|
|
9
|
-
export const TX_EFFECT_PREFIX_BYTE_LENGTH = TX_START_PREFIX_BYTES_LENGTH + 7;
|
|
10
|
-
export const REVERT_CODE_PREFIX = 1;
|
|
11
|
-
/**
|
|
12
|
-
* Deserializes a blob buffer into an array of field elements.
|
|
13
|
-
*
|
|
14
|
-
* Blobs are converted into BN254 fields to perform a poseidon2 hash on them (fieldHash).
|
|
15
|
-
* This method is sparse, meaning it does not include trailing zeros at the end of the blob.
|
|
16
|
-
*
|
|
17
|
-
* However, we cannot simply trim the zero's from the end of the blob, as some logs may include zero's
|
|
18
|
-
* within them.
|
|
19
|
-
* If we end on a set of zeros, such as the log below:
|
|
20
|
-
* length 7: [ a, b, c, d, e, 0, 0]
|
|
21
|
-
*
|
|
22
|
-
* we will end up with the incorrect hash if we trim the zeros from the end.
|
|
23
|
-
*
|
|
24
|
-
* Each transactions logs contains a TX start prefix, which includes a string followed
|
|
25
|
-
* by the length ( in field elements ) of the transaction's log.
|
|
26
|
-
*
|
|
27
|
-
* This function finds the end of the last transaction's logs, and returns the array up to this point.
|
|
28
|
-
*
|
|
29
|
-
* We search for a series of Tx Prefixes progressing the cursor in the field reader until we hit
|
|
30
|
-
* a field that is not a Tx Prefix, this indicates that we have reached the end of the last transaction's logs.
|
|
31
|
-
*
|
|
32
|
-
* +------------------+------------------+------------------+------------------+
|
|
33
|
-
* | TX1 Start Prefix | TX1 Log Fields | TX2 Start Prefix | Padded zeros |
|
|
34
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
35
|
-
* +------------------+------------------+------------------+------------------+
|
|
36
|
-
* ^
|
|
37
|
-
* |
|
|
38
|
-
* Function reads until here --------------------------------
|
|
39
|
-
*
|
|
40
|
-
* @param blob - The blob buffer to deserialize.
|
|
41
|
-
* @returns An array of field elements.
|
|
42
|
-
*/ export function deserializeEncodedBlobToFields(blob) {
|
|
43
|
-
// Convert blob buffer to array of field elements
|
|
44
|
-
const reader = BufferReader.asReader(blob);
|
|
45
|
-
const array = reader.readArray(blob.length >> 5, Fr); // >> 5 = / 32 (bytes per field)
|
|
46
|
-
const fieldReader = FieldReader.asReader(array);
|
|
47
|
-
// Read fields until we hit zeros at the end
|
|
48
|
-
while(!fieldReader.isFinished()){
|
|
49
|
-
const currentField = fieldReader.peekField();
|
|
50
|
-
// Stop when we hit a zero field
|
|
51
|
-
if (!currentField || currentField.isZero()) {
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
// Skip the remaining fields in this transaction
|
|
55
|
-
const len = getLengthFromFirstField(currentField);
|
|
56
|
-
fieldReader.skip(len);
|
|
57
|
-
}
|
|
58
|
-
// Return array up to last non-zero field
|
|
59
|
-
return array.slice(0, fieldReader.cursor);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get the length of the transaction from the first field.
|
|
63
|
-
*
|
|
64
|
-
* @param firstField - The first field of the transaction.
|
|
65
|
-
* @returns The length of the transaction.
|
|
66
|
-
*
|
|
67
|
-
* @throws If the first field does not include the correct prefix - encoding invalid.
|
|
68
|
-
*/ export function getLengthFromFirstField(firstField) {
|
|
69
|
-
// Check that the first field includes the correct prefix
|
|
70
|
-
if (!isValidFirstField(firstField)) {
|
|
71
|
-
throw new Error('Invalid prefix');
|
|
72
|
-
}
|
|
73
|
-
const buf = firstField.toBuffer().subarray(-TX_EFFECT_PREFIX_BYTE_LENGTH);
|
|
74
|
-
return new Fr(buf.subarray(TX_START_PREFIX_BYTES_LENGTH + 1, TX_START_PREFIX_BYTES_LENGTH + 3)).toNumber();
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Determines whether a field is the first field of a tx effect
|
|
78
|
-
*/ export function isValidFirstField(field) {
|
|
79
|
-
const buf = field.toBuffer();
|
|
80
|
-
if (!buf.subarray(0, field.size - TX_EFFECT_PREFIX_BYTE_LENGTH).equals(Buffer.alloc(field.size - TX_EFFECT_PREFIX_BYTE_LENGTH))) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
const sliced = buf.subarray(-TX_EFFECT_PREFIX_BYTE_LENGTH);
|
|
84
|
-
if (// Checking we start with the correct prefix...
|
|
85
|
-
!new Fr(sliced.subarray(0, TX_START_PREFIX_BYTES_LENGTH)).equals(new Fr(TX_START_PREFIX)) || // ...and include the revert code prefix..
|
|
86
|
-
sliced[sliced.length - 3] !== REVERT_CODE_PREFIX || // ...and the following revert code is valid.
|
|
87
|
-
sliced[sliced.length - 1] > 4) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Extract the fields from a blob buffer, but do not take into account encoding
|
|
94
|
-
* that will include trailing zeros.
|
|
95
|
-
*
|
|
96
|
-
* +------------------+------------------+------------------+------------------+
|
|
97
|
-
* | | | | Padded zeros |
|
|
98
|
-
* | [3 a,b,c] | [3, a, b, c] | [5 d,e,f,0,0] | [0, 0, 0, .., 0] |
|
|
99
|
-
* +------------------+------------------+------------------+------------------+
|
|
100
|
-
* ^
|
|
101
|
-
* |
|
|
102
|
-
* Function reads until here ----------------------
|
|
103
|
-
*/ export function extractBlobFieldsFromBuffer(blob) {
|
|
104
|
-
const reader = BufferReader.asReader(blob);
|
|
105
|
-
const array = reader.readArray(blob.length >> 5, Fr);
|
|
106
|
-
// Find the index of the last non-zero field
|
|
107
|
-
let lastNonZeroIndex = array.length - 1;
|
|
108
|
-
while(lastNonZeroIndex >= 0 && array[lastNonZeroIndex].isZero()){
|
|
109
|
-
lastNonZeroIndex--;
|
|
110
|
-
}
|
|
111
|
-
// Return the trimmed array
|
|
112
|
-
return array.slice(0, lastNonZeroIndex + 1);
|
|
113
|
-
}
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { BLS12_FQ_LIMBS, BLS12_FR_LIMBS } from '@aztec/constants';
|
|
2
|
-
import { BLS12Fq, BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
-
|
|
5
|
-
import { inspect } from 'util';
|
|
6
|
-
|
|
7
|
-
import { Blob } from './blob.js';
|
|
8
|
-
import { BatchedBlob, BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* See nr BlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
12
|
-
*/
|
|
13
|
-
export class BlobAccumulatorPublicInputs {
|
|
14
|
-
constructor(
|
|
15
|
-
public blobCommitmentsHashAcc: Fr,
|
|
16
|
-
public zAcc: Fr,
|
|
17
|
-
public yAcc: BLS12Fr,
|
|
18
|
-
public cAcc: BLS12Point,
|
|
19
|
-
public gammaAcc: Fr,
|
|
20
|
-
public gammaPowAcc: BLS12Fr,
|
|
21
|
-
) {}
|
|
22
|
-
|
|
23
|
-
static empty(): BlobAccumulatorPublicInputs {
|
|
24
|
-
return new BlobAccumulatorPublicInputs(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO, Fr.ZERO, BLS12Fr.ZERO);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
equals(other: BlobAccumulatorPublicInputs) {
|
|
28
|
-
return (
|
|
29
|
-
this.blobCommitmentsHashAcc.equals(other.blobCommitmentsHashAcc) &&
|
|
30
|
-
this.zAcc.equals(other.zAcc) &&
|
|
31
|
-
this.yAcc.equals(other.yAcc) &&
|
|
32
|
-
this.cAcc.equals(other.cAcc) &&
|
|
33
|
-
this.gammaAcc.equals(other.gammaAcc) &&
|
|
34
|
-
this.gammaPowAcc.equals(other.gammaPowAcc)
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static fromBuffer(buffer: Buffer | BufferReader): BlobAccumulatorPublicInputs {
|
|
39
|
-
const reader = BufferReader.asReader(buffer);
|
|
40
|
-
return new BlobAccumulatorPublicInputs(
|
|
41
|
-
Fr.fromBuffer(reader),
|
|
42
|
-
Fr.fromBuffer(reader),
|
|
43
|
-
BLS12Fr.fromBuffer(reader),
|
|
44
|
-
BLS12Point.fromBuffer(reader),
|
|
45
|
-
Fr.fromBuffer(reader),
|
|
46
|
-
BLS12Fr.fromBuffer(reader),
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
toBuffer() {
|
|
51
|
-
return serializeToBuffer(
|
|
52
|
-
this.blobCommitmentsHashAcc,
|
|
53
|
-
this.zAcc,
|
|
54
|
-
this.yAcc,
|
|
55
|
-
this.cAcc,
|
|
56
|
-
this.gammaAcc,
|
|
57
|
-
this.gammaPowAcc,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Given blobs, accumulate all public inputs state.
|
|
63
|
-
* We assume the input blobs have not been evaluated at z.
|
|
64
|
-
* NOTE: Does NOT accumulate non circuit values including Q. This exists to simulate/check exactly what the circuit is doing
|
|
65
|
-
* and is unsafe for other use. For that reason, a toBatchedBlobAccumulator does not exist. See evaluateBlobs() oracle for usage.
|
|
66
|
-
* @returns An updated blob accumulator.
|
|
67
|
-
*/
|
|
68
|
-
async accumulateBlobs(blobs: Blob[], finalBlobChallenges: FinalBlobBatchingChallenges) {
|
|
69
|
-
let acc = new BatchedBlobAccumulator(
|
|
70
|
-
this.blobCommitmentsHashAcc,
|
|
71
|
-
this.zAcc,
|
|
72
|
-
this.yAcc,
|
|
73
|
-
this.cAcc,
|
|
74
|
-
BLS12Point.ZERO,
|
|
75
|
-
this.gammaAcc,
|
|
76
|
-
this.gammaPowAcc,
|
|
77
|
-
finalBlobChallenges,
|
|
78
|
-
);
|
|
79
|
-
acc = await acc.accumulateBlobs(blobs);
|
|
80
|
-
return new BlobAccumulatorPublicInputs(
|
|
81
|
-
acc.blobCommitmentsHashAcc,
|
|
82
|
-
acc.zAcc,
|
|
83
|
-
acc.yAcc,
|
|
84
|
-
acc.cAcc,
|
|
85
|
-
acc.gammaAcc,
|
|
86
|
-
acc.gammaPow,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
toFields() {
|
|
91
|
-
return [
|
|
92
|
-
this.blobCommitmentsHashAcc,
|
|
93
|
-
this.zAcc,
|
|
94
|
-
...this.yAcc.toNoirBigNum().limbs.map(Fr.fromString),
|
|
95
|
-
...this.cAcc.x.toNoirBigNum().limbs.map(Fr.fromString),
|
|
96
|
-
...this.cAcc.y.toNoirBigNum().limbs.map(Fr.fromString),
|
|
97
|
-
new Fr(this.cAcc.isInfinite),
|
|
98
|
-
this.gammaAcc,
|
|
99
|
-
...this.gammaPowAcc.toNoirBigNum().limbs.map(Fr.fromString),
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static fromFields(fields: Fr[] | FieldReader): BlobAccumulatorPublicInputs {
|
|
104
|
-
const reader = FieldReader.asReader(fields);
|
|
105
|
-
return new BlobAccumulatorPublicInputs(
|
|
106
|
-
reader.readField(),
|
|
107
|
-
reader.readField(),
|
|
108
|
-
BLS12Fr.fromNoirBigNum({ limbs: reader.readFieldArray(BLS12_FR_LIMBS).map(f => f.toString()) }),
|
|
109
|
-
new BLS12Point(
|
|
110
|
-
BLS12Fq.fromNoirBigNum({ limbs: reader.readFieldArray(BLS12_FQ_LIMBS).map(f => f.toString()) }),
|
|
111
|
-
BLS12Fq.fromNoirBigNum({ limbs: reader.readFieldArray(BLS12_FQ_LIMBS).map(f => f.toString()) }),
|
|
112
|
-
reader.readBoolean(),
|
|
113
|
-
),
|
|
114
|
-
reader.readField(),
|
|
115
|
-
BLS12Fr.fromNoirBigNum({ limbs: reader.readFieldArray(BLS12_FR_LIMBS).map(f => f.toString()) }),
|
|
116
|
-
);
|
|
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
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* See nr FinalBlobAccumulatorPublicInputs and ts BatchedBlobAccumulator for documentation.
|
|
137
|
-
*/
|
|
138
|
-
export class FinalBlobAccumulatorPublicInputs {
|
|
139
|
-
constructor(
|
|
140
|
-
public blobCommitmentsHash: Fr,
|
|
141
|
-
public z: Fr,
|
|
142
|
-
public y: BLS12Fr,
|
|
143
|
-
public c: BLS12Point,
|
|
144
|
-
) {}
|
|
145
|
-
|
|
146
|
-
static empty(): FinalBlobAccumulatorPublicInputs {
|
|
147
|
-
return new FinalBlobAccumulatorPublicInputs(Fr.ZERO, Fr.ZERO, BLS12Fr.ZERO, BLS12Point.ZERO);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
static fromBuffer(buffer: Buffer | BufferReader): FinalBlobAccumulatorPublicInputs {
|
|
151
|
-
const reader = BufferReader.asReader(buffer);
|
|
152
|
-
return new FinalBlobAccumulatorPublicInputs(
|
|
153
|
-
Fr.fromBuffer(reader),
|
|
154
|
-
Fr.fromBuffer(reader),
|
|
155
|
-
BLS12Fr.fromBuffer(reader),
|
|
156
|
-
BLS12Point.fromBuffer(reader),
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
toBuffer() {
|
|
161
|
-
return serializeToBuffer(this.blobCommitmentsHash, this.z, this.y, this.c);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
static fromBatchedBlob(blob: BatchedBlob) {
|
|
165
|
-
return new FinalBlobAccumulatorPublicInputs(blob.blobCommitmentsHash, blob.z, blob.y, blob.commitment);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
toFields() {
|
|
169
|
-
return [
|
|
170
|
-
this.blobCommitmentsHash,
|
|
171
|
-
this.z,
|
|
172
|
-
...this.y.toNoirBigNum().limbs.map(Fr.fromString),
|
|
173
|
-
...this.c.toBN254Fields(),
|
|
174
|
-
];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// The below is used to send to L1 for proof verification
|
|
178
|
-
toString() {
|
|
179
|
-
// We prepend 32 bytes for the (unused) 'blobHash' slot. This is not read or required by getEpochProofPublicInputs() on L1, but
|
|
180
|
-
// is expected since we usually pass the full precompile inputs via verifyEpochRootProof() to getEpochProofPublicInputs() to ensure
|
|
181
|
-
// we use calldata rather than a slice in memory:
|
|
182
|
-
const buf = Buffer.concat([Buffer.alloc(32), this.z.toBuffer(), this.y.toBuffer(), this.c.compress()]);
|
|
183
|
-
return buf.toString('hex');
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
equals(other: FinalBlobAccumulatorPublicInputs) {
|
|
187
|
-
return (
|
|
188
|
-
this.blobCommitmentsHash.equals(other.blobCommitmentsHash) &&
|
|
189
|
-
this.z.equals(other.z) &&
|
|
190
|
-
this.y.equals(other.y) &&
|
|
191
|
-
this.c.equals(other.c)
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Creates a random instance. Used for testing only - will not prove/verify.
|
|
196
|
-
static random() {
|
|
197
|
-
return new FinalBlobAccumulatorPublicInputs(Fr.random(), Fr.random(), BLS12Fr.random(), BLS12Point.random());
|
|
198
|
-
}
|
|
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
|
-
|
|
210
|
-
[inspect.custom]() {
|
|
211
|
-
return `FinalBlobAccumulatorPublicInputs {
|
|
212
|
-
blobCommitmentsHash: ${inspect(this.blobCommitmentsHash)},
|
|
213
|
-
z: ${inspect(this.z)},
|
|
214
|
-
y: ${inspect(this.y)},
|
|
215
|
-
c: ${inspect(this.c)},
|
|
216
|
-
}`;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* startBlobAccumulator: Accumulated opening proofs for all blobs before this block range.
|
|
222
|
-
* endBlobAccumulator: Accumulated opening proofs for all blobs after adding this block range.
|
|
223
|
-
* finalBlobChallenges: Final values z and gamma, shared across the epoch.
|
|
224
|
-
*/
|
|
225
|
-
export class BlockBlobPublicInputs {
|
|
226
|
-
constructor(
|
|
227
|
-
public startBlobAccumulator: BlobAccumulatorPublicInputs,
|
|
228
|
-
public endBlobAccumulator: BlobAccumulatorPublicInputs,
|
|
229
|
-
public finalBlobChallenges: FinalBlobBatchingChallenges,
|
|
230
|
-
) {}
|
|
231
|
-
|
|
232
|
-
static empty(): BlockBlobPublicInputs {
|
|
233
|
-
return new BlockBlobPublicInputs(
|
|
234
|
-
BlobAccumulatorPublicInputs.empty(),
|
|
235
|
-
BlobAccumulatorPublicInputs.empty(),
|
|
236
|
-
FinalBlobBatchingChallenges.empty(),
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
static fromBuffer(buffer: Buffer | BufferReader): BlockBlobPublicInputs {
|
|
241
|
-
const reader = BufferReader.asReader(buffer);
|
|
242
|
-
return new BlockBlobPublicInputs(
|
|
243
|
-
reader.readObject(BlobAccumulatorPublicInputs),
|
|
244
|
-
reader.readObject(BlobAccumulatorPublicInputs),
|
|
245
|
-
reader.readObject(FinalBlobBatchingChallenges),
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
toBuffer() {
|
|
250
|
-
return serializeToBuffer(this.startBlobAccumulator, this.endBlobAccumulator, this.finalBlobChallenges);
|
|
251
|
-
}
|
|
252
|
-
}
|