@aztec/stdlib 0.0.1-commit.3f296a7d2 → 0.0.1-commit.42ee6df9b

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 (107) hide show
  1. package/dest/abi/decoder.d.ts +5 -44
  2. package/dest/abi/decoder.d.ts.map +1 -1
  3. package/dest/abi/decoder.js +12 -67
  4. package/dest/abi/function_selector.js +1 -1
  5. package/dest/abi/function_signature_decoder.d.ts +43 -0
  6. package/dest/abi/function_signature_decoder.d.ts.map +1 -0
  7. package/dest/abi/function_signature_decoder.js +66 -0
  8. package/dest/abi/index.d.ts +2 -1
  9. package/dest/abi/index.d.ts.map +1 -1
  10. package/dest/abi/index.js +1 -0
  11. package/dest/block/l2_block_source.d.ts +80 -3
  12. package/dest/block/l2_block_source.d.ts.map +1 -1
  13. package/dest/block/l2_block_source.js +1 -0
  14. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +1 -1
  15. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  16. package/dest/block/l2_block_stream/l2_tips_store_base.js +17 -4
  17. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  18. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  19. package/dest/block/test/l2_tips_store_test_suite.js +3 -2
  20. package/dest/checkpoint/checkpoint.d.ts +7 -1
  21. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  22. package/dest/checkpoint/checkpoint.js +9 -1
  23. package/dest/checkpoint/checkpoint_data.d.ts +71 -5
  24. package/dest/checkpoint/checkpoint_data.d.ts.map +1 -1
  25. package/dest/checkpoint/checkpoint_data.js +10 -0
  26. package/dest/epoch-helpers/index.d.ts +5 -1
  27. package/dest/epoch-helpers/index.d.ts.map +1 -1
  28. package/dest/epoch-helpers/index.js +6 -0
  29. package/dest/file-store/factory.d.ts +4 -3
  30. package/dest/file-store/factory.d.ts.map +1 -1
  31. package/dest/file-store/factory.js +2 -2
  32. package/dest/file-store/http.d.ts +9 -2
  33. package/dest/file-store/http.d.ts.map +1 -1
  34. package/dest/file-store/http.js +20 -9
  35. package/dest/file-store/index.d.ts +2 -1
  36. package/dest/file-store/index.d.ts.map +1 -1
  37. package/dest/hash/hash.d.ts +4 -1
  38. package/dest/hash/hash.d.ts.map +1 -1
  39. package/dest/hash/hash.js +5 -0
  40. package/dest/interfaces/archiver.d.ts +1 -1
  41. package/dest/interfaces/archiver.d.ts.map +1 -1
  42. package/dest/interfaces/archiver.js +3 -1
  43. package/dest/interfaces/aztec-node-admin.d.ts +1 -4
  44. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  45. package/dest/interfaces/validator.d.ts +2 -10
  46. package/dest/interfaces/validator.d.ts.map +1 -1
  47. package/dest/interfaces/validator.js +0 -1
  48. package/dest/logs/extended_directional_app_tagging_secret.d.ts +4 -4
  49. package/dest/logs/extended_directional_app_tagging_secret.d.ts.map +1 -1
  50. package/dest/logs/extended_directional_app_tagging_secret.js +12 -5
  51. package/dest/logs/message_context.d.ts +4 -7
  52. package/dest/logs/message_context.d.ts.map +1 -1
  53. package/dest/logs/message_context.js +23 -9
  54. package/dest/logs/pending_tagged_log.d.ts +2 -3
  55. package/dest/logs/pending_tagged_log.d.ts.map +1 -1
  56. package/dest/logs/pending_tagged_log.js +2 -2
  57. package/dest/logs/shared_secret_derivation.d.ts +11 -10
  58. package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
  59. package/dest/logs/shared_secret_derivation.js +15 -9
  60. package/dest/logs/siloed_tag.d.ts +4 -1
  61. package/dest/logs/siloed_tag.d.ts.map +1 -1
  62. package/dest/logs/siloed_tag.js +7 -3
  63. package/dest/messaging/l1_to_l2_message.d.ts +3 -2
  64. package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
  65. package/dest/messaging/l1_to_l2_message.js +11 -13
  66. package/dest/note/note_dao.d.ts +1 -1
  67. package/dest/note/note_dao.d.ts.map +1 -1
  68. package/dest/note/note_dao.js +1 -4
  69. package/dest/proofs/chonk_proof.d.ts +46 -2
  70. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  71. package/dest/proofs/chonk_proof.js +85 -10
  72. package/dest/tests/factories.d.ts +1 -1
  73. package/dest/tests/factories.d.ts.map +1 -1
  74. package/dest/tests/factories.js +10 -0
  75. package/dest/tx/capsule.d.ts +6 -2
  76. package/dest/tx/capsule.d.ts.map +1 -1
  77. package/dest/tx/capsule.js +9 -3
  78. package/dest/tx/global_variable_builder.d.ts +14 -2
  79. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  80. package/package.json +8 -8
  81. package/src/abi/decoder.ts +23 -78
  82. package/src/abi/function_selector.ts +1 -1
  83. package/src/abi/function_signature_decoder.ts +77 -0
  84. package/src/abi/index.ts +1 -0
  85. package/src/block/l2_block_source.ts +10 -2
  86. package/src/block/l2_block_stream/l2_tips_store_base.ts +24 -12
  87. package/src/block/test/l2_tips_store_test_suite.ts +8 -1
  88. package/src/checkpoint/checkpoint.ts +11 -1
  89. package/src/checkpoint/checkpoint_data.ts +40 -4
  90. package/src/epoch-helpers/index.ts +13 -0
  91. package/src/file-store/factory.ts +13 -4
  92. package/src/file-store/http.ts +29 -10
  93. package/src/file-store/index.ts +1 -0
  94. package/src/hash/hash.ts +5 -0
  95. package/src/interfaces/archiver.ts +3 -1
  96. package/src/interfaces/validator.ts +1 -5
  97. package/src/logs/extended_directional_app_tagging_secret.ts +19 -8
  98. package/src/logs/message_context.ts +17 -7
  99. package/src/logs/pending_tagged_log.ts +1 -3
  100. package/src/logs/shared_secret_derivation.ts +21 -10
  101. package/src/logs/siloed_tag.ts +7 -2
  102. package/src/messaging/l1_to_l2_message.ts +12 -9
  103. package/src/note/note_dao.ts +1 -4
  104. package/src/proofs/chonk_proof.ts +91 -5
  105. package/src/tests/factories.ts +4 -0
  106. package/src/tx/capsule.ts +10 -2
  107. package/src/tx/global_variable_builder.ts +15 -0
