@aztec/blob-lib 0.0.0-test.1 → 0.0.1-fake-c83136db25

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.
Files changed (69) hide show
  1. package/dest/blob.d.ts +58 -99
  2. package/dest/blob.d.ts.map +1 -1
  3. package/dest/blob.js +83 -183
  4. package/dest/blob_batching.d.ts +155 -0
  5. package/dest/blob_batching.d.ts.map +1 -0
  6. package/dest/blob_batching.js +260 -0
  7. package/dest/blob_utils.d.ts +30 -0
  8. package/dest/blob_utils.d.ts.map +1 -0
  9. package/dest/blob_utils.js +60 -0
  10. package/dest/circuit_types/blob_accumulator.d.ts +21 -0
  11. package/dest/circuit_types/blob_accumulator.d.ts.map +1 -0
  12. package/dest/circuit_types/blob_accumulator.js +58 -0
  13. package/dest/circuit_types/final_blob_accumulator.d.ts +22 -0
  14. package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -0
  15. package/dest/circuit_types/final_blob_accumulator.js +63 -0
  16. package/dest/circuit_types/final_blob_batching_challenges.d.ts +15 -0
  17. package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -0
  18. package/dest/circuit_types/final_blob_batching_challenges.js +25 -0
  19. package/dest/circuit_types/index.d.ts +4 -0
  20. package/dest/circuit_types/index.d.ts.map +1 -0
  21. package/dest/circuit_types/index.js +4 -0
  22. package/dest/deserialize.d.ts +14 -0
  23. package/dest/deserialize.d.ts.map +1 -0
  24. package/dest/deserialize.js +33 -0
  25. package/dest/encoding.d.ts +22 -62
  26. package/dest/encoding.d.ts.map +1 -1
  27. package/dest/encoding.js +114 -104
  28. package/dest/hash.d.ts +35 -0
  29. package/dest/hash.d.ts.map +1 -0
  30. package/dest/hash.js +69 -0
  31. package/dest/index.d.ts +6 -2
  32. package/dest/index.d.ts.map +1 -1
  33. package/dest/index.js +6 -15
  34. package/dest/interface.d.ts +1 -2
  35. package/dest/interface.d.ts.map +1 -1
  36. package/dest/kzg_context.d.ts +4 -0
  37. package/dest/kzg_context.d.ts.map +1 -0
  38. package/dest/kzg_context.js +5 -0
  39. package/dest/sponge_blob.d.ts +15 -13
  40. package/dest/sponge_blob.d.ts.map +1 -1
  41. package/dest/sponge_blob.js +28 -17
  42. package/dest/testing.d.ts +12 -16
  43. package/dest/testing.d.ts.map +1 -1
  44. package/dest/testing.js +60 -46
  45. package/dest/types.d.ts +16 -0
  46. package/dest/types.d.ts.map +1 -0
  47. package/dest/types.js +3 -0
  48. package/package.json +16 -12
  49. package/src/blob.ts +82 -221
  50. package/src/blob_batching.ts +335 -0
  51. package/src/blob_utils.ts +71 -0
  52. package/src/circuit_types/blob_accumulator.ts +84 -0
  53. package/src/circuit_types/final_blob_accumulator.ts +75 -0
  54. package/src/circuit_types/final_blob_batching_challenges.ts +29 -0
  55. package/src/circuit_types/index.ts +4 -0
  56. package/src/deserialize.ts +38 -0
  57. package/src/encoding.ts +136 -120
  58. package/src/hash.ts +77 -0
  59. package/src/index.ts +6 -19
  60. package/src/interface.ts +1 -4
  61. package/src/kzg_context.ts +5 -0
  62. package/src/sponge_blob.ts +24 -14
  63. package/src/testing.ts +68 -43
  64. package/src/trusted_setup_bit_reversed.json +4100 -0
  65. package/src/types.ts +16 -0
  66. package/dest/blob_public_inputs.d.ts +0 -50
  67. package/dest/blob_public_inputs.d.ts.map +0 -1
  68. package/dest/blob_public_inputs.js +0 -146
  69. package/src/blob_public_inputs.ts +0 -157
