@aztec/blob-lib 3.0.0-canary.a9708bd → 3.0.0-devnet.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/blob.d.ts +52 -95
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +73 -165
- package/dest/blob_batching.d.ts +15 -48
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +81 -120
- package/dest/blob_utils.d.ts +30 -0
- package/dest/blob_utils.d.ts.map +1 -0
- package/dest/blob_utils.js +60 -0
- package/dest/circuit_types/blob_accumulator.d.ts +21 -0
- package/dest/circuit_types/blob_accumulator.d.ts.map +1 -0
- package/dest/circuit_types/blob_accumulator.js +58 -0
- package/dest/circuit_types/final_blob_accumulator.d.ts +22 -0
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -0
- package/dest/circuit_types/final_blob_accumulator.js +63 -0
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +15 -0
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -0
- package/dest/circuit_types/final_blob_batching_challenges.js +25 -0
- package/dest/circuit_types/index.d.ts +4 -0
- package/dest/circuit_types/index.d.ts.map +1 -0
- package/dest/circuit_types/index.js +4 -0
- package/dest/deserialize.d.ts +14 -0
- package/dest/deserialize.d.ts.map +1 -0
- package/dest/deserialize.js +33 -0
- package/dest/encoding.d.ts +22 -62
- package/dest/encoding.d.ts.map +1 -1
- package/dest/encoding.js +114 -104
- package/dest/hash.d.ts +35 -0
- package/dest/hash.d.ts.map +1 -0
- package/dest/hash.js +69 -0
- package/dest/index.d.ts +5 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -15
- package/dest/kzg_context.d.ts +4 -0
- package/dest/kzg_context.d.ts.map +1 -0
- package/dest/kzg_context.js +5 -0
- package/dest/sponge_blob.d.ts +13 -9
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +28 -17
- package/dest/testing.d.ts +7 -12
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +54 -41
- package/dest/types.d.ts +16 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +3 -0
- package/package.json +6 -4
- package/src/blob.ts +76 -191
- package/src/blob_batching.ts +109 -137
- package/src/blob_utils.ts +71 -0
- package/src/circuit_types/blob_accumulator.ts +84 -0
- package/src/circuit_types/final_blob_accumulator.ts +75 -0
- package/src/circuit_types/final_blob_batching_challenges.ts +29 -0
- package/src/circuit_types/index.ts +4 -0
- package/src/deserialize.ts +38 -0
- package/src/encoding.ts +136 -120
- package/src/hash.ts +77 -0
- package/src/index.ts +5 -18
- package/src/kzg_context.ts +5 -0
- package/src/sponge_blob.ts +24 -14
- package/src/testing.ts +55 -40
- package/src/types.ts +16 -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/src/blob_batching_public_inputs.ts +0 -252
package/dest/index.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import cKzg from 'c-kzg';
|
|
2
|
-
const { loadTrustedSetup } = cKzg;
|
|
3
1
|
export * from './blob.js';
|
|
4
2
|
export * from './blob_batching.js';
|
|
3
|
+
export * from './blob_utils.js';
|
|
4
|
+
export * from './circuit_types/index.js';
|
|
5
|
+
export * from './deserialize.js';
|
|
5
6
|
export * from './encoding.js';
|
|
6
|
-
export * from './interface.js';
|
|
7
7
|
export * from './errors.js';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './hash.js';
|
|
9
|
+
export * from './interface.js';
|
|
9
10
|
export * from './sponge_blob.js';
|
|
10
|
-
try {
|
|
11
|
-
loadTrustedSetup();
|
|
12
|
-
} catch (error) {
|
|
13
|
-
if (error.message.includes('trusted setup is already loaded')) {
|
|
14
|
-
// NB: The c-kzg lib has no way of checking whether the setup is loaded or not,
|
|
15
|
-
// and it throws an error if it's already loaded, even though nothing is wrong.
|
|
16
|
-
// This is a rudimentary way of ensuring we load the trusted setup if we need it.
|
|
17
|
-
} else {
|
|
18
|
-
throw new Error(error);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kzg_context.d.ts","sourceRoot":"","sources":["../src/kzg_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,cAAc,4BAA4B,CAAC;AAE3C,eAAO,MAAM,GAAG,cAA4C,CAAC"}
|
package/dest/sponge_blob.d.ts
CHANGED
|
@@ -2,23 +2,23 @@ import { type FieldsOf } from '@aztec/foundation/array';
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { BufferReader, FieldReader, type Tuple } from '@aztec/foundation/serialize';
|
|
4
4
|
/**
|
|
5
|
-
* A Poseidon2 sponge used to accumulate data that will be added to
|
|
5
|
+
* A Poseidon2 sponge used to accumulate data that will be added to blobs.
|
|
6
6
|
* See noir-projects/noir-protocol-circuits/crates/types/src/abis/sponge_blob.nr.
|
|
7
7
|
*/
|
|
8
8
|
export declare class SpongeBlob {
|
|
9
|
-
/** Sponge with absorbed
|
|
9
|
+
/** Sponge with absorbed fields that will go into one or more blobs. */
|
|
10
10
|
readonly sponge: Poseidon2Sponge;
|
|
11
11
|
/** Number of effects absorbed so far. */
|
|
12
|
-
|
|
12
|
+
numAbsorbedFields: number;
|
|
13
13
|
/** Number of effects that will be absorbed. */
|
|
14
|
-
readonly
|
|
14
|
+
readonly numExpectedFields: number;
|
|
15
15
|
constructor(
|
|
16
|
-
/** Sponge with absorbed
|
|
16
|
+
/** Sponge with absorbed fields that will go into one or more blobs. */
|
|
17
17
|
sponge: Poseidon2Sponge,
|
|
18
18
|
/** Number of effects absorbed so far. */
|
|
19
|
-
|
|
19
|
+
numAbsorbedFields: number,
|
|
20
20
|
/** Number of effects that will be absorbed. */
|
|
21
|
-
|
|
21
|
+
numExpectedFields: number);
|
|
22
22
|
static fromBuffer(buffer: Buffer | BufferReader): SpongeBlob;
|
|
23
23
|
toBuffer(): Buffer<ArrayBufferLike>;
|
|
24
24
|
static getFields(fields: FieldsOf<SpongeBlob>): (number | Poseidon2Sponge)[];
|
|
@@ -28,7 +28,11 @@ export declare class SpongeBlob {
|
|
|
28
28
|
absorb(fields: Fr[]): Promise<void>;
|
|
29
29
|
squeeze(): Promise<Fr>;
|
|
30
30
|
static empty(): SpongeBlob;
|
|
31
|
-
|
|
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>;
|
|
32
36
|
}
|
|
33
37
|
export declare class Poseidon2Sponge {
|
|
34
38
|
cache: Tuple<Fr, 3>;
|
|
@@ -42,7 +46,7 @@ export declare class Poseidon2Sponge {
|
|
|
42
46
|
toFields(): Fr[];
|
|
43
47
|
static fromFields(fields: Fr[] | FieldReader): Poseidon2Sponge;
|
|
44
48
|
static empty(): Poseidon2Sponge;
|
|
45
|
-
static init(
|
|
49
|
+
static init(numExpectedFields: number): Poseidon2Sponge;
|
|
46
50
|
performDuplex(): Promise<void>;
|
|
47
51
|
absorb(fields: Fr[]): Promise<void>;
|
|
48
52
|
squeeze(): Promise<Fr>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sponge_blob.d.ts","sourceRoot":"","sources":["../src/sponge_blob.ts"],"names":[],"mappings":"
|
|
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;IAEnB,uEAAuE;aACvD,MAAM,EAAE,eAAe;IACvC,yCAAyC;IAClC,iBAAiB,EAAE,MAAM;IAChC,+CAA+C;aAC/B,iBAAiB,EAAE,MAAM;;IALzC,uEAAuE;IACvD,MAAM,EAAE,eAAe;IACvC,yCAAyC;IAClC,iBAAiB,EAAE,MAAM;IAChC,+CAA+C;IAC/B,iBAAiB,EAAE,MAAM;IAG3C,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,UAAU;IAK5D,QAAQ;IAIR,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC;IAI7C,QAAQ,IAAI,EAAE,EAAE;IAIhB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,UAAU;IASzD,KAAK;IAIC,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE;IAUnB,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC;IAS5B,MAAM,CAAC,KAAK,IAAI,UAAU;IAI1B;;;OAGG;WACU,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAQlE;AAGD,qBAAa,eAAe;IAEjB,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IACnB,SAAS,EAAE,MAAM;IACjB,WAAW,EAAE,OAAO;gBAHpB,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EACnB,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EACnB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,OAAO;IAG7B,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,eAAe;IAUjE,QAAQ;IAIR,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC;IAIlD,QAAQ,IAAI,EAAE,EAAE;IAIhB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,eAAe;IAU9D,MAAM,CAAC,KAAK,IAAI,eAAe;IAS/B,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,eAAe;IAUjD,aAAa;IAWb,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE;IAenB,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC;CAQ7B"}
|
package/dest/sponge_blob.js
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
|
+
import { TWO_POW_64 } from '@aztec/constants';
|
|
1
2
|
import { makeTuple } from '@aztec/foundation/array';
|
|
2
3
|
import { poseidon2Permutation } from '@aztec/foundation/crypto';
|
|
3
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
5
|
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
|
|
5
6
|
/**
|
|
6
|
-
* A Poseidon2 sponge used to accumulate data that will be added to
|
|
7
|
+
* A Poseidon2 sponge used to accumulate data that will be added to blobs.
|
|
7
8
|
* See noir-projects/noir-protocol-circuits/crates/types/src/abis/sponge_blob.nr.
|
|
8
9
|
*/ export class SpongeBlob {
|
|
9
10
|
sponge;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor(/** Sponge with absorbed
|
|
11
|
+
numAbsorbedFields;
|
|
12
|
+
numExpectedFields;
|
|
13
|
+
constructor(/** Sponge with absorbed fields that will go into one or more blobs. */ sponge, /** Number of effects absorbed so far. */ numAbsorbedFields, /** Number of effects that will be absorbed. */ numExpectedFields){
|
|
13
14
|
this.sponge = sponge;
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
15
|
+
this.numAbsorbedFields = numAbsorbedFields;
|
|
16
|
+
this.numExpectedFields = numExpectedFields;
|
|
16
17
|
}
|
|
17
18
|
static fromBuffer(buffer) {
|
|
18
19
|
const reader = BufferReader.asReader(buffer);
|
|
19
20
|
return new SpongeBlob(reader.readObject(Poseidon2Sponge), reader.readNumber(), reader.readNumber());
|
|
20
21
|
}
|
|
21
22
|
toBuffer() {
|
|
22
|
-
return serializeToBuffer(
|
|
23
|
+
return serializeToBuffer(...SpongeBlob.getFields(this));
|
|
23
24
|
}
|
|
24
25
|
static getFields(fields) {
|
|
25
26
|
return [
|
|
26
27
|
fields.sponge,
|
|
27
|
-
fields.
|
|
28
|
-
fields.
|
|
28
|
+
fields.numAbsorbedFields,
|
|
29
|
+
fields.numExpectedFields
|
|
29
30
|
];
|
|
30
31
|
}
|
|
31
32
|
toFields() {
|
|
@@ -39,16 +40,16 @@ import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from
|
|
|
39
40
|
return SpongeBlob.fromBuffer(this.toBuffer());
|
|
40
41
|
}
|
|
41
42
|
async absorb(fields) {
|
|
42
|
-
if (this.
|
|
43
|
-
throw new Error(`Attempted to fill
|
|
43
|
+
if (this.numAbsorbedFields + fields.length > this.numExpectedFields) {
|
|
44
|
+
throw new Error(`Attempted to fill spongeBlob with ${this.numAbsorbedFields + fields.length}, but it has a max of ${this.numExpectedFields}`);
|
|
44
45
|
}
|
|
45
46
|
await this.sponge.absorb(fields);
|
|
46
|
-
this.
|
|
47
|
+
this.numAbsorbedFields += fields.length;
|
|
47
48
|
}
|
|
48
49
|
async squeeze() {
|
|
49
50
|
// If the blob sponge is not 'full', we append 1 to match Poseidon2::hash_internal()
|
|
50
51
|
// NB: There is currently no use case in which we don't 'fill' a blob sponge, but adding for completeness
|
|
51
|
-
if (this.
|
|
52
|
+
if (this.numAbsorbedFields != this.numExpectedFields) {
|
|
52
53
|
await this.sponge.absorb([
|
|
53
54
|
Fr.ONE
|
|
54
55
|
]);
|
|
@@ -58,8 +59,18 @@ import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from
|
|
|
58
59
|
static empty() {
|
|
59
60
|
return new SpongeBlob(Poseidon2Sponge.empty(), 0, 0);
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Initialize the sponge blob with the number of expected fields in the checkpoint and absorb it as the first field.
|
|
64
|
+
* Note: `numExpectedFields` includes the first field absorbed in this method.
|
|
65
|
+
*/ static async init(numExpectedFields) {
|
|
66
|
+
// This must match what the checkpoint root rollup circuit expects.
|
|
67
|
+
// See noir-projects/noir-protocol-circuits/types/src/abis/sponge_blob.nr -> init_for_checkpoint.
|
|
68
|
+
const sponge = Poseidon2Sponge.init(numExpectedFields);
|
|
69
|
+
await sponge.absorb([
|
|
70
|
+
new Fr(numExpectedFields)
|
|
71
|
+
]);
|
|
72
|
+
const numAbsorbedFields = 1;
|
|
73
|
+
return new SpongeBlob(sponge, numAbsorbedFields, numExpectedFields);
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
// This is just noir's stdlib version of the poseidon2 sponge. We use it for a blob-specific implmentation of the hasher.
|
|
@@ -99,8 +110,8 @@ export class Poseidon2Sponge {
|
|
|
99
110
|
static empty() {
|
|
100
111
|
return new Poseidon2Sponge(makeTuple(3, ()=>Fr.ZERO), makeTuple(4, ()=>Fr.ZERO), 0, false);
|
|
101
112
|
}
|
|
102
|
-
static init(
|
|
103
|
-
const iv = new Fr(
|
|
113
|
+
static init(numExpectedFields) {
|
|
114
|
+
const iv = new Fr(numExpectedFields).mul(new Fr(TWO_POW_64));
|
|
104
115
|
const sponge = Poseidon2Sponge.empty();
|
|
105
116
|
sponge.state[3] = iv;
|
|
106
117
|
return sponge;
|
package/dest/testing.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { Blob } from './blob.js';
|
|
3
3
|
import { BatchedBlobAccumulator } from './blob_batching.js';
|
|
4
|
-
import { BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
|
|
5
4
|
import { SpongeBlob } from './sponge_blob.js';
|
|
6
5
|
/**
|
|
7
6
|
* Makes arbitrary poseidon sponge for blob inputs.
|
|
@@ -17,13 +16,9 @@ export declare function makeSpongeBlob(seed?: number): SpongeBlob;
|
|
|
17
16
|
* @returns A blob accumulator instance.
|
|
18
17
|
*/
|
|
19
18
|
export declare function makeBatchedBlobAccumulator(seed?: number): BatchedBlobAccumulator;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* @param seed - The seed to use for generating the blob inputs.
|
|
24
|
-
* @returns A block blob public inputs instance.
|
|
25
|
-
*/
|
|
26
|
-
export declare function makeBlockBlobPublicInputs(seed?: number): BlockBlobPublicInputs;
|
|
19
|
+
export declare function makeEncodedTxBlobFields(length: number): Fr[];
|
|
20
|
+
export declare function makeEncodedBlockBlobFields(...lengths: number[]): Fr[];
|
|
21
|
+
export declare function makeEncodedBlobFields(length: number): Fr[];
|
|
27
22
|
/**
|
|
28
23
|
* Make an encoded blob with the given length
|
|
29
24
|
*
|
|
@@ -31,14 +26,14 @@ export declare function makeBlockBlobPublicInputs(seed?: number): BlockBlobPubli
|
|
|
31
26
|
* @param length
|
|
32
27
|
* @returns
|
|
33
28
|
*/
|
|
34
|
-
export declare function makeEncodedBlob(length: number):
|
|
29
|
+
export declare function makeEncodedBlob(length: number): Blob;
|
|
30
|
+
export declare function makeEncodedBlobs(length: number): Blob[];
|
|
35
31
|
/**
|
|
36
|
-
* Make
|
|
32
|
+
* Make a blob with random fields.
|
|
37
33
|
*
|
|
38
34
|
* This will fail deserialisation in the archiver
|
|
39
35
|
* @param length
|
|
40
36
|
* @returns
|
|
41
37
|
*/
|
|
42
|
-
export declare function
|
|
43
|
-
export declare function makeEncodedBlobFields(fields: Fr[]): Promise<Blob>;
|
|
38
|
+
export declare function makeRandomBlob(length: number): Blob;
|
|
44
39
|
//# sourceMappingURL=testing.d.ts.map
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAI5D,OAAO,EAAmB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,SAAI,GAAG,UAAU,CAWnD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,SAAI,GAAG,sBAAsB,CAW3E;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,CAoB5D;AAED,wBAAgB,0BAA0B,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAMrE;AAGD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,CAO1D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAMpD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,CAGvD;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEnD"}
|
package/dest/testing.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { FIELDS_PER_BLOB } from '@aztec/constants';
|
|
1
2
|
import { makeTuple } from '@aztec/foundation/array';
|
|
2
|
-
import {
|
|
3
|
+
import { randomInt } from '@aztec/foundation/crypto';
|
|
3
4
|
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
4
5
|
import { Blob } from './blob.js';
|
|
5
|
-
import { BatchedBlobAccumulator
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { BatchedBlobAccumulator } from './blob_batching.js';
|
|
7
|
+
import { getBlobsPerL1Block } from './blob_utils.js';
|
|
8
|
+
import { FinalBlobBatchingChallenges } from './circuit_types/index.js';
|
|
9
|
+
import { createBlockEndMarker, encodeTxStartMarker } from './encoding.js';
|
|
8
10
|
import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
9
11
|
/**
|
|
10
12
|
* Makes arbitrary poseidon sponge for blob inputs.
|
|
@@ -22,30 +24,45 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
|
22
24
|
*/ export function makeBatchedBlobAccumulator(seed = 1) {
|
|
23
25
|
return new BatchedBlobAccumulator(new Fr(seed), new Fr(seed + 1), new BLS12Fr(seed + 2), BLS12Point.random(), BLS12Point.random(), new Fr(seed + 3), new BLS12Fr(seed + 4), new FinalBlobBatchingChallenges(new Fr(seed + 5), new BLS12Fr(seed + 6)));
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
export function makeEncodedTxBlobFields(length) {
|
|
28
|
+
const txStartMarker = {
|
|
29
|
+
numBlobFields: length,
|
|
30
|
+
// The rest of the values don't matter. The test components using it do not try to deserialize everything.
|
|
31
|
+
// Only `checkBlobFieldsEncoding` is used and it only looks at `numBlobFields`. This might change in the future
|
|
32
|
+
// when we add more thorough checks to `checkBlobFieldsEncoding`.
|
|
33
|
+
revertCode: 0,
|
|
34
|
+
numNoteHashes: 0,
|
|
35
|
+
numNullifiers: 0,
|
|
36
|
+
numL2ToL1Msgs: 0,
|
|
37
|
+
numPublicDataWrites: 0,
|
|
38
|
+
numPrivateLogs: 0,
|
|
39
|
+
publicLogsLength: 0,
|
|
40
|
+
contractClassLogLength: 0
|
|
41
|
+
};
|
|
42
|
+
return [
|
|
43
|
+
encodeTxStartMarker(txStartMarker),
|
|
44
|
+
...Array.from({
|
|
45
|
+
length: length - 1
|
|
46
|
+
}, ()=>new Fr(randomInt(Number.MAX_SAFE_INTEGER)))
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
export function makeEncodedBlockBlobFields(...lengths) {
|
|
50
|
+
return [
|
|
51
|
+
...lengths.length > 0 ? makeEncodedTxBlobFields(lengths[0] - 1) : [],
|
|
52
|
+
...lengths.slice(1).flatMap((length)=>makeEncodedTxBlobFields(length)),
|
|
53
|
+
createBlockEndMarker(lengths.length)
|
|
54
|
+
];
|
|
33
55
|
}
|
|
34
|
-
//
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
1
|
|
45
|
-
]),
|
|
46
|
-
Buffer.alloc(1),
|
|
47
|
-
Buffer.alloc(1)
|
|
48
|
-
]));
|
|
56
|
+
// Create blob fields for a checkpoint with a single block.
|
|
57
|
+
export function makeEncodedBlobFields(length) {
|
|
58
|
+
if (length <= 2) {
|
|
59
|
+
throw new Error('Encoded blob fields length must be greater than 2');
|
|
60
|
+
}
|
|
61
|
+
const checkpointPrefix = new Fr(length);
|
|
62
|
+
return [
|
|
63
|
+
checkpointPrefix,
|
|
64
|
+
...makeEncodedBlockBlobFields(length - 1)
|
|
65
|
+
]; // -1 to account for the checkpoint prefix.
|
|
49
66
|
}
|
|
50
67
|
/**
|
|
51
68
|
* Make an encoded blob with the given length
|
|
@@ -54,29 +71,25 @@ function encodeFirstField(length) {
|
|
|
54
71
|
* @param length
|
|
55
72
|
* @returns
|
|
56
73
|
*/ export function makeEncodedBlob(length) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
if (length > FIELDS_PER_BLOB) {
|
|
75
|
+
throw new Error(`A single encoded blob must be less than ${FIELDS_PER_BLOB} fields`);
|
|
76
|
+
}
|
|
77
|
+
return Blob.fromFields(makeEncodedBlobFields(length));
|
|
78
|
+
}
|
|
79
|
+
export function makeEncodedBlobs(length) {
|
|
80
|
+
const fields = makeEncodedBlobFields(length);
|
|
81
|
+
return getBlobsPerL1Block(fields);
|
|
63
82
|
}
|
|
64
83
|
/**
|
|
65
|
-
* Make
|
|
84
|
+
* Make a blob with random fields.
|
|
66
85
|
*
|
|
67
86
|
* This will fail deserialisation in the archiver
|
|
68
87
|
* @param length
|
|
69
88
|
* @returns
|
|
70
|
-
*/ export function
|
|
89
|
+
*/ export function makeRandomBlob(length) {
|
|
71
90
|
return Blob.fromFields([
|
|
72
91
|
...Array.from({
|
|
73
92
|
length: length
|
|
74
93
|
}, ()=>Fr.random())
|
|
75
94
|
]);
|
|
76
95
|
}
|
|
77
|
-
export function makeEncodedBlobFields(fields) {
|
|
78
|
-
return Blob.fromFields([
|
|
79
|
-
encodeFirstField(fields.length + 1),
|
|
80
|
-
...fields
|
|
81
|
-
]);
|
|
82
|
-
}
|
package/dest/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './circuit_types/index.js';
|
|
2
|
+
export * from './interface.js';
|
|
3
|
+
export * from './sponge_blob.js';
|
|
4
|
+
/**
|
|
5
|
+
* Type definition for the KZG instance returned by Blob.getViemKzgInstance().
|
|
6
|
+
* Contains the cryptographic functions needed for blob commitment and proof generation.
|
|
7
|
+
*/
|
|
8
|
+
export interface BlobKzgInstance {
|
|
9
|
+
/** Function to compute KZG commitment from blob data */
|
|
10
|
+
blobToKzgCommitment(blob: Uint8Array): Uint8Array;
|
|
11
|
+
/** Function to compute KZG proof for blob data */
|
|
12
|
+
computeBlobKzgProof(blob: Uint8Array, commitment: Uint8Array): Uint8Array;
|
|
13
|
+
/** Function to compute both blob data cells and their corresponding KZG proofs for EIP7594 */
|
|
14
|
+
computeCellsAndKzgProofs(blob: Uint8Array): [Uint8Array[], Uint8Array[]];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AAEjC;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAClD,kDAAkD;IAClD,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;IAC1E,8FAA8F;IAC9F,wBAAwB,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;CAC1E"}
|
package/dest/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/blob-lib",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-devnet.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
7
|
+
"./encoding": "./dest/encoding.js",
|
|
8
|
+
"./types": "./dest/types.js",
|
|
7
9
|
"./testing": "./dest/testing.js"
|
|
8
10
|
},
|
|
9
11
|
"typedocOptions": {
|
|
@@ -25,9 +27,9 @@
|
|
|
25
27
|
"../package.common.json"
|
|
26
28
|
],
|
|
27
29
|
"dependencies": {
|
|
28
|
-
"@aztec/constants": "3.0.0-
|
|
29
|
-
"@aztec/foundation": "3.0.0-
|
|
30
|
-
"
|
|
30
|
+
"@aztec/constants": "3.0.0-devnet.2",
|
|
31
|
+
"@aztec/foundation": "3.0.0-devnet.2",
|
|
32
|
+
"@crate-crypto/node-eth-kzg": "^0.10.0",
|
|
31
33
|
"tslib": "^2.4.0"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|