@aztec/stdlib 5.0.0-rc.1 → 5.0.0-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 (136) hide show
  1. package/dest/abi/buffer.d.ts +6 -2
  2. package/dest/abi/buffer.d.ts.map +1 -1
  3. package/dest/abi/buffer.js +13 -1
  4. package/dest/avm/avm.js +1 -1
  5. package/dest/aztec-address/index.d.ts +35 -5
  6. package/dest/aztec-address/index.d.ts.map +1 -1
  7. package/dest/aztec-address/index.js +32 -8
  8. package/dest/block/l2_block_source.d.ts +11 -25
  9. package/dest/block/l2_block_source.d.ts.map +1 -1
  10. package/dest/block/l2_block_source.js +0 -1
  11. package/dest/block/l2_block_stream/interfaces.d.ts +25 -5
  12. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  13. package/dest/block/l2_block_stream/l2_block_stream.d.ts +29 -7
  14. package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
  15. package/dest/block/l2_block_stream/l2_block_stream.js +165 -152
  16. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +10 -2
  17. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  18. package/dest/block/l2_block_stream/l2_tips_store_base.js +33 -15
  19. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  20. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  21. package/dest/block/test/l2_tips_store_test_suite.js +94 -3
  22. package/dest/checkpoint/index.d.ts +2 -1
  23. package/dest/checkpoint/index.d.ts.map +1 -1
  24. package/dest/checkpoint/index.js +1 -0
  25. package/dest/checkpoint/simulation_overrides.d.ts +61 -0
  26. package/dest/checkpoint/simulation_overrides.d.ts.map +1 -0
  27. package/dest/checkpoint/simulation_overrides.js +98 -0
  28. package/dest/contract/interfaces/contract_data_source.d.ts +3 -5
  29. package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
  30. package/dest/file-store/factory.d.ts +1 -1
  31. package/dest/file-store/factory.d.ts.map +1 -1
  32. package/dest/file-store/factory.js +7 -0
  33. package/dest/file-store/index.d.ts +2 -1
  34. package/dest/file-store/index.d.ts.map +1 -1
  35. package/dest/file-store/index.js +1 -0
  36. package/dest/file-store/memory.d.ts +24 -0
  37. package/dest/file-store/memory.d.ts.map +1 -0
  38. package/dest/file-store/memory.js +80 -0
  39. package/dest/interfaces/archiver.js +1 -1
  40. package/dest/interfaces/aztec-node-debug.d.ts +26 -1
  41. package/dest/interfaces/aztec-node-debug.d.ts.map +1 -1
  42. package/dest/interfaces/aztec-node-debug.js +20 -0
  43. package/dest/interfaces/aztec-node.d.ts +20 -20
  44. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  45. package/dest/interfaces/aztec-node.js +8 -15
  46. package/dest/interfaces/chain_tips.d.ts +8 -47
  47. package/dest/interfaces/chain_tips.d.ts.map +1 -1
  48. package/dest/interfaces/chain_tips.js +1 -6
  49. package/dest/interfaces/checkpoint_parameter.d.ts +3 -3
  50. package/dest/interfaces/checkpoint_parameter.d.ts.map +1 -1
  51. package/dest/interfaces/checkpoint_parameter.js +3 -3
  52. package/dest/interfaces/prover-node.d.ts +6 -7
  53. package/dest/interfaces/prover-node.d.ts.map +1 -1
  54. package/dest/interfaces/prover-node.js +15 -10
  55. package/dest/kernel/hints/read_request.js +1 -1
  56. package/dest/kernel/log_hash.d.ts +1 -1
  57. package/dest/kernel/log_hash.d.ts.map +1 -1
  58. package/dest/kernel/log_hash.js +2 -2
  59. package/dest/kernel/note_hash.js +1 -1
  60. package/dest/kernel/nullifier.js +1 -1
  61. package/dest/kernel/private_log_data.d.ts +1 -1
  62. package/dest/kernel/private_log_data.d.ts.map +1 -1
  63. package/dest/kernel/private_log_data.js +1 -1
  64. package/dest/logs/app_tagging_secret.d.ts +21 -6
  65. package/dest/logs/app_tagging_secret.d.ts.map +1 -1
  66. package/dest/logs/app_tagging_secret.js +32 -22
  67. package/dest/logs/contract_class_log.d.ts +1 -2
  68. package/dest/logs/contract_class_log.d.ts.map +1 -1
  69. package/dest/logs/contract_class_log.js +0 -4
  70. package/dest/logs/message_context.d.ts +5 -15
  71. package/dest/logs/message_context.d.ts.map +1 -1
  72. package/dest/logs/message_context.js +1 -66
  73. package/dest/logs/pending_tagged_log.d.ts +6 -8
  74. package/dest/logs/pending_tagged_log.d.ts.map +1 -1
  75. package/dest/logs/pending_tagged_log.js +1 -31
  76. package/dest/p2p/checkpoint_attestation.d.ts +2 -1
  77. package/dest/p2p/checkpoint_attestation.d.ts.map +1 -1
  78. package/dest/p2p/checkpoint_proposal.d.ts +2 -1
  79. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  80. package/dest/p2p/consensus_payload.d.ts +2 -1
  81. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  82. package/dest/rollup/checkpoint_header.d.ts +8 -3
  83. package/dest/rollup/checkpoint_header.d.ts.map +1 -1
  84. package/dest/rollup/checkpoint_header.js +20 -10
  85. package/dest/tests/factories.d.ts +1 -1
  86. package/dest/tests/factories.d.ts.map +1 -1
  87. package/dest/tests/factories.js +3 -12
  88. package/dest/trees/nullifier_membership_witness.d.ts +5 -8
  89. package/dest/trees/nullifier_membership_witness.d.ts.map +1 -1
  90. package/dest/trees/nullifier_membership_witness.js +0 -9
  91. package/dest/trees/public_data_witness.d.ts +7 -17
  92. package/dest/trees/public_data_witness.d.ts.map +1 -1
  93. package/dest/trees/public_data_witness.js +0 -27
  94. package/dest/tx/execution_payload.d.ts +1 -1
  95. package/dest/tx/execution_payload.d.ts.map +1 -1
  96. package/dest/tx/execution_payload.js +1 -1
  97. package/dest/tx/global_variable_builder.d.ts +2 -12
  98. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  99. package/dest/tx/global_variables.js +2 -2
  100. package/package.json +8 -8
  101. package/src/abi/buffer.ts +13 -1
  102. package/src/avm/avm.ts +1 -1
  103. package/src/aztec-address/index.ts +36 -6
  104. package/src/block/l2_block_source.ts +10 -15
  105. package/src/block/l2_block_stream/interfaces.ts +25 -5
  106. package/src/block/l2_block_stream/l2_block_stream.ts +222 -172
  107. package/src/block/l2_block_stream/l2_tips_store_base.ts +36 -15
  108. package/src/block/test/l2_tips_store_test_suite.ts +73 -4
  109. package/src/checkpoint/index.ts +1 -0
  110. package/src/checkpoint/simulation_overrides.ts +171 -0
  111. package/src/contract/interfaces/contract_data_source.ts +2 -4
  112. package/src/file-store/factory.ts +7 -0
  113. package/src/file-store/index.ts +1 -0
  114. package/src/file-store/memory.ts +94 -0
  115. package/src/interfaces/archiver.ts +1 -1
  116. package/src/interfaces/aztec-node-debug.ts +37 -0
  117. package/src/interfaces/aztec-node.ts +30 -33
  118. package/src/interfaces/chain_tips.ts +8 -16
  119. package/src/interfaces/checkpoint_parameter.ts +3 -3
  120. package/src/interfaces/prover-node.ts +19 -11
  121. package/src/kernel/hints/read_request.ts +1 -1
  122. package/src/kernel/log_hash.ts +5 -2
  123. package/src/kernel/note_hash.ts +1 -1
  124. package/src/kernel/nullifier.ts +1 -1
  125. package/src/kernel/private_log_data.ts +4 -1
  126. package/src/logs/app_tagging_secret.ts +39 -23
  127. package/src/logs/contract_class_log.ts +0 -9
  128. package/src/logs/message_context.ts +7 -65
  129. package/src/logs/pending_tagged_log.ts +6 -33
  130. package/src/rollup/checkpoint_header.ts +16 -2
  131. package/src/tests/factories.ts +3 -6
  132. package/src/trees/nullifier_membership_witness.ts +0 -11
  133. package/src/trees/public_data_witness.ts +0 -31
  134. package/src/tx/execution_payload.ts +2 -1
  135. package/src/tx/global_variable_builder.ts +1 -17
  136. package/src/tx/global_variables.ts +2 -2