package/dest/index.js CHANGED
@@ -1,19 +1,10 @@
1
- import cKzg from 'c-kzg';
2
- /* eslint-disable import/no-named-as-default-member */ const { loadTrustedSetup } = cKzg;
3
1
  export * from './blob.js';
2
+ export * from './blob_batching.js';
3
+ export * from './blob_utils.js';
4
+ export * from './circuit_types/index.js';
5
+ export * from './deserialize.js';
4
6
  export * from './encoding.js';
5
- export * from './interface.js';
6
7
  export * from './errors.js';
7
- export * from './blob_public_inputs.js';
8
+ export * from './hash.js';
9
+ export * from './interface.js';
8
10
  export * from './sponge_blob.js';
9
- try {
10
- loadTrustedSetup();
11
- } catch (error) {
12
- if (error.message.includes('trusted setup is already loaded')) {
13
- // NB: The c-kzg lib has no way of checking whether the setup is loaded or not,
14
- // and it throws an error if it's already loaded, even though nothing is wrong.
15
- // This is a rudimentary way of ensuring we load the trusted setup if we need it.
16
- } else {
17
- throw new Error(error);
18
- }
19
- }
@@ -3,8 +3,7 @@
3
3
  */
4
4
  export interface BlobJson {
5
5
  blob: string;
6
- index?: number;
6
+ index: string;
7
7
  kzg_commitment: string;
8
- kzg_proof: string;
9
8
  }
10
9
  //# sourceMappingURL=interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,cAAc,EAAE,MAAM,CAAC;IAEvB,SAAS,EAAE,MAAM,CAAC;CACnB"}
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;CACxB"}
@@ -0,0 +1,4 @@
1
+ import { DasContextJs } from '@crate-crypto/node-eth-kzg';
2
+ export * from '@crate-crypto/node-eth-kzg';
3
+ export declare const kzg: DasContextJs;
4
+ //# sourceMappingURL=kzg_context.d.ts.map
@@ -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"}
@@ -0,0 +1,5 @@
1
+ import { DasContextJs } from '@crate-crypto/node-eth-kzg';
2
+ export * from '@crate-crypto/node-eth-kzg';
3
+ export const kzg = DasContextJs.create({
4
+ usePrecomp: true
5
+ });
@@ -1,28 +1,26 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  import { type FieldsOf } from '@aztec/foundation/array';
4
2
  import { Fr } from '@aztec/foundation/fields';
5
3
  import { BufferReader, FieldReader, type Tuple } from '@aztec/foundation/serialize';
6
4
  /**
7
- * A Poseidon2 sponge used to accumulate data that will be added to a blob.
5
+ * A Poseidon2 sponge used to accumulate data that will be added to blobs.
8
6
  * See noir-projects/noir-protocol-circuits/crates/types/src/abis/sponge_blob.nr.
9
7
  */
10
8
  export declare class SpongeBlob {
11
- /** Sponge with absorbed tx effects that will go into a blob. */
9
+ /** Sponge with absorbed fields that will go into one or more blobs. */
12
10
  readonly sponge: Poseidon2Sponge;
13
11
  /** Number of effects absorbed so far. */
14
- fields: number;
12
+ numAbsorbedFields: number;
15
13
  /** Number of effects that will be absorbed. */
16
- readonly expectedFields: number;
14
+ readonly numExpectedFields: number;
17
15
  constructor(
18
- /** Sponge with absorbed tx effects that will go into a blob. */
16
+ /** Sponge with absorbed fields that will go into one or more blobs. */
19
17
  sponge: Poseidon2Sponge,
20
18
  /** Number of effects absorbed so far. */
21
- fields: number,
19
+ numAbsorbedFields: number,
22
20
  /** Number of effects that will be absorbed. */
23
- expectedFields: number);
21
+ numExpectedFields: number);
24
22
  static fromBuffer(buffer: Buffer | BufferReader): SpongeBlob;
25
- toBuffer(): Buffer;
23
+ toBuffer(): Buffer<ArrayBufferLike>;
26
24
  static getFields(fields: FieldsOf<SpongeBlob>): (number | Poseidon2Sponge)[];
27
25
  toFields(): Fr[];
28
26
  static fromFields(fields: Fr[] | FieldReader): SpongeBlob;
