@aztec/stdlib 0.0.1-commit.88c5703d4 → 0.0.1-commit.88e6f9396

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 (56) hide show
  1. package/dest/abi/abi.d.ts +138 -1
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +10 -2
  4. package/dest/checkpoint/validate.js +2 -2
  5. package/dest/config/index.d.ts +2 -1
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +1 -0
  8. package/dest/config/pipelining-config.d.ts +19 -0
  9. package/dest/config/pipelining-config.d.ts.map +1 -0
  10. package/dest/config/pipelining-config.js +18 -0
  11. package/dest/contract/contract_address.d.ts +3 -3
  12. package/dest/contract/contract_address.js +3 -3
  13. package/dest/contract/contract_class_id.d.ts +2 -2
  14. package/dest/contract/contract_class_id.js +2 -2
  15. package/dest/hash/hash.d.ts +16 -1
  16. package/dest/hash/hash.d.ts.map +1 -1
  17. package/dest/hash/hash.js +24 -0
  18. package/dest/interfaces/aztec-node-admin.d.ts +1 -4
  19. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  20. package/dest/interfaces/aztec-node.d.ts +2 -1
  21. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  22. package/dest/interfaces/block-builder.d.ts +26 -7
  23. package/dest/interfaces/block-builder.d.ts.map +1 -1
  24. package/dest/interfaces/block-builder.js +1 -4
  25. package/dest/interfaces/configs.d.ts +2 -7
  26. package/dest/interfaces/configs.d.ts.map +1 -1
  27. package/dest/interfaces/configs.js +0 -1
  28. package/dest/interfaces/proving-job.d.ts +166 -166
  29. package/dest/logs/log_filter.d.ts +4 -1
  30. package/dest/logs/log_filter.d.ts.map +1 -1
  31. package/dest/logs/log_filter.js +2 -1
  32. package/dest/logs/tx_scoped_l2_log.d.ts +3 -1
  33. package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
  34. package/dest/logs/tx_scoped_l2_log.js +7 -0
  35. package/dest/noir/index.d.ts +3 -3
  36. package/dest/noir/index.d.ts.map +1 -1
  37. package/dest/p2p/checkpoint_proposal.d.ts +1 -1
  38. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  39. package/dest/p2p/checkpoint_proposal.js +13 -11
  40. package/dest/tx/simulated_tx.d.ts +109 -1
  41. package/dest/tx/simulated_tx.d.ts.map +1 -1
  42. package/package.json +8 -8
  43. package/src/abi/abi.ts +25 -2
  44. package/src/checkpoint/validate.ts +2 -2
  45. package/src/config/index.ts +1 -0
  46. package/src/config/pipelining-config.ts +31 -0
  47. package/src/contract/contract_address.ts +3 -3
  48. package/src/contract/contract_class_id.ts +2 -2
  49. package/src/hash/hash.ts +29 -0
  50. package/src/interfaces/aztec-node.ts +1 -0
  51. package/src/interfaces/block-builder.ts +27 -9
  52. package/src/interfaces/configs.ts +1 -6
  53. package/src/logs/log_filter.ts +5 -0
  54. package/src/logs/tx_scoped_l2_log.ts +16 -0
  55. package/src/noir/index.ts +2 -2
  56. package/src/p2p/checkpoint_proposal.ts +23 -20
@@ -13,9 +13,9 @@ import type { ContractInstance } from './interfaces/contract_instance.js';
13
13
  /**
14
14
  * Returns the deployment address for a given contract instance.
15
15
  * ```
16
- * salted_initialization_hash = pedersen([salt, initialization_hash, deployer], GENERATOR__SALTED_INITIALIZATION_HASH)
17
- * partial_address = pedersen([contract_class_id, salted_initialization_hash], GENERATOR__CONTRACT_PARTIAL_ADDRESS_V1)
18
- * address = ((poseidon2Hash([public_keys_hash, partial_address, GENERATOR__CONTRACT_ADDRESS_V1]) * G) + ivpk_m).x <- the x-coordinate of the address point
16
+ * salted_initialization_hash = poseidon2(DOM_SEP__PARTIAL_ADDRESS, [salt, initialization_hash, deployer])
17
+ * partial_address = poseidon2(DOM_SEP__PARTIAL_ADDRESS, [contract_class_id, salted_initialization_hash])
18
+ * address = ((poseidon2(DOM_SEP__CONTRACT_ADDRESS_V1, [public_keys_hash, partial_address]) * G) + ivpk_m).x <- the x-coordinate of the address point
19
19
  * ```
20
20
  * @param instance - A contract instance for which to calculate the deployment address.
21
21
  */
