@aztec/stdlib 4.0.4-rc.9 → 4.1.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 (42) hide show
  1. package/dest/block/l2_block_source.d.ts +6 -1
  2. package/dest/block/l2_block_source.d.ts.map +1 -1
  3. package/dest/interfaces/allowed_element.d.ts +26 -20
  4. package/dest/interfaces/allowed_element.d.ts.map +1 -1
  5. package/dest/interfaces/allowed_element.js +8 -8
  6. package/dest/interfaces/archiver.d.ts +1 -1
  7. package/dest/interfaces/archiver.d.ts.map +1 -1
  8. package/dest/interfaces/archiver.js +1 -0
  9. package/dest/interfaces/aztec-node-admin.d.ts +34 -24
  10. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  11. package/dest/interfaces/aztec-node.d.ts +10 -5
  12. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  13. package/dest/interfaces/aztec-node.js +3 -2
  14. package/dest/interfaces/block-builder.d.ts +2 -2
  15. package/dest/interfaces/block-builder.d.ts.map +1 -1
  16. package/dest/interfaces/block-builder.js +1 -1
  17. package/dest/interfaces/configs.d.ts +37 -27
  18. package/dest/interfaces/configs.d.ts.map +1 -1
  19. package/dest/interfaces/configs.js +1 -1
  20. package/dest/interfaces/validator.d.ts +35 -25
  21. package/dest/interfaces/validator.d.ts.map +1 -1
  22. package/dest/interfaces/validator.js +1 -1
  23. package/dest/slashing/tally.d.ts +7 -2
  24. package/dest/slashing/tally.d.ts.map +1 -1
  25. package/dest/slashing/tally.js +30 -2
  26. package/dest/tx/simulated_tx.d.ts +5 -2
  27. package/dest/tx/simulated_tx.d.ts.map +1 -1
  28. package/dest/tx/simulated_tx.js +4 -1
  29. package/dest/tx/validator/error_texts.d.ts +5 -1
  30. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  31. package/dest/tx/validator/error_texts.js +4 -0
  32. package/package.json +9 -9
  33. package/src/block/l2_block_source.ts +6 -0
  34. package/src/interfaces/allowed_element.ts +29 -9
  35. package/src/interfaces/archiver.ts +1 -0
  36. package/src/interfaces/aztec-node.ts +14 -4
  37. package/src/interfaces/block-builder.ts +2 -2
  38. package/src/interfaces/configs.ts +4 -4
  39. package/src/interfaces/validator.ts +2 -2
  40. package/src/slashing/tally.ts +34 -1
  41. package/src/tx/simulated_tx.ts +8 -1
  42. package/src/tx/validator/error_texts.ts +4 -0
@@ -6,18 +6,38 @@ import type { FunctionSelector } from '../abi/function_selector.js';
6
6
  import type { AztecAddress } from '../aztec-address/index.js';
7
7
  import { schemas, zodFor } from '../schemas/index.js';
8
8
 
9
- type AllowedInstance = { address: AztecAddress };
10
- type AllowedInstanceFunction = { address: AztecAddress; selector: FunctionSelector };
11
- type AllowedClass = { classId: Fr };
12
- type AllowedClassFunction = { classId: Fr; selector: FunctionSelector };
9
+ type AllowedInstanceFunction = {
10
+ address: AztecAddress;
11
+ selector: FunctionSelector;
12
+ onlySelf?: boolean;
13
+ rejectNullMsgSender?: boolean;
14
+ calldataLength?: number;
15
+ };
16
+ type AllowedClassFunction = {
17
+ classId: Fr;
18
+ selector: FunctionSelector;
19
+ onlySelf?: boolean;
20
+ rejectNullMsgSender?: boolean;
21
+ calldataLength?: number;
22
+ };
13
23
 
14
- export type AllowedElement = AllowedInstance | AllowedInstanceFunction | AllowedClass | AllowedClassFunction;
24
+ export type AllowedElement = AllowedInstanceFunction | AllowedClassFunction;
15
25
 
16
26
  export const AllowedElementSchema = zodFor<AllowedElement>()(
17
27
  z.union([
18
- z.object({ address: schemas.AztecAddress, selector: schemas.FunctionSelector }),
19
- z.object({ address: schemas.AztecAddress }),
20
- z.object({ classId: schemas.Fr, selector: schemas.FunctionSelector }),
21
- z.object({ classId: schemas.Fr }),
28
+ z.object({
29
+ address: schemas.AztecAddress,
30
+ selector: schemas.FunctionSelector,
31
+ onlySelf: z.boolean().optional(),
32
+ rejectNullMsgSender: z.boolean().optional(),
33
+ calldataLength: z.number().optional(),
34
+ }),
35
+ z.object({
36
+ classId: schemas.Fr,
37
+ selector: schemas.FunctionSelector,
38
+ onlySelf: z.boolean().optional(),
39
+ rejectNullMsgSender: z.boolean().optional(),
40
+ calldataLength: z.number().optional(),
41
+ }),
22
42
  ]),
23
43
  );
