@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,5 +1,7 @@
1
+ import { DomainSeparator } from '@aztec/constants';
2
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
1
3
  import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { computeUnbalancedPoseidonRoot } from '@aztec/foundation/trees';
4
+ import { computeUnbalancedMerkleTreeRootAsync } from '@aztec/foundation/trees';
3
5
 
4
6
  import type { BlockHeader } from '../tx/block_header.js';
5
7
 
@@ -7,6 +9,13 @@ export async function computeBlockHeadersHash(blockHeaders: BlockHeader[]): Prom
7
9
  const blockHeaderHashes = await Promise.all(blockHeaders.map(header => header.hash()));
8
10
  // Must match the implementation in merge_block_rollups.nr, with the **unbalanced** rollup structure
9
11
  // (see validate_consecutive_block_rollups.nr > assert_rollups_filled_greedily.nr).
10
- const blockHeadersHash = await computeUnbalancedPoseidonRoot(blockHeaderHashes.map(hash => hash.toBuffer()));
12
+ const blockHeadersHasher = async (left: Uint8Array, right: Uint8Array) =>
13
+ (
14
+ await poseidon2HashWithSeparator([Buffer.from(left), Buffer.from(right)], DomainSeparator.BLOCK_HEADERS_HASH)
15
+ ).toBuffer() as Buffer<ArrayBuffer>;
16
+ const blockHeadersHash = await computeUnbalancedMerkleTreeRootAsync(
17
+ blockHeaderHashes.map(hash => hash.toBuffer()),
18
+ blockHeadersHasher,
19
+ );
11
20
  return Fr.fromBuffer(blockHeadersHash);
12
21
  }
@@ -176,7 +176,7 @@ import { TxHash } from '../tx/tx_hash.js';
176
176
  import { TxRequest } from '../tx/tx_request.js';
177
177
  import { Vector } from '../types/index.js';
178
178
  import { VkData } from '../vks/index.js';
179
- import { VerificationKey, VerificationKeyAsFields, VerificationKeyData } from '../vks/verification_key.js';
179
+ import { VerificationKeyAsFields, VerificationKeyData } from '../vks/verification_key.js';
180
180
 
181
181
  /**
182
182
  * Creates an arbitrary side effect object with the given seed.
@@ -573,14 +573,6 @@ export function makeVerificationKeyAsFields(size: number): VerificationKeyAsFiel
573
573
  return VerificationKeyAsFields.makeFake(size);
574
574
  }
575
575
 
576
- /**
577
- * Creates arbitrary/mocked verification key.
578
- * @returns A verification key object
579
- */
580
- export function makeVerificationKey(): VerificationKey {
581
- return VerificationKey.makeFake();
582
- }
583
-
584
576
  /**
585
577
  * Creates an arbitrary point in a curve.
586
578
  * @param seed - Seed to generate the point values.
@@ -587,6 +587,7 @@ export const makeBlockProposal = (options?: MakeBlockProposalOptions): Promise<B
587
587
 
588
588
  return BlockProposal.createProposalFromSigner(
589
589
  blockHeader,
590
+ CheckpointNumber(1),
590
591
  indexWithinCheckpoint,
591
592
  inHash,
592
593
  archiveRoot,
@@ -618,6 +619,7 @@ export const makeCheckpointProposal = async (options?: MakeCheckpointProposalOpt
618
619
  return CheckpointProposal.createProposalFromSigner(
619
620
  checkpointHeader,
620
621
  archiveRoot,
622
+ CheckpointNumber(1),
621
623
  feeAssetPriceModifier,
622
624
  lastBlockProposal,
623
625
  payload => Promise.resolve(signer.signMessage(payload)),
@@ -25,6 +25,219 @@ export const DEFAULT_L1_PUBLISHING_TIME = 12;
25
25
  /** Minimum execution time for building a block in seconds */
26
26
  export const MIN_EXECUTION_TIME = 2;
27
27
 
