@aztec/blob-lib 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107

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 (106) hide show
  1. package/dest/batched_blob.d.ts +26 -0
  2. package/dest/batched_blob.d.ts.map +1 -0
  3. package/dest/batched_blob.js +20 -0
  4. package/dest/blob.d.ts +50 -99
  5. package/dest/blob.d.ts.map +1 -1
  6. package/dest/blob.js +78 -169
  7. package/dest/blob_batching.d.ts +41 -123
  8. package/dest/blob_batching.d.ts.map +1 -1
  9. package/dest/blob_batching.js +129 -203
  10. package/dest/blob_utils.d.ts +40 -0
  11. package/dest/blob_utils.d.ts.map +1 -0
  12. package/dest/blob_utils.js +69 -0
  13. package/dest/circuit_types/blob_accumulator.d.ts +23 -0
  14. package/dest/circuit_types/blob_accumulator.d.ts.map +1 -0
  15. package/dest/circuit_types/blob_accumulator.js +62 -0
  16. package/dest/circuit_types/final_blob_accumulator.d.ts +23 -0
  17. package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -0
  18. package/dest/circuit_types/final_blob_accumulator.js +66 -0
  19. package/dest/circuit_types/final_blob_batching_challenges.d.ts +16 -0
  20. package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -0
  21. package/dest/circuit_types/final_blob_batching_challenges.js +26 -0
  22. package/dest/circuit_types/index.d.ts +4 -0
  23. package/dest/circuit_types/index.d.ts.map +1 -0
  24. package/dest/circuit_types/index.js +4 -0
  25. package/dest/encoding/block_blob_data.d.ts +22 -0
  26. package/dest/encoding/block_blob_data.d.ts.map +1 -0
  27. package/dest/encoding/block_blob_data.js +65 -0
  28. package/dest/encoding/block_end_marker.d.ts +11 -0
  29. package/dest/encoding/block_end_marker.d.ts.map +1 -0
  30. package/dest/encoding/block_end_marker.js +41 -0
  31. package/dest/encoding/block_end_state_field.d.ts +12 -0
  32. package/dest/encoding/block_end_state_field.d.ts.map +1 -0
  33. package/dest/encoding/block_end_state_field.js +39 -0
  34. package/dest/encoding/checkpoint_blob_data.d.ts +15 -0
  35. package/dest/encoding/checkpoint_blob_data.d.ts.map +1 -0
  36. package/dest/encoding/checkpoint_blob_data.js +67 -0
  37. package/dest/encoding/checkpoint_end_marker.d.ts +8 -0
  38. package/dest/encoding/checkpoint_end_marker.d.ts.map +1 -0
  39. package/dest/encoding/checkpoint_end_marker.js +28 -0
  40. package/dest/encoding/fixtures.d.ts +41 -0
  41. package/dest/encoding/fixtures.d.ts.map +1 -0
  42. package/dest/encoding/fixtures.js +140 -0
  43. package/dest/encoding/index.d.ts +10 -0
  44. package/dest/encoding/index.d.ts.map +1 -0
  45. package/dest/encoding/index.js +9 -0
  46. package/dest/encoding/tx_blob_data.d.ts +19 -0
  47. package/dest/encoding/tx_blob_data.d.ts.map +1 -0
  48. package/dest/encoding/tx_blob_data.js +79 -0
  49. package/dest/encoding/tx_start_marker.d.ts +16 -0
  50. package/dest/encoding/tx_start_marker.d.ts.map +1 -0
  51. package/dest/encoding/tx_start_marker.js +77 -0
  52. package/dest/errors.d.ts +1 -1
  53. package/dest/errors.d.ts.map +1 -1
  54. package/dest/hash.d.ts +43 -0
  55. package/dest/hash.d.ts.map +1 -0
  56. package/dest/hash.js +80 -0
  57. package/dest/index.d.ts +7 -4
  58. package/dest/index.d.ts.map +1 -1
  59. package/dest/index.js +6 -16
  60. package/dest/interface.d.ts +1 -2
  61. package/dest/interface.d.ts.map +1 -1
  62. package/dest/kzg_context.d.ts +8 -0
  63. package/dest/kzg_context.d.ts.map +1 -0
  64. package/dest/kzg_context.js +14 -0
  65. package/dest/sponge_blob.d.ts +12 -14
  66. package/dest/sponge_blob.d.ts.map +1 -1
  67. package/dest/sponge_blob.js +26 -30
  68. package/dest/testing.d.ts +10 -23
  69. package/dest/testing.d.ts.map +1 -1
  70. package/dest/testing.js +37 -53
  71. package/dest/types.d.ts +17 -0
  72. package/dest/types.d.ts.map +1 -0
  73. package/dest/types.js +4 -0
  74. package/package.json +10 -7
  75. package/src/batched_blob.ts +26 -0
  76. package/src/blob.ts +81 -195
  77. package/src/blob_batching.ts +168 -231
  78. package/src/blob_utils.ts +82 -0
  79. package/src/circuit_types/blob_accumulator.ts +96 -0
  80. package/src/circuit_types/final_blob_accumulator.ts +76 -0
  81. package/src/circuit_types/final_blob_batching_challenges.ts +30 -0
  82. package/src/circuit_types/index.ts +4 -0
  83. package/src/encoding/block_blob_data.ts +102 -0
  84. package/src/encoding/block_end_marker.ts +55 -0
  85. package/src/encoding/block_end_state_field.ts +59 -0
  86. package/src/encoding/checkpoint_blob_data.ts +95 -0
  87. package/src/encoding/checkpoint_end_marker.ts +40 -0
  88. package/src/encoding/fixtures.ts +210 -0
  89. package/src/encoding/index.ts +9 -0
  90. package/src/encoding/tx_blob_data.ts +116 -0
  91. package/src/encoding/tx_start_marker.ts +97 -0
  92. package/src/hash.ts +89 -0
  93. package/src/index.ts +6 -19
  94. package/src/interface.ts +0 -1
  95. package/src/kzg_context.ts +16 -0
  96. package/src/sponge_blob.ts +28 -31
  97. package/src/testing.ts +48 -59
  98. package/src/types.ts +17 -0
  99. package/dest/blob_batching_public_inputs.d.ts +0 -71
  100. package/dest/blob_batching_public_inputs.d.ts.map +0 -1
  101. package/dest/blob_batching_public_inputs.js +0 -168
  102. package/dest/encoding.d.ts +0 -66
  103. package/dest/encoding.d.ts.map +0 -1
  104. package/dest/encoding.js +0 -113
  105. package/src/blob_batching_public_inputs.ts +0 -252
  106. package/src/encoding.ts +0 -138