@@ -86,6 +86,7 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
86
86
  getBlockNumber: z.function().args().returns(BlockNumberSchema),
87
87
  getProvenBlockNumber: z.function().args().returns(BlockNumberSchema),
88
88
  getCheckpointedL2BlockNumber: z.function().args().returns(BlockNumberSchema),
89
+ getCheckpointNumber: z.function().args().returns(CheckpointNumberSchema),
89
90
  getFinalizedL2BlockNumber: z.function().args().returns(BlockNumberSchema),
90
91
  getBlock: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
91
92
  getBlockHeader: z
@@ -4,7 +4,9 @@ import {
4
4
  BlockNumber,
5
5
  BlockNumberPositiveSchema,
6
6
  BlockNumberSchema,
7
+ CheckpointNumber,
7
8
  CheckpointNumberPositiveSchema,
9
+ CheckpointNumberSchema,
8
10
  EpochNumber,
9
11
  EpochNumberSchema,
10
12
  type SlotNumber,
@@ -172,14 +174,14 @@ export interface AztecNode
172
174
  l1ToL2Message: Fr,
173
175
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined>;
174
176
 
175
- /** Returns the L2 block number in which this L1 to L2 message becomes available, or undefined if not found. */
176
- getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined>;
177
+ /** Returns the L2 checkpoint number in which this L1 to L2 message becomes available, or undefined if not found. */
178
+ getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined>;
177
179
 
178
180
  /**
179
181
  * Returns whether an L1 to L2 message is synced by archiver.
180
182
  * @param l1ToL2Message - The L1 to L2 message to check.
181
183
  * @returns Whether the message is synced.
182
- * @deprecated Use `getL1ToL2MessageBlock` instead. This method may return true even if the message is not ready to use.
184
+ * @deprecated Use `getL1ToL2MessageCheckpoint` instead. This method may return true even if the message is not ready to use.
183
185
  */
184
186
  isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean>;
185
187
 
@@ -230,6 +232,12 @@ export interface AztecNode
230
232
  */
231
233
  getCheckpointedBlockNumber(): Promise<BlockNumber>;
232
234
 
235
+ /**
236
+ * Method to fetch the latest checkpoint number synchronized by the node.
237
+ * @returns The checkpoint number.
238
+ */
239
+ getCheckpointNumber(): Promise<CheckpointNumber>;
240
+
233
241
  /**
234
242
  * Method to determine if the node is ready to accept transactions.
235
243
  * @returns - Flag indicating the readiness for tx submission.
@@ -517,7 +525,7 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
517
525
  .args(BlockParameterSchema, schemas.Fr)
518
526
  .returns(z.tuple([schemas.BigInt, SiblingPath.schemaFor(L1_TO_L2_MSG_TREE_HEIGHT)]).optional()),
519
527
 
520
- getL1ToL2MessageBlock: z.function().args(schemas.Fr).returns(BlockNumberSchema.optional()),
528
+ getL1ToL2MessageCheckpoint: z.function().args(schemas.Fr).returns(CheckpointNumberSchema.optional()),
521
529
 
522
530
  isL1ToL2MessageSynced: z.function().args(schemas.Fr).returns(z.boolean()),
523
531
 
@@ -534,6 +542,8 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
534
542
 
535
543
  getBlockNumber: z.function().returns(BlockNumberSchema),
536
544
 
545
+ getCheckpointNumber: z.function().returns(CheckpointNumberSchema),
546
+
537
547
  getProvenBlockNumber: z.function().returns(BlockNumberSchema),
538
548
 
539
549
  getCheckpointedBlockNumber: z.function().returns(BlockNumberSchema),
@@ -57,7 +57,7 @@ export type FullNodeBlockBuilderConfig = Pick<L1RollupConstants, 'l1GenesisTime'
57
57
  Pick<ChainConfig, 'l1ChainId' | 'rollupVersion'> &
58
58
  Pick<
59
59
  SequencerConfig,
60
- | 'txPublicSetupAllowList'
60
+ | 'txPublicSetupAllowListExtend'
61
61
  | 'fakeProcessingDelayPerTxMs'
62
62
  | 'fakeThrowAfterProcessingTxCount'
63
63
  | 'maxTxsPerBlock'
@@ -74,7 +74,7 @@ export const FullNodeBlockBuilderConfigKeys: (keyof FullNodeBlockBuilderConfig)[
74
74
  'slotDuration',
75
75
  'l1ChainId',
76
76
  'rollupVersion',
77
- 'txPublicSetupAllowList',
77
+ 'txPublicSetupAllowListExtend',
78
78
  'fakeProcessingDelayPerTxMs',
79
79
  'fakeThrowAfterProcessingTxCount',
80
80
  'maxTxsPerBlock',
@@ -35,8 +35,8 @@ export interface SequencerConfig {
35
35
  acvmWorkingDirectory?: string;
36
36
  /** The path to the ACVM binary */
37
37
  acvmBinaryPath?: string;
38
- /** The list of functions calls allowed to run in setup */
39
- txPublicSetupAllowList?: AllowedElement[];
38
+ /** Additional entries to extend the default setup allow list. */
39
+ txPublicSetupAllowListExtend?: AllowedElement[];
40
40
  /** Payload address to vote for */
41
41
  governanceProposerPayload?: EthAddress;
42
42
  /** Whether to enforce the time table when building blocks */
@@ -98,7 +98,7 @@ export const SequencerConfigSchema = zodFor<SequencerConfig>()(
98
98
  feeRecipient: schemas.AztecAddress.optional(),
99
99
  acvmWorkingDirectory: z.string().optional(),
100
100
  acvmBinaryPath: z.string().optional(),
101
- txPublicSetupAllowList: z.array(AllowedElementSchema).optional(),
101
+ txPublicSetupAllowListExtend: z.array(AllowedElementSchema).optional(),
102
102
  governanceProposerPayload: schemas.EthAddress.optional(),
103
103
  l1PublishingTime: z.number().optional(),
104
104
  enforceTimeTable: z.boolean().optional(),
@@ -135,7 +135,7 @@ type SequencerConfigOptionalKeys =
135
135
  | 'fakeProcessingDelayPerTxMs'
136
136
  | 'fakeThrowAfterProcessingTxCount'
137
137
  | 'l1PublishingTime'
138
- | 'txPublicSetupAllowList'
138
+ | 'txPublicSetupAllowListExtend'
139
139
  | 'minValidTxsPerBlock'
140
140
  | 'minBlocksForCheckpoint'
141
141
  | 'maxTxsPerBlock'
@@ -74,7 +74,7 @@ export type ValidatorClientConfig = ValidatorHASignerConfig & {
74
74
  };
75
75
 
76
76
  export type ValidatorClientFullConfig = ValidatorClientConfig &
77
- Pick<SequencerConfig, 'txPublicSetupAllowList' | 'broadcastInvalidBlockProposal'> &
77
+ Pick<SequencerConfig, 'txPublicSetupAllowListExtend' | 'broadcastInvalidBlockProposal'> &
78
78
  Pick<
79
79
  SlasherConfig,
80
80
  'slashBroadcastedInvalidBlockPenalty' | 'slashDuplicateProposalPenalty' | 'slashDuplicateAttestationPenalty'
@@ -107,7 +107,7 @@ export const ValidatorClientConfigSchema = zodFor<Omit<ValidatorClientConfig, 'v
107
107
 
108
108
  export const ValidatorClientFullConfigSchema = zodFor<Omit<ValidatorClientFullConfig, 'validatorPrivateKeys'>>()(
109
109
  ValidatorClientConfigSchema.extend({
110
- txPublicSetupAllowList: z.array(AllowedElementSchema).optional(),
110
+ txPublicSetupAllowListExtend: z.array(AllowedElementSchema).optional(),
111
111
  broadcastInvalidBlockProposal: z.boolean().optional(),
112
112
  slashBroadcastedInvalidBlockPenalty: schemas.BigInt,
113
113
  slashDuplicateProposalPenalty: schemas.BigInt,
@@ -1,6 +1,7 @@
1
1
  import { sumBigint } from '@aztec/foundation/bigint';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { type Logger, createLogger } from '@aztec/foundation/log';
4
5
  import type { PartialBy } from '@aztec/foundation/types';
5
6
 
6
7
  import { getEpochForOffense } from './helpers.js';
@@ -12,6 +13,9 @@ import type { Offense, ValidatorSlashVote } from './types.js';
12
13
  * @param committees - Array of committees (each containing array of validator addresses)
13
14
  * @param epochsForCommittees - Array of epochs corresponding to each committee
14
15
  * @param settings - Settings including slashingAmounts and optional validator override lists
16
+ * @param settings.maxSlashedValidators - If set, limits the total number of [validator, epoch] pairs
17
+ * with non-zero votes. The lowest-vote pairs are zeroed out to stay within the limit.
18
+ * @param logger - Logger, logs which validators were dropped.
15
19
  * @returns Array of ValidatorSlashVote, where each vote is how many slash units the validator in that position should be slashed
16
20
  */
17
21
  export function getSlashConsensusVotesFromOffenses(
@@ -22,9 +26,11 @@ export function getSlashConsensusVotesFromOffenses(
22
26
  slashingAmounts: [bigint, bigint, bigint];
23
27
  epochDuration: number;
24
28
  targetCommitteeSize: number;
29
+ maxSlashedValidators?: number;
25
30
  },
31
+ logger: Logger = createLogger('slasher:tally'),
26
32
  ): ValidatorSlashVote[] {
27
- const { slashingAmounts, targetCommitteeSize } = settings;
33
+ const { slashingAmounts, targetCommitteeSize, maxSlashedValidators } = settings;
28
34
 
29
35
  if (committees.length !== epochsForCommittees.length) {
30
36
  throw new Error('committees and epochsForCommittees must have the same length');
@@ -53,6 +59,33 @@ export function getSlashConsensusVotesFromOffenses(
53
59
  return padArrayEnd(votes, 0, targetCommitteeSize);
54
60
  });
55
61
 
62
+ // if a cap is set, zero out the lowest-vote [validator, epoch] pairs so that the most severe slashes stay.
63
+ if (maxSlashedValidators === undefined) {
64
+ return votes;
65
+ }
66
+
67
+ const nonZeroByDescendingVote = [...votes.entries()].filter(([, vote]) => vote > 0).sort(([, a], [, b]) => b - a);
68
+
69
+ const toTruncate = nonZeroByDescendingVote.slice(maxSlashedValidators);
70
+ for (const [idx] of toTruncate) {
71
+ votes[idx] = 0;
72
+ }
73
+
74
+ if (toTruncate.length > 0) {
75
+ const truncated = toTruncate.map(([idx]) => {
76
+ const committeeIndex = Math.floor(idx / targetCommitteeSize);
77
+ const positionInCommittee = idx % targetCommitteeSize;
78
+ return {
79
+ validator: committees[committeeIndex][positionInCommittee].toString(),
80
+ epoch: epochsForCommittees[committeeIndex],
81
+ };
82
+ });
83
+ logger.warn(
84
+ `Truncated ${toTruncate.length} validator-epoch pairs to stay within limit of ${maxSlashedValidators}`,
85
+ { truncated },
86
+ );
87
+ }
88
+
56
89
  return votes;
57
90
  }
58
91
 
@@ -12,9 +12,11 @@ import { Gas } from '../gas/gas.js';
12
12
  import type { GasUsed } from '../gas/gas_used.js';
13
13
  import { PrivateKernelTailCircuitPublicInputs } from '../kernel/private_kernel_tail_circuit_public_inputs.js';
14
14
  import { ChonkProof } from '../proofs/chonk_proof.js';
15
+ import type { OffchainEffect } from './offchain_effect.js';
15
16
  import {
16
17
  PrivateCallExecutionResult,
17
18
  PrivateExecutionResult,
19
+ collectOffchainEffects,
18
20
  collectSortedContractClassLogs,
19
21
  } from './private_execution_result.js';
20
22
  import { type SimulationStats, SimulationStatsSchema } from './profiling.js';
@@ -84,6 +86,11 @@ export class TxSimulationResult {
84
86
  public stats?: SimulationStats,
85
87
  ) {}
86
88
 
89
+ /** Returns offchain effects collected from private execution. */
90
+ get offchainEffects(): OffchainEffect[] {
91
+ return collectOffchainEffects(this.privateExecutionResult);
92
+ }
93
+
87
94
  get gasUsed(): GasUsed {
88
95
  return (
89
96
  this.publicOutput?.gasUsed ?? {
@@ -106,7 +113,7 @@ export class TxSimulationResult {
106
113
  .transform(TxSimulationResult.from);
107
114
  }
108
115
 
109
- static from(fields: Omit<FieldsOf<TxSimulationResult>, 'gasUsed'>) {
116
+ static from(fields: Omit<FieldsOf<TxSimulationResult>, 'gasUsed' | 'offchainEffects'>) {
110
117
  return new TxSimulationResult(
111
118
  fields.privateExecutionResult,
112
119
  fields.publicInputs,
@@ -6,6 +6,10 @@ export const TX_ERROR_GAS_LIMIT_TOO_HIGH = 'Gas limit is higher than the amount
6
6
 
7
7
  // Phases
8
8
  export const TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED = 'Setup function not on allow list';
9
+ export const TX_ERROR_SETUP_FUNCTION_UNKNOWN_CONTRACT = 'Setup function targets unknown contract';
10
+ export const TX_ERROR_SETUP_ONLY_SELF_WRONG_SENDER = 'Setup only_self function called with incorrect msg_sender';
11
+ export const TX_ERROR_SETUP_NULL_MSG_SENDER = 'Setup function called with null msg sender';
12
+ export const TX_ERROR_SETUP_WRONG_CALLDATA_LENGTH = 'Setup function called with wrong calldata length';
9
13
 
10
14
  // Nullifiers
11
15
  export const TX_ERROR_DUPLICATE_NULLIFIER_IN_TX = 'Duplicate nullifier in tx';