@@ -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';
@@ -13,7 +13,7 @@ import type { TypedEventEmitter } from '@aztec/foundation/types';
13
13
  import { z } from 'zod';
14
14
 
15
15
  import type { Checkpoint } from '../checkpoint/checkpoint.js';
16
- import type { CheckpointData } from '../checkpoint/checkpoint_data.js';
16
+ import type { CheckpointData, CommonCheckpointData, ProposedCheckpointData } from '../checkpoint/checkpoint_data.js';
17
17
  import type { PublishedCheckpoint } from '../checkpoint/published_checkpoint.js';
18
18
  import type { L1RollupConstants } from '../epoch-helpers/index.js';
19
19
  import { CheckpointHeader } from '../rollup/checkpoint_header.js';
@@ -229,6 +229,12 @@ export interface L2BlockSource {
229
229
  */
230
230
  getPendingChainValidationStatus(): Promise<ValidateCheckpointResult>;
231
231
 
232
+ /** Returns the checkpoint at the proposed chain tip. */
233
+ getProposedCheckpoint(): Promise<CommonCheckpointData | undefined>;
234
+
235
+ /** Returns proposed checkpoint, if set, undefined if not*/
236
+ getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined>;
237
+
232
238
  /** Force a sync. */
233
239
  syncImmediate(): Promise<void>;
234
240
 
@@ -312,12 +318,13 @@ export interface L2BlockSourceEventEmitter extends L2BlockSource {
312
318
  * - proven: Proven block on L1.
313
319
  * - finalized: Proven block on a finalized L1 block (not implemented, set to proven for now).
314
320
  */
315
- export type L2BlockTag = 'proposed' | 'checkpointed' | 'proven' | 'finalized';
321
+ export type L2BlockTag = 'proposed' | 'proposedCheckpoint' | 'checkpointed' | 'proven' | 'finalized';
316
322
 
317
323
  /** Tips of the L2 chain. */
318
324
  export type L2Tips = {
319
325
  proposed: L2BlockId;
320
326
  checkpointed: L2TipId;
327
+ proposedCheckpoint: L2TipId;
321
328
  proven: L2TipId;
322
329
  finalized: L2TipId;
323
330
  };
@@ -362,6 +369,7 @@ const L2TipIdSchema = z.object({
362
369
  export const L2TipsSchema = z.object({
363
370
  proposed: L2BlockIdSchema,
364
371
  checkpointed: L2TipIdSchema,
372
+ proposedCheckpoint: L2TipIdSchema,
365
373
  proven: L2TipIdSchema,
366
374
  finalized: L2TipIdSchema,
367
375
  });
@@ -66,24 +66,29 @@ export abstract class L2TipsStoreBase implements L2BlockStreamEventHandler, L2Bl
66
66
 
67
67
  public getL2Tips(): Promise<L2Tips> {
68
68
  return this.runInTransaction(async () => {
69
- const [proposedBlockId, finalizedBlockId, provenBlockId, checkpointedBlockId] = await Promise.all([
70
- this.getBlockId('proposed'),
71
- this.getBlockId('finalized'),
72
- this.getBlockId('proven'),
73
- this.getBlockId('checkpointed'),
74
- ]);
75
-
76
- const [finalizedCheckpointId, provenCheckpointId, checkpointedCheckpointId] = await Promise.all([
77
- this.getCheckpointId('finalized'),
78
- this.getCheckpointId('proven'),
79
- this.getCheckpointId('checkpointed'),
80
- ]);
69
+ const [proposedBlockId, finalizedBlockId, provenBlockId, checkpointedBlockId, proposedCheckpointBlockId] =
70
+ await Promise.all([
71
+ this.getBlockId('proposed'),
72
+ this.getBlockId('finalized'),
73
+ this.getBlockId('proven'),
74
+ this.getBlockId('checkpointed'),
75
+ this.getBlockId('proposedCheckpoint'),
76
+ ]);
77
+
78
+ const [finalizedCheckpointId, provenCheckpointId, checkpointedCheckpointId, proposedCheckpointId] =
79
+ await Promise.all([
80
+ this.getCheckpointId('finalized'),
81
+ this.getCheckpointId('proven'),
82
+ this.getCheckpointId('checkpointed'),
83
+ this.getCheckpointId('proposedCheckpoint'),
84
+ ]);
81
85
 
82
86
  return {
83
87
  proposed: proposedBlockId,
84
88
  finalized: { block: finalizedBlockId, checkpoint: finalizedCheckpointId },
85
89
  proven: { block: provenBlockId, checkpoint: provenCheckpointId },
86
90
  checkpointed: { block: checkpointedBlockId, checkpoint: checkpointedCheckpointId },
91
+ proposedCheckpoint: { block: proposedCheckpointBlockId, checkpoint: proposedCheckpointId },
87
92
  };
88
93
  });
89
94
  }
@@ -164,6 +169,12 @@ export abstract class L2TipsStoreBase implements L2BlockStreamEventHandler, L2Bl
164
169
  await this.runInTransaction(async () => {
165
170
  await this.saveTag('checkpointed', event.block);
166
171
  await this.saveCheckpoint(event.checkpoint);
172
+ // proposedCheckpoint is always >= checkpointed. If checkpointed has caught up
173
+ // or surpassed it, advance proposedCheckpoint to match.
174
+ const proposedCheckpointBlock = await this.getBlockId('proposedCheckpoint');
175
+ if (event.block.number > proposedCheckpointBlock.number) {
176
+ await this.saveTag('proposedCheckpoint', event.block);
177
+ }
167
178
  });
168
179
  }
169
180
 
@@ -174,6 +185,7 @@ export abstract class L2TipsStoreBase implements L2BlockStreamEventHandler, L2Bl
174
185
  await this.runInTransaction(async () => {
175
186
  await this.saveTag('proposed', event.block);
176
187
  await this.saveTag('checkpointed', event.block);
188
+ await this.saveTag('proposedCheckpoint', event.block);
177
189
  const storeProven = await this.getBlockId('proven');
178
190
  if (storeProven.number > event.block.number) {
179
191
  await this.saveTag('proven', event.block);
@@ -67,11 +67,18 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
67
67
  checkpoint: makeCheckpointIdForBlock(blockNumber),
68
68
  });
69
69
 
70
- const makeTips = (proposed: number, proven: number, finalized: number, checkpointed: number = 0) => ({
70
+ const makeTips = (
71
+ proposed: number,
72
+ proven: number,
73
+ finalized: number,
74
+ checkpointed: number = 0,
75
+ proposedCheckpoint: number = 0,
76
+ ) => ({
71
77
  proposed: makeTip(proposed),
72
78
  proven: makeTipId(proven),
73
79
  finalized: makeTipId(finalized),
74
80
  checkpointed: makeTipId(checkpointed),
81
+ proposedCheckpoint: makeTipId(proposedCheckpoint),
75
82
  });
76
83
 
77
84
  const makeCheckpoint = async (checkpointNumber: number, blocks: L2Block[]): Promise<PublishedCheckpoint> => {
@@ -100,7 +100,16 @@ export class Checkpoint {
100
100
  * checkpoints up to and including this one in the epoch.
101
101
  */
102
102
  public getCheckpointOutHash(): Fr {
103
- const msgs = this.blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs));
103
+ return Checkpoint.getCheckpointOutHash(this.blocks);
104
+ }
105
+
106
+ /**
107
+ * Returns the out hash computed from all l2-to-l1 messages in this checkpoint.
108
+ * Note: This value is different from the out hash in the header, which is the **accumulated** out hash over all
109
+ * checkpoints up to and including this one in the epoch.
110
+ */
111
+ static getCheckpointOutHash(blocks: L2Block[]): Fr {
112
+ const msgs = blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs));
104
113
  return computeCheckpointOutHash(msgs);
105
114
  }
106
115
 
@@ -165,6 +174,7 @@ export class Checkpoint {
165
174
  let lastArchive = previousArchive;
166
175
  for (let i = 0; i < numBlocks; i++) {
167
176
  const block = await L2Block.random(BlockNumber(startBlockNumber + i), {
177
+ checkpointNumber,
168
178
  indexWithinCheckpoint: IndexWithinCheckpoint(i),
169
179
  ...options,
170
180
  ...(lastArchive ? { lastArchive } : {}),
@@ -14,18 +14,54 @@ import { CheckpointHeader } from '../rollup/checkpoint_header.js';
14
14
  import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
15
15
  import { L1PublishedData } from './published_checkpoint.js';
16
16
 
17
- /** Lightweight checkpoint metadata without full block data. */
18
- export type CheckpointData = {
17
+ /** Base type for checkpoint data */
18
+ export type CommonCheckpointData = {
19
19
  checkpointNumber: CheckpointNumber;
20
20
  header: CheckpointHeader;
21
- archive: AppendOnlyTreeSnapshot;
22
- checkpointOutHash: Fr;
23
21
  startBlock: BlockNumber;
24
22
  blockCount: number;
23
+ };
24
+
25
+ /** Data stored with checkpoint data after publishing on l1 */
26
+ export type L1EnrichedCheckpointData = {
25
27
  attestations: CommitteeAttestation[];
26
28
  l1: L1PublishedData;
27
29
  };
28
30
 
31
+ /** Data stored alongside checkpoint data in storage */
32
+ export type StorageEnrichedCheckpointData = {
33
+ archive: AppendOnlyTreeSnapshot;
34
+ checkpointOutHash: Fr;
35
+ };
36
+
37
+ /** Data stored only with proposed checkpoint data */
38
+ export type ProposedOnlyCheckpointData = {
39
+ totalManaUsed: bigint;
40
+ feeAssetPriceModifier: bigint;
41
+ };
42
+
43
+ /** Lightweight checkpoint metadata without full block data. */
44
+ export type CheckpointData = CommonCheckpointData & StorageEnrichedCheckpointData & L1EnrichedCheckpointData;
45
+
46
+ /** Input for setting a proposed checkpoint. The archive and checkpointOutHash are computed
47
+ * internally by the block store from the stored blocks. */
48
+ export type ProposedCheckpointInput = CommonCheckpointData & ProposedOnlyCheckpointData;
49
+
50
+ /** Full data for a proposed checkpoint (proposed but not yet L1-confirmed).
51
+ * Includes fee-relevant fields used during pipelining to compute the fee header override. */
52
+ export type ProposedCheckpointData = ProposedCheckpointInput & StorageEnrichedCheckpointData;
53
+
54
+ export const ProposedCheckpointDataSchema = z.object({
55
+ checkpointNumber: CheckpointNumberSchema,
56
+ header: CheckpointHeader.schema,
57
+ archive: AppendOnlyTreeSnapshot.schema,
58
+ checkpointOutHash: schemas.Fr,
59
+ startBlock: BlockNumberSchema,
60
+ blockCount: z.number(),
61
+ totalManaUsed: schemas.BigInt,
62
+ feeAssetPriceModifier: schemas.BigInt,
63
+ });
64
+
29
65
  export const CheckpointDataSchema = z
30
66
  .object({
31
67
  checkpointNumber: CheckpointNumberSchema,
@@ -68,6 +68,14 @@ export function getNextL1SlotTimestamp(
68
68
  return constants.l1GenesisTime + (currentL1Slot + 1n) * BigInt(constants.ethereumSlotDuration);
69
69
  }
70
70
 
71
+ /** Returns the timestamp of the last L1 slot within a given L2 slot. */
72
+ export function getLastL1SlotTimestampForL2Slot(
73
+ slot: SlotNumber,
74
+ constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>,
75
+ ): bigint {
76
+ return getTimestampForSlot(slot, constants) + BigInt(constants.slotDuration - constants.ethereumSlotDuration);
77
+ }
78
+
71
79
  /** Returns the L2 slot number at the next L1 block based on the current timestamp. */
72
80
  export function getSlotAtNextL1Block(
73
81
  currentL1Timestamp: bigint,
@@ -154,6 +162,11 @@ export function getProofSubmissionDeadlineTimestamp(
154
162
  return getTimestampForSlot(deadlineSlot, constants);
155
163
  }
156
164
 
165
+ /** Computes the quorum size required for a committee (⌊2n/3⌋ + 1). */
166
+ export function computeQuorum(committeeSize: number): number {
167
+ return Math.floor((committeeSize * 2) / 3) + 1;
168
+ }
169
+
157
170
  /** Returns the timestamp to start building a block for a given L2 slot. Computed as the start timestamp of the slot minus one L1 slot duration. */
158
171
  export function getSlotStartBuildTimestamp(
159
172
  slotNumber: SlotNumber,
@@ -1,7 +1,7 @@
1
1
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import { GoogleCloudFileStore } from './gcs.js';
4
- import { HttpFileStore } from './http.js';
4
+ import { HttpFileStore, type HttpFileStoreOptions } from './http.js';
5
5
  import type { FileStore, ReadOnlyFileStore } from './interface.js';
6
6
  import { LocalFileStore } from './local.js';
7
7
  import { S3FileStore } from './s3.js';
@@ -59,17 +59,26 @@ export async function createFileStore(
59
59
  }
60
60
  }
61
61
 
62
- export async function createReadOnlyFileStore(config: string, logger?: Logger): Promise<ReadOnlyFileStore>;
63
- export async function createReadOnlyFileStore(config: undefined, logger?: Logger): Promise<undefined>;
62
+ export async function createReadOnlyFileStore(
63
+ config: string,
64
+ logger?: Logger,
65
+ options?: HttpFileStoreOptions,
66
+ ): Promise<ReadOnlyFileStore>;
67
+ export async function createReadOnlyFileStore(
68
+ config: undefined,
69
+ logger?: Logger,
70
+ options?: HttpFileStoreOptions,
71
+ ): Promise<undefined>;
64
72
  export async function createReadOnlyFileStore(
65
73
  config: string | undefined,
66
74
  logger = createLogger('stdlib:file-store'),
75
+ options?: HttpFileStoreOptions,
67
76
  ): Promise<ReadOnlyFileStore | undefined> {
68
77
  if (config === undefined) {
69
78
  return undefined;
70
79
  } else if (config.startsWith('http://') || config.startsWith('https://')) {
71
80
  logger.info(`Creating read-only HTTP file store at ${config}`);
72
- return new HttpFileStore(config, logger);
81
+ return new HttpFileStore(config, logger, options);
73
82
  } else {
74
83
  return await createFileStore(config, logger);
75
84
  }
@@ -10,6 +10,14 @@ import { pipeline } from 'stream/promises';
10
10
 
11
11
  import type { ReadOnlyFileStore } from './interface.js';
12
12
 
13
+ /** Options for configuring HttpFileStore behavior. */
14
+ export interface HttpFileStoreOptions {
15
+ /** Retry backoff intervals in seconds. Empty array disables retries. Default: [1, 1, 3]. */
16
+ retryBackoff?: number[];
17
+ /** Request timeout in milliseconds. Default: no timeout (axios default). */
18
+ timeoutMs?: number;
19
+ }
20
+
13
21
  export class HttpFileStore implements ReadOnlyFileStore {
14
22
  private readonly axiosInstance: AxiosInstance;
15
23
  private readonly fetch: <T>(config: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
@@ -17,17 +25,28 @@ export class HttpFileStore implements ReadOnlyFileStore {
17
25
  constructor(
18
26
  private readonly baseUrl: string,
19
27
  private readonly log: Logger = createLogger('stdlib:http-file-store'),
28
+ options?: HttpFileStoreOptions,
20
29
  ) {
21
- this.axiosInstance = axios.create();
22
- this.fetch = async <T>(config: AxiosRequestConfig) => {
23
- return await retry(
24
- () => this.axiosInstance.request<T>(config),
25
- `Fetching ${config.url}`,
26
- makeBackoff([1, 1, 3]),
27
- this.log,
28
- /*failSilently=*/ true,
29
- );
30
- };
30
+ this.axiosInstance = axios.create({
31
+ ...(options?.timeoutMs !== undefined && { timeout: options.timeoutMs }),
32
+ });
33
+
34
+ const retryBackoff = options?.retryBackoff ?? [1, 1, 3];
35
+ if (retryBackoff.length > 0) {
36
+ this.fetch = async <T>(config: AxiosRequestConfig) => {
37
+ return await retry(
38
+ () => this.axiosInstance.request<T>(config),
39
+ `Fetching ${config.url}`,
40
+ makeBackoff(retryBackoff),
41
+ this.log,
42
+ /*failSilently=*/ true,
43
+ );
44
+ };
45
+ } else {
46
+ this.fetch = async <T>(config: AxiosRequestConfig) => {
47
+ return await this.axiosInstance.request<T>(config);
48
+ };
49
+ }
31
50
  }
32
51
 
33
52
  public async read(pathOrUrl: string): Promise<Buffer> {
@@ -1,2 +1,3 @@
1
1
  export * from './interface.js';
2
2
  export * from './factory.js';
3
+ export { type HttpFileStoreOptions } from './http.js';
package/src/hash/hash.ts CHANGED
@@ -98,6 +98,11 @@ export function computeProtocolNullifier(txRequestHash: Fr): Promise<Fr> {
98
98
  return siloNullifier(AztecAddress.fromBigInt(NULL_MSG_SENDER_CONTRACT_ADDRESS), txRequestHash);
99
99
  }
100
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
+
101
106
  export function computeSiloedPrivateLogFirstField(contract: AztecAddress, field: Fr): Promise<Fr> {
102
107
  return poseidon2HashWithSeparator([contract, field], DomainSeparator.PRIVATE_LOG_FIRST_FIELD);
103
108
  }
@@ -11,7 +11,7 @@ import { L2Block } from '../block/l2_block.js';
11
11
  import { type L2BlockSource, L2TipsSchema } from '../block/l2_block_source.js';
12
12
  import { ValidateCheckpointResultSchema } from '../block/validate_block_result.js';
13
13
  import { Checkpoint } from '../checkpoint/checkpoint.js';
14
- import { CheckpointDataSchema } from '../checkpoint/checkpoint_data.js';
14
+ import { CheckpointDataSchema, ProposedCheckpointDataSchema } from '../checkpoint/checkpoint_data.js';
15
15
  import { PublishedCheckpoint } from '../checkpoint/published_checkpoint.js';
16
16
  import {
17
17
  ContractClassPublicSchema,
@@ -150,6 +150,8 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
150
150
  .args()
151
151
  .returns(z.object({ genesisArchiveRoot: schemas.Fr })),
152
152
  getL1Timestamp: z.function().args().returns(schemas.BigInt.optional()),
153
+ getProposedCheckpoint: z.function().args().returns(ProposedCheckpointDataSchema.optional()),
154
+ getProposedCheckpointOnly: z.function().args().returns(ProposedCheckpointDataSchema.optional()),
153
155
  syncImmediate: z.function().args().returns(z.void()),
154
156
  isPendingChainInvalid: z.function().args().returns(z.boolean()),
155
157
  getPendingChainValidationStatus: z.function().args().returns(ValidateCheckpointResultSchema),
@@ -48,10 +48,7 @@ export type ValidatorClientConfig = ValidatorHASignerConfig &
48
48
  /** Interval between polling for new attestations from peers */
49
49
  attestationPollingIntervalMs: number;
50
50
 
51
- /** Whether to re-execute transactions in a block proposal before attesting */
52
- validatorReexecute: boolean;
53
-
54
- /** Whether to always reexecute block proposals, even for non-validator nodes or when out of the currnet committee */
51
+ /** Whether to always reexecute block proposals, even for non-validator nodes or when out of the current committee */
55
52
  alwaysReexecuteBlockProposals?: boolean;
56
53
 
57
54
  /** Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus */
@@ -98,7 +95,6 @@ export const ValidatorClientConfigSchema = zodFor<Omit<ValidatorClientConfig, 'v
98
95
  disableValidator: z.boolean(),
99
96
  disabledValidators: z.array(schemas.EthAddress),
100
97
  attestationPollingIntervalMs: z.number().min(0),
101
- validatorReexecute: z.boolean(),
102
98
  alwaysReexecuteBlockProposals: z.boolean().optional(),
103
99
  fishermanMode: z.boolean().optional(),
104
100
  skipCheckpointProposalValidation: z.boolean().optional(),
@@ -23,14 +23,14 @@ import { computeAddressSecret, computePreaddress } from '../keys/derivation.js';
23
23
  * doesn't seem to be a good way around this.
24
24
  */
25
25
  export class ExtendedDirectionalAppTaggingSecret {
26
- private constructor(
26
+ constructor(
27
27
  public readonly secret: Fr,
28
28
  public readonly app: AztecAddress,
29
29
  ) {}
30
30
 
31
31
  /**
32
32
  * Derives shared tagging secret and from that, the app address and recipient derives the directional app tagging
33
- * secret.
33
+ * secret. Returns undefined if `externalAddress` is an invalid address.
34
34
  *
35
35
  * @param localAddress - The complete address of entity A in the shared tagging secret derivation scheme
36
36
  * @param localIvsk - The incoming viewing secret key of entity A
@@ -45,8 +45,12 @@ export class ExtendedDirectionalAppTaggingSecret {
45
45
  externalAddress: AztecAddress,
46
46
  app: AztecAddress,
47
47
  recipient: AztecAddress,
48
- ): Promise<ExtendedDirectionalAppTaggingSecret> {
48
+ ): Promise<ExtendedDirectionalAppTaggingSecret | undefined> {
49
49
  const taggingSecretPoint = await computeSharedTaggingSecret(localAddress, localIvsk, externalAddress);
50
+ if (!taggingSecretPoint) {
51
+ return undefined;
52
+ }
53
+
50
54
  const appTaggingSecret = await poseidon2Hash([taggingSecretPoint.x, taggingSecretPoint.y, app]);
51
55
  const directionalAppTaggingSecret = await poseidon2Hash([appTaggingSecret, recipient]);
52
56
 
@@ -63,18 +67,25 @@ export class ExtendedDirectionalAppTaggingSecret {
63
67
  }
64
68
  }
65
69
 
66
- // Returns shared tagging secret computed with Diffie-Hellman key exchange.
70
+ // Returns shared tagging secret computed with Diffie-Hellman key exchange, or undefined if `externalAddress` is an
71
+ // invalid address.
67
72
  async function computeSharedTaggingSecret(
68
73
  localAddress: CompleteAddress,
69
74
  localIvsk: Fq,
70
75
  externalAddress: AztecAddress,
71
- ): Promise<Point> {
72
- const knownPreaddress = await computePreaddress(await localAddress.publicKeys.hash(), localAddress.partialAddress);
73
- // TODO: #8970 - Computation of address point from x coordinate might fail
74
- const externalAddressPoint = await externalAddress.toAddressPoint();
76
+ ): Promise<Point | undefined> {
75
77
  // Given A (local complete address) -> B (external address) and h == preaddress
76
78
  // Compute shared secret as S = (h_A + local_ivsk_A) * Addr_Point_B
77
79
 
80
+ const knownPreaddress = await computePreaddress(await localAddress.publicKeys.hash(), localAddress.partialAddress);
81
+
82
+ // An invalid address has no corresponding address point
83
+ if (!(await externalAddress.isValid())) {
84
+ return undefined;
85
+ }
86
+
87
+ const externalAddressPoint = await externalAddress.toAddressPoint();
88
+
78
89
  // Beware! h_a + local_ivsk_a (also known as the address secret) can lead to an address point with a negative
79
90
  // y-coordinate, since there's two possible candidates computeAddressSecret takes care of selecting the one that
80
91
  // leads to a positive y-coordinate, which is the only valid address point
@@ -1,8 +1,7 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX } from '@aztec/constants';
2
+ import { range } from '@aztec/foundation/array';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
4
 
4
- import type { AztecAddress } from '../aztec-address/index.js';
5
- import type { TxEffect } from '../tx/tx_effect.js';
6
5
  import type { TxHash } from '../tx/tx_hash.js';
7
6
 
8
7
  /**
@@ -19,7 +18,6 @@ export class MessageContext {
19
18
  public txHash: TxHash,
20
19
  public uniqueNoteHashesInTx: Fr[],
21
20
  public firstNullifierInTx: Fr,
22
- public recipient: AztecAddress,
23
21
  ) {}
24
22
 
25
23
  toFields(): Fr[] {
@@ -27,7 +25,6 @@ export class MessageContext {
27
25
  this.txHash.hash,
28
26
  ...serializeBoundedVec(this.uniqueNoteHashesInTx, MAX_NOTE_HASHES_PER_TX),
29
27
  this.firstNullifierInTx,
30
- this.recipient.toField(),
31
28
  ];
32
29
  }
33
30
 
@@ -37,13 +34,22 @@ export class MessageContext {
37
34
  tx_hash: this.txHash.hash,
38
35
  unique_note_hashes_in_tx: this.uniqueNoteHashesInTx,
39
36
  first_nullifier_in_tx: this.firstNullifierInTx,
40
- recipient: this.recipient,
41
37
  };
42
38
  /* eslint-enable camelcase */
43
39
  }
44
40
 
45
- static fromTxEffectAndRecipient(txEffect: TxEffect, recipient: AztecAddress): MessageContext {
46
- return new MessageContext(txEffect.txHash, txEffect.noteHashes, txEffect.nullifiers[0], recipient);
41
+ static toEmptyFields(): Fr[] {
42
+ const serializationLen =
43
+ 1 /* txHash */ + MAX_NOTE_HASHES_PER_TX + 1 /* uniqueNoteHashesInTx BVec */ + 1; /* firstNullifierInTx */
44
+ return range(serializationLen).map(_ => Fr.zero());
45
+ }
46
+
47
+ static toSerializedOption(response: MessageContext | null): Fr[] {
48
+ if (response) {
49
+ return [new Fr(1), ...response.toFields()];
50
+ } else {
51
+ return [new Fr(0), ...MessageContext.toEmptyFields()];
52
+ }
47
53
  }
48
54
  }
49
55
 
@@ -55,6 +61,10 @@ export class MessageContext {
55
61
  * @dev Copied over from pending_tagged_log.ts.
56
62
  */
57
63
  function serializeBoundedVec(values: Fr[], maxLength: number): Fr[] {
64
+ if (values.length > maxLength) {
65
+ throw new Error(`Attempted to serialize ${values} values into a BoundedVec with max length ${maxLength}`);
66
+ }
67
+
58
68
  const lengthDiff = maxLength - values.length;
59
69
  const zeroPaddingArray = Array(lengthDiff).fill(Fr.ZERO);
60
70
  const storage = values.concat(zeroPaddingArray);
@@ -1,7 +1,6 @@
1
1
  import { PRIVATE_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
 
4
- import type { AztecAddress } from '../aztec-address/index.js';
5
4
  import type { TxHash } from '../tx/tx_hash.js';
6
5
  import { MessageContext } from './message_context.js';
7
6
 
@@ -17,9 +16,8 @@ export class PendingTaggedLog {
17
16
  txHash: TxHash,
18
17
  uniqueNoteHashesInTx: Fr[],
19
18
  firstNullifierInTx: Fr,
20
- recipient: AztecAddress,
21
19
  ) {
22
- this.context = new MessageContext(txHash, uniqueNoteHashesInTx, firstNullifierInTx, recipient);
20
+ this.context = new MessageContext(txHash, uniqueNoteHashesInTx, firstNullifierInTx);
23
21
  }
24
22
 
25
23
  toFields(): Fr[] {