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

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.
@@ -1,5 +1,5 @@
1
1
  import type { Fr } from '@aztec/foundation/curves/bn254';
2
- import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
2
+ import { GrumpkinScalar, type Point } from '@aztec/foundation/curves/grumpkin';
3
3
  import type { AztecAddress } from '../aztec-address/index.js';
4
4
  import type { PublicKey } from '../keys/public_key.js';
5
5
  /**
@@ -28,4 +28,14 @@ export declare function appSiloEcdhSharedSecret(secretKey: GrumpkinScalar, publi
28
28
  * @param app - The contract address to silo to.
29
29
  */
30
30
  export declare function appSiloEcdhSharedSecretPoint(point: Point, app: AztecAddress): Promise<Fr>;
31
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2hhcmVkX3NlY3JldF9kZXJpdmF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbG9ncy9zaGFyZWRfc2VjcmV0X2Rlcml2YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDekQsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLEtBQUssRUFBRSxNQUFNLG1DQUFtQyxDQUFDO0FBRS9FLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRXZEOzs7O0dBSUc7QUFDSCx3QkFBZ0IsMkJBQTJCLENBQUMsU0FBUyxFQUFFLGNBQWMsRUFBRSxTQUFTLEVBQUUsU0FBUyxHQUFHLE9BQU8sQ0FBQyxLQUFLLENBQUMsQ0FPM0c7QUFFRDs7Ozs7Ozs7O0dBU0c7QUFDSCx3QkFBc0IsdUJBQXVCLENBQzNDLFNBQVMsRUFBRSxjQUFjLEVBQ3pCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLGVBQWUsRUFBRSxZQUFZLEdBQzVCLE9BQU8sQ0FBQyxFQUFFLENBQUMsQ0FHYjtBQUVEOzs7Ozs7O0dBT0c7QUFDSCx3QkFBZ0IsNEJBQTRCLENBQUMsS0FBSyxFQUFFLEtBQUssRUFBRSxHQUFHLEVBQUUsWUFBWSxHQUFHLE9BQU8sQ0FBQyxFQUFFLENBQUMsQ0FFekYifQ==
31
+ /**
32
+ * Protects a handshake's shared secret from being forged by the recipient: `S' = hash(ephPk, recipientPoint) * S`.
33
+ *
34
+ * Mirrors aztec-nr's `protect_from_forgery` and must stay byte-compatible with it.
35
+ *
36
+ * @param secret - The raw shared secret `S` to protect.
37
+ * @param ephPk - The handshake's ephemeral public key.
38
+ * @param recipientPoint - The recipient's address point.
39
+ */
40
+ export declare function protectFromForgery(secret: Point, ephPk: Point, recipientPoint: Point): Promise<Point>;
41
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2hhcmVkX3NlY3JldF9kZXJpdmF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbG9ncy9zaGFyZWRfc2VjcmV0X2Rlcml2YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDekQsT0FBTyxFQUFFLGNBQWMsRUFBRSxLQUFLLEtBQUssRUFBRSxNQUFNLG1DQUFtQyxDQUFDO0FBRS9FLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRXZEOzs7O0dBSUc7QUFDSCx3QkFBZ0IsMkJBQTJCLENBQUMsU0FBUyxFQUFFLGNBQWMsRUFBRSxTQUFTLEVBQUUsU0FBUyxHQUFHLE9BQU8sQ0FBQyxLQUFLLENBQUMsQ0FPM0c7QUFFRDs7Ozs7Ozs7O0dBU0c7QUFDSCx3QkFBc0IsdUJBQXVCLENBQzNDLFNBQVMsRUFBRSxjQUFjLEVBQ3pCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLGVBQWUsRUFBRSxZQUFZLEdBQzVCLE9BQU8sQ0FBQyxFQUFFLENBQUMsQ0FHYjtBQUVEOzs7Ozs7O0dBT0c7QUFDSCx3QkFBZ0IsNEJBQTRCLENBQUMsS0FBSyxFQUFFLEtBQUssRUFBRSxHQUFHLEVBQUUsWUFBWSxHQUFHLE9BQU8sQ0FBQyxFQUFFLENBQUMsQ0FFekY7QUFFRDs7Ozs7Ozs7R0FRRztBQUNILHdCQUFzQixrQkFBa0IsQ0FBQyxNQUFNLEVBQUUsS0FBSyxFQUFFLEtBQUssRUFBRSxLQUFLLEVBQUUsY0FBYyxFQUFFLEtBQUssR0FBRyxPQUFPLENBQUMsS0FBSyxDQUFDLENBTTNHIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"shared_secret_derivation.d.ts","sourceRoot":"","sources":["../../src/logs/shared_secret_derivation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAO3G;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,cAAc,EACzB,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,YAAY,GAC5B,OAAO,CAAC,EAAE,CAAC,CAGb;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,CAAC,CAEzF"}
1
+ {"version":3,"file":"shared_secret_derivation.d.ts","sourceRoot":"","sources":["../../src/logs/shared_secret_derivation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,KAAK,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAO3G;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,cAAc,EACzB,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,YAAY,GAC5B,OAAO,CAAC,EAAE,CAAC,CAGb;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,CAAC,CAEzF;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAM3G"}
@@ -1,6 +1,7 @@
1
1
  import { DomainSeparator } from '@aztec/constants';
2
2
  import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
3
3
  import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
4
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
4
5
  /**
5
6
  * Derives the raw ECDH shared secret point `S = secretKey * publicKey`.
6
7
  *
@@ -38,3 +39,20 @@ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
38
39
  app
39
40
  ], DomainSeparator.APP_SILOED_ECDH_SHARED_SECRET);
40
41
  }
42
+ /**
43
+ * Protects a handshake's shared secret from being forged by the recipient: `S' = hash(ephPk, recipientPoint) * S`.
44
+ *
45
+ * Mirrors aztec-nr's `protect_from_forgery` and must stay byte-compatible with it.
46
+ *
47
+ * @param secret - The raw shared secret `S` to protect.
48
+ * @param ephPk - The handshake's ephemeral public key.
49
+ * @param recipientPoint - The recipient's address point.
50
+ */ export async function protectFromForgery(secret, ephPk, recipientPoint) {
51
+ const scalar = await poseidon2HashWithSeparator([
52
+ ephPk.x,
53
+ ephPk.y,
54
+ recipientPoint.x,
55
+ recipientPoint.y
56
+ ], DomainSeparator.HANDSHAKE_FORGERY_PROTECTION);
57
+ return Grumpkin.mul(secret, new GrumpkinScalar(scalar.toBigInt()));
58
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/stdlib",
3
- "version": "5.0.0-nightly.20260713",
3
+ "version": "5.0.0-nightly.20260714",
4
4
  "type": "module",
5
5
  "inherits": [
6
6
  "../package.common.json",
@@ -92,13 +92,13 @@
92
92
  },
93
93
  "dependencies": {
94
94
  "@aws-sdk/client-s3": "^3.892.0",
95
- "@aztec/bb.js": "5.0.0-nightly.20260713",
96
- "@aztec/blob-lib": "5.0.0-nightly.20260713",
97
- "@aztec/constants": "5.0.0-nightly.20260713",
98
- "@aztec/ethereum": "5.0.0-nightly.20260713",
99
- "@aztec/foundation": "5.0.0-nightly.20260713",
100
- "@aztec/l1-artifacts": "5.0.0-nightly.20260713",
101
- "@aztec/noir-noirc_abi": "5.0.0-nightly.20260713",
95
+ "@aztec/bb.js": "5.0.0-nightly.20260714",
96
+ "@aztec/blob-lib": "5.0.0-nightly.20260714",
97
+ "@aztec/constants": "5.0.0-nightly.20260714",
98
+ "@aztec/ethereum": "5.0.0-nightly.20260714",
99
+ "@aztec/foundation": "5.0.0-nightly.20260714",
100
+ "@aztec/l1-artifacts": "5.0.0-nightly.20260714",
101
+ "@aztec/noir-noirc_abi": "5.0.0-nightly.20260714",
102
102
  "@google-cloud/storage": "^7.15.0",
103
103
  "axios": "^1.15.1",
104
104
  "json-stringify-deterministic": "1.0.12",
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.
@@ -2,7 +2,7 @@ import { DomainSeparator } from '@aztec/constants';
2
2
  import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
3
3
  import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
4
4
  import type { Fr } from '@aztec/foundation/curves/bn254';
5
- import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
5
+ import { GrumpkinScalar, type Point } from '@aztec/foundation/curves/grumpkin';
6
6
 
7
7
  import type { AztecAddress } from '../aztec-address/index.js';
8
8
  import type { PublicKey } from '../keys/public_key.js';
@@ -51,3 +51,20 @@ export async function appSiloEcdhSharedSecret(
51
51
  export function appSiloEcdhSharedSecretPoint(point: Point, app: AztecAddress): Promise<Fr> {
52
52
  return poseidon2HashWithSeparator([point.x, point.y, app], DomainSeparator.APP_SILOED_ECDH_SHARED_SECRET);
53
53
  }
54
+
55
+ /**
56
+ * Protects a handshake's shared secret from being forged by the recipient: `S' = hash(ephPk, recipientPoint) * S`.
57
+ *
58
+ * Mirrors aztec-nr's `protect_from_forgery` and must stay byte-compatible with it.
59
+ *
60
+ * @param secret - The raw shared secret `S` to protect.
61
+ * @param ephPk - The handshake's ephemeral public key.
62
+ * @param recipientPoint - The recipient's address point.
63
+ */
64
+ export async function protectFromForgery(secret: Point, ephPk: Point, recipientPoint: Point): Promise<Point> {
65
+ const scalar = await poseidon2HashWithSeparator(
66
+ [ephPk.x, ephPk.y, recipientPoint.x, recipientPoint.y],
67
+ DomainSeparator.HANDSHAKE_FORGERY_PROTECTION,
68
+ );
69
+ return Grumpkin.mul(secret, new GrumpkinScalar(scalar.toBigInt()));
70
+ }