@@ -0,0 +1,26 @@
1
+ import { BLS12Fr, BLS12Point } from '@aztec/foundation/curves/bls12';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { FinalBlobAccumulator } from './circuit_types/index.js';
4
+ /**
5
+ * A class to represent the result from accumulating blobs in an epoch using BatchedBlobAccumulator.
6
+ */
7
+ export declare class BatchedBlob {
8
+ readonly blobCommitmentsHash: Fr;
9
+ readonly z: Fr;
10
+ readonly y: BLS12Fr;
11
+ readonly commitment: BLS12Point;
12
+ readonly q: BLS12Point;
13
+ constructor(
14
+ /** Hash of Cs (to link to L1 blob hashes). */
15
+ blobCommitmentsHash: Fr,
16
+ /** Challenge point z such that p_i(z) = y_i. */
17
+ z: Fr,
18
+ /** Evaluation y, linear combination of all evaluations y_i = p_i(z) with gamma. */
19
+ y: BLS12Fr,
20
+ /** Commitment C, linear combination of all commitments C_i = [p_i] with gamma. */
21
+ commitment: BLS12Point,
22
+ /** KZG opening 'proof' Q (commitment to the quotient poly.), linear combination of all blob kzg 'proofs' Q_i with gamma. */
23
+ q: BLS12Point);
24
+ toFinalBlobAccumulator(): FinalBlobAccumulator;
25
+ }
26
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmF0Y2hlZF9ibG9iLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYmF0Y2hlZF9ibG9iLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDckUsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBRWhFOztHQUVHO0FBQ0gscUJBQWEsV0FBVzthQUdKLG1CQUFtQixFQUFFLEVBQUU7YUFFdkIsQ0FBQyxFQUFFLEVBQUU7YUFFTCxDQUFDLEVBQUUsT0FBTzthQUVWLFVBQVUsRUFBRSxVQUFVO2FBRXRCLENBQUMsRUFBRSxVQUFVO0lBVi9CO0lBQ0UsOENBQThDO0lBQzlCLG1CQUFtQixFQUFFLEVBQUU7SUFDdkMsZ0RBQWdEO0lBQ2hDLENBQUMsRUFBRSxFQUFFO0lBQ3JCLG1GQUFtRjtJQUNuRSxDQUFDLEVBQUUsT0FBTztJQUMxQixrRkFBa0Y7SUFDbEUsVUFBVSxFQUFFLFVBQVU7SUFDdEMsNEhBQTRIO0lBQzVHLENBQUMsRUFBRSxVQUFVLEVBQzNCO0lBRUosc0JBQXNCLHlCQUVyQjtDQUNGIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batched_blob.d.ts","sourceRoot":"","sources":["../src/batched_blob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE;;GAEG;AACH,qBAAa,WAAW;aAGJ,mBAAmB,EAAE,EAAE;aAEvB,CAAC,EAAE,EAAE;aAEL,CAAC,EAAE,OAAO;aAEV,UAAU,EAAE,UAAU;aAEtB,CAAC,EAAE,UAAU;IAV/B;IACE,8CAA8C;IAC9B,mBAAmB,EAAE,EAAE;IACvC,gDAAgD;IAChC,CAAC,EAAE,EAAE;IACrB,mFAAmF;IACnE,CAAC,EAAE,OAAO;IAC1B,kFAAkF;IAClE,UAAU,EAAE,UAAU;IACtC,4HAA4H;IAC5G,CAAC,EAAE,UAAU,EAC3B;IAEJ,sBAAsB,yBAErB;CACF"}
@@ -0,0 +1,20 @@
1
+ import { FinalBlobAccumulator } from './circuit_types/index.js';
2
+ /**
3
+ * A class to represent the result from accumulating blobs in an epoch using BatchedBlobAccumulator.
4
+ */ export class BatchedBlob {
5
+ blobCommitmentsHash;
6
+ z;
7
+ y;
8
+ commitment;
9
+ q;
10
+ constructor(/** Hash of Cs (to link to L1 blob hashes). */ blobCommitmentsHash, /** Challenge point z such that p_i(z) = y_i. */ z, /** Evaluation y, linear combination of all evaluations y_i = p_i(z) with gamma. */ y, /** Commitment C, linear combination of all commitments C_i = [p_i] with gamma. */ commitment, /** KZG opening 'proof' Q (commitment to the quotient poly.), linear combination of all blob kzg 'proofs' Q_i with gamma. */ q){
11
+ this.blobCommitmentsHash = blobCommitmentsHash;
12
+ this.z = z;
13
+ this.y = y;
14
+ this.commitment = commitment;
15
+ this.q = q;
16
+ }
17
+ toFinalBlobAccumulator() {
18
+ return new FinalBlobAccumulator(this.blobCommitmentsHash, this.z, this.y, this.commitment);
19
+ }
20
+ }
package/dest/blob.d.ts CHANGED
@@ -1,131 +1,94 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { FIELDS_PER_BLOB } from '@aztec/constants';
2
+ import { BLS12Fr } from '@aztec/foundation/curves/bls12';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
4
  import { BufferReader } from '@aztec/foundation/serialize';
