@aztec/stdlib 0.0.1-commit.bf2612ae → 0.0.1-commit.c2595eba

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 (68) hide show
  1. package/dest/block/block_hash.d.ts +14 -17
  2. package/dest/block/block_hash.d.ts.map +1 -1
  3. package/dest/block/block_hash.js +21 -34
  4. package/dest/block/block_parameter.d.ts +2 -2
  5. package/dest/block/block_parameter.d.ts.map +1 -1
  6. package/dest/block/in_block.d.ts +5 -5
  7. package/dest/block/in_block.js +1 -1
  8. package/dest/block/l2_block.d.ts +3 -2
  9. package/dest/block/l2_block.d.ts.map +1 -1
  10. package/dest/block/l2_block.js +2 -3
  11. package/dest/block/l2_block_source.d.ts +5 -4
  12. package/dest/block/l2_block_source.d.ts.map +1 -1
  13. package/dest/contract/contract_address.js +1 -1
  14. package/dest/contract/contract_class_id.d.ts +1 -1
  15. package/dest/contract/contract_class_id.js +1 -1
  16. package/dest/contract/private_function.js +1 -1
  17. package/dest/contract/private_function_membership_proof.d.ts +1 -1
  18. package/dest/contract/private_function_membership_proof.js +1 -1
  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 +4 -0
  22. package/dest/hash/hash.js +2 -2
  23. package/dest/hash/map_slot.d.ts +1 -1
  24. package/dest/hash/map_slot.d.ts.map +1 -1
  25. package/dest/hash/map_slot.js +4 -3
  26. package/dest/interfaces/archiver.d.ts +1 -1
  27. package/dest/interfaces/archiver.d.ts.map +1 -1
  28. package/dest/interfaces/archiver.js +4 -3
  29. package/dest/interfaces/aztec-node.d.ts +2 -2
  30. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  31. package/dest/interfaces/aztec-node.js +1 -1
  32. package/dest/interfaces/block-builder.d.ts +3 -2
  33. package/dest/interfaces/block-builder.d.ts.map +1 -1
  34. package/dest/interfaces/get_logs_response.d.ts +6 -6
  35. package/dest/interfaces/validator.d.ts +2 -2
  36. package/dest/interfaces/validator.d.ts.map +1 -1
  37. package/dest/logs/extended_public_log.d.ts +5 -5
  38. package/dest/logs/log_id.d.ts +4 -4
  39. package/dest/logs/log_id.d.ts.map +1 -1
  40. package/dest/logs/log_id.js +2 -1
  41. package/dest/logs/siloed_tag.d.ts +1 -1
  42. package/dest/logs/siloed_tag.d.ts.map +1 -1
  43. package/dest/logs/siloed_tag.js +4 -3
  44. package/dest/tx/block_header.js +2 -2
  45. package/dest/tx/in_tx.d.ts +2 -2
  46. package/dest/tx/indexed_tx_effect.d.ts +3 -3
  47. package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
  48. package/dest/tx/indexed_tx_effect.js +2 -1
  49. package/package.json +9 -9
  50. package/src/block/block_hash.ts +25 -50
  51. package/src/block/in_block.ts +1 -1
  52. package/src/block/l2_block.ts +3 -3
  53. package/src/block/l2_block_source.ts +4 -3
  54. package/src/contract/contract_address.ts +1 -1
  55. package/src/contract/contract_class_id.ts +1 -1
  56. package/src/contract/private_function.ts +1 -1
  57. package/src/contract/private_function_membership_proof.ts +1 -1
  58. package/src/epoch-helpers/index.ts +9 -0
  59. package/src/hash/hash.ts +2 -2
  60. package/src/hash/map_slot.ts +3 -2
  61. package/src/interfaces/archiver.ts +4 -3
  62. package/src/interfaces/aztec-node.ts +2 -2
  63. package/src/interfaces/block-builder.ts +2 -0
  64. package/src/interfaces/validator.ts +1 -2
  65. package/src/logs/log_id.ts +2 -1
  66. package/src/logs/siloed_tag.ts +3 -2
  67. package/src/tx/block_header.ts +3 -3
  68. package/src/tx/indexed_tx_effect.ts +2 -1
