@aztec/stdlib 5.0.0-nightly.20260713 → 5.0.0-nightly.20260715

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 (73) hide show
  1. package/dest/interfaces/private_kernel_prover.d.ts +9 -11
  2. package/dest/interfaces/private_kernel_prover.d.ts.map +1 -1
  3. package/dest/interfaces/proving-job.d.ts +4 -4
  4. package/dest/interfaces/proving-job.d.ts.map +1 -1
  5. package/dest/interfaces/proving-job.js +2 -2
  6. package/dest/interfaces/server_circuit_prover.d.ts +3 -3
  7. package/dest/interfaces/server_circuit_prover.d.ts.map +1 -1
  8. package/dest/kernel/hints/find_private_kernel_reset_dimensions.d.ts +8 -2
  9. package/dest/kernel/hints/find_private_kernel_reset_dimensions.d.ts.map +1 -1
  10. package/dest/kernel/hints/find_private_kernel_reset_dimensions.js +12 -74
  11. package/dest/kernel/index.d.ts +2 -2
  12. package/dest/kernel/index.d.ts.map +1 -1
  13. package/dest/kernel/index.js +1 -1
  14. package/dest/kernel/private_circuit_public_inputs.d.ts +13 -3
  15. package/dest/kernel/private_circuit_public_inputs.d.ts.map +1 -1
  16. package/dest/kernel/private_circuit_public_inputs.js +14 -7
  17. package/dest/kernel/private_context_inputs.d.ts +4 -3
  18. package/dest/kernel/private_context_inputs.d.ts.map +1 -1
  19. package/dest/kernel/private_context_inputs.js +7 -3
  20. package/dest/kernel/private_kernel_circuit_public_inputs.d.ts +7 -1
  21. package/dest/kernel/private_kernel_circuit_public_inputs.d.ts.map +1 -1
  22. package/dest/kernel/private_kernel_circuit_public_inputs.js +7 -0
  23. package/dest/kernel/private_kernel_init_2_circuit_private_inputs.d.ts +2 -3
  24. package/dest/kernel/private_kernel_init_2_circuit_private_inputs.d.ts.map +1 -1
  25. package/dest/kernel/private_kernel_init_2_circuit_private_inputs.js +3 -5
  26. package/dest/kernel/private_kernel_init_3_circuit_private_inputs.d.ts +2 -3
  27. package/dest/kernel/private_kernel_init_3_circuit_private_inputs.d.ts.map +1 -1
  28. package/dest/kernel/private_kernel_init_3_circuit_private_inputs.js +3 -5
  29. package/dest/kernel/private_kernel_init_circuit_private_inputs.d.ts +1 -9
  30. package/dest/kernel/private_kernel_init_circuit_private_inputs.d.ts.map +1 -1
  31. package/dest/kernel/private_kernel_init_circuit_private_inputs.js +2 -6
  32. package/dest/kernel/private_kernel_reset_dimensions.d.ts +7 -8
  33. package/dest/kernel/private_kernel_reset_dimensions.d.ts.map +1 -1
  34. package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.d.ts +29 -0
  35. package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.d.ts.map +1 -0
  36. package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.js +36 -0
  37. package/dest/logs/shared_secret_derivation.d.ts +12 -2
  38. package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
  39. package/dest/logs/shared_secret_derivation.js +18 -0
  40. package/dest/rollup/avm_proof_data.d.ts +3 -3
  41. package/dest/rollup/avm_proof_data.d.ts.map +1 -1
  42. package/dest/stats/stats.d.ts +2 -2
  43. package/dest/stats/stats.d.ts.map +1 -1
  44. package/dest/tests/factories.d.ts +1 -1
  45. package/dest/tests/factories.d.ts.map +1 -1
  46. package/dest/tests/factories.js +4 -3
  47. package/dest/tx/private_tx_constant_data.d.ts +18 -2
  48. package/dest/tx/private_tx_constant_data.d.ts.map +1 -1
  49. package/dest/tx/private_tx_constant_data.js +13 -4
  50. package/package.json +8 -8
  51. package/src/gas/README.md +108 -36
  52. package/src/interfaces/private_kernel_prover.ts +10 -12
  53. package/src/interfaces/proving-job.ts +3 -3
  54. package/src/interfaces/server_circuit_prover.ts +2 -2
  55. package/src/kernel/hints/find_private_kernel_reset_dimensions.ts +22 -112
  56. package/src/kernel/index.ts +1 -1
  57. package/src/kernel/private_circuit_public_inputs.ts +12 -1
  58. package/src/kernel/private_context_inputs.ts +10 -3
  59. package/src/kernel/private_kernel_circuit_public_inputs.ts +9 -0
  60. package/src/kernel/private_kernel_init_2_circuit_private_inputs.ts +0 -3
  61. package/src/kernel/private_kernel_init_3_circuit_private_inputs.ts +0 -3
  62. package/src/kernel/private_kernel_init_circuit_private_inputs.ts +0 -6
  63. package/src/kernel/private_kernel_reset_dimensions.ts +15 -5
  64. package/src/kernel/private_kernel_reset_tail_circuit_private_inputs.ts +69 -0
  65. package/src/logs/shared_secret_derivation.ts +18 -1
  66. package/src/rollup/avm_proof_data.ts +2 -2
  67. package/src/stats/stats.ts +2 -2
  68. package/src/tests/factories.ts +3 -6
  69. package/src/tx/private_tx_constant_data.ts +25 -2
  70. package/dest/kernel/private_kernel_tail_circuit_private_inputs.d.ts +0 -47
  71. package/dest/kernel/private_kernel_tail_circuit_private_inputs.d.ts.map +0 -1
  72. package/dest/kernel/private_kernel_tail_circuit_private_inputs.js +0 -38
  73. package/src/kernel/private_kernel_tail_circuit_private_inputs.ts +0 -58
