@aztec/blob-lib 3.0.0-nightly.20251121 → 3.0.0-nightly.20251123
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_batching.d.ts +6 -6
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +24 -20
- package/dest/blob_utils.d.ts +0 -1
- package/dest/blob_utils.d.ts.map +1 -1
- package/dest/blob_utils.js +1 -9
- package/dest/encoding/block_end_marker.js +1 -1
- package/dest/encoding/block_end_state_field.js +1 -1
- package/dest/encoding/checkpoint_blob_data.d.ts +4 -2
- package/dest/encoding/checkpoint_blob_data.d.ts.map +1 -1
- package/dest/encoding/checkpoint_blob_data.js +42 -29
- 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.js +5 -3
- package/dest/encoding/index.d.ts +1 -0
- package/dest/encoding/index.d.ts.map +1 -1
- package/dest/encoding/index.js +1 -0
- package/dest/encoding/tx_start_marker.js +1 -1
- package/dest/hash.d.ts +10 -3
- package/dest/hash.d.ts.map +1 -1
- package/dest/hash.js +14 -4
- package/dest/sponge_blob.d.ts +7 -11
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +19 -34
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +1 -1
- package/package.json +3 -3
- package/src/blob_batching.ts +25 -20
- package/src/blob_utils.ts +1 -11
- package/src/encoding/block_blob_data.ts +1 -1
- package/src/encoding/block_end_marker.ts +1 -1
- package/src/encoding/block_end_state_field.ts +1 -1
- package/src/encoding/checkpoint_blob_data.ts +54 -34
- package/src/encoding/checkpoint_end_marker.ts +40 -0
- package/src/encoding/fixtures.ts +3 -3
- package/src/encoding/index.ts +1 -0
- package/src/encoding/tx_blob_data.ts +1 -1
- package/src/encoding/tx_start_marker.ts +1 -1
- package/src/hash.ts +14 -4
- package/src/sponge_blob.ts +21 -34
- package/src/testing.ts +0 -1
package/dest/blob_batching.d.ts
CHANGED
|
@@ -33,13 +33,13 @@ export declare class BatchedBlob {
|
|
|
33
33
|
*
|
|
34
34
|
* @returns A batched blob.
|
|
35
35
|
*/
|
|
36
|
-
static batch(
|
|
36
|
+
static batch(blobFieldsPerCheckpoint: Fr[][]): Promise<BatchedBlob>;
|
|
37
37
|
/**
|
|
38
38
|
* Returns an empty BatchedBlobAccumulator with precomputed challenges from all blobs in the epoch.
|
|
39
39
|
* @dev MUST input all blobs to be broadcast. Does not work in multiple calls because z and gamma are calculated
|
|
40
40
|
* beforehand from ALL blobs.
|
|
41
41
|
*/
|
|
42
|
-
static newAccumulator(
|
|
42
|
+
static newAccumulator(blobFieldsPerCheckpoint: Fr[][]): Promise<BatchedBlobAccumulator>;
|
|
43
43
|
/**
|
|
44
44
|
* Gets the final challenges based on all blobs and their elements to perform a multi opening proof.
|
|
45
45
|
* Used in BatchedBlobAccumulator as 'finalZ' and finalGamma':
|
|
@@ -52,7 +52,7 @@ export declare class BatchedBlob {
|
|
|
52
52
|
* @param blobs - The blobs to precompute the challenges for. Each sub-array is the blobs for an L1 block.
|
|
53
53
|
* @returns Challenges z and gamma.
|
|
54
54
|
*/
|
|
55
|
-
static precomputeBatchedBlobChallenges(
|
|
55
|
+
static precomputeBatchedBlobChallenges(blobFieldsPerCheckpoint: Fr[][]): Promise<FinalBlobBatchingChallenges>;
|
|
56
56
|
verify(): boolean;
|
|
57
57
|
getEthVersionedBlobHash(): Buffer;
|
|
58
58
|
/**
|
|
@@ -124,14 +124,14 @@ export declare class BatchedBlobAccumulator {
|
|
|
124
124
|
* We assume the input blob has not been evaluated at z.
|
|
125
125
|
* @returns An updated blob accumulator.
|
|
126
126
|
*/
|
|
127
|
-
|
|
127
|
+
accumulateBlob(blob: Blob, blobFieldsHash: Fr): Promise<BatchedBlobAccumulator>;
|
|
128
128
|
/**
|
|
129
129
|
* Given blobs, accumulate all state.
|
|
130
130
|
* We assume the input blobs have not been evaluated at z.
|
|
131
|
-
* @param
|
|
131
|
+
* @param blobFields - The blob fields of a checkpoint to accumulate.
|
|
132
132
|
* @returns An updated blob accumulator.
|
|
133
133
|
*/
|
|
134
|
-
|
|
134
|
+
accumulateFields(blobFields: Fr[]): Promise<BatchedBlobAccumulator>;
|
|
135
135
|
/**
|
|
136
136
|
* Finalize accumulation state of the epoch.
|
|
137
137
|
* We assume ALL blobs in the epoch have been accumulated.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob_batching.d.ts","sourceRoot":"","sources":["../src/blob_batching.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAI9G;;GAEG;AACH,qBAAa,WAAW;IAEpB,8CAA8C;aAC9B,mBAAmB,EAAE,EAAE;IACvC,gDAAgD;aAChC,CAAC,EAAE,EAAE;IACrB,mFAAmF;aACnE,CAAC,EAAE,OAAO;IAC1B,kFAAkF;aAClE,UAAU,EAAE,UAAU;IACtC,4HAA4H;aAC5G,CAAC,EAAE,UAAU;;IAT7B,8CAA8C;IAC9B,mBAAmB,EAAE,EAAE;IACvC,gDAAgD;IAChC,CAAC,EAAE,EAAE;IACrB,mFAAmF;IACnE,CAAC,EAAE,OAAO;IAC1B,kFAAkF;IAClE,UAAU,EAAE,UAAU;IACtC,4HAA4H;IAC5G,CAAC,EAAE,UAAU;IAG/B;;;;;;OAMG;WACU,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"blob_batching.d.ts","sourceRoot":"","sources":["../src/blob_batching.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B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AU;IAChC;;;;OAIG;aACa,QAAQ,EAAE,EAAE;IAC5B,uGAAuG;aACvF,QAAQ,EAAE,OAAO;IACjC,oGAAoG;aACpF,mBAAmB,EAAE,2BAA2B;;IAnBhE,8CAA8C;IAC9B,sBAAsB,EAAE,EAAE;IAC1C,sEAAsE;IACtD,IAAI,EAAE,EAAE;IACxB,yGAAyG;IACzF,IAAI,EAAE,OAAO;IAC7B,qGAAqG;IACrF,IAAI,EAAE,UAAU;IAChC,oGAAoG;IACpF,IAAI,EAAE,UAAU;IAChC;;;;OAIG;IACa,QAAQ,EAAE,EAAE;IAC5B,uGAAuG;IACvF,QAAQ,EAAE,OAAO;IACjC,oGAAoG;IACpF,mBAAmB,EAAE,2BAA2B;IAGlE;;;OAGG;IACH,MAAM,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,2BAA2B,GAAG,sBAAsB;IAalG;;;;OAIG;IACG,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE;IAyCnD;;;;;OAKG;IACG,gBAAgB,CAAC,UAAU,EAAE,EAAE,EAAE;IAoBvC;;;;;;;;;;;;;OAaG;IACG,QAAQ,CAAC,WAAW,UAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBzD,YAAY;IAYZ,KAAK;IAaL,iBAAiB;IAWjB,sBAAsB;CAGvB"}
|
package/dest/blob_batching.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AZTEC_MAX_EPOCH_DURATION, BLOBS_PER_CHECKPOINT } from '@aztec/constants';
|
|
2
2
|
import { poseidon2Hash, sha256ToField } from '@aztec/foundation/crypto';
|
|
3
3
|
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
4
|
-
import {
|
|
4
|
+
import { getBlobsPerL1Block } from './blob_utils.js';
|
|
5
5
|
import { BlobAccumulator, FinalBlobAccumulator, FinalBlobBatchingChallenges } from './circuit_types/index.js';
|
|
6
|
-
import { computeEthVersionedBlobHash, hashNoirBigNumLimbs } from './hash.js';
|
|
6
|
+
import { computeBlobFieldsHash, computeEthVersionedBlobHash, hashNoirBigNumLimbs } from './hash.js';
|
|
7
7
|
import { kzg } from './kzg_context.js';
|
|
8
8
|
/**
|
|
9
9
|
* A class to create, manage, and prove batched EVM blobs.
|
|
@@ -26,15 +26,16 @@ import { kzg } from './kzg_context.js';
|
|
|
26
26
|
* beforehand from ALL blobs.
|
|
27
27
|
*
|
|
28
28
|
* @returns A batched blob.
|
|
29
|
-
*/ static async batch(
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
*/ static async batch(blobFieldsPerCheckpoint) {
|
|
30
|
+
const numCheckpoints = blobFieldsPerCheckpoint.length;
|
|
31
|
+
if (numCheckpoints > AZTEC_MAX_EPOCH_DURATION) {
|
|
32
|
+
throw new Error(`Too many checkpoints sent to batch(). The maximum is ${AZTEC_MAX_EPOCH_DURATION}. Got ${numCheckpoints}.`);
|
|
32
33
|
}
|
|
33
34
|
// Precalculate the values (z and gamma) and initialize the accumulator:
|
|
34
|
-
let acc = await this.newAccumulator(
|
|
35
|
+
let acc = await this.newAccumulator(blobFieldsPerCheckpoint);
|
|
35
36
|
// Now we can create a multi opening proof of all input blobs:
|
|
36
|
-
for (const
|
|
37
|
-
acc = await acc.
|
|
37
|
+
for (const blobFields of blobFieldsPerCheckpoint){
|
|
38
|
+
acc = await acc.accumulateFields(blobFields);
|
|
38
39
|
}
|
|
39
40
|
return await acc.finalize();
|
|
40
41
|
}
|
|
@@ -42,8 +43,8 @@ import { kzg } from './kzg_context.js';
|
|
|
42
43
|
* Returns an empty BatchedBlobAccumulator with precomputed challenges from all blobs in the epoch.
|
|
43
44
|
* @dev MUST input all blobs to be broadcast. Does not work in multiple calls because z and gamma are calculated
|
|
44
45
|
* beforehand from ALL blobs.
|
|
45
|
-
*/ static async newAccumulator(
|
|
46
|
-
const finalBlobChallenges = await this.precomputeBatchedBlobChallenges(
|
|
46
|
+
*/ static async newAccumulator(blobFieldsPerCheckpoint) {
|
|
47
|
+
const finalBlobChallenges = await this.precomputeBatchedBlobChallenges(blobFieldsPerCheckpoint);
|
|
47
48
|
return BatchedBlobAccumulator.newWithChallenges(finalBlobChallenges);
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
@@ -57,13 +58,15 @@ import { kzg } from './kzg_context.js';
|
|
|
57
58
|
*
|
|
58
59
|
* @param blobs - The blobs to precompute the challenges for. Each sub-array is the blobs for an L1 block.
|
|
59
60
|
* @returns Challenges z and gamma.
|
|
60
|
-
*/ static async precomputeBatchedBlobChallenges(
|
|
61
|
+
*/ static async precomputeBatchedBlobChallenges(blobFieldsPerCheckpoint) {
|
|
61
62
|
// Compute the final challenge z to evaluate the blobs.
|
|
62
63
|
let z;
|
|
63
|
-
|
|
64
|
+
const allBlobs = [];
|
|
65
|
+
for (const blobFields of blobFieldsPerCheckpoint){
|
|
64
66
|
// Compute the hash of all the fields in the block.
|
|
65
|
-
const blobFieldsHash = await
|
|
66
|
-
|
|
67
|
+
const blobFieldsHash = await computeBlobFieldsHash(blobFields);
|
|
68
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
69
|
+
for (const blob of blobs){
|
|
67
70
|
// Compute the challenge z for each blob and accumulate it.
|
|
68
71
|
const challengeZ = await blob.computeChallengeZ(blobFieldsHash);
|
|
69
72
|
if (!z) {
|
|
@@ -75,12 +78,12 @@ import { kzg } from './kzg_context.js';
|
|
|
75
78
|
]);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
81
|
+
allBlobs.push(...blobs);
|
|
78
82
|
}
|
|
79
83
|
if (!z) {
|
|
80
84
|
throw new Error('No blobs to precompute challenges for.');
|
|
81
85
|
}
|
|
82
86
|
// Now we have a shared challenge for all blobs, evaluate them...
|
|
83
|
-
const allBlobs = blobs.flat();
|
|
84
87
|
const proofObjects = allBlobs.map((b)=>b.evaluate(z));
|
|
85
88
|
const evaluations = await Promise.all(proofObjects.map(({ y })=>hashNoirBigNumLimbs(y)));
|
|
86
89
|
// ...and find the challenge for the linear combination of blobs.
|
|
@@ -164,7 +167,7 @@ import { kzg } from './kzg_context.js';
|
|
|
164
167
|
* Given blob i, accumulate all state.
|
|
165
168
|
* We assume the input blob has not been evaluated at z.
|
|
166
169
|
* @returns An updated blob accumulator.
|
|
167
|
-
*/ async
|
|
170
|
+
*/ async accumulateBlob(blob, blobFieldsHash) {
|
|
168
171
|
const { proof, y: thisY } = blob.evaluate(this.finalBlobChallenges.z);
|
|
169
172
|
const thisC = BLS12Point.decompress(blob.commitment);
|
|
170
173
|
const thisQ = BLS12Point.decompress(proof);
|
|
@@ -198,18 +201,19 @@ import { kzg } from './kzg_context.js';
|
|
|
198
201
|
/**
|
|
199
202
|
* Given blobs, accumulate all state.
|
|
200
203
|
* We assume the input blobs have not been evaluated at z.
|
|
201
|
-
* @param
|
|
204
|
+
* @param blobFields - The blob fields of a checkpoint to accumulate.
|
|
202
205
|
* @returns An updated blob accumulator.
|
|
203
|
-
*/ async
|
|
206
|
+
*/ async accumulateFields(blobFields) {
|
|
207
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
204
208
|
if (blobs.length > BLOBS_PER_CHECKPOINT) {
|
|
205
209
|
throw new Error(`Too many blobs to accumulate. The maximum is ${BLOBS_PER_CHECKPOINT} per checkpoint. Got ${blobs.length}.`);
|
|
206
210
|
}
|
|
207
211
|
// Compute the hash of all the fields in the block.
|
|
208
|
-
const blobFieldsHash = await
|
|
212
|
+
const blobFieldsHash = await computeBlobFieldsHash(blobFields);
|
|
209
213
|
// Initialize the acc to iterate over:
|
|
210
214
|
let acc = this.clone();
|
|
211
215
|
for (const blob of blobs){
|
|
212
|
-
acc = await acc.
|
|
216
|
+
acc = await acc.accumulateBlob(blob, blobFieldsHash);
|
|
213
217
|
}
|
|
214
218
|
return acc;
|
|
215
219
|
}
|
package/dest/blob_utils.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ export declare function getBlobsPerL1Block(fields: Fr[]): Blob[];
|
|
|
21
21
|
* @returns The encoded data of the checkpoint.
|
|
22
22
|
*/
|
|
23
23
|
export declare function decodeCheckpointBlobDataFromBlobs(blobs: Blob[]): CheckpointBlobData;
|
|
24
|
-
export declare function computeBlobFieldsHashFromBlobs(blobs: Blob[]): Promise<Fr>;
|
|
25
24
|
export declare function computeBlobsHashFromBlobs(blobs: Blob[]): Fr;
|
|
26
25
|
export declare function getBlobCommitmentsFromBlobs(blobs: Blob[]): BLS12Point[];
|
|
27
26
|
//# sourceMappingURL=blob_utils.d.ts.map
|
package/dest/blob_utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob_utils.d.ts","sourceRoot":"","sources":["../src/blob_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,kBAAkB,EAAsC,MAAM,qBAAqB,CAAC;AAGlG;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,MAAM,EAAE,CAS1E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CASvD;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAGnF;AAED,
|
|
1
|
+
{"version":3,"file":"blob_utils.d.ts","sourceRoot":"","sources":["../src/blob_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,kBAAkB,EAAsC,MAAM,qBAAqB,CAAC;AAGlG;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,MAAM,EAAE,CAS1E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CASvD;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAGnF;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAE3D;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,CAEvE"}
|
package/dest/blob_utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import { FIELDS_PER_BLOB } from '@aztec/constants';
|
|
|
2
2
|
import { BLS12Point } from '@aztec/foundation/fields';
|
|
3
3
|
import { Blob } from './blob.js';
|
|
4
4
|
import { decodeCheckpointBlobDataFromBuffer } from './encoding/index.js';
|
|
5
|
-
import {
|
|
5
|
+
import { computeBlobsHash } from './hash.js';
|
|
6
6
|
/**
|
|
7
7
|
* @param blobs - The blobs to emit.
|
|
8
8
|
* @returns The blobs' compressed commitments in hex prefixed by the number of blobs. 1 byte for the prefix, 48 bytes
|
|
@@ -41,14 +41,6 @@ import { computeBlobFieldsHash, computeBlobsHash } from './hash.js';
|
|
|
41
41
|
const buf = Buffer.concat(blobs.map((b)=>b.data));
|
|
42
42
|
return decodeCheckpointBlobDataFromBuffer(buf);
|
|
43
43
|
}
|
|
44
|
-
export async function computeBlobFieldsHashFromBlobs(blobs) {
|
|
45
|
-
const fields = blobs.map((b)=>b.toFields()).flat();
|
|
46
|
-
const numBlobFields = fields[0].toNumber();
|
|
47
|
-
if (numBlobFields > fields.length) {
|
|
48
|
-
throw new Error(`The prefix indicates ${numBlobFields} fields. Got ${fields.length}.`);
|
|
49
|
-
}
|
|
50
|
-
return await computeBlobFieldsHash(fields.slice(0, numBlobFields));
|
|
51
|
-
}
|
|
52
44
|
export function computeBlobsHashFromBlobs(blobs) {
|
|
53
45
|
return computeBlobsHash(blobs.map((b)=>b.getEthVersionedBlobHash()));
|
|
54
46
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BLOCK_END_PREFIX } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { BlobDeserializationError } from '../errors.js';
|
|
4
|
-
// Must match the implementation in `noir-protocol-circuits/crates/
|
|
4
|
+
// Must match the implementation in `noir-protocol-circuits/crates/types/src/blob_data/block_blob_data.nr`.
|
|
5
5
|
const BLOCK_NUMBER_BIT_SIZE = 32n;
|
|
6
6
|
const TIMESTAMP_BIT_SIZE = 64n;
|
|
7
7
|
const NUM_TXS_BIT_SIZE = 16n;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { L1_TO_L2_MSG_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { BlobDeserializationError } from '../errors.js';
|
|
4
|
-
// Must match the implementation in `noir-protocol-circuits/crates/
|
|
4
|
+
// Must match the implementation in `noir-protocol-circuits/crates/types/src/blob_data/block_blob_data.nr`.
|
|
5
5
|
export const TOTAL_MANA_USED_BIT_SIZE = 48n;
|
|
6
6
|
export function encodeBlockEndStateField(blockEndStateField) {
|
|
7
7
|
let value = BigInt(blockEndStateField.l1ToL2MessageNextAvailableLeafIndex);
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { FieldReader } from '@aztec/foundation/serialize';
|
|
3
3
|
import { type BlockBlobData } from './block_blob_data.js';
|
|
4
|
+
import { type CheckpointEndMarker } from './checkpoint_end_marker.js';
|
|
4
5
|
import type { TxStartMarker } from './tx_start_marker.js';
|
|
5
6
|
export interface CheckpointBlobData {
|
|
6
|
-
|
|
7
|
+
checkpointEndMarker: CheckpointEndMarker;
|
|
7
8
|
blocks: BlockBlobData[];
|
|
8
9
|
}
|
|
9
10
|
export declare function encodeCheckpointBlobData(checkpointBlobData: CheckpointBlobData): Fr[];
|
|
11
|
+
export declare function encodeCheckpointBlobDataFromBlocks(blocks: BlockBlobData[]): Fr[];
|
|
10
12
|
export declare function decodeCheckpointBlobData(fields: Fr[] | FieldReader): CheckpointBlobData;
|
|
11
13
|
export declare function decodeCheckpointBlobDataFromBuffer(buf: Buffer): CheckpointBlobData;
|
|
12
|
-
export declare function getTotalNumBlobFieldsFromTxs(
|
|
14
|
+
export declare function getTotalNumBlobFieldsFromTxs(txsPerBlock: TxStartMarker[][]): number;
|
|
13
15
|
//# sourceMappingURL=checkpoint_blob_data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoint_blob_data.d.ts","sourceRoot":"","sources":["../../src/encoding/checkpoint_blob_data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAgB,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EAAE,KAAK,aAAa,EAA4C,MAAM,sBAAsB,CAAC;AACpG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,WAAW,kBAAkB;IACjC,
|
|
1
|
+
{"version":3,"file":"checkpoint_blob_data.d.ts","sourceRoot":"","sources":["../../src/encoding/checkpoint_blob_data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAgB,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EAAE,KAAK,aAAa,EAA4C,MAAM,sBAAsB,CAAC;AACpG,OAAO,EACL,KAAK,mBAAmB,EAIzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,WAAW,kBAAkB;IACjC,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;AAED,wBAAgB,wBAAwB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,EAAE,EAAE,CAKrF;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,CAIhF;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,kBAAkB,CA0CvF;AAED,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAKlF;AAED,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,aAAa,EAAE,EAAE,GAAG,MAAM,CAYnF"}
|
|
@@ -2,53 +2,66 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
3
|
import { BlobDeserializationError } from '../errors.js';
|
|
4
4
|
import { decodeBlockBlobData, encodeBlockBlobData } from './block_blob_data.js';
|
|
5
|
+
import { decodeCheckpointEndMarker, encodeCheckpointEndMarker, isCheckpointEndMarker } from './checkpoint_end_marker.js';
|
|
5
6
|
export function encodeCheckpointBlobData(checkpointBlobData) {
|
|
6
7
|
return [
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
...checkpointBlobData.blocks.map((block)=>encodeBlockBlobData(block)).flat(),
|
|
9
|
+
encodeCheckpointEndMarker(checkpointBlobData.checkpointEndMarker)
|
|
9
10
|
];
|
|
10
11
|
}
|
|
12
|
+
export function encodeCheckpointBlobDataFromBlocks(blocks) {
|
|
13
|
+
const blocksBlobFields = blocks.map((block)=>encodeBlockBlobData(block)).flat();
|
|
14
|
+
const numBlobFields = blocksBlobFields.length + 1; // +1 for the checkpoint end marker.
|
|
15
|
+
return blocksBlobFields.concat(encodeCheckpointEndMarker({
|
|
16
|
+
numBlobFields
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
11
19
|
export function decodeCheckpointBlobData(fields) {
|
|
12
20
|
const reader = FieldReader.asReader(fields);
|
|
13
21
|
if (reader.isFinished()) {
|
|
14
22
|
throw new BlobDeserializationError(`Cannot decode empty blob data.`);
|
|
15
23
|
}
|
|
16
|
-
const firstField = reader.readField();
|
|
17
|
-
// Use toBigInt instead of toNumber so that we can catch it and throw a more descriptive error if the first field is
|
|
18
|
-
// larger than a javascript integer.
|
|
19
|
-
const totalNumBlobFields = firstField.toBigInt();
|
|
20
|
-
if (totalNumBlobFields > BigInt(reader.remainingFields() + 1)) {
|
|
21
|
-
// +1 because we already read the first field.
|
|
22
|
-
throw new BlobDeserializationError(`Incorrect encoding of blob fields: not enough fields for checkpoint blob data. Expected ${totalNumBlobFields} fields, got ${reader.remainingFields() + 1}.`);
|
|
23
|
-
}
|
|
24
24
|
const blocks = [];
|
|
25
|
-
|
|
25
|
+
let checkpointEndMarker;
|
|
26
|
+
while(!reader.isFinished() && !checkpointEndMarker){
|
|
26
27
|
blocks.push(decodeBlockBlobData(reader, blocks.length === 0 /* isFirstBlock */ ));
|
|
28
|
+
// After reading a block, the next item must be either a checkpoint end marker or another block.
|
|
29
|
+
// The first field of a block is always a tx start marker. So if the provided fields are valid, it's not possible to
|
|
30
|
+
// misinterpret a tx start marker as checkpoint end marker, or vice versa.
|
|
31
|
+
const nextField = reader.peekField();
|
|
32
|
+
if (isCheckpointEndMarker(nextField)) {
|
|
33
|
+
checkpointEndMarker = decodeCheckpointEndMarker(reader.readField());
|
|
34
|
+
const numFieldsRead = reader.cursor;
|
|
35
|
+
if (numFieldsRead !== checkpointEndMarker.numBlobFields) {
|
|
36
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: mismatch number of blob fields. Expected ${checkpointEndMarker.numBlobFields} fields, got ${numFieldsRead}.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!checkpointEndMarker) {
|
|
41
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: checkpoint end marker does not exist.`);
|
|
42
|
+
}
|
|
43
|
+
const remainingFields = reader.readFieldArray(reader.remainingFields());
|
|
44
|
+
if (!remainingFields.every((f)=>f.isZero())) {
|
|
45
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: unexpected non-zero field after checkpoint end marker.`);
|
|
27
46
|
}
|
|
28
47
|
return {
|
|
29
|
-
|
|
48
|
+
checkpointEndMarker,
|
|
30
49
|
blocks
|
|
31
50
|
};
|
|
32
51
|
}
|
|
33
52
|
export function decodeCheckpointBlobDataFromBuffer(buf) {
|
|
34
53
|
const reader = BufferReader.asReader(buf);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
// larger than a javascript integer.
|
|
38
|
-
const numFields = firstField.toBigInt();
|
|
39
|
-
const totalFieldsInBuffer = BigInt(buf.length / Fr.SIZE_IN_BYTES);
|
|
40
|
-
if (numFields > totalFieldsInBuffer) {
|
|
41
|
-
throw new BlobDeserializationError(`Failed to deserialize blob buffer: not enough fields for checkpoint blob data. Expected ${numFields} fields, got ${totalFieldsInBuffer}.`);
|
|
42
|
-
}
|
|
43
|
-
const numFieldsWithoutPrefix = Number(numFields) - 1;
|
|
44
|
-
const blobFields = [
|
|
45
|
-
firstField
|
|
46
|
-
].concat(reader.readArray(numFieldsWithoutPrefix, Fr));
|
|
54
|
+
const totalFieldsInBuffer = Math.floor(buf.length / Fr.SIZE_IN_BYTES);
|
|
55
|
+
const blobFields = reader.readArray(totalFieldsInBuffer, Fr);
|
|
47
56
|
return decodeCheckpointBlobData(blobFields);
|
|
48
57
|
}
|
|
49
|
-
export function getTotalNumBlobFieldsFromTxs(
|
|
50
|
-
|
|
51
|
-
(
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
export function getTotalNumBlobFieldsFromTxs(txsPerBlock) {
|
|
59
|
+
const numBlocks = txsPerBlock.length;
|
|
60
|
+
if (!numBlocks) {
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
return (numBlocks ? 1 : 0) + // l1ToL2Messages root in the first block
|
|
64
|
+
numBlocks * 6 + // 6 fields for each block end blob data.
|
|
65
|
+
txsPerBlock.reduce((total, txs)=>total + txs.reduce((total, tx)=>total + tx.numBlobFields, 0), 0) + 1 // checkpoint end marker
|
|
66
|
+
;
|
|
54
67
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
export interface CheckpointEndMarker {
|
|
3
|
+
numBlobFields: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function encodeCheckpointEndMarker(checkpointEndMarker: CheckpointEndMarker): Fr;
|
|
6
|
+
export declare function decodeCheckpointEndMarker(field: Fr): CheckpointEndMarker;
|
|
7
|
+
export declare function isCheckpointEndMarker(field: Fr): boolean;
|
|
8
|
+
//# sourceMappingURL=checkpoint_end_marker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint_end_marker.d.ts","sourceRoot":"","sources":["../../src/encoding/checkpoint_end_marker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAQ9C,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,yBAAyB,CAAC,mBAAmB,EAAE,mBAAmB,MAKjF;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,EAAE,GAAG,mBAAmB,CAaxE;AAGD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,EAAE,GAAG,OAAO,CAGxD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CHECKPOINT_END_PREFIX } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BlobDeserializationError } from '../errors.js';
|
|
4
|
+
// Must match the implementation in `noir-protocol-circuits/crates/types/src/blob_data/checkpoint_blob_data.nr`.
|
|
5
|
+
const NUM_BLOB_FIELDS_BIT_SIZE = 32n;
|
|
6
|
+
export function encodeCheckpointEndMarker(checkpointEndMarker) {
|
|
7
|
+
let value = CHECKPOINT_END_PREFIX;
|
|
8
|
+
value <<= NUM_BLOB_FIELDS_BIT_SIZE;
|
|
9
|
+
value += BigInt(checkpointEndMarker.numBlobFields);
|
|
10
|
+
return new Fr(value);
|
|
11
|
+
}
|
|
12
|
+
export function decodeCheckpointEndMarker(field) {
|
|
13
|
+
let value = field.toBigInt();
|
|
14
|
+
const numBlobFields = Number(value & 2n ** NUM_BLOB_FIELDS_BIT_SIZE - 1n);
|
|
15
|
+
value >>= NUM_BLOB_FIELDS_BIT_SIZE;
|
|
16
|
+
const prefix = value;
|
|
17
|
+
if (prefix !== CHECKPOINT_END_PREFIX) {
|
|
18
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: invalid checkpoint end marker.`);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
numBlobFields
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// Check if a field is a checkpoint end marker. Used to check if it has reached the end of the blob fields.
|
|
25
|
+
export function isCheckpointEndMarker(field) {
|
|
26
|
+
const prefix = field.toBigInt() >> NUM_BLOB_FIELDS_BIT_SIZE;
|
|
27
|
+
return prefix === CHECKPOINT_END_PREFIX;
|
|
28
|
+
}
|
|
@@ -129,9 +129,11 @@ export function makeCheckpointBlobData({ numBlocks = 1, numTxsPerBlock = 1, isFu
|
|
|
129
129
|
isFullTx,
|
|
130
130
|
seed: seed + i * 0x1000
|
|
131
131
|
}), seed);
|
|
132
|
-
const
|
|
132
|
+
const numBlobFields = overrides.checkpointEndMarker?.numBlobFields ?? getTotalNumBlobFieldsFromTxs(blocks.map((block)=>block.txs.map((tx)=>tx.txStartMarker)));
|
|
133
133
|
return {
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
blocks,
|
|
135
|
+
checkpointEndMarker: {
|
|
136
|
+
numBlobFields
|
|
137
|
+
}
|
|
136
138
|
};
|
|
137
139
|
}
|
package/dest/encoding/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './block_blob_data.js';
|
|
|
2
2
|
export * from './block_end_marker.js';
|
|
3
3
|
export * from './block_end_state_field.js';
|
|
4
4
|
export * from './checkpoint_blob_data.js';
|
|
5
|
+
export * from './checkpoint_end_marker.js';
|
|
5
6
|
export * from './fixtures.js';
|
|
6
7
|
export * from './tx_blob_data.js';
|
|
7
8
|
export * from './tx_start_marker.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encoding/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encoding/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
package/dest/encoding/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './block_blob_data.js';
|
|
|
2
2
|
export * from './block_end_marker.js';
|
|
3
3
|
export * from './block_end_state_field.js';
|
|
4
4
|
export * from './checkpoint_blob_data.js';
|
|
5
|
+
export * from './checkpoint_end_marker.js';
|
|
5
6
|
export * from './fixtures.js';
|
|
6
7
|
export * from './tx_blob_data.js';
|
|
7
8
|
export * from './tx_start_marker.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TX_START_PREFIX } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { BlobDeserializationError } from '../errors.js';
|
|
4
|
-
// Must match the implementation in `noir-protocol-circuits/crates/
|
|
4
|
+
// Must match the implementation in `noir-protocol-circuits/crates/types/src/blob_data/tx_blob_data.nr`.
|
|
5
5
|
const NUM_BLOB_FIELDS_BIT_SIZE = 32n;
|
|
6
6
|
const REVERT_CODE_BIT_SIZE = 8n;
|
|
7
7
|
const NUM_NOTE_HASH_BIT_SIZE = 16n;
|
package/dest/hash.d.ts
CHANGED
|
@@ -5,9 +5,16 @@ import { BLS12Fr, Fr } from '@aztec/foundation/fields';
|
|
|
5
5
|
export declare function computeEthVersionedBlobHash(commitment: Buffer): Buffer;
|
|
6
6
|
export declare function computeBlobsHash(evmVersionedBlobHashes: Buffer[]): Fr;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* This
|
|
8
|
+
* Computes a non-standard Poseidon2 hash over the provided fields.
|
|
9
|
+
*
|
|
10
|
+
* This function is used to compute:
|
|
11
|
+
* - `blobFieldsHash` of a checkpoint:
|
|
12
|
+
* Verified in the circuit against all fields absorbed into the blob sponge over the entire checkpoint.
|
|
13
|
+
* The exact number of fields is encoded in the checkpoint end marker (the last field).
|
|
14
|
+
* This hash is used when generating the challenge `z` for all blobs in the checkpoint.
|
|
15
|
+
* - `spongeBlobHash` of a block:
|
|
16
|
+
* Computed from the block's tx effects, its end-state, and the blob fields of all prior blocks in the same checkpoint.
|
|
17
|
+
* This hash is included in the block header.
|
|
11
18
|
*/
|
|
12
19
|
export declare function computeBlobFieldsHash(fields: Fr[]): Promise<Fr>;
|
|
13
20
|
export declare function computeBlobCommitment(data: Uint8Array): Buffer;
|
package/dest/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAOvD;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAItE;AAOD,wBAAgB,gBAAgB,CAAC,sBAAsB,EAAE,MAAM,EAAE,GAAG,EAAE,CAErE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAIrE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAM9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAM/D;AAED,wBAAsB,iBAAiB,CAAC,cAAc,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,CAG3F;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAGrE"}
|
package/dest/hash.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { poseidon2Hash, sha256, sha256ToField } from '@aztec/foundation/crypto';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, kzg } from './kzg_context.js';
|
|
4
|
+
import { SpongeBlob } from './sponge_blob.js';
|
|
4
5
|
const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
5
6
|
/**
|
|
6
7
|
* Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
|
|
@@ -18,11 +19,20 @@ export function computeBlobsHash(evmVersionedBlobHashes) {
|
|
|
18
19
|
return sha256ToField(evmVersionedBlobHashes);
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* This
|
|
22
|
+
* Computes a non-standard Poseidon2 hash over the provided fields.
|
|
23
|
+
*
|
|
24
|
+
* This function is used to compute:
|
|
25
|
+
* - `blobFieldsHash` of a checkpoint:
|
|
26
|
+
* Verified in the circuit against all fields absorbed into the blob sponge over the entire checkpoint.
|
|
27
|
+
* The exact number of fields is encoded in the checkpoint end marker (the last field).
|
|
28
|
+
* This hash is used when generating the challenge `z` for all blobs in the checkpoint.
|
|
29
|
+
* - `spongeBlobHash` of a block:
|
|
30
|
+
* Computed from the block's tx effects, its end-state, and the blob fields of all prior blocks in the same checkpoint.
|
|
31
|
+
* This hash is included in the block header.
|
|
24
32
|
*/ export async function computeBlobFieldsHash(fields) {
|
|
25
|
-
|
|
33
|
+
const sponge = SpongeBlob.init();
|
|
34
|
+
await sponge.absorb(fields);
|
|
35
|
+
return sponge.squeeze();
|
|
26
36
|
}
|
|
27
37
|
export function computeBlobCommitment(data) {
|
|
28
38
|
if (data.length !== BYTES_PER_BLOB) {
|
package/dest/sponge_blob.d.ts
CHANGED
|
@@ -10,15 +10,16 @@ export declare class SpongeBlob {
|
|
|
10
10
|
readonly sponge: Poseidon2Sponge;
|
|
11
11
|
/** Number of effects absorbed so far. */
|
|
12
12
|
numAbsorbedFields: number;
|
|
13
|
-
|
|
14
|
-
readonly numExpectedFields: number;
|
|
13
|
+
static MAX_FIELDS: number;
|
|
15
14
|
constructor(
|
|
16
15
|
/** Sponge with absorbed fields that will go into one or more blobs. */
|
|
17
16
|
sponge: Poseidon2Sponge,
|
|
18
17
|
/** Number of effects absorbed so far. */
|
|
19
|
-
numAbsorbedFields: number
|
|
20
|
-
/**
|
|
21
|
-
|
|
18
|
+
numAbsorbedFields: number);
|
|
19
|
+
/**
|
|
20
|
+
* Initialize the sponge blob to absorb data for a checkpoint.
|
|
21
|
+
*/
|
|
22
|
+
static init(): SpongeBlob;
|
|
22
23
|
static fromBuffer(buffer: Buffer | BufferReader): SpongeBlob;
|
|
23
24
|
toBuffer(): Buffer<ArrayBufferLike>;
|
|
24
25
|
static getFields(fields: FieldsOf<SpongeBlob>): (number | Poseidon2Sponge)[];
|
|
@@ -28,11 +29,6 @@ export declare class SpongeBlob {
|
|
|
28
29
|
absorb(fields: Fr[]): Promise<void>;
|
|
29
30
|
squeeze(): Promise<Fr>;
|
|
30
31
|
static empty(): SpongeBlob;
|
|
31
|
-
/**
|
|
32
|
-
* Initialize the sponge blob with the number of expected fields in the checkpoint and absorb it as the first field.
|
|
33
|
-
* Note: `numExpectedFields` includes the first field absorbed in this method.
|
|
34
|
-
*/
|
|
35
|
-
static init(numExpectedFields: number): Promise<SpongeBlob>;
|
|
36
32
|
}
|
|
37
33
|
export declare class Poseidon2Sponge {
|
|
38
34
|
cache: Tuple<Fr, 3>;
|
|
@@ -46,7 +42,7 @@ export declare class Poseidon2Sponge {
|
|
|
46
42
|
toFields(): Fr[];
|
|
47
43
|
static fromFields(fields: Fr[] | FieldReader): Poseidon2Sponge;
|
|
48
44
|
static empty(): Poseidon2Sponge;
|
|
49
|
-
static init(
|
|
45
|
+
static init(iv: Fr): Poseidon2Sponge;
|
|
50
46
|
performDuplex(): Promise<void>;
|
|
51
47
|
absorb(fields: Fr[]): Promise<void>;
|
|
52
48
|
squeeze(): Promise<Fr>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sponge_blob.d.ts","sourceRoot":"","sources":["../src/sponge_blob.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAa,MAAM,yBAAyB,CAAC;AAEnE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,WAAW,EACX,KAAK,KAAK,EAGX,MAAM,6BAA6B,CAAC;AAErC;;;GAGG;AACH,qBAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"sponge_blob.d.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