@aztec/stdlib 4.1.2 → 4.2.0-aztecnr-rc.2

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 (145) hide show
  1. package/dest/abi/buffer.d.ts +14 -4
  2. package/dest/abi/buffer.d.ts.map +1 -1
  3. package/dest/abi/buffer.js +25 -4
  4. package/dest/abi/decoder.d.ts +5 -44
  5. package/dest/abi/decoder.d.ts.map +1 -1
  6. package/dest/abi/decoder.js +12 -67
  7. package/dest/abi/function_selector.js +1 -1
  8. package/dest/abi/function_signature_decoder.d.ts +43 -0
  9. package/dest/abi/function_signature_decoder.d.ts.map +1 -0
  10. package/dest/abi/function_signature_decoder.js +66 -0
  11. package/dest/abi/index.d.ts +2 -1
  12. package/dest/abi/index.d.ts.map +1 -1
  13. package/dest/abi/index.js +1 -0
  14. package/dest/avm/avm_accumulated_data.js +2 -2
  15. package/dest/avm/avm_circuit_public_inputs.js +2 -2
  16. package/dest/block/l2_block_source.d.ts +5 -3
  17. package/dest/block/l2_block_source.d.ts.map +1 -1
  18. package/dest/checkpoint/validate.js +2 -2
  19. package/dest/epoch-helpers/index.d.ts +3 -1
  20. package/dest/epoch-helpers/index.d.ts.map +1 -1
  21. package/dest/epoch-helpers/index.js +6 -0
  22. package/dest/gas/gas_fees.d.ts +1 -1
  23. package/dest/gas/gas_fees.d.ts.map +1 -1
  24. package/dest/gas/gas_fees.js +4 -1
  25. package/dest/hash/hash.d.ts +19 -1
  26. package/dest/hash/hash.d.ts.map +1 -1
  27. package/dest/hash/hash.js +29 -0
  28. package/dest/interfaces/aztec-node-admin.d.ts +4 -1
  29. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  30. package/dest/interfaces/aztec-node.d.ts +2 -1
  31. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  32. package/dest/interfaces/block-builder.d.ts +25 -6
  33. package/dest/interfaces/block-builder.d.ts.map +1 -1
  34. package/dest/interfaces/configs.d.ts +7 -2
  35. package/dest/interfaces/configs.d.ts.map +1 -1
  36. package/dest/interfaces/configs.js +1 -0
  37. package/dest/interfaces/world_state.d.ts +5 -4
  38. package/dest/interfaces/world_state.d.ts.map +1 -1
  39. package/dest/kernel/claimed_length_array.js +1 -1
  40. package/dest/kernel/hints/private_kernel_reset_hints.d.ts +1 -1
  41. package/dest/kernel/hints/private_kernel_reset_hints.d.ts.map +1 -1
  42. package/dest/kernel/padded_side_effects.js +1 -1
  43. package/dest/kernel/private_to_avm_accumulated_data.js +2 -2
  44. package/dest/kernel/private_to_public_accumulated_data.js +2 -2
  45. package/dest/kernel/private_to_rollup_accumulated_data.js +1 -1
  46. package/dest/logs/index.d.ts +2 -1
  47. package/dest/logs/index.d.ts.map +1 -1
  48. package/dest/logs/index.js +1 -0
  49. package/dest/logs/message_context.d.ts +4 -7
  50. package/dest/logs/message_context.d.ts.map +1 -1
  51. package/dest/logs/message_context.js +23 -9
  52. package/dest/logs/pending_tagged_log.d.ts +2 -3
  53. package/dest/logs/pending_tagged_log.d.ts.map +1 -1
  54. package/dest/logs/pending_tagged_log.js +2 -2
  55. package/dest/logs/private_log.js +1 -1
  56. package/dest/logs/public_log.d.ts +1 -1
  57. package/dest/logs/public_log.d.ts.map +1 -1
  58. package/dest/logs/public_log.js +7 -1
  59. package/dest/logs/shared_secret_derivation.d.ts +11 -10
  60. package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
  61. package/dest/logs/shared_secret_derivation.js +15 -9
  62. package/dest/logs/siloed_tag.d.ts +4 -1
  63. package/dest/logs/siloed_tag.d.ts.map +1 -1
  64. package/dest/logs/siloed_tag.js +7 -3
  65. package/dest/logs/tagging_index_range.d.ts +40 -0
  66. package/dest/logs/tagging_index_range.d.ts.map +1 -0
  67. package/dest/logs/tagging_index_range.js +8 -0
  68. package/dest/messaging/l1_to_l2_message.d.ts +3 -2
  69. package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
  70. package/dest/messaging/l1_to_l2_message.js +11 -13
  71. package/dest/noir/index.d.ts +3 -3
  72. package/dest/noir/index.d.ts.map +1 -1
  73. package/dest/parity/parity_base_private_inputs.js +1 -1
  74. package/dest/proofs/chonk_proof.d.ts +1 -1
  75. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  76. package/dest/proofs/chonk_proof.js +7 -1
  77. package/dest/rollup/base_rollup_hints.js +2 -2
  78. package/dest/rollup/block_root_rollup_private_inputs.js +5 -5
  79. package/dest/rollup/checkpoint_rollup_public_inputs.js +1 -1
  80. package/dest/rollup/checkpoint_root_rollup_private_inputs.js +3 -3
  81. package/dest/rollup/root_rollup_public_inputs.js +1 -1
  82. package/dest/rollup/tree_snapshot_diff_hints.js +2 -2
  83. package/dest/tx/capsule.d.ts +6 -2
  84. package/dest/tx/capsule.d.ts.map +1 -1
  85. package/dest/tx/capsule.js +9 -3
  86. package/dest/tx/private_execution_result.d.ts +6 -6
  87. package/dest/tx/private_execution_result.d.ts.map +1 -1
  88. package/dest/tx/private_execution_result.js +6 -6
  89. package/dest/tx/profiling.d.ts +14 -2
  90. package/dest/tx/profiling.d.ts.map +1 -1
  91. package/dest/tx/profiling.js +13 -3
  92. package/dest/tx/protocol_contracts.js +2 -2
  93. package/dest/tx/validator/error_texts.d.ts +3 -1
  94. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  95. package/dest/tx/validator/error_texts.js +3 -0
  96. package/dest/vks/vk_data.js +1 -1
  97. package/package.json +9 -9
  98. package/src/abi/buffer.ts +25 -4
  99. package/src/abi/decoder.ts +23 -78
  100. package/src/abi/function_selector.ts +1 -1
  101. package/src/abi/function_signature_decoder.ts +77 -0
  102. package/src/abi/index.ts +1 -0
  103. package/src/avm/avm_accumulated_data.ts +6 -6
  104. package/src/avm/avm_circuit_public_inputs.ts +4 -4
  105. package/src/block/l2_block_source.ts +4 -2
  106. package/src/checkpoint/validate.ts +2 -2
  107. package/src/epoch-helpers/index.ts +11 -0
  108. package/src/gas/README.md +123 -0
  109. package/src/gas/gas_fees.ts +7 -1
  110. package/src/hash/hash.ts +34 -0
  111. package/src/interfaces/aztec-node.ts +1 -0
  112. package/src/interfaces/block-builder.ts +27 -3
  113. package/src/interfaces/configs.ts +4 -1
  114. package/src/interfaces/world_state.ts +4 -3
  115. package/src/kernel/claimed_length_array.ts +2 -2
  116. package/src/kernel/hints/private_kernel_reset_hints.ts +5 -2
  117. package/src/kernel/hints/read_request_hints.ts +3 -3
  118. package/src/kernel/padded_side_effects.ts +3 -3
  119. package/src/kernel/private_to_avm_accumulated_data.ts +4 -4
  120. package/src/kernel/private_to_public_accumulated_data.ts +10 -10
  121. package/src/kernel/private_to_rollup_accumulated_data.ts +5 -5
  122. package/src/logs/index.ts +1 -0
  123. package/src/logs/message_context.ts +17 -7
  124. package/src/logs/pending_tagged_log.ts +1 -3
  125. package/src/logs/private_log.ts +1 -1
  126. package/src/logs/public_log.ts +11 -1
  127. package/src/logs/shared_secret_derivation.ts +21 -10
  128. package/src/logs/siloed_tag.ts +7 -2
  129. package/src/logs/tagging_index_range.ts +24 -0
  130. package/src/messaging/l1_to_l2_message.ts +12 -9
  131. package/src/noir/index.ts +2 -2
  132. package/src/parity/parity_base_private_inputs.ts +1 -1
  133. package/src/proofs/chonk_proof.ts +9 -1
  134. package/src/rollup/base_rollup_hints.ts +2 -2
  135. package/src/rollup/block_root_rollup_private_inputs.ts +8 -8
  136. package/src/rollup/checkpoint_rollup_public_inputs.ts +2 -2
  137. package/src/rollup/checkpoint_root_rollup_private_inputs.ts +4 -4
  138. package/src/rollup/root_rollup_public_inputs.ts +2 -2
  139. package/src/rollup/tree_snapshot_diff_hints.ts +5 -5
  140. package/src/tx/capsule.ts +10 -2
  141. package/src/tx/private_execution_result.ts +5 -5
  142. package/src/tx/profiling.ts +11 -2
  143. package/src/tx/protocol_contracts.ts +2 -2
  144. package/src/tx/validator/error_texts.ts +4 -0
  145. package/src/vks/vk_data.ts +1 -1