package/src/gas/README.md CHANGED
@@ -1,47 +1,69 @@
1
1
  # Aztec Gas and Fee Model
2
2
 
3
3
  The minimum fee per mana and its components are computed on L1 in
4
- `l1-contracts/src/core/libraries/rollup/FeeLib.sol`. This document describes the
5
- formulas, the oracle lag/lifetime mechanism, and the TypeScript types in this directory.
4
+ `l1-contracts/src/core/libraries/rollup/FeeLib.sol` (`fee_math.ts` in this directory is a
5
+ TypeScript port of those formulas, used to predict fees a few slots ahead). This document
6
+ describes the formulas, the oracle lag/lifetime mechanism, how a transaction's fee is
7
+ derived from them, the gas and data limits, and the TypeScript types in this directory.
6
8
 
7
9
  ## Mana
8
10
 
9
- Aztec uses **mana** as its unit of work (analogous to Ethereum gas). Transactions consume
10
- mana in two dimensions: **DA** (data availability) and **L2** (execution). The total fee
11
- is `gasUsed * feePerMana` summed across both dimensions.
11
+ Aztec meters work as gas in two dimensions: **DA** (data availability, i.e. blob data
12
+ published to L1) and **L2** (execution). The L2 dimension is called **mana** (analogous to
13
+ Ethereum gas): block headers track `totalManaUsed`, and the fee model below prices one unit
14
+ of mana. The total fee is `gasUsed * feePerGas` summed across both dimensions.
15
+
16
+ ### The DA dimension is priced at zero
17
+
18
+ Only the L2 dimension currently carries a price. When building checkpoint global variables,
19
+ the sequencer sets `feePerDaGas = 0` and sets `feePerL2Gas` to the L1-computed minimum fee
20
+ per mana (`sequencer-client/src/global_variable_builder/global_builder.ts` and
21
+ `fee_provider.ts` in the same directory). The cost of publishing data is still recovered:
22
+ the blob gas a checkpoint pays on L1 is part of the *sequencer cost* component of the mana
23
+ fee below. DA gas remains fully metered and limited (see
24
+ [Gas and Data Limits](#gas-and-data-limits)) — it bounds how much data a tx or checkpoint
25
+ may publish — it just contributes nothing to the fee today.
12
26
 
13
27
  ## Fee Components
14
28
 
15
- The minimum fee per mana has four components:
29
+ The minimum fee per mana has four components. All are computed in ETH (wei) per mana and
30
+ converted to the fee asset at the end (see [Fee Asset Price](#fee-asset-price)).
16
31
 
17
32
  ### Sequencer Cost
18
33
 
19
34
  L1 cost to propose a checkpoint (calldata gas + blob data), amortized over `manaTarget`:
20
35
 
21
36
  ```
22
- sequencerCost = ((L1_GAS_PER_CHECKPOINT_PROPOSED * baseFee)
37
+ sequencerCost = ceil(((L1_GAS_PER_CHECKPOINT_PROPOSED * baseFee)
23
38
  + (BLOBS_PER_CHECKPOINT * BLOB_GAS_PER_BLOB * blobFee))
24
- / manaTarget
39
+ / manaTarget)
25
40
  ```
26
41
 
42
+ Note that `BLOBS_PER_CHECKPOINT` here is FeeLib's own constant (3), not the protocol blob
43
+ capacity of the same name (6) — see the note under [Key Constants](#key-constants).
44
+
27
45
  ### Prover Cost
28
46
 
29
47
  L1 cost to verify an epoch proof, amortized over epoch duration and `manaTarget`, plus a
30
48
  governance-set proving cost that compensates for off-chain proof generation:
31
49
 
32
50
  ```
33
- proverCost = (L1_GAS_PER_EPOCH_VERIFIED * baseFee / epochDuration) / manaTarget
51
+ proverCost = ceil(ceil((L1_GAS_PER_EPOCH_VERIFIED * baseFee) / epochDuration) / manaTarget)
34
52
  + provingCostPerMana
35
53
  ```
36
54
 
55
+ Updates to `provingCostPerMana` are rate-limited on L1 (`FeeLib.updateProvingCostPerMana`):
56
+ at most one update every 30 days, each moving the value by at most ×1.5 (or ÷1.5), with a
57
+ floor of 2 wei per mana.
58
+
37
59
  ### Congestion Cost
38
60
 
39
61
  An exponential surcharge when the network is congested (inspired by EIP-1559; the
40
62
  implementation uses the `fakeExponential` Taylor series approximation from EIP-4844):
41
63
 
42
64
  ```
43
- baseCost = sequencerCost + proverCost
44
- congestionCost = baseCost * congestionMultiplier / MINIMUM_CONGESTION_MULTIPLIER - baseCost
65
+ baseCost = sequencerCost + proverCost
66
+ congestionCost = floor(baseCost * congestionMultiplier / MINIMUM_CONGESTION_MULTIPLIER) - baseCost
45
67
  ```
46
68
 
47
69
  When there is no congestion the multiplier equals `MINIMUM_CONGESTION_MULTIPLIER` (1e9)
@@ -50,11 +72,15 @@ and congestion cost is zero.
50
72
  ### Congestion Multiplier
51
73
 
52
74
  ```
53
- excessMana = max(0, prevExcessMana + prevManaUsed - manaTarget)
54
- congestionMultiplier = fakeExponential(MINIMUM_CONGESTION_MULTIPLIER, excessMana, denominator)
75
+ excessMana = max(0, prevExcessMana + prevManaUsed - manaTarget)
76
+ denominator = manaTarget * 854,700,854 / 1e8 ≈ 8.547 * manaTarget
77
+ congestionMultiplier = fakeExponential(MINIMUM_CONGESTION_MULTIPLIER,
78
+ min(excessMana, 100 * denominator), denominator)
55
79
  ```
56
80
 
57
- Each additional `manaTarget` of excess mana increases the multiplier by ~12.5%.
81
+ Each additional `manaTarget` of excess mana multiplies the fee by `e^(1/8.547) ≈ 1.124`,
82
+ i.e. ~12.5%. The exponent is capped at 100 (multiplier ≤ ~2.7e43 × the minimum) to keep
83
+ the Taylor series from overflowing.
58
84
 
59
85
  ### Total
60
86
 
@@ -62,6 +88,11 @@ Each additional `manaTarget` of excess mana increases the multiplier by ~12.5%.
62
88
  minFeePerMana = sequencerCost + proverCost + congestionCost
63
89
  ```
64
90
 
91
+ Each component is converted from ETH to the fee asset individually (rounding up) before
92
+ summing. The sum is capped at `type(uint128).max` (`FeeLib.summedMinFee`) so it always fits
93
+ the proposal header's `feePerL2Gas` field — without the cap, extreme congestion could
94
+ produce a fee no valid header can represent, halting the chain.
95
+
65
96
  ## L1 Gas Oracle: Lag and Lifetime
66
97
 
67
98
  The oracle feeds Ethereum's `baseFee` and `blobFee` into the fee model using a two-phase
@@ -70,9 +101,9 @@ The oracle feeds Ethereum's `baseFee` and `blobFee` into the fee model using a t
70
101
  - **LAG = 2 slots** — when new L1 fees are observed, they activate `LAG` slots later
71
102
  (`slotOfChange = currentSlot + LAG`). This gives mempool transactions time to land
72
103
  before fees change.
73
- - **LIFETIME = 5 slots** — after an oracle update, the next update is rejected until
74
- `slotOfChange + (LIFETIME - LAG)` = 3 more slots have passed. This rate-limits how
75
- frequently L1 fee data can change.
104
+ - **LIFETIME = 5 slots** — after an oracle update, further updates are ignored
105
+ (`updateL1GasFeeOracle` returns without effect) until `slotOfChange + (LIFETIME - LAG)`
106
+ = 3 more slots have passed. This rate-limits how frequently L1 fee data can change.
76
107
 
77
108
  Fee resolution at a given timestamp:
78
109
 
@@ -84,6 +115,12 @@ else → use post (new fees)
84
115
  **Net effect**: L1 fee changes reach L2 with a 2-slot delay and can update at most once
85
116
  every 5 slots.
86
117
 
118
+ Because queued values only activate `LAG` slots later, the min fee for the next `LAG`
119
+ slots is fully determined by current on-chain state. `fee_math.ts` ports the FeeLib
120
+ formulas so the sequencer can predict min fees over that window (`FeePredictor` in
121
+ `sequencer-client/src/global_variable_builder`), under a configurable mana-usage
122
+ assumption (`ManaUsageEstimate`: none / target / limit).
123
+
87
124
  ### Worked Example
88
125
 
89
126
  Suppose the oracle is updated at slot 10 with new L1 fees. Here is the timeline:
@@ -117,34 +154,68 @@ Key observations:
117
154
 
118
155
  ## Fee Asset Price
119
156
 
120
- Fees are computed in ETH internally but converted to the fee asset (Fee Juice) via
121
- `ethPerFeeAsset` (1e12 precision). The price updates at most ±1% (±100 bps) per
122
- checkpoint:
157
+ Fees are computed in ETH (wei) internally and converted to the fee asset (Fee Juice) via
158
+ `ethPerFeeAsset` (1e12 precision), rounding up (`PriceLib.toFeeAsset` in
159
+ `l1-contracts/src/core/libraries/compressed-data/fees/FeeConfig.sol`).
160
+
161
+ Each checkpoint proposal carries a fee-asset price modifier (`OracleInput`) chosen by the
162
+ proposer, bounded to ±1% (±100 bps) per checkpoint:
123
163
 
124
164
  ```
125
165
  newPrice = currentPrice * (10000 + modifierBps) / 10000
126
166
  ```
127
167
 
168
+ The result is clamped to [`MIN_ETH_PER_FEE_ASSET` = 100, `MAX_ETH_PER_FEE_ASSET` = 1e14],
169
+ i.e. 1e-10 to 100 ETH per fee asset. The floor of 100 guarantees a ±1% step always moves
170
+ the integer price by at least 1.
171
+
172
+ ## Transaction Fees
173
+
174
+ The checkpoint's `gasFees` (the L1-computed min fee per mana, with DA priced at zero) act
175
+ as a base fee. Senders declare `GasSettings`: gas limits, teardown gas limits,
176
+ `maxFeesPerGas`, and `maxPriorityFeesPerGas`. A tx is only includable if `maxFeesPerGas`
177
+ covers the checkpoint's `gasFees` in both dimensions. The effective fee adds an
178
+ EIP-1559-style priority fee on top of the base, capped by the max
179
+ (`computeEffectiveGasFees` in `stdlib/src/fees/transaction_fee.ts`):
180
+
181
+ ```
182
+ effectiveFeePerGas = gasFees + min(maxPriorityFeePerGas, maxFeesPerGas - gasFees) (per dimension)
183
+ transactionFee = billedGas.daGas * effectiveFeePerDaGas + billedGas.l2Gas * effectiveFeePerL2Gas
184
+ ```
185
+
186
+ `billedGas` is actual consumption except for the teardown phase, which is billed at the
187
+ declared `teardownGasLimits` rather than actual usage — the fee is charged during teardown
188
+ itself, before actual teardown consumption is known.
189
+
128
190
  ## Maximum Fee Change Rate
129
191
 
130
- | Component | Bound |
131
- | ---------------------- | ------------------------------------------------------- |
132
- | L1 base fee / blob fee | At most once every 5 slots (oracle LIFETIME) |
133
- | Fee asset price | ±1% per checkpoint |
192
+ | Component | Bound |
193
+ | ---------------------- | -------------------------------------------------------- |
194
+ | L1 base fee / blob fee | At most once every 5 slots (oracle LIFETIME) |
195
+ | Fee asset price | ±1% per checkpoint |
196
+ | Proving cost per mana | At most ×1.5 (or ÷1.5) per update, one update per 30 days |
134
197
  | Congestion multiplier | Depends on excess mana accumulation/drain per checkpoint |
135
- | Sequencer/prover costs | Scale linearly with L1 fees |
198
+ | Sequencer/prover costs | Scale linearly with L1 fees |
136
199
 
137
200
  ## Key Constants
138
201
 
139
- | Constant | Value |
140
- | ------------------------------ | -------------- |
141
- | `L1_GAS_PER_CHECKPOINT_PROPOSED` | 300,000 |
142
- | `L1_GAS_PER_EPOCH_VERIFIED` | 3,600,000 |
143
- | `BLOBS_PER_CHECKPOINT` | 3 |
144
- | `BLOB_GAS_PER_BLOB` | 2^17 |
145
- | `MINIMUM_CONGESTION_MULTIPLIER` | 1e9 |
146
- | `LAG` | 2 slots |
147
- | `LIFETIME` | 5 slots |
202
+ | Constant | Value |
203
+ | ------------------------------- | -------------- |
204
+ | `L1_GAS_PER_CHECKPOINT_PROPOSED` | 300,000 |
205
+ | `L1_GAS_PER_EPOCH_VERIFIED` | 3,600,000 |
206
+ | `BLOBS_PER_CHECKPOINT` (FeeLib) | 3 |
207
+ | `BLOB_GAS_PER_BLOB` | 2^17 |
208
+ | `MINIMUM_CONGESTION_MULTIPLIER` | 1e9 |
209
+ | `LAG` | 2 slots |
210
+ | `LIFETIME` | 5 slots |
211
+ | `MIN_ETH_PER_FEE_ASSET` | 100 (1e-10 ETH) |
212
+ | `MAX_ETH_PER_FEE_ASSET` | 1e14 (100 ETH) |
213
+
214
+ ⚠️ Name clash: `FeeLib.sol` (and its port `fee_math.ts`) defines `BLOBS_PER_CHECKPOINT = 3`,
215
+ used only to price the sequencer's blob costs. The protocol constant of the same name in
216
+ `@aztec/constants` is **6** — the actual blob capacity of a checkpoint, used throughout the
217
+ limits section below. The FeeLib value is a holdover from the pre-checkpoint
218
+ `BLOBS_PER_BLOCK`, so the fee model prices half of a full checkpoint's blobs.
148
219
 
149
220
  ## Gas and Data Limits
150
221
 
@@ -196,7 +267,7 @@ advertises them in `NodeInfo.txsLimits` (a required field); wallets read it and
196
267
  `GasSettings.fallback` as the default gas limits when sending without explicit limits, and they are enforced
197
268
  by `GasLimitsValidator` (clamped to the per-tx protocol maxima) at three points: RPC tx acceptance
198
269
  (`aztec-node/src/aztec-node/server.ts`), gossip validation (`p2p/src/services/libp2p/libp2p_service.ts`),
199
- and pending-pool admission (`p2p/src/client/factory.ts`). They are deliberately *not* enforced at reqresp or
270
+ and pending-pool admission (`p2p/src/client/factory.ts`). They are deliberately *not* enforced at req/resp or
200
271
  block-proposal validation — admission is relay policy, not block validity.
201
272
 
202
273
  ### Per-block builder budgets
@@ -240,7 +311,8 @@ The outermost limits, enforced as proposal validity in `validateCheckpointLimits
240
311
 
241
312
  ## TypeScript Types
242
313
 
243
- - **`Gas`** — mana quantity in two dimensions (`daGas`, `l2Gas`).
314
+ - **`Gas`** — gas quantity in two dimensions (`daGas`, `l2Gas`).
244
315
  - **`GasFees`** — per-unit price in each dimension (`feePerDaGas`, `feePerL2Gas`).
245
316
  - **`GasSettings`** — sender-chosen fee parameters: gas limits, teardown limits, max fees, priority fees.
246
317
  - **`GasUsed`** — actual consumption after execution. Note: `billedGas` uses the teardown gas *limit*, not actual usage.
318
+ - **`fee_math.ts`** — TypeScript port of the FeeLib formulas, used for fee prediction over the oracle LAG window.
@@ -10,8 +10,8 @@ import type {
10
10
  PrivateKernelInner3CircuitPrivateInputs,
11
11
  PrivateKernelInnerCircuitPrivateInputs,
12
12
  PrivateKernelResetCircuitPrivateInputs,
13
+ PrivateKernelResetTailCircuitPrivateInputs,
13
14
  PrivateKernelSimulateOutput,
14
- PrivateKernelTailCircuitPrivateInputs,
15
15
  PrivateKernelTailCircuitPublicInputs,
16
16
  } from '../kernel/index.js';
17
17
  import type { ChonkProofWithPublicInputs } from '../proofs/chonk_proof.js';
@@ -166,23 +166,21 @@ export interface PrivateKernelProver {
166
166
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>>;
167
167
 
168
168
  /**
169
- * Creates a proof output based on the last inner kernel iteration kernel data for the final ordering iteration.
169
+ * Creates a proof output for the terminal reset+tail step. Dispatches to the rollup-bound or
170
+ * public-bound family based on `inputs.isForPublic()`.
170
171
  *
171
- * @param privateKernelInputsTail - The private input data structure for the final ordering iteration.
172
- * @returns A Promise resolving to a ProofOutput object containing public inputs and the kernel proof.
172
+ * @param privateKernelInputs - Reset hints, dimensions, and tail params.
173
+ * @returns A Promise resolving to a ProofOutput containing the tail-shaped public inputs.
173
174
  */
174
- generateTailOutput(
175
- privateKernelInputsTail: PrivateKernelTailCircuitPrivateInputs,
175
+ generateResetTailOutput(
176
+ privateKernelInputs: PrivateKernelResetTailCircuitPrivateInputs,
176
177
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>>;
177
178
 
178
179
  /**
179
- * Executes the final ordering iteration circuit.
180
- *
181
- * @param privateKernelInputsTail - The private input data structure for the final ordering iteration.
182
- * @returns A Promise resolving to a ProofOutput object containing public inputs an empty kernel proof.
180
+ * Simulates the terminal reset+tail step without generating a proof.
183
181
  */
184
- simulateTail(
185
- privateKernelInputsTail: PrivateKernelTailCircuitPrivateInputs,
182
+ simulateResetTail(
183
+ privateKernelInputs: PrivateKernelResetTailCircuitPrivateInputs,
186
184
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>>;
187
185
 
188
186
  generateHidingToRollupOutput(
@@ -1,5 +1,5 @@
1
1
  import {
2
- AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
2
+ AVM_V2_PROOF_LENGTH_IN_FIELDS,
3
3
  NESTED_RECURSIVE_PROOF_LENGTH,
4
4
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
5
5
  RECURSIVE_PROOF_LENGTH,
@@ -204,7 +204,7 @@ export type ProvingJobInputsMap = {
204
204
  export const ProvingJobResult = z.discriminatedUnion('type', [
205
205
  z.object({
206
206
  type: z.literal(ProvingRequestType.PUBLIC_VM),
207
- result: RecursiveProof.schemaFor(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED),
207
+ result: RecursiveProof.schemaFor(AVM_V2_PROOF_LENGTH_IN_FIELDS),
208
208
  }),
209
209
  z.object({
210
210
  type: z.literal(ProvingRequestType.PUBLIC_CHONK_VERIFIER),
@@ -319,7 +319,7 @@ export const ProvingJobResult = z.discriminatedUnion('type', [
319
319
  ]);
320
320
  export type ProvingJobResult = z.infer<typeof ProvingJobResult>;
321
321
  export type ProvingJobResultsMap = {
322
- [ProvingRequestType.PUBLIC_VM]: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>;
322
+ [ProvingRequestType.PUBLIC_VM]: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>;
323
323
  [ProvingRequestType.PUBLIC_CHONK_VERIFIER]: PublicInputsAndRecursiveProof<
324
324
  PublicChonkVerifierPublicInputs,
325
325
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
@@ -1,5 +1,5 @@
1
1
  import type {
2
- AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
2
+ AVM_V2_PROOF_LENGTH_IN_FIELDS,
3
3
  NESTED_RECURSIVE_PROOF_LENGTH,
4
4
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
5
5
  RECURSIVE_PROOF_LENGTH,
@@ -189,7 +189,7 @@ export interface ServerCircuitProver {
189
189
  inputs: AvmCircuitInputs,
190
190
  signal?: AbortSignal,
191
191
  epochNumber?: number,
192
- ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>>;
192
+ ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>>;
193
193
  }
194
194
 
195
195
  export type IVCProofVerificationResult = {
@@ -1,8 +1,7 @@
1
- import { isDefined } from '@aztec/foundation/types';
2
-
3
1
  import {
4
2
  PrivateKernelResetDimensions,
5
3
  type PrivateKernelResetDimensionsConfig,
4
+ type ResetCatalogEntry,
6
5
  privateKernelResetDimensionNames,
7
6
  } from '../private_kernel_reset_dimensions.js';
8
7
 
@@ -12,13 +11,6 @@ interface DimensionOption {
12
11
  remainder?: PrivateKernelResetDimensions;
13
12
  }
14
13
 
15
- function computeCost(dimensions: PrivateKernelResetDimensions, config: PrivateKernelResetDimensionsConfig) {
16
- return privateKernelResetDimensionNames.reduce(
17
- (accum, name) => accum + dimensions[name] * config.dimensions[name].cost,
18
- 0,
19
- );
20
- }
21
-
22
14
  function getSize(dimensions: PrivateKernelResetDimensions) {
23
15
  return privateKernelResetDimensionNames.reduce((accum, name) => accum + dimensions[name], 0);
24
16
  }
@@ -38,124 +30,42 @@ function getRemainder(
38
30
  return remainingDimensions ? remainder : undefined;
39
31
  }
40
32
 
41
- function pickFromValues(targetValue: number, values: number[]) {
42
- // Find the min value in `values` that's greater than or equal to `targetValue`.
43
- const minGte = values.reduce(
44
- (prev: number | undefined, curr) => (curr >= targetValue && (prev === undefined || curr < prev) ? curr : prev),
45
- undefined,
46
- );
47
-
48
- // If no such value is found, returns the max value.
49
- return minGte ?? Math.max(...values);
50
- }
51
-
52
- function pickCheapest(options: DimensionOption[]) {
53
- return options.reduce((prev, curr) => (curr.cost < prev.cost ? curr : prev), options[0]);
54
- }
55
-
56
- function pickSmallestRemainder(options: DimensionOption[]) {
57
- const optionsWithSize = options
58
- .filter(o => o.remainder)
59
- .map(option => ({ option, size: getSize(option.remainder!) }));
60
- return optionsWithSize.reduce((prev, curr) => (curr.size < prev.size ? curr : prev), optionsWithSize[0])?.option;
61
- }
62
-
63
- function pickBestOption(options: DimensionOption[]) {
64
- const optionsResetAll = options.filter(opt => !opt.remainder);
65
- const optionsResetPartial = options.filter(opt => opt.remainder);
66
- // The best option is the cheapest one that can reset all dimensions.
67
- // If no such option exists, find one that can reset the most data.
68
- return pickCheapest(optionsResetAll) || pickSmallestRemainder(optionsResetPartial);
69
- }
70
-
71
- function findVariant(
72
- requestedDimensions: PrivateKernelResetDimensions,
73
- config: PrivateKernelResetDimensionsConfig,
74
- isQualified: (dimensions: PrivateKernelResetDimensions) => boolean,
75
- ): DimensionOption | undefined {
76
- const variant = PrivateKernelResetDimensions.empty();
77
- privateKernelResetDimensionNames.forEach(name => {
78
- variant[name] = pickFromValues(requestedDimensions[name], config.dimensions[name].variants);
79
- });
80
- if (!isQualified(variant)) {
81
- return;
33
+ // Returns the cheapest option that fully covers the request, or the option with the smallest
34
+ // remainder if none do. Caller must pass a non-empty list.
35
+ function pickBestOption(options: DimensionOption[]): DimensionOption {
36
+ const fullCoverage = options.filter(opt => !opt.remainder);
37
+ if (fullCoverage.length) {
38
+ return fullCoverage.reduce((prev, curr) => (curr.cost < prev.cost ? curr : prev));
82
39
  }
83
-
84
- return {
85
- dimensions: variant,
86
- cost: computeCost(variant, config),
87
- remainder: getRemainder(requestedDimensions, variant),
88
- };
40
+ return options.reduce((prev, curr) => (getSize(curr.remainder!) < getSize(prev.remainder!) ? curr : prev));
89
41
  }
90
42
 
91
- function findStandalone(
92
- requestedDimensions: PrivateKernelResetDimensions,
93
- config: PrivateKernelResetDimensionsConfig,
94
- isQualified: (dimensions: PrivateKernelResetDimensions) => boolean,
95
- ): DimensionOption | undefined {
96
- const needsReset = privateKernelResetDimensionNames.filter(name => requestedDimensions[name] > 0);
97
- if (needsReset.length !== 1) {
98
- // At the moment, we only use standalone to reset one dimension when it's about to overflow.
99
- return;
100
- }
101
-
102
- const name = needsReset[0];
103
- const value = pickFromValues(requestedDimensions[name], config.dimensions[name].standalone);
104
- if (!value) {
105
- return;
106
- }
107
-
108
- const dimensions = PrivateKernelResetDimensions.from({ [name]: value });
109
- if (!isQualified(dimensions)) {
110
- return;
111
- }
112
-
43
+ function buildOption(entry: ResetCatalogEntry, requestedDimensions: PrivateKernelResetDimensions): DimensionOption {
44
+ const dimensions = PrivateKernelResetDimensions.fromValues(entry.dimensions);
113
45
  return {
114
46
  dimensions,
115
- cost: computeCost(dimensions, config),
47
+ cost: entry.cost,
116
48
  remainder: getRemainder(requestedDimensions, dimensions),
117
49
  };
118
50
  }
119
51
 
120
- function findSpecialCase(
121
- requestedDimensions: PrivateKernelResetDimensions,
122
- config: PrivateKernelResetDimensionsConfig,
123
- isQualified: (dimensions: PrivateKernelResetDimensions) => boolean,
124
- ): DimensionOption | undefined {
125
- const specialCases = config.specialCases.map(PrivateKernelResetDimensions.fromValues);
126
- const options = specialCases.filter(isQualified).map(dimensions => ({
127
- dimensions,
128
- cost: computeCost(dimensions, config),
129
- remainder: getRemainder(requestedDimensions, dimensions),
130
- }));
131
- return pickBestOption(options);
132
- }
52
+ /**
53
+ * Picks which catalog group the selector should search. Mid-tx resets go to `inner` (no
54
+ * siloing); terminal kernels go to `finalTail` or `finalTailToPublic`, depending on whether
55
+ * the tx has public function calls.
56
+ */
57
+ export type ResetDimensionsMode = 'inner' | 'finalTail' | 'finalTailToPublic';
133
58
 
134
59
  export function findPrivateKernelResetDimensions(
135
60
  requestedDimensions: PrivateKernelResetDimensions,
136
61
  config: PrivateKernelResetDimensionsConfig,
137
- isInner = false,
62
+ mode: ResetDimensionsMode,
138
63
  allowRemainder = false,
139
64
  ) {
140
- const requestedValues = requestedDimensions.toValues();
141
- const isEnough = allowRemainder
142
- ? () => true
143
- : (dimensions: PrivateKernelResetDimensions) => dimensions.toValues().every((v, i) => v >= requestedValues[i]);
144
-
145
- const isQualified = !isInner
146
- ? isEnough
147
- : // If isInner is true, it's a reset to prevent overflow. The following must be zero because siloing can't be done at the moment.
148
- (dimensions: PrivateKernelResetDimensions) =>
149
- dimensions.NOTE_HASH_SILOING === 0 &&
150
- dimensions.NULLIFIER_SILOING === 0 &&
151
- dimensions.PRIVATE_LOG_SILOING === 0 &&
152
- isEnough(dimensions);
153
-
154
- const options = [
155
- findVariant(requestedDimensions, config, isQualified),
156
- findStandalone(requestedDimensions, config, isQualified),
157
- findSpecialCase(requestedDimensions, config, isQualified),
158
- ].filter(isDefined);
65
+ const catalog = config[mode];
66
+ const options = catalog
67
+ .map(entry => buildOption(entry, requestedDimensions))
68
+ .filter(option => allowRemainder || !option.remainder);
159
69
 
160
70
  if (!options.length) {
161
71
  throw new Error(`Cannot find an option for dimension: ${requestedDimensions.toValues()}`);
@@ -14,7 +14,7 @@ export * from './private_kernel_inner_2_circuit_private_inputs.js';
14
14
  export * from './private_kernel_inner_3_circuit_private_inputs.js';
15
15
  export * from './private_kernel_reset_circuit_private_inputs.js';
16
16
  export * from './private_kernel_reset_dimensions.js';
17
- export * from './private_kernel_tail_circuit_private_inputs.js';
17
+ export * from './private_kernel_reset_tail_circuit_private_inputs.js';
18
18
  export * from './private_kernel_tail_circuit_public_inputs.js';
19
19
  export * from './private_to_avm_accumulated_data.js';
20
20
  export * from './private_to_public_accumulated_data.js';
@@ -144,6 +144,11 @@ export class PrivateCircuitPublicInputs {
144
144
  * Hash of the contract class logs emitted in this function call.
145
145
  */
146
146
  public contractClassLogsHashes: ClaimedLengthArray<CountedLogHash, typeof MAX_CONTRACT_CLASS_LOGS_PER_CALL>,
147
+ /**
148
+ * The tx request's salt. Keeps `tx_request.hash()` (the protocol nullifier) unpredictable, and lets the init
149
+ * kernel bind this proof to a specific tx request (it asserts this equals `tx_request.salt`).
150
+ */
151
+ public txRequestSalt: Fr,
147
152
  ) {}
148
153
 
149
154
  /**
@@ -188,6 +193,7 @@ export class PrivateCircuitPublicInputs {
188
193
  reader.readObject(ClaimedLengthArrayFromBuffer(CountedL2ToL1Message, MAX_L2_TO_L1_MSGS_PER_CALL)),
189
194
  reader.readObject(ClaimedLengthArrayFromBuffer(PrivateLogData, MAX_PRIVATE_LOGS_PER_CALL)),
190
195
  reader.readObject(ClaimedLengthArrayFromBuffer(CountedLogHash, MAX_CONTRACT_CLASS_LOGS_PER_CALL)),
196
+ reader.readObject(Fr),
191
197
  );
192
198
  }
193
199
 
@@ -219,6 +225,7 @@ export class PrivateCircuitPublicInputs {
219
225
  reader.readObject(ClaimedLengthArrayFromFields(CountedL2ToL1Message, MAX_L2_TO_L1_MSGS_PER_CALL)),
220
226
  reader.readObject(ClaimedLengthArrayFromFields(PrivateLogData, MAX_PRIVATE_LOGS_PER_CALL)),
221
227
  reader.readObject(ClaimedLengthArrayFromFields(CountedLogHash, MAX_CONTRACT_CLASS_LOGS_PER_CALL)),
228
+ reader.readField(),
222
229
  );
223
230
  }
224
231
 
@@ -251,6 +258,7 @@ export class PrivateCircuitPublicInputs {
251
258
  ClaimedLengthArray.empty(CountedL2ToL1Message, MAX_L2_TO_L1_MSGS_PER_CALL),
252
259
  ClaimedLengthArray.empty(PrivateLogData, MAX_PRIVATE_LOGS_PER_CALL),
253
260
  ClaimedLengthArray.empty(CountedLogHash, MAX_CONTRACT_CLASS_LOGS_PER_CALL),
261
+ Fr.ZERO,
254
262
  );
255
263
  }
256
264
 
@@ -278,7 +286,8 @@ export class PrivateCircuitPublicInputs {
278
286
  this.nullifiers.isEmpty() &&
279
287
  this.l2ToL1Msgs.isEmpty() &&
280
288
  this.privateLogs.isEmpty() &&
281
- this.contractClassLogsHashes.isEmpty()
289
+ this.contractClassLogsHashes.isEmpty() &&
290
+ this.txRequestSalt.isZero()
282
291
  );
283
292
  }
284
293
 
@@ -312,6 +321,7 @@ export class PrivateCircuitPublicInputs {
312
321
  fields.l2ToL1Msgs,
313
322
  fields.privateLogs,
314
323
  fields.contractClassLogsHashes,
324
+ fields.txRequestSalt,
315
325
  ] as const;
316
326
  }
317
327
 
@@ -346,6 +356,7 @@ export class PrivateCircuitPublicInputs {
346
356
  this.l2ToL1Msgs,
347
357
  this.privateLogs,
348
358
  this.contractClassLogsHashes,
359
+ this.txRequestSalt,
349
360
  ]);
350
361
  }
351
362
 
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/curves/bn254';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { serializeToFields } from '@aztec/foundation/serialize';
3
3
 
4
4
  import { BlockHeader } from '../tx/block_header.js';
@@ -11,13 +11,20 @@ export class PrivateContextInputs {
11
11
  public anchorBlockHeader: BlockHeader,
12
12
  public txContext: TxContext,
13
13
  public startSideEffectCounter: number,
14
+ public txRequestSalt: Fr,
14
15
  ) {}
15
16
 
16
17
  public static empty(): PrivateContextInputs {
17
- return new PrivateContextInputs(CallContext.empty(), BlockHeader.empty(), TxContext.empty(), 0);
18
+ return new PrivateContextInputs(CallContext.empty(), BlockHeader.empty(), TxContext.empty(), 0, Fr.ZERO);
18
19
  }
19
20
 
20
21
  public toFields(): Fr[] {
21
- return serializeToFields([this.callContext, this.anchorBlockHeader, this.txContext, this.startSideEffectCounter]);
22
+ return serializeToFields([
23
+ this.callContext,
24
+ this.anchorBlockHeader,
25
+ this.txContext,
26
+ this.startSideEffectCounter,
27
+ this.txRequestSalt,
28
+ ]);
22
29
  }
23
30
  }
@@ -115,3 +115,12 @@ export class PrivateKernelCircuitPublicInputs {
115
115
  );
116
116
  }
117
117
  }
118
+
119
+ /**
120
+ * Returns true iff the tx requires the public-bound terminal path: it has either un-processed
121
+ * public-call requests in the side-effect stream or a pending public-teardown call request. Every
122
+ * site picking between the rollup-bound and public-bound terminal artifact must route through this.
123
+ */
124
+ export function kernelStateIsForPublic(publicInputs: PrivateKernelCircuitPublicInputs): boolean {
125
+ return publicInputs.end.publicCallRequests.claimedLength > 0 || !publicInputs.publicTeardownCallRequest.isEmpty();
126
+ }
@@ -17,7 +17,6 @@ export class PrivateKernelInit2CircuitPrivateInputs {
17
17
  public privateCall0: PrivateCallData,
18
18
  public privateCall1: PrivateCallData,
19
19
  public isPrivateOnly: boolean,
20
- public firstNullifierHint: Fr,
21
20
  public revertibleCounterHint: number,
22
21
  ) {}
23
22
 
@@ -28,7 +27,6 @@ export class PrivateKernelInit2CircuitPrivateInputs {
28
27
  this.protocolContracts,
29
28
  this.privateCall0,
30
29
  this.privateCall1,
31
- this.firstNullifierHint,
32
30
  this.revertibleCounterHint,
33
31
  );
34
32
  }
@@ -42,7 +40,6 @@ export class PrivateKernelInit2CircuitPrivateInputs {
42
40
  reader.readObject(PrivateCallData),
43
41
  reader.readObject(PrivateCallData),
44
42
  reader.readBoolean(),
45
- Fr.fromBuffer(reader),
46
43
  reader.readNumber(),
47
44
  );
48
45
  }
@@ -18,7 +18,6 @@ export class PrivateKernelInit3CircuitPrivateInputs {
18
18
  public privateCall1: PrivateCallData,
19
19
  public privateCall2: PrivateCallData,
20
20
  public isPrivateOnly: boolean,
21
- public firstNullifierHint: Fr,
22
21
  public revertibleCounterHint: number,
23
22
  ) {}
24
23
 
@@ -30,7 +29,6 @@ export class PrivateKernelInit3CircuitPrivateInputs {
30
29
  this.privateCall0,
31
30
  this.privateCall1,
32
31
  this.privateCall2,
33
- this.firstNullifierHint,
34
32
  this.revertibleCounterHint,
35
33
  );
36
34
  }
@@ -45,7 +43,6 @@ export class PrivateKernelInit3CircuitPrivateInputs {
45
43
  reader.readObject(PrivateCallData),
46
44
  reader.readObject(PrivateCallData),
47
45
  reader.readBoolean(),
48
- Fr.fromBuffer(reader),
49
46
  reader.readNumber(),
50
47
  );
51
48
  }