@aztec/stdlib 0.0.1-commit.321f6a9 → 0.0.1-commit.330febf

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 (78) hide show
  1. package/dest/abi/abi.d.ts +25 -7
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +11 -2
  4. package/dest/abi/contract_artifact.js +9 -11
  5. package/dest/abi/decoder.d.ts +12 -5
  6. package/dest/abi/decoder.d.ts.map +1 -1
  7. package/dest/abi/decoder.js +18 -21
  8. package/dest/abi/function_call.d.ts +17 -8
  9. package/dest/abi/function_call.d.ts.map +1 -1
  10. package/dest/abi/function_call.js +28 -9
  11. package/dest/avm/avm.d.ts +212 -211
  12. package/dest/avm/avm.d.ts.map +1 -1
  13. package/dest/avm/avm.js +3 -1
  14. package/dest/avm/avm_proving_request.d.ts +70 -70
  15. package/dest/block/l2_block_source.d.ts +1 -1
  16. package/dest/block/l2_block_source.d.ts.map +1 -1
  17. package/dest/block/l2_block_source.js +6 -2
  18. package/dest/block/l2_block_stream/interfaces.d.ts +7 -5
  19. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  20. package/dest/block/l2_block_stream/l2_block_stream.d.ts +2 -1
  21. package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
  22. package/dest/block/l2_block_stream/l2_block_stream.js +47 -20
  23. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  24. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  25. package/dest/block/test/l2_tips_store_test_suite.js +9 -4
  26. package/dest/config/node-rpc-config.d.ts +1 -1
  27. package/dest/config/node-rpc-config.d.ts.map +1 -1
  28. package/dest/config/node-rpc-config.js +1 -1
  29. package/dest/contract/artifact_hash.d.ts +2 -2
  30. package/dest/contract/artifact_hash.d.ts.map +1 -1
  31. package/dest/contract/artifact_hash.js +10 -2
  32. package/dest/interfaces/api_limit.d.ts +6 -1
  33. package/dest/interfaces/api_limit.d.ts.map +1 -1
  34. package/dest/interfaces/api_limit.js +3 -0
  35. package/dest/interfaces/aztec-node-admin.d.ts +2 -1
  36. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  37. package/dest/interfaces/configs.d.ts +7 -1
  38. package/dest/interfaces/configs.d.ts.map +1 -1
  39. package/dest/interfaces/configs.js +1 -0
  40. package/dest/interfaces/tx_provider.d.ts +5 -1
  41. package/dest/interfaces/tx_provider.d.ts.map +1 -1
  42. package/dest/logs/logs_query.d.ts +2 -2
  43. package/dest/rollup/checkpoint_rollup_public_inputs.d.ts +1 -1
  44. package/dest/tx/hashed_values.d.ts +7 -1
  45. package/dest/tx/hashed_values.d.ts.map +1 -1
  46. package/dest/tx/hashed_values.js +9 -1
  47. package/dest/tx/offchain_effect.js +1 -1
  48. package/dest/tx/simulated_tx.d.ts +1 -1
  49. package/dest/tx/simulated_tx.d.ts.map +1 -1
  50. package/dest/tx/simulated_tx.js +7 -2
  51. package/dest/tx/tx.d.ts +8 -1
  52. package/dest/tx/tx.d.ts.map +1 -1
  53. package/dest/tx/tx.js +9 -3
  54. package/dest/validators/errors.d.ts +16 -1
  55. package/dest/validators/errors.d.ts.map +1 -1
  56. package/dest/validators/errors.js +12 -0
  57. package/package.json +8 -8
  58. package/src/abi/abi.ts +24 -4
  59. package/src/abi/contract_artifact.ts +7 -7
  60. package/src/abi/decoder.ts +20 -24
  61. package/src/abi/function_call.ts +19 -7
  62. package/src/avm/avm.ts +4 -1
  63. package/src/block/l2_block_source.ts +14 -2
  64. package/src/block/l2_block_stream/interfaces.ts +6 -4
  65. package/src/block/l2_block_stream/l2_block_stream.ts +58 -21
  66. package/src/block/test/l2_tips_store_test_suite.ts +5 -0
  67. package/src/config/node-rpc-config.ts +2 -1
  68. package/src/contract/artifact_hash.ts +15 -3
  69. package/src/interfaces/api_limit.ts +5 -0
  70. package/src/interfaces/configs.ts +6 -0
  71. package/src/interfaces/tx_provider.ts +4 -0
  72. package/src/kernel/private_kernel_reset_dimensions.ts +1 -1
  73. package/src/logs/logs_query.ts +2 -2
  74. package/src/tx/hashed_values.ts +11 -6
  75. package/src/tx/offchain_effect.ts +1 -1
  76. package/src/tx/simulated_tx.ts +13 -2
  77. package/src/tx/tx.ts +19 -3
  78. package/src/validators/errors.ts +17 -0