@@ -1,8 +1,17 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
3
 
3
4
  import { AztecAddress } from '../aztec-address/index.js';
4
- import type { ABIParameter, ABIVariable, AbiType } from './abi.js';
5
- import { isAztecAddressStruct, isOptionStruct, parseSignedInt } from './utils.js';
5
+ import type { AbiType } from './abi.js';
6
+ import { FunctionSelector } from './function_selector.js';
7
+ import {
8
+ isAztecAddressStruct,
9
+ isEthAddressStruct,
10
+ isFunctionSelectorStruct,
11
+ isOptionStruct,
12
+ isWrappedFieldStruct,
13
+ parseSignedInt,
14
+ } from './utils.js';
6
15
 
7
16
  /**
8
17
  * The type of our decoded ABI.
@@ -12,6 +21,9 @@ export type AbiDecoded =
12
21
  | boolean
13
22
  | string
14
23
  | AztecAddress
24
+ | EthAddress
25
+ | FunctionSelector
26
+ | Fr
15
27
  | AbiDecoded[]
16
28
  | { [key: string]: AbiDecoded }
17
29
  | undefined;
@@ -58,6 +70,15 @@ class AbiDecoder {
58
70
  if (isAztecAddressStruct(abiType)) {
59
71
  return new AztecAddress(this.getNextField().toBuffer());
60
72
  }
73
+ if (isEthAddressStruct(abiType)) {
74
+ return EthAddress.fromField(this.getNextField());
75
+ }
76
+ if (isFunctionSelectorStruct(abiType)) {
77
+ return FunctionSelector.fromField(this.getNextField());
78
+ }
79
+ if (isWrappedFieldStruct(abiType)) {
80
+ return this.getNextField();
81
+ }
61
82
  if (isOptionStruct(abiType)) {
62
83
  const isSome = this.decodeNext(abiType.fields[0].type);
63
84
  const value = this.decodeNext(abiType.fields[1].type);
@@ -123,79 +144,3 @@ class AbiDecoder {
123
144
  export function decodeFromAbi(typ: AbiType[], buffer: Fr[]) {
124
145
  return new AbiDecoder(typ, buffer.slice()).decode();
125
146
  }
126
-
127
- /**
128
- * Decodes the signature of a function from the name and parameters.
129
- */
130
- export class FunctionSignatureDecoder {
131
- private separator: string;
132
- constructor(
133
- private name: string,
134
- private parameters: ABIParameter[],
135
- private includeNames = false,
136
- ) {
137
- this.separator = includeNames ? ', ' : ',';
138
- }
139
-
140
- /**
141
- * Decodes a single function parameter type for the function signature.
142
- * @param param - The parameter type to decode.
143
- * @returns A string representing the parameter type.
144
- */
145
- private getParameterType(param: AbiType): string {
146
- switch (param.kind) {
147
- case 'field':
148
- return 'Field';
149
- case 'integer':
150
- return param.sign === 'signed' ? `i${param.width}` : `u${param.width}`;
151
- case 'boolean':
152
- return 'bool';
153
- case 'array':
154
- return `[${this.getParameterType(param.type)};${param.length}]`;
155
- case 'string':
156
- return `str<${param.length}>`;
157
- case 'struct':
158
- return `(${param.fields.map(field => `${this.decodeParameter(field)}`).join(this.separator)})`;
159
- default:
160
- throw new Error(`Unsupported type: ${param.kind}`);
161
- }
162
- }
163
-
164
- /**
165
- * Decodes a single function parameter for the function signature.
166
- * @param param - The parameter to decode.
167
- * @returns A string representing the parameter type and optionally its name.
168
- */
169
- private decodeParameter(param: ABIVariable): string {
170
- const type = this.getParameterType(param.type);
171
- return this.includeNames ? `${param.name}: ${type}` : type;
172
- }
173
-
174
- /**
175
- * Decodes all the parameters and build the function signature
176
- * @returns The function signature.
177
- */
178
- public decode(): string {
179
- return `${this.name}(${this.parameters.map(param => this.decodeParameter(param)).join(this.separator)})`;
180
- }
181
- }
182
-
183
- /**
184
- * Decodes a function signature from the name and parameters.
185
- * @param name - The name of the function.
186
- * @param parameters - The parameters of the function.
187
- * @returns - The function signature.
188
- */
189
- export function decodeFunctionSignature(name: string, parameters: ABIParameter[]) {
190
- return new FunctionSignatureDecoder(name, parameters).decode();
191
- }
192
-
193
- /**
194
- * Decodes a function signature from the name and parameters including parameter names.
195
- * @param name - The name of the function.
196
- * @param parameters - The parameters of the function.
197
- * @returns - The user-friendly function signature.
198
- */
199
- export function decodeFunctionSignatureWithParameterNames(name: string, parameters: ABIParameter[]) {
200
- return new FunctionSignatureDecoder(name, parameters, true).decode();
201
- }
@@ -6,7 +6,7 @@ import { type ZodFor, hexSchemaFor } from '@aztec/foundation/schemas';
6
6
  import { BufferReader, FieldReader, TypeRegistry } from '@aztec/foundation/serialize';