3
- import cKzg from 'c-kzg';
4
- import type { Blob as BlobBuffer } from 'c-kzg';
5
5
  import type { BlobJson } from './interface.js';
6
- export declare const VERSIONED_HASH_VERSION_KZG = 1;
6
+ export { FIELDS_PER_BLOB };
7
7
  /**
8
8
  * A class to create, manage, and prove EVM blobs.
9
+ *
10
+ * @dev Note: All methods in this class do not check the encoding of the given data. It's the responsibility of other
11
+ * components to ensure that the blob data (which might spread across multiple blobs) was created following the protocol
12
+ * and is correctly encoded.
9
13
  */
10
14
  export declare class Blob {
11
- /** The blob to be broadcast on L1 in bytes form. */
12
- readonly data: BlobBuffer;
13
- /** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */
14
- readonly fieldsHash: Fr;
15
- /** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts). */
16
- readonly challengeZ: Fr;
17
- /** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */
15
+ readonly data: Uint8Array;
18
16
  readonly commitment: Buffer;
19
17
  constructor(
20
- /** The blob to be broadcast on L1 in bytes form. */
21
- data: BlobBuffer,
22
- /** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */
23
- fieldsHash: Fr,
24
- /** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts). */
25
- challengeZ: Fr,
26
- /** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */
18
+ /**
19
+ * The data to be broadcast on L1 in bytes form.
20
+ */
21
+ data: Uint8Array,
22
+ /**
23
+ * Commitment to the blob data. Used in compressed BLS12 point format (48 bytes).
24
+ */
27
25
  commitment: Buffer);
28
26
  /**
29
- * The encoded version of the blob will determine the end of the blob based on the transaction encoding.
30
- * This is required when the fieldsHash of a blob will contain trailing zeros.
31
- *
32
- * See `./encoding.ts` for more details.
33
- *
34
- * This method is used to create a Blob from a buffer.
35
- * @param blob - The buffer to create the Blob from.
36
- * @param multiBlobFieldsHash - The fields hash to use for the Blob.
27
+ * Create a Blob from a buffer.
28
+ * @param data - The buffer of the Blob.
37
29
  * @returns A Blob created from the buffer.
38
30
  *
39
- * @throws If unable to deserialize the blob.
31
+ * @throws If data does not match the expected length (BYTES_PER_BLOB).
40
32
  */
41
- static fromEncodedBlobBuffer(blob: BlobBuffer, multiBlobFieldsHash?: Fr): Promise<Blob>;
33
+ static fromBlobBuffer(data: Uint8Array): Blob;
42
34
  /**
43
35
  * Create a Blob from an array of fields.
44
36
  *
37
+ * @dev This method pads 0s to the data, extending it to the size of a full blob.
38
+ *
45
39
  * @param fields - The array of fields to create the Blob from.
46
- * @param multiBlobFieldsHash - The fields hash to use for the Blob.
47
40
  * @returns A Blob created from the array of fields.
48
41
  */
49
- static fromFields(fields: Fr[], multiBlobFieldsHash?: Fr): Promise<Blob>;
42
+ static fromFields(fields: Fr[]): Blob;
43
+ /**
44
+ * Get the fields from the blob data.
45
+ *
46
+ * @dev WARNING: this method returns all fields
47
+ *
48
+ * @returns The fields from the blob.
49
+ */
50
+ toFields(): Fr[];
50
51
  /**
51
52
  * Create a Blob from a JSON object.
52
53
  *
53
- * Blobs will be in this form when requested from the blob sink, or from
54
+ * Blobs will be in this form when requested from the blob client, or from
54
55
  * the beacon chain via `getBlobSidecars`
55
56
  * https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getBlobSidecars
56
57
  *
57
- * @dev WARNING: by default json deals with encoded buffers
58
- *
59
58
  * @param json - The JSON object to create the Blob from.
60
59
  * @returns A Blob created from the JSON object.
61
60
  */
62
- static fromJson(json: BlobJson): Promise<Blob>;
61
+ static fromJson(json: BlobJson): Blob;
63
62
  /**
64
63
  * Get the JSON representation of the blob.
65
64
  *
66
- * @dev WARNING: by default json deals with encoded buffers
67
- * @param index - optional - The index of the blob in the block.
68
65
  * @returns The JSON representation of the blob.
69
66
  */
70
- toJson(index: number): BlobJson;
71
- /**
72
- * Get the fields from the blob.
73
- *
74
- * @dev WARNING: this method does not take into account trailing zeros
75
- *
76
- * @returns The fields from the blob.
77
- */
78
- toFields(): Fr[];
79
- /**
80
- * Get the encoded fields from the blob.
81
- *
82
- * @dev This method takes into account trailing zeros
83
- *
84
- * @returns The encoded fields from the blob.
85
- *
86
- * @throws If unable to deserialize the blob.
87
- */
88
- toEncodedFields(): Fr[];
89
- /**
90
- * Get the encoded fields from multiple blobs.
91
- *
92
- * @dev This method takes into account trailing zeros
93
- *
94
- * @returns The encoded fields from the blobs.
95
- */
96
- static toEncodedFields(blobs: Blob[]): Fr[];
67
+ toJSON(): BlobJson;
68
+ getEthVersionedBlobHash(): Buffer;
97
69
  /**
98
- * Get the commitment fields from the blob.
99
- *
100
- * The 48-byte commitment is encoded into two field elements:
101
- * +------------------+------------------+
102
- * | Field Element 1 | Field Element 2 |
103
- * | [bytes 0-31] | [bytes 32-47] |
104
- * +------------------+------------------+
105
- * | 32 bytes | 16 bytes |
106
- * +------------------+------------------+
107
- * @returns The commitment fields from the blob.
70
+ * Challenge point z (= H(H(tx_effects), kzgCommitment)).
71
+ * Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts).
108
72
  */
109
- commitmentToFields(): [Fr, Fr];
110
- getEthVersionedBlobHash(): Buffer;
111
- static getEthVersionedBlobHash(commitment: Buffer): Buffer;
73
+ computeChallengeZ(blobFieldsHash: Fr): Promise<Fr>;
112
74
  /**
113
75
  * Evaluate the blob at a given challenge and return the evaluation and KZG proof.
114
76
  *
115
- * @param challengeZ - The challenge z at which to evaluate the blob. If not given, assume we want to evaluate at the individual blob's z.
77
+ * @param challengeZ - The challenge z at which to evaluate the blob.
78
+ * @param verifyProof - Whether to verify the KZG proof.
116
79
  *
117
- * @returns -
118
- * y: Buffer - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts
80
+ * @returns
81
+ * y: BLS12Fr - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts.
119
82
  * proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
120
83
  */
121
- evaluate(challengeZ?: Fr): {
122
- y: Buffer<ArrayBuffer>;
84
+ evaluate(challengeZ: Fr, verifyProof?: boolean): {
85
+ y: BLS12Fr;
123
86
  proof: Buffer<ArrayBuffer>;
124
87
  };
125
88
  /**
126
89
  * Get the buffer representation of the ENTIRE blob.
127
90
  *
128
- * @dev WARNING: this buffer contains all metadata aswell as the data itself
91
+ * @dev WARNING: this buffer contains all metadata as well as the data itself.
129
92
  *
130
93
  * @returns The buffer representation of the blob.
131
94
  */
@@ -133,7 +96,7 @@ export declare class Blob {
133
96
  /**
134
97
  * Create a Blob from a buffer.
135
98
  *
136
- * @dev WARNING: this method contains all metadata aswell as the data itself
99
+ * @dev WARNING: this method contains all metadata as well as the data itself.
137
100
  *
138
101
  * @param buf - The buffer to create the Blob from.
139
102
  * @returns A Blob created from the buffer.
@@ -143,22 +106,10 @@ export declare class Blob {
143
106
  * Get the size of the blob in bytes
144
107
  */
145
108
  getSize(): number;
146
- /**
147
- * @param blobs - The blobs to emit
148
- * @returns The blobs' compressed commitments in hex prefixed by the number of blobs
149
- * @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs:
150
- * One byte for the number blobs + 48 bytes per blob commitment
151
- */
152
- static getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${string}`;
153
109
  static getViemKzgInstance(): {
154
- blobToKzgCommitment: typeof cKzg.blobToKzgCommitment;
155
- computeBlobKzgProof: typeof cKzg.computeBlobKzgProof;
110
+ blobToKzgCommitment: (blob: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
111
+ computeBlobKzgProof: (blob: Uint8Array<ArrayBufferLike>, commitment: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
112
+ computeCellsAndKzgProofs: (b: Uint8Array<ArrayBufferLike>) => [Uint8Array<ArrayBufferLike>[], Uint8Array<ArrayBufferLike>[]];
156
113
  };
157
- /**
158
- * @param fields - Fields to broadcast in the blob(s)
159
- * @returns As many blobs as we require to broadcast the given fields for a block
160
- * @dev Assumes we share the fields hash between all blobs which can only be done for ONE BLOCK because the hash is calculated in block root.
161
- */
162
- static getBlobsPerBlock(fields: Fr[]): Promise<Blob[]>;
163
114
  }
164
- //# sourceMappingURL=blob.d.ts.map
115
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvYi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2Jsb2IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGVBQWUsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBQ25ELE9BQU8sRUFBRSxPQUFPLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxFQUFFLFlBQVksRUFBcUIsTUFBTSw2QkFBNkIsQ0FBQztBQUc5RSxPQUFPLEtBQUssRUFBRSxRQUFRLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUcvQyxPQUFPLEVBQUUsZUFBZSxFQUFFLENBQUM7Q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UAAU;aAIhB,UAAU,EAAE,MAAM;IARpC;IACE;;OAEG;IACa,IAAI,EAAE,UAAU;IAChC;;OAEG;IACa,UAAU,EAAE,MAAM,EAQnC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAG5C;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAQpC;IAED;;;;;;OAMG;IACH,QAAQ,IAAI,EAAE,EAAE,CAIf;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CASpC;IAED;;;;OAIG;IACH,MAAM,IAAI,QAAQ,CAMjB;IAED,uBAAuB,IAAI,MAAM,CAEhC;IAED;;;OAGG;IACG,iBAAiB,CAAC,cAAc,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAEvD;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,UAAU,EAAE,EAAE,EAAE,WAAW,UAAQ;;;MAU3C;IAED;;;;;;OAMG;IACH,QAAQ,IAAI,MAAM,CAEjB;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAGlD;IAED;;OAEG;IACH,OAAO,WAEN;IAED,MAAM,CAAC,kBAAkB;;;;MAUxB;CACF"}
package/dest/blob.js CHANGED
@@ -1,181 +1,125 @@
1
- import { poseidon2Hash, sha256 } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
1
+ import { FIELDS_PER_BLOB } from '@aztec/constants';
2
+ import { BLS12Fr } from '@aztec/foundation/curves/bls12';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
- // Importing directly from 'c-kzg' does not work:
5
- import cKzg from 'c-kzg';
6
- import { deserializeEncodedBlobToFields, extractBlobFieldsFromBuffer } from './encoding.js';
7
- import { BlobDeserializationError } from './errors.js';
8
- const { BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, blobToKzgCommitment, computeKzgProof, verifyKzgProof } = cKzg;
9
- // The prefix to the EVM blobHash, defined here: https://eips.ethereum.org/EIPS/eip-4844#specification
10
- export const VERSIONED_HASH_VERSION_KZG = 0x01;
5
+ import { computeBlobCommitment, computeChallengeZ, computeEthVersionedBlobHash } from './hash.js';
6
+ import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, getKzg } from './kzg_context.js';
7
+ export { FIELDS_PER_BLOB };
11
8
  /**
12
9
  * A class to create, manage, and prove EVM blobs.
10
+ *
11
+ * @dev Note: All methods in this class do not check the encoding of the given data. It's the responsibility of other
12
+ * components to ensure that the blob data (which might spread across multiple blobs) was created following the protocol
13
+ * and is correctly encoded.
13
14
  */ export class Blob {
14
15
  data;
15
- fieldsHash;
16
- challengeZ;
17
16
  commitment;
18
- constructor(/** The blob to be broadcast on L1 in bytes form. */ data, /** The hash of all tx effects inside the blob. Used in generating the challenge z and proving that we have included all required effects. */ fieldsHash, /** Challenge point z (= H(H(tx_effects), kzgCommmitment). Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts). */ challengeZ, /** Commitment to the blob C. Used in compressed BLS12 point format (48 bytes). */ commitment){
17
+ constructor(/**
18
+ * The data to be broadcast on L1 in bytes form.
19
+ */ data, /**
20
+ * Commitment to the blob data. Used in compressed BLS12 point format (48 bytes).
21
+ */ commitment){
19
22
  this.data = data;
20
- this.fieldsHash = fieldsHash;
21
- this.challengeZ = challengeZ;
22
23
  this.commitment = commitment;
24
+ if (data.length !== BYTES_PER_BLOB) {
25
+ throw new Error(`Blob data must be ${BYTES_PER_BLOB} bytes. Got ${data.length}.`);
26
+ }
27
+ if (commitment.length !== BYTES_PER_COMMITMENT) {
28
+ throw new Error(`Blob commitment must be ${BYTES_PER_COMMITMENT} bytes. Got ${commitment.length}.`);
29
+ }
23
30
  }
24
31
  /**
25
- * The encoded version of the blob will determine the end of the blob based on the transaction encoding.
26
- * This is required when the fieldsHash of a blob will contain trailing zeros.
27
- *
28
- * See `./encoding.ts` for more details.
29
- *
30
- * This method is used to create a Blob from a buffer.
31
- * @param blob - The buffer to create the Blob from.
32
- * @param multiBlobFieldsHash - The fields hash to use for the Blob.
32
+ * Create a Blob from a buffer.
33
+ * @param data - The buffer of the Blob.
33
34
  * @returns A Blob created from the buffer.
34
35
  *
35
- * @throws If unable to deserialize the blob.
36
- */ static fromEncodedBlobBuffer(blob, multiBlobFieldsHash) {
37
- try {
38
- const fields = deserializeEncodedBlobToFields(blob);
39
- return Blob.fromFields(fields, multiBlobFieldsHash);
40
- } catch {
41
- throw new BlobDeserializationError(`Failed to create Blob from encoded blob buffer, this blob was likely not created by us`);
42
- }
36
+ * @throws If data does not match the expected length (BYTES_PER_BLOB).
37
+ */ static fromBlobBuffer(data) {
38
+ const commitment = computeBlobCommitment(data);
39
+ return new Blob(data, commitment);
43
40
  }
44
41
  /**
45
42
  * Create a Blob from an array of fields.
46
43
  *
44
+ * @dev This method pads 0s to the data, extending it to the size of a full blob.
45
+ *
47
46
  * @param fields - The array of fields to create the Blob from.
48
- * @param multiBlobFieldsHash - The fields hash to use for the Blob.
49
47
  * @returns A Blob created from the array of fields.
50
- */ static async fromFields(fields, multiBlobFieldsHash) {
51
- if (fields.length > FIELD_ELEMENTS_PER_BLOB) {
52
- throw new Error(`Attempted to overfill blob with ${fields.length} elements. The maximum is ${FIELD_ELEMENTS_PER_BLOB}`);
48
+ */ static fromFields(fields) {
49
+ if (fields.length > FIELDS_PER_BLOB) {
50
+ throw new Error(`Attempted to overfill blob with ${fields.length} fields. The maximum is ${FIELDS_PER_BLOB}.`);
53
51
  }
54
52
  const data = Buffer.concat([
55
53
  serializeToBuffer(fields)
56
54
  ], BYTES_PER_BLOB);
57
- // This matches the output of SpongeBlob.squeeze() in the blob circuit
58
- const fieldsHash = multiBlobFieldsHash ? multiBlobFieldsHash : await poseidon2Hash(fields);
59
- const commitment = Buffer.from(blobToKzgCommitment(data));
60
- const challengeZ = await poseidon2Hash([
61
- fieldsHash,
62
- ...commitmentToFields(commitment)
63
- ]);
64
- return new Blob(data, fieldsHash, challengeZ, commitment);
55
+ const commitment = computeBlobCommitment(data);
56
+ return new Blob(data, commitment);
57
+ }
58
+ /**
59
+ * Get the fields from the blob data.
60
+ *
61
+ * @dev WARNING: this method returns all fields
62
+ *
63
+ * @returns The fields from the blob.
64
+ */ toFields() {
65
+ const reader = BufferReader.asReader(this.data);
66
+ const numTotalFields = this.data.length / Fr.SIZE_IN_BYTES;
67
+ return reader.readArray(numTotalFields, Fr);
65
68
  }
66
69
  /**
67
70
  * Create a Blob from a JSON object.
68
71
  *
69
- * Blobs will be in this form when requested from the blob sink, or from
72
+ * Blobs will be in this form when requested from the blob client, or from
70
73
  * the beacon chain via `getBlobSidecars`
71
74
  * https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getBlobSidecars
72
75
  *
73
- * @dev WARNING: by default json deals with encoded buffers
74
- *
75
76
  * @param json - The JSON object to create the Blob from.
76
77
  * @returns A Blob created from the JSON object.
77
- */ static async fromJson(json) {
78
+ */ static fromJson(json) {
78
79
  const blobBuffer = Buffer.from(json.blob.slice(2), 'hex');
79
- const blob = await Blob.fromEncodedBlobBuffer(blobBuffer);
80
+ const blob = Blob.fromBlobBuffer(blobBuffer);
80
81
  if (blob.commitment.toString('hex') !== json.kzg_commitment.slice(2)) {
81
82
  throw new Error('KZG commitment does not match');
82
83
  }
83
- // We do not check the proof, as it will be different if the challenge is shared
84
- // across multiple blobs
85
84
  return blob;
86
85
  }
87
86
  /**
88
87
  * Get the JSON representation of the blob.
89
88
  *
90
- * @dev WARNING: by default json deals with encoded buffers
91
- * @param index - optional - The index of the blob in the block.
92
89
  * @returns The JSON representation of the blob.
93
- */ toJson(index) {
90
+ */ toJSON() {
94
91
  return {
95
92
  blob: `0x${Buffer.from(this.data).toString('hex')}`,
96
- index: index.toString(),
97
93
  // eslint-disable-next-line camelcase
98
94
  kzg_commitment: `0x${this.commitment.toString('hex')}`
99
95
  };
100
96
  }
101
- /**
102
- * Get the fields from the blob.
103
- *
104
- * @dev WARNING: this method does not take into account trailing zeros
105
- *
106
- * @returns The fields from the blob.
107
- */ toFields() {
108
- return extractBlobFieldsFromBuffer(this.data);
109
- }
110
- /**
111
- * Get the encoded fields from the blob.
112
- *
113
- * @dev This method takes into account trailing zeros
114
- *
115
- * @returns The encoded fields from the blob.
116
- *
117
- * @throws If unable to deserialize the blob.
118
- */ toEncodedFields() {
119
- try {
120
- return deserializeEncodedBlobToFields(this.data);
121
- } catch {
122
- throw new BlobDeserializationError(`Failed to deserialize encoded blob fields, this blob was likely not created by us`);
123
- }
124
- }
125
- /**
126
- * Get the encoded fields from multiple blobs.
127
- *
128
- * @dev This method takes into account trailing zeros
129
- *
130
- * @returns The encoded fields from the blobs.
131
- */ static toEncodedFields(blobs) {
132
- try {
133
- return deserializeEncodedBlobToFields(Buffer.concat(blobs.map((b)=>b.data)));
134
- } catch {
135
- throw new BlobDeserializationError(`Failed to deserialize encoded blob fields, this blob was likely not created by us`);
136
- }
137
- }
138
- /**
139
- * Get the commitment fields from the blob.
140
- *
141
- * The 48-byte commitment is encoded into two field elements:
142
- * +------------------+------------------+
143
- * | Field Element 1 | Field Element 2 |
144
- * | [bytes 0-31] | [bytes 32-47] |
145
- * +------------------+------------------+
146
- * | 32 bytes | 16 bytes |
147
- * +------------------+------------------+
148
- * @returns The commitment fields from the blob.
149
- */ commitmentToFields() {
150
- return commitmentToFields(this.commitment);
151
- }
152
- // Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
153
97
  getEthVersionedBlobHash() {
154
- const hash = sha256(this.commitment);
155
- hash[0] = VERSIONED_HASH_VERSION_KZG;
156
- return hash;
98
+ return computeEthVersionedBlobHash(this.commitment);
157
99
  }
158
- static getEthVersionedBlobHash(commitment) {
159
- const hash = sha256(commitment);
160
- hash[0] = VERSIONED_HASH_VERSION_KZG;
161
- return hash;
100
+ /**
101
+ * Challenge point z (= H(H(tx_effects), kzgCommitment)).
102
+ * Used such that p(z) = y for a single blob, used as z_i in batching (see ./blob_batching.ts).
103
+ */ async computeChallengeZ(blobFieldsHash) {
104
+ return await computeChallengeZ(blobFieldsHash, this.commitment);
162
105
  }
163
106
  /**
164
107
  * Evaluate the blob at a given challenge and return the evaluation and KZG proof.
165
108
  *
166
- * @param challengeZ - The challenge z at which to evaluate the blob. If not given, assume we want to evaluate at the individual blob's z.
109
+ * @param challengeZ - The challenge z at which to evaluate the blob.
110
+ * @param verifyProof - Whether to verify the KZG proof.
167
111
  *
168
- * @returns -
169
- * y: Buffer - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts
112
+ * @returns
113
+ * y: BLS12Fr - Evaluation y = p(z), where p() is the blob polynomial. BLS12 field element, rep. as BigNum in nr, bigint in ts.
170
114
  * proof: Buffer - KZG opening proof for y = p(z). The commitment to quotient polynomial Q, used in compressed BLS12 point format (48 bytes).
171
- */ evaluate(challengeZ) {
172
- const z = challengeZ || this.challengeZ;
173
- const res = computeKzgProof(this.data, z.toBuffer());
174
- if (!verifyKzgProof(this.commitment, z.toBuffer(), res[1], res[0])) {
115
+ */ evaluate(challengeZ, verifyProof = false) {
116
+ const kzg = getKzg();
117
+ const res = kzg.computeKzgProof(this.data, challengeZ.toBuffer());
118
+ if (verifyProof && !kzg.verifyKzgProof(this.commitment, challengeZ.toBuffer(), res[1], res[0])) {
175
119
  throw new Error(`KZG proof did not verify.`);
176
120
  }
177
121
  const proof = Buffer.from(res[0]);
178
- const y = Buffer.from(res[1]);
122
+ const y = BLS12Fr.fromBuffer(Buffer.from(res[1]));
179
123
  return {
180
124
  y,
181
125
  proof
@@ -184,75 +128,40 @@ export const VERSIONED_HASH_VERSION_KZG = 0x01;
184
128
  /**
185
129
  * Get the buffer representation of the ENTIRE blob.
186
130
  *
187
- * @dev WARNING: this buffer contains all metadata aswell as the data itself
131
+ * @dev WARNING: this buffer contains all metadata as well as the data itself.
188
132
  *
189
133
  * @returns The buffer representation of the blob.
190
134
  */ toBuffer() {
191
- return Buffer.from(serializeToBuffer(this.data.length, this.data, this.fieldsHash, this.challengeZ, this.commitment.length, this.commitment));
135
+ return Buffer.from(serializeToBuffer(this.data.length, this.data, this.commitment.length, this.commitment));
192
136
  }
193
137
  /**
194
138
  * Create a Blob from a buffer.
195
139
  *
196
- * @dev WARNING: this method contains all metadata aswell as the data itself
140
+ * @dev WARNING: this method contains all metadata as well as the data itself.
197
141
  *
198
142
  * @param buf - The buffer to create the Blob from.
199
143
  * @returns A Blob created from the buffer.
200
144
  */ static fromBuffer(buf) {
201
145
  const reader = BufferReader.asReader(buf);
202
- return new Blob(reader.readUint8Array(), reader.readObject(Fr), reader.readObject(Fr), reader.readBuffer());
146
+ return new Blob(reader.readUint8Array(), reader.readBuffer());
203
147
  }
204
148
  /**
205
149
  * Get the size of the blob in bytes
206
150
  */ getSize() {
207
151
  return this.data.length;
208
152
  }
209
- /**
210
- * @param blobs - The blobs to emit
211
- * @returns The blobs' compressed commitments in hex prefixed by the number of blobs
212
- * @dev Used for proposing blocks to validate injected blob commitments match real broadcast blobs:
213
- * One byte for the number blobs + 48 bytes per blob commitment
214
- */ static getPrefixedEthBlobCommitments(blobs) {
215
- let buf = Buffer.alloc(0);
216
- blobs.forEach((blob)=>{
217
- buf = Buffer.concat([
218
- buf,
219
- blob.commitment
220
- ]);
221
- });
222
- // We prefix the number of blobs:
223
- const lenBuf = Buffer.alloc(1);
224
- lenBuf.writeUint8(blobs.length);
225
- buf = Buffer.concat([
226
- lenBuf,
227
- buf
228
- ]);
229
- return `0x${buf.toString('hex')}`;
230
- }
231
153
  static getViemKzgInstance() {
154
+ const kzg = getKzg();
232
155
  return {
233
- blobToKzgCommitment: cKzg.blobToKzgCommitment,
234
- computeBlobKzgProof: cKzg.computeBlobKzgProof
156
+ blobToKzgCommitment: kzg.blobToKzgCommitment.bind(kzg),
157
+ computeBlobKzgProof: kzg.computeBlobKzgProof.bind(kzg),
158
+ computeCellsAndKzgProofs: (b)=>{
159
+ const result = kzg.computeCellsAndKzgProofs(b);
160
+ return [
161
+ result.cells,
162
+ result.proofs
163
+ ];
164
+ }
235
165
  };
236
166
  }
237
- /**
238
- * @param fields - Fields to broadcast in the blob(s)
239
- * @returns As many blobs as we require to broadcast the given fields for a block
240
- * @dev Assumes we share the fields hash between all blobs which can only be done for ONE BLOCK because the hash is calculated in block root.
241
- */ static async getBlobsPerBlock(fields) {
242
- const numBlobs = Math.max(Math.ceil(fields.length / FIELD_ELEMENTS_PER_BLOB), 1);
243
- const multiBlobFieldsHash = await poseidon2Hash(fields);
244
- const res = [];
245
- for(let i = 0; i < numBlobs; i++){
246
- const end = fields.length < (i + 1) * FIELD_ELEMENTS_PER_BLOB ? fields.length : (i + 1) * FIELD_ELEMENTS_PER_BLOB;
247
- res.push(await Blob.fromFields(fields.slice(i * FIELD_ELEMENTS_PER_BLOB, end), multiBlobFieldsHash));
248
- }
249
- return res;
250
- }
251
- }
252
- // 48 bytes encoded in fields as [Fr, Fr] = [0->31, 31->48]
253
- function commitmentToFields(commitment) {
254
- return [
255
- new Fr(commitment.subarray(0, 31)),
256
- new Fr(commitment.subarray(31, 48))
257
- ];
258
167
  }