@aztec/blob-lib 2.1.0-rc.9 → 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.
Files changed (65) hide show
  1. package/dest/blob.d.ts +52 -95
  2. package/dest/blob.d.ts.map +1 -1
  3. package/dest/blob.js +73 -165
  4. package/dest/blob_batching.d.ts +15 -48
  5. package/dest/blob_batching.d.ts.map +1 -1
  6. package/dest/blob_batching.js +81 -120
  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 +5 -2
  32. package/dest/index.d.ts.map +1 -1
  33. package/dest/index.js +5 -15
  34. package/dest/kzg_context.d.ts +4 -0
  35. package/dest/kzg_context.d.ts.map +1 -0
  36. package/dest/kzg_context.js +5 -0
  37. package/dest/sponge_blob.d.ts +13 -9
  38. package/dest/sponge_blob.d.ts.map +1 -1
  39. package/dest/sponge_blob.js +28 -17
  40. package/dest/testing.d.ts +7 -12
  41. package/dest/testing.d.ts.map +1 -1
  42. package/dest/testing.js +54 -41
  43. package/dest/types.d.ts +4 -0
  44. package/dest/types.d.ts.map +1 -1
  45. package/dest/types.js +2 -0
  46. package/package.json +5 -4
  47. package/src/blob.ts +76 -191
  48. package/src/blob_batching.ts +109 -137
  49. package/src/blob_utils.ts +71 -0
  50. package/src/circuit_types/blob_accumulator.ts +84 -0
  51. package/src/circuit_types/final_blob_accumulator.ts +75 -0
  52. package/src/circuit_types/final_blob_batching_challenges.ts +29 -0
  53. package/src/circuit_types/index.ts +4 -0
  54. package/src/deserialize.ts +38 -0
  55. package/src/encoding.ts +136 -120
  56. package/src/hash.ts +77 -0
  57. package/src/index.ts +5 -18
  58. package/src/kzg_context.ts +5 -0
  59. package/src/sponge_blob.ts +24 -14
  60. package/src/testing.ts +55 -40
  61. package/src/types.ts +4 -2
  62. package/dest/blob_batching_public_inputs.d.ts +0 -71
  63. package/dest/blob_batching_public_inputs.d.ts.map +0 -1
  64. package/dest/blob_batching_public_inputs.js +0 -168
  65. 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 './blob_batching_public_inputs.js';
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,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
+ });
@@ -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 a blob.
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 tx effects that will go into a blob. */
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
- fields: number;
12
+ numAbsorbedFields: number;
13
13
  /** Number of effects that will be absorbed. */
14
- readonly expectedFields: number;
14
+ readonly numExpectedFields: number;
15
15
  constructor(
16
- /** Sponge with absorbed tx effects that will go into a blob. */
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
- fields: number,
19
+ numAbsorbedFields: number,
20
20
  /** Number of effects that will be absorbed. */
21
- expectedFields: number);
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
- 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>;
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(expectedFields: number): Poseidon2Sponge;
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":"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,MAA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AC,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"}
@@ -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,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
- * Makes arbitrary block blob public inputs.
22
- * Note: will not verify inside the circuit.
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): Promise<Blob>;
29
+ export declare function makeEncodedBlob(length: number): Blob;
30
+ export declare function makeEncodedBlobs(length: number): Blob[];
35
31
  /**
36
- * Make an unencoded blob with the given length
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 makeUnencodedBlob(length: number): Promise<Blob>;
43
- export declare function makeEncodedBlobFields(fields: Fr[]): Promise<Blob>;
38
+ export declare function makeRandomBlob(length: number): Blob;
44
39
  //# sourceMappingURL=testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MA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O,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 { toBufferBE } from '@aztec/foundation/bigint-buffer';
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, FinalBlobBatchingChallenges } from './blob_batching.js';
6
- import { BlobAccumulatorPublicInputs, BlockBlobPublicInputs } from './blob_batching_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.
@@ -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
- * 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
- const startBlobAccumulator = makeBatchedBlobAccumulator(seed);
32
- return new BlockBlobPublicInputs(BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(startBlobAccumulator), BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(makeBatchedBlobAccumulator(seed + 1)), startBlobAccumulator.finalBlobChallenges);
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
- // TODO: copied form stdlib tx effect
35
- function encodeFirstField(length) {
36
- const lengthBuf = Buffer.alloc(2);
37
- lengthBuf.writeUInt16BE(length, 0);
38
- return new Fr(Buffer.concat([
39
- toBufferBE(TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH),
40
- Buffer.alloc(1),
41
- lengthBuf,
42
- Buffer.alloc(1),
43
- Buffer.from([
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
- return Blob.fromFields([
58
- encodeFirstField(length + 1),
59
- ...Array.from({
60
- length: length
61
- }, ()=>Fr.random())
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 an unencoded blob with the given length
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 makeUnencodedBlob(length) {
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 CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './circuit_types/index.js';
2
+ export * from './interface.js';
1
3
  export * from './sponge_blob.js';
2
4
  /**
3
5
  * Type definition for the KZG instance returned by Blob.getViemKzgInstance().
@@ -8,5 +10,7 @@ export interface BlobKzgInstance {
8
10
  blobToKzgCommitment(blob: Uint8Array): Uint8Array;
9
11
  /** Function to compute KZG proof for blob data */
10
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[]];
11
15
  }
12
16
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAIjC;;;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;CAC3E"}
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 CHANGED
@@ -1 +1,3 @@
1
+ export * from './circuit_types/index.js';
2
+ export * from './interface.js';
1
3
  export * from './sponge_blob.js';
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@aztec/blob-lib",
3
- "version": "2.1.0-rc.9",
3
+ "version": "3.0.0-devnet.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
7
+ "./encoding": "./dest/encoding.js",
7
8
  "./types": "./dest/types.js",
8
9
  "./testing": "./dest/testing.js"
9
10
  },
@@ -26,9 +27,9 @@
26
27
  "../package.common.json"
27
28
  ],
28
29
  "dependencies": {
29
- "@aztec/constants": "2.1.0-rc.9",
30
- "@aztec/foundation": "2.1.0-rc.9",
31
- "c-kzg": "4.0.0-alpha.1",
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",
32
33
  "tslib": "^2.4.0"
33
34
  },
34
35
  "devDependencies": {