7
7
 
8
8
  import type { ABIParameter } from './abi.js';
9
- import { decodeFunctionSignature } from './decoder.js';
9
+ import { decodeFunctionSignature } from './function_signature_decoder.js';
10
10
  import { Selector } from './selector.js';
11
11
 
12
12
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
@@ -0,0 +1,77 @@
1
+ import type { ABIParameter, ABIVariable, AbiType } from './abi.js';
2
+
3
+ /**
4
+ * Decodes the signature of a function from the name and parameters.
5
+ */
6
+ export class FunctionSignatureDecoder {
7
+ private separator: string;
8
+ constructor(
9
+ private name: string,
10
+ private parameters: ABIParameter[],
11
+ private includeNames = false,
12
+ ) {
13
+ this.separator = includeNames ? ', ' : ',';
14
+ }
15
+
16
+ /**
17
+ * Decodes a single function parameter type for the function signature.
18
+ * @param param - The parameter type to decode.
19
+ * @returns A string representing the parameter type.
20
+ */
21
+ private getParameterType(param: AbiType): string {
22
+ switch (param.kind) {
23
+ case 'field':
24
+ return 'Field';
25
+ case 'integer':
26
+ return param.sign === 'signed' ? `i${param.width}` : `u${param.width}`;
27
+ case 'boolean':
28
+ return 'bool';
29
+ case 'array':
30
+ return `[${this.getParameterType(param.type)};${param.length}]`;
31
+ case 'string':
32
+ return `str<${param.length}>`;
33
+ case 'struct':
34
+ return `(${param.fields.map(field => `${this.decodeParameter(field)}`).join(this.separator)})`;
35
+ default:
36
+ throw new Error(`Unsupported type: ${param.kind}`);
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Decodes a single function parameter for the function signature.
42
+ * @param param - The parameter to decode.
43
+ * @returns A string representing the parameter type and optionally its name.
44
+ */
45
+ private decodeParameter(param: ABIVariable): string {
46
+ const type = this.getParameterType(param.type);
47
+ return this.includeNames ? `${param.name}: ${type}` : type;
48
+ }
49
+
50
+ /**
51
+ * Decodes all the parameters and build the function signature
52
+ * @returns The function signature.
53
+ */
54
+ public decode(): string {
55
+ return `${this.name}(${this.parameters.map(param => this.decodeParameter(param)).join(this.separator)})`;
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Decodes a function signature from the name and parameters.
61
+ * @param name - The name of the function.
62
+ * @param parameters - The parameters of the function.
63
+ * @returns - The function signature.
64
+ */
65
+ export function decodeFunctionSignature(name: string, parameters: ABIParameter[]) {
66
+ return new FunctionSignatureDecoder(name, parameters).decode();
67
+ }
68
+
69
+ /**
70
+ * Decodes a function signature from the name and parameters including parameter names.
71
+ * @param name - The name of the function.
72
+ * @param parameters - The parameters of the function.
73
+ * @returns - The user-friendly function signature.
74
+ */
75
+ export function decodeFunctionSignatureWithParameterNames(name: string, parameters: ABIParameter[]) {
76
+ return new FunctionSignatureDecoder(name, parameters, true).decode();
77
+ }
package/src/abi/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './abi.js';
2
2
  export * from './buffer.js';
3
3
  export * from './decoder.js';
4
+ export * from './function_signature_decoder.js';
4
5
  export * from './encoder.js';
5
6
  export * from './authorization_selector.js';
6
7
  export * from './event_metadata_definition.js';
@@ -88,11 +88,11 @@ export class AvmAccumulatedData {
88
88
  static fromBuffer(buffer: Buffer | BufferReader) {
89
89
  const reader = BufferReader.asReader(buffer);
90
90
  return new this(
91
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
92
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
93
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
91
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
92
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
93
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
94
94
  reader.readObject(FlatPublicLogs),
95
- reader.readArray(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite),
95
+ reader.readTuple(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite),
96
96
  );
97
97
  }
98
98
 
@@ -115,9 +115,9 @@ export class AvmAccumulatedData {
115
115
  return new this(
116
116
  reader.readFieldArray(MAX_NOTE_HASHES_PER_TX),
117
117
  reader.readFieldArray(MAX_NULLIFIERS_PER_TX),
118
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
118
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
119
119
  reader.readObject(FlatPublicLogs),
120
- reader.readArray(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite),
120
+ reader.readTuple(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite),
121
121
  );
122
122
  }
123
123
 
@@ -143,8 +143,8 @@ export class AvmCircuitPublicInputs {
143
143
  reader.readObject(AztecAddress),
144
144
  reader.readObject(Fr),
145
145
  reader.readObject(PublicCallRequestArrayLengths),
146
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
147
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
146
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
147
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
148
148
  reader.readObject(PublicCallRequest),
149
149
  reader.readObject(PrivateToAvmAccumulatedDataArrayLengths),
150
150
  reader.readObject(PrivateToAvmAccumulatedDataArrayLengths),
@@ -206,8 +206,8 @@ export class AvmCircuitPublicInputs {
206
206
  AztecAddress.fromFields(reader),
207
207
  reader.readField(),
208
208
  PublicCallRequestArrayLengths.fromFields(reader),
209
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
210
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
209
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
210
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
211
211
  PublicCallRequest.fromFields(reader),
212
212
  PrivateToAvmAccumulatedDataArrayLengths.fromFields(reader),
213
213
  PrivateToAvmAccumulatedDataArrayLengths.fromFields(reader),
@@ -175,8 +175,10 @@ export interface L2BlockSource {
175
175
  getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined>;
176
176
 
177
177
  /**
178
- * Returns the last L2 slot number that has been fully synchronized from L1.
179
- * An L2 slot is fully synced when all L1 blocks that fall within its time range have been processed.
178
+ * Returns the last L2 slot number for which we have all L1 data needed to build the next checkpoint.
179
+ * Determined by the max of two signals: L1 block sync progress and latest synced checkpoint slot.
180
+ * The checkpoint signal handles missed L1 blocks, since a published checkpoint seals the message tree
181
+ * for the next checkpoint via the inbox LAG mechanism.
180
182
  */
181
183
  getSyncedL2SlotNumber(): Promise<SlotNumber | undefined>;
182
184
 
@@ -36,7 +36,7 @@ export function validateCheckpoint(
36
36
  ): void {
37
37
  validateCheckpointStructure(checkpoint);
38
38
  validateCheckpointLimits(checkpoint, opts);
39
- validateCheckpointBlocksGasLimits(checkpoint, opts);
39
+ validateCheckpointBlocksLimits(checkpoint, opts);
40
40
  }
41
41
 
42
42
  /**
@@ -125,7 +125,7 @@ export function validateCheckpointStructure(checkpoint: Checkpoint): void {
125
125
  }
126
126
 
127
127
  /** Validates checkpoint blocks gas limits */
128
- function validateCheckpointBlocksGasLimits(
128
+ function validateCheckpointBlocksLimits(
129
129
  checkpoint: Checkpoint,
130
130
  opts: {
131
131
  maxL2BlockGas?: number;
@@ -57,6 +57,17 @@ export function getSlotAtTimestamp(
57
57
  : SlotNumber.fromBigInt((ts - constants.l1GenesisTime) / BigInt(constants.slotDuration));
58
58
  }
59
59
 
60
+ /** Returns the timestamp of the next L1 slot boundary after the given wall-clock time. */
61
+ export function getNextL1SlotTimestamp(
62
+ nowInSeconds: number,
63
+ constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'ethereumSlotDuration'>,
64
+ ): bigint {
65
+ const now = BigInt(nowInSeconds);
66
+ const elapsed = now - constants.l1GenesisTime;
67
+ const currentL1Slot = elapsed / BigInt(constants.ethereumSlotDuration);
68
+ return constants.l1GenesisTime + (currentL1Slot + 1n) * BigInt(constants.ethereumSlotDuration);
69
+ }
70
+
60
71
  /** Returns the L2 slot number at the next L1 block based on the current timestamp. */
61
72
  export function getSlotAtNextL1Block(
62
73
  currentL1Timestamp: bigint,
@@ -0,0 +1,123 @@
1
+ # Aztec Gas and Fee Model
2
+
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.
6
+
7
+ ## Mana
8
+
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.
12
+
13
+ ## Fee Components
14
+
15
+ The minimum fee per mana has four components:
16
+
17
+ ### Sequencer Cost
18
+
19
+ L1 cost to propose a checkpoint (calldata gas + blob data), amortized over `manaTarget`:
20
+
21
+ ```
22
+ sequencerCost = ((L1_GAS_PER_CHECKPOINT_PROPOSED * baseFee)
23
+ + (BLOBS_PER_CHECKPOINT * BLOB_GAS_PER_BLOB * blobFee))
24
+ / manaTarget
25
+ ```
26
+
27
+ ### Prover Cost
28
+
29
+ L1 cost to verify an epoch proof, amortized over epoch duration and `manaTarget`, plus a
30
+ governance-set proving cost that compensates for off-chain proof generation:
31
+
32
+ ```
33
+ proverCost = (L1_GAS_PER_EPOCH_VERIFIED * baseFee / epochDuration) / manaTarget
34
+ + provingCostPerMana
35
+ ```
36
+
37
+ ### Congestion Cost
38
+
39
+ An exponential surcharge when the network is congested (inspired by EIP-1559; the
40
+ implementation uses the `fakeExponential` Taylor series approximation from EIP-4844):
41
+
42
+ ```
43
+ baseCost = sequencerCost + proverCost
44
+ congestionCost = baseCost * congestionMultiplier / MINIMUM_CONGESTION_MULTIPLIER - baseCost
45
+ ```
46
+
47
+ When there is no congestion the multiplier equals `MINIMUM_CONGESTION_MULTIPLIER` (1e9)
48
+ and congestion cost is zero.
49
+
50
+ ### Congestion Multiplier
51
+
52
+ ```
53
+ excessMana = max(0, prevExcessMana + prevManaUsed - manaTarget)
54
+ congestionMultiplier = fakeExponential(MINIMUM_CONGESTION_MULTIPLIER, excessMana, denominator)
55
+ ```
56
+
57
+ Each additional `manaTarget` of excess mana increases the multiplier by ~12.5%.
58
+
59
+ ### Total
60
+
61
+ ```
62
+ minFeePerMana = sequencerCost + proverCost + congestionCost
63
+ ```
64
+
65
+ ## L1 Gas Oracle: Lag and Lifetime
66
+
67
+ The oracle feeds Ethereum's `baseFee` and `blobFee` into the fee model using a two-phase
68
+ (`pre` / `post`) system that smooths out L1 fee volatility.
69
+
70
+ - **LAG = 2 slots** — when new L1 fees are observed, they activate `LAG` slots later
71
+ (`slotOfChange = currentSlot + LAG`). This gives mempool transactions time to land
72
+ 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.
76
+
77
+ Fee resolution at a given timestamp:
78
+
79
+ ```
80
+ if slot < slotOfChange → use pre (old fees)
81
+ else → use post (new fees)
82
+ ```
83
+
84
+ **Net effect**: L1 fee changes reach L2 with a 2-slot delay and can update at most once
85
+ every 5 slots.
86
+
87
+ ## Fee Asset Price
88
+
89
+ Fees are computed in ETH internally but converted to the fee asset (Fee Juice) via
90
+ `ethPerFeeAsset` (1e12 precision). The price updates at most ±1% (±100 bps) per
91
+ checkpoint:
92
+
93
+ ```
94
+ newPrice = currentPrice * (10000 + modifierBps) / 10000
95
+ ```
96
+
97
+ ## Maximum Fee Change Rate
98
+
99
+ | Component | Bound |
100
+ | ---------------------- | ------------------------------------------------------- |
101
+ | L1 base fee / blob fee | At most once every 5 slots (oracle LIFETIME) |
102
+ | Fee asset price | ±1% per checkpoint |
103
+ | Congestion multiplier | Depends on excess mana accumulation/drain per checkpoint |
104
+ | Sequencer/prover costs | Scale linearly with L1 fees |
105
+
106
+ ## Key Constants
107
+
108
+ | Constant | Value |
109
+ | ------------------------------ | -------------- |
110
+ | `L1_GAS_PER_CHECKPOINT_PROPOSED` | 300,000 |
111
+ | `L1_GAS_PER_EPOCH_VERIFIED` | 3,600,000 |
112
+ | `BLOBS_PER_CHECKPOINT` | 3 |
113
+ | `BLOB_GAS_PER_BLOB` | 2^17 |
114
+ | `MINIMUM_CONGESTION_MULTIPLIER` | 1e9 |
115
+ | `LAG` | 2 slots |
116
+ | `LIFETIME` | 5 slots |
117
+
118
+ ## TypeScript Types
119
+
120
+ - **`Gas`** — mana quantity in two dimensions (`daGas`, `l2Gas`).
121
+ - **`GasFees`** — per-unit price in each dimension (`feePerDaGas`, `feePerL2Gas`).
122
+ - **`GasSettings`** — sender-chosen fee parameters: gas limits, teardown limits, max fees, priority fees.
123
+ - **`GasUsed`** — actual consumption after execution. Note: `billedGas` uses the teardown gas *limit*, not actual usage.
@@ -56,8 +56,14 @@ export class GasFees {
56
56
  return this.clone();
57
57
  } else if (typeof scalar === 'bigint') {
58
58
  return new GasFees(this.feePerDaGas * scalar, this.feePerL2Gas * scalar);
59
+ } else if (Number.isInteger(scalar)) {
60
+ const s = BigInt(scalar);
61
+ return new GasFees(this.feePerDaGas * s, this.feePerL2Gas * s);
59
62
  } else {
60
- return new GasFees(Number(this.feePerDaGas) * scalar, Number(this.feePerL2Gas) * scalar);
63
+ return new GasFees(
64
+ BigInt(Math.ceil(Number(this.feePerDaGas) * scalar)),
65
+ BigInt(Math.ceil(Number(this.feePerL2Gas) * scalar)),
66
+ );
61
67
  }
62
68
  }
63
69
 
package/src/hash/hash.ts CHANGED
@@ -58,6 +58,35 @@ export function siloNullifier(contract: AztecAddress, innerNullifier: Fr): Promi
58
58
  return poseidon2HashWithSeparator([contract, innerNullifier], DomainSeparator.SILOED_NULLIFIER);
59
59
  }
60
60
 
61
+ /**
62
+ * Computes the siloed private initialization nullifier for a contract, given its address and initialization hash.
63
+ * @param contract - The contract address.
64
+ * @param initializationHash - The contract's initialization hash.
65
+ * @returns The siloed private initialization nullifier.
66
+ */
67
+ export async function computeSiloedPrivateInitializationNullifier(
68
+ contract: AztecAddress,
69
+ initializationHash: Fr,
70
+ ): Promise<Fr> {
71
+ const innerNullifier = await poseidon2HashWithSeparator(
72
+ [contract, initializationHash],
73
+ DomainSeparator.PRIVATE_INITIALIZATION_NULLIFIER,
74
+ );
75
+ return siloNullifier(contract, innerNullifier);
76
+ }
77
+
78
+ /**
79
+ * Computes the siloed public initialization nullifier for a contract. Not all contracts emit this nullifier: it is only
80
+ * emitted when the contract has public functions that perform initialization checks (i.e. external public functions that
81
+ * are not `#[noinitcheck]` or `#[only_self]`).
82
+ * @param contract - The contract address.
83
+ * @returns The siloed public initialization nullifier.
84
+ */
85
+ export async function computeSiloedPublicInitializationNullifier(contract: AztecAddress): Promise<Fr> {
86
+ const innerNullifier = await poseidon2HashWithSeparator([contract], DomainSeparator.PUBLIC_INITIALIZATION_NULLIFIER);
87
+ return siloNullifier(contract, innerNullifier);
88
+ }
89
+
61
90
  /**
62
91
  * Computes the protocol nullifier, which is the hash of the initial tx request siloed with the null msg sender address.
63
92
  * @param txRequestHash - The hash of the initial tx request.
@@ -69,6 +98,11 @@ export function computeProtocolNullifier(txRequestHash: Fr): Promise<Fr> {
69
98
  return siloNullifier(AztecAddress.fromBigInt(NULL_MSG_SENDER_CONTRACT_ADDRESS), txRequestHash);
70
99
  }
71
100
 
101
+ /** Domain-separates a raw log tag with the given domain separator. */
102
+ export function computeLogTag(rawTag: number | bigint | boolean | Fr | Buffer, domSep: DomainSeparator): Promise<Fr> {
103
+ return poseidon2HashWithSeparator([new Fr(rawTag)], domSep);
104
+ }
105
+
72
106
  export function computeSiloedPrivateLogFirstField(contract: AztecAddress, field: Fr): Promise<Fr> {
73
107
  return poseidon2HashWithSeparator([contract, field], DomainSeparator.PRIVATE_LOG_FIRST_FIELD);
74
108
  }
@@ -122,6 +122,7 @@ export interface AztecNode
122
122
  * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
123
123
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
124
124
  * @returns The low nullifier membership witness (if found).
125
+ * @throws If the nullifier already exists in the tree, since non-inclusion cannot be proven.
125
126
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
126
127
  * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
127
128
  * we are trying to prove non-inclusion for.
@@ -35,7 +35,8 @@ export interface IBlockFactory extends ProcessedTxHandler {
35
35
  setBlockCompleted(expectedBlockHeader?: BlockHeader): Promise<L2Block>;
36
36
  }
37
37
 
38
- export interface PublicProcessorLimits {
38
+ /** Limits passed to the public processor for tx processing within a block. */
39
+ export type PublicProcessorLimits = {
39
40
  /** Maximum number of txs to process. */
40
41
  maxTransactions?: number;
41
42
  /** L2 and DA gas limits. */
@@ -46,7 +47,30 @@ export interface PublicProcessorLimits {
46
47
  deadline?: Date;
47
48
  /** Whether this processor is building a proposal (as opposed to re-executing one). Skipping txs due to gas or blob limits is only done during proposal building. */
48
49
  isBuildingProposal?: boolean;
49
- }
50
+ };
51
+
52
+ /** Base fields shared by both proposer and validator block builder options. */
53
+ type BlockBuilderOptionsBase = PublicProcessorLimits & {
54
+ /** Minimum number of successfully processed txs required. Block is rejected if fewer succeed. */
55
+ minValidTxs: number;
56
+ };
57
+
58
+ /** Proposer mode: redistribution params are required. */
59
+ type ProposerBlockBuilderOptions = BlockBuilderOptionsBase & {
60
+ isBuildingProposal: true;
61
+ /** Maximum number of blocks per checkpoint, derived from the timetable. */
62
+ maxBlocksPerCheckpoint: number;
63
+ /** Per-block gas budget multiplier. Budget = (remaining / remainingBlocks) * multiplier. */
64
+ perBlockAllocationMultiplier: number;
65
+ };
66
+
67
+ /** Validator mode: no redistribution params needed. */
68
+ type ValidatorBlockBuilderOptions = BlockBuilderOptionsBase & {
69
+ isBuildingProposal: false;
70
+ };
71
+
72
+ /** Options for building a block within a checkpoint. When proposing, redistribution params are required. */
73
+ export type BlockBuilderOptions = ProposerBlockBuilderOptions | ValidatorBlockBuilderOptions;
50
74
 
51
75
  export interface PublicProcessorValidator {
52
76
  preprocessValidator?: TxValidator<Tx>;
@@ -109,7 +133,7 @@ export interface ICheckpointBlockBuilder {
109
133
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
110
134
  blockNumber: BlockNumber,
111
135
  timestamp: bigint,
112
- opts: PublicProcessorLimits & { minValidTxs?: number },
136
+ opts: BlockBuilderOptions,
113
137
  ): Promise<BuildBlockInCheckpointResult>;
114
138
  }
115
139
 
@@ -27,6 +27,8 @@ export interface SequencerConfig {
27
27
  maxDABlockGas?: number;
28
28
  /** Per-block gas budget multiplier for both L2 and DA gas. Budget = (checkpointLimit / maxBlocks) * multiplier. */
29
29
  perBlockAllocationMultiplier?: number;
30
+ /** Redistribute remaining checkpoint budget evenly across remaining blocks instead of allowing a single block to consume the entire remaining budget. */
31
+ redistributeCheckpointBudget?: boolean;
30
32
  /** Recipient of block reward. */
31
33
  coinbase?: EthAddress;
32
34
  /** Address to receive fees. */
@@ -94,6 +96,7 @@ export const SequencerConfigSchema = zodFor<SequencerConfig>()(
94
96
  publishTxsWithProposals: z.boolean().optional(),
95
97
  maxDABlockGas: z.number().optional(),
96
98
  perBlockAllocationMultiplier: z.number().optional(),
99
+ redistributeCheckpointBudget: z.boolean().optional(),
97
100
  coinbase: schemas.EthAddress.optional(),
98
101
  feeRecipient: schemas.AztecAddress.optional(),
99
102
  acvmWorkingDirectory: z.string().optional(),
@@ -142,7 +145,7 @@ type SequencerConfigOptionalKeys =
142
145
  | 'maxTxsPerCheckpoint'
143
146
  | 'maxL2BlockGas'
144
147
  | 'maxDABlockGas'
145
- | 'perBlockAllocationMultiplier';
148
+ | 'redistributeCheckpointBudget';
146
149
 
147
150
  export type ResolvedSequencerConfig = Prettify<
148
151
  Required<Omit<SequencerConfig, SequencerConfigOptionalKeys>> & Pick<SequencerConfig, SequencerConfigOptionalKeys>
@@ -3,6 +3,7 @@ import type { PromiseWithResolvers } from '@aztec/foundation/promise';
3
3
 
4
4
  import { z } from 'zod';
5
5
 
6
+ import type { BlockHash } from '../block/block_hash.js';
6
7
  import type { SnapshotDataKeys } from '../snapshots/types.js';
7
8
  import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from './merkle_tree_operations.js';
8
9
 
@@ -80,12 +81,12 @@ export interface WorldStateSynchronizer extends ReadonlyWorldStateAccess, ForkMe
80
81
  resumeSync(): void;
81
82
 
82
83
  /**
83
- * Forces an immediate sync to an optionally provided minimum block number
84
+ * Forces an immediate sync to an optionally provided minimum block number.
84
85
  * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
85
- * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
86
+ * @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash. On mismatch, triggers a resync (reorg detection).
86
87
  * @returns A promise that resolves with the block number the world state was synced to
87
88
  */
88
- syncImmediate(minBlockNumber?: BlockNumber, skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber>;
89
+ syncImmediate(minBlockNumber?: BlockNumber, blockHash?: BlockHash): Promise<BlockNumber>;
89
90
 
90
91
  /** Deletes the db */
91
92
  clear(): Promise<void>;
@@ -25,7 +25,7 @@ export class ClaimedLengthArray<T extends Serializable, N extends number> {
25
25
  arrayLength: N,
26
26
  ): ClaimedLengthArray<T, N> {
27
27
  const reader = BufferReader.asReader(buffer);
28
- const array = reader.readArray(arrayLength, deserializer);
28
+ const array = reader.readArray(arrayLength, deserializer) as Tuple<T, N>;
29
29
  const claimedLength = reader.readNumber();
30
30
  return new ClaimedLengthArray(array, claimedLength);
31
31
  }
@@ -42,7 +42,7 @@ export class ClaimedLengthArray<T extends Serializable, N extends number> {
42
42
  arrayLength: N,
43
43
  ): ClaimedLengthArray<T, N> {
44
44
  const reader = FieldReader.asReader(fields);
45
- const array = reader.readArray(arrayLength, deserializer);
45
+ const array = reader.readTuple(arrayLength, deserializer);
46
46
  const claimedLength = reader.readU32();
47
47
  return new ClaimedLengthArray(array, claimedLength);
48
48
  }
@@ -105,8 +105,11 @@ export class PrivateKernelResetHints<
105
105
  fromBuffer: buf =>
106
106
  nullifierReadRequestHintsFromBuffer(buf, numNullifierReadRequestPending, numNullifierReadRequestSettled),
107
107
  }),
108
- reader.readArray(numKeyValidationHints, KeyValidationHint),
109
- reader.readArray(numTransientDataSquashingHints, TransientDataSquashingHint),
108
+ reader.readArray(numKeyValidationHints, KeyValidationHint) as Tuple<KeyValidationHint, KEY_VALIDATION_HINTS_LEN>,
109
+ reader.readArray(numTransientDataSquashingHints, TransientDataSquashingHint) as Tuple<
110
+ TransientDataSquashingHint,
111
+ TRANSIENT_DATA_HINTS_LEN
112
+ >,
110
113
  );
111
114
  }
112
115
  }