@aztec/blob-lib 0.0.1-fake-c83136db25 → 0.0.1-fake-ceab37513c
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/blob.d.ts +98 -52
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +167 -73
- package/dest/blob_batching.d.ts +48 -15
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +120 -81
- package/dest/blob_batching_public_inputs.d.ts +71 -0
- package/dest/blob_batching_public_inputs.d.ts.map +1 -0
- package/dest/blob_batching_public_inputs.js +168 -0
- package/dest/encoding.d.ts +62 -22
- package/dest/encoding.d.ts.map +1 -1
- package/dest/encoding.js +104 -114
- package/dest/index.d.ts +2 -5
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +15 -5
- package/dest/sponge_blob.d.ts +9 -13
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +17 -28
- package/dest/testing.d.ts +12 -7
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +41 -54
- package/dest/types.d.ts +0 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +0 -2
- package/package.json +4 -5
- package/src/blob.ts +198 -76
- package/src/blob_batching.ts +137 -109
- package/src/blob_batching_public_inputs.ts +252 -0
- package/src/encoding.ts +120 -136
- package/src/index.ts +18 -5
- package/src/sponge_blob.ts +14 -24
- package/src/testing.ts +40 -55
- package/src/types.ts +2 -2
- package/dest/blob_utils.d.ts +0 -30
- package/dest/blob_utils.d.ts.map +0 -1
- package/dest/blob_utils.js +0 -60
- package/dest/circuit_types/blob_accumulator.d.ts +0 -21
- package/dest/circuit_types/blob_accumulator.d.ts.map +0 -1
- package/dest/circuit_types/blob_accumulator.js +0 -58
- package/dest/circuit_types/final_blob_accumulator.d.ts +0 -22
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +0 -1
- package/dest/circuit_types/final_blob_accumulator.js +0 -63
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +0 -15
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +0 -1
- package/dest/circuit_types/final_blob_batching_challenges.js +0 -25
- package/dest/circuit_types/index.d.ts +0 -4
- package/dest/circuit_types/index.d.ts.map +0 -1
- package/dest/circuit_types/index.js +0 -4
- package/dest/deserialize.d.ts +0 -14
- package/dest/deserialize.d.ts.map +0 -1
- package/dest/deserialize.js +0 -33
- package/dest/hash.d.ts +0 -35
- package/dest/hash.d.ts.map +0 -1
- package/dest/hash.js +0 -69
- package/dest/kzg_context.d.ts +0 -4
- package/dest/kzg_context.d.ts.map +0 -1
- package/dest/kzg_context.js +0 -5
- package/src/blob_utils.ts +0 -71
- package/src/circuit_types/blob_accumulator.ts +0 -84
- package/src/circuit_types/final_blob_accumulator.ts +0 -75
- package/src/circuit_types/final_blob_batching_challenges.ts +0 -29
- package/src/circuit_types/index.ts +0 -4
- package/src/deserialize.ts +0 -38
- package/src/hash.ts +0 -77
- package/src/kzg_context.ts +0 -5
package/src/deserialize.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
-
|
|
4
|
-
import { checkBlobFieldsEncoding } from './encoding.js';
|
|
5
|
-
import { BlobDeserializationError } from './errors.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Deserializes a buffer into an array of field elements.
|
|
9
|
-
*
|
|
10
|
-
* This function returns the fields that were actually added in a checkpoint. The number of fields is specified by the
|
|
11
|
-
* first field.
|
|
12
|
-
*
|
|
13
|
-
* @param buf - The buffer to deserialize.
|
|
14
|
-
* @param checkEncoding - Whether to check if the encoding is correct. If false, it will still check the checkpoint
|
|
15
|
-
* prefix and throw if there's not enough fields.
|
|
16
|
-
* @returns An array of field elements.
|
|
17
|
-
*/
|
|
18
|
-
export function deserializeEncodedBlobToFields(buf: Uint8Array, checkEncoding = false): Fr[] {
|
|
19
|
-
const reader = BufferReader.asReader(buf);
|
|
20
|
-
const firstField = reader.readObject(Fr);
|
|
21
|
-
|
|
22
|
-
// Use toBigInt instead of toNumber so that we can catch it and throw a more descriptive error below if the first
|
|
23
|
-
// field is larger than a javascript integer.
|
|
24
|
-
const numFields = firstField.toBigInt();
|
|
25
|
-
const totalFieldsInBuffer = BigInt(buf.length / Fr.SIZE_IN_BYTES);
|
|
26
|
-
if (numFields > totalFieldsInBuffer) {
|
|
27
|
-
throw new BlobDeserializationError(`Failed to deserialize blob fields, this blob was likely not created by us`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const numFieldsWithoutPrefix = Number(numFields) - 1;
|
|
31
|
-
const blobFields = [firstField].concat(reader.readArray(numFieldsWithoutPrefix, Fr));
|
|
32
|
-
|
|
33
|
-
if (checkEncoding && !checkBlobFieldsEncoding(blobFields)) {
|
|
34
|
-
throw new BlobDeserializationError(`Incorrect encoding of blob fields, this blob was likely not created by us`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return blobFields;
|
|
38
|
-
}
|
package/src/hash.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { poseidon2Hash, sha256, sha256ToField } from '@aztec/foundation/crypto';
|
|
2
|
-
import { BLS12Fr, Fr } from '@aztec/foundation/fields';
|
|
3
|
-
|
|
4
|
-
import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, kzg } from './kzg_context.js';
|
|
5
|
-
|
|
6
|
-
const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
|
|
10
|
-
*/
|
|
11
|
-
export function computeEthVersionedBlobHash(commitment: Buffer): Buffer {
|
|
12
|
-
const hash = sha256(commitment);
|
|
13
|
-
hash[0] = VERSIONED_HASH_VERSION_KZG;
|
|
14
|
-
return hash;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// TODO(#13430): The blobsHash is confusingly similar to blobCommitmentsHash, calculated from below blobCommitments:
|
|
18
|
-
// - blobsHash := sha256([blobhash_0, ..., blobhash_m]) = a hash of all blob hashes in a block with m+1 blobs inserted into the header, exists so a user can cross check blobs.
|
|
19
|
-
// - blobCommitmentsHash := sha256( ...sha256(sha256(C_0), C_1) ... C_n) = iteratively calculated hash of all blob commitments in an epoch with n+1 blobs (see calculateBlobCommitmentsHash()),
|
|
20
|
-
// exists so we can validate injected commitments to the rollup circuits correspond to the correct real blobs.
|
|
21
|
-
// We may be able to combine these values e.g. blobCommitmentsHash := sha256( ...sha256(sha256(blobshash_0), blobshash_1) ... blobshash_l) for an epoch with l+1 blocks.
|
|
22
|
-
export function computeBlobsHash(evmVersionedBlobHashes: Buffer[]): Fr {
|
|
23
|
-
return sha256ToField(evmVersionedBlobHashes);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The hash of the fields added throughout the checkpoint. The exact number of fields is specified by the checkpoint
|
|
28
|
-
* prefix (the first field). It's verified in the circuit against the fields absorbed into the sponge blob.
|
|
29
|
-
* This hash is used in generating the challenge z for all blobs in the same checkpoint.
|
|
30
|
-
*/
|
|
31
|
-
export async function computeBlobFieldsHash(fields: Fr[]): Promise<Fr> {
|
|
32
|
-
return await poseidon2Hash(fields);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function computeBlobCommitment(data: Uint8Array): Buffer {
|
|
36
|
-
if (data.length !== BYTES_PER_BLOB) {
|
|
37
|
-
throw new Error(`Expected ${BYTES_PER_BLOB} bytes per blob. Got ${data.length}.`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return Buffer.from(kzg.blobToKzgCommitment(data));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Get the commitment fields of the blob, to compute the challenge z.
|
|
45
|
-
*
|
|
46
|
-
* The 48-byte commitment is encoded into two field elements:
|
|
47
|
-
* +-------------------+------------------------+
|
|
48
|
-
* | 31 bytes | 17 bytes |
|
|
49
|
-
* +-------------------+------------------------+
|
|
50
|
-
* | Field Element 1 | Field Element 2 |
|
|
51
|
-
* | [0][bytes 0-30] | [0...0][bytes 31-47] |
|
|
52
|
-
* +-------------------+------------------------+
|
|
53
|
-
*
|
|
54
|
-
* @param commitment - The commitment to convert to fields. Computed from `computeBlobCommitment`.
|
|
55
|
-
* @returns The fields representing the commitment buffer.
|
|
56
|
-
*/
|
|
57
|
-
export function commitmentToFields(commitment: Buffer): [Fr, Fr] {
|
|
58
|
-
if (commitment.length !== BYTES_PER_COMMITMENT) {
|
|
59
|
-
throw new Error(`Expected ${BYTES_PER_COMMITMENT} bytes for blob commitment. Got ${commitment.length}.`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return [new Fr(commitment.subarray(0, 31)), new Fr(commitment.subarray(31, BYTES_PER_COMMITMENT))];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function computeChallengeZ(blobFieldsHash: Fr, commitment: Buffer): Promise<Fr> {
|
|
66
|
-
const commitmentFields = commitmentToFields(commitment);
|
|
67
|
-
return await poseidon2Hash([blobFieldsHash, commitmentFields[0], commitmentFields[1]]);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Hash each u128 limb of the noir bignum struct representing the BLS field, to mimic the hash accumulation in the
|
|
72
|
-
* rollup circuits.
|
|
73
|
-
*/
|
|
74
|
-
export async function hashNoirBigNumLimbs(field: BLS12Fr): Promise<Fr> {
|
|
75
|
-
const num = field.toNoirBigNum();
|
|
76
|
-
return await poseidon2Hash(num.limbs.map(Fr.fromHexString));
|
|
77
|
-
}
|