@aztec/stdlib 0.0.1-commit.f650c0a5c → 0.0.1-commit.f7ea82942

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.
Files changed (205) hide show
  1. package/dest/abi/authorization_selector.d.ts +3 -6
  2. package/dest/abi/authorization_selector.d.ts.map +1 -1
  3. package/dest/abi/encoder.d.ts +1 -1
  4. package/dest/abi/encoder.d.ts.map +1 -1
  5. package/dest/abi/encoder.js +32 -6
  6. package/dest/abi/event_selector.d.ts +3 -6
  7. package/dest/abi/event_selector.d.ts.map +1 -1
  8. package/dest/abi/function_selector.d.ts +3 -6
  9. package/dest/abi/function_selector.d.ts.map +1 -1
  10. package/dest/abi/function_selector.js +1 -3
  11. package/dest/abi/note_selector.d.ts +3 -6
  12. package/dest/abi/note_selector.d.ts.map +1 -1
  13. package/dest/abi/note_selector.js +1 -3
  14. package/dest/avm/avm.d.ts +300 -300
  15. package/dest/aztec-address/index.d.ts +3 -6
  16. package/dest/aztec-address/index.d.ts.map +1 -1
  17. package/dest/aztec-address/index.js +2 -4
  18. package/dest/block/block_data.d.ts +8 -8
  19. package/dest/block/block_data.d.ts.map +1 -1
  20. package/dest/block/block_data.js +2 -2
  21. package/dest/block/block_hash.d.ts +11 -10
  22. package/dest/block/block_hash.d.ts.map +1 -1
  23. package/dest/block/block_hash.js +10 -9
  24. package/dest/block/l2_block_info.d.ts +6 -5
  25. package/dest/block/l2_block_info.d.ts.map +1 -1
  26. package/dest/block/l2_block_info.js +6 -5
  27. package/dest/block/l2_block_stream/interfaces.d.ts +6 -3
  28. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  29. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +1 -1
  30. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  31. package/dest/block/l2_block_stream/l2_tips_store_base.js +1 -1
  32. package/dest/block/test/l2_tips_store_test_suite.js +1 -1
  33. package/dest/config/chain-config.d.ts +1 -1
  34. package/dest/config/chain-config.d.ts.map +1 -1
  35. package/dest/config/chain-config.js +7 -1
  36. package/dest/config/sequencer-config.d.ts +2 -2
  37. package/dest/config/sequencer-config.d.ts.map +1 -1
  38. package/dest/config/sequencer-config.js +10 -3
  39. package/dest/contract/private_function.d.ts +1 -1
  40. package/dest/contract/private_function.d.ts.map +1 -1
  41. package/dest/contract/private_function.js +2 -4
  42. package/dest/gas/fee_math.d.ts +49 -0
  43. package/dest/gas/fee_math.d.ts.map +1 -0
  44. package/dest/gas/fee_math.js +80 -0
  45. package/dest/gas/gas_fees.d.ts +5 -1
  46. package/dest/gas/gas_fees.d.ts.map +1 -1
  47. package/dest/gas/gas_fees.js +10 -1
  48. package/dest/gas/index.d.ts +2 -1
  49. package/dest/gas/index.d.ts.map +1 -1
  50. package/dest/gas/index.js +1 -0
  51. package/dest/ha-signing/config.d.ts +6 -6
  52. package/dest/ha-signing/config.d.ts.map +1 -1
  53. package/dest/ha-signing/config.js +4 -3
  54. package/dest/ha-signing/index.d.ts +2 -2
  55. package/dest/ha-signing/index.d.ts.map +1 -1
  56. package/dest/ha-signing/index.js +1 -1
  57. package/dest/ha-signing/local_config.js +1 -1
  58. package/dest/ha-signing/types.d.ts +37 -32
  59. package/dest/ha-signing/types.d.ts.map +1 -1
  60. package/dest/ha-signing/types.js +13 -6
  61. package/dest/hash/hash.d.ts +16 -1
  62. package/dest/hash/hash.d.ts.map +1 -1
  63. package/dest/hash/hash.js +32 -0
  64. package/dest/interfaces/archiver.d.ts +11 -1
  65. package/dest/interfaces/archiver.d.ts.map +1 -1
  66. package/dest/interfaces/archiver.js +3 -1
  67. package/dest/interfaces/aztec-node-admin.d.ts +6 -4
  68. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  69. package/dest/interfaces/aztec-node-debug.d.ts +21 -0
  70. package/dest/interfaces/aztec-node-debug.d.ts.map +1 -0
  71. package/dest/interfaces/aztec-node-debug.js +18 -0
  72. package/dest/interfaces/aztec-node.d.ts +10 -1
  73. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  74. package/dest/interfaces/aztec-node.js +2 -0
  75. package/dest/interfaces/client.d.ts +2 -1
  76. package/dest/interfaces/client.d.ts.map +1 -1
  77. package/dest/interfaces/client.js +1 -0
  78. package/dest/interfaces/merkle_tree_operations.d.ts +4 -3
  79. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  80. package/dest/interfaces/prover-client.d.ts +1 -1
  81. package/dest/interfaces/prover-client.d.ts.map +1 -1
  82. package/dest/interfaces/prover-client.js +0 -3
  83. package/dest/interfaces/proving-job.d.ts +166 -166
  84. package/dest/interfaces/validator.d.ts +13 -13
  85. package/dest/interfaces/validator.d.ts.map +1 -1
  86. package/dest/logs/log_id.d.ts +1 -1
  87. package/dest/logs/log_id.d.ts.map +1 -1
  88. package/dest/logs/log_id.js +1 -2
  89. package/dest/logs/siloed_tag.d.ts +5 -7
  90. package/dest/logs/siloed_tag.d.ts.map +1 -1
  91. package/dest/logs/siloed_tag.js +4 -0
  92. package/dest/logs/tag.d.ts +5 -6
  93. package/dest/logs/tag.d.ts.map +1 -1
  94. package/dest/logs/tag.js +4 -0
  95. package/dest/p2p/block_proposal.d.ts +6 -8
  96. package/dest/p2p/block_proposal.d.ts.map +1 -1
  97. package/dest/p2p/block_proposal.js +4 -9
  98. package/dest/p2p/checkpoint_attestation.d.ts +4 -6
  99. package/dest/p2p/checkpoint_attestation.d.ts.map +1 -1
  100. package/dest/p2p/checkpoint_attestation.js +2 -7
  101. package/dest/p2p/checkpoint_proposal.d.ts +8 -10
  102. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  103. package/dest/p2p/checkpoint_proposal.js +4 -11
  104. package/dest/p2p/gossipable.d.ts +4 -4
  105. package/dest/p2p/gossipable.d.ts.map +1 -1
  106. package/dest/rollup/block_headers_hash.d.ts +1 -1
  107. package/dest/rollup/block_headers_hash.d.ts.map +1 -1
  108. package/dest/rollup/block_headers_hash.js +8 -2
  109. package/dest/tests/factories.d.ts +2 -7
  110. package/dest/tests/factories.d.ts.map +1 -1
  111. package/dest/tests/factories.js +1 -7
  112. package/dest/tests/mocks.d.ts +1 -1
  113. package/dest/tests/mocks.d.ts.map +1 -1
  114. package/dest/tests/mocks.js +2 -2
  115. package/dest/timetable/index.d.ts +50 -1
  116. package/dest/timetable/index.d.ts.map +1 -1
  117. package/dest/timetable/index.js +204 -18
  118. package/dest/trees/nullifier_leaf.d.ts +2 -1
  119. package/dest/trees/nullifier_leaf.d.ts.map +1 -1
  120. package/dest/trees/nullifier_leaf.js +3 -0
  121. package/dest/tx/block_header.d.ts +2 -2
  122. package/dest/tx/block_header.d.ts.map +1 -1
  123. package/dest/tx/block_header.js +1 -1
  124. package/dest/tx/fee_provider.d.ts +10 -0
  125. package/dest/tx/fee_provider.d.ts.map +1 -0
  126. package/dest/tx/fee_provider.js +1 -0
  127. package/dest/tx/global_variable_builder.d.ts +3 -16
  128. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  129. package/dest/tx/index.d.ts +2 -1
  130. package/dest/tx/index.d.ts.map +1 -1
  131. package/dest/tx/index.js +1 -0
  132. package/dest/tx/indexed_tx_effect.d.ts +1 -1
  133. package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
  134. package/dest/tx/indexed_tx_effect.js +1 -2
  135. package/dest/tx/simulated_tx.d.ts +1 -1
  136. package/dest/tx/simulated_tx.js +1 -1
  137. package/dest/tx/tx.d.ts +3 -3
  138. package/dest/tx/tx.d.ts.map +1 -1
  139. package/dest/types/shared.d.ts +1 -10
  140. package/dest/types/shared.d.ts.map +1 -1
  141. package/dest/types/shared.js +0 -9
  142. package/dest/vks/verification_key.d.ts +2 -137
  143. package/dest/vks/verification_key.d.ts.map +1 -1
  144. package/dest/vks/verification_key.js +5 -126
  145. package/dest/world-state/world_state_revision.d.ts +8 -1
  146. package/dest/world-state/world_state_revision.d.ts.map +1 -1
  147. package/dest/world-state/world_state_revision.js +7 -1
  148. package/package.json +8 -8
  149. package/src/abi/authorization_selector.ts +2 -8
  150. package/src/abi/encoder.ts +42 -6
  151. package/src/abi/event_selector.ts +2 -8
  152. package/src/abi/function_selector.ts +3 -12
  153. package/src/abi/note_selector.ts +3 -12
  154. package/src/aztec-address/index.ts +4 -10
  155. package/src/block/block_data.ts +3 -4
  156. package/src/block/block_hash.ts +21 -14
  157. package/src/block/l2_block_info.ts +8 -6
  158. package/src/block/l2_block_stream/interfaces.ts +6 -2
  159. package/src/block/l2_block_stream/l2_tips_store_base.ts +1 -1
  160. package/src/block/test/l2_tips_store_test_suite.ts +1 -1
  161. package/src/config/chain-config.ts +7 -1
  162. package/src/config/sequencer-config.ts +14 -4
  163. package/src/contract/private_function.ts +3 -1
  164. package/src/gas/README.md +31 -0
  165. package/src/gas/fee_math.ts +120 -0
  166. package/src/gas/gas_fees.ts +17 -4
  167. package/src/gas/index.ts +1 -0
  168. package/src/ha-signing/config.ts +5 -2
  169. package/src/ha-signing/index.ts +3 -1
  170. package/src/ha-signing/local_config.ts +1 -1
  171. package/src/ha-signing/types.ts +48 -34
  172. package/src/hash/hash.ts +27 -0
  173. package/src/interfaces/archiver.ts +8 -0
  174. package/src/interfaces/aztec-node-debug.ts +40 -0
  175. package/src/interfaces/aztec-node.ts +15 -0
  176. package/src/interfaces/client.ts +1 -0
  177. package/src/interfaces/merkle_tree_operations.ts +3 -2
  178. package/src/interfaces/prover-client.ts +2 -5
  179. package/src/interfaces/validator.ts +14 -4
  180. package/src/logs/log_id.ts +1 -2
  181. package/src/logs/siloed_tag.ts +8 -9
  182. package/src/logs/tag.ts +8 -8
  183. package/src/p2p/block_proposal.ts +13 -9
  184. package/src/p2p/checkpoint_attestation.ts +5 -9
  185. package/src/p2p/checkpoint_proposal.ts +12 -11
  186. package/src/p2p/gossipable.ts +4 -4
  187. package/src/rollup/block_headers_hash.ts +11 -2
  188. package/src/tests/factories.ts +1 -9
  189. package/src/tests/mocks.ts +2 -0
  190. package/src/timetable/index.ts +291 -16
  191. package/src/trees/nullifier_leaf.ts +4 -0
  192. package/src/tx/block_header.ts +2 -2
  193. package/src/tx/fee_provider.ts +10 -0
  194. package/src/tx/global_variable_builder.ts +2 -18
  195. package/src/tx/index.ts +1 -0
  196. package/src/tx/indexed_tx_effect.ts +1 -2
  197. package/src/tx/simulated_tx.ts +1 -1
  198. package/src/tx/tx.ts +2 -2
  199. package/src/types/shared.ts +0 -10
  200. package/src/vks/verification_key.ts +5 -184
  201. package/src/world-state/world_state_revision.ts +9 -1
  202. package/dest/abi/mocked_keys.d.ts +0 -2
  203. package/dest/abi/mocked_keys.d.ts.map +0 -1
  204. package/dest/abi/mocked_keys.js +0 -1
  205. package/src/abi/mocked_keys.ts +0 -2