package/src/avm/avm.ts CHANGED
@@ -1152,7 +1152,7 @@ export class CallStackMetadata {
1152
1152
 
1153
1153
  const { stack, leaf } = failingCall;
1154
1154
  const aztecCallStack = stack.map(call => ({
1155
- contractAddress: AztecAddress.fromField(call.contractAddress),
1155
+ contractAddress: AztecAddress.fromFieldUnsafe(call.contractAddress),
1156
1156
  functionSelector: call.calldata.length > 0 ? FunctionSelector.fromFieldOrUndefined(call.calldata[0]) : undefined,
1157
1157
  }));
1158
1158
 
@@ -43,34 +43,64 @@ export class AztecAddress {
43
43
  static ZERO = new AztecAddress(Buffer.alloc(32, 0));
44
44
 
45
45
  /** Null msg sender address. Not part of the protocol contracts tree. */
46
- static NULL_MSG_SENDER = AztecAddress.fromBigInt(NULL_MSG_SENDER_CONTRACT_ADDRESS);
46
+ static NULL_MSG_SENDER = AztecAddress.fromBigIntUnsafe(NULL_MSG_SENDER_CONTRACT_ADDRESS);
47
47
 
48
48
  static zero(): AztecAddress {
49
49
  return AztecAddress.ZERO;
50
50
  }
51
51
 
52
- static fromField(fr: Fr) {
52
+ /**
53
+ * Builds an `AztecAddress` from a field **without checking it is a valid address** (the x-coordinate of a point on
54
+ * the Grumpkin curve, which is what lets it be encrypted to). Use {@link AztecAddress.isValid} to validate an
55
+ * untrusted one, or {@link AztecAddress.random} for valid test addresses.
56
+ */
57
+ static fromFieldUnsafe(fr: Fr) {
53
58
  return new AztecAddress(fr);
54
59
  }
55
60
 
61
+ /**
62
+ * Deserializes an `AztecAddress` from a buffer. It does **not** check the value is a valid Grumpkin-curve address
63
+ * (see {@link AztecAddress.isValid}); it is meant for reading addresses from already-validated serialized data. Use
64
+ * {@link AztecAddress.random} for valid test addresses.
65
+ */
56
66
  static fromBuffer(buffer: Buffer | BufferReader) {
57
67
  return new AztecAddress(fromBuffer(buffer, Fr));
58
68
  }
59
69
 
70
+ /**
71
+ * Deserializes an `AztecAddress` from a field reader. It does **not** check the value is a valid Grumpkin-curve
72
+ * address (see {@link AztecAddress.isValid}); it is meant for reading addresses from already-validated serialized
73
+ * data. Use {@link AztecAddress.random} for valid test addresses.
74
+ */
60
75
  static fromFields(fields: Fr[] | FieldReader) {
61
76
  const reader = FieldReader.asReader(fields);
62
77
  return new AztecAddress(reader.readField());
63
78
  }
64
79
 
65
- static fromBigInt(value: bigint) {
80
+ /**
81
+ * Builds an `AztecAddress` from a bigint **without checking it is a valid address** (the x-coordinate of a point on
82
+ * the Grumpkin curve, which is what lets it be encrypted to). Use {@link AztecAddress.isValid} to validate an
83
+ * untrusted one, or {@link AztecAddress.random} for valid test addresses.
84
+ */
85
+ static fromBigIntUnsafe(value: bigint) {
66
86
  return new AztecAddress(new Fr(value));
67
87
  }
68
88
 
69
- static fromNumber(value: number) {
89
+ /**
90
+ * Builds an `AztecAddress` from a number **without checking it is a valid address** (the x-coordinate of a point on
91
+ * the Grumpkin curve, which is what lets it be encrypted to). Use {@link AztecAddress.isValid} to validate an
92
+ * untrusted one, or {@link AztecAddress.random} for valid test addresses.
93
+ */
94
+ static fromNumberUnsafe(value: number) {
70
95
  return new AztecAddress(new Fr(value));
71
96
  }
72
97
 
73
- static fromString(buf: string) {
98
+ /**
99
+ * Builds an `AztecAddress` from a hex string **without checking it is a valid address** (the x-coordinate of a
100
+ * point on the Grumpkin curve, which is what lets it be encrypted to). Use {@link AztecAddress.isValid} to
101
+ * validate an untrusted one, or {@link AztecAddress.random} for valid test addresses.
102
+ */
103
+ static fromStringUnsafe(buf: string) {
74
104
  return new AztecAddress(hexToBuffer(buf));
75
105
  }
76
106
 
@@ -89,7 +119,7 @@ export class AztecAddress {
89
119
  if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
90
120
  return new AztecAddress(obj);
91
121
  }
92
- return AztecAddress.fromString(obj);
122
+ return AztecAddress.fromStringUnsafe(obj);
93
123
  }
94
124
 
95
125
  /**
@@ -241,7 +241,10 @@ export interface L2BlockSource {
241
241
 
242
242
  /**
243
243
  * Looks up a proposed (archiver-internal, not-yet-L1-confirmed) checkpoint.
244
- * Returns the latest proposed entry when called with no args or `{ tag: 'proposed' }`.
244
+ * Returns the latest proposed entry when called with no args or `{ tag: 'proposed' }`; since a
245
+ * proposed entry can only be stored with a checkpoint number beyond the confirmed frontier (and is
246
+ * deleted on confirmation), the latest entry is always the leading one. Callers derive the proposed
247
+ * tip from the payload (checkpoint number, and last block `startBlock + blockCount - 1`).
245
248
  * With `{ number }` or `{ slot }`, returns the matching entry or undefined.
246
249
  * Never falls back to confirmed checkpoints.
247
250
  */
@@ -327,36 +330,29 @@ export interface L2BlockSourceEventEmitter extends L2BlockSource {
327
330
  }
328
331
 
329
332
  /**
330
- * Identifier for L2 block tags. Internal counterpart to {@link BlockTag} that exposes
331
- * the additional `proposedCheckpoint` value (used for the optimistic chain tip on the
332
- * archiver side) and omits `latest` (which is an alias for `proposed` accepted only at
333
- * the public RPC surface).
333
+ * Identifier for L2 block tags. Internal counterpart to {@link BlockTag} that omits `latest`
334
+ * (which is an alias for `proposed` accepted only at the public RPC surface).
334
335
  *
335
336
  * - proposed: Latest block proposed on L2.
336
- * - proposedCheckpoint: Latest block in the most recent proposed checkpoint (archiver-internal).
337
337
  * - checkpointed: Latest block whose enclosing checkpoint has been published on L1.
338
338
  * - proven: Latest block whose enclosing checkpoint has been proven on L1.
339
339
  * - finalized: Latest block whose proving L1 transaction has reached L1 finality.
340
- *
341
- * TODO(palla): Remove `proposedCheckpoint` and unify with `proposed`.
342
340
  */
343
- export type L2BlockTag = 'proposed' | 'proposedCheckpoint' | 'checkpointed' | 'proven' | 'finalized';
341
+ export type L2BlockTag = 'proposed' | 'checkpointed' | 'proven' | 'finalized';
344
342
 
345
343
  /** Tips of the L2 chain. */
346
344
  export type L2Tips = {
347
345
  proposed: L2BlockId;
348
346
  checkpointed: L2TipId;
349
- proposedCheckpoint: L2TipId;
350
347
  proven: L2TipId;
351
348
  finalized: L2TipId;
352
349
  };
353
350
 
354
351
  /**
355
- * Tips of the L2 chain as tracked by a local provider (world-state, l2-tips-store). Omits
356
- * `proposedCheckpoint`, which is degenerate in local stores (always equal to `checkpointed`) and
357
- * is only meaningful on the archiver side via {@link L2BlockSource}.
352
+ * Tips of the L2 chain as tracked by a local provider (world-state, l2-tips-store). Identical to
353
+ * {@link L2Tips}; the alias is retained for call sites that document a local-only provenance.
358
354
  */
359
- export type LocalL2Tips = Omit<L2Tips, 'proposedCheckpoint'>;
355
+ export type LocalL2Tips = L2Tips;
360
356
 
361
357
  export const GENESIS_CHECKPOINT_HEADER_HASH = CheckpointHeader.empty().hash();
362
358
 
@@ -398,7 +394,6 @@ const L2TipIdSchema = z.object({
398
394
  export const L2TipsSchema = z.object({
399
395
  proposed: L2BlockIdSchema,
400
396
  checkpointed: L2TipIdSchema,
401
- proposedCheckpoint: L2TipIdSchema,
402
397
  proven: L2TipIdSchema,
403
398
  finalized: L2TipIdSchema,
404
399
  });
@@ -1,6 +1,5 @@
1
1
  import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
 
3
- import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
4
3
  import type { L2Block } from '../l2_block.js';
5
4
  import type { CheckpointId, L2BlockId, L2TipId, LocalL2Tips } from '../l2_block_source.js';
6
5
 
@@ -21,7 +20,7 @@ export type LocalL2BlockId = { number: BlockNumber; hash?: string };
21
20
  */
22
21
  export type LocalChainTips = {
23
22
  proposed: LocalL2BlockId;
24
- checkpointed?: { checkpoint: CheckpointId };
23
+ checkpointed?: { block: LocalL2BlockId; checkpoint: CheckpointId };
25
24
  proven: { block: LocalL2BlockId };
26
25
  finalized: { block: LocalL2BlockId };
27
26
  };
@@ -46,10 +45,24 @@ export type L2BlockStreamEvent =
46
45
  type: 'blocks-added';
47
46
  blocks: L2Block[];
48
47
  }
49
- | /** Emits checkpoints published to L1. */ {
48
+ | /**
49
+ * Reports the new proposed tip of the chain. Emitted once per sync pass when the source's proposed tip differs
50
+ * from the pre-pass local one (downloads, a prune, or a thin tip movement). Carries only the block id; in block
51
+ * mode the corresponding payloads arrive via preceding `blocks-added` events, while in tips-only mode this is the
52
+ * sole signal that the proposed tip moved. Consumers that only track the proposed tip can ignore `blocks-added`
53
+ * entirely and anchor on this event instead.
54
+ */ {
55
+ type: 'chain-proposed';
56
+ block: L2BlockId;
57
+ }
58
+ | /**
59
+ * Reports a new checkpointed tip. Emitted at most once per sync pass when the source's checkpointed tip
60
+ * leads the local one. Carries only the block + checkpoint ids; consumers that need the full checkpoint
61
+ * payload fetch it on demand from the block source.
62
+ */ {
50
63
  type: 'chain-checkpointed';
51
- checkpoint: PublishedCheckpoint;
52
64
  block: L2BlockId;
65
+ checkpoint: CheckpointId;
53
66
  }
54
67
  | /**
55
68
  * Reports last correct block (new tip of the proposed chain). Note that this is not necessarily the anchor block
@@ -77,4 +90,11 @@ export type L2BlockStreamEvent =
77
90
 
78
91
  export type L2TipsStore = L2BlockStreamEventHandler &
79
92
  L2TipsProvider &
80
- Pick<L2BlockStreamLocalDataProvider, 'getL2BlockHash'>;
93
+ Pick<L2BlockStreamLocalDataProvider, 'getL2BlockHash'> & {
94
+ /**
95
+ * Records `(number → hash)` witnesses into the walk-back hash index without moving any tip cursor. Consumers that
96
+ * materialize per-height state should record a witness for each height they materialize, so a reorg below the
97
+ * nearest sparse anchor does not produce an over-deep prune event. See {@link L2TipsStoreBase.recordBlockHashes}.
98
+ */
99
+ recordBlockHashes(blocks: L2BlockId[]): Promise<void>;
100
+ };