@aztec/blob-lib 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/batched_blob.d.ts +6 -1
- package/dest/batched_blob.d.ts.map +1 -1
- package/dest/blob.d.ts +13 -7
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +15 -15
- package/dest/blob_batching.d.ts +14 -2
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +24 -24
- package/dest/blob_utils.d.ts +2 -2
- package/dest/blob_utils.d.ts.map +1 -1
- package/dest/blob_utils.js +3 -3
- package/dest/circuit_types/final_blob_accumulator.js +3 -1
- package/dest/encoding/block_blob_data.d.ts +9 -1
- package/dest/encoding/block_blob_data.d.ts.map +1 -1
- package/dest/encoding/block_blob_data.js +11 -1
- package/dest/encoding/block_end_marker.js +3 -3
- package/dest/encoding/checkpoint_blob_data.d.ts +1 -1
- package/dest/encoding/checkpoint_blob_data.d.ts.map +1 -1
- package/dest/encoding/checkpoint_blob_data.js +5 -5
- package/dest/encoding/checkpoint_end_marker.js +3 -3
- package/dest/encoding/tx_start_marker.js +2 -2
- package/dest/hash.d.ts +6 -5
- package/dest/hash.d.ts.map +1 -1
- package/dest/hash.js +17 -15
- package/dest/kzg_context.d.ts +5 -3
- package/dest/kzg_context.d.ts.map +1 -1
- package/dest/kzg_context.js +18 -3
- package/dest/sponge_blob.d.ts +3 -1
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/testing.d.ts +2 -2
- package/dest/testing.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/blob.ts +15 -15
- package/src/blob_batching.ts +21 -18
- package/src/blob_utils.ts +5 -3
- package/src/encoding/block_blob_data.ts +13 -1
- package/src/encoding/block_end_marker.ts +3 -3
- package/src/encoding/checkpoint_blob_data.ts +12 -5
- package/src/encoding/checkpoint_end_marker.ts +3 -3
- package/src/encoding/tx_start_marker.ts +2 -2
- package/src/hash.ts +19 -14
- package/src/kzg_context.ts +28 -3
- package/src/testing.ts +1 -1
package/src/hash.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DomainSeparator } from '@aztec/constants';
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
2
3
|
import { sha256, sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
3
4
|
import { BLS12Fr } from '@aztec/foundation/curves/bls12';
|
|
4
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
6
|
|
|
6
|
-
import {
|
|
7
|
+
import { getBytesPerBlob, getBytesPerCommitment, getKzg } from './kzg_context.js';
|
|
7
8
|
import { SpongeBlob } from './sponge_blob.js';
|
|
8
9
|
|
|
9
10
|
const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
@@ -44,12 +45,12 @@ export async function computeBlobFieldsHash(fields: Fr[]): Promise<Fr> {
|
|
|
44
45
|
return sponge.squeeze();
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
export function computeBlobCommitment(data: Uint8Array): Buffer {
|
|
48
|
-
if (data.length !==
|
|
49
|
-
throw new Error(`Expected ${
|
|
48
|
+
export async function computeBlobCommitment(data: Uint8Array): Promise<Buffer> {
|
|
49
|
+
if (data.length !== getBytesPerBlob()) {
|
|
50
|
+
throw new Error(`Expected ${getBytesPerBlob()} bytes per blob. Got ${data.length}.`);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
return Buffer.from(getKzg().
|
|
53
|
+
return Buffer.from(await getKzg().asyncBlobToKzgCommitment(data));
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/**
|
|
@@ -67,23 +68,27 @@ export function computeBlobCommitment(data: Uint8Array): Buffer {
|
|
|
67
68
|
* @returns The fields representing the commitment buffer.
|
|
68
69
|
*/
|
|
69
70
|
export function commitmentToFields(commitment: Buffer): [Fr, Fr] {
|
|
70
|
-
if (commitment.length !==
|
|
71
|
-
throw new Error(`Expected ${
|
|
71
|
+
if (commitment.length !== getBytesPerCommitment()) {
|
|
72
|
+
throw new Error(`Expected ${getBytesPerCommitment()} bytes for blob commitment. Got ${commitment.length}.`);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
return [new Fr(commitment.subarray(0, 31)), new Fr(commitment.subarray(31,
|
|
75
|
+
return [new Fr(commitment.subarray(0, 31)), new Fr(commitment.subarray(31, getBytesPerCommitment()))];
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
export async function computeChallengeZ(blobFieldsHash: Fr, commitment: Buffer): Promise<Fr> {
|
|
78
79
|
const commitmentFields = commitmentToFields(commitment);
|
|
79
|
-
return await
|
|
80
|
+
return await poseidon2HashWithSeparator(
|
|
81
|
+
[blobFieldsHash, commitmentFields[0], commitmentFields[1]],
|
|
82
|
+
DomainSeparator.BLOB_CHALLENGE_Z,
|
|
83
|
+
);
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
/**
|
|
83
|
-
* Hash
|
|
84
|
-
*
|
|
87
|
+
* Hash the u128 limbs of a BLS field's noir bignum representation under the `BLOB_HASHED_Y_LIMBS` separator.
|
|
88
|
+
* Used to commit to blob evaluation values `y_i` before folding them into the gamma accumulator; mirrors the
|
|
89
|
+
* hash accumulation performed in the rollup circuits.
|
|
85
90
|
*/
|
|
86
|
-
export async function
|
|
91
|
+
export async function hashBlobYLimbs(field: BLS12Fr): Promise<Fr> {
|
|
87
92
|
const num = field.toNoirBigNum();
|
|
88
|
-
return await
|
|
93
|
+
return await poseidon2HashWithSeparator(num.limbs.map(Fr.fromHexString), DomainSeparator.BLOB_HASHED_Y_LIMBS);
|
|
89
94
|
}
|
package/src/kzg_context.ts
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
import { DasContextJs } from '@crate-crypto/node-eth-kzg';
|
|
1
|
+
import type { DasContextJs } from '@crate-crypto/node-eth-kzg';
|
|
2
|
+
import { createRequire } from 'module';
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
+
// Re-export the type only. The native module is loaded lazily to avoid
|
|
5
|
+
// creating a napi-rs CustomGC handle at import time, which keeps the
|
|
6
|
+
// Node.js event loop alive and can deadlock process.exit().
|
|
7
|
+
export type { DasContextJs } from '@crate-crypto/node-eth-kzg';
|
|
8
|
+
|
|
9
|
+
let nativeModule: typeof import('@crate-crypto/node-eth-kzg') | undefined;
|
|
10
|
+
|
|
11
|
+
/** Lazily loads the @crate-crypto/node-eth-kzg native module. */
|
|
12
|
+
function loadNativeModule(): typeof import('@crate-crypto/node-eth-kzg') {
|
|
13
|
+
if (!nativeModule) {
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
nativeModule = require('@crate-crypto/node-eth-kzg') as typeof import('@crate-crypto/node-eth-kzg');
|
|
16
|
+
}
|
|
17
|
+
return nativeModule!;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Ethereum blob constants, loaded lazily from the native module.
|
|
21
|
+
// Values: BYTES_PER_BLOB=131072, BYTES_PER_COMMITMENT=48
|
|
22
|
+
export function getBytesPerBlob(): number {
|
|
23
|
+
return loadNativeModule().BYTES_PER_BLOB;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getBytesPerCommitment(): number {
|
|
27
|
+
return loadNativeModule().BYTES_PER_COMMITMENT;
|
|
28
|
+
}
|
|
4
29
|
|
|
5
30
|
let kzgInstance: DasContextJs | undefined;
|
|
6
31
|
|
|
@@ -10,7 +35,7 @@ let kzgInstance: DasContextJs | undefined;
|
|
|
10
35
|
*/
|
|
11
36
|
export function getKzg(): DasContextJs {
|
|
12
37
|
if (!kzgInstance) {
|
|
13
|
-
kzgInstance = DasContextJs.create({ usePrecomp: true });
|
|
38
|
+
kzgInstance = loadNativeModule().DasContextJs.create({ usePrecomp: true });
|
|
14
39
|
}
|
|
15
40
|
return kzgInstance;
|
|
16
41
|
}
|
package/src/testing.ts
CHANGED
|
@@ -89,6 +89,6 @@ export function makeFinalBlobBatchingChallenges(seed = 1) {
|
|
|
89
89
|
* @param length
|
|
90
90
|
* @returns
|
|
91
91
|
*/
|
|
92
|
-
export function makeRandomBlob(length: number): Blob {
|
|
92
|
+
export function makeRandomBlob(length: number): Promise<Blob> {
|
|
93
93
|
return Blob.fromFields([...Array.from({ length: length }, () => Fr.random())]);
|
|
94
94
|
}
|