@aztec/stdlib 5.0.0-nightly.20260410 → 5.0.0-nightly.20260412

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 (50) hide show
  1. package/dest/avm/avm.d.ts +300 -300
  2. package/dest/config/sequencer-config.d.ts +2 -2
  3. package/dest/config/sequencer-config.d.ts.map +1 -1
  4. package/dest/config/sequencer-config.js +7 -0
  5. package/dest/gas/fee_math.d.ts +49 -0
  6. package/dest/gas/fee_math.d.ts.map +1 -0
  7. package/dest/gas/fee_math.js +80 -0
  8. package/dest/gas/gas_fees.d.ts +1 -1
  9. package/dest/gas/gas_fees.d.ts.map +1 -1
  10. package/dest/gas/gas_fees.js +10 -1
  11. package/dest/gas/index.d.ts +2 -1
  12. package/dest/gas/index.d.ts.map +1 -1
  13. package/dest/gas/index.js +1 -0
  14. package/dest/interfaces/aztec-node-debug.d.ts +21 -0
  15. package/dest/interfaces/aztec-node-debug.d.ts.map +1 -0
  16. package/dest/interfaces/aztec-node-debug.js +18 -0
  17. package/dest/interfaces/aztec-node.d.ts +10 -1
  18. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  19. package/dest/interfaces/aztec-node.js +2 -0
  20. package/dest/interfaces/client.d.ts +2 -1
  21. package/dest/interfaces/client.d.ts.map +1 -1
  22. package/dest/interfaces/client.js +1 -0
  23. package/dest/interfaces/proving-job.d.ts +166 -166
  24. package/dest/timetable/index.d.ts +50 -1
  25. package/dest/timetable/index.d.ts.map +1 -1
  26. package/dest/timetable/index.js +204 -18
  27. package/dest/tx/fee_provider.d.ts +10 -0
  28. package/dest/tx/fee_provider.d.ts.map +1 -0
  29. package/dest/tx/fee_provider.js +1 -0
  30. package/dest/tx/global_variable_builder.d.ts +3 -16
  31. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  32. package/dest/tx/index.d.ts +2 -1
  33. package/dest/tx/index.d.ts.map +1 -1
  34. package/dest/tx/index.js +1 -0
  35. package/dest/tx/simulated_tx.d.ts +1 -1
  36. package/dest/tx/simulated_tx.js +1 -1
  37. package/package.json +8 -8
  38. package/src/config/sequencer-config.ts +11 -1
  39. package/src/gas/README.md +31 -0
  40. package/src/gas/fee_math.ts +120 -0
  41. package/src/gas/gas_fees.ts +12 -4
  42. package/src/gas/index.ts +1 -0
  43. package/src/interfaces/aztec-node-debug.ts +40 -0
  44. package/src/interfaces/aztec-node.ts +15 -0
  45. package/src/interfaces/client.ts +1 -0
  46. package/src/timetable/index.ts +291 -16
  47. package/src/tx/fee_provider.ts +10 -0
  48. package/src/tx/global_variable_builder.ts +2 -18
  49. package/src/tx/index.ts +1 -0
  50. package/src/tx/simulated_tx.ts +1 -1
@@ -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
 
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';
@@ -0,0 +1,40 @@
1
+ import { createSafeJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/client';
2
+
3
+ import { z } from 'zod';
4
+
5
+ import type { ApiSchemaFor } from '../schemas/schemas.js';
6
+ import { type ComponentsVersions, getVersioningResponseHandler } from '../versioning/index.js';
7
+
8
+ /**
9
+ * Debug interface for Aztec node available in sandbox/local-network mode.
10
+ */
11
+ export interface AztecNodeDebug {
12
+ /**
13
+ * Triggers the sequencer to produce an L2 block and waits for it to appear.
14
+ *
15
+ * **Precondition**: The current L2 slot must not already contain a block. Callers must ensure L1 time has been
16
+ * advanced to a slot with no existing block before calling this method (e.g. via `EthCheatCodes.warp()`).
17
+ * If the slot is already taken, the sequencer will fail to propose and this call will time out.
18
+ *
19
+ * @throws If no sequencer is running.
20
+ */
21
+ mineBlock(): Promise<void>;
22
+ }
23
+
24
+ export const AztecNodeDebugApiSchema: ApiSchemaFor<AztecNodeDebug> = {
25
+ mineBlock: z.function().returns(z.void()),
26
+ };
27
+
28
+ export function createAztecNodeDebugClient(
29
+ url: string,
30
+ versions: Partial<ComponentsVersions> = {},
31
+ fetch = defaultFetch,
32
+ apiKey?: string,
33
+ ): AztecNodeDebug {
34
+ return createSafeJsonRpcClient<AztecNodeDebug>(url, AztecNodeDebugApiSchema, {
35
+ namespaceMethods: 'nodeDebug',
36
+ fetch,
37
+ onResponse: getVersioningResponseHandler(versions),
38
+ ...(apiKey ? { extraHeaders: { 'x-api-key': apiKey } } : {}),
39
+ });
40
+ }
@@ -37,6 +37,7 @@ import {
37
37
  type ProtocolContractAddresses,
38
38
  ProtocolContractAddressesSchema,
39
39
  } from '../contract/index.js';
40
+ import { ManaUsageEstimate } from '../gas/fee_math.js';
40
41
  import { GasFees } from '../gas/gas_fees.js';
41
42
  import { SiloedTag, Tag, TxScopedL2Log } from '../logs/index.js';
42
43
  import { type LogFilter, LogFilterSchema } from '../logs/log_filter.js';
@@ -272,6 +273,15 @@ export interface AztecNode
272
273
  */
273
274
  getCurrentMinFees(): Promise<GasFees>;
274
275
 
276
+ /**
277
+ * Returns predicted min fees for the current slot and next N slots.
278
+ * Each entry accounts for the L1 gas oracle transition and congestion growth based on the
279
+ * given mana usage estimate. Defaults to target usage (steady state).
280
+ * @param manaUsage - Expected mana usage per checkpoint (none, target, or limit).
281
+ * @returns An array of GasFees, one per slot in the prediction window.
282
+ */
283
+ getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]>;
284
+
275
285
  /**
276
286
  * Method to fetch the current max priority fee of txs in the mempool.
277
287
  * @returns The current max priority fees.
@@ -578,6 +588,11 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
578
588
 
579
589
  getCurrentMinFees: z.function().returns(GasFees.schema),
580
590
 
591
+ getPredictedMinFees: z
592
+ .function()
593
+ .args(optional(z.nativeEnum(ManaUsageEstimate)))
594
+ .returns(z.array(GasFees.schema)),
595
+
581
596
  getMaxPriorityFees: z.function().returns(GasFees.schema),
582
597
 
583
598
  getNodeVersion: z.function().returns(z.string()),
@@ -1,5 +1,6 @@
1
1
  export * from './aztec-node.js';
2
2
  export * from './aztec-node-admin.js';
3
+ export * from './aztec-node-debug.js';
3
4
  export * from './private_kernel_prover.js';
4
5
  export * from './get_logs_response.js';
5
6
  export * from './api_limit.js';
@@ -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
  }
@@ -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';
@@ -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