@aztec/blob-lib 3.0.0-devnet.5 → 3.0.0-devnet.6-patch.1
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 +6 -11
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +5 -2
- package/dest/blob_batching.d.ts +35 -84
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +73 -108
- package/dest/blob_utils.d.ts +21 -11
- package/dest/blob_utils.d.ts.map +1 -1
- package/dest/blob_utils.js +29 -20
- package/dest/circuit_types/blob_accumulator.d.ts +4 -2
- package/dest/circuit_types/blob_accumulator.d.ts.map +1 -1
- package/dest/circuit_types/blob_accumulator.js +5 -1
- package/dest/circuit_types/final_blob_accumulator.d.ts +3 -2
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -1
- package/dest/circuit_types/final_blob_accumulator.js +2 -1
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +3 -2
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -1
- package/dest/circuit_types/final_blob_batching_challenges.js +2 -1
- package/dest/circuit_types/index.d.ts +1 -1
- 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.js → encoding/tx_start_marker.js} +13 -59
- package/dest/errors.d.ts +1 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/hash.d.ts +13 -5
- package/dest/hash.d.ts.map +1 -1
- package/dest/hash.js +19 -8
- package/dest/index.d.ts +4 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -3
- package/dest/interface.d.ts +1 -1
- package/dest/kzg_context.d.ts +6 -2
- package/dest/kzg_context.d.ts.map +1 -1
- package/dest/kzg_context.js +12 -3
- package/dest/sponge_blob.d.ts +9 -15
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +21 -36
- package/dest/testing.d.ts +8 -16
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +35 -64
- package/dest/types.d.ts +2 -1
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +1 -0
- package/package.json +8 -7
- package/src/batched_blob.ts +26 -0
- package/src/blob.ts +5 -2
- package/src/blob_batching.ts +91 -126
- package/src/blob_utils.ts +33 -22
- package/src/circuit_types/blob_accumulator.ts +13 -1
- package/src/circuit_types/final_blob_accumulator.ts +2 -1
- package/src/circuit_types/final_blob_batching_challenges.ts +2 -1
- 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.ts → encoding/tx_start_marker.ts} +19 -76
- package/src/hash.ts +20 -8
- package/src/index.ts +3 -3
- package/src/kzg_context.ts +12 -1
- package/src/sponge_blob.ts +23 -36
- package/src/testing.ts +47 -73
- package/src/types.ts +1 -0
- package/dest/deserialize.d.ts +0 -14
- package/dest/deserialize.d.ts.map +0 -1
- package/dest/deserialize.js +0 -33
- package/dest/encoding.d.ts +0 -26
- package/dest/encoding.d.ts.map +0 -1
- package/src/deserialize.ts +0 -38
package/src/kzg_context.ts
CHANGED
|
@@ -2,4 +2,15 @@ import { DasContextJs } from '@crate-crypto/node-eth-kzg';
|
|
|
2
2
|
|
|
3
3
|
export * from '@crate-crypto/node-eth-kzg';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
let kzgInstance: DasContextJs | undefined;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the lazily-initialized KZG context.
|
|
9
|
+
* The first call takes ~3 seconds to initialize the precomputation tables.
|
|
10
|
+
*/
|
|
11
|
+
export function getKzg(): DasContextJs {
|
|
12
|
+
if (!kzgInstance) {
|
|
13
|
+
kzgInstance = DasContextJs.create({ usePrecomp: true });
|
|
14
|
+
}
|
|
15
|
+
return kzgInstance;
|
|
16
|
+
}
|
package/src/sponge_blob.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TWO_POW_64 } from '@aztec/constants';
|
|
1
|
+
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, TWO_POW_64 } from '@aztec/constants';
|
|
2
2
|
import { type FieldsOf, makeTuple } from '@aztec/foundation/array';
|
|
3
|
-
import { poseidon2Permutation } from '@aztec/foundation/crypto';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import { poseidon2Permutation } from '@aztec/foundation/crypto/poseidon';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import {
|
|
6
6
|
BufferReader,
|
|
7
7
|
FieldReader,
|
|
@@ -15,18 +15,28 @@ import {
|
|
|
15
15
|
* See noir-projects/noir-protocol-circuits/crates/types/src/abis/sponge_blob.nr.
|
|
16
16
|
*/
|
|
17
17
|
export class SpongeBlob {
|
|
18
|
+
static MAX_FIELDS = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB;
|
|
19
|
+
|
|
18
20
|
constructor(
|
|
19
21
|
/** Sponge with absorbed fields that will go into one or more blobs. */
|
|
20
22
|
public readonly sponge: Poseidon2Sponge,
|
|
21
23
|
/** Number of effects absorbed so far. */
|
|
22
24
|
public numAbsorbedFields: number,
|
|
23
|
-
/** Number of effects that will be absorbed. */
|
|
24
|
-
public readonly numExpectedFields: number,
|
|
25
25
|
) {}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Initialize the sponge blob to absorb data for a checkpoint.
|
|
29
|
+
*/
|
|
30
|
+
static init(): SpongeBlob {
|
|
31
|
+
// This must match the implementation in noir-projects/noir-protocol-circuits/types/src/abis/sponge_blob.nr
|
|
32
|
+
const iv = new Fr(BigInt(SpongeBlob.MAX_FIELDS) * TWO_POW_64);
|
|
33
|
+
const sponge = Poseidon2Sponge.init(iv);
|
|
34
|
+
return new SpongeBlob(sponge, 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
static fromBuffer(buffer: Buffer | BufferReader): SpongeBlob {
|
|
28
38
|
const reader = BufferReader.asReader(buffer);
|
|
29
|
-
return new SpongeBlob(reader.readObject(Poseidon2Sponge), reader.readNumber()
|
|
39
|
+
return new SpongeBlob(reader.readObject(Poseidon2Sponge), reader.readNumber());
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
toBuffer() {
|
|
@@ -34,7 +44,7 @@ export class SpongeBlob {
|
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
static getFields(fields: FieldsOf<SpongeBlob>) {
|
|
37
|
-
return [fields.sponge, fields.numAbsorbedFields
|
|
47
|
+
return [fields.sponge, fields.numAbsorbedFields];
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
toFields(): Fr[] {
|
|
@@ -43,11 +53,7 @@ export class SpongeBlob {
|
|
|
43
53
|
|
|
44
54
|
static fromFields(fields: Fr[] | FieldReader): SpongeBlob {
|
|
45
55
|
const reader = FieldReader.asReader(fields);
|
|
46
|
-
return new SpongeBlob(
|
|
47
|
-
reader.readObject(Poseidon2Sponge),
|
|
48
|
-
reader.readField().toNumber(),
|
|
49
|
-
reader.readField().toNumber(),
|
|
50
|
-
);
|
|
56
|
+
return new SpongeBlob(reader.readObject(Poseidon2Sponge), reader.readField().toNumber());
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
clone() {
|
|
@@ -55,9 +61,9 @@ export class SpongeBlob {
|
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
async absorb(fields: Fr[]) {
|
|
58
|
-
if (this.numAbsorbedFields + fields.length >
|
|
64
|
+
if (this.numAbsorbedFields + fields.length > SpongeBlob.MAX_FIELDS) {
|
|
59
65
|
throw new Error(
|
|
60
|
-
`Attempted to fill spongeBlob with ${this.numAbsorbedFields + fields.length}, but it has a max of ${
|
|
66
|
+
`Attempted to fill spongeBlob with ${this.numAbsorbedFields + fields.length}, but it has a max of ${SpongeBlob.MAX_FIELDS}`,
|
|
61
67
|
);
|
|
62
68
|
}
|
|
63
69
|
await this.sponge.absorb(fields);
|
|
@@ -65,29 +71,11 @@ export class SpongeBlob {
|
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
async squeeze(): Promise<Fr> {
|
|
68
|
-
|
|
69
|
-
// NB: There is currently no use case in which we don't 'fill' a blob sponge, but adding for completeness
|
|
70
|
-
if (this.numAbsorbedFields != this.numExpectedFields) {
|
|
71
|
-
await this.sponge.absorb([Fr.ONE]);
|
|
72
|
-
}
|
|
73
|
-
return this.sponge.squeeze();
|
|
74
|
+
return await this.sponge.squeeze();
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
static empty(): SpongeBlob {
|
|
77
|
-
return new SpongeBlob(Poseidon2Sponge.empty(), 0
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Initialize the sponge blob with the number of expected fields in the checkpoint and absorb it as the first field.
|
|
82
|
-
* Note: `numExpectedFields` includes the first field absorbed in this method.
|
|
83
|
-
*/
|
|
84
|
-
static async init(numExpectedFields: number): Promise<SpongeBlob> {
|
|
85
|
-
// This must match what the checkpoint root rollup circuit expects.
|
|
86
|
-
// See noir-projects/noir-protocol-circuits/types/src/abis/sponge_blob.nr -> init_for_checkpoint.
|
|
87
|
-
const sponge = Poseidon2Sponge.init(numExpectedFields);
|
|
88
|
-
await sponge.absorb([new Fr(numExpectedFields)]);
|
|
89
|
-
const numAbsorbedFields = 1;
|
|
90
|
-
return new SpongeBlob(sponge, numAbsorbedFields, numExpectedFields);
|
|
78
|
+
return new SpongeBlob(Poseidon2Sponge.empty(), 0);
|
|
91
79
|
}
|
|
92
80
|
}
|
|
93
81
|
|
|
@@ -141,8 +129,7 @@ export class Poseidon2Sponge {
|
|
|
141
129
|
);
|
|
142
130
|
}
|
|
143
131
|
|
|
144
|
-
static init(
|
|
145
|
-
const iv = new Fr(numExpectedFields).mul(new Fr(TWO_POW_64));
|
|
132
|
+
static init(iv: Fr): Poseidon2Sponge {
|
|
146
133
|
const sponge = Poseidon2Sponge.empty();
|
|
147
134
|
sponge.state[3] = iv;
|
|
148
135
|
return sponge;
|
package/src/testing.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { FIELDS_PER_BLOB } from '@aztec/constants';
|
|
2
1
|
import { makeTuple } from '@aztec/foundation/array';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { BLS12Fq, BLS12Fr, BLS12Point, BLSPointNotOnCurveError } from '@aztec/foundation/curves/bls12';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
4
|
|
|
6
5
|
import { Blob } from './blob.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { FinalBlobBatchingChallenges } from './circuit_types/
|
|
10
|
-
import { createBlockEndMarker, encodeTxStartMarker } from './encoding.js';
|
|
6
|
+
import { BlobAccumulator } from './circuit_types/blob_accumulator.js';
|
|
7
|
+
import { FinalBlobAccumulator } from './circuit_types/final_blob_accumulator.js';
|
|
8
|
+
import { FinalBlobBatchingChallenges } from './circuit_types/final_blob_batching_challenges.js';
|
|
11
9
|
import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
12
10
|
|
|
11
|
+
export * from './encoding/fixtures.js';
|
|
12
|
+
|
|
13
13
|
/**
|
|
14
14
|
* Makes arbitrary poseidon sponge for blob inputs.
|
|
15
15
|
* Note: will not verify inside the circuit.
|
|
@@ -25,87 +25,61 @@ export function makeSpongeBlob(seed = 1): SpongeBlob {
|
|
|
25
25
|
false,
|
|
26
26
|
),
|
|
27
27
|
seed,
|
|
28
|
-
seed + 1,
|
|
29
28
|
);
|
|
30
29
|
}
|
|
31
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Makes an arbitrary but valid BLS12 point. The value is deterministic for a given seed.
|
|
33
|
+
* @param seed - The seed to use for generating the point.
|
|
34
|
+
* @returns A BLS12 point instance.
|
|
35
|
+
*/
|
|
36
|
+
function makeBLS12Point(seed = 1): BLS12Point {
|
|
37
|
+
let accum = 0;
|
|
38
|
+
while (true) {
|
|
39
|
+
try {
|
|
40
|
+
const x = new BLS12Fq(seed + accum);
|
|
41
|
+
const y = BLS12Point.YFromX(x);
|
|
42
|
+
if (y) {
|
|
43
|
+
return new BLS12Point(x, y, false);
|
|
44
|
+
}
|
|
45
|
+
accum++;
|
|
46
|
+
} catch (e: any) {
|
|
47
|
+
if (!(e instanceof BLSPointNotOnCurveError)) {
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
// The point is not on the curve - try again
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
/**
|
|
33
56
|
* Makes arbitrary blob public accumulator.
|
|
34
57
|
* Note: will not verify inside the circuit.
|
|
35
58
|
* @param seed - The seed to use for generating the blob accumulator.
|
|
36
59
|
* @returns A blob accumulator instance.
|
|
37
60
|
*/
|
|
38
|
-
export function
|
|
39
|
-
return new
|
|
61
|
+
export function makeBlobAccumulator(seed = 1): BlobAccumulator {
|
|
62
|
+
return new BlobAccumulator(
|
|
40
63
|
new Fr(seed),
|
|
41
|
-
new Fr(seed +
|
|
42
|
-
new BLS12Fr(seed +
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
new
|
|
46
|
-
new BLS12Fr(seed + 4),
|
|
47
|
-
new FinalBlobBatchingChallenges(new Fr(seed + 5), new BLS12Fr(seed + 6)),
|
|
64
|
+
new Fr(seed + 0x10),
|
|
65
|
+
new BLS12Fr(seed + 0x20),
|
|
66
|
+
makeBLS12Point(seed + 0x30),
|
|
67
|
+
new Fr(seed + 0x50),
|
|
68
|
+
new BLS12Fr(seed + 0x60),
|
|
48
69
|
);
|
|
49
70
|
}
|
|
50
71
|
|
|
51
|
-
export function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
numNoteHashes: 0,
|
|
59
|
-
numNullifiers: 0,
|
|
60
|
-
numL2ToL1Msgs: 0,
|
|
61
|
-
numPublicDataWrites: 0,
|
|
62
|
-
numPrivateLogs: 0,
|
|
63
|
-
publicLogsLength: 0,
|
|
64
|
-
contractClassLogLength: 0,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return [
|
|
68
|
-
encodeTxStartMarker(txStartMarker),
|
|
69
|
-
...Array.from({ length: length - 1 }, () => new Fr(randomInt(Number.MAX_SAFE_INTEGER))), // -1 to account for the tx start marker.
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function makeEncodedBlockBlobFields(...lengths: number[]): Fr[] {
|
|
74
|
-
return [
|
|
75
|
-
...(lengths.length > 0 ? makeEncodedTxBlobFields(lengths[0] - 1) : []), // -1 to account for the block end marker.
|
|
76
|
-
...lengths.slice(1).flatMap(length => makeEncodedTxBlobFields(length)),
|
|
77
|
-
createBlockEndMarker(lengths.length),
|
|
78
|
-
];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Create blob fields for a checkpoint with a single block.
|
|
82
|
-
export function makeEncodedBlobFields(length: number): Fr[] {
|
|
83
|
-
if (length <= 2) {
|
|
84
|
-
throw new Error('Encoded blob fields length must be greater than 2');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const checkpointPrefix = new Fr(length);
|
|
88
|
-
return [checkpointPrefix, ...makeEncodedBlockBlobFields(length - 1)]; // -1 to account for the checkpoint prefix.
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Make an encoded blob with the given length
|
|
93
|
-
*
|
|
94
|
-
* This will deserialise correctly in the archiver
|
|
95
|
-
* @param length
|
|
96
|
-
* @returns
|
|
97
|
-
*/
|
|
98
|
-
export function makeEncodedBlob(length: number): Blob {
|
|
99
|
-
if (length > FIELDS_PER_BLOB) {
|
|
100
|
-
throw new Error(`A single encoded blob must be less than ${FIELDS_PER_BLOB} fields`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return Blob.fromFields(makeEncodedBlobFields(length));
|
|
72
|
+
export function makeFinalBlobAccumulator(seed = 1) {
|
|
73
|
+
return new FinalBlobAccumulator(
|
|
74
|
+
new Fr(seed),
|
|
75
|
+
new Fr(seed + 0x10),
|
|
76
|
+
new BLS12Fr(seed + 0x20),
|
|
77
|
+
makeBLS12Point(seed + 0x30),
|
|
78
|
+
);
|
|
104
79
|
}
|
|
105
80
|
|
|
106
|
-
export function
|
|
107
|
-
|
|
108
|
-
return getBlobsPerL1Block(fields);
|
|
81
|
+
export function makeFinalBlobBatchingChallenges(seed = 1) {
|
|
82
|
+
return new FinalBlobBatchingChallenges(new Fr(seed), new BLS12Fr(seed + 0x10));
|
|
109
83
|
}
|
|
110
84
|
|
|
111
85
|
/**
|
package/src/types.ts
CHANGED
package/dest/deserialize.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
/**
|
|
3
|
-
* Deserializes a buffer into an array of field elements.
|
|
4
|
-
*
|
|
5
|
-
* This function returns the fields that were actually added in a checkpoint. The number of fields is specified by the
|
|
6
|
-
* first field.
|
|
7
|
-
*
|
|
8
|
-
* @param buf - The buffer to deserialize.
|
|
9
|
-
* @param checkEncoding - Whether to check if the encoding is correct. If false, it will still check the checkpoint
|
|
10
|
-
* prefix and throw if there's not enough fields.
|
|
11
|
-
* @returns An array of field elements.
|
|
12
|
-
*/
|
|
13
|
-
export declare function deserializeEncodedBlobToFields(buf: Uint8Array, checkEncoding?: boolean): Fr[];
|
|
14
|
-
//# sourceMappingURL=deserialize.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../src/deserialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAM9C;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,UAAU,EAAE,aAAa,UAAQ,GAAG,EAAE,EAAE,CAoB3F"}
|
package/dest/deserialize.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
-
import { checkBlobFieldsEncoding } from './encoding.js';
|
|
4
|
-
import { BlobDeserializationError } from './errors.js';
|
|
5
|
-
/**
|
|
6
|
-
* Deserializes a buffer into an array of field elements.
|
|
7
|
-
*
|
|
8
|
-
* This function returns the fields that were actually added in a checkpoint. The number of fields is specified by the
|
|
9
|
-
* first field.
|
|
10
|
-
*
|
|
11
|
-
* @param buf - The buffer to deserialize.
|
|
12
|
-
* @param checkEncoding - Whether to check if the encoding is correct. If false, it will still check the checkpoint
|
|
13
|
-
* prefix and throw if there's not enough fields.
|
|
14
|
-
* @returns An array of field elements.
|
|
15
|
-
*/ export function deserializeEncodedBlobToFields(buf, checkEncoding = false) {
|
|
16
|
-
const reader = BufferReader.asReader(buf);
|
|
17
|
-
const firstField = reader.readObject(Fr);
|
|
18
|
-
// Use toBigInt instead of toNumber so that we can catch it and throw a more descriptive error below if the first
|
|
19
|
-
// field is larger than a javascript integer.
|
|
20
|
-
const numFields = firstField.toBigInt();
|
|
21
|
-
const totalFieldsInBuffer = BigInt(buf.length / Fr.SIZE_IN_BYTES);
|
|
22
|
-
if (numFields > totalFieldsInBuffer) {
|
|
23
|
-
throw new BlobDeserializationError(`Failed to deserialize blob fields, this blob was likely not created by us`);
|
|
24
|
-
}
|
|
25
|
-
const numFieldsWithoutPrefix = Number(numFields) - 1;
|
|
26
|
-
const blobFields = [
|
|
27
|
-
firstField
|
|
28
|
-
].concat(reader.readArray(numFieldsWithoutPrefix, Fr));
|
|
29
|
-
if (checkEncoding && !checkBlobFieldsEncoding(blobFields)) {
|
|
30
|
-
throw new BlobDeserializationError(`Incorrect encoding of blob fields, this blob was likely not created by us`);
|
|
31
|
-
}
|
|
32
|
-
return blobFields;
|
|
33
|
-
}
|
package/dest/encoding.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
export interface TxStartMarker {
|
|
3
|
-
prefix: bigint;
|
|
4
|
-
numBlobFields: number;
|
|
5
|
-
revertCode: number;
|
|
6
|
-
numNoteHashes: number;
|
|
7
|
-
numNullifiers: number;
|
|
8
|
-
numL2ToL1Msgs: number;
|
|
9
|
-
numPublicDataWrites: number;
|
|
10
|
-
numPrivateLogs: number;
|
|
11
|
-
publicLogsLength: number;
|
|
12
|
-
contractClassLogLength: number;
|
|
13
|
-
}
|
|
14
|
-
export declare function encodeTxStartMarker(txStartMarker: Omit<TxStartMarker, 'prefix'>): Fr;
|
|
15
|
-
export declare function decodeTxStartMarker(field: Fr): TxStartMarker;
|
|
16
|
-
export declare function getNumBlobFieldsFromTxStartMarker(field: Fr): number;
|
|
17
|
-
export declare function isValidTxStartMarker(txStartMarker: TxStartMarker): boolean;
|
|
18
|
-
export declare function createBlockEndMarker(numTxs: number): Fr;
|
|
19
|
-
export declare function getNumTxsFromBlockEndMarker(field: Fr): number;
|
|
20
|
-
export declare function isBlockEndMarker(field: Fr): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Check that the fields are emitted from the circuits and conform to the encoding.
|
|
23
|
-
* @param blobFields - The concatenated fields from all blobs of an L1 block.
|
|
24
|
-
*/
|
|
25
|
-
export declare function checkBlobFieldsEncoding(blobFields: Fr[]): boolean;
|
|
26
|
-
//# 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":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAa9C,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAGD,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,MAqB/E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,EAAE,GAAG,aAAa,CAmC5D;AAED,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,EAAE,UAE1D;AAED,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,aAAa,WAEhE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,MAGlD;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,EAAE,UAEpD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,EAAE,WAIzC;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,EAAE,EAAE,WAsCvD"}
|
package/src/deserialize.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
-
|
|
4
|
-
import { checkBlobFieldsEncoding } from './encoding.js';
|
|
5
|
-
import { BlobDeserializationError } from './errors.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Deserializes a buffer into an array of field elements.
|
|
9
|
-
*
|
|
10
|
-
* This function returns the fields that were actually added in a checkpoint. The number of fields is specified by the
|
|
11
|
-
* first field.
|
|
12
|
-
*
|
|
13
|
-
* @param buf - The buffer to deserialize.
|
|
14
|
-
* @param checkEncoding - Whether to check if the encoding is correct. If false, it will still check the checkpoint
|
|
15
|
-
* prefix and throw if there's not enough fields.
|
|
16
|
-
* @returns An array of field elements.
|
|
17
|
-
*/
|
|
18
|
-
export function deserializeEncodedBlobToFields(buf: Uint8Array, checkEncoding = false): Fr[] {
|
|
19
|
-
const reader = BufferReader.asReader(buf);
|
|
20
|
-
const firstField = reader.readObject(Fr);
|
|
21
|
-
|
|
22
|
-
// Use toBigInt instead of toNumber so that we can catch it and throw a more descriptive error below if the first
|
|
23
|
-
// field is larger than a javascript integer.
|
|
24
|
-
const numFields = firstField.toBigInt();
|
|
25
|
-
const totalFieldsInBuffer = BigInt(buf.length / Fr.SIZE_IN_BYTES);
|
|
26
|
-
if (numFields > totalFieldsInBuffer) {
|
|
27
|
-
throw new BlobDeserializationError(`Failed to deserialize blob fields, this blob was likely not created by us`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const numFieldsWithoutPrefix = Number(numFields) - 1;
|
|
31
|
-
const blobFields = [firstField].concat(reader.readArray(numFieldsWithoutPrefix, Fr));
|
|
32
|
-
|
|
33
|
-
if (checkEncoding && !checkBlobFieldsEncoding(blobFields)) {
|
|
34
|
-
throw new BlobDeserializationError(`Incorrect encoding of blob fields, this blob was likely not created by us`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return blobFields;
|
|
38
|
-
}
|