@@ -33,7 +33,7 @@ export async function wrapDataInBlock<T>(data: T, block: L2Block): Promise<DataI
33
33
  return {
34
34
  data,
35
35
  l2BlockNumber: block.number,
36
- l2BlockHash: BlockHash.fromField(await block.hash()),
36
+ l2BlockHash: await block.hash(),
37
37
  };
38
38
  }
39
39
 
@@ -15,6 +15,7 @@ import { z } from 'zod';
15
15
  import type { PrivateLog } from '../logs/private_log.js';
16
16
  import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
17
17
  import { BlockHeader } from '../tx/block_header.js';
18
+ import type { BlockHash } from './block_hash.js';
18
19
  import { Body } from './body.js';
19
20
  import type { L2BlockInfo } from './l2_block_info.js';
20
21
 
@@ -89,9 +90,8 @@ export class L2Block {
89
90
  * Returns the block's hash (hash of block header).
90
91
  * @returns The block's hash.
91
92
  */
92
- public async hash(): Promise<Fr> {
93
- const blockHash = await this.header.hash();
94
- return blockHash.toField();
93
+ public hash(): Promise<BlockHash> {
94
+ return this.header.hash();
95
95
  }
96
96
 
97
97
  /**
@@ -20,6 +20,7 @@ import type { BlockHeader } from '../tx/block_header.js';
20
20
  import type { IndexedTxEffect } from '../tx/indexed_tx_effect.js';
21
21
  import type { TxHash } from '../tx/tx_hash.js';
22
22
  import type { TxReceipt } from '../tx/tx_receipt.js';
23
+ import type { BlockHash } from './block_hash.js';
23
24
  import type { CheckpointedL2Block } from './checkpointed_l2_block.js';
24
25
  import type { L2Block } from './l2_block.js';
25
26
  import type { ValidateCheckpointNegativeResult, ValidateCheckpointResult } from './validate_block_result.js';
@@ -102,7 +103,7 @@ export interface L2BlockSource {
102
103
  * @param blockHash - The block hash to retrieve.
103
104
  * @returns The requested block header (or undefined if not found).
104
105
  */
105
- getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined>;
106
+ getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined>;
106
107
 
107
108
  /**
108
109
  * Gets a block header by its archive root.
@@ -123,7 +124,7 @@ export interface L2BlockSource {
123
124
  * @param blockHash - The block hash to retrieve.
124
125
  * @returns The requested L2 block (or undefined if not found).
125
126
  */
126
- getL2BlockByHash(blockHash: Fr): Promise<L2Block | undefined>;
127
+ getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined>;
127
128
 
128
129
  /**
129
130
  * Gets an L2 block by its archive root.
@@ -228,7 +229,7 @@ export interface L2BlockSource {
228
229
  * @param blockHash - The block hash to retrieve.
229
230
  * @returns The requested block (or undefined if not found).
230
231
  */
231
- getCheckpointedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined>;
232
+ getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined>;
232
233
 
233
234
  /**
234
235
  * Gets a checkpointed block by its archive root.
@@ -87,5 +87,5 @@ export async function computeInitializationHashFromEncodedArgs(
87
87
  encodedArgs: Fr[],
88
88
  ): Promise<Fr> {
89
89
  const argsHash = await computeVarArgsHash(encodedArgs);
90
- return poseidon2HashWithSeparator([initFn, argsHash], GeneratorIndex.CONSTRUCTOR);
90
+ return poseidon2HashWithSeparator([initFn, argsHash], GeneratorIndex.INITIALIZER);
91
91
  }
@@ -13,7 +13,7 @@ import { computePrivateFunctionsRoot } from './private_function.js';
13
13
  *
14
14
  * ```
15
15
  * version = 1
16
- * private_function_leaves = private_functions.map(fn => pedersen([fn.function_selector as Field, fn.vk_hash], GENERATOR__FUNCTION_LEAF))
16
+ * private_function_leaves = private_functions.map(fn => pedersen([fn.function_selector as Field, fn.vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF))
17
17
  * private_functions_root = merkleize(private_function_leaves)
18
18
  * bytecode_commitment = calculate_commitment(packed_bytecode)
19
19
  * contract_class_id = pedersen([version, artifact_hash, private_functions_root, bytecode_commitment], GENERATOR__CLASS_IDENTIFIER)
@@ -31,7 +31,7 @@ function computePrivateFunctionLeaves(fns: PrivateFunction[]): Promise<Buffer[]>
31
31
 
32
32
  /** Returns the leaf for a given private function. */
33
33
  export async function computePrivateFunctionLeaf(fn: PrivateFunction): Promise<Buffer> {
34
- return (await poseidon2HashWithSeparator([fn.selector, fn.vkHash], GeneratorIndex.FUNCTION_LEAF)).toBuffer();
34
+ return (await poseidon2HashWithSeparator([fn.selector, fn.vkHash], GeneratorIndex.PRIVATE_FUNCTION_LEAF)).toBuffer();
35
35
  }
36
36
 
37
37
  async function getPrivateFunctionTreeCalculator(): Promise<MerkleTreeCalculator> {
@@ -99,7 +99,7 @@ export async function createPrivateFunctionMembershipProof(
99
99
  * contract_class = db.get_contract_class(contract_class_id)
100
100
  *
101
101
  * // Compute function leaf and assert it belongs to the private functions tree
102
- * function_leaf = pedersen([selector as Field, vk_hash], GENERATOR__FUNCTION_LEAF)
102
+ * function_leaf = pedersen([selector as Field, vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF)
103
103
  * computed_private_function_tree_root = compute_root(function_leaf, private_function_tree_sibling_path)
104
104
  * assert computed_private_function_tree_root == contract_class.private_functions_root
105
105
  *
@@ -51,6 +51,15 @@ export function getSlotAtTimestamp(
51
51
  : SlotNumber.fromBigInt((ts - constants.l1GenesisTime) / BigInt(constants.slotDuration));
52
52
  }
53
53
 
54
+ /** Returns the L2 slot number at the next L1 block based on the current timestamp. */
55
+ export function getSlotAtNextL1Block(
56
+ currentL1Timestamp: bigint,
57
+ constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>,
58
+ ): SlotNumber {
59
+ const nextL1BlockTimestamp = currentL1Timestamp + BigInt(constants.ethereumSlotDuration);
60
+ return getSlotAtTimestamp(nextL1BlockTimestamp, constants);
61
+ }
62
+
54
63
  /** Returns the epoch number for a given timestamp. */
55
64
  export function getEpochNumberAtTimestamp(
56
65
  ts: bigint,
package/src/hash/hash.ts CHANGED
@@ -55,7 +55,7 @@ export function computeUniqueNoteHash(noteNonce: Fr, siloedNoteHash: Fr): Promis
55
55
  * @returns A siloed nullifier.
56
56
  */
57
57
  export function siloNullifier(contract: AztecAddress, innerNullifier: Fr): Promise<Fr> {
58
- return poseidon2HashWithSeparator([contract, innerNullifier], GeneratorIndex.OUTER_NULLIFIER);
58
+ return poseidon2HashWithSeparator([contract, innerNullifier], GeneratorIndex.SILOED_NULLIFIER);
59
59
  }
60
60
 
61
61
  /**
@@ -87,7 +87,7 @@ export function computePublicDataTreeValue(value: Fr): Fr {
87
87
 
88
88
  */
89
89
  export function computePublicDataTreeLeafSlot(contractAddress: AztecAddress, storageSlot: Fr): Promise<Fr> {
90
- return poseidon2HashWithSeparator([contractAddress, storageSlot], GeneratorIndex.PUBLIC_LEAF_INDEX);
90
+ return poseidon2HashWithSeparator([contractAddress, storageSlot], GeneratorIndex.PUBLIC_LEAF_SLOT);
91
91
  }
92
92
 
93
93
  /**
@@ -1,4 +1,5 @@
1
- import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
1
+ import { GeneratorIndex } from '@aztec/constants';
2
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
2
3
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
4
 
4
5
  /**
@@ -14,5 +15,5 @@ export function deriveStorageSlotInMap(
14
15
  toField: () => Fr;
15
16
  },
16
17
  ): Promise<Fr> {
17
- return poseidon2Hash([mapSlot, key.toField()]);
18
+ return poseidon2HashWithSeparator([mapSlot, key.toField()], GeneratorIndex.PUBLIC_STORAGE_MAP_SLOT);
18
19
  }
@@ -4,6 +4,7 @@ import type { ApiSchemaFor } from '@aztec/foundation/schemas';
4
4
 
5
5
  import { z } from 'zod';
6
6
 
7
+ import { BlockHash } from '../block/block_hash.js';
7
8
  import { CheckpointedL2Block } from '../block/checkpointed_l2_block.js';
8
9
  import { L2Block } from '../block/l2_block.js';
9
10
  import { type L2BlockSource, L2TipsSchema } from '../block/l2_block_source.js';
@@ -99,12 +100,12 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
99
100
  .function()
100
101
  .args(CheckpointNumberSchema, schemas.Integer)
101
102
  .returns(z.array(PublishedCheckpoint.schema)),
102
- getCheckpointedBlockByHash: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
103
+ getCheckpointedBlockByHash: z.function().args(BlockHash.schema).returns(CheckpointedL2Block.schema.optional()),
103
104
  getCheckpointedBlockByArchive: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
104
- getBlockHeaderByHash: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
105
+ getBlockHeaderByHash: z.function().args(BlockHash.schema).returns(BlockHeader.schema.optional()),
105
106
  getBlockHeaderByArchive: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
106
107
  getL2Block: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
107
- getL2BlockByHash: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
108
+ getL2BlockByHash: z.function().args(BlockHash.schema).returns(L2Block.schema.optional()),
108
109
  getL2BlockByArchive: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
109
110
  getTxEffect: z.function().args(TxHash.schema).returns(indexedTxSchema().optional()),
110
111
  getSettledTxReceipt: z.function().args(TxHash.schema).returns(TxReceipt.schema.optional()),
@@ -234,7 +234,7 @@ export interface AztecNode
234
234
  * @param blockHash - The block hash being requested.
235
235
  * @returns The requested block.
236
236
  */
237
- getBlockByHash(blockHash: Fr): Promise<L2Block | undefined>;
237
+ getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined>;
238
238
 
239
239
  /**
240
240
  * Get a block specified by its archive root.
@@ -579,7 +579,7 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
579
579
 
580
580
  getBlock: z.function().args(BlockParameterSchema).returns(L2Block.schema.optional()),
581
581
 
582
- getBlockByHash: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
582
+ getBlockByHash: z.function().args(BlockHash.schema).returns(L2Block.schema.optional()),
583
583
 
584
584
  getBlockByArchive: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
585
585
 
@@ -1,5 +1,6 @@
1
1
  import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
2
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { LoggerBindings } from '@aztec/foundation/log';
3
4
 
4
5
  import type { L2Block } from '../block/l2_block.js';
5
6
  import type { ChainConfig, SequencerConfig } from '../config/chain-config.js';
@@ -92,5 +93,6 @@ export interface ICheckpointsBuilder {
92
93
  l1ToL2Messages: Fr[],
93
94
  previousCheckpointOutHashes: Fr[],
94
95
  fork: MerkleTreeWriteOperations,
96
+ bindings?: LoggerBindings,
95
97
  ): Promise<ICheckpointBlockBuilder>;
96
98
  }
@@ -51,8 +51,7 @@ export type ValidatorClientConfig = ValidatorHASignerConfig & {
51
51
  /** Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus */
52
52
  fishermanMode?: boolean;
53
53
 
54
- // TODO(palla/mbps): Change default to false once checkpoint validation is stable
55
- /** Skip checkpoint proposal validation and always attest (default: true) */
54
+ /** Skip checkpoint proposal validation and always attest (default: false) */
56
55
  skipCheckpointProposalValidation?: boolean;
57
56
 
58
57
  /** Skip pushing re-executed blocks to archiver (default: false) */
@@ -1,6 +1,7 @@
1
1
  import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
2
  import { toBufferBE } from '@aztec/foundation/bigint-buffer';
3
3
  import { BlockNumber, BlockNumberSchema } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
5
  import { BufferReader } from '@aztec/foundation/serialize';
5
6
 
6
7
  import { z } from 'zod';
@@ -81,7 +82,7 @@ export class LogId {
81
82
  const reader = BufferReader.asReader(buffer);
82
83
 
83
84
  const blockNumber = BlockNumber(reader.readNumber());
84
- const blockHash = reader.readObject(BlockHash);
85
+ const blockHash = new BlockHash(reader.readObject(Fr));
85
86
  const txIndex = reader.readNumber();
86
87
  const logIndex = reader.readNumber();
87
88
 
@@ -1,4 +1,5 @@
1
- import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
1
+ import { GeneratorIndex } from '@aztec/constants';
2
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
2
3
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { ZodFor } from '@aztec/foundation/schemas';
4
5
 
@@ -22,7 +23,7 @@ export class SiloedTag {
22
23
  constructor(public readonly value: Fr) {}
23
24
 
24
25
  static async compute(tag: Tag, app: AztecAddress): Promise<SiloedTag> {
25
- const siloedTag = await poseidon2Hash([app, tag.value]);
26
+ const siloedTag = await poseidon2HashWithSeparator([app, tag.value], GeneratorIndex.PRIVATE_LOG_FIRST_FIELD);
26
27
  return new SiloedTag(siloedTag);
27
28
  }
28
29
 
@@ -164,8 +164,8 @@ export class BlockHeader {
164
164
 
165
165
  hash(): Promise<BlockHash> {
166
166
  if (!this._cachedHash) {
167
- this._cachedHash = poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.BLOCK_HASH).then(fr =>
168
- BlockHash.fromField(fr),
167
+ this._cachedHash = poseidon2HashWithSeparator(this.toFields(), GeneratorIndex.BLOCK_HEADER_HASH).then(
168
+ fr => new BlockHash(fr),
169
169
  );
170
170
  }
171
171
  return this._cachedHash;
@@ -173,7 +173,7 @@ export class BlockHeader {
173
173
 
174
174
  /** Manually set the hash for this block header if already computed */
175
175
  setHash(hashed: Fr) {
176
- this._cachedHash = Promise.resolve(BlockHash.fromField(hashed));
176
+ this._cachedHash = Promise.resolve(new BlockHash(hashed));
177
177
  }
178
178
 
179
179
  static random(overrides: Partial<FieldsOf<BlockHeader>> & Partial<FieldsOf<GlobalVariables>> = {}): BlockHeader {
@@ -1,4 +1,5 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { schemas } from '@aztec/foundation/schemas';
3
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
5
 
@@ -26,7 +27,7 @@ export function serializeIndexedTxEffect(effect: IndexedTxEffect): Buffer {
26
27
  export function deserializeIndexedTxEffect(buffer: Buffer): IndexedTxEffect {
27
28
  const reader = BufferReader.asReader(buffer);
28
29
 
29
- const l2BlockHash = reader.readObject(BlockHash);
30
+ const l2BlockHash = new BlockHash(reader.readObject(Fr));
30
31
  const l2BlockNumber = BlockNumber(reader.readNumber());
31
32
  const txIndexInBlock = reader.readNumber();
32
33
  const data = reader.readObject(TxEffect);