@@ -1,18 +1,17 @@
1
1
  import { CheckpointNumberSchema, IndexWithinCheckpointSchema } from '@aztec/foundation/branded-types';
2
2
  import type { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
3
- import type { Fr } from '@aztec/foundation/curves/bn254';
4
- import { schemas } from '@aztec/foundation/schemas';
5
3
 
6
4
  import { z } from 'zod';
7
5
 
8
6
  import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
9
7
  import { BlockHeader } from '../tx/block_header.js';
8
+ import { BlockHash } from './block_hash.js';
10
9
 
11
10
  /** L2Block metadata. Equivalent to L2Block but without block body containing tx data. */
12
11
  export type BlockData = {
13
12
  header: BlockHeader;
14
13
  archive: AppendOnlyTreeSnapshot;
15
- blockHash: Fr;
14
+ blockHash: BlockHash;
16
15
  checkpointNumber: CheckpointNumber;
17
16
  indexWithinCheckpoint: IndexWithinCheckpoint;
18
17
  };
@@ -20,7 +19,7 @@ export type BlockData = {
20
19
  export const BlockDataSchema = z.object({
21
20
  header: BlockHeader.schema,
22
21
  archive: AppendOnlyTreeSnapshot.schema,
23
- blockHash: schemas.Fr,
22
+ blockHash: BlockHash.schema,
24
23
  checkpointNumber: CheckpointNumberSchema,
25
24
  indexWithinCheckpoint: IndexWithinCheckpointSchema,
26
25
  });
@@ -1,21 +1,24 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
1
+ import { GENESIS_BLOCK_HEADER_HASH as GENESIS_BLOCK_HEADER_HASH_FR } from '@aztec/constants';
2
+ import { BaseFr, Fr } from '@aztec/foundation/curves/bn254';
2
3
  import type { ZodFor } from '@aztec/foundation/schemas';
4
+ import type { BufferReader } from '@aztec/foundation/serialize';
3
5
 
4
6
  import { inspect } from 'util';
5
7
 
6
8
  import { hexSchemaFor } from '../schemas/schemas.js';
7
9
 
8
- const BLOCK_HASH_BRAND = Symbol.for('aztec.BlockHash');
9
-
10
10
  /** Hash of an L2 block. */
11
- export class BlockHash extends Fr {
12
- readonly [BLOCK_HASH_BRAND] = true as const;
11
+ export class BlockHash extends BaseFr {
12
+ /** Branding for nominal typing. */
13
+ declare private readonly _branding: 'BlockHash';
14
+
15
+ static ZERO = new BlockHash(Fr.ZERO);
13
16
 
14
17
  constructor(hash: Fr) {
15
18
  super(hash);
16
19
  }
17
20
 
18
- override [inspect.custom]() {
21
+ [inspect.custom]() {
19
22
  return `BlockHash<${this.toString()}>`;
20
23
  }
21
24
 
@@ -23,23 +26,27 @@ export class BlockHash extends Fr {
23
26
  return new Fr(this.toBigInt());
24
27
  }
25
28
 
26
- /**
27
- * Type guard that checks if a value is a BlockHash instance.
28
- * Uses Symbol.for to ensure cross-module compatibility.
29
- */
29
+ /** Type guard that checks if a value is a BlockHash instance. */
30
30
  static isBlockHash(value: unknown): value is BlockHash {
31
- return typeof value === 'object' && value !== null && BLOCK_HASH_BRAND in value;
31
+ return value instanceof BlockHash;
32
32
  }
33
33
 
34
- static override random() {
34
+ static random() {
35
35
  return new BlockHash(Fr.random());
36
36
  }
37
37
 
38
- static override fromString(str: string): BlockHash {
38
+ static fromBuffer(buffer: Buffer | BufferReader): BlockHash {
39
+ return new BlockHash(Fr.fromBuffer(buffer));
40
+ }
41
+
42
+ static fromString(str: string): BlockHash {
39
43
  return new BlockHash(Fr.fromString(str));
40
44
  }
41
45
 
42
- static override get schema() {
46
+ static get schema() {
43
47
  return hexSchemaFor(BlockHash) as ZodFor<BlockHash>;
44
48
  }
45
49
  }
50
+
51
+ /** The block header hash for the genesis block (block 0). */
52
+ export const GENESIS_BLOCK_HEADER_HASH: BlockHash = new BlockHash(GENESIS_BLOCK_HEADER_HASH_FR);
@@ -5,8 +5,10 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
5
 
6
6
  import { z } from 'zod';
7
7
 
8
+ import { BlockHash } from './block_hash.js';
9
+
8
10
  export type L2BlockInfo = {
9
- blockHash?: Fr;
11
+ blockHash?: BlockHash;
10
12
  archive: Fr;
11
13
  lastArchive: Fr;
12
14
  blockNumber: BlockNumber;
@@ -17,7 +19,7 @@ export type L2BlockInfo = {
17
19
 
18
20
  export function randomBlockInfo(blockNumber?: BlockNumber | number): L2BlockInfo {
19
21
  return {
20
- blockHash: Fr.random(),
22
+ blockHash: BlockHash.random(),
21
23
  archive: Fr.random(),
22
24
  lastArchive: Fr.random(),
23
25
  blockNumber: BlockNumber(blockNumber ?? Math.floor(Math.random() * 100000) + 1),
@@ -28,7 +30,7 @@ export function randomBlockInfo(blockNumber?: BlockNumber | number): L2BlockInfo
28
30
  }
29
31
 
30
32
  export const BlockInfoSchema = z.object({
31
- blockHash: schemas.Fr.optional(),
33
+ blockHash: BlockHash.schema.optional(),
32
34
  archive: schemas.Fr,
33
35
  lastArchive: schemas.Fr,
34
36
  blockNumber: BlockNumberSchema,
@@ -39,7 +41,7 @@ export const BlockInfoSchema = z.object({
39
41
 
40
42
  export function serializeBlockInfo(blockInfo: L2BlockInfo): Buffer {
41
43
  return serializeToBuffer(
42
- blockInfo.blockHash ?? Fr.ZERO,
44
+ blockInfo.blockHash ?? BlockHash.ZERO,
43
45
  blockInfo.archive,
44
46
  blockInfo.lastArchive,
45
47
  blockInfo.blockNumber,
@@ -51,9 +53,9 @@ export function serializeBlockInfo(blockInfo: L2BlockInfo): Buffer {
51
53
 
52
54
  export function deserializeBlockInfo(buffer: Buffer | BufferReader): L2BlockInfo {
53
55
  const reader = BufferReader.asReader(buffer);
54
- const blockHash = reader.readObject(Fr);
56
+ const blockHash = BlockHash.fromBuffer(reader);
55
57
  return {
56
- blockHash: blockHash.equals(Fr.ZERO) ? undefined : blockHash,
58
+ blockHash: blockHash.equals(BlockHash.ZERO) ? undefined : blockHash,
57
59
  archive: reader.readObject(Fr),
58
60
  lastArchive: reader.readObject(Fr),
59
61
  blockNumber: BlockNumber(reader.readNumber()),
@@ -2,10 +2,14 @@ import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.
2
2
  import type { L2Block } from '../l2_block.js';
3
3
  import type { CheckpointId, L2BlockId, L2Tips } from '../l2_block_source.js';
4
4
 
5
+ /** Provides the current chain tips. Implemented by world-state, l2-tips-store, and AztecNode. */
6
+ export interface L2TipsProvider {
7
+ getL2Tips(): Promise<L2Tips>;
8
+ }
9
+
5
10
  /** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
6
- export interface L2BlockStreamLocalDataProvider {
11
+ export interface L2BlockStreamLocalDataProvider extends L2TipsProvider {
7
12
  getL2BlockHash(number: number): Promise<string | undefined>;
8
- getL2Tips(): Promise<L2Tips>;
9
13
  }
10
14
 
11
15
  /** Interface to a handler of events emitted. */
@@ -1,7 +1,7 @@
1
- import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
1
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
2
 
4
3
  import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
4
+ import { GENESIS_BLOCK_HEADER_HASH } from '../block_hash.js';
5
5
  import type { L2Block } from '../l2_block.js';
6
6
  import {
7
7
  type CheckpointId,
@@ -1,4 +1,3 @@
1
- import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
1
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
2
  import { times } from '@aztec/foundation/collection';
4
3
  import { Fr } from '@aztec/foundation/curves/bn254';
@@ -13,6 +12,7 @@ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/
13
12
 
14
13
  import { jestExpect as expect } from '@jest/expect';
15
14
 
15
+ import { GENESIS_BLOCK_HEADER_HASH } from '../block_hash.js';
16
16
  import type { L2TipsStore } from '../l2_block_stream/index.js';
17
17
 
18
18
  export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
@@ -21,7 +21,13 @@ export const chainConfigMappings: ConfigMappingsType<ChainConfig> = {
21
21
  rollupVersion: {
22
22
  env: 'ROLLUP_VERSION',
23
23
  description: 'The version of the rollup.',
24
- parseEnv: (val: string) => (Number.isSafeInteger(parseInt(val, 10)) ? parseInt(val, 10) : undefined),
24
+ parseEnv: (val: string) => {
25
+ const parsed = parseInt(val, 10);
26
+ if (!Number.isSafeInteger(parsed)) {
27
+ throw new Error(`Invalid rollup version: ${val}`);
28
+ }
29
+ return parsed;
30
+ },
25
31
  },
26
32
  l1Contracts: {
27
33
  description: 'The deployed L1 contract addresses',
@@ -1,6 +1,7 @@
1
1
  import type { ConfigMappingsType } from '@aztec/foundation/config';
2
2
 
3
3
  import type { SequencerConfig } from '../interfaces/configs.js';
4
+ import { DEFAULT_P2P_PROPAGATION_TIME } from '../timetable/index.js';
4
5
 
5
6
  /** Default maximum number of transactions per block. */
6
7
  export const DEFAULT_MAX_TXS_PER_BLOCK = 32;
@@ -12,26 +13,35 @@ export const DEFAULT_MAX_TXS_PER_BLOCK = 32;
12
13
  * to avoid duplication.
13
14
  */
14
15
  export const sharedSequencerConfigMappings: ConfigMappingsType<
15
- Pick<SequencerConfig, 'blockDurationMs' | 'expectedBlockProposalsPerSlot' | 'maxTxsPerBlock'>
16
+ Pick<
17
+ SequencerConfig,
18
+ 'blockDurationMs' | 'expectedBlockProposalsPerSlot' | 'maxTxsPerBlock' | 'attestationPropagationTime'
19
+ >
16
20
  > = {
17
21
  blockDurationMs: {
18
22
  env: 'SEQ_BLOCK_DURATION_MS',
19
23
  description:
20
24
  'Duration per block in milliseconds when building multiple blocks per slot. ' +
21
25
  'If undefined (default), builds a single block per slot using the full slot duration.',
22
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
26
+ parseEnv: (val: string) => parseInt(val, 10),
23
27
  },
24
28
  expectedBlockProposalsPerSlot: {
25
29
  env: 'SEQ_EXPECTED_BLOCK_PROPOSALS_PER_SLOT',
26
30
  description:
27
31
  'Expected number of block proposals per slot for P2P peer scoring. ' +
28
32
  '0 (default) disables block proposal scoring. Set to a positive value to enable.',
29
- parseEnv: (val: string) => (val ? parseInt(val, 10) : 0),
33
+ parseEnv: (val: string) => parseInt(val, 10),
30
34
  defaultValue: 0,
31
35
  },
32
36
  maxTxsPerBlock: {
33
37
  env: 'SEQ_MAX_TX_PER_BLOCK',
34
38
  description: 'The maximum number of txs to include in a block.',
35
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
39
+ parseEnv: (val: string) => parseInt(val, 10),
40
+ },
41
+ attestationPropagationTime: {
42
+ env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
43
+ description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way).',
44
+ parseEnv: (val: string) => parseFloat(val),
45
+ defaultValue: DEFAULT_P2P_PROPAGATION_TIME,
36
46
  },
37
47
  };
@@ -3,6 +3,7 @@ import { poseidon2Hash, poseidon2HashWithSeparator } from '@aztec/foundation/cry
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { type MerkleTree, MerkleTreeCalculator } from '@aztec/foundation/trees';
5
5
 
6
+ import { computeMerkleHash } from '../hash/hash.js';
6
7
  import type { PrivateFunction } from './interfaces/contract_class.js';
7
8
 
8
9
  // Memoize the merkle tree calculators to avoid re-computing the zero-hash for each level in each call
@@ -42,7 +43,8 @@ async function getPrivateFunctionTreeCalculator(): Promise<MerkleTreeCalculator>
42
43
  privateFunctionTreeCalculator = await MerkleTreeCalculator.create(
43
44
  FUNCTION_TREE_HEIGHT,
44
45
  functionTreeZeroLeaf,
45
- async (left, right) => (await poseidon2Hash([left, right])).toBuffer() as Buffer<ArrayBuffer>,
46
+ async (left, right) =>
47
+ (await computeMerkleHash(Fr.fromBuffer(left), Fr.fromBuffer(right))).toBuffer() as Buffer<ArrayBuffer>,
46
48
  );
47
49
  }
48
50
  return privateFunctionTreeCalculator;
package/src/gas/README.md CHANGED
@@ -84,6 +84,37 @@ else → use post (new fees)
84
84
  **Net effect**: L1 fee changes reach L2 with a 2-slot delay and can update at most once
85
85
  every 5 slots.
86
86
 
87
+ ### Worked Example
88
+
89
+ Suppose the oracle is updated at slot 10 with new L1 fees. Here is the timeline:
90
+
91
+ ```
92
+ Slot Oracle state Active fees Notes
93
+ ──── ──────────────────── ──────────── ──────────────────────────────────
94
+ 10 pre=A, post=B, soc=12 A Update queued. slotOfChange = 10 + LAG = 12.
95
+ 11 (same) A Still before slotOfChange → pre (A).
96
+ 12 (same) B slot >= slotOfChange → post (B) activates.
97
+ 13 (same) B B remains active.
98
+ 14 (same) B B remains active.
99
+ 15 Update allowed again B Earliest next update: soc + (LIFETIME - LAG)
100
+ = 12 + 3 = 15.
101
+ ```
102
+
103
+ Key observations:
104
+
105
+ 1. **Slots 10-11**: The old fees (A) are still in effect. Transactions submitted during
106
+ these slots see the old L1 cost. This is the **LAG** window — it gives pending
107
+ transactions 2 slots to land before fees change.
108
+
109
+ 2. **Slot 12**: The new fees (B) activate. Any checkpoint proposed at slot >= 12 uses B
110
+ for its sequencer/prover cost calculation.
111
+
112
+ 3. **Slots 12-14**: No new oracle update is accepted. The system is in a **cooldown**
113
+ period of `LIFETIME - LAG = 3` slots after the transition.
114
+
115
+ 4. **Slot 15**: A new oracle update can be queued (earliest `acceptableSlot`). If
116
+ triggered, the new values would activate at slot 15 + LAG = 17.
117
+
87
118
  ## Fee Asset Price
88
119
 
89
120
  Fees are computed in ETH internally but converted to the fee asset (Fee Juice) via
@@ -0,0 +1,120 @@
1
+ /**
2
+ * TypeScript port of fee computation logic from FeeLib.sol.
3
+ * Used to predict worst-case min fees over a future window of L2 slots.
4
+ */
5
+
6
+ // Constants matching FeeLib.sol
7
+ export const MINIMUM_CONGESTION_MULTIPLIER = 1_000_000_000n;
8
+ export const L1_GAS_PER_CHECKPOINT_PROPOSED = 300_000n;
9
+ export const L1_GAS_PER_EPOCH_VERIFIED = 3_600_000n;
10
+ export const BLOBS_PER_CHECKPOINT = 3n;
11
+ export const BLOB_GAS_PER_BLOB = 2n ** 17n;
12
+ export const MAGIC_CONGESTION_VALUE_MULTIPLIER = 854_700_854n;
13
+ export const MAGIC_CONGESTION_VALUE_DIVISOR = 100_000_000n;
14
+ export const ETH_PER_FEE_ASSET_PRECISION = 1_000_000_000_000n;
15
+ export const MIN_ETH_PER_FEE_ASSET = 100n;
16
+
17
+ /** Number of L2 slots of lag before new oracle values activate. Defines the prediction window. */
18
+ export const FEE_ORACLE_LAG = 2;
19
+
20
+ /** Expected mana usage per checkpoint for fee prediction. */
21
+ export enum ManaUsageEstimate {
22
+ /** No usage — fees decrease as congestion drains. */
23
+ None = 'none',
24
+ /** Target usage — congestion stays roughly flat (steady state). */
25
+ Target = 'target',
26
+ /** Limit usage (2x target) — worst case, congestion grows maximally. */
27
+ Limit = 'limit',
28
+ }
29
+
30
+ /** Parameters for computing the mana min fee at a given point in time. */
31
+ export type ManaMinFeeParams = {
32
+ l1BaseFee: bigint;
33
+ l1BlobFee: bigint;
34
+ manaTarget: bigint;
35
+ epochDuration: bigint;
36
+ provingCostPerManaEth: bigint;
37
+ excessMana: bigint;
38
+ ethPerFeeAsset: bigint;
39
+ };
40
+
41
+ /**
42
+ * Taylor series approximation of `factor * e^(numerator/denominator)`.
43
+ * Direct port of FeeLib.sol fakeExponential (EIP-4844 style).
44
+ */
45
+ export function fakeExponential(factor: bigint, numerator: bigint, denominator: bigint): bigint {
46
+ let i = 1n;
47
+ let output = 0n;
48
+ let numeratorAccumulator = factor * denominator;
49
+ while (numeratorAccumulator > 0n) {
50
+ output += numeratorAccumulator;
51
+ numeratorAccumulator = (numeratorAccumulator * numerator) / (denominator * i);
52
+ i += 1n;
53
+ }
54
+ return output / denominator;
55
+ }
56
+
57
+ /** Computes excess mana for the next checkpoint, clamped to zero. */
58
+ export function computeExcessMana(prevExcessMana: bigint, prevManaUsed: bigint, manaTarget: bigint): bigint {
59
+ const sum = prevExcessMana + prevManaUsed;
60
+ return sum > manaTarget ? sum - manaTarget : 0n;
61
+ }
62
+
63
+ /** Computes the congestion multiplier from excess mana (1e9 = no congestion). */
64
+ export function computeCongestionMultiplier(excessMana: bigint, manaTarget: bigint): bigint {
65
+ const denominator = (manaTarget * MAGIC_CONGESTION_VALUE_MULTIPLIER) / MAGIC_CONGESTION_VALUE_DIVISOR;
66
+ const cappedNumerator = excessMana < denominator * 100n ? excessMana : denominator * 100n;
67
+ return fakeExponential(MINIMUM_CONGESTION_MULTIPLIER, cappedNumerator, denominator);
68
+ }
69
+
70
+ /** Ceiling division for positive bigints. */
71
+ function ceilDiv(a: bigint, b: bigint): bigint {
72
+ return (a + b - 1n) / b;
73
+ }
74
+
75
+ /** Converts an ETH value to fee asset value using ethPerFeeAsset (1e12 precision). */
76
+ function toFeeAsset(ethValue: bigint, ethPerFeeAsset: bigint): bigint {
77
+ if (ethPerFeeAsset === 0n) {
78
+ return 0n;
79
+ }
80
+ return ceilDiv(ethValue * ETH_PER_FEE_ASSET_PRECISION, ethPerFeeAsset);
81
+ }
82
+
83
+ /**
84
+ * Computes the full mana min fee (sequencer + prover + congestion) in fee asset terms.
85
+ * Mirrors FeeLib.getManaMinFeeComponentsAt + summedMinFee.
86
+ */
87
+ export function computeManaMinFee(params: ManaMinFeeParams): bigint {
88
+ const { l1BaseFee, l1BlobFee, manaTarget, epochDuration, provingCostPerManaEth, excessMana, ethPerFeeAsset } = params;
89
+
90
+ if (manaTarget === 0n) {
91
+ return 0n;
92
+ }
93
+
94
+ // Sequencer cost per mana (in ETH)
95
+ const ethUsed = L1_GAS_PER_CHECKPOINT_PROPOSED * l1BaseFee + BLOBS_PER_CHECKPOINT * BLOB_GAS_PER_BLOB * l1BlobFee;
96
+ const sequencerCostEth = ceilDiv(ethUsed, manaTarget);
97
+
98
+ // Prover cost per mana (in ETH): L1 verification gas + governance-set proving cost
99
+ const proverCostEth =
100
+ ceilDiv(ceilDiv(L1_GAS_PER_EPOCH_VERIFIED * l1BaseFee, epochDuration), manaTarget) + provingCostPerManaEth;
101
+
102
+ // Total base cost in ETH (congestion is computed on this)
103
+ const totalEth = sequencerCostEth + proverCostEth;
104
+
105
+ // Congestion multiplier and cost (in ETH)
106
+ const congestionMul = computeCongestionMultiplier(excessMana, manaTarget);
107
+ const congestionCostEth = (totalEth * congestionMul) / MINIMUM_CONGESTION_MULTIPLIER - totalEth;
108
+
109
+ // Convert all components to fee asset
110
+ const clampedEthPerFeeAsset = ethPerFeeAsset < MIN_ETH_PER_FEE_ASSET ? MIN_ETH_PER_FEE_ASSET : ethPerFeeAsset;
111
+ const sequencerCost = toFeeAsset(sequencerCostEth, clampedEthPerFeeAsset);
112
+ const proverCost = toFeeAsset(proverCostEth, clampedEthPerFeeAsset);
113
+ const congestionCost = toFeeAsset(congestionCostEth, clampedEthPerFeeAsset);
114
+
115
+ const total = sequencerCost + proverCost + congestionCost;
116
+
117
+ // Cap at uint128 max (matching FeeLib.summedMinFee)
118
+ const UINT128_MAX = (1n << 128n) - 1n;
119
+ return total < UINT128_MAX ? total : UINT128_MAX;
120
+ }
@@ -15,6 +15,17 @@ import { z } from 'zod';
15
15
  import type { UInt128 } from '../types/shared.js';
16
16
  import type { GasDimensions } from './gas.js';
17
17
 
18
+ /**
19
+ * Multiplies a bigint by a non-integer scalar and returns the ceiling of the result.
20
+ * Avoids converting the bigint to Number (which loses precision above 2^53) by instead
21
+ * scaling the scalar into a bigint rational and performing ceiling division.
22
+ */
23
+ function bigintMulCeil(value: bigint, scalar: number): bigint {
24
+ const SCALE = 1_000_000_000_000n; // 1e12
25
+ const scaledScalar = BigInt(Math.round(scalar * 1e12));
26
+ return (value * scaledScalar + SCALE - 1n) / SCALE;
27
+ }
28
+
18
29
  /** Gas prices for each dimension. */
19
30
  export class GasFees {
20
31
  public readonly feePerDaGas: UInt128;
@@ -60,10 +71,7 @@ export class GasFees {
60
71
  const s = BigInt(scalar);
61
72
  return new GasFees(this.feePerDaGas * s, this.feePerL2Gas * s);
62
73
  } else {
63
- return new GasFees(
64
- BigInt(Math.ceil(Number(this.feePerDaGas) * scalar)),
65
- BigInt(Math.ceil(Number(this.feePerL2Gas) * scalar)),
66
- );
74
+ return new GasFees(bigintMulCeil(this.feePerDaGas, scalar), bigintMulCeil(this.feePerL2Gas, scalar));
67
75
  }
68
76
  }
69
77
 
@@ -126,3 +134,8 @@ export class GasFees {
126
134
  return `GasFees { feePerDaGas=${this.feePerDaGas} feePerL2Gas=${this.feePerL2Gas} }`;
127
135
  }
128
136
  }
137
+
138
+ /** Provides projected minimum gas fees for the next block. */
139
+ export interface BlockMinFeesProvider {
140
+ getCurrentMinFees(): Promise<GasFees>;
141
+ }
package/src/gas/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './fee_math.js';
1
2
  export * from './gas.js';
2
3
  export * from './gas_fees.js';
3
4
  export * from './gas_settings.js';
@@ -1,11 +1,13 @@
1
1
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
2
2
  import {
3
3
  type ConfigMappingsType,
4
+ SecretValue,
4
5
  booleanConfigHelper,
5
6
  getConfigFromMappings,
6
7
  getDefaultConfig,
7
8
  numberConfigHelper,
8
9
  optionalNumberConfigHelper,
10
+ secretStringConfigHelper,
9
11
  } from '@aztec/foundation/config';
10
12
  import { EthAddress } from '@aztec/foundation/eth-address';
11
13
  import type { ZodFor } from '@aztec/foundation/schemas';
@@ -88,7 +90,7 @@ export interface ValidatorHASignerConfig extends BaseSignerConfig {
88
90
  * PostgreSQL connection string
89
91
  * Format: postgresql://user:password@host:port/database
90
92
  */
91
- databaseUrl?: string;
93
+ databaseUrl?: SecretValue<string>;
92
94
  /** Maximum number of clients in the pool (default: 10) */
93
95
  poolMaxCount?: number;
94
96
  /** Minimum number of clients in the pool (default: 0) */
@@ -110,6 +112,7 @@ export const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASign
110
112
  env: 'VALIDATOR_HA_DATABASE_URL',
111
113
  description:
112
114
  'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)',
115
+ ...secretStringConfigHelper(),
113
116
  },
114
117
  poolMaxCount: {
115
118
  env: 'VALIDATOR_HA_POOL_MAX',
@@ -148,7 +151,7 @@ export function getConfigEnvVars(): ValidatorHASignerConfig {
148
151
 
149
152
  export const ValidatorHASignerConfigSchema = BaseSignerConfigSchema.extend({
150
153
  haSigningEnabled: z.boolean(),
151
- databaseUrl: z.string().optional(),
154
+ databaseUrl: SecretValue.schema(z.string()).optional(),
152
155
  poolMaxCount: z.number().min(0).optional(),
153
156
  poolMinCount: z.number().min(0).optional(),
154
157
  poolIdleTimeoutMs: z.number().min(0).optional(),
@@ -16,12 +16,14 @@ export {
16
16
  } from './local_config.js';
17
17
  export {
18
18
  DutyType,
19
+ type AttestationSigningContext,
19
20
  type BlockProposalSigningContext,
21
+ type CheckpointProposalSigningContext,
20
22
  type HAProtectedSigningContext,
21
23
  type NoHAProtectionSigningContext,
22
- type OtherSigningContext,
23
24
  type SigningContext,
24
25
  type VoteSigningContext,
25
26
  getBlockNumberFromSigningContext,
27
+ getCheckpointNumberFromSigningContext,
26
28
  isHAProtectedContext,
27
29
  } from './types.js';
@@ -26,7 +26,7 @@ export const localSignerConfigMappings: ConfigMappingsType<LocalSignerConfig> =
26
26
  env: 'SIGNING_PROTECTION_MAP_SIZE_KB',
27
27
  description:
28
28
  'Maximum size of the local signing-protection LMDB store in KB. Overwrites the general dataStoreMapSizeKb.',
29
- parseEnv: (val: string | undefined) => (val ? +val : undefined),
29
+ parseEnv: (val: string) => +val,
30
30
  },
31
31
  };
32
32