@@ -30,7 +28,11 @@ export declare class SpongeBlob {
30
28
  absorb(fields: Fr[]): Promise<void>;
31
29
  squeeze(): Promise<Fr>;
32
30
  static empty(): SpongeBlob;
33
- static init(expectedFields: number): 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>;
34
36
  }
35
37
  export declare class Poseidon2Sponge {
36
38
  cache: Tuple<Fr, 3>;
@@ -39,12 +41,12 @@ export declare class Poseidon2Sponge {
39
41
  squeezeMode: boolean;
40
42
  constructor(cache: Tuple<Fr, 3>, state: Tuple<Fr, 4>, cacheSize: number, squeezeMode: boolean);
41
43
  static fromBuffer(buffer: Buffer | BufferReader): Poseidon2Sponge;
42
- toBuffer(): Buffer;
44
+ toBuffer(): Buffer<ArrayBufferLike>;
43
45
  static getFields(fields: FieldsOf<Poseidon2Sponge>): (number | boolean | [Fr, Fr, Fr] | [Fr, Fr, Fr, Fr])[];
44
46
  toFields(): Fr[];
45
47
  static fromFields(fields: Fr[] | FieldReader): Poseidon2Sponge;
46
48
  static empty(): Poseidon2Sponge;
47
- static init(expectedFields: number): Poseidon2Sponge;
49
+ static init(numExpectedFields: number): Poseidon2Sponge;
48
50
  performDuplex(): Promise<void>;
49
51
  absorb(fields: Fr[]): Promise<void>;
50
52
  squeeze(): Promise<Fr>;
@@ -1 +1 @@
1
- {"version":3,"file":"sponge_blob.d.ts","sourceRoot":"","sources":["../src/sponge_blob.ts"],"names":[],"mappings":";;AAAA,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,gEAAgE;aAChD,MAAM,EAAE,eAAe;IACvC,yCAAyC;IAClC,MAAM,EAAE,MAAM;IACrB,+CAA+C;aAC/B,cAAc,EAAE,MAAM;;IALtC,gEAAgE;IAChD,MAA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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"}
@@ -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 a blob.
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
- fields;
11
- expectedFields;
12
- constructor(/** Sponge with absorbed tx effects that will go into a blob. */ sponge, /** Number of effects absorbed so far. */ fields, /** Number of effects that will be absorbed. */ expectedFields){
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.fields = fields;
15
- this.expectedFields = expectedFields;
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(this.sponge, this.fields, this.expectedFields);
23
+ return serializeToBuffer(...SpongeBlob.getFields(this));
23
24
  }
24
25
  static getFields(fields) {
25
26
  return [
26
27
  fields.sponge,
27
- fields.fields,
28
- fields.expectedFields
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.fields + fields.length > this.expectedFields) {
43
- throw new Error(`Attempted to fill spongeblob with ${this.fields + fields.length}, but it has a max of ${this.expectedFields}`);
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.fields += fields.length;
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.fields != this.expectedFields) {
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
- static init(expectedFields) {
62
- return new SpongeBlob(Poseidon2Sponge.init(expectedFields), 0, expectedFields);
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(expectedFields) {
103
- const iv = new Fr(expectedFields).mul(new Fr(BigInt('18446744073709551616')));
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,6 +1,6 @@
1
1
  import { Fr } from '@aztec/foundation/fields';
2
2
  import { Blob } from './blob.js';
3
- import { BlobPublicInputs, BlockBlobPublicInputs } from './blob_public_inputs.js';
3
+ import { BatchedBlobAccumulator } from './blob_batching.js';
4
4
  import { SpongeBlob } from './sponge_blob.js';
5
5
  /**
6
6
  * Makes arbitrary poseidon sponge for blob inputs.
@@ -10,19 +10,15 @@ import { SpongeBlob } from './sponge_blob.js';
10
10
  */
11
11
  export declare function makeSpongeBlob(seed?: number): SpongeBlob;
12
12
  /**
13
- * Makes arbitrary blob public inputs.
13
+ * Makes arbitrary blob public accumulator.
14
14
  * Note: will not verify inside the circuit.
15
- * @param seed - The seed to use for generating the blob inputs.
16
- * @returns A blob public inputs instance.
15
+ * @param seed - The seed to use for generating the blob accumulator.
16
+ * @returns A blob accumulator instance.
17
17
  */
18
- export declare function makeBlobPublicInputs(seed?: number): BlobPublicInputs;
19
- /**
20
- * Makes arbitrary block blob public inputs.
21
- * Note: will not verify inside the circuit.
22
- * @param seed - The seed to use for generating the blob inputs.
23
- * @returns A block blob public inputs instance.
24
- */
25
- export declare function makeBlockBlobPublicInputs(seed?: number): BlockBlobPublicInputs;
18
+ export declare function makeBatchedBlobAccumulator(seed?: number): BatchedBlobAccumulator;
19
+ export declare function makeEncodedTxBlobFields(length: number): Fr[];
20
+ export declare function makeEncodedBlockBlobFields(...lengths: number[]): Fr[];
21
+ export declare function makeEncodedBlobFields(length: number): Fr[];
26
22
  /**
27
23
  * Make an encoded blob with the given length
28
24
  *
@@ -30,14 +26,14 @@ export declare function makeBlockBlobPublicInputs(seed?: number): BlockBlobPubli
30
26
  * @param length
31
27
  * @returns
32
28
  */
33
- export declare function makeEncodedBlob(length: number): Promise<Blob>;
29
+ export declare function makeEncodedBlob(length: number): Blob;
30
+ export declare function makeEncodedBlobs(length: number): Blob[];
34
31
  /**
35
- * Make an unencoded blob with the given length
32
+ * Make a blob with random fields.
36
33
  *
37
34
  * This will fail deserialisation in the archiver
38
35
  * @param length
39
36
  * @returns
40
37
  */
41
- export declare function makeUnencodedBlob(length: number): Promise<Blob>;
42
- export declare function makeEncodedBlobFields(fields: Fr[]): Promise<Blob>;
38
+ export declare function makeRandomBlob(length: number): Blob;
43
39
  //# sourceMappingURL=testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,EAAmB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,SAAI,GAAG,UAAU,CAWnD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,SAAI,GAAG,gBAAgB,CAM/D;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,SAAI,GAAG,qBAAqB,CAEzE;AAmBD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/D;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjE"}
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 { BLOBS_PER_BLOCK } from '@aztec/constants';
1
+ import { FIELDS_PER_BLOB } from '@aztec/constants';
2
2
  import { makeTuple } from '@aztec/foundation/array';
3
- import { toBufferBE } from '@aztec/foundation/bigint-buffer';
4
- import { Fr } from '@aztec/foundation/fields';
3
+ import { randomInt } from '@aztec/foundation/crypto';
4
+ import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
5
5
  import { Blob } from './blob.js';
6
- import { BlobPublicInputs, BlockBlobPublicInputs } from './blob_public_inputs.js';
7
- import { TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH } from './encoding.js';
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.
@@ -15,36 +17,52 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
15
17
  return new SpongeBlob(new Poseidon2Sponge(makeTuple(3, (i)=>new Fr(i)), makeTuple(4, (i)=>new Fr(i)), 1, false), seed, seed + 1);
16
18
  }
17
19
  /**
18
- * Makes arbitrary blob public inputs.
20
+ * Makes arbitrary blob public accumulator.
19
21
  * Note: will not verify inside the circuit.
20
- * @param seed - The seed to use for generating the blob inputs.
21
- * @returns A blob public inputs instance.
22
- */ export function makeBlobPublicInputs(seed = 1) {
23
- return new BlobPublicInputs(new Fr(seed), BigInt(seed + 1), makeTuple(2, (i)=>new Fr(i)));
22
+ * @param seed - The seed to use for generating the blob accumulator.
23
+ * @returns A blob accumulator instance.
24
+ */ export function makeBatchedBlobAccumulator(seed = 1) {
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
- * Makes arbitrary block blob public inputs.
27
- * Note: will not verify inside the circuit.
28
- * @param seed - The seed to use for generating the blob inputs.
29
- * @returns A block blob public inputs instance.
30
- */ export function makeBlockBlobPublicInputs(seed = 1) {
31
- return new BlockBlobPublicInputs(makeTuple(BLOBS_PER_BLOCK, ()=>makeBlobPublicInputs(seed)));
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
+ ];
32
55
  }
33
- // TODO: copied form stdlib tx effect
34
- function encodeFirstField(length) {
35
- const lengthBuf = Buffer.alloc(2);
36
- lengthBuf.writeUInt16BE(length, 0);
37
- return new Fr(Buffer.concat([
38
- toBufferBE(TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH),
39
- Buffer.alloc(1),
40
- lengthBuf,
41
- Buffer.alloc(1),
42
- Buffer.from([
43
- 1
44
- ]),
45
- Buffer.alloc(1),
46
- Buffer.alloc(1)
47
- ]));
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.
48
66
  }
49
67
  /**
50
68
  * Make an encoded blob with the given length
@@ -53,29 +71,25 @@ function encodeFirstField(length) {
53
71
  * @param length
54
72
  * @returns
55
73
  */ export function makeEncodedBlob(length) {
56
- return Blob.fromFields([
57
- encodeFirstField(length + 1),
58
- ...Array.from({
59
- length: length
60
- }, ()=>Fr.random())
61
- ]);
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);
62
82
  }
63
83
  /**
64
- * Make an unencoded blob with the given length
84
+ * Make a blob with random fields.
65
85
  *
66
86
  * This will fail deserialisation in the archiver
67
87
  * @param length
68
88
  * @returns
69
- */ export function makeUnencodedBlob(length) {
89
+ */ export function makeRandomBlob(length) {
70
90
  return Blob.fromFields([
71
91
  ...Array.from({
72
92
  length: length
73
93
  }, ()=>Fr.random())
74
94
  ]);
75
95
  }
76
- export function makeEncodedBlobFields(fields) {
77
- return Blob.fromFields([
78
- encodeFirstField(fields.length + 1),
79
- ...fields
80
- ]);
81
- }
@@ -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
@@ -0,0 +1,3 @@
1
+ export * from './circuit_types/index.js';
2
+ export * from './interface.js';
3
+ export * from './sponge_blob.js';
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@aztec/blob-lib",
3
- "version": "0.0.0-test.1",
3
+ "version": "0.0.1-fake-c83136db25",
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": {
@@ -17,8 +19,6 @@
17
19
  "build": "yarn clean && tsc -b",
18
20
  "build:dev": "tsc -b --watch",
19
21
  "clean": "rm -rf ./dest .tsbuildinfo",
20
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
21
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
22
22
  "start:dev": "tsc-watch -p tsconfig.json --onSuccess 'yarn start'",
23
23
  "start": "node ./dest/index.js",
24
24
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
@@ -27,19 +27,19 @@
27
27
  "../package.common.json"
28
28
  ],
29
29
  "dependencies": {
30
- "@aztec/constants": "0.0.0-test.1",
31
- "@aztec/foundation": "0.0.0-test.1",
32
- "c-kzg": "4.0.0-alpha.1",
30
+ "@aztec/constants": "0.0.1-fake-c83136db25",
31
+ "@aztec/foundation": "0.0.1-fake-c83136db25",
32
+ "@crate-crypto/node-eth-kzg": "^0.10.0",
33
33
  "tslib": "^2.4.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@jest/globals": "^29.5.0",
37
- "@types/jest": "^29.5.0",
38
- "@types/node": "^18.14.6",
36
+ "@jest/globals": "^30.0.0",
37
+ "@types/jest": "^30.0.0",
38
+ "@types/node": "^22.15.17",
39
39
  "get-port": "^7.1.0",
40
- "jest": "^29.5.0",
40
+ "jest": "^30.0.0",
41
41
  "ts-node": "^10.9.1",
42
- "typescript": "^5.0.4"
42
+ "typescript": "^5.3.3"
43
43
  },
44
44
  "files": [
45
45
  "dest",
@@ -78,9 +78,13 @@
78
78
  "testTimeout": 120000,
79
79
  "setupFiles": [
80
80
  "../../foundation/src/jest/setup.mjs"
81
+ ],
82
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
83
+ "setupFilesAfterEnv": [
84
+ "../../foundation/src/jest/setupAfterEnv.mjs"
81
85
  ]
82
86
  },
83
87
  "engines": {
84
- "node": ">=18"
88
+ "node": ">=20.10"
85
89
  }
86
90
  }