@@ -10,6 +10,7 @@ import {
10
10
  type L2TipId,
11
11
  } from '@aztec/stdlib/block';
12
12
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
13
+ import { BlockHeader } from '@aztec/stdlib/tx';
13
14
 
14
15
  import { expect } from 'vitest';
15
16
 
@@ -132,6 +133,7 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
132
133
  await tipsStore.handleBlockStreamEvent({
133
134
  type: 'chain-proposed',
134
135
  block: { number: BlockNumber(5), hash: new Fr(500).toString() },
136
+ header: BlockHeader.empty(),
135
137
  });
136
138
 
137
139
  const tips = await tipsStore.getL2Tips();
@@ -145,10 +147,12 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
145
147
  await tipsStore.handleBlockStreamEvent({
146
148
  type: 'chain-proposed',
147
149
  block: { number: BlockNumber(4), hash: new Fr(400).toString() },
150
+ header: BlockHeader.empty(),
148
151
  });
149
152
  await tipsStore.handleBlockStreamEvent({
150
153
  type: 'chain-proposed',
151
154
  block: { number: BlockNumber(9), hash: new Fr(900).toString() },
155
+ header: BlockHeader.empty(),
152
156
  });
153
157
 
154
158
  // Both recorded heights resolve; the heights between them were never seen and stay undefined.
@@ -165,6 +169,7 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
165
169
  await tipsStore.handleBlockStreamEvent({
166
170
  type: 'chain-proposed',
167
171
  block: { number: BlockNumber(9), hash: new Fr(900).toString() },
172
+ header: BlockHeader.empty(),
168
173
  });
169
174
 
170
175
  // Record sparse witnesses at heights below the tip (e.g. a consumer materializing per-height state).
@@ -1,6 +1,7 @@
1
- import { DEFAULT_MAX_DEBUG_LOG_MEMORY_READS } from '@aztec/constants';
2
1
  import { type ConfigMappingsType, numberConfigHelper } from '@aztec/foundation/config';
3
2
 
3
+ import { DEFAULT_MAX_DEBUG_LOG_MEMORY_READS } from '../avm/avm.js';
4
+
4
5
  export const nodeRpcConfigMappings: ConfigMappingsType<NodeRPCConfig> = {
5
6
  rpcSimulatePublicMaxGasLimit: {
6
7
  env: 'RPC_SIMULATE_PUBLIC_MAX_GAS_LIMIT',
@@ -6,7 +6,13 @@ import { MerkleTree, MerkleTreeCalculator } from '@aztec/foundation/trees';
6
6
 
7
7
  import deterministicStringify from 'json-stringify-deterministic';
8
8
 
9
- import { type ContractArtifact, type FunctionArtifact, FunctionSelector, FunctionType } from '../abi/index.js';
9
+ import {
10
+ type ContractArtifact,
11
+ type FunctionArtifact,
12
+ FunctionSelector,
13
+ FunctionType,
14
+ getFunctionReturnType,
15
+ } from '../abi/index.js';
10
16
 
11
17
  const VERSION = 1;
12
18
 
@@ -104,8 +110,14 @@ export async function computeFunctionArtifactHash(
104
110
  return sha256Fr(Buffer.concat([numToUInt8(VERSION), selector.toBuffer(), metadataHash.toBuffer(), bytecodeHash]));
105
111
  }
106
112
 
107
- export function computeFunctionMetadataHash(fn: FunctionArtifact) {
108
- return sha256Fr(Buffer.from(deterministicStringify(fn.returnTypes), 'utf8'));
113
+ export function computeFunctionMetadataHash(fn: Pick<FunctionArtifact, 'returnType' | 'returnTypes'>) {
114
+ // Wrap the type in a list (empty when the function returns nothing) so the hash preimage is identical to
115
+ // what it was when this hash consumed the deprecated `returnTypes` list. This hash is part of the
116
+ // artifact hash preimage, which contract class ids commit to - changing it would move the computed
117
+ // class id and address of every contract, and break artifact validation against already-registered
118
+ // classes.
119
+ const returnType = getFunctionReturnType(fn);
120
+ return sha256Fr(Buffer.from(deterministicStringify(returnType ? [returnType] : []), 'utf8'));
109
121
  }
110
122
 
111
123
  function getLogger() {
@@ -2,4 +2,9 @@ export const MAX_RPC_LEN = 100;
2
2
  export const MAX_RPC_TXS_LEN = 50;
3
3
  export const MAX_RPC_BLOCKS_LEN = 50;
4
4
  export const MAX_RPC_CHECKPOINTS_LEN = 50;
5
+ /** Checkpoint data carries no attestations or block bodies, so a page can be larger than a full checkpoint response. */
6
+ export const MAX_RPC_CHECKPOINTS_DATA_LEN = 200;
5
7
  export const MAX_LOGS_PER_TAG = 20;
8
+ /** Overrides are written into a public data tree fork before simulation, outside the simulated tx's gas budget. */
9
+ export const MAX_RPC_PUBLIC_STORAGE_OVERRIDES_LEN = 200;
10
+ export const MAX_RPC_CONTRACT_OVERRIDES_LEN = 50;
@@ -49,6 +49,11 @@ export interface SequencerConfig {
49
49
  txPublicSetupAllowListExtend?: AllowedElement[];
50
50
  /** Payload address to vote for */
51
51
  governanceProposerPayload?: EthAddress;
52
+ /**
53
+ * Keep signalling the configured governance payload even if a proposal referencing it was already
54
+ * executed within the lookback window. For payloads deliberately designed to be re-executed.
55
+ */
56
+ governanceProposerForcePayloadVote?: boolean;
52
57
  /**
53
58
  * Minimum block-building time (`min_block_duration`) still worth allocating if the proposer starts
54
59
  * late, in seconds.
@@ -150,6 +155,7 @@ export const SequencerConfigSchema = zodFor<SequencerConfig>()(
150
155
  acvmBinaryPath: z.string().optional(),
151
156
  txPublicSetupAllowListExtend: z.array(AllowedElementSchema).optional(),
152
157
  governanceProposerPayload: schemas.EthAddress.optional(),
158
+ governanceProposerForcePayloadVote: z.boolean().optional(),
153
159
  minBlockDuration: z.number().positive().optional(),
154
160
  checkpointProposalPrepareTime: z.number().nonnegative().optional(),
155
161
  l1PublishingTime: z.number().optional(),
@@ -13,6 +13,10 @@ export interface ITxProvider {
13
13
  */
14
14
  hasTxs(txHashes: TxHash[]): Promise<boolean[]>;
15
15
 
16
+ /**
17
+ * Collects the txs for a block proposal from the tx pool, the proposal body, and the network.
18
+ * @throws InvalidBlockProposalTxsError - If a tx carried in the proposal fails minimum integrity validation.
19
+ */
16
20
  getTxsForBlockProposal(
17
21
  blockProposal: BlockProposal,
18
22
  blockNumber: number,
@@ -78,7 +78,7 @@ export interface ResetCatalogEntry {
78
78
  cost: number;
79
79
  }
80
80
 
81
- // Must match the config in noir-projects/noir-protocol-circuits/private_kernel_reset_config.json
81
+ // Must match the shipped private_kernel_reset_config.json, loaded by @aztec/noir-protocol-circuits-types.
82
82
  export interface PrivateKernelResetDimensionsConfig {
83
83
  // Variants used for mid-tx resets that prevent overflow. Never the last kernel in the chain.
84
84
  inner: ResetCatalogEntry[];
@@ -33,8 +33,8 @@ export type LogsQueryBase = {
33
33
  */
34
34
  txHash?: TxHash;
35
35
  /**
36
- * Reorg-safety anchor: the latest block hash the caller has synced to. If set and the block is no
37
- * longer present, the call throws. Distinct from `toBlock`, which is a filter, not a safety check.
36
+ * Reorg-safety anchor: the latest block hash the caller has synced to. The call throws if that block is no longer
37
+ * present. Results are capped at that block, and `toBlock` can only narrow the range further, never past it.
38
38
  */
39
39
  referenceBlock?: BlockHash;
40
40
  /** When set, each log also carries `noteHashes` and all `nullifiers` for note-nonce discovery. */
@@ -28,12 +28,17 @@ export class HashedValues {
28
28
  }
29
29
 
30
30
  static get schema(): ZodFor<HashedValues> {
31
- return z
32
- .object({
33
- values: z.array(schemas.Fr),
34
- hash: schemas.Fr,
35
- })
36
- .transform(HashedValues.from);
31
+ return HashedValues.schemaFor();
32
+ }
33
+
34
+ /**
35
+ * Returns a schema that additionally rejects more than `maxValues` values. The bound belongs to the caller
36
+ * rather than to this class: the same container carries public calldata, private call arguments and authwit
37
+ * arguments, and those have different limits.
38
+ */
39
+ static schemaFor(maxValues?: number): ZodFor<HashedValues> {
40
+ const values = maxValues === undefined ? z.array(schemas.Fr) : z.array(schemas.Fr).max(maxValues);
41
+ return z.object({ values, hash: schemas.Fr }).transform(HashedValues.from);
37
42
  }
38
43
 
39
44
  static from(fields: FieldsOf<HashedValues>): HashedValues {
@@ -2,7 +2,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import type { AztecAddress } from '../aztec-address/index.js';
4
4
 
5
- // The following identifier was copied over from `noir-projects/aztec-nr/aztec/src/messages/offchain_messages.nr`.
5
+ // The following identifier was copied over from `noir-projects/labs/aztec-nr/aztec/src/messages/offchain_messages.nr`.
6
6
  // poseidon2hash("aztecnr_offchain_message")
7
7
  export const OFFCHAIN_MESSAGE_IDENTIFIER: Fr = new Fr(
8
8
  6023466688192654631553769360478808766602235351827869819420284624004071427516n,
@@ -9,6 +9,7 @@ import {
9
9
  } from '../contract/interfaces/contract_instance.js';
10
10
  import { Gas } from '../gas/gas.js';
11
11
  import type { GasUsed } from '../gas/gas_used.js';
12
+ import { MAX_RPC_CONTRACT_OVERRIDES_LEN, MAX_RPC_PUBLIC_STORAGE_OVERRIDES_LEN } from '../interfaces/api_limit.js';
12
13
  import { type PublicStorageOverride, PublicStorageOverrideSchema } from '../interfaces/public_storage_override.js';
13
14
  import { PrivateKernelTailCircuitPublicInputs } from '../kernel/private_kernel_tail_circuit_public_inputs.js';
14
15
  import { ChonkProof } from '../proofs/chonk_proof.js';
@@ -50,8 +51,18 @@ export class SimulationOverrides {
50
51
  static get schema() {
51
52
  return z
52
53
  .object({
53
- publicStorage: optional(z.array(PublicStorageOverrideSchema)),
54
- contracts: optional(z.record(z.string(), z.object({ instance: ContractInstanceWithAddressSchema }))),
54
+ publicStorage: optional(
55
+ z.array(PublicStorageOverrideSchema).max(MAX_RPC_PUBLIC_STORAGE_OVERRIDES_LEN, {
56
+ message: `publicStorage must have at most ${MAX_RPC_PUBLIC_STORAGE_OVERRIDES_LEN} entries`,
57
+ }),
58
+ ),
59
+ contracts: optional(
60
+ z
61
+ .record(z.string(), z.object({ instance: ContractInstanceWithAddressSchema }))
62
+ .refine(contracts => Object.keys(contracts).length <= MAX_RPC_CONTRACT_OVERRIDES_LEN, {
63
+ message: `contracts must have at most ${MAX_RPC_CONTRACT_OVERRIDES_LEN} entries`,
64
+ }),
65
+ ),
55
66
  })
56
67
  .transform(args => new SimulationOverrides(args));
57
68
  }
package/src/tx/tx.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { DA_GAS_PER_FIELD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
1
+ import {
2
+ DA_GAS_PER_FIELD,
3
+ MAX_CONTRACT_CLASS_LOGS_PER_TX,
4
+ MAX_ENQUEUED_CALLS_PER_TX,
5
+ MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS,
6
+ TX_DA_GAS_OVERHEAD,
7
+ } from '@aztec/constants';
2
8
  import { type BaseBuffer32, Buffer32 } from '@aztec/foundation/buffer';
3
9
  import { Fr } from '@aztec/foundation/curves/bn254';
4
10
  import type { ZodFor } from '@aztec/foundation/schemas';
@@ -33,6 +39,14 @@ import { TxHash } from './tx_hash.js';
33
39
  // with the existing cost.
34
40
  const TX_SINK_PRESIZE_BYTES = 131072;
35
41
 
42
+ /**
43
+ * Upper bound on the calldata entries a tx can carry: one per enqueued call, plus one for the teardown call.
44
+ * The revertible and non-revertible call request arrays are each sized `MAX_ENQUEUED_CALLS_PER_TX`, but the
45
+ * private tail circuit fills them by partitioning a single array of that size, so their lengths sum to it. The
46
+ * teardown request is propagated separately and can only be set once.
47
+ */
48
+ export const MAX_PUBLIC_FUNCTION_CALLDATA_PER_TX = MAX_ENQUEUED_CALLS_PER_TX + 1;
49
+
36
50
  /**
37
51
  * The interface of an L2 transaction.
38
52
  */
@@ -172,8 +186,10 @@ export class Tx extends Gossipable {
172
186
  .object({
173
187
  data: PrivateKernelTailCircuitPublicInputs.schema,
174
188
  chonkProof: ChonkProof.schema,
175
- contractClassLogFields: z.array(ContractClassLogFields.schema),
176
- publicFunctionCalldata: z.array(HashedValues.schema),
189
+ contractClassLogFields: z.array(ContractClassLogFields.schema).max(MAX_CONTRACT_CLASS_LOGS_PER_TX),
190
+ publicFunctionCalldata: z
191
+ .array(HashedValues.schemaFor(MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS))
192
+ .max(MAX_PUBLIC_FUNCTION_CALLDATA_PER_TX),
177
193
  })
178
194
  .transform(Tx.create);
179
195
  }
@@ -30,6 +30,23 @@ export class TransactionsNotAvailableError extends ValidatorError {
30
30
  }
31
31
  }
32
32
 
33
+ /**
34
+ * Thrown when a tx carried in a block proposal fails minimum integrity validation (metadata, size, data,
35
+ * contract instances, or proof). The proposer signs both the tx hashes and the tx objects, so this is
36
+ * proposer misbehavior rather than a local failure, and callers classify it as an invalid block proposal.
37
+ */
38
+ export class InvalidBlockProposalTxsError extends ValidatorError {
39
+ constructor(public readonly invalidTxs: { txHash: TxHash; reasons: string[] }[]) {
40
+ super(
41
+ `Invalid txs in block proposal: ${invalidTxs
42
+ .map(({ txHash, reasons }) => `${txHash} (${reasons.join(', ')})`)
43
+ .join('; ')}`,
44
+ );
45
+ // Set so `isErrorClass` can recognize this error across package instances, where `instanceof` fails.
46
+ this.name = 'InvalidBlockProposalTxsError';
47
+ }
48
+ }
49
+
33
50
  export class FailedToReExecuteTransactionsError extends ValidatorError {
34
51
  constructor(txHashes: TxHash[]) {
35
52
  super(`Failed to re-execute transactions: ${txHashes.join(', ')}`);