@aztec/blob-lib 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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 +8 -2
- package/dest/batched_blob.d.ts.map +1 -1
- package/dest/blob.d.ts +17 -11
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +21 -20
- package/dest/blob_batching.d.ts +16 -3
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +29 -27
- package/dest/blob_utils.d.ts +4 -3
- package/dest/blob_utils.d.ts.map +1 -1
- package/dest/blob_utils.js +4 -4
- package/dest/circuit_types/blob_accumulator.d.ts +3 -2
- package/dest/circuit_types/blob_accumulator.d.ts.map +1 -1
- package/dest/circuit_types/blob_accumulator.js +2 -1
- package/dest/circuit_types/final_blob_accumulator.d.ts +3 -2
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -1
- package/dest/circuit_types/final_blob_accumulator.js +5 -2
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +3 -2
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -1
- package/dest/circuit_types/final_blob_batching_challenges.js +2 -1
- package/dest/encoding/block_blob_data.d.ts +10 -2
- 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.d.ts +4 -3
- package/dest/encoding/block_end_marker.d.ts.map +1 -1
- package/dest/encoding/block_end_marker.js +6 -5
- package/dest/encoding/block_end_state_field.d.ts +2 -2
- package/dest/encoding/block_end_state_field.d.ts.map +1 -1
- package/dest/encoding/block_end_state_field.js +1 -1
- package/dest/encoding/checkpoint_blob_data.d.ts +2 -2
- package/dest/encoding/checkpoint_blob_data.d.ts.map +1 -1
- package/dest/encoding/checkpoint_blob_data.js +6 -6
- package/dest/encoding/checkpoint_end_marker.d.ts +2 -2
- package/dest/encoding/checkpoint_end_marker.d.ts.map +1 -1
- package/dest/encoding/checkpoint_end_marker.js +4 -4
- package/dest/encoding/fixtures.d.ts +1 -1
- package/dest/encoding/fixtures.d.ts.map +1 -1
- package/dest/encoding/fixtures.js +3 -2
- package/dest/encoding/tx_blob_data.d.ts +2 -2
- package/dest/encoding/tx_blob_data.d.ts.map +1 -1
- package/dest/encoding/tx_blob_data.js +1 -1
- package/dest/encoding/tx_start_marker.d.ts +2 -2
- package/dest/encoding/tx_start_marker.d.ts.map +1 -1
- package/dest/encoding/tx_start_marker.js +3 -3
- package/dest/hash.d.ts +8 -6
- package/dest/hash.d.ts.map +1 -1
- package/dest/hash.js +19 -16
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/interface.d.ts +1 -2
- package/dest/interface.d.ts.map +1 -1
- package/dest/kzg_context.d.ts +10 -4
- package/dest/kzg_context.d.ts.map +1 -1
- package/dest/kzg_context.js +29 -5
- package/dest/sponge_blob.d.ts +4 -2
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +2 -2
- package/dest/testing.d.ts +2 -2
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +2 -1
- package/package.json +7 -7
- package/src/batched_blob.ts +2 -1
- package/src/blob.ts +21 -20
- package/src/blob_batching.ts +31 -21
- package/src/blob_utils.ts +7 -4
- package/src/circuit_types/blob_accumulator.ts +2 -1
- package/src/circuit_types/final_blob_accumulator.ts +2 -1
- package/src/circuit_types/final_blob_batching_challenges.ts +2 -1
- package/src/encoding/block_blob_data.ts +14 -2
- package/src/encoding/block_end_marker.ts +7 -6
- package/src/encoding/block_end_state_field.ts +1 -1
- package/src/encoding/checkpoint_blob_data.ts +13 -6
- package/src/encoding/checkpoint_end_marker.ts +4 -4
- package/src/encoding/fixtures.ts +3 -2
- package/src/encoding/tx_blob_data.ts +1 -1
- package/src/encoding/tx_start_marker.ts +3 -3
- package/src/hash.ts +22 -15
- package/src/index.ts +1 -0
- package/src/interface.ts +0 -1
- package/src/kzg_context.ts +39 -3
- package/src/sponge_blob.ts +2 -2
- package/src/testing.ts +3 -2
package/src/encoding/fixtures.ts
CHANGED
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
PRIVATE_LOG_SIZE_IN_FIELDS,
|
|
10
10
|
} from '@aztec/constants';
|
|
11
11
|
import { makeTuple } from '@aztec/foundation/array';
|
|
12
|
-
import {
|
|
12
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
13
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
14
|
|
|
14
15
|
import type { BlockBlobData, BlockEndBlobData } from './block_blob_data.js';
|
|
15
16
|
import type { BlockEndMarker } from './block_end_marker.js';
|
|
@@ -109,7 +110,7 @@ export function makeBlockEndMarker({
|
|
|
109
110
|
}: { seed?: number } & Partial<BlockEndMarker> = {}): BlockEndMarker {
|
|
110
111
|
return {
|
|
111
112
|
numTxs: seed,
|
|
112
|
-
blockNumber: seed + 1,
|
|
113
|
+
blockNumber: BlockNumber(seed + 1),
|
|
113
114
|
timestamp: BigInt(seed + 2),
|
|
114
115
|
...overrides,
|
|
115
116
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { chunk } from '@aztec/foundation/collection';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { FieldReader } from '@aztec/foundation/serialize';
|
|
4
4
|
|
|
5
5
|
import { BlobDeserializationError } from '../errors.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TX_START_PREFIX } from '@aztec/constants';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
|
|
4
4
|
import { BlobDeserializationError } from '../errors.js';
|
|
5
5
|
|
|
@@ -30,7 +30,7 @@ export interface TxStartMarker {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function encodeTxStartMarker(txStartMarker: TxStartMarker): Fr {
|
|
33
|
-
let value = TX_START_PREFIX;
|
|
33
|
+
let value = BigInt(TX_START_PREFIX);
|
|
34
34
|
value <<= NUM_NOTE_HASH_BIT_SIZE;
|
|
35
35
|
value += BigInt(txStartMarker.numNoteHashes);
|
|
36
36
|
value <<= NUM_NULLIFIER_BIT_SIZE;
|
|
@@ -78,7 +78,7 @@ export function decodeTxStartMarker(field: Fr): TxStartMarker {
|
|
|
78
78
|
value >>= NUM_NOTE_HASH_BIT_SIZE;
|
|
79
79
|
|
|
80
80
|
const prefix = value;
|
|
81
|
-
if (prefix !== TX_START_PREFIX) {
|
|
81
|
+
if (prefix !== BigInt(TX_START_PREFIX)) {
|
|
82
82
|
throw new BlobDeserializationError(`Incorrect encoding of blob fields: invalid tx start marker.`);
|
|
83
83
|
}
|
|
84
84
|
|
package/src/hash.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DomainSeparator } from '@aztec/constants';
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
3
|
+
import { sha256, sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
4
|
+
import { BLS12Fr } from '@aztec/foundation/curves/bls12';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
6
|
|
|
4
|
-
import {
|
|
7
|
+
import { getBytesPerBlob, getBytesPerCommitment, getKzg } from './kzg_context.js';
|
|
5
8
|
import { SpongeBlob } from './sponge_blob.js';
|
|
6
9
|
|
|
7
10
|
const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
@@ -42,12 +45,12 @@ export async function computeBlobFieldsHash(fields: Fr[]): Promise<Fr> {
|
|
|
42
45
|
return sponge.squeeze();
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
export function computeBlobCommitment(data: Uint8Array): Buffer {
|
|
46
|
-
if (data.length !==
|
|
47
|
-
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}.`);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
return Buffer.from(
|
|
53
|
+
return Buffer.from(await getKzg().asyncBlobToKzgCommitment(data));
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -65,23 +68,27 @@ export function computeBlobCommitment(data: Uint8Array): Buffer {
|
|
|
65
68
|
* @returns The fields representing the commitment buffer.
|
|
66
69
|
*/
|
|
67
70
|
export function commitmentToFields(commitment: Buffer): [Fr, Fr] {
|
|
68
|
-
if (commitment.length !==
|
|
69
|
-
throw new Error(`Expected ${
|
|
71
|
+
if (commitment.length !== getBytesPerCommitment()) {
|
|
72
|
+
throw new Error(`Expected ${getBytesPerCommitment()} bytes for blob commitment. Got ${commitment.length}.`);
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
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()))];
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
export async function computeChallengeZ(blobFieldsHash: Fr, commitment: Buffer): Promise<Fr> {
|
|
76
79
|
const commitmentFields = commitmentToFields(commitment);
|
|
77
|
-
return await
|
|
80
|
+
return await poseidon2HashWithSeparator(
|
|
81
|
+
[blobFieldsHash, commitmentFields[0], commitmentFields[1]],
|
|
82
|
+
DomainSeparator.BLOB_CHALLENGE_Z,
|
|
83
|
+
);
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
/**
|
|
81
|
-
* Hash
|
|
82
|
-
*
|
|
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.
|
|
83
90
|
*/
|
|
84
|
-
export async function
|
|
91
|
+
export async function hashBlobYLimbs(field: BLS12Fr): Promise<Fr> {
|
|
85
92
|
const num = field.toNoirBigNum();
|
|
86
|
-
return await
|
|
93
|
+
return await poseidon2HashWithSeparator(num.limbs.map(Fr.fromHexString), DomainSeparator.BLOB_HASHED_Y_LIMBS);
|
|
87
94
|
}
|
package/src/index.ts
CHANGED
package/src/interface.ts
CHANGED
package/src/kzg_context.ts
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
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';
|
|
4
8
|
|
|
5
|
-
|
|
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
|
+
}
|
|
29
|
+
|
|
30
|
+
let kzgInstance: DasContextJs | undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns the lazily-initialized KZG context.
|
|
34
|
+
* The first call takes ~3 seconds to initialize the precomputation tables.
|
|
35
|
+
*/
|
|
36
|
+
export function getKzg(): DasContextJs {
|
|
37
|
+
if (!kzgInstance) {
|
|
38
|
+
kzgInstance = loadNativeModule().DasContextJs.create({ usePrecomp: true });
|
|
39
|
+
}
|
|
40
|
+
return kzgInstance;
|
|
41
|
+
}
|
package/src/sponge_blob.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, TWO_POW_64 } from '@aztec/constants';
|
|
2
2
|
import { type FieldsOf, makeTuple } from '@aztec/foundation/array';
|
|
3
|
-
import { poseidon2Permutation } from '@aztec/foundation/crypto';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import { poseidon2Permutation } from '@aztec/foundation/crypto/poseidon';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import {
|
|
6
6
|
BufferReader,
|
|
7
7
|
FieldReader,
|
package/src/testing.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { makeTuple } from '@aztec/foundation/array';
|
|
2
|
-
import { BLS12Fq, BLS12Fr, BLS12Point, BLSPointNotOnCurveError
|
|
2
|
+
import { BLS12Fq, BLS12Fr, BLS12Point, BLSPointNotOnCurveError } from '@aztec/foundation/curves/bls12';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
|
|
4
5
|
import { Blob } from './blob.js';
|
|
5
6
|
import { BlobAccumulator } from './circuit_types/blob_accumulator.js';
|
|
@@ -88,6 +89,6 @@ export function makeFinalBlobBatchingChallenges(seed = 1) {
|
|
|
88
89
|
* @param length
|
|
89
90
|
* @returns
|
|
90
91
|
*/
|
|
91
|
-
export function makeRandomBlob(length: number): Blob {
|
|
92
|
+
export function makeRandomBlob(length: number): Promise<Blob> {
|
|
92
93
|
return Blob.fromFields([...Array.from({ length: length }, () => Fr.random())]);
|
|
93
94
|
}
|