28
+ export type CheckpointTimingConfig = {
29
+ aztecSlotDuration: number;
30
+ ethereumSlotDuration?: number;
31
+ blockDuration?: number;
32
+ checkpointAssembleTime?: number;
33
+ checkpointInitializationTime?: number;
34
+ l1PublishingTime?: number;
35
+ minExecutionTime?: number;
36
+ p2pPropagationTime?: number;
37
+ pipelining?: boolean;
38
+ };
39
+
40
+ export interface CheckpointTiming {
41
+ readonly aztecSlotDuration: number;
42
+ readonly blockDuration: number | undefined;
43
+ readonly checkpointAssembleTime: number;
44
+ readonly checkpointInitializationTime: number;
45
+ readonly l1PublishingTime: number;
46
+ readonly minExecutionTime: number;
47
+ readonly p2pPropagationTime: number;
48
+ readonly checkpointFinalizationTime: number;
49
+ readonly pipeliningAttestationGracePeriod: number;
50
+ readonly timeReservedAtEnd: number;
51
+ readonly minimumBuildSlotWork: number;
52
+ readonly initializeDeadline: number;
53
+ readonly checkpointAssemblyDeadline: number;
54
+ readonly checkpointAttestationStartDeadline: number;
55
+ readonly checkpointAttestationDeadline: number;
56
+ readonly checkpointPublishingDeadline: number;
57
+
58
+ calculateMaxBlocksPerSlot(): number;
59
+ }
60
+
61
+ export interface PipelinedCheckpointTiming extends CheckpointTiming {
62
+ readonly proposalWindowIntoTargetSlot: number;
63
+ readonly attestationWindowIntoTargetSlot: number;
64
+ }
65
+
66
+ /**
67
+ * Shared base for checkpoint timing implementations.
68
+ *
69
+ * This class owns the common inputs and formulas used by both pipelined and
70
+ * non-pipelined scheduling. Variant-specific deadline math is delegated to the
71
+ * concrete subclasses below.
72
+ */
73
+ abstract class BaseCheckpointTiming implements CheckpointTiming {
74
+ public readonly aztecSlotDuration: number;
75
+ public readonly blockDuration: number | undefined;
76
+ public readonly checkpointAssembleTime: number;
77
+ public readonly checkpointInitializationTime: number;
78
+ public readonly l1PublishingTime: number;
79
+ public readonly minExecutionTime: number;
80
+ public readonly p2pPropagationTime: number;
81
+
82
+ constructor(opts: CheckpointTimingConfig) {
83
+ this.aztecSlotDuration = opts.aztecSlotDuration;
84
+ this.blockDuration = opts.blockDuration;
85
+
86
+ this.checkpointAssembleTime = opts.checkpointAssembleTime ?? CHECKPOINT_ASSEMBLE_TIME;
87
+ this.checkpointInitializationTime = opts.checkpointInitializationTime ?? CHECKPOINT_INITIALIZATION_TIME;
88
+ this.l1PublishingTime = opts.l1PublishingTime ?? DEFAULT_L1_PUBLISHING_TIME;
89
+ this.minExecutionTime = opts.minExecutionTime ?? MIN_EXECUTION_TIME;
90
+ this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
91
+ }
92
+
93
+ public get checkpointFinalizationTime(): number {
94
+ // Allow enough time to
95
+ // - build the checkpoint
96
+ // - Round-trip over p2p
97
+ // - Publish to L1
98
+ return this.checkpointAssembleTime + this.p2pPropagationTime * 2 + this.l1PublishingTime;
99
+ }
100
+
101
+ public get pipeliningAttestationGracePeriod(): number {
102
+ // Allow enough time to
103
+ // - build the block
104
+ // - pass it back over p2p
105
+ return (this.blockDuration ?? 0) + this.p2pPropagationTime;
106
+ }
107
+
108
+ public abstract get timeReservedAtEnd(): number;
109
+ public abstract get minimumBuildSlotWork(): number;
110
+
111
+ public get initializeDeadline(): number {
112
+ return this.aztecSlotDuration - this.minimumBuildSlotWork;
113
+ }
114
+
115
+ public abstract get checkpointAssemblyDeadline(): number;
116
+
117
+ public get checkpointAttestationStartDeadline(): number {
118
+ return this.checkpointAssemblyDeadline;
119
+ }
120
+
121
+ public abstract get checkpointAttestationDeadline(): number;
122
+ public abstract get checkpointPublishingDeadline(): number;
123
+
124
+ public calculateMaxBlocksPerSlot(): number {
125
+ if (!this.blockDuration) {
126
+ return 1;
127
+ }
128
+
129
+ const timeAvailableForBlocks = this.aztecSlotDuration - this.checkpointInitializationTime - this.timeReservedAtEnd;
130
+ return Math.floor(timeAvailableForBlocks / this.blockDuration);
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Checkpoint timing model for the non-pipelined sequencer flow.
136
+ *
137
+ * In this mode, checkpoint assembly, attestation collection, and L1 publishing
138
+ * must all complete within the current Aztec slot.
139
+ */
140
+ class StandardCheckpointTimingModel extends BaseCheckpointTiming {
141
+ public get timeReservedAtEnd(): number {
142
+ return (this.blockDuration ?? 0) + this.checkpointFinalizationTime;
143
+ }
144
+
145
+ public get minimumBuildSlotWork(): number {
146
+ return this.checkpointInitializationTime + this.minExecutionTime * 2 + this.checkpointFinalizationTime;
147
+ }
148
+
149
+ public get checkpointAssemblyDeadline(): number {
150
+ return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
151
+ }
152
+
153
+ public get checkpointAttestationDeadline(): number {
154
+ return this.aztecSlotDuration - this.l1PublishingTime;
155
+ }
156
+
157
+ public get checkpointPublishingDeadline(): number {
158
+ return this.aztecSlotDuration - this.l1PublishingTime;
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Checkpoint timing model for proposer pipelining.
164
+ *
165
+ * In this mode, the build work still starts in the current slot, but checkpoint
166
+ * assembly and attestation collection can extend into the target slot. The extra
167
+ * target-slot window getters are intended for consumers such as P2P validators
168
+ * that need to validate pipelined messages against wallclock time.
169
+ */
170
+ class PipelinedCheckpointTimingModel extends BaseCheckpointTiming implements PipelinedCheckpointTiming {
171
+ public get proposalWindowIntoTargetSlot(): number {
172
+ // Allow the p2p propagation time to receive a checkpoint proposal from leader
173
+ return this.p2pPropagationTime;
174
+ }
175
+
176
+ public get attestationWindowIntoTargetSlot(): number {
177
+ return this.aztecSlotDuration - this.l1PublishingTime;
178
+ }
179
+
180
+ public get timeReservedAtEnd(): number {
181
+ return this.checkpointAssembleTime + this.p2pPropagationTime;
182
+ }
183
+
184
+ public get minimumBuildSlotWork(): number {
185
+ return this.checkpointInitializationTime + this.minExecutionTime * 2;
186
+ }
187
+
188
+ public get checkpointAssemblyDeadline(): number {
189
+ // Allow enough time to
190
+ // - build all blocks
191
+ // - receive attestations
192
+ return this.aztecSlotDuration + this.pipeliningAttestationGracePeriod;
193
+ }
194
+
195
+ public get checkpointAttestationDeadline(): number {
196
+ // Allowed to be into the next wallclock slot minus the allocated l1 publishing time
197
+ return this.aztecSlotDuration * 2 - this.l1PublishingTime;
198
+ }
199
+
200
+ public get checkpointPublishingDeadline(): number {
201
+ // Allowed to be into the next wallclock slot minus the allocated l1 Publishing time
202
+ return this.aztecSlotDuration * 2 - this.l1PublishingTime;
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Creates a checkpoint timing model for the requested scheduling mode.
208
+ *
209
+ * Most callers should use this factory and depend only on the shared
210
+ * `CheckpointTiming` interface. The returned implementation is selected from
211
+ * `opts.pipelining`.
212
+ */
213
+ export function createCheckpointTimingModel(opts: CheckpointTimingConfig): CheckpointTiming {
214
+ validateCheckpointTimingConfig(opts);
215
+ const normalizedOpts = normalizeCheckpointTimingConfig(opts);
216
+
217
+ const timing = normalizedOpts.pipelining
218
+ ? new PipelinedCheckpointTimingModel(normalizedOpts)
219
+ : new StandardCheckpointTimingModel(normalizedOpts);
220
+ validateCheckpointTimingModel(timing);
221
+ return timing;
222
+ }
223
+
224
+ /**
225
+ * Creates a pipelined checkpoint timing model with target-slot window accessors.
226
+ *
227
+ * Use this when the caller specifically needs the pipelined-only timing surface,
228
+ * such as proposal or attestation acceptance windows into the target slot.
229
+ */
230
+ export function createPipelinedCheckpointTimingModel(
231
+ opts: Omit<CheckpointTimingConfig, 'pipelining'>,
232
+ ): PipelinedCheckpointTiming {
233
+ validateCheckpointTimingConfig(opts);
234
+ const normalizedOpts = normalizeCheckpointTimingConfig(opts);
235
+
236
+ const timing = new PipelinedCheckpointTimingModel(normalizedOpts);
237
+ validateCheckpointTimingModel(timing);
238
+ return timing;
239
+ }
240
+
28
241
  /**
29
242
  * Calculates the maximum number of blocks that can be built in a slot.
30
243
  * Used by both the sequencer timetable and p2p gossipsub scoring.
@@ -45,27 +258,89 @@ export function calculateMaxBlocksPerSlot(
45
258
  pipelining?: boolean;
46
259
  } = {},
47
260
  ): number {
48
- if (!blockDurationSec) {
49
- return 1; // Single block per slot
261
+ return createCheckpointTimingModel({
262
+ aztecSlotDuration: aztecSlotDurationSec,
263
+ blockDuration: blockDurationSec,
264
+ checkpointAssembleTime: opts.checkpointAssembleTime,
265
+ checkpointInitializationTime: opts.checkpointInitializationTime,
266
+ l1PublishingTime: opts.l1PublishingTime,
267
+ p2pPropagationTime: opts.p2pPropagationTime,
268
+ pipelining: opts.pipelining,
269
+ }).calculateMaxBlocksPerSlot();
270
+ }
271
+
272
+ function assertNonNegative(name: string, value: number): void {
273
+ if (value < 0) {
274
+ throw new Error(`${name} must be non-negative (got ${value})`);
50
275
  }
276
+ }
51
277
 
52
- const initOffset = opts.checkpointInitializationTime ?? CHECKPOINT_INITIALIZATION_TIME;
53
- const assembleTime = opts.checkpointAssembleTime ?? CHECKPOINT_ASSEMBLE_TIME;
54
- const p2pTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
55
- const l1Time = opts.l1PublishingTime ?? DEFAULT_L1_PUBLISHING_TIME;
278
+ function validateCheckpointTimingConfig(opts: CheckpointTimingConfig): void {
279
+ if (opts.aztecSlotDuration <= 0) {
280
+ throw new Error(`aztecSlotDuration must be positive (got ${opts.aztecSlotDuration})`);
281
+ }
56
282
 
57
- // Calculate checkpoint finalization time (assembly + round-trip propagation + L1 publishing)
58
- const checkpointFinalizationTime = assembleTime + p2pTime * 2 + l1Time;
283
+ if (opts.ethereumSlotDuration !== undefined && opts.ethereumSlotDuration <= 0) {
284
+ throw new Error(`ethereumSlotDuration must be positive when provided (got ${opts.ethereumSlotDuration})`);
285
+ }
59
286
 
60
- // When pipelining, finalization is deferred to the next slot, but we still reserve
61
- // a sub-slot for validator re-execution so they can produce attestations.
62
- let timeReservedAtEnd = blockDurationSec;
63
- if (!opts.pipelining) {
64
- timeReservedAtEnd += checkpointFinalizationTime;
287
+ if (opts.blockDuration !== undefined && opts.blockDuration <= 0) {
288
+ throw new Error(`blockDuration must be positive when provided (got ${opts.blockDuration})`);
65
289
  }
66
290
 
67
- // Time available for building blocks
68
- const timeAvailableForBlocks = aztecSlotDurationSec - initOffset - timeReservedAtEnd;
291
+ if (opts.minExecutionTime !== undefined && opts.minExecutionTime <= 0) {
292
+ throw new Error(`minExecutionTime must be positive when provided (got ${opts.minExecutionTime})`);
293
+ }
69
294
 
70
- return Math.max(1, Math.floor(timeAvailableForBlocks / blockDurationSec));
295
+ if (opts.checkpointAssembleTime !== undefined) {
296
+ assertNonNegative('checkpointAssembleTime', opts.checkpointAssembleTime);
297
+ }
298
+ if (opts.checkpointInitializationTime !== undefined) {
299
+ assertNonNegative('checkpointInitializationTime', opts.checkpointInitializationTime);
300
+ }
301
+ if (opts.l1PublishingTime !== undefined) {
302
+ assertNonNegative('l1PublishingTime', opts.l1PublishingTime);
303
+ }
304
+ if (opts.p2pPropagationTime !== undefined) {
305
+ assertNonNegative('p2pPropagationTime', opts.p2pPropagationTime);
306
+ }
307
+ }
308
+
309
+ function normalizeCheckpointTimingConfig(opts: CheckpointTimingConfig): CheckpointTimingConfig {
310
+ let checkpointAssembleTime = opts.checkpointAssembleTime ?? CHECKPOINT_ASSEMBLE_TIME;
311
+ let checkpointInitializationTime = opts.checkpointInitializationTime ?? CHECKPOINT_INITIALIZATION_TIME;
312
+ let minExecutionTime = opts.minExecutionTime ?? MIN_EXECUTION_TIME;
313
+ let p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
314
+
315
+ if (opts.ethereumSlotDuration !== undefined && opts.ethereumSlotDuration < 8) {
316
+ p2pPropagationTime = 0;
317
+ checkpointAssembleTime = 0.5;
318
+ checkpointInitializationTime = 0.5;
319
+ minExecutionTime = 1;
320
+ }
321
+
322
+ if (opts.blockDuration !== undefined && minExecutionTime > opts.blockDuration) {
323
+ minExecutionTime = opts.blockDuration;
324
+ }
325
+
326
+ return {
327
+ ...opts,
328
+ checkpointAssembleTime,
329
+ checkpointInitializationTime,
330
+ minExecutionTime,
331
+ p2pPropagationTime,
332
+ };
333
+ }
334
+
335
+ function validateCheckpointTimingModel(model: CheckpointTiming): void {
336
+ if (model.blockDuration === undefined) {
337
+ return;
338
+ }
339
+
340
+ const timeAvailableForBlocks = model.aztecSlotDuration - model.checkpointInitializationTime - model.timeReservedAtEnd;
341
+ if (timeAvailableForBlocks < model.blockDuration) {
342
+ throw new Error(
343
+ `Invalid timing configuration: only ${timeAvailableForBlocks}s available for block building, which is less than one blockDuration (${model.blockDuration}s).`,
344
+ );
345
+ }
71
346
  }
@@ -86,6 +86,10 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage {
86
86
  ];
87
87
  }
88
88
 
89
+ isEmpty(): boolean {
90
+ return this.leaf.isEmpty() && this.nextKey.isZero() && this.nextIndex === 0n;
91
+ }
92
+
89
93
  toFields(): Fr[] {
90
94
  return this.toHashInputs().map(buf => Fr.fromBuffer(buf));
91
95
  }
@@ -172,8 +172,8 @@ export class BlockHeader {
172
172
  }
173
173
 
174
174
  /** Manually set the hash for this block header if already computed */
175
- setHash(hashed: Fr) {
176
- this._cachedHash = Promise.resolve(new BlockHash(hashed));
175
+ setHash(hashed: BlockHash) {
176
+ this._cachedHash = Promise.resolve(hashed);
177
177
  }
178
178
 
179
179
  /** Recomputes the cached hash. Used for testing when header fields are mutated via unfreeze. */
@@ -0,0 +1,10 @@
1
+ import type { ManaUsageEstimate } from '../gas/fee_math.js';
2
+ import type { GasFees } from '../gas/gas_fees.js';
3
+
4
+ /** Provides current and predicted fee information for transaction pricing. */
5
+ export interface FeeProvider {
6
+ /** Returns the current minimum fees for inclusion in the next block. */
7
+ getCurrentMinFees(): Promise<GasFees>;
8
+ /** Returns predicted min fees for each slot in the prediction window. */
9
+ getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]>;
10
+ }
@@ -1,31 +1,15 @@
1
- import type { FeeHeader } from '@aztec/ethereum/contracts';
2
- import type { CheckpointNumber } from '@aztec/foundation/branded-types';
1
+ import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
3
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
3
  import type { SlotNumber } from '@aztec/foundation/schemas';
5
4
 
6
5
  import type { AztecAddress } from '../aztec-address/index.js';
7
- import type { GasFees } from '../gas/gas_fees.js';
8
6
  import type { UInt32 } from '../types/index.js';
9
7
  import type { CheckpointGlobalVariables, GlobalVariables } from './global_variables.js';
10
8
 
11
- /** Fee header fields needed for pipelining overrides. */
12
- export type ForceProposedFeeHeader = {
13
- checkpointNumber: CheckpointNumber;
14
- feeHeader: FeeHeader;
15
- };
16
-
17
- /** Options for building checkpoint global variables during pipelining. */
18
- export type BuildCheckpointGlobalVariablesOpts = {
19
- forcePendingCheckpointNumber?: CheckpointNumber;
20
- forceProposedFeeHeader?: ForceProposedFeeHeader;
21
- };
22
-
23
9
  /**
24
10
  * Interface for building global variables for Aztec blocks.
25
11
  */
26
12
  export interface GlobalVariableBuilder {
27
- getCurrentMinFees(): Promise<GasFees>;
28
-
29
13
  /**
30
14
  * Builds global variables for a given block.
31
15
  * @param blockNumber - The block number to build global variables for.
@@ -46,6 +30,6 @@ export interface GlobalVariableBuilder {
46
30
  coinbase: EthAddress,
47
31
  feeRecipient: AztecAddress,
48
32
  slotNumber: SlotNumber,
49
- opts?: BuildCheckpointGlobalVariablesOpts,
33
+ simulationOverridesPlan?: SimulationOverridesPlan,
50
34
  ): Promise<CheckpointGlobalVariables>;
51
35
  }
package/src/tx/index.ts CHANGED
@@ -24,6 +24,7 @@ export * from './validator/tx_validator.js';
24
24
  export * from './validator/empty_validator.js';
25
25
  export * from './validator/error_texts.js';
26
26
  export * from './capsule.js';
27
+ export * from './fee_provider.js';
27
28
  export * from './global_variable_builder.js';
28
29
  export * from './hashed_values.js';
29
30
  export * from './indexed_tx_effect.js';
@@ -1,5 +1,4 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/curves/bn254';
3
2
  import { schemas } from '@aztec/foundation/schemas';
4
3
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
4
 
@@ -27,7 +26,7 @@ export function serializeIndexedTxEffect(effect: IndexedTxEffect): Buffer {
27
26
  export function deserializeIndexedTxEffect(buffer: Buffer): IndexedTxEffect {
28
27
  const reader = BufferReader.asReader(buffer);
29
28
 
30
- const l2BlockHash = new BlockHash(reader.readObject(Fr));
29
+ const l2BlockHash = BlockHash.fromBuffer(reader);
31
30
  const l2BlockNumber = BlockNumber(reader.readNumber());
32
31
  const txIndexInBlock = reader.readNumber();
33
32
  const data = reader.readObject(TxEffect);
@@ -161,7 +161,7 @@ export class TxSimulationResult {
161
161
  }
162
162
 
163
163
  /**
164
- * Recursively accummulate the return values of a call result and its nested executions,
164
+ * Recursively accumulate the return values of a call result and its nested executions,
165
165
  * so they can be retrieved in order.
166
166
  * @param executionResult
167
167
  * @returns
package/src/tx/tx.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DA_GAS_PER_FIELD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
2
- import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { type BaseBuffer32, Buffer32 } from '@aztec/foundation/buffer';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import type { ZodFor } from '@aztec/foundation/schemas';
5
5
  import { BufferReader, serializeArrayOfBufferableToVector, serializeToBuffer } from '@aztec/foundation/serialize';
@@ -64,7 +64,7 @@ export class Tx extends Gossipable {
64
64
  // docs:end:tx_class
65
65
 
66
66
  // Gossipable method
67
- override generateP2PMessageIdentifier(): Promise<Buffer32> {
67
+ override generateP2PMessageIdentifier(): Promise<BaseBuffer32> {
68
68
  return Promise.resolve(new Buffer32(this.getTxHash().toBuffer()));
69
69
  }
70
70
 
@@ -34,13 +34,3 @@ export type UInt64 = bigint;
34
34
  * A type alias for a 128-bit unsigned integer.
35
35
  */
36
36
  export type UInt128 = bigint;
37
-
38
- /**
39
- * CircuitType replaces ComposerType for now. When using Plonk, CircuitType is equivalent to the information of the proving system that will be used
40
- * to construct a proof. In the future Aztec zk stack, more information must be specified (e.g., the curve over which circuits are constructed;
41
- * Plonk vs Honk; zk-SNARK or just SNARK; etc).
42
- */
43
- export enum CircuitType {
44
- STANDARD = 0,
45
- ULTRA = 1,
46
- }