@aztec/blob-lib 3.0.0-nightly.20251113 → 3.0.0-nightly.20251115
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_utils.d.ts +5 -8
- package/dest/blob_utils.d.ts.map +1 -1
- package/dest/blob_utils.js +7 -10
- package/dest/encoding/block_blob_data.d.ts +22 -0
- package/dest/encoding/block_blob_data.d.ts.map +1 -0
- package/dest/encoding/block_blob_data.js +65 -0
- package/dest/encoding/block_end_marker.d.ts +10 -0
- package/dest/encoding/block_end_marker.d.ts.map +1 -0
- package/dest/encoding/block_end_marker.js +40 -0
- package/dest/encoding/block_end_state_field.d.ts +12 -0
- package/dest/encoding/block_end_state_field.d.ts.map +1 -0
- package/dest/encoding/block_end_state_field.js +39 -0
- package/dest/encoding/checkpoint_blob_data.d.ts +13 -0
- package/dest/encoding/checkpoint_blob_data.d.ts.map +1 -0
- package/dest/encoding/checkpoint_blob_data.js +54 -0
- package/dest/encoding/fixtures.d.ts +41 -0
- package/dest/encoding/fixtures.d.ts.map +1 -0
- package/dest/encoding/fixtures.js +137 -0
- package/dest/encoding/index.d.ts +8 -0
- package/dest/encoding/index.d.ts.map +1 -0
- package/dest/encoding/index.js +7 -0
- package/dest/encoding/tx_blob_data.d.ts +19 -0
- package/dest/encoding/tx_blob_data.d.ts.map +1 -0
- package/dest/encoding/tx_blob_data.js +79 -0
- package/dest/encoding/tx_start_marker.d.ts +16 -0
- package/dest/encoding/tx_start_marker.d.ts.map +1 -0
- package/dest/{encoding.js → encoding/tx_start_marker.js} +12 -58
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/testing.d.ts +1 -13
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +1 -60
- package/package.json +4 -4
- package/src/blob_utils.ts +7 -10
- package/src/encoding/block_blob_data.ts +102 -0
- package/src/encoding/block_end_marker.ts +54 -0
- package/src/encoding/block_end_state_field.ts +59 -0
- package/src/encoding/checkpoint_blob_data.ts +75 -0
- package/src/encoding/fixtures.ts +209 -0
- package/src/encoding/index.ts +7 -0
- package/src/encoding/tx_blob_data.ts +116 -0
- package/src/{encoding.ts → encoding/tx_start_marker.ts} +18 -75
- package/src/index.ts +1 -2
- package/src/testing.ts +2 -64
- package/dest/deserialize.d.ts +0 -14
- package/dest/deserialize.d.ts.map +0 -1
- package/dest/deserialize.js +0 -33
- package/dest/encoding.d.ts +0 -26
- package/dest/encoding.d.ts.map +0 -1
- package/src/deserialize.ts +0 -38
package/dest/blob_utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { Blob } from './blob.js';
|
|
3
|
+
import { type CheckpointBlobData } from './encoding/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* @param blobs - The blobs to emit.
|
|
5
6
|
* @returns The blobs' compressed commitments in hex prefixed by the number of blobs. 1 byte for the prefix, 48 bytes
|
|
@@ -15,15 +16,11 @@ export declare function getPrefixedEthBlobCommitments(blobs: Blob[]): `0x${strin
|
|
|
15
16
|
*/
|
|
16
17
|
export declare function getBlobsPerL1Block(fields: Fr[]): Blob[];
|
|
17
18
|
/**
|
|
18
|
-
* Get the
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param blobs - The blobs to read fields from. Should be all the blobs in the L1 block proposing the checkpoint.
|
|
22
|
-
* @param checkEncoding - Whether to check if the entire encoded blob fields are valid. If false, it will still check
|
|
23
|
-
* the checkpoint prefix and throw if there's not enough fields.
|
|
24
|
-
* @returns The fields added throughout the checkpoint.
|
|
19
|
+
* Get the encoded data from all blobs in the checkpoint.
|
|
20
|
+
* @param blobs - The blobs to read data from. Should be all the blobs for the L1 block proposing the checkpoint.
|
|
21
|
+
* @returns The encoded data of the checkpoint.
|
|
25
22
|
*/
|
|
26
|
-
export declare function
|
|
23
|
+
export declare function decodeCheckpointBlobDataFromBlobs(blobs: Blob[]): CheckpointBlobData;
|
|
27
24
|
export declare function computeBlobFieldsHashFromBlobs(blobs: Blob[]): Promise<Fr>;
|
|
28
25
|
export declare function computeBlobsHashFromBlobs(blobs: Blob[]): Fr;
|
|
29
26
|
export declare function getBlobCommitmentsFromBlobs(blobs: Blob[]): BLS12Point[];
|
package/dest/blob_utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob_utils.d.ts","sourceRoot":"","sources":["../src/blob_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"blob_utils.d.ts","sourceRoot":"","sources":["../src/blob_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,kBAAkB,EAAsC,MAAM,qBAAqB,CAAC;AAGlG;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,MAAM,EAAE,CAS1E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CASvD;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAGnF;AAED,wBAAsB,8BAA8B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAQ/E;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAE3D;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,CAEvE"}
|
package/dest/blob_utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FIELDS_PER_BLOB } from '@aztec/constants';
|
|
2
2
|
import { BLS12Point } from '@aztec/foundation/fields';
|
|
3
3
|
import { Blob } from './blob.js';
|
|
4
|
-
import {
|
|
4
|
+
import { decodeCheckpointBlobDataFromBuffer } from './encoding/index.js';
|
|
5
5
|
import { computeBlobFieldsHash, computeBlobsHash } from './hash.js';
|
|
6
6
|
/**
|
|
7
7
|
* @param blobs - The blobs to emit.
|
|
@@ -34,15 +34,12 @@ import { computeBlobFieldsHash, computeBlobsHash } from './hash.js';
|
|
|
34
34
|
}, (_, i)=>Blob.fromFields(fields.slice(i * FIELDS_PER_BLOB, (i + 1) * FIELDS_PER_BLOB)));
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Get the
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* @returns The fields added throughout the checkpoint.
|
|
44
|
-
*/ export function getBlobFieldsInCheckpoint(blobs, checkEncoding = false) {
|
|
45
|
-
return deserializeEncodedBlobToFields(Buffer.concat(blobs.map((b)=>b.data)), checkEncoding);
|
|
37
|
+
* Get the encoded data from all blobs in the checkpoint.
|
|
38
|
+
* @param blobs - The blobs to read data from. Should be all the blobs for the L1 block proposing the checkpoint.
|
|
39
|
+
* @returns The encoded data of the checkpoint.
|
|
40
|
+
*/ export function decodeCheckpointBlobDataFromBlobs(blobs) {
|
|
41
|
+
const buf = Buffer.concat(blobs.map((b)=>b.data));
|
|
42
|
+
return decodeCheckpointBlobDataFromBuffer(buf);
|
|
46
43
|
}
|
|
47
44
|
export async function computeBlobFieldsHashFromBlobs(blobs) {
|
|
48
45
|
const fields = blobs.map((b)=>b.toFields()).flat();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { type BlockEndMarker } from './block_end_marker.js';
|
|
4
|
+
import { type BlockEndStateField } from './block_end_state_field.js';
|
|
5
|
+
import { type TxBlobData } from './tx_blob_data.js';
|
|
6
|
+
export interface BlockEndBlobData {
|
|
7
|
+
blockEndMarker: BlockEndMarker;
|
|
8
|
+
blockEndStateField: BlockEndStateField;
|
|
9
|
+
lastArchiveRoot: Fr;
|
|
10
|
+
noteHashRoot: Fr;
|
|
11
|
+
nullifierRoot: Fr;
|
|
12
|
+
publicDataRoot: Fr;
|
|
13
|
+
l1ToL2MessageRoot: Fr | undefined;
|
|
14
|
+
}
|
|
15
|
+
export interface BlockBlobData extends BlockEndBlobData {
|
|
16
|
+
txs: TxBlobData[];
|
|
17
|
+
}
|
|
18
|
+
export declare function encodeBlockEndBlobData(blockEndBlobData: BlockEndBlobData): Fr[];
|
|
19
|
+
export declare function decodeBlockEndBlobData(fields: Fr[] | FieldReader, isFirstBlock: boolean): BlockEndBlobData;
|
|
20
|
+
export declare function encodeBlockBlobData(blockBlobData: BlockBlobData): Fr[];
|
|
21
|
+
export declare function decodeBlockBlobData(fields: Fr[] | FieldReader, isFirstBlock: boolean): BlockBlobData;
|
|
22
|
+
//# sourceMappingURL=block_blob_data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_blob_data.d.ts","sourceRoot":"","sources":["../../src/encoding/block_blob_data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EACL,KAAK,cAAc,EAIpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,KAAK,UAAU,EAAsC,MAAM,mBAAmB,CAAC;AAIxF,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,eAAe,EAAE,EAAE,CAAC;IACpB,YAAY,EAAE,EAAE,CAAC;IACjB,aAAa,EAAE,EAAE,CAAC;IAClB,cAAc,EAAE,EAAE,CAAC;IACnB,iBAAiB,EAAE,EAAE,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,GAAG,EAAE,UAAU,EAAE,CAAC;CACnB;AAED,wBAAgB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,EAAE,EAAE,CAU/E;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,EAAE,YAAY,EAAE,OAAO,GAAG,gBAAgB,CAmB1G;AAED,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,EAAE,EAAE,CAEtE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,EAAE,YAAY,EAAE,OAAO,GAAG,aAAa,CA+BpG"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { FieldReader } from '@aztec/foundation/serialize';
|
|
2
|
+
import { BlobDeserializationError } from '../errors.js';
|
|
3
|
+
import { decodeBlockEndMarker, encodeBlockEndMarker, isBlockEndMarker } from './block_end_marker.js';
|
|
4
|
+
import { decodeBlockEndStateField, encodeBlockEndStateField } from './block_end_state_field.js';
|
|
5
|
+
import { decodeTxBlobData, encodeTxBlobData } from './tx_blob_data.js';
|
|
6
|
+
export function encodeBlockEndBlobData(blockEndBlobData) {
|
|
7
|
+
return [
|
|
8
|
+
encodeBlockEndMarker(blockEndBlobData.blockEndMarker),
|
|
9
|
+
encodeBlockEndStateField(blockEndBlobData.blockEndStateField),
|
|
10
|
+
blockEndBlobData.lastArchiveRoot,
|
|
11
|
+
blockEndBlobData.noteHashRoot,
|
|
12
|
+
blockEndBlobData.nullifierRoot,
|
|
13
|
+
blockEndBlobData.publicDataRoot,
|
|
14
|
+
...blockEndBlobData.l1ToL2MessageRoot ? [
|
|
15
|
+
blockEndBlobData.l1ToL2MessageRoot
|
|
16
|
+
] : []
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
export function decodeBlockEndBlobData(fields, isFirstBlock) {
|
|
20
|
+
const reader = FieldReader.asReader(fields);
|
|
21
|
+
const numBlockEndData = isFirstBlock ? 7 : 6;
|
|
22
|
+
if (numBlockEndData > reader.remainingFields()) {
|
|
23
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: not enough fields for block end data. Expected ${numBlockEndData} fields, only ${reader.remainingFields()} remaining.`);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
blockEndMarker: decodeBlockEndMarker(reader.readField()),
|
|
27
|
+
blockEndStateField: decodeBlockEndStateField(reader.readField()),
|
|
28
|
+
lastArchiveRoot: reader.readField(),
|
|
29
|
+
noteHashRoot: reader.readField(),
|
|
30
|
+
nullifierRoot: reader.readField(),
|
|
31
|
+
publicDataRoot: reader.readField(),
|
|
32
|
+
l1ToL2MessageRoot: isFirstBlock ? reader.readField() : undefined
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function encodeBlockBlobData(blockBlobData) {
|
|
36
|
+
return [
|
|
37
|
+
...blockBlobData.txs.map((tx)=>encodeTxBlobData(tx)).flat(),
|
|
38
|
+
...encodeBlockEndBlobData(blockBlobData)
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
export function decodeBlockBlobData(fields, isFirstBlock) {
|
|
42
|
+
const reader = FieldReader.asReader(fields);
|
|
43
|
+
const txs = [];
|
|
44
|
+
let hasReachedBlockEnd = false;
|
|
45
|
+
while(!hasReachedBlockEnd){
|
|
46
|
+
if (reader.isFinished()) {
|
|
47
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: not enough fields for block end marker.`);
|
|
48
|
+
}
|
|
49
|
+
const currentField = reader.peekField();
|
|
50
|
+
if (isBlockEndMarker(currentField)) {
|
|
51
|
+
hasReachedBlockEnd = true;
|
|
52
|
+
} else {
|
|
53
|
+
txs.push(decodeTxBlobData(reader));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const blockEndBlobData = decodeBlockEndBlobData(reader, isFirstBlock);
|
|
57
|
+
const blockEndMarker = blockEndBlobData.blockEndMarker;
|
|
58
|
+
if (blockEndMarker.numTxs !== txs.length) {
|
|
59
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: expected ${blockEndMarker.numTxs} txs, but got ${txs.length}.`);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
txs,
|
|
63
|
+
...blockEndBlobData
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
export interface BlockEndMarker {
|
|
3
|
+
timestamp: bigint;
|
|
4
|
+
blockNumber: number;
|
|
5
|
+
numTxs: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function encodeBlockEndMarker(blockEndMarker: BlockEndMarker): Fr;
|
|
8
|
+
export declare function decodeBlockEndMarker(field: Fr): BlockEndMarker;
|
|
9
|
+
export declare function isBlockEndMarker(field: Fr): boolean;
|
|
10
|
+
//# sourceMappingURL=block_end_marker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_end_marker.d.ts","sourceRoot":"","sources":["../../src/encoding/block_end_marker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAU9C,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,cAAc,MASlE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,EAAE,GAAG,cAAc,CAmB9D;AAGD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,EAAE,GAAG,OAAO,CAGnD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BLOCK_END_PREFIX } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BlobDeserializationError } from '../errors.js';
|
|
4
|
+
// Must match the implementation in `noir-protocol-circuits/crates/rollup-lib/src/block_merge/components/block_blob_data.nr`.
|
|
5
|
+
const BLOCK_NUMBER_BIT_SIZE = 32n;
|
|
6
|
+
const TIMESTAMP_BIT_SIZE = 64n;
|
|
7
|
+
const NUM_TXS_BIT_SIZE = 16n;
|
|
8
|
+
export function encodeBlockEndMarker(blockEndMarker) {
|
|
9
|
+
let value = BLOCK_END_PREFIX;
|
|
10
|
+
value <<= TIMESTAMP_BIT_SIZE;
|
|
11
|
+
value += blockEndMarker.timestamp;
|
|
12
|
+
value <<= BLOCK_NUMBER_BIT_SIZE;
|
|
13
|
+
value += BigInt(blockEndMarker.blockNumber);
|
|
14
|
+
value <<= NUM_TXS_BIT_SIZE;
|
|
15
|
+
value += BigInt(blockEndMarker.numTxs);
|
|
16
|
+
return new Fr(value);
|
|
17
|
+
}
|
|
18
|
+
export function decodeBlockEndMarker(field) {
|
|
19
|
+
let value = field.toBigInt();
|
|
20
|
+
const numTxs = Number(value & 2n ** NUM_TXS_BIT_SIZE - 1n);
|
|
21
|
+
value >>= NUM_TXS_BIT_SIZE;
|
|
22
|
+
const blockNumber = Number(value & 2n ** BLOCK_NUMBER_BIT_SIZE - 1n);
|
|
23
|
+
value >>= BLOCK_NUMBER_BIT_SIZE;
|
|
24
|
+
const timestamp = value & 2n ** TIMESTAMP_BIT_SIZE - 1n;
|
|
25
|
+
value >>= TIMESTAMP_BIT_SIZE;
|
|
26
|
+
const prefix = value;
|
|
27
|
+
if (prefix !== BLOCK_END_PREFIX) {
|
|
28
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: invalid block end marker.`);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
blockNumber,
|
|
32
|
+
timestamp,
|
|
33
|
+
numTxs
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Check if a field is a block end marker. Used before decoding to check if it has reached the end of the block.
|
|
37
|
+
export function isBlockEndMarker(field) {
|
|
38
|
+
const prefix = field.toBigInt() >> NUM_TXS_BIT_SIZE + BLOCK_NUMBER_BIT_SIZE + TIMESTAMP_BIT_SIZE;
|
|
39
|
+
return prefix === BLOCK_END_PREFIX;
|
|
40
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
export declare const TOTAL_MANA_USED_BIT_SIZE = 48n;
|
|
3
|
+
export interface BlockEndStateField {
|
|
4
|
+
l1ToL2MessageNextAvailableLeafIndex: number;
|
|
5
|
+
noteHashNextAvailableLeafIndex: number;
|
|
6
|
+
nullifierNextAvailableLeafIndex: number;
|
|
7
|
+
publicDataNextAvailableLeafIndex: number;
|
|
8
|
+
totalManaUsed: bigint;
|
|
9
|
+
}
|
|
10
|
+
export declare function encodeBlockEndStateField(blockEndStateField: BlockEndStateField): Fr;
|
|
11
|
+
export declare function decodeBlockEndStateField(field: Fr): BlockEndStateField;
|
|
12
|
+
//# sourceMappingURL=block_end_state_field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_end_state_field.d.ts","sourceRoot":"","sources":["../../src/encoding/block_end_state_field.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAM9C,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC,mCAAmC,EAAE,MAAM,CAAC;IAC5C,8BAA8B,EAAE,MAAM,CAAC;IACvC,+BAA+B,EAAE,MAAM,CAAC;IACxC,gCAAgC,EAAE,MAAM,CAAC;IACzC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,wBAAwB,CAAC,kBAAkB,EAAE,kBAAkB,MAW9E;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,EAAE,GAAG,kBAAkB,CAuBtE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { L1_TO_L2_MSG_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BlobDeserializationError } from '../errors.js';
|
|
4
|
+
// Must match the implementation in `noir-protocol-circuits/crates/rollup-lib/src/block_merge/components/block_blob_data.nr`.
|
|
5
|
+
export const TOTAL_MANA_USED_BIT_SIZE = 48n;
|
|
6
|
+
export function encodeBlockEndStateField(blockEndStateField) {
|
|
7
|
+
let value = BigInt(blockEndStateField.l1ToL2MessageNextAvailableLeafIndex);
|
|
8
|
+
value <<= BigInt(NOTE_HASH_TREE_HEIGHT);
|
|
9
|
+
value += BigInt(blockEndStateField.noteHashNextAvailableLeafIndex);
|
|
10
|
+
value <<= BigInt(NULLIFIER_TREE_HEIGHT);
|
|
11
|
+
value += BigInt(blockEndStateField.nullifierNextAvailableLeafIndex);
|
|
12
|
+
value <<= BigInt(PUBLIC_DATA_TREE_HEIGHT);
|
|
13
|
+
value += BigInt(blockEndStateField.publicDataNextAvailableLeafIndex);
|
|
14
|
+
value <<= BigInt(TOTAL_MANA_USED_BIT_SIZE);
|
|
15
|
+
value += BigInt(blockEndStateField.totalManaUsed);
|
|
16
|
+
return new Fr(value);
|
|
17
|
+
}
|
|
18
|
+
export function decodeBlockEndStateField(field) {
|
|
19
|
+
let value = field.toBigInt();
|
|
20
|
+
const totalManaUsed = value & 2n ** TOTAL_MANA_USED_BIT_SIZE - 1n;
|
|
21
|
+
value >>= TOTAL_MANA_USED_BIT_SIZE;
|
|
22
|
+
const publicDataNextAvailableLeafIndex = Number(value & 2n ** BigInt(PUBLIC_DATA_TREE_HEIGHT) - 1n);
|
|
23
|
+
value >>= BigInt(PUBLIC_DATA_TREE_HEIGHT);
|
|
24
|
+
const nullifierNextAvailableLeafIndex = Number(value & 2n ** BigInt(NULLIFIER_TREE_HEIGHT) - 1n);
|
|
25
|
+
value >>= BigInt(NULLIFIER_TREE_HEIGHT);
|
|
26
|
+
const noteHashNextAvailableLeafIndex = Number(value & 2n ** BigInt(NOTE_HASH_TREE_HEIGHT) - 1n);
|
|
27
|
+
value >>= BigInt(NOTE_HASH_TREE_HEIGHT);
|
|
28
|
+
if (value > 2n ** BigInt(L1_TO_L2_MSG_TREE_HEIGHT) - 1n) {
|
|
29
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: invalid block end state field.`);
|
|
30
|
+
}
|
|
31
|
+
const l1ToL2MessageNextAvailableLeafIndex = Number(value);
|
|
32
|
+
return {
|
|
33
|
+
l1ToL2MessageNextAvailableLeafIndex,
|
|
34
|
+
noteHashNextAvailableLeafIndex,
|
|
35
|
+
nullifierNextAvailableLeafIndex,
|
|
36
|
+
publicDataNextAvailableLeafIndex,
|
|
37
|
+
totalManaUsed
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { type BlockBlobData } from './block_blob_data.js';
|
|
4
|
+
import type { TxStartMarker } from './tx_start_marker.js';
|
|
5
|
+
export interface CheckpointBlobData {
|
|
6
|
+
totalNumBlobFields: number;
|
|
7
|
+
blocks: BlockBlobData[];
|
|
8
|
+
}
|
|
9
|
+
export declare function encodeCheckpointBlobData(checkpointBlobData: CheckpointBlobData): Fr[];
|
|
10
|
+
export declare function decodeCheckpointBlobData(fields: Fr[] | FieldReader): CheckpointBlobData;
|
|
11
|
+
export declare function decodeCheckpointBlobDataFromBuffer(buf: Buffer): CheckpointBlobData;
|
|
12
|
+
export declare function getTotalNumBlobFieldsFromTxs(txs: TxStartMarker[][]): number;
|
|
13
|
+
//# sourceMappingURL=checkpoint_blob_data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint_blob_data.d.ts","sourceRoot":"","sources":["../../src/encoding/checkpoint_blob_data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAgB,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EAAE,KAAK,aAAa,EAA4C,MAAM,sBAAsB,CAAC;AACpG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,WAAW,kBAAkB;IACjC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;AAED,wBAAgB,wBAAwB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,EAAE,EAAE,CAKrF;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,kBAAkB,CA0BvF;AAED,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAkBlF;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,aAAa,EAAE,EAAE,GAAG,MAAM,CAO3E"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { BlobDeserializationError } from '../errors.js';
|
|
4
|
+
import { decodeBlockBlobData, encodeBlockBlobData } from './block_blob_data.js';
|
|
5
|
+
export function encodeCheckpointBlobData(checkpointBlobData) {
|
|
6
|
+
return [
|
|
7
|
+
new Fr(checkpointBlobData.totalNumBlobFields),
|
|
8
|
+
...checkpointBlobData.blocks.map((block)=>encodeBlockBlobData(block)).flat()
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
export function decodeCheckpointBlobData(fields) {
|
|
12
|
+
const reader = FieldReader.asReader(fields);
|
|
13
|
+
if (reader.isFinished()) {
|
|
14
|
+
throw new BlobDeserializationError(`Cannot decode empty blob data.`);
|
|
15
|
+
}
|
|
16
|
+
const firstField = reader.readField();
|
|
17
|
+
// Use toBigInt instead of toNumber so that we can catch it and throw a more descriptive error if the first field is
|
|
18
|
+
// larger than a javascript integer.
|
|
19
|
+
const totalNumBlobFields = firstField.toBigInt();
|
|
20
|
+
if (totalNumBlobFields > BigInt(reader.remainingFields() + 1)) {
|
|
21
|
+
// +1 because we already read the first field.
|
|
22
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: not enough fields for checkpoint blob data. Expected ${totalNumBlobFields} fields, got ${reader.remainingFields() + 1}.`);
|
|
23
|
+
}
|
|
24
|
+
const blocks = [];
|
|
25
|
+
while(reader.cursor < totalNumBlobFields){
|
|
26
|
+
blocks.push(decodeBlockBlobData(reader, blocks.length === 0 /* isFirstBlock */ ));
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
totalNumBlobFields: Number(totalNumBlobFields),
|
|
30
|
+
blocks
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function decodeCheckpointBlobDataFromBuffer(buf) {
|
|
34
|
+
const reader = BufferReader.asReader(buf);
|
|
35
|
+
const firstField = reader.readObject(Fr);
|
|
36
|
+
// Use toBigInt instead of toNumber so that we can catch it and throw a more descriptive error if the first field is
|
|
37
|
+
// larger than a javascript integer.
|
|
38
|
+
const numFields = firstField.toBigInt();
|
|
39
|
+
const totalFieldsInBuffer = BigInt(buf.length / Fr.SIZE_IN_BYTES);
|
|
40
|
+
if (numFields > totalFieldsInBuffer) {
|
|
41
|
+
throw new BlobDeserializationError(`Failed to deserialize blob buffer: not enough fields for checkpoint blob data. Expected ${numFields} fields, got ${totalFieldsInBuffer}.`);
|
|
42
|
+
}
|
|
43
|
+
const numFieldsWithoutPrefix = Number(numFields) - 1;
|
|
44
|
+
const blobFields = [
|
|
45
|
+
firstField
|
|
46
|
+
].concat(reader.readArray(numFieldsWithoutPrefix, Fr));
|
|
47
|
+
return decodeCheckpointBlobData(blobFields);
|
|
48
|
+
}
|
|
49
|
+
export function getTotalNumBlobFieldsFromTxs(txs) {
|
|
50
|
+
return 1 + // totalNumBlobFields
|
|
51
|
+
(txs.length ? 1 : 0) + // l1ToL2Messages root in the first block
|
|
52
|
+
txs.length * 6 + // 6 fields for each block end blob data.
|
|
53
|
+
txs.reduce((total, txs)=>total + txs.reduce((total, tx)=>total + tx.numBlobFields, 0), 0);
|
|
54
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { BlockBlobData, BlockEndBlobData } from './block_blob_data.js';
|
|
2
|
+
import type { BlockEndMarker } from './block_end_marker.js';
|
|
3
|
+
import type { BlockEndStateField } from './block_end_state_field.js';
|
|
4
|
+
import { type CheckpointBlobData } from './checkpoint_blob_data.js';
|
|
5
|
+
import { type TxBlobData } from './tx_blob_data.js';
|
|
6
|
+
import type { TxStartMarker } from './tx_start_marker.js';
|
|
7
|
+
export declare function makeTxStartMarker({ isFullTx, ...overrides }?: {
|
|
8
|
+
isFullTx?: boolean;
|
|
9
|
+
} & Partial<TxStartMarker>): TxStartMarker;
|
|
10
|
+
export declare function makeTxBlobData({ isFullTx, seed, ...overrides }?: {
|
|
11
|
+
isFullTx?: boolean;
|
|
12
|
+
seed?: number;
|
|
13
|
+
} & Partial<Omit<TxBlobData, 'txStartMarker'> & {
|
|
14
|
+
txStartMarker?: Partial<TxStartMarker>;
|
|
15
|
+
}>): TxBlobData;
|
|
16
|
+
export declare function makeBlockEndMarker({ seed, ...overrides }?: {
|
|
17
|
+
seed?: number;
|
|
18
|
+
} & Partial<BlockEndMarker>): BlockEndMarker;
|
|
19
|
+
export declare function makeBlockEndStateField({ seed, ...overrides }?: {
|
|
20
|
+
seed?: number;
|
|
21
|
+
} & Partial<BlockEndStateField>): BlockEndStateField;
|
|
22
|
+
export declare function makeBlockEndBlobData({ isFirstBlock, seed, ...overrides }?: {
|
|
23
|
+
seed?: number;
|
|
24
|
+
isFirstBlock?: boolean;
|
|
25
|
+
} & Partial<Omit<BlockEndBlobData, 'blockEndMarker' | 'blockEndStateField'>> & {
|
|
26
|
+
blockEndMarker?: Partial<BlockEndMarker>;
|
|
27
|
+
blockEndStateField?: Partial<BlockEndStateField>;
|
|
28
|
+
}): BlockEndBlobData;
|
|
29
|
+
export declare function makeBlockBlobData({ numTxs, isFirstBlock, isFullTx, seed, ...overrides }?: {
|
|
30
|
+
numTxs?: number;
|
|
31
|
+
isFirstBlock?: boolean;
|
|
32
|
+
isFullTx?: boolean;
|
|
33
|
+
seed?: number;
|
|
34
|
+
} & Partial<Parameters<typeof makeBlockEndBlobData>[0]>): BlockBlobData;
|
|
35
|
+
export declare function makeCheckpointBlobData({ numBlocks, numTxsPerBlock, isFullTx, seed, ...overrides }?: {
|
|
36
|
+
numBlocks?: number;
|
|
37
|
+
numTxsPerBlock?: number;
|
|
38
|
+
isFullTx?: boolean;
|
|
39
|
+
seed?: number;
|
|
40
|
+
} & Partial<CheckpointBlobData>): CheckpointBlobData;
|
|
41
|
+
//# sourceMappingURL=fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/encoding/fixtures.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,KAAK,kBAAkB,EAAgC,MAAM,2BAA2B,CAAC;AAClG,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,wBAAgB,iBAAiB,CAAC,EAChC,QAAgB,EAChB,GAAG,SAAS,EACb,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,aAAa,CAAM,GAAG,aAAa,CAmBtE;AAED,wBAAgB,cAAc,CAAC,EAC7B,QAAgB,EAChB,IAAQ,EACR,GAAG,SAAS,EACb,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAChD,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,GAAG;IAAE,aAAa,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CAAE,CAC1E,GAAG,UAAU,CAmDlB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,IAAQ,EACR,GAAG,SAAS,EACb,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAM,GAAG,cAAc,CAOnE;AAED,wBAAgB,sBAAsB,CAAC,EACrC,IAAQ,EACR,GAAG,SAAS,EACb,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,kBAAkB,CAAM,GAAG,kBAAkB,CAS3E;AAED,wBAAgB,oBAAoB,CAAC,EACnC,YAAmB,EACnB,IAAQ,EACR,GAAG,SAAS,EACb,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CACpD,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,oBAAoB,CAAC,CAChE,GAAG;IACA,cAAc,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACzC,kBAAkB,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC7C,GAAG,gBAAgB,CAgB1B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,MAAU,EACV,YAAmB,EACnB,QAAgB,EAChB,IAAQ,EACR,GAAG,SAAS,EACb,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CACzF,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CACtC,GAAG,aAAa,CAYrB;AAED,wBAAgB,sBAAsB,CAAC,EACrC,SAAa,EACb,cAAkB,EAClB,QAAgB,EAChB,IAAQ,EACR,GAAG,SAAS,EACb,GAAE;IACD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,kBAAkB,CAAM,GAAG,kBAAkB,CAiBxD"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH, MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PRIVATE_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
|
|
2
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { getTotalNumBlobFieldsFromTxs } from './checkpoint_blob_data.js';
|
|
5
|
+
import { getNumTxBlobFields } from './tx_blob_data.js';
|
|
6
|
+
const fr = (seed)=>new Fr(BigInt(seed));
|
|
7
|
+
export function makeTxStartMarker({ isFullTx = false, ...overrides } = {}) {
|
|
8
|
+
const partialTxStartMarker = {
|
|
9
|
+
revertCode: 0,
|
|
10
|
+
numNoteHashes: isFullTx ? MAX_NOTE_HASHES_PER_TX : 1,
|
|
11
|
+
numNullifiers: isFullTx ? MAX_NULLIFIERS_PER_TX : 1,
|
|
12
|
+
numL2ToL1Msgs: isFullTx ? MAX_L2_TO_L1_MSGS_PER_TX : 1,
|
|
13
|
+
numPublicDataWrites: isFullTx ? MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX : 1,
|
|
14
|
+
numPrivateLogs: isFullTx ? MAX_PRIVATE_LOGS_PER_TX : 1,
|
|
15
|
+
privateLogsLength: isFullTx ? PRIVATE_LOG_SIZE_IN_FIELDS * MAX_PRIVATE_LOGS_PER_TX : 1,
|
|
16
|
+
publicLogsLength: isFullTx ? FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH : 1,
|
|
17
|
+
contractClassLogLength: isFullTx ? MAX_CONTRACT_CLASS_LOGS_PER_TX : 1,
|
|
18
|
+
...overrides
|
|
19
|
+
};
|
|
20
|
+
const numBlobFields = overrides.numBlobFields ?? getNumTxBlobFields(partialTxStartMarker);
|
|
21
|
+
return {
|
|
22
|
+
...partialTxStartMarker,
|
|
23
|
+
numBlobFields
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function makeTxBlobData({ isFullTx = false, seed = 1, ...overrides } = {}) {
|
|
27
|
+
const { txStartMarker: txStartMarkerOverrides, ...txBlobDataOverrides } = overrides;
|
|
28
|
+
const txStartMarker = makeTxStartMarker({
|
|
29
|
+
isFullTx,
|
|
30
|
+
...txStartMarkerOverrides
|
|
31
|
+
});
|
|
32
|
+
const noteHashes = makeTuple(txStartMarker.numNoteHashes, fr, seed);
|
|
33
|
+
const nullifiers = makeTuple(txStartMarker.numNullifiers, fr, seed + 0x100);
|
|
34
|
+
const l2ToL1Msgs = makeTuple(txStartMarker.numL2ToL1Msgs, fr, seed + 0x200);
|
|
35
|
+
const publicDataWrites = makeTuple(txStartMarker.numPublicDataWrites, (i)=>[
|
|
36
|
+
fr(seed + i * 2),
|
|
37
|
+
fr(seed + i * 2 + 1)
|
|
38
|
+
], seed + 0x300);
|
|
39
|
+
const privateLogs = [];
|
|
40
|
+
if (txStartMarker.privateLogsLength > txStartMarker.numPrivateLogs * PRIVATE_LOG_SIZE_IN_FIELDS) {
|
|
41
|
+
throw new Error('Private logs length is too large');
|
|
42
|
+
}
|
|
43
|
+
if (txStartMarker.privateLogsLength < txStartMarker.numPrivateLogs) {
|
|
44
|
+
throw new Error('Private logs length is too small');
|
|
45
|
+
}
|
|
46
|
+
let remainingNumPrivateLogs = txStartMarker.numPrivateLogs;
|
|
47
|
+
let remainingPrivateLogsLength = txStartMarker.privateLogsLength;
|
|
48
|
+
for(let i = 0; i < txStartMarker.numPrivateLogs; i++){
|
|
49
|
+
const minLength = Math.max(1, remainingPrivateLogsLength - (remainingNumPrivateLogs - 1) * PRIVATE_LOG_SIZE_IN_FIELDS);
|
|
50
|
+
const length = Math.max(minLength, Math.floor(remainingPrivateLogsLength / remainingNumPrivateLogs));
|
|
51
|
+
privateLogs.push(makeTuple(length, fr, seed + 0x400 + i * PRIVATE_LOG_SIZE_IN_FIELDS));
|
|
52
|
+
remainingNumPrivateLogs -= 1;
|
|
53
|
+
remainingPrivateLogsLength -= length;
|
|
54
|
+
}
|
|
55
|
+
const publicLogs = makeTuple(txStartMarker.publicLogsLength, fr, seed + 0x500);
|
|
56
|
+
const contractClassLogBlobDataLength = txStartMarker.contractClassLogLength > 0 ? txStartMarker.contractClassLogLength + 1 : 0; // If the log exists, +1 for the contract address
|
|
57
|
+
const contractClassLog = makeTuple(contractClassLogBlobDataLength, fr, seed + 0x600);
|
|
58
|
+
return {
|
|
59
|
+
txStartMarker,
|
|
60
|
+
txHash: fr(seed + 0x700),
|
|
61
|
+
transactionFee: fr(seed + 0x800),
|
|
62
|
+
noteHashes,
|
|
63
|
+
nullifiers,
|
|
64
|
+
l2ToL1Msgs,
|
|
65
|
+
publicDataWrites,
|
|
66
|
+
privateLogs,
|
|
67
|
+
publicLogs,
|
|
68
|
+
contractClassLog,
|
|
69
|
+
...txBlobDataOverrides
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function makeBlockEndMarker({ seed = 1, ...overrides } = {}) {
|
|
73
|
+
return {
|
|
74
|
+
numTxs: seed,
|
|
75
|
+
blockNumber: seed + 1,
|
|
76
|
+
timestamp: BigInt(seed + 2),
|
|
77
|
+
...overrides
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function makeBlockEndStateField({ seed = 1, ...overrides } = {}) {
|
|
81
|
+
return {
|
|
82
|
+
l1ToL2MessageNextAvailableLeafIndex: seed,
|
|
83
|
+
noteHashNextAvailableLeafIndex: seed + 0x10,
|
|
84
|
+
nullifierNextAvailableLeafIndex: seed + 0x20,
|
|
85
|
+
publicDataNextAvailableLeafIndex: seed + 0x30,
|
|
86
|
+
totalManaUsed: BigInt(seed + 0x40),
|
|
87
|
+
...overrides
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function makeBlockEndBlobData({ isFirstBlock = true, seed = 1, ...overrides } = {}) {
|
|
91
|
+
const { blockEndMarker: blockEndMarkerOverrides, blockEndStateField: blockEndStateFieldOverrides, ...blockEndBlobDataOverrides } = overrides;
|
|
92
|
+
return {
|
|
93
|
+
blockEndMarker: makeBlockEndMarker({
|
|
94
|
+
seed,
|
|
95
|
+
...blockEndMarkerOverrides
|
|
96
|
+
}),
|
|
97
|
+
blockEndStateField: makeBlockEndStateField({
|
|
98
|
+
seed: seed + 0x100,
|
|
99
|
+
...blockEndStateFieldOverrides
|
|
100
|
+
}),
|
|
101
|
+
lastArchiveRoot: fr(seed + 0x200),
|
|
102
|
+
noteHashRoot: fr(seed + 0x300),
|
|
103
|
+
nullifierRoot: fr(seed + 0x400),
|
|
104
|
+
publicDataRoot: fr(seed + 0x500),
|
|
105
|
+
l1ToL2MessageRoot: isFirstBlock ? fr(seed + 0x600) : undefined,
|
|
106
|
+
...blockEndBlobDataOverrides
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function makeBlockBlobData({ numTxs = 1, isFirstBlock = true, isFullTx = false, seed = 1, ...overrides } = {}) {
|
|
110
|
+
return {
|
|
111
|
+
txs: makeTuple(numTxs, (i)=>makeTxBlobData({
|
|
112
|
+
isFullTx,
|
|
113
|
+
seed: seed + i * 0x100
|
|
114
|
+
}), seed),
|
|
115
|
+
...makeBlockEndBlobData({
|
|
116
|
+
seed: seed + 0x1000 * numTxs,
|
|
117
|
+
blockEndMarker: {
|
|
118
|
+
numTxs
|
|
119
|
+
},
|
|
120
|
+
isFirstBlock,
|
|
121
|
+
...overrides
|
|
122
|
+
})
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export function makeCheckpointBlobData({ numBlocks = 1, numTxsPerBlock = 1, isFullTx = false, seed = 1, ...overrides } = {}) {
|
|
126
|
+
const blocks = overrides.blocks ?? makeTuple(numBlocks, (i)=>makeBlockBlobData({
|
|
127
|
+
numTxs: numTxsPerBlock,
|
|
128
|
+
isFirstBlock: i === seed,
|
|
129
|
+
isFullTx,
|
|
130
|
+
seed: seed + i * 0x1000
|
|
131
|
+
}), seed);
|
|
132
|
+
const totalNumBlobFields = overrides.totalNumBlobFields ?? getTotalNumBlobFieldsFromTxs(blocks.map((block)=>block.txs.map((tx)=>tx.txStartMarker)));
|
|
133
|
+
return {
|
|
134
|
+
totalNumBlobFields,
|
|
135
|
+
blocks
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './block_blob_data.js';
|
|
2
|
+
export * from './block_end_marker.js';
|
|
3
|
+
export * from './block_end_state_field.js';
|
|
4
|
+
export * from './checkpoint_blob_data.js';
|
|
5
|
+
export * from './fixtures.js';
|
|
6
|
+
export * from './tx_blob_data.js';
|
|
7
|
+
export * from './tx_start_marker.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encoding/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './block_blob_data.js';
|
|
2
|
+
export * from './block_end_marker.js';
|
|
3
|
+
export * from './block_end_state_field.js';
|
|
4
|
+
export * from './checkpoint_blob_data.js';
|
|
5
|
+
export * from './fixtures.js';
|
|
6
|
+
export * from './tx_blob_data.js';
|
|
7
|
+
export * from './tx_start_marker.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { type TxStartMarker } from './tx_start_marker.js';
|
|
4
|
+
export interface TxBlobData {
|
|
5
|
+
txStartMarker: TxStartMarker;
|
|
6
|
+
txHash: Fr;
|
|
7
|
+
transactionFee: Fr;
|
|
8
|
+
noteHashes: Fr[];
|
|
9
|
+
nullifiers: Fr[];
|
|
10
|
+
l2ToL1Msgs: Fr[];
|
|
11
|
+
publicDataWrites: [Fr, Fr][];
|
|
12
|
+
privateLogs: Fr[][];
|
|
13
|
+
publicLogs: Fr[];
|
|
14
|
+
contractClassLog: Fr[];
|
|
15
|
+
}
|
|
16
|
+
export declare function encodeTxBlobData(txBlobData: TxBlobData): Fr[];
|
|
17
|
+
export declare function decodeTxBlobData(fields: Fr[] | FieldReader): TxBlobData;
|
|
18
|
+
export declare function getNumTxBlobFields(txStartMarker: Omit<TxStartMarker, 'revertCode' | 'numBlobFields'>): number;
|
|
19
|
+
//# sourceMappingURL=tx_blob_data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx_blob_data.d.ts","sourceRoot":"","sources":["../../src/encoding/tx_blob_data.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EAAE,KAAK,aAAa,EAA4C,MAAM,sBAAsB,CAAC;AAIpG,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,EAAE,CAAC;IACX,cAAc,EAAE,EAAE,CAAC;IACnB,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,gBAAgB,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAC7B,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC;IACpB,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,gBAAgB,EAAE,EAAE,EAAE,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,EAAE,EAAE,CAa7D;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,UAAU,CA6DvE;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,eAAe,CAAC,UAepG"}
|