@@ -13,10 +13,10 @@ 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__PRIVATE_FUNCTION_LEAF))
16
+ * private_function_leaves = private_functions.map(fn => poseidon2(DOM_SEP__PRIVATE_FUNCTION_LEAF, [fn.function_selector as Field, fn.vk_hash]))
17
17
  * private_functions_root = merkleize(private_function_leaves)
18
18
  * bytecode_commitment = calculate_commitment(packed_bytecode)
19
- * contract_class_id = pedersen([version, artifact_hash, private_functions_root, bytecode_commitment], GENERATOR__CLASS_IDENTIFIER)
19
+ * contract_class_id = poseidon2(DOM_SEP__CONTRACT_CLASS_ID, [version, artifact_hash, private_functions_root, bytecode_commitment])
20
20
  * ```
21
21
  * @param contractClass - Contract class.
22
22
  * @returns The identifier.
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.
@@ -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>;
@@ -64,9 +88,6 @@ export type FullNodeBlockBuilderConfig = Pick<L1RollupConstants, 'l1GenesisTime'
64
88
  | 'maxTxsPerCheckpoint'
65
89
  | 'maxL2BlockGas'
66
90
  | 'maxDABlockGas'
67
- | 'redistributeCheckpointBudget'
68
- | 'perBlockAllocationMultiplier'
69
- | 'maxBlocksPerCheckpoint'
70
91
  >;
71
92
 
72
93
  export const FullNodeBlockBuilderConfigKeys: (keyof FullNodeBlockBuilderConfig)[] = [
@@ -82,9 +103,6 @@ export const FullNodeBlockBuilderConfigKeys: (keyof FullNodeBlockBuilderConfig)[
82
103
  'maxL2BlockGas',
83
104
  'maxDABlockGas',
84
105
  'rollupManaLimit',
85
- 'redistributeCheckpointBudget',
86
- 'perBlockAllocationMultiplier',
87
- 'maxBlocksPerCheckpoint',
88
106
  ] as const;
89
107
 
90
108
  /** Thrown when the number of successfully processed transactions is below the required minimum. */
@@ -115,7 +133,7 @@ export interface ICheckpointBlockBuilder {
115
133
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
116
134
  blockNumber: BlockNumber,
117
135
  timestamp: bigint,
118
- opts: PublicProcessorLimits & { minValidTxs?: number },
136
+ opts: BlockBuilderOptions,
119
137
  ): Promise<BuildBlockInCheckpointResult>;
120
138
  }
121
139
 
@@ -29,8 +29,6 @@ export interface SequencerConfig {
29
29
  perBlockAllocationMultiplier?: number;
30
30
  /** Redistribute remaining checkpoint budget evenly across remaining blocks instead of allowing a single block to consume the entire remaining budget. */
31
31
  redistributeCheckpointBudget?: boolean;
32
- /** Computed max number of blocks per checkpoint from timetable. */
33
- maxBlocksPerCheckpoint?: number;
34
32
  /** Recipient of block reward. */
35
33
  coinbase?: EthAddress;
36
34
  /** Address to receive fees. */
@@ -99,7 +97,6 @@ export const SequencerConfigSchema = zodFor<SequencerConfig>()(
99
97
  maxDABlockGas: z.number().optional(),
100
98
  perBlockAllocationMultiplier: z.number().optional(),
101
99
  redistributeCheckpointBudget: z.boolean().optional(),
102
- maxBlocksPerCheckpoint: z.number().optional(),
103
100
  coinbase: schemas.EthAddress.optional(),
104
101
  feeRecipient: schemas.AztecAddress.optional(),
105
102
  acvmWorkingDirectory: z.string().optional(),
@@ -148,9 +145,7 @@ type SequencerConfigOptionalKeys =
148
145
  | 'maxTxsPerCheckpoint'
149
146
  | 'maxL2BlockGas'
150
147
  | 'maxDABlockGas'
151
- | 'perBlockAllocationMultiplier'
152
- | 'redistributeCheckpointBudget'
153
- | 'maxBlocksPerCheckpoint';
148
+ | 'redistributeCheckpointBudget';
154
149
 
155
150
  export type ResolvedSequencerConfig = Prettify<
156
151
  Required<Omit<SequencerConfig, SequencerConfigOptionalKeys>> & Pick<SequencerConfig, SequencerConfigOptionalKeys>
@@ -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
  });
@@ -1,4 +1,5 @@
1
1
  import { BlockNumber, BlockNumberSchema } from '@aztec/foundation/branded-types';
2
+ import { times } from '@aztec/foundation/collection';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { schemas as foundationSchemas } from '@aztec/foundation/schemas';
4
5
  import {
@@ -83,6 +84,21 @@ export class TxScopedL2Log {
83
84
  return new TxScopedL2Log(txHash, blockNumber, blockTimestamp, logData, noteHashes, firstNullifier);
84
85
  }
85
86
 
87
+ static getBlockNumberFromBuffer(buffer: Buffer) {
88
+ return BlockNumber(buffer.readUint32BE(Fr.SIZE_IN_BYTES));
89
+ }
90
+
91
+ static random() {
92
+ return new TxScopedL2Log(
93
+ TxHash.fromField(Fr.random()),
94
+ BlockNumber(Math.floor(Math.random() * 100000) + 1),
95
+ BigInt(Math.floor(Date.now() / 1000)),
96
+ times(3, Fr.random),
97
+ times(3, Fr.random),
98
+ Fr.random(),
99
+ );
100
+ }
101
+
86
102
  equals(other: TxScopedL2Log) {
87
103
  return (
88
104
  this.txHash.equals(other.txHash) &&
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
  }
@@ -178,29 +178,32 @@ export class CheckpointProposal extends Gossipable {
178
178
  blockNumber: lastBlockInfo?.blockHeader?.globalVariables.blockNumber ?? BlockNumber(0),
179
179
  dutyType: DutyType.CHECKPOINT_PROPOSAL,
180
180
  };
181
- const checkpointSignature = await payloadSigner(checkpointHash, checkpointContext);
182
181
 
183
- if (!lastBlockInfo) {
184
- return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature);
182
+ if (lastBlockInfo) {
183
+ // Sign block proposal before signing checkpoint proposal to ensure HA protection
184
+ const lastBlockProposal = await BlockProposal.createProposalFromSigner(
185
+ lastBlockInfo.blockHeader,
186
+ lastBlockInfo.indexWithinCheckpoint,
187
+ checkpointHeader.inHash,
188
+ archiveRoot,
189
+ lastBlockInfo.txHashes,
190
+ lastBlockInfo.txs,
191
+ payloadSigner,
192
+ );
193
+
194
+ const checkpointSignature = await payloadSigner(checkpointHash, checkpointContext);
195
+
196
+ return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature, {
197
+ blockHeader: lastBlockInfo.blockHeader,
198
+ indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
199
+ txHashes: lastBlockInfo.txHashes,
200
+ signature: lastBlockProposal.signature,
201
+ signedTxs: lastBlockProposal.signedTxs,
202
+ });
185
203
  }
186
204
 
187
- const lastBlockProposal = await BlockProposal.createProposalFromSigner(
188
- lastBlockInfo.blockHeader,
189
- lastBlockInfo.indexWithinCheckpoint,
190
- checkpointHeader.inHash,
191
- archiveRoot,
192
- lastBlockInfo.txHashes,
193
- lastBlockInfo.txs,
194
- payloadSigner,
195
- );
196
-
197
- return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature, {
198
- blockHeader: lastBlockInfo.blockHeader,
199
- indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
200
- txHashes: lastBlockInfo.txHashes,
201
- signature: lastBlockProposal.signature,
202
- signedTxs: lastBlockProposal.signedTxs,
203
- });
205
+ const checkpointSignature = await payloadSigner(checkpointHash, checkpointContext);
206
+ return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature);
204
207
  }
205
208
 
206
209
  /**