@aztec/stdlib 0.0.1-commit.e6bd8901 → 0.0.1-commit.f146247c
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/block/block_hash.d.ts +16 -18
- package/dest/block/block_hash.d.ts.map +1 -1
- package/dest/block/block_hash.js +21 -31
- package/dest/block/block_parameter.d.ts +4 -4
- package/dest/block/block_parameter.d.ts.map +1 -1
- package/dest/block/block_parameter.js +2 -2
- package/dest/block/in_block.d.ts +9 -9
- package/dest/block/in_block.d.ts.map +1 -1
- package/dest/block/in_block.js +4 -4
- package/dest/block/l2_block.d.ts +3 -2
- package/dest/block/l2_block.d.ts.map +1 -1
- package/dest/block/l2_block_source.d.ts +5 -4
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/contract/contract_address.js +1 -1
- package/dest/contract/contract_class_id.d.ts +1 -1
- package/dest/contract/contract_class_id.js +1 -1
- package/dest/contract/private_function.js +1 -1
- package/dest/contract/private_function_membership_proof.d.ts +1 -1
- package/dest/contract/private_function_membership_proof.js +1 -1
- package/dest/database-version/database_version.d.ts +58 -0
- package/dest/database-version/database_version.d.ts.map +1 -0
- package/dest/database-version/database_version.js +69 -0
- package/dest/database-version/version_manager.d.ts +2 -50
- package/dest/database-version/version_manager.d.ts.map +1 -1
- package/dest/database-version/version_manager.js +1 -66
- package/dest/epoch-helpers/index.d.ts +3 -1
- package/dest/epoch-helpers/index.d.ts.map +1 -1
- package/dest/epoch-helpers/index.js +4 -0
- package/dest/hash/hash.js +2 -2
- package/dest/hash/map_slot.d.ts +1 -1
- package/dest/hash/map_slot.d.ts.map +1 -1
- package/dest/hash/map_slot.js +4 -3
- package/dest/interfaces/archiver.d.ts +1 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +4 -3
- package/dest/interfaces/aztec-node.d.ts +33 -54
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +6 -10
- package/dest/interfaces/block-builder.d.ts +10 -4
- package/dest/interfaces/block-builder.d.ts.map +1 -1
- package/dest/interfaces/block-builder.js +7 -0
- package/dest/interfaces/get_logs_response.d.ts +7 -7
- package/dest/interfaces/validator.d.ts +2 -2
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/keys/derivation.d.ts +3 -3
- package/dest/keys/derivation.js +8 -8
- package/dest/keys/key_types.d.ts +1 -1
- package/dest/keys/utils.d.ts +1 -1
- package/dest/keys/utils.d.ts.map +1 -1
- package/dest/keys/utils.js +7 -3
- package/dest/l1-contracts/slash_factory.d.ts +1 -1
- package/dest/l1-contracts/slash_factory.d.ts.map +1 -1
- package/dest/l1-contracts/slash_factory.js +1 -0
- package/dest/logs/extended_public_log.d.ts +6 -6
- package/dest/logs/log_id.d.ts +8 -8
- package/dest/logs/log_id.d.ts.map +1 -1
- package/dest/logs/log_id.js +6 -5
- package/dest/logs/siloed_tag.d.ts +1 -1
- package/dest/logs/siloed_tag.d.ts.map +1 -1
- package/dest/logs/siloed_tag.js +4 -3
- package/dest/p2p/block_proposal.d.ts +10 -3
- package/dest/p2p/block_proposal.d.ts.map +1 -1
- package/dest/p2p/checkpoint_proposal.d.ts +10 -3
- package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
- package/dest/stats/stats.d.ts +1 -3
- package/dest/stats/stats.d.ts.map +1 -1
- package/dest/tests/mocks.d.ts +6 -2
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +4 -3
- package/dest/tx/block_header.d.ts +3 -2
- package/dest/tx/block_header.d.ts.map +1 -1
- package/dest/tx/block_header.js +3 -2
- package/dest/tx/in_tx.d.ts +3 -3
- package/dest/tx/indexed_tx_effect.d.ts +5 -5
- package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
- package/dest/tx/indexed_tx_effect.js +3 -2
- package/dest/tx/tx_receipt.d.ts +5 -5
- package/dest/tx/tx_receipt.d.ts.map +1 -1
- package/dest/tx/tx_receipt.js +2 -2
- package/package.json +11 -10
- package/src/block/block_hash.ts +26 -47
- package/src/block/block_parameter.ts +3 -3
- package/src/block/in_block.ts +5 -5
- package/src/block/l2_block.ts +2 -1
- package/src/block/l2_block_source.ts +4 -3
- package/src/contract/contract_address.ts +1 -1
- package/src/contract/contract_class_id.ts +1 -1
- package/src/contract/private_function.ts +1 -1
- package/src/contract/private_function_membership_proof.ts +1 -1
- package/src/database-version/database_version.ts +87 -0
- package/src/database-version/version_manager.ts +1 -77
- package/src/epoch-helpers/index.ts +9 -0
- package/src/hash/hash.ts +2 -2
- package/src/hash/map_slot.ts +3 -2
- package/src/interfaces/archiver.ts +4 -3
- package/src/interfaces/aztec-node.ts +42 -93
- package/src/interfaces/block-builder.ts +12 -2
- package/src/interfaces/validator.ts +1 -2
- package/src/keys/derivation.ts +8 -8
- package/src/keys/key_types.ts +1 -1
- package/src/keys/utils.ts +7 -3
- package/src/l1-contracts/slash_factory.ts +1 -0
- package/src/logs/log_id.ts +7 -6
- package/src/logs/siloed_tag.ts +3 -2
- package/src/p2p/block_proposal.ts +9 -2
- package/src/p2p/checkpoint_proposal.ts +9 -2
- package/src/stats/stats.ts +0 -2
- package/src/tests/mocks.ts +6 -4
- package/src/tx/block_header.ts +7 -4
- package/src/tx/indexed_tx_effect.ts +3 -2
- package/src/tx/tx_receipt.ts +4 -4
- package/dest/database-version/index.d.ts +0 -2
- package/dest/database-version/index.d.ts.map +0 -1
- package/dest/database-version/index.js +0 -1
- package/src/database-version/index.ts +0 -1
package/src/block/block_hash.ts
CHANGED
|
@@ -1,66 +1,45 @@
|
|
|
1
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import {
|
|
2
|
+
import type { ZodFor } from '@aztec/foundation/schemas';
|
|
4
3
|
|
|
5
|
-
import {
|
|
4
|
+
import { inspect } from 'util';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
export class L2BlockHash extends Buffer32 {
|
|
9
|
-
constructor(
|
|
10
|
-
/** The buffer containing the hash. */
|
|
11
|
-
hash: Buffer,
|
|
12
|
-
) {
|
|
13
|
-
super(hash);
|
|
14
|
-
}
|
|
6
|
+
import { hexSchemaFor } from '../schemas/schemas.js';
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
* Type guard that checks if a value is an L2BlockHash instance.
|
|
18
|
-
* Uses duck typing to handle cases where instanceof fails due to module duplication.
|
|
19
|
-
* Checks for Buffer32-like structure with a 32-byte buffer.
|
|
20
|
-
*/
|
|
21
|
-
static isL2BlockHash(value: unknown): value is L2BlockHash {
|
|
22
|
-
if (value instanceof L2BlockHash) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
// Duck typing fallback: check if it looks like a Buffer32 with a 32-byte buffer
|
|
26
|
-
// This helps when instanceof fails due to module duplication
|
|
27
|
-
return (
|
|
28
|
-
typeof value === 'object' &&
|
|
29
|
-
value !== null &&
|
|
30
|
-
'buffer' in value &&
|
|
31
|
-
Buffer.isBuffer((value as Buffer32).buffer) &&
|
|
32
|
-
(value as Buffer32).buffer.length === 32 &&
|
|
33
|
-
'toBuffer' in value &&
|
|
34
|
-
typeof (value as Buffer32).toBuffer === 'function'
|
|
35
|
-
);
|
|
36
|
-
}
|
|
8
|
+
const BLOCK_HASH_BRAND = Symbol.for('aztec.BlockHash');
|
|
37
9
|
|
|
38
|
-
|
|
39
|
-
|
|
10
|
+
/** Hash of an L2 block. */
|
|
11
|
+
export class BlockHash extends Fr {
|
|
12
|
+
readonly [BLOCK_HASH_BRAND] = true as const;
|
|
13
|
+
|
|
14
|
+
constructor(hash: Fr) {
|
|
15
|
+
super(hash);
|
|
40
16
|
}
|
|
41
17
|
|
|
42
|
-
|
|
43
|
-
return
|
|
18
|
+
override [inspect.custom]() {
|
|
19
|
+
return `BlockHash<${this.toString()}>`;
|
|
44
20
|
}
|
|
45
21
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return new L2BlockHash(reader.readBytes(L2BlockHash.SIZE));
|
|
22
|
+
toFr(): Fr {
|
|
23
|
+
return new Fr(this.toBigInt());
|
|
49
24
|
}
|
|
50
25
|
|
|
51
|
-
|
|
52
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Type guard that checks if a value is a BlockHash instance.
|
|
28
|
+
* Uses Symbol.for to ensure cross-module compatibility.
|
|
29
|
+
*/
|
|
30
|
+
static isBlockHash(value: unknown): value is BlockHash {
|
|
31
|
+
return typeof value === 'object' && value !== null && BLOCK_HASH_BRAND in value;
|
|
53
32
|
}
|
|
54
33
|
|
|
55
|
-
static
|
|
56
|
-
return
|
|
34
|
+
static override random() {
|
|
35
|
+
return new BlockHash(Fr.random());
|
|
57
36
|
}
|
|
58
37
|
|
|
59
|
-
static
|
|
60
|
-
return new
|
|
38
|
+
static override fromString(str: string): BlockHash {
|
|
39
|
+
return new BlockHash(Fr.fromString(str));
|
|
61
40
|
}
|
|
62
41
|
|
|
63
|
-
static override
|
|
64
|
-
return
|
|
42
|
+
static override get schema() {
|
|
43
|
+
return hexSchemaFor(BlockHash) as ZodFor<BlockHash>;
|
|
65
44
|
}
|
|
66
45
|
}
|
|
@@ -2,9 +2,9 @@ import { BlockNumberSchema } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { BlockHash } from './block_hash.js';
|
|
6
6
|
|
|
7
|
-
export const BlockParameterSchema = z.union([
|
|
7
|
+
export const BlockParameterSchema = z.union([BlockHash.schema, BlockNumberSchema, z.literal('latest')]);
|
|
8
8
|
|
|
9
|
-
/** Block parameter - either a specific BlockNumber, block hash (
|
|
9
|
+
/** Block parameter - either a specific BlockNumber, block hash (BlockHash), or 'latest' */
|
|
10
10
|
export type BlockParameter = z.infer<typeof BlockParameterSchema>;
|
package/src/block/in_block.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { BlockNumber, BlockNumberSchema } from '@aztec/foundation/branded-types'
|
|
|
2
2
|
|
|
3
3
|
import { type ZodTypeAny, z } from 'zod';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { BlockHash } from './block_hash.js';
|
|
6
6
|
import type { L2Block } from './l2_block.js';
|
|
7
7
|
|
|
8
8
|
export type InBlock = {
|
|
9
9
|
l2BlockNumber: BlockNumber;
|
|
10
|
-
l2BlockHash:
|
|
10
|
+
l2BlockHash: BlockHash;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// Note: If you expand this type with indexInBlock, then delete `IndexedTxEffect` and use this type instead.
|
|
@@ -18,7 +18,7 @@ export type DataInBlock<T> = {
|
|
|
18
18
|
export function randomInBlock(): InBlock {
|
|
19
19
|
return {
|
|
20
20
|
l2BlockNumber: BlockNumber(Math.floor(Math.random() * 1000)),
|
|
21
|
-
l2BlockHash:
|
|
21
|
+
l2BlockHash: BlockHash.random(),
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -33,14 +33,14 @@ export async function wrapDataInBlock<T>(data: T, block: L2Block): Promise<DataI
|
|
|
33
33
|
return {
|
|
34
34
|
data,
|
|
35
35
|
l2BlockNumber: block.number,
|
|
36
|
-
l2BlockHash:
|
|
36
|
+
l2BlockHash: await block.hash(),
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export function inBlockSchema() {
|
|
41
41
|
return z.object({
|
|
42
42
|
l2BlockNumber: BlockNumberSchema,
|
|
43
|
-
l2BlockHash:
|
|
43
|
+
l2BlockHash: BlockHash.schema,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
package/src/block/l2_block.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { z } from 'zod';
|
|
|
15
15
|
import type { PrivateLog } from '../logs/private_log.js';
|
|
16
16
|
import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
|
|
17
17
|
import { BlockHeader } from '../tx/block_header.js';
|
|
18
|
+
import type { BlockHash } from './block_hash.js';
|
|
18
19
|
import { Body } from './body.js';
|
|
19
20
|
import type { L2BlockInfo } from './l2_block_info.js';
|
|
20
21
|
|
|
@@ -89,7 +90,7 @@ export class L2Block {
|
|
|
89
90
|
* Returns the block's hash (hash of block header).
|
|
90
91
|
* @returns The block's hash.
|
|
91
92
|
*/
|
|
92
|
-
public hash(): Promise<
|
|
93
|
+
public hash(): Promise<BlockHash> {
|
|
93
94
|
return this.header.hash();
|
|
94
95
|
}
|
|
95
96
|
|
|
@@ -20,6 +20,7 @@ import type { BlockHeader } from '../tx/block_header.js';
|
|
|
20
20
|
import type { IndexedTxEffect } from '../tx/indexed_tx_effect.js';
|
|
21
21
|
import type { TxHash } from '../tx/tx_hash.js';
|
|
22
22
|
import type { TxReceipt } from '../tx/tx_receipt.js';
|
|
23
|
+
import type { BlockHash } from './block_hash.js';
|
|
23
24
|
import type { CheckpointedL2Block } from './checkpointed_l2_block.js';
|
|
24
25
|
import type { L2Block } from './l2_block.js';
|
|
25
26
|
import type { ValidateCheckpointNegativeResult, ValidateCheckpointResult } from './validate_block_result.js';
|
|
@@ -102,7 +103,7 @@ export interface L2BlockSource {
|
|
|
102
103
|
* @param blockHash - The block hash to retrieve.
|
|
103
104
|
* @returns The requested block header (or undefined if not found).
|
|
104
105
|
*/
|
|
105
|
-
getBlockHeaderByHash(blockHash:
|
|
106
|
+
getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined>;
|
|
106
107
|
|
|
107
108
|
/**
|
|
108
109
|
* Gets a block header by its archive root.
|
|
@@ -123,7 +124,7 @@ export interface L2BlockSource {
|
|
|
123
124
|
* @param blockHash - The block hash to retrieve.
|
|
124
125
|
* @returns The requested L2 block (or undefined if not found).
|
|
125
126
|
*/
|
|
126
|
-
getL2BlockByHash(blockHash:
|
|
127
|
+
getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined>;
|
|
127
128
|
|
|
128
129
|
/**
|
|
129
130
|
* Gets an L2 block by its archive root.
|
|
@@ -228,7 +229,7 @@ export interface L2BlockSource {
|
|
|
228
229
|
* @param blockHash - The block hash to retrieve.
|
|
229
230
|
* @returns The requested block (or undefined if not found).
|
|
230
231
|
*/
|
|
231
|
-
getCheckpointedBlockByHash(blockHash:
|
|
232
|
+
getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined>;
|
|
232
233
|
|
|
233
234
|
/**
|
|
234
235
|
* Gets a checkpointed block by its archive root.
|
|
@@ -87,5 +87,5 @@ export async function computeInitializationHashFromEncodedArgs(
|
|
|
87
87
|
encodedArgs: Fr[],
|
|
88
88
|
): Promise<Fr> {
|
|
89
89
|
const argsHash = await computeVarArgsHash(encodedArgs);
|
|
90
|
-
return poseidon2HashWithSeparator([initFn, argsHash], GeneratorIndex.
|
|
90
|
+
return poseidon2HashWithSeparator([initFn, argsHash], GeneratorIndex.INITIALIZER);
|
|
91
91
|
}
|
|
@@ -13,7 +13,7 @@ import { computePrivateFunctionsRoot } from './private_function.js';
|
|
|
13
13
|
*
|
|
14
14
|
* ```
|
|
15
15
|
* version = 1
|
|
16
|
-
* private_function_leaves = private_functions.map(fn => pedersen([fn.function_selector as Field, fn.vk_hash],
|
|
16
|
+
* private_function_leaves = private_functions.map(fn => pedersen([fn.function_selector as Field, fn.vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF))
|
|
17
17
|
* private_functions_root = merkleize(private_function_leaves)
|
|
18
18
|
* bytecode_commitment = calculate_commitment(packed_bytecode)
|
|
19
19
|
* contract_class_id = pedersen([version, artifact_hash, private_functions_root, bytecode_commitment], GENERATOR__CLASS_IDENTIFIER)
|
|
@@ -31,7 +31,7 @@ function computePrivateFunctionLeaves(fns: PrivateFunction[]): Promise<Buffer[]>
|
|
|
31
31
|
|
|
32
32
|
/** Returns the leaf for a given private function. */
|
|
33
33
|
export async function computePrivateFunctionLeaf(fn: PrivateFunction): Promise<Buffer> {
|
|
34
|
-
return (await poseidon2HashWithSeparator([fn.selector, fn.vkHash], GeneratorIndex.
|
|
34
|
+
return (await poseidon2HashWithSeparator([fn.selector, fn.vkHash], GeneratorIndex.PRIVATE_FUNCTION_LEAF)).toBuffer();
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async function getPrivateFunctionTreeCalculator(): Promise<MerkleTreeCalculator> {
|
|
@@ -99,7 +99,7 @@ export async function createPrivateFunctionMembershipProof(
|
|
|
99
99
|
* contract_class = db.get_contract_class(contract_class_id)
|
|
100
100
|
*
|
|
101
101
|
* // Compute function leaf and assert it belongs to the private functions tree
|
|
102
|
-
* function_leaf = pedersen([selector as Field, vk_hash],
|
|
102
|
+
* function_leaf = pedersen([selector as Field, vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF)
|
|
103
103
|
* computed_private_function_tree_root = compute_root(function_leaf, private_function_tree_sibling_path)
|
|
104
104
|
* assert computed_private_function_tree_root == contract_class.private_functions_root
|
|
105
105
|
*
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
|
+
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Symbol for Node.js custom inspect. Using Symbol.for() is the documented way to
|
|
8
|
+
* reference this without importing node:util. In browsers, objects with this symbol
|
|
9
|
+
* simply won't have custom inspect behavior (which is fine).
|
|
10
|
+
* @see https://nodejs.org/api/util.html#utilinspectcustom
|
|
11
|
+
*/
|
|
12
|
+
const inspectCustomSymbol = Symbol.for('nodejs.util.inspect.custom');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents a version record for storing in a version file.
|
|
16
|
+
*/
|
|
17
|
+
export class DatabaseVersion {
|
|
18
|
+
constructor(
|
|
19
|
+
/** The version of the data on disk. Used to perform upgrades */
|
|
20
|
+
public readonly schemaVersion: number,
|
|
21
|
+
/** The rollup the data pertains to */
|
|
22
|
+
public readonly rollupAddress: EthAddress,
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
public toBuffer(): Buffer {
|
|
26
|
+
return Buffer.from(jsonStringify(this));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static fromBuffer(buf: Buffer): DatabaseVersion {
|
|
30
|
+
try {
|
|
31
|
+
return jsonParseWithSchema(buf.toString('utf-8'), DatabaseVersion.schema);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
throw new Error(`Failed to deserialize version information: ${err}`, { cause: err });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Compares two versions. If the rollups addresses are different then it returns undefined
|
|
39
|
+
*/
|
|
40
|
+
public cmp(other: DatabaseVersion): undefined | -1 | 0 | 1 {
|
|
41
|
+
if (this.rollupAddress.equals(other.rollupAddress)) {
|
|
42
|
+
if (this.schemaVersion < other.schemaVersion) {
|
|
43
|
+
return -1;
|
|
44
|
+
} else if (this.schemaVersion > other.schemaVersion) {
|
|
45
|
+
return 1;
|
|
46
|
+
} else {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Checks if two versions exactly match
|
|
55
|
+
*/
|
|
56
|
+
public equals(other: DatabaseVersion): boolean {
|
|
57
|
+
return this.cmp(other) === 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns the schema for this class
|
|
62
|
+
*/
|
|
63
|
+
static get schema() {
|
|
64
|
+
return z
|
|
65
|
+
.object({
|
|
66
|
+
schemaVersion: z.number(),
|
|
67
|
+
rollupAddress: EthAddress.schema,
|
|
68
|
+
})
|
|
69
|
+
.transform(({ schemaVersion, rollupAddress }) => new DatabaseVersion(schemaVersion, rollupAddress));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Allows for better introspection in Node.js console. Ignored in browser envs. */
|
|
73
|
+
public [inspectCustomSymbol](): string {
|
|
74
|
+
return this.toString();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public toString(): string {
|
|
78
|
+
return `DatabaseVersion{schemaVersion=${this.schemaVersion},rollupAddress=${this.rollupAddress}"}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Returns an empty instance
|
|
83
|
+
*/
|
|
84
|
+
static empty() {
|
|
85
|
+
return new DatabaseVersion(0, EthAddress.ZERO);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -1,86 +1,10 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
3
|
|
|
5
4
|
import fs from 'fs/promises';
|
|
6
|
-
import { inspect } from 'node:util';
|
|
7
5
|
import { join } from 'path';
|
|
8
|
-
import { z } from 'zod';
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
* Represents a version record for storing in a version file.
|
|
12
|
-
*/
|
|
13
|
-
export class DatabaseVersion {
|
|
14
|
-
constructor(
|
|
15
|
-
/** The version of the data on disk. Used to perform upgrades */
|
|
16
|
-
public readonly schemaVersion: number,
|
|
17
|
-
/** The rollup the data pertains to */
|
|
18
|
-
public readonly rollupAddress: EthAddress,
|
|
19
|
-
) {}
|
|
20
|
-
|
|
21
|
-
public toBuffer(): Buffer {
|
|
22
|
-
return Buffer.from(jsonStringify(this));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static fromBuffer(buf: Buffer): DatabaseVersion {
|
|
26
|
-
try {
|
|
27
|
-
return jsonParseWithSchema(buf.toString('utf-8'), DatabaseVersion.schema);
|
|
28
|
-
} catch (err) {
|
|
29
|
-
throw new Error(`Failed to deserialize version information: ${err}`, { cause: err });
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Compares two versions. If the rollups addresses are different then it returns undefined
|
|
35
|
-
*/
|
|
36
|
-
public cmp(other: DatabaseVersion): undefined | -1 | 0 | 1 {
|
|
37
|
-
if (this.rollupAddress.equals(other.rollupAddress)) {
|
|
38
|
-
if (this.schemaVersion < other.schemaVersion) {
|
|
39
|
-
return -1;
|
|
40
|
-
} else if (this.schemaVersion > other.schemaVersion) {
|
|
41
|
-
return 1;
|
|
42
|
-
} else {
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Checks if two versions exactly match
|
|
51
|
-
*/
|
|
52
|
-
public equals(other: DatabaseVersion): boolean {
|
|
53
|
-
return this.cmp(other) === 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Returns the schema for this class
|
|
58
|
-
*/
|
|
59
|
-
static get schema() {
|
|
60
|
-
return z
|
|
61
|
-
.object({
|
|
62
|
-
schemaVersion: z.number(),
|
|
63
|
-
rollupAddress: EthAddress.schema,
|
|
64
|
-
})
|
|
65
|
-
.transform(({ schemaVersion, rollupAddress }) => new DatabaseVersion(schemaVersion, rollupAddress));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Allows for better introspection. */
|
|
69
|
-
public [inspect.custom](): string {
|
|
70
|
-
return this.toString();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public toString(): string {
|
|
74
|
-
return `DatabaseVersion{schemaVersion=${this.schemaVersion},rollupAddress=${this.rollupAddress}"}`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Returns an empty instance
|
|
79
|
-
*/
|
|
80
|
-
static empty() {
|
|
81
|
-
return new DatabaseVersion(0, EthAddress.ZERO);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
7
|
+
import { DatabaseVersion } from './database_version.js';
|
|
84
8
|
|
|
85
9
|
export type DatabaseVersionManagerFs = Pick<typeof fs, 'readFile' | 'writeFile' | 'rm' | 'mkdir'>;
|
|
86
10
|
|
|
@@ -51,6 +51,15 @@ export function getSlotAtTimestamp(
|
|
|
51
51
|
: SlotNumber.fromBigInt((ts - constants.l1GenesisTime) / BigInt(constants.slotDuration));
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/** Returns the L2 slot number at the next L1 block based on the current timestamp. */
|
|
55
|
+
export function getSlotAtNextL1Block(
|
|
56
|
+
currentL1Timestamp: bigint,
|
|
57
|
+
constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>,
|
|
58
|
+
): SlotNumber {
|
|
59
|
+
const nextL1BlockTimestamp = currentL1Timestamp + BigInt(constants.ethereumSlotDuration);
|
|
60
|
+
return getSlotAtTimestamp(nextL1BlockTimestamp, constants);
|
|
61
|
+
}
|
|
62
|
+
|
|
54
63
|
/** Returns the epoch number for a given timestamp. */
|
|
55
64
|
export function getEpochNumberAtTimestamp(
|
|
56
65
|
ts: bigint,
|
package/src/hash/hash.ts
CHANGED
|
@@ -55,7 +55,7 @@ export function computeUniqueNoteHash(noteNonce: Fr, siloedNoteHash: Fr): Promis
|
|
|
55
55
|
* @returns A siloed nullifier.
|
|
56
56
|
*/
|
|
57
57
|
export function siloNullifier(contract: AztecAddress, innerNullifier: Fr): Promise<Fr> {
|
|
58
|
-
return poseidon2HashWithSeparator([contract, innerNullifier], GeneratorIndex.
|
|
58
|
+
return poseidon2HashWithSeparator([contract, innerNullifier], GeneratorIndex.SILOED_NULLIFIER);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
@@ -87,7 +87,7 @@ export function computePublicDataTreeValue(value: Fr): Fr {
|
|
|
87
87
|
|
|
88
88
|
*/
|
|
89
89
|
export function computePublicDataTreeLeafSlot(contractAddress: AztecAddress, storageSlot: Fr): Promise<Fr> {
|
|
90
|
-
return poseidon2HashWithSeparator([contractAddress, storageSlot], GeneratorIndex.
|
|
90
|
+
return poseidon2HashWithSeparator([contractAddress, storageSlot], GeneratorIndex.PUBLIC_LEAF_SLOT);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
package/src/hash/map_slot.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeneratorIndex } from '@aztec/constants';
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
2
3
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -14,5 +15,5 @@ export function deriveStorageSlotInMap(
|
|
|
14
15
|
toField: () => Fr;
|
|
15
16
|
},
|
|
16
17
|
): Promise<Fr> {
|
|
17
|
-
return
|
|
18
|
+
return poseidon2HashWithSeparator([mapSlot, key.toField()], GeneratorIndex.PUBLIC_STORAGE_MAP_SLOT);
|
|
18
19
|
}
|
|
@@ -4,6 +4,7 @@ import type { ApiSchemaFor } from '@aztec/foundation/schemas';
|
|
|
4
4
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
|
+
import { BlockHash } from '../block/block_hash.js';
|
|
7
8
|
import { CheckpointedL2Block } from '../block/checkpointed_l2_block.js';
|
|
8
9
|
import { L2Block } from '../block/l2_block.js';
|
|
9
10
|
import { type L2BlockSource, L2TipsSchema } from '../block/l2_block_source.js';
|
|
@@ -99,12 +100,12 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
|
|
|
99
100
|
.function()
|
|
100
101
|
.args(CheckpointNumberSchema, schemas.Integer)
|
|
101
102
|
.returns(z.array(PublishedCheckpoint.schema)),
|
|
102
|
-
getCheckpointedBlockByHash: z.function().args(
|
|
103
|
+
getCheckpointedBlockByHash: z.function().args(BlockHash.schema).returns(CheckpointedL2Block.schema.optional()),
|
|
103
104
|
getCheckpointedBlockByArchive: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
|
|
104
|
-
getBlockHeaderByHash: z.function().args(
|
|
105
|
+
getBlockHeaderByHash: z.function().args(BlockHash.schema).returns(BlockHeader.schema.optional()),
|
|
105
106
|
getBlockHeaderByArchive: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
|
|
106
107
|
getL2Block: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
|
|
107
|
-
getL2BlockByHash: z.function().args(
|
|
108
|
+
getL2BlockByHash: z.function().args(BlockHash.schema).returns(L2Block.schema.optional()),
|
|
108
109
|
getL2BlockByArchive: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
|
|
109
110
|
getTxEffect: z.function().args(TxHash.schema).returns(indexedTxSchema().optional()),
|
|
110
111
|
getSettledTxReceipt: z.function().args(TxHash.schema).returns(TxReceipt.schema.optional()),
|