@aztec/stdlib 6.0.0-nightly.20260723 → 6.0.0-nightly.20260725
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.
- package/dest/abi/abi.d.ts +8 -1
- package/dest/abi/abi.d.ts.map +1 -1
- package/dest/abi/contract_artifact.d.ts +1 -1
- package/dest/abi/contract_artifact.d.ts.map +1 -1
- package/dest/abi/contract_artifact.js +26 -8
- package/dest/hash/hash.d.ts +1 -2
- package/dest/hash/hash.d.ts.map +1 -1
- package/dest/hash/hash.js +0 -7
- package/dest/interfaces/archiver.d.ts +8 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +2 -1
- package/dest/interfaces/block-builder.d.ts +7 -2
- package/dest/interfaces/block-builder.d.ts.map +1 -1
- package/dest/interfaces/proving-job.d.ts +14 -1
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/proving-job.js +11 -2
- package/dest/keys/derivation.d.ts +1 -2
- package/dest/keys/derivation.d.ts.map +1 -1
- package/dest/keys/derivation.js +0 -7
- package/dest/logs/app_tagging_secret.d.ts +1 -1
- package/dest/logs/app_tagging_secret.d.ts.map +1 -1
- package/dest/logs/app_tagging_secret.js +4 -13
- package/dest/logs/shared_secret_derivation.d.ts +12 -2
- package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
- package/dest/logs/shared_secret_derivation.js +18 -0
- package/dest/messaging/l1_to_l2_message.d.ts +23 -2
- package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
- package/dest/messaging/l1_to_l2_message.js +36 -11
- package/dest/noir/index.d.ts +3 -3
- package/dest/noir/index.d.ts.map +1 -1
- package/dest/rollup/checkpoint_rollup_public_inputs.d.ts +1 -1
- package/dest/world-state/genesis_data.d.ts +9 -1
- package/dest/world-state/genesis_data.d.ts.map +1 -1
- package/dest/world-state/genesis_data.js +1 -0
- package/package.json +8 -8
- package/src/abi/abi.ts +8 -0
- package/src/abi/contract_artifact.ts +33 -9
- package/src/gas/README.md +108 -36
- package/src/hash/hash.ts +0 -8
- package/src/interfaces/archiver.ts +8 -0
- package/src/interfaces/block-builder.ts +6 -1
- package/src/interfaces/proving-job.ts +12 -0
- package/src/keys/derivation.ts +0 -5
- package/src/logs/app_tagging_secret.ts +8 -17
- package/src/logs/shared_secret_derivation.ts +18 -1
- package/src/messaging/l1_to_l2_message.ts +51 -13
- package/src/noir/index.ts +2 -1
- package/src/world-state/genesis_data.ts +10 -0
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
|
|
5
|
-
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
44
|
-
congestionCost
|
|
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
|
|
54
|
-
|
|
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
|
|
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,
|
|
74
|
-
`slotOfChange + (LIFETIME - LAG)`
|
|
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
|
|
121
|
-
`ethPerFeeAsset` (1e12 precision)
|
|
122
|
-
|
|
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
|
|
140
|
-
|
|
|
141
|
-
| `L1_GAS_PER_CHECKPOINT_PROPOSED` | 300,000
|
|
142
|
-
| `L1_GAS_PER_EPOCH_VERIFIED` | 3,600,000
|
|
143
|
-
| `BLOBS_PER_CHECKPOINT`
|
|
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
|
|
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`** —
|
|
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.
|
package/src/hash/hash.ts
CHANGED
|
@@ -188,14 +188,6 @@ export function computeSecretHash(secret: Fr): Promise<Fr> {
|
|
|
188
188
|
return poseidon2HashWithSeparator([secret], DomainSeparator.SECRET_HASH);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
export async function computeL1ToL2MessageNullifier(contract: AztecAddress, messageHash: Fr, secret: Fr) {
|
|
192
|
-
const innerMessageNullifier = await poseidon2HashWithSeparator(
|
|
193
|
-
[messageHash, secret],
|
|
194
|
-
DomainSeparator.MESSAGE_NULLIFIER,
|
|
195
|
-
);
|
|
196
|
-
return siloNullifier(contract, innerMessageNullifier);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
191
|
/**
|
|
200
192
|
* Calculates a siloed hash of a scoped l2 to l1 message.
|
|
201
193
|
* @returns Fr containing 248 bits of information of sha256 hash.
|
|
@@ -68,6 +68,13 @@ export type ArchiverSpecificConfig = {
|
|
|
68
68
|
|
|
69
69
|
/** Skip pruning orphan proposed blocks that have no matching proposed checkpoint. */
|
|
70
70
|
skipOrphanProposedBlockPruning?: boolean;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Preload the standard contracts (AuthRegistry, PublicChecks, HandshakeRegistry) into the contract store at block 0.
|
|
74
|
+
* For test environments only: it must only be set when genesis also seeds the matching registration/deployment
|
|
75
|
+
* nullifiers, otherwise a later on-chain publish of a preloaded class would collide with the block-0 preload.
|
|
76
|
+
*/
|
|
77
|
+
testPreloadStandardContracts?: boolean;
|
|
71
78
|
};
|
|
72
79
|
|
|
73
80
|
export const ArchiverSpecificConfigSchema = z.object({
|
|
@@ -82,6 +89,7 @@ export const ArchiverSpecificConfigSchema = z.object({
|
|
|
82
89
|
skipPromoteProposedCheckpointDuringL1Sync: z.boolean().optional(),
|
|
83
90
|
orphanPruneNoProposalTolerance: schemas.Integer.optional(),
|
|
84
91
|
skipOrphanProposedBlockPruning: z.boolean().optional(),
|
|
92
|
+
testPreloadStandardContracts: z.boolean().optional(),
|
|
85
93
|
});
|
|
86
94
|
|
|
87
95
|
export type ArchiverApi = Omit<
|
|
@@ -2,6 +2,7 @@ import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-ty
|
|
|
2
2
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
4
4
|
|
|
5
|
+
import type { BlockHash } from '../block/block_hash.js';
|
|
5
6
|
import type { L2Block } from '../block/l2_block.js';
|
|
6
7
|
import type { ChainConfig, SequencerConfig } from '../config/chain-config.js';
|
|
7
8
|
import type { L1RollupConstants } from '../epoch-helpers/index.js';
|
|
@@ -143,7 +144,11 @@ export interface ICheckpointBlockBuilder {
|
|
|
143
144
|
|
|
144
145
|
/** Interface for creating checkpoint builders. */
|
|
145
146
|
export interface ICheckpointsBuilder {
|
|
146
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Syncs world state to `blockNumber` and returns a fork of it at that block. When `blockHash` is
|
|
149
|
+
* provided it is verified against the synced block, triggering a resync on mismatch (reorg detection).
|
|
150
|
+
*/
|
|
151
|
+
getFork(blockNumber: BlockNumber, blockHash?: BlockHash): Promise<MerkleTreeWriteOperations>;
|
|
147
152
|
|
|
148
153
|
startCheckpoint(
|
|
149
154
|
checkpointNumber: CheckpointNumber,
|
|
@@ -441,9 +441,20 @@ export const ProvingJobRejectedResult = z.object({
|
|
|
441
441
|
});
|
|
442
442
|
export type ProvingJobRejectedResult = z.infer<typeof ProvingJobRejectedResult>;
|
|
443
443
|
|
|
444
|
+
/**
|
|
445
|
+
* The result of a job that was cancelled by its producer. Unlike a fulfilled or rejected result it
|
|
446
|
+
* is not truly terminal: re-enqueuing the same job id revives it, so an abort never permanently
|
|
447
|
+
* blocks a proof from being produced.
|
|
448
|
+
*/
|
|
449
|
+
export const ProvingJobAbortedResult = z.object({
|
|
450
|
+
status: z.literal('aborted'),
|
|
451
|
+
});
|
|
452
|
+
export type ProvingJobAbortedResult = z.infer<typeof ProvingJobAbortedResult>;
|
|
453
|
+
|
|
444
454
|
export const ProvingJobSettledResult = z.discriminatedUnion('status', [
|
|
445
455
|
ProvingJobFulfilledResult,
|
|
446
456
|
ProvingJobRejectedResult,
|
|
457
|
+
ProvingJobAbortedResult,
|
|
447
458
|
]);
|
|
448
459
|
export type ProvingJobSettledResult = z.infer<typeof ProvingJobSettledResult>;
|
|
449
460
|
|
|
@@ -453,5 +464,6 @@ export const ProvingJobStatus = z.discriminatedUnion('status', [
|
|
|
453
464
|
z.object({ status: z.literal('not-found') }),
|
|
454
465
|
ProvingJobFulfilledResult,
|
|
455
466
|
ProvingJobRejectedResult,
|
|
467
|
+
ProvingJobAbortedResult,
|
|
456
468
|
]);
|
|
457
469
|
export type ProvingJobStatus = z.infer<typeof ProvingJobStatus>;
|
package/src/keys/derivation.ts
CHANGED
|
@@ -50,11 +50,6 @@ export function deriveMasterFallbackSecretKey(secretKey: Fr): GrumpkinScalar {
|
|
|
50
50
|
return sha512ToGrumpkinScalar([secretKey, DomainSeparator.FBSK_M]);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export function deriveSigningKey(secretKey: Fr): GrumpkinScalar {
|
|
54
|
-
// TODO(#5837): come up with a standard signing key derivation scheme instead of using ivsk_m as signing keys here
|
|
55
|
-
return sha512ToGrumpkinScalar([secretKey, DomainSeparator.IVSK_M]);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
53
|
export function computePreaddress(publicKeysHash: Fr, partialAddress: Fr) {
|
|
59
54
|
return poseidon2HashWithSeparator([publicKeysHash, partialAddress], DomainSeparator.CONTRACT_ADDRESS_V2);
|
|
60
55
|
}
|
|
@@ -89,29 +89,20 @@ export class AppTaggingSecret {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
toString(): string {
|
|
92
|
-
// TODO(F-680): Migrate stored tagging keys and remove the legacy unconstrained format.
|
|
93
|
-
if (this.kind === AppTaggingSecretKind.UNCONSTRAINED) {
|
|
94
|
-
return `${this.secret.toString()}:${this.app.toString()}`;
|
|
95
|
-
}
|
|
96
92
|
return `${this.kind}:${this.secret.toString()}:${this.app.toString()}`;
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
static fromString(str: string): AppTaggingSecret {
|
|
100
96
|
const parts = str.split(':');
|
|
101
|
-
if (parts.length
|
|
102
|
-
|
|
103
|
-
const [secretStr, appStr] = parts;
|
|
104
|
-
return new AppTaggingSecret(Fr.fromString(secretStr), AztecAddress.fromStringUnsafe(appStr));
|
|
105
|
-
}
|
|
106
|
-
if (parts.length === 3) {
|
|
107
|
-
const [kindStr, secretStr, appStr] = parts;
|
|
108
|
-
return new AppTaggingSecret(
|
|
109
|
-
Fr.fromString(secretStr),
|
|
110
|
-
AztecAddress.fromStringUnsafe(appStr),
|
|
111
|
-
appTaggingSecretKindFromString(kindStr),
|
|
112
|
-
);
|
|
97
|
+
if (parts.length !== 3) {
|
|
98
|
+
throw new Error(`Invalid AppTaggingSecret string: ${str}`);
|
|
113
99
|
}
|
|
114
|
-
|
|
100
|
+
const [kindStr, secretStr, appStr] = parts;
|
|
101
|
+
return new AppTaggingSecret(
|
|
102
|
+
Fr.fromString(secretStr),
|
|
103
|
+
AztecAddress.fromStringUnsafe(appStr),
|
|
104
|
+
appTaggingSecretKindFromString(kindStr),
|
|
105
|
+
);
|
|
115
106
|
}
|
|
116
107
|
}
|
|
117
108
|
|
|
@@ -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
|
|
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
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { DomainSeparator, type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
2
3
|
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
3
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
@@ -7,7 +8,7 @@ import { SiblingPath } from '@aztec/foundation/trees';
|
|
|
7
8
|
|
|
8
9
|
import type { AztecAddress } from '../aztec-address/index.js';
|
|
9
10
|
import type { BlockParameter } from '../block/block_parameter.js';
|
|
10
|
-
import {
|
|
11
|
+
import { siloNullifier } from '../hash/hash.js';
|
|
11
12
|
import type { AztecNode } from '../interfaces/aztec-node.js';
|
|
12
13
|
import { MerkleTreeId } from '../trees/merkle_tree_id.js';
|
|
13
14
|
import { L1Actor } from './l1_actor.js';
|
|
@@ -74,28 +75,65 @@ export class L1ToL2Message {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The unsiloed nullifier a message consumer derives, together with the contract address needed to silo it.
|
|
80
|
+
*/
|
|
81
|
+
export interface UnsiloedMessageNullifier {
|
|
82
|
+
contractAddress: AztecAddress;
|
|
83
|
+
nullifier: Fr;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Computes the unsiloed nullifier that the fee juice contract (and any consumer following the same scheme) derives when
|
|
88
|
+
* consuming an L1 to L2 message.
|
|
89
|
+
*
|
|
90
|
+
* This is not a general-purpose utility: other contracts may derive the secret hash and hence the nullifier
|
|
91
|
+
* differently. The result is unsiloed — callers silo it (with the consuming contract's address) before looking it up
|
|
92
|
+
* in the nullifier tree.
|
|
93
|
+
*/
|
|
94
|
+
export function computeFeeJuiceMessageNullifier(messageHash: Fr, secret: Fr): Promise<Fr> {
|
|
95
|
+
return poseidon2HashWithSeparator([messageHash, secret], DomainSeparator.MESSAGE_NULLIFIER);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Fetches the membership witness of an L1 to L2 message. When `unsiloedNullifier` is provided, the message is
|
|
100
|
+
* additionally required to be un-nullified.
|
|
101
|
+
*/
|
|
102
|
+
export async function getL1ToL2MessageWitness(
|
|
79
103
|
node: AztecNode,
|
|
80
|
-
contractAddress: AztecAddress,
|
|
81
104
|
messageHash: Fr,
|
|
82
|
-
|
|
105
|
+
unsiloedNullifier?: UnsiloedMessageNullifier,
|
|
83
106
|
referenceBlock: BlockParameter = 'latest',
|
|
84
107
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
// Both requests are dispatched before awaiting so they run concurrently.
|
|
109
|
+
const l1ToL2ResponsePromise = node.getL1ToL2MessageMembershipWitness(referenceBlock, messageHash);
|
|
110
|
+
const nullifierResponsePromise = unsiloedNullifier
|
|
111
|
+
? siloNullifier(unsiloedNullifier.contractAddress, unsiloedNullifier.nullifier).then(siloed =>
|
|
112
|
+
node.findLeavesIndexes(referenceBlock, MerkleTreeId.NULLIFIER_TREE, [siloed]),
|
|
113
|
+
)
|
|
114
|
+
: undefined;
|
|
91
115
|
|
|
116
|
+
const l1ToL2Response = await l1ToL2ResponsePromise;
|
|
92
117
|
if (!l1ToL2Response) {
|
|
93
118
|
throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
94
119
|
}
|
|
95
120
|
|
|
96
|
-
|
|
121
|
+
const nullifierResponse = await nullifierResponsePromise;
|
|
122
|
+
if (nullifierResponse?.[0] !== undefined) {
|
|
97
123
|
throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
98
124
|
}
|
|
99
125
|
|
|
100
126
|
return l1ToL2Response;
|
|
101
127
|
}
|
|
128
|
+
|
|
129
|
+
// This functionality is not on the node because we do not want to pass the node the secret, and give the node the ability to derive a valid nullifer for an L1 to L2 message.
|
|
130
|
+
export async function getNonNullifiedL1ToL2MessageWitness(
|
|
131
|
+
node: AztecNode,
|
|
132
|
+
contractAddress: AztecAddress,
|
|
133
|
+
messageHash: Fr,
|
|
134
|
+
secret: Fr,
|
|
135
|
+
referenceBlock: BlockParameter = 'latest',
|
|
136
|
+
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
|
|
137
|
+
const nullifier = await computeFeeJuiceMessageNullifier(messageHash, secret);
|
|
138
|
+
return getL1ToL2MessageWitness(node, messageHash, { contractAddress, nullifier }, referenceBlock);
|
|
139
|
+
}
|
package/src/noir/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
ABIParameter,
|
|
3
3
|
ABIParameterVisibility,
|
|
4
4
|
AbiErrorType,
|
|
5
|
+
AbiNamedValue,
|
|
5
6
|
AbiType,
|
|
6
7
|
AbiValue,
|
|
7
8
|
DebugFileMap,
|
|
@@ -73,7 +74,7 @@ export interface NoirCompiledContract {
|
|
|
73
74
|
/** The events of the contract */
|
|
74
75
|
outputs: {
|
|
75
76
|
structs: Record<string, AbiType[]>;
|
|
76
|
-
globals: Record<string, AbiValue[]>;
|
|
77
|
+
globals: Record<string, (AbiNamedValue | AbiValue)[]>;
|
|
77
78
|
};
|
|
78
79
|
/** The map of file ID to the source code and path of the file. */
|
|
79
80
|
file_map: DebugFileMap;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
|
|
1
3
|
import type { PublicDataTreeLeaf } from '../trees/index.js';
|
|
2
4
|
|
|
3
5
|
/** Data used to initialize the genesis block, including prefilled public state and an optional timestamp. */
|
|
4
6
|
export type GenesisData = {
|
|
5
7
|
/** Public data tree leaves to pre-populate in the genesis state (e.g. fee juice balances). */
|
|
6
8
|
prefilledPublicData: PublicDataTreeLeaf[];
|
|
9
|
+
/**
|
|
10
|
+
* Nullifiers to pre-insert into the genesis nullifier tree. Optional; defaults to an empty list, which leaves the
|
|
11
|
+
* nullifier tree at its canonical empty-genesis state so that production genesis roots are unchanged. When non-empty,
|
|
12
|
+
* the leaves must be unique and strictly increasing in field value (the native world state enforces this before
|
|
13
|
+
* construction). Test networks pass a non-empty list to seed e.g. standard-contract registration nullifiers.
|
|
14
|
+
*/
|
|
15
|
+
prefilledNullifiers?: Fr[];
|
|
7
16
|
/** Timestamp for the genesis block header. Defaults to 0 (canonical empty genesis) in production. */
|
|
8
17
|
genesisTimestamp: bigint;
|
|
9
18
|
};
|
|
@@ -11,6 +20,7 @@ export type GenesisData = {
|
|
|
11
20
|
/** An empty genesis data with no prefilled state and a zero timestamp. */
|
|
12
21
|
export const EMPTY_GENESIS_DATA: GenesisData = {
|
|
13
22
|
prefilledPublicData: [],
|
|
23
|
+
prefilledNullifiers: [],
|
|
14
24
|
genesisTimestamp: 0n,
|
|
15
25
|
};
|
|
16
26
|
|