@aztec/stdlib 6.0.0-nightly.20260723 → 6.0.0-nightly.20260724
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/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/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
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
2
|
import type { PublicDataTreeLeaf } from '../trees/index.js';
|
|
2
3
|
/** Data used to initialize the genesis block, including prefilled public state and an optional timestamp. */
|
|
3
4
|
export type GenesisData = {
|
|
4
5
|
/** Public data tree leaves to pre-populate in the genesis state (e.g. fee juice balances). */
|
|
5
6
|
prefilledPublicData: PublicDataTreeLeaf[];
|
|
7
|
+
/**
|
|
8
|
+
* Nullifiers to pre-insert into the genesis nullifier tree. Optional; defaults to an empty list, which leaves the
|
|
9
|
+
* nullifier tree at its canonical empty-genesis state so that production genesis roots are unchanged. When non-empty,
|
|
10
|
+
* the leaves must be unique and strictly increasing in field value (the native world state enforces this before
|
|
11
|
+
* construction). Test networks pass a non-empty list to seed e.g. standard-contract registration nullifiers.
|
|
12
|
+
*/
|
|
13
|
+
prefilledNullifiers?: Fr[];
|
|
6
14
|
/** Timestamp for the genesis block header. Defaults to 0 (canonical empty genesis) in production. */
|
|
7
15
|
genesisTimestamp: bigint;
|
|
8
16
|
};
|
|
@@ -10,4 +18,4 @@ export type GenesisData = {
|
|
|
10
18
|
export declare const EMPTY_GENESIS_DATA: GenesisData;
|
|
11
19
|
/** Returns if an object looks like genesis data */
|
|
12
20
|
export declare function isGenesisData(obj: any): obj is GenesisData;
|
|
13
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXNpc19kYXRhLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd29ybGQtc3RhdGUvZ2VuZXNpc19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXpELE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFFNUQsNkdBQTZHO0FBQzdHLE1BQU0sTUFBTSxXQUFXLEdBQUc7SUFDeEIsOEZBQThGO0lBQzlGLG1CQUFtQixFQUFFLGtCQUFrQixFQUFFLENBQUM7SUFDMUM7Ozs7O09BS0c7SUFDSCxtQkFBbUIsQ0FBQyxFQUFFLEVBQUUsRUFBRSxDQUFDO0lBQzNCLHFHQUFxRztJQUNyRyxnQkFBZ0IsRUFBRSxNQUFNLENBQUM7Q0FDMUIsQ0FBQztBQUVGLDBFQUEwRTtBQUMxRSxlQUFPLE1BQU0sa0JBQWtCLEVBQUUsV0FJaEMsQ0FBQztBQUVGLG1EQUFtRDtBQUNuRCx3QkFBZ0IsYUFBYSxDQUFDLEdBQUcsRUFBRSxHQUFHLEdBQUcsR0FBRyxJQUFJLFdBQVcsQ0FTMUQifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genesis_data.d.ts","sourceRoot":"","sources":["../../src/world-state/genesis_data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,6GAA6G;AAC7G,MAAM,MAAM,WAAW,GAAG;IACxB,8FAA8F;IAC9F,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,qGAAqG;IACrG,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"genesis_data.d.ts","sourceRoot":"","sources":["../../src/world-state/genesis_data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,6GAA6G;AAC7G,MAAM,MAAM,WAAW,GAAG;IACxB,8FAA8F;IAC9F,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,EAAE,EAAE,CAAC;IAC3B,qGAAqG;IACrG,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,kBAAkB,EAAE,WAIhC,CAAC;AAEF,mDAAmD;AACnD,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,WAAW,CAS1D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** An empty genesis data with no prefilled state and a zero timestamp. */ export const EMPTY_GENESIS_DATA = {
|
|
2
2
|
prefilledPublicData: [],
|
|
3
|
+
prefilledNullifiers: [],
|
|
3
4
|
genesisTimestamp: 0n
|
|
4
5
|
};
|
|
5
6
|
/** Returns if an object looks like genesis data */ export function isGenesisData(obj) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/stdlib",
|
|
3
|
-
"version": "6.0.0-nightly.
|
|
3
|
+
"version": "6.0.0-nightly.20260724",
|
|
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": "6.0.0-nightly.
|
|
96
|
-
"@aztec/blob-lib": "6.0.0-nightly.
|
|
97
|
-
"@aztec/constants": "6.0.0-nightly.
|
|
98
|
-
"@aztec/ethereum": "6.0.0-nightly.
|
|
99
|
-
"@aztec/foundation": "6.0.0-nightly.
|
|
100
|
-
"@aztec/l1-artifacts": "6.0.0-nightly.
|
|
101
|
-
"@aztec/noir-noirc_abi": "6.0.0-nightly.
|
|
95
|
+
"@aztec/bb.js": "6.0.0-nightly.20260724",
|
|
96
|
+
"@aztec/blob-lib": "6.0.0-nightly.20260724",
|
|
97
|
+
"@aztec/constants": "6.0.0-nightly.20260724",
|
|
98
|
+
"@aztec/ethereum": "6.0.0-nightly.20260724",
|
|
99
|
+
"@aztec/foundation": "6.0.0-nightly.20260724",
|
|
100
|
+
"@aztec/l1-artifacts": "6.0.0-nightly.20260724",
|
|
101
|
+
"@aztec/noir-noirc_abi": "6.0.0-nightly.20260724",
|
|
102
102
|
"@google-cloud/storage": "^7.15.0",
|
|
103
103
|
"axios": "^1.15.1",
|
|
104
104
|
"json-stringify-deterministic": "1.0.12",
|
package/src/abi/abi.ts
CHANGED
|
@@ -27,6 +27,14 @@ export type AbiValue =
|
|
|
27
27
|
| IntegerValue
|
|
28
28
|
| StructValue;
|
|
29
29
|
|
|
30
|
+
/** An exported value together with the name of the global that produced it. */
|
|
31
|
+
export interface AbiNamedValue {
|
|
32
|
+
/** The name of the exported global. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** The exported value. */
|
|
35
|
+
value: AbiValue;
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
export const AbiValueSchema: z.ZodType<AbiValue> = z.discriminatedUnion('kind', [
|
|
31
39
|
z.object({ kind: z.literal('boolean'), value: z.boolean() }),
|
|
32
40
|
z.object({ kind: z.literal('string'), value: z.string() }),
|
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
type ABIParameter,
|
|
14
14
|
type ABIParameterVisibility,
|
|
15
15
|
ARTIFACT_VERSION_BEFORE_INJECTION,
|
|
16
|
+
type AbiNamedValue,
|
|
16
17
|
type AbiType,
|
|
18
|
+
type AbiValue,
|
|
17
19
|
type BasicValue,
|
|
18
20
|
type ContractArtifact,
|
|
19
21
|
ContractArtifactSchema,
|
|
@@ -246,20 +248,24 @@ function hasKernelFunctionInputs(params: ABIParameter[]): boolean {
|
|
|
246
248
|
|
|
247
249
|
/**
|
|
248
250
|
* Generates a storage layout for the contract artifact.
|
|
249
|
-
* @param
|
|
251
|
+
* @param contractName - The name of the compiled Noir contract.
|
|
252
|
+
* @param globals - The normalized globals exported by the contract.
|
|
250
253
|
* @returns A storage layout for the contract.
|
|
251
254
|
*/
|
|
252
|
-
function getStorageLayout(
|
|
255
|
+
function getStorageLayout(contractName: string, globals: Record<string, AbiValue[]>) {
|
|
253
256
|
// If another contract is imported by the main contract, its storage layout its going to also show up here.
|
|
254
257
|
// The layout export includes the contract name, so here we can find the one that belongs to the current one and
|
|
255
258
|
// ignore the rest.
|
|
256
|
-
const storageExports =
|
|
257
|
-
const storageForContract = storageExports.find(storageExport => {
|
|
259
|
+
const storageExports = globals.storage ?? [];
|
|
260
|
+
const storageForContract = storageExports.find((storageExport): storageExport is StructValue => {
|
|
261
|
+
if (storageExport.kind !== 'struct') {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
258
264
|
const contractNameField = storageExport.fields.find(field => field.name === 'contract_name')?.value as BasicValue<
|
|
259
265
|
'string',
|
|
260
266
|
string
|
|
261
267
|
>;
|
|
262
|
-
return contractNameField.value ===
|
|
268
|
+
return contractNameField.value === contractName;
|
|
263
269
|
});
|
|
264
270
|
const storageFields = storageForContract
|
|
265
271
|
? ((storageForContract.fields.find(field => field.name == 'fields') as TypedStructFieldValue<StructValue>).value
|
|
@@ -280,6 +286,22 @@ function getStorageLayout(input: NoirCompiledContract) {
|
|
|
280
286
|
}, {});
|
|
281
287
|
}
|
|
282
288
|
|
|
289
|
+
function isAbiNamedValue(value: AbiNamedValue | AbiValue): value is AbiNamedValue {
|
|
290
|
+
return 'name' in value;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function normalizeContractOutputs(outputs: NoirCompiledContract['outputs']): ContractArtifact['outputs'] {
|
|
294
|
+
return {
|
|
295
|
+
structs: outputs.structs,
|
|
296
|
+
globals: Object.fromEntries(
|
|
297
|
+
Object.entries(outputs.globals).map(([tag, values]) => [
|
|
298
|
+
tag,
|
|
299
|
+
values.map(value => (isAbiNamedValue(value) ? value.value : value)),
|
|
300
|
+
]),
|
|
301
|
+
),
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
283
305
|
/**
|
|
284
306
|
* Given a post-processed Nargo output defined as `contract` generates an Aztec-compatible contract artifact.
|
|
285
307
|
*
|
|
@@ -290,6 +312,7 @@ function generateContractArtifact(contract: NoirCompiledContract): ContractArtif
|
|
|
290
312
|
if (!contract.transpiled) {
|
|
291
313
|
throw new Error("Contract's public bytecode has not been transpiled");
|
|
292
314
|
}
|
|
315
|
+
const outputs = normalizeContractOutputs(contract.outputs);
|
|
293
316
|
return ContractArtifactSchema.parse({
|
|
294
317
|
name: contract.name,
|
|
295
318
|
aztecVersion: contract.aztec_version,
|
|
@@ -297,8 +320,8 @@ function generateContractArtifact(contract: NoirCompiledContract): ContractArtif
|
|
|
297
320
|
nonDispatchPublicFunctions: contract.functions
|
|
298
321
|
.filter(f => !retainBytecode(f))
|
|
299
322
|
.map(f => generateFunctionAbi(f, contract)),
|
|
300
|
-
outputs
|
|
301
|
-
storageLayout: getStorageLayout(contract),
|
|
323
|
+
outputs,
|
|
324
|
+
storageLayout: getStorageLayout(contract.name, outputs.globals),
|
|
302
325
|
fileMap: contract.file_map,
|
|
303
326
|
});
|
|
304
327
|
} catch (err) {
|
|
@@ -313,6 +336,7 @@ function generateContractArtifact(contract: NoirCompiledContract): ContractArtif
|
|
|
313
336
|
*/
|
|
314
337
|
function generateContractArtifactForPublic(contract: NoirCompiledContract): ContractArtifact {
|
|
315
338
|
try {
|
|
339
|
+
const outputs = normalizeContractOutputs(contract.outputs);
|
|
316
340
|
return ContractArtifactSchema.parse({
|
|
317
341
|
name: contract.name,
|
|
318
342
|
aztecVersion: contract.aztec_version,
|
|
@@ -320,8 +344,8 @@ function generateContractArtifactForPublic(contract: NoirCompiledContract): Cont
|
|
|
320
344
|
nonDispatchPublicFunctions: contract.functions
|
|
321
345
|
.filter(f => !retainBytecode(f))
|
|
322
346
|
.map(f => generateFunctionAbi(f, contract)),
|
|
323
|
-
outputs
|
|
324
|
-
storageLayout: getStorageLayout(contract),
|
|
347
|
+
outputs,
|
|
348
|
+
storageLayout: getStorageLayout(contract.name, outputs.globals),
|
|
325
349
|
fileMap: contract.file_map,
|
|
326
350
|
});
|
|
327
351
|
} catch (err) {
|
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<
|
|
@@ -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;
|