@aztec/stdlib 0.0.1-commit.10bd49492 → 0.0.1-commit.125b3452

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 (58) hide show
  1. package/dest/contract/contract_address.d.ts +3 -3
  2. package/dest/contract/contract_address.js +3 -3
  3. package/dest/contract/contract_class_id.d.ts +2 -2
  4. package/dest/contract/contract_class_id.js +2 -2
  5. package/dest/hash/hash.d.ts +16 -1
  6. package/dest/hash/hash.d.ts.map +1 -1
  7. package/dest/hash/hash.js +24 -0
  8. package/dest/interfaces/aztec-node-admin.d.ts +7 -1
  9. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  10. package/dest/interfaces/aztec-node.d.ts +2 -1
  11. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  12. package/dest/interfaces/block-builder.d.ts +11 -6
  13. package/dest/interfaces/block-builder.d.ts.map +1 -1
  14. package/dest/interfaces/block-builder.js +10 -5
  15. package/dest/interfaces/configs.d.ts +12 -2
  16. package/dest/interfaces/configs.d.ts.map +1 -1
  17. package/dest/interfaces/configs.js +2 -0
  18. package/dest/interfaces/l2_logs_source.d.ts +5 -3
  19. package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
  20. package/dest/interfaces/merkle_tree_operations.d.ts +9 -19
  21. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  22. package/dest/interfaces/prover-client.js +1 -1
  23. package/dest/interfaces/world_state.d.ts +5 -4
  24. package/dest/interfaces/world_state.d.ts.map +1 -1
  25. package/dest/logs/log_filter.d.ts +4 -1
  26. package/dest/logs/log_filter.d.ts.map +1 -1
  27. package/dest/logs/log_filter.js +2 -1
  28. package/dest/messaging/l1_to_l2_message_source.d.ts +4 -2
  29. package/dest/messaging/l1_to_l2_message_source.d.ts.map +1 -1
  30. package/dest/noir/index.d.ts +3 -3
  31. package/dest/noir/index.d.ts.map +1 -1
  32. package/dest/tx/profiling.d.ts +14 -2
  33. package/dest/tx/profiling.d.ts.map +1 -1
  34. package/dest/tx/profiling.js +13 -3
  35. package/dest/update-checker/package_version.d.ts +2 -2
  36. package/dest/update-checker/package_version.d.ts.map +1 -1
  37. package/dest/update-checker/package_version.js +16 -3
  38. package/dest/versioning/versioning.d.ts +4 -2
  39. package/dest/versioning/versioning.d.ts.map +1 -1
  40. package/dest/versioning/versioning.js +4 -1
  41. package/package.json +8 -8
  42. package/src/contract/contract_address.ts +3 -3
  43. package/src/contract/contract_class_id.ts +2 -2
  44. package/src/gas/README.md +123 -0
  45. package/src/hash/hash.ts +29 -0
  46. package/src/interfaces/aztec-node.ts +1 -0
  47. package/src/interfaces/block-builder.ts +17 -6
  48. package/src/interfaces/configs.ts +9 -1
  49. package/src/interfaces/l2_logs_source.ts +4 -1
  50. package/src/interfaces/merkle_tree_operations.ts +8 -18
  51. package/src/interfaces/prover-client.ts +1 -1
  52. package/src/interfaces/world_state.ts +4 -3
  53. package/src/logs/log_filter.ts +5 -0
  54. package/src/messaging/l1_to_l2_message_source.ts +3 -1
  55. package/src/noir/index.ts +2 -2
  56. package/src/tx/profiling.ts +11 -2
  57. package/src/update-checker/package_version.ts +19 -6
  58. package/src/versioning/versioning.ts +4 -1
@@ -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.
@@ -64,6 +64,9 @@ export type FullNodeBlockBuilderConfig = Pick<L1RollupConstants, 'l1GenesisTime'
64
64
  | 'maxTxsPerCheckpoint'
65
65
  | 'maxL2BlockGas'
66
66
  | 'maxDABlockGas'
67
+ | 'redistributeCheckpointBudget'
68
+ | 'perBlockAllocationMultiplier'
69
+ | 'maxBlocksPerCheckpoint'
67
70
  >;
68
71
 
69
72
  export const FullNodeBlockBuilderConfigKeys: (keyof FullNodeBlockBuilderConfig)[] = [
@@ -79,13 +82,20 @@ export const FullNodeBlockBuilderConfigKeys: (keyof FullNodeBlockBuilderConfig)[
79
82
  'maxL2BlockGas',
80
83
  'maxDABlockGas',
81
84
  'rollupManaLimit',
85
+ 'redistributeCheckpointBudget',
86
+ 'perBlockAllocationMultiplier',
87
+ 'maxBlocksPerCheckpoint',
82
88
  ] as const;
83
89
 
84
- /** Thrown when no valid transactions are available to include in a block after processing, and this is not the first block in a checkpoint. */
85
- export class NoValidTxsError extends Error {
86
- constructor(public readonly failedTxs: FailedTx[]) {
87
- super('No valid transactions to include in block');
88
- this.name = 'NoValidTxsError';
90
+ /** Thrown when the number of successfully processed transactions is below the required minimum. */
91
+ export class InsufficientValidTxsError extends Error {
92
+ constructor(
93
+ public readonly processedCount: number,
94
+ public readonly minRequired: number,
95
+ public readonly failedTxs: FailedTx[],
96
+ ) {
97
+ super(`Insufficient valid txs: got ${processedCount} but need ${minRequired}`);
98
+ this.name = 'InsufficientValidTxsError';
89
99
  }
90
100
  }
91
101
 
@@ -100,11 +110,12 @@ export type BuildBlockInCheckpointResult = {
100
110
 
101
111
  /** Interface for building blocks within a checkpoint context. */
102
112
  export interface ICheckpointBlockBuilder {
113
+ /** Builds a single block within this checkpoint. Throws InsufficientValidTxsError if fewer than minValidTxs succeed. */
103
114
  buildBlock(
104
115
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
105
116
  blockNumber: BlockNumber,
106
117
  timestamp: bigint,
107
- opts: PublicProcessorLimits,
118
+ opts: PublicProcessorLimits & { minValidTxs?: number },
108
119
  ): Promise<BuildBlockInCheckpointResult>;
109
120
  }
110
121
 
@@ -27,6 +27,10 @@ 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;
32
+ /** Computed max number of blocks per checkpoint from timetable. */
33
+ maxBlocksPerCheckpoint?: number;
30
34
  /** Recipient of block reward. */
31
35
  coinbase?: EthAddress;
32
36
  /** Address to receive fees. */
@@ -94,6 +98,8 @@ export const SequencerConfigSchema = zodFor<SequencerConfig>()(
94
98
  publishTxsWithProposals: z.boolean().optional(),
95
99
  maxDABlockGas: z.number().optional(),
96
100
  perBlockAllocationMultiplier: z.number().optional(),
101
+ redistributeCheckpointBudget: z.boolean().optional(),
102
+ maxBlocksPerCheckpoint: z.number().optional(),
97
103
  coinbase: schemas.EthAddress.optional(),
98
104
  feeRecipient: schemas.AztecAddress.optional(),
99
105
  acvmWorkingDirectory: z.string().optional(),
@@ -142,7 +148,9 @@ type SequencerConfigOptionalKeys =
142
148
  | 'maxTxsPerCheckpoint'
143
149
  | 'maxL2BlockGas'
144
150
  | 'maxDABlockGas'
145
- | 'perBlockAllocationMultiplier';
151
+ | 'perBlockAllocationMultiplier'
152
+ | 'redistributeCheckpointBudget'
153
+ | 'maxBlocksPerCheckpoint';
146
154
 
147
155
  export type ResolvedSequencerConfig = Prettify<
148
156
  Required<Omit<SequencerConfig, SequencerConfigOptionalKeys>> & Pick<SequencerConfig, SequencerConfigOptionalKeys>
@@ -16,10 +16,11 @@ export interface L2LogsSource {
16
16
  * array implies no logs match that tag.
17
17
  * @param tags - The tags to search for.
18
18
  * @param page - The page number (0-indexed) for pagination.
19
+ * @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
19
20
  * @returns An array of log arrays, one per tag. Returns at most 10 logs per tag per page. If 10 logs are returned
20
21
  * for a tag, the caller should fetch the next page to check for more logs.
21
22
  */
22
- getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]>;
23
+ getPrivateLogsByTags(tags: SiloedTag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]>;
23
24
 
24
25
  /**
25
26
  * Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
@@ -27,6 +28,7 @@ export interface L2LogsSource {
27
28
  * @param contractAddress - The contract address to search logs for.
28
29
  * @param tags - The tags to search for.
29
30
  * @param page - The page number (0-indexed) for pagination.
31
+ * @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
30
32
  * @returns An array of log arrays, one per tag. Returns at most 10 logs per tag per page. If 10 logs are returned
31
33
  * for a tag, the caller should fetch the next page to check for more logs.
32
34
  */
@@ -34,6 +36,7 @@ export interface L2LogsSource {
34
36
  contractAddress: AztecAddress,
35
37
  tags: Tag[],
36
38
  page?: number,
39
+ upToBlockNumber?: BlockNumber,
37
40
  ): Promise<TxScopedL2Log[][]>;
38
41
 
39
42
  /**
@@ -225,30 +225,20 @@ export interface MerkleTreeReadOperations {
225
225
  }
226
226
 
227
227
  export interface MerkleTreeCheckpointOperations {
228
- /**
229
- * Checkpoints the current fork state
230
- */
231
- createCheckpoint(): Promise<void>;
228
+ /** Checkpoints the current fork state. Returns the depth of the new checkpoint. */
229
+ createCheckpoint(): Promise<number>;
232
230
 
233
- /**
234
- * Commits the current checkpoint
235
- */
231
+ /** Commits the current checkpoint. */
236
232
  commitCheckpoint(): Promise<void>;
237
233
 
238
- /**
239
- * Reverts the current checkpoint
240
- */
234
+ /** Reverts the current checkpoint. */
241
235
  revertCheckpoint(): Promise<void>;
242
236
 
243
- /**
244
- * Commits all checkpoints
245
- */
246
- commitAllCheckpoints(): Promise<void>;
237
+ /** Commits all checkpoints above the given depth, leaving checkpoint depth at the given value. */
238
+ commitAllCheckpointsTo(depth: number): Promise<void>;
247
239
 
248
- /**
249
- * Reverts all checkpoints
250
- */
251
- revertAllCheckpoints(): Promise<void>;
240
+ /** Reverts all checkpoints above the given depth, leaving checkpoint depth at the given value. */
241
+ revertAllCheckpointsTo(depth: number): Promise<void>;
252
242
  }
253
243
 
254
244
  export interface MerkleTreeWriteOperations
@@ -113,7 +113,7 @@ export const proverConfigMappings: ConfigMappingsType<ProverConfig> = {
113
113
  enqueueConcurrency: {
114
114
  env: 'PROVER_ENQUEUE_CONCURRENCY',
115
115
  description: 'Max concurrent jobs the orchestrator serializes and enqueues to the broker.',
116
- ...numberConfigHelper(10),
116
+ ...numberConfigHelper(50),
117
117
  },
118
118
  };
119
119
 
@@ -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>;
@@ -1,3 +1,5 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+
1
3
  import { z } from 'zod';
2
4
 
3
5
  import type { AztecAddress } from '../aztec-address/index.js';
@@ -20,6 +22,8 @@ export type LogFilter = {
20
22
  afterLog?: LogId;
21
23
  /** The contract address to filter logs by. */
22
24
  contractAddress?: AztecAddress;
25
+ /** The tag (first field of the log) to filter logs by. */
26
+ tag?: Fr;
23
27
  };
24
28
 
25
29
  export const LogFilterSchema: ZodFor<LogFilter> = z.object({
@@ -28,4 +32,5 @@ export const LogFilterSchema: ZodFor<LogFilter> = z.object({
28
32
  toBlock: schemas.Integer.optional(),
29
33
  afterLog: LogId.schema.optional(),
30
34
  contractAddress: schemas.AztecAddress.optional(),
35
+ tag: schemas.Fr.optional(),
31
36
  });
@@ -10,7 +10,9 @@ export interface L1ToL2MessageSource {
10
10
  /**
11
11
  * Gets new L1 to L2 message (to be) included in a given checkpoint.
12
12
  * @param checkpointNumber - Checkpoint number to get messages for.
13
- * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
13
+ * @returns The L1 to L2 messages/leaves of the messages subtree.
14
+ * @throws If the message tree for the given checkpoint has not yet been sealed on L1
15
+ * (i.e., checkpointNumber >= inbox treeInProgress).
14
16
  */
15
17
  getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]>;
16
18
 
package/src/noir/index.ts CHANGED
@@ -19,7 +19,7 @@ export const AZTEC_VIEW_ATTRIBUTE = 'abi_view';
19
19
  export interface NoirFunctionAbi {
20
20
  /** The parameters of the function. */
21
21
  parameters: ABIParameter[];
22
- /** The return type of the function. */
22
+ /** The return type of the function, or null for void functions. */
23
23
  return_type: {
24
24
  /**
25
25
  * The type of the return value.
@@ -29,7 +29,7 @@ export interface NoirFunctionAbi {
29
29
  * The visibility of the return value.
30
30
  */
31
31
  visibility: ABIParameterVisibility;
32
- };
32
+ } | null;
33
33
  /** Mapping of error selector => error type */
34
34
  error_types: Partial<Record<string, AbiErrorType>>;
35
35
  }
@@ -3,6 +3,7 @@ import { type ZodFor, optional, schemas } from '@aztec/foundation/schemas';
3
3
 
4
4
  import { z } from 'zod';
5
5
 
6
+ import { AztecAddress } from '../aztec-address/index.js';
6
7
  import type { AztecNode } from '../interfaces/aztec-node.js';
7
8
  import { type PrivateExecutionStep, PrivateExecutionStepSchema } from '../kernel/private_kernel_prover_output.js';
8
9
 
@@ -160,6 +161,9 @@ export class TxProfileResult {
160
161
  export class UtilityExecutionResult {
161
162
  constructor(
162
163
  public result: Fr[],
164
+ public offchainEffects: { data: Fr[]; contractAddress: AztecAddress }[],
165
+ /** Timestamp of the anchor block used during utility execution. */
166
+ public anchorBlockTimestamp: bigint,
163
167
  public stats?: SimulationStats,
164
168
  ) {}
165
169
 
@@ -167,13 +171,18 @@ export class UtilityExecutionResult {
167
171
  return z
168
172
  .object({
169
173
  result: z.array(schemas.Fr),
174
+ offchainEffects: z.array(z.object({ data: z.array(schemas.Fr), contractAddress: AztecAddress.schema })),
175
+ anchorBlockTimestamp: schemas.BigInt,
170
176
  stats: optional(SimulationStatsSchema),
171
177
  })
172
- .transform(({ result, stats }) => new UtilityExecutionResult(result, stats));
178
+ .transform(
179
+ ({ result, offchainEffects, anchorBlockTimestamp, stats }) =>
180
+ new UtilityExecutionResult(result, offchainEffects, anchorBlockTimestamp, stats),
181
+ );
173
182
  }
174
183
 
175
184
  static random(): UtilityExecutionResult {
176
- return new UtilityExecutionResult([Fr.random()], {
185
+ return new UtilityExecutionResult([Fr.random()], [], 0n, {
177
186
  nodeRPCCalls: {
178
187
  perMethod: { getBlockHeader: { times: [1] } },
179
188
  roundTrips: {
@@ -3,15 +3,28 @@ import { fileURLToPath } from '@aztec/foundation/url';
3
3
  import { readFileSync } from 'fs';
4
4
  import { dirname, resolve } from 'path';
5
5
 
6
- /** Returns the package version from the release-please manifest, or undefined if not found. */
6
+ /** Returns the package version from the release-please manifest or the package.json, or undefined if not found. */
7
7
  export function getPackageVersion(): string | undefined {
8
+ const dir = dirname(fileURLToPath(import.meta.url));
9
+
10
+ // Try the release-please manifest first (works in dev/repo checkout).
8
11
  try {
9
- const releasePleaseManifestPath = resolve(
10
- dirname(fileURLToPath(import.meta.url)),
11
- '../../../../.release-please-manifest.json',
12
- );
12
+ const releasePleaseManifestPath = resolve(dir, '../../../../.release-please-manifest.json');
13
13
  return JSON.parse(readFileSync(releasePleaseManifestPath).toString())['.'];
14
14
  } catch {
15
- return undefined;
15
+ // Not in a repo checkout, fall through.
16
+ }
17
+
18
+ // Fall back to the stdlib package.json version (works in npm-installed packages).
19
+ try {
20
+ const packageJsonPath = resolve(dir, '../../package.json');
21
+ const version = JSON.parse(readFileSync(packageJsonPath).toString()).version;
22
+ if (version && version !== '0.1.0') {
23
+ return version;
24
+ }
25
+ } catch {
26
+ // No package.json found either.
16
27
  }
28
+
29
+ return undefined;
17
30
  }
@@ -115,7 +115,7 @@ export function validatePartialComponentVersionsMatch(
115
115
  }
116
116
 
117
117
  /** Returns a Koa middleware that injects the versioning info as headers. */
118
- export function getVersioningMiddleware(versions: Partial<ComponentsVersions>) {
118
+ export function getVersioningMiddleware(versions: Partial<ComponentsVersions>, opts?: { packageVersion?: string }) {
119
119
  return async (ctx: Koa.Context, next: () => Promise<void>) => {
120
120
  try {
121
121
  await next();
@@ -128,6 +128,9 @@ export function getVersioningMiddleware(versions: Partial<ComponentsVersions>) {
128
128
  ctx.set(`x-aztec-${key}`, value.toString());
129
129
  }
130
130
  }
131
+ if (opts?.packageVersion) {
132
+ ctx.set('x-aztec-packageVersion', opts.packageVersion);
133
+ }
131
134
  }
132
135
  };
133
136
  }