@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.5476d83

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 (174) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +61 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +261 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +80 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.js +334 -0
  7. package/dest/bench/client_flows/config.d.ts +14 -0
  8. package/dest/bench/client_flows/config.d.ts.map +1 -0
  9. package/dest/bench/client_flows/config.js +106 -0
  10. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  12. package/dest/bench/client_flows/data_extractor.js +77 -0
  13. package/dest/bench/utils.d.ts +12 -38
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +26 -66
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +21 -13
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +85 -57
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +19 -25
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +50 -70
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +16 -8
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +13 -19
  25. package/dest/e2e_epochs/epochs_test.d.ts +59 -18
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +226 -44
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  29. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  30. package/dest/e2e_fees/bridging_race.notest.js +63 -0
  31. package/dest/e2e_fees/fees_test.d.ts +21 -10
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +103 -109
  34. package/dest/e2e_l1_publisher/write_json.d.ts +10 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +58 -0
  37. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  38. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  39. package/dest/e2e_multi_validator/utils.js +214 -0
  40. package/dest/e2e_nested_contract/nested_contract_test.d.ts +10 -7
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +24 -20
  43. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.js +139 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +275 -23
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +184 -131
  49. package/dest/e2e_p2p/shared.d.ts +43 -7
  50. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  51. package/dest/e2e_p2p/shared.js +164 -19
  52. package/dest/e2e_token_contract/token_contract_test.d.ts +12 -6
  53. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  54. package/dest/e2e_token_contract/token_contract_test.js +50 -26
  55. package/dest/fixtures/e2e_prover_test.d.ts +63 -0
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +104 -105
  58. package/dest/fixtures/fixtures.d.ts +6 -7
  59. package/dest/fixtures/fixtures.d.ts.map +1 -1
  60. package/dest/fixtures/fixtures.js +4 -3
  61. package/dest/fixtures/get_acvm_config.d.ts +2 -2
  62. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  63. package/dest/fixtures/get_acvm_config.js +2 -14
  64. package/dest/fixtures/get_bb_config.d.ts +2 -2
  65. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  66. package/dest/fixtures/get_bb_config.js +10 -17
  67. package/dest/fixtures/index.d.ts +1 -1
  68. package/dest/fixtures/l1_to_l2_messaging.d.ts +9 -6
  69. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  70. package/dest/fixtures/l1_to_l2_messaging.js +44 -18
  71. package/dest/fixtures/logging.d.ts +1 -1
  72. package/dest/fixtures/setup_l1_contracts.d.ts +476 -5
  73. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  74. package/dest/fixtures/setup_l1_contracts.js +4 -4
  75. package/dest/fixtures/setup_p2p_test.d.ts +15 -14
  76. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  77. package/dest/fixtures/setup_p2p_test.js +81 -21
  78. package/dest/fixtures/snapshot_manager.d.ts +17 -9
  79. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  80. package/dest/fixtures/snapshot_manager.js +147 -121
  81. package/dest/fixtures/token_utils.d.ts +10 -4
  82. package/dest/fixtures/token_utils.d.ts.map +1 -1
  83. package/dest/fixtures/token_utils.js +28 -12
  84. package/dest/fixtures/utils.d.ts +524 -40
  85. package/dest/fixtures/utils.d.ts.map +1 -1
  86. package/dest/fixtures/utils.js +464 -369
  87. package/dest/fixtures/web3signer.d.ts +5 -0
  88. package/dest/fixtures/web3signer.d.ts.map +1 -0
  89. package/dest/fixtures/web3signer.js +53 -0
  90. package/dest/fixtures/with_telemetry_utils.d.ts +1 -1
  91. package/dest/index.d.ts +1 -1
  92. package/dest/quality_of_service/alert_checker.d.ts +2 -2
  93. package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
  94. package/dest/shared/cross_chain_test_harness.d.ts +39 -34
  95. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  96. package/dest/shared/cross_chain_test_harness.js +104 -50
  97. package/dest/shared/gas_portal_test_harness.d.ts +29 -31
  98. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  99. package/dest/shared/gas_portal_test_harness.js +51 -30
  100. package/dest/shared/index.d.ts +1 -1
  101. package/dest/shared/jest_setup.d.ts +1 -1
  102. package/dest/shared/jest_setup.js +1 -1
  103. package/dest/shared/submit-transactions.d.ts +6 -4
  104. package/dest/shared/submit-transactions.d.ts.map +1 -1
  105. package/dest/shared/submit-transactions.js +8 -7
  106. package/dest/shared/uniswap_l1_l2.d.ts +14 -12
  107. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  108. package/dest/shared/uniswap_l1_l2.js +146 -116
  109. package/dest/simulators/index.d.ts +1 -1
  110. package/dest/simulators/lending_simulator.d.ts +7 -11
  111. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  112. package/dest/simulators/lending_simulator.js +15 -16
  113. package/dest/simulators/token_simulator.d.ts +6 -3
  114. package/dest/simulators/token_simulator.d.ts.map +1 -1
  115. package/dest/simulators/token_simulator.js +16 -13
  116. package/dest/spartan/setup_test_wallets.d.ts +26 -11
  117. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  118. package/dest/spartan/setup_test_wallets.js +201 -58
  119. package/dest/spartan/utils.d.ts +118 -313
  120. package/dest/spartan/utils.d.ts.map +1 -1
  121. package/dest/spartan/utils.js +472 -135
  122. package/package.json +65 -58
  123. package/src/bench/client_flows/benchmark.ts +341 -0
  124. package/src/bench/client_flows/client_flows_benchmark.ts +447 -0
  125. package/src/bench/client_flows/config.ts +61 -0
  126. package/src/bench/client_flows/data_extractor.ts +89 -0
  127. package/src/bench/utils.ts +22 -76
  128. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
  129. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +65 -106
  130. package/src/e2e_deploy_contract/deploy_test.ts +24 -39
  131. package/src/e2e_epochs/epochs_test.ts +276 -55
  132. package/src/e2e_fees/bridging_race.notest.ts +80 -0
  133. package/src/e2e_fees/fees_test.ts +142 -138
  134. package/src/e2e_l1_publisher/write_json.ts +77 -0
  135. package/src/e2e_multi_validator/utils.ts +258 -0
  136. package/src/e2e_nested_contract/nested_contract_test.ts +29 -19
  137. package/src/e2e_p2p/inactivity_slash_test.ts +182 -0
  138. package/src/e2e_p2p/p2p_network.ts +279 -169
  139. package/src/e2e_p2p/shared.ts +247 -29
  140. package/src/e2e_token_contract/token_contract_test.ts +43 -39
  141. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  142. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +107 -152
  143. package/src/fixtures/fixtures.ts +4 -3
  144. package/src/fixtures/get_acvm_config.ts +3 -11
  145. package/src/fixtures/get_bb_config.ts +18 -13
  146. package/src/fixtures/l1_to_l2_messaging.ts +53 -23
  147. package/src/fixtures/setup_l1_contracts.ts +6 -7
  148. package/src/fixtures/setup_p2p_test.ts +126 -38
  149. package/src/fixtures/snapshot_manager.ts +187 -139
  150. package/src/fixtures/token_utils.ts +32 -15
  151. package/src/fixtures/utils.ts +580 -434
  152. package/src/fixtures/web3signer.ts +63 -0
  153. package/src/guides/up_quick_start.sh +7 -15
  154. package/src/quality_of_service/alert_checker.ts +1 -1
  155. package/src/shared/cross_chain_test_harness.ts +108 -79
  156. package/src/shared/gas_portal_test_harness.ts +59 -50
  157. package/src/shared/jest_setup.ts +1 -1
  158. package/src/shared/submit-transactions.ts +12 -8
  159. package/src/shared/uniswap_l1_l2.ts +181 -184
  160. package/src/simulators/lending_simulator.ts +14 -15
  161. package/src/simulators/token_simulator.ts +21 -13
  162. package/src/spartan/DEVELOP.md +121 -0
  163. package/src/spartan/setup_test_wallets.ts +251 -93
  164. package/src/spartan/utils.ts +536 -136
  165. package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
  166. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  167. package/dest/sample-dapp/connect.js +0 -12
  168. package/dest/sample-dapp/contracts.js +0 -10
  169. package/dest/sample-dapp/deploy.js +0 -35
  170. package/dest/sample-dapp/index.js +0 -98
  171. package/src/sample-dapp/connect.mjs +0 -16
  172. package/src/sample-dapp/contracts.mjs +0 -14
  173. package/src/sample-dapp/deploy.mjs +0 -40
  174. package/src/sample-dapp/index.mjs +0 -128
@@ -1,26 +1,42 @@
1
- import { getSchnorrWalletWithSecretKey } from '@aztec/accounts/schnorr';
2
1
  import type { InitialAccountData } from '@aztec/accounts/testing';
3
2
  import type { AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
4
- import type { AccountWalletWithSecretKey } from '@aztec/aztec.js';
5
- import { ChainMonitor } from '@aztec/aztec.js/ethereum';
6
- import { RollupContract, getExpectedAddress, getL1ContractsConfigEnvVars } from '@aztec/ethereum';
7
- import { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
8
- import { EthCheatCodesWithState } from '@aztec/ethereum/test';
3
+ import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
4
+ import { Fr } from '@aztec/aztec.js/fields';
5
+ import {
6
+ type EmpireSlashingProposerContract,
7
+ type ExtendedViemWalletClient,
8
+ GSEContract,
9
+ MultiAdderArtifact,
10
+ type Operator,
11
+ RollupContract,
12
+ type TallySlashingProposerContract,
13
+ type ViemClient,
14
+ createL1TxUtilsFromViemWallet,
15
+ deployL1Contract,
16
+ getL1ContractsConfigEnvVars,
17
+ } from '@aztec/ethereum';
18
+ import { ChainMonitor } from '@aztec/ethereum/test';
19
+ import { EpochNumber } from '@aztec/foundation/branded-types';
20
+ import { SecretValue } from '@aztec/foundation/config';
9
21
  import { type Logger, createLogger } from '@aztec/foundation/log';
10
- import { ForwarderAbi, ForwarderBytecode, RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts';
11
- import { SpamContract } from '@aztec/noir-contracts.js/Spam';
22
+ import { retryUntil } from '@aztec/foundation/retry';
23
+ import { RollupAbi, SlasherAbi, TestERC20Abi } from '@aztec/l1-artifacts';
24
+ import { SpamContract } from '@aztec/noir-test-contracts.js/Spam';
12
25
  import type { BootstrapNode } from '@aztec/p2p/bootstrap';
13
26
  import { createBootstrapNodeFromPrivateKey, getBootstrapNodeEnr } from '@aztec/p2p/test-helpers';
27
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
28
+ import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
14
29
  import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
30
+ import { ZkPassportProofParams } from '@aztec/stdlib/zkpassport';
31
+ import type { TestWallet } from '@aztec/test-wallet/server';
15
32
  import { getGenesisValues } from '@aztec/world-state/testing';
16
33
 
17
34
  import getPort from 'get-port';
18
- import { getContract } from 'viem';
35
+ import { type GetContractReturnType, getAddress, getContract } from 'viem';
19
36
  import { privateKeyToAccount } from 'viem/accounts';
20
37
 
21
38
  import {
22
39
  ATTESTER_PRIVATE_KEYS_START_INDEX,
23
- PROPOSER_PRIVATE_KEYS_START_INDEX,
24
40
  createValidatorConfig,
25
41
  generatePrivateKeys,
26
42
  } from '../fixtures/setup_p2p_test.js';
@@ -30,7 +46,7 @@ import {
30
46
  createSnapshotManager,
31
47
  deployAccounts,
32
48
  } from '../fixtures/snapshot_manager.js';
33
- import { getPrivateKeyFromIndex } from '../fixtures/utils.js';
49
+ import { type SetupOptions, getPrivateKeyFromIndex, getSponsoredFPCAddress } from '../fixtures/utils.js';
34
50
  import { getEndToEndTestTelemetryClient } from '../fixtures/with_telemetry_utils.js';
35
51
 
36
52
  // Use a fixed bootstrap node private key so that we can re-use the same snapshot and the nodes can find each other
@@ -38,14 +54,16 @@ const BOOTSTRAP_NODE_PRIVATE_KEY = '080212208f988fc0899e4a73a5aee4d271a5f2067060
38
54
  const l1ContractsConfig = getL1ContractsConfigEnvVars();
39
55
  export const WAIT_FOR_TX_TIMEOUT = l1ContractsConfig.aztecSlotDuration * 3;
40
56
 
41
- export const SHORTENED_BLOCK_TIME_CONFIG = {
57
+ export const SHORTENED_BLOCK_TIME_CONFIG_NO_PRUNES = {
42
58
  aztecSlotDuration: 12,
43
59
  ethereumSlotDuration: 4,
60
+ aztecProofSubmissionWindow: 640,
44
61
  };
45
62
 
46
63
  export class P2PNetworkTest {
47
64
  private snapshotManager: ISnapshotManager;
48
- private baseAccount;
65
+ public baseAccountPrivateKey: `0x${string}`;
66
+ public baseAccount;
49
67
 
50
68
  public logger: Logger;
51
69
  public monitor!: ChainMonitor;
@@ -53,38 +71,44 @@ export class P2PNetworkTest {
53
71
  public ctx!: SubsystemsContext;
54
72
  public attesterPrivateKeys: `0x${string}`[] = [];
55
73
  public attesterPublicKeys: string[] = [];
56
- public proposerPrivateKeys: `0x${string}`[] = [];
57
74
  public peerIdPrivateKeys: string[] = [];
75
+ public validators: Operator[] = [];
58
76
 
59
77
  public deployedAccounts: InitialAccountData[] = [];
60
78
  public prefilledPublicData: PublicDataTreeLeaf[] = [];
79
+
61
80
  // The re-execution test needs a wallet and a spam contract
62
- public wallet?: AccountWalletWithSecretKey;
81
+ public wallet?: TestWallet;
82
+ public defaultAccountAddress?: AztecAddress;
63
83
  public spamContract?: SpamContract;
64
84
 
65
85
  public bootstrapNode?: BootstrapNode;
66
86
 
67
- private cleanupInterval: NodeJS.Timeout | undefined = undefined;
68
-
69
- private gasUtils: L1TxUtilsWithBlobs | undefined = undefined;
70
-
71
87
  constructor(
72
- testName: string,
88
+ public readonly testName: string,
73
89
  public bootstrapNodeEnr: string,
74
90
  public bootNodePort: number,
75
- private numberOfNodes: number,
76
- initialValidatorConfig: AztecNodeConfig,
91
+ public numberOfValidators: number,
92
+ initialValidatorConfig: SetupOptions,
93
+ public numberOfNodes = 0,
77
94
  // If set enable metrics collection
78
95
  private metricsPort?: number,
96
+ startProverNode?: boolean,
97
+ mockZkPassportVerifier?: boolean,
79
98
  ) {
80
99
  this.logger = createLogger(`e2e:e2e_p2p:${testName}`);
81
100
 
82
101
  // Set up the base account and node private keys for the initial network deployment
83
- this.baseAccount = privateKeyToAccount(`0x${getPrivateKeyFromIndex(0)!.toString('hex')}`);
84
- this.proposerPrivateKeys = generatePrivateKeys(PROPOSER_PRIVATE_KEYS_START_INDEX, numberOfNodes);
85
- this.attesterPrivateKeys = generatePrivateKeys(ATTESTER_PRIVATE_KEYS_START_INDEX, numberOfNodes);
102
+ this.baseAccountPrivateKey = `0x${getPrivateKeyFromIndex(1)!.toString('hex')}`;
103
+ this.baseAccount = privateKeyToAccount(this.baseAccountPrivateKey);
104
+ this.attesterPrivateKeys = generatePrivateKeys(
105
+ ATTESTER_PRIVATE_KEYS_START_INDEX + numberOfNodes,
106
+ numberOfValidators,
107
+ );
86
108
  this.attesterPublicKeys = this.attesterPrivateKeys.map(privateKey => privateKeyToAccount(privateKey).address);
87
109
 
110
+ const zkPassportParams = ZkPassportProofParams.random();
111
+
88
112
  this.snapshotManager = createSnapshotManager(
89
113
  `e2e_p2p_network/${testName}`,
90
114
  process.env.E2E_DATA_PATH,
@@ -93,19 +117,35 @@ export class P2PNetworkTest {
93
117
  ethereumSlotDuration: initialValidatorConfig.ethereumSlotDuration ?? l1ContractsConfig.ethereumSlotDuration,
94
118
  aztecEpochDuration: initialValidatorConfig.aztecEpochDuration ?? l1ContractsConfig.aztecEpochDuration,
95
119
  aztecSlotDuration: initialValidatorConfig.aztecSlotDuration ?? l1ContractsConfig.aztecSlotDuration,
96
- aztecProofSubmissionWindow:
97
- initialValidatorConfig.aztecProofSubmissionWindow ?? l1ContractsConfig.aztecProofSubmissionWindow,
120
+ aztecProofSubmissionEpochs:
121
+ initialValidatorConfig.aztecProofSubmissionEpochs ?? l1ContractsConfig.aztecProofSubmissionEpochs,
122
+ slashingRoundSizeInEpochs:
123
+ initialValidatorConfig.slashingRoundSizeInEpochs ?? l1ContractsConfig.slashingRoundSizeInEpochs,
124
+ slasherFlavor: initialValidatorConfig.slasherFlavor ?? 'tally',
125
+ aztecTargetCommitteeSize: numberOfValidators,
98
126
  salt: 420,
99
127
  metricsPort: metricsPort,
100
- numberOfInitialFundedAccounts: 1,
128
+ numberOfInitialFundedAccounts: 2,
129
+ startProverNode,
101
130
  },
102
131
  {
132
+ ...initialValidatorConfig,
103
133
  aztecEpochDuration: initialValidatorConfig.aztecEpochDuration ?? l1ContractsConfig.aztecEpochDuration,
134
+ slashingRoundSizeInEpochs:
135
+ initialValidatorConfig.slashingRoundSizeInEpochs ?? l1ContractsConfig.slashingRoundSizeInEpochs,
136
+ slasherFlavor: initialValidatorConfig.slasherFlavor ?? 'tally',
137
+
104
138
  ethereumSlotDuration: initialValidatorConfig.ethereumSlotDuration ?? l1ContractsConfig.ethereumSlotDuration,
105
139
  aztecSlotDuration: initialValidatorConfig.aztecSlotDuration ?? l1ContractsConfig.aztecSlotDuration,
106
- aztecProofSubmissionWindow:
107
- initialValidatorConfig.aztecProofSubmissionWindow ?? l1ContractsConfig.aztecProofSubmissionWindow,
140
+ aztecProofSubmissionEpochs:
141
+ initialValidatorConfig.aztecProofSubmissionEpochs ?? l1ContractsConfig.aztecProofSubmissionEpochs,
142
+ aztecTargetCommitteeSize: numberOfValidators,
108
143
  initialValidators: [],
144
+ zkPassportArgs: {
145
+ mockZkPassportVerifier,
146
+ zkPassportDomain: zkPassportParams.domain,
147
+ zkPassportScope: zkPassportParams.scope,
148
+ },
109
149
  },
110
150
  );
111
151
  }
@@ -113,15 +153,21 @@ export class P2PNetworkTest {
113
153
  static async create({
114
154
  testName,
115
155
  numberOfNodes,
156
+ numberOfValidators,
116
157
  basePort,
117
158
  metricsPort,
118
159
  initialConfig,
160
+ startProverNode,
161
+ mockZkPassportVerifier,
119
162
  }: {
120
163
  testName: string;
121
164
  numberOfNodes: number;
165
+ numberOfValidators: number;
122
166
  basePort?: number;
123
167
  metricsPort?: number;
124
- initialConfig?: Partial<AztecNodeConfig>;
168
+ initialConfig?: SetupOptions;
169
+ startProverNode?: boolean;
170
+ mockZkPassportVerifier?: boolean;
125
171
  }) {
126
172
  const port = basePort || (await getPort());
127
173
 
@@ -133,7 +179,17 @@ export class P2PNetworkTest {
133
179
  bootstrapNodeEnr,
134
180
  );
135
181
 
136
- return new P2PNetworkTest(testName, bootstrapNodeEnr, port, numberOfNodes, initialValidatorConfig, metricsPort);
182
+ return new P2PNetworkTest(
183
+ testName,
184
+ bootstrapNodeEnr,
185
+ port,
186
+ numberOfValidators,
187
+ initialValidatorConfig,
188
+ numberOfNodes,
189
+ metricsPort,
190
+ startProverNode,
191
+ mockZkPassportVerifier,
192
+ );
137
193
  }
138
194
 
139
195
  get fundedAccount() {
@@ -143,33 +199,7 @@ export class P2PNetworkTest {
143
199
  return this.deployedAccounts[0];
144
200
  }
145
201
 
146
- /**
147
- * Start a loop to sync the mock system time with the L1 block time
148
- */
149
- public startSyncMockSystemTimeInterval() {
150
- this.cleanupInterval = setInterval(() => {
151
- void this.syncMockSystemTime().catch(err => this.logger.error('Error syncing mock system time', err));
152
- }, l1ContractsConfig.aztecSlotDuration * 1000);
153
- }
154
-
155
- /**
156
- * When using fake timers, we need to keep the system and anvil clocks in sync.
157
- */
158
- public async syncMockSystemTime() {
159
- this.logger.info('Syncing mock system time');
160
- const { dateProvider, deployL1ContractsValues } = this.ctx!;
161
- // Send a tx and only update the time after the tx is mined, as eth time is not continuous
162
- const { receipt } = await this.gasUtils!.sendAndMonitorTransaction({
163
- to: this.baseAccount.address,
164
- data: '0x',
165
- value: 1n,
166
- });
167
- const timestamp = await deployL1ContractsValues.publicClient.getBlock({ blockNumber: receipt.blockNumber });
168
- this.logger.info(`Timestamp: ${timestamp.timestamp}`);
169
- dateProvider.setTime(Number(timestamp.timestamp) * 1000);
170
- }
171
-
172
- async applyBaseSnapshots() {
202
+ async addBootstrapNode() {
173
203
  await this.snapshotManager.snapshot('add-bootstrap-node', async ({ aztecNodeConfig }) => {
174
204
  const telemetry = getEndToEndTestTelemetryClient(this.metricsPort);
175
205
  this.bootstrapNode = await createBootstrapNodeFromPrivateKey(
@@ -181,96 +211,107 @@ export class P2PNetworkTest {
181
211
  // Overwrite enr with updated info
182
212
  this.bootstrapNodeEnr = this.bootstrapNode.getENR().encodeTxt();
183
213
  });
214
+ }
184
215
 
185
- await this.snapshotManager.snapshot(
186
- 'add-validators',
187
- async ({ deployL1ContractsValues, aztecNodeConfig, dateProvider }) => {
188
- const rollup = getContract({
189
- address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
190
- abi: RollupAbi,
191
- client: deployL1ContractsValues.walletClient,
192
- });
193
-
194
- this.logger.verbose(`Adding ${this.numberOfNodes} validators`);
216
+ getValidators() {
217
+ const validators: Operator[] = [];
195
218
 
196
- const stakingAsset = getContract({
197
- address: deployL1ContractsValues.l1ContractAddresses.stakingAssetAddress.toString(),
198
- abi: TestERC20Abi,
199
- client: deployL1ContractsValues.walletClient,
200
- });
219
+ for (let i = 0; i < this.numberOfValidators; i++) {
220
+ const keyIndex = i;
221
+ const attester = privateKeyToAccount(this.attesterPrivateKeys[keyIndex]!);
201
222
 
202
- const stakeNeeded = l1ContractsConfig.minimumStake * BigInt(this.numberOfNodes);
203
- await Promise.all(
204
- [
205
- await stakingAsset.write.mint(
206
- [deployL1ContractsValues.walletClient.account.address, stakeNeeded],
207
- {} as any,
208
- ),
209
- await stakingAsset.write.approve(
210
- [deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(), stakeNeeded],
211
- {} as any,
212
- ),
213
- ].map(txHash => deployL1ContractsValues.publicClient.waitForTransactionReceipt({ hash: txHash })),
214
- );
223
+ validators.push({
224
+ attester: EthAddress.fromString(attester.address),
225
+ withdrawer: EthAddress.fromString(attester.address),
226
+ bn254SecretKey: new SecretValue(Fr.random().toBigInt()),
227
+ });
215
228
 
216
- const validators = [];
217
-
218
- for (let i = 0; i < this.numberOfNodes; i++) {
219
- const attester = privateKeyToAccount(this.attesterPrivateKeys[i]!);
220
- const proposerEOA = privateKeyToAccount(this.proposerPrivateKeys[i]!);
221
- const forwarder = getExpectedAddress(
222
- ForwarderAbi,
223
- ForwarderBytecode,
224
- [proposerEOA.address],
225
- proposerEOA.address,
226
- ).address;
227
- validators.push({
228
- attester: attester.address,
229
- proposer: forwarder,
230
- withdrawer: attester.address,
231
- amount: l1ContractsConfig.minimumStake,
232
- } as const);
233
-
234
- this.logger.verbose(`Adding (attester, proposer) pair: (${attester.address}, ${forwarder}) as validator`);
235
- }
229
+ this.logger.info(`Adding attester ${attester.address} as validator`);
230
+ }
231
+ return { validators };
232
+ }
236
233
 
237
- await deployL1ContractsValues.publicClient.waitForTransactionReceipt({
238
- hash: await rollup.write.cheat__InitialiseValidatorSet([validators]),
239
- });
234
+ async applyBaseSnapshots() {
235
+ await this.addBootstrapNode();
236
+ await this.snapshotManager.snapshot('add-validators', async ({ deployL1ContractsValues, cheatCodes }) => {
237
+ const rollup = getContract({
238
+ address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
239
+ abi: RollupAbi,
240
+ client: deployL1ContractsValues.l1Client,
241
+ });
242
+
243
+ this.logger.info(`Adding ${this.numberOfValidators} validators`);
244
+
245
+ const stakingAsset = getContract({
246
+ address: deployL1ContractsValues.l1ContractAddresses.stakingAssetAddress.toString(),
247
+ abi: TestERC20Abi,
248
+ client: deployL1ContractsValues.l1Client,
249
+ });
250
+
251
+ const { address: multiAdderAddress } = await deployL1Contract(
252
+ deployL1ContractsValues.l1Client,
253
+ MultiAdderArtifact.contractAbi,
254
+ MultiAdderArtifact.contractBytecode,
255
+ [rollup.address, deployL1ContractsValues.l1Client.account.address],
256
+ );
240
257
 
241
- const slotsInEpoch = await rollup.read.getEpochDuration();
242
- const timestamp = await rollup.read.getTimestampForSlot([slotsInEpoch]);
243
- const cheatCodes = new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrls);
244
- try {
245
- await cheatCodes.warp(Number(timestamp));
246
- } catch (err) {
247
- this.logger.debug('Warp failed, time already satisfied');
248
- }
258
+ const multiAdder = getContract({
259
+ address: multiAdderAddress.toString(),
260
+ abi: MultiAdderArtifact.contractAbi,
261
+ client: deployL1ContractsValues.l1Client,
262
+ });
263
+
264
+ const stakeNeeded = (await rollup.read.getActivationThreshold()) * BigInt(this.numberOfValidators);
265
+ await Promise.all(
266
+ [await stakingAsset.write.mint([multiAdder.address, stakeNeeded], {} as any)].map(txHash =>
267
+ deployL1ContractsValues.l1Client.waitForTransactionReceipt({ hash: txHash }),
268
+ ),
269
+ );
249
270
 
250
- // Send and await a tx to make sure we mine a block for the warp to correctly progress.
251
- await deployL1ContractsValues.publicClient.waitForTransactionReceipt({
252
- hash: await deployL1ContractsValues.walletClient.sendTransaction({
253
- to: this.baseAccount.address,
254
- value: 1n,
255
- account: this.baseAccount,
256
- }),
257
- });
271
+ const { validators } = this.getValidators();
272
+ this.validators = validators;
273
+
274
+ const gseAddress = deployL1ContractsValues.l1ContractAddresses.gseAddress!;
275
+ if (!gseAddress) {
276
+ throw new Error('GSE contract not deployed');
277
+ }
278
+
279
+ const gseContract = new GSEContract(deployL1ContractsValues.l1Client, gseAddress.toString());
280
+
281
+ const makeValidatorTuples = async (validator: Operator) => {
282
+ const registrationTuple = await gseContract.makeRegistrationTuple(validator.bn254SecretKey.getValue());
283
+ return {
284
+ attester: validator.attester.toString() as `0x${string}`,
285
+ withdrawer: validator.withdrawer.toString() as `0x${string}`,
286
+ ...registrationTuple,
287
+ };
288
+ };
289
+ const validatorTuples = await Promise.all(validators.map(makeValidatorTuples));
290
+
291
+ await deployL1ContractsValues.l1Client.waitForTransactionReceipt({
292
+ hash: await multiAdder.write.addValidators([validatorTuples]),
293
+ });
294
+
295
+ await cheatCodes.rollup.advanceToEpoch(
296
+ EpochNumber.fromBigInt(
297
+ BigInt(await cheatCodes.rollup.getEpoch()) + (await rollup.read.getLagInEpochsForValidatorSet()) + 1n,
298
+ ),
299
+ );
258
300
 
259
- // Set the system time in the node, only after we have warped the time and waited for a block
260
- // Time is only set in the NEXT block
261
- dateProvider.setTime(Number(timestamp) * 1000);
262
- },
263
- );
301
+ // Send and await a tx to make sure we mine a block for the warp to correctly progress.
302
+ await this._sendDummyTx(deployL1ContractsValues.l1Client);
303
+ });
264
304
  }
265
305
 
266
306
  async setupAccount() {
267
307
  await this.snapshotManager.snapshot(
268
308
  'setup-account',
269
- deployAccounts(1, this.logger, false),
270
- async ({ deployedAccounts }, { pxe }) => {
309
+ deployAccounts(1, this.logger),
310
+ ({ deployedAccounts }, { wallet }) => {
271
311
  this.deployedAccounts = deployedAccounts;
272
- const [account] = deployedAccounts;
273
- this.wallet = await getSchnorrWalletWithSecretKey(pxe, account.secret, account.signingKey, account.salt);
312
+ [{ address: this.defaultAccountAddress }] = deployedAccounts;
313
+ this.wallet = wallet;
314
+ return Promise.resolve();
274
315
  },
275
316
  );
276
317
  }
@@ -283,31 +324,28 @@ export class P2PNetworkTest {
283
324
  throw new Error('Call snapshot t.setupAccount before deploying account contract');
284
325
  }
285
326
 
286
- const spamContract = await SpamContract.deploy(this.wallet).send().deployed();
327
+ const spamContract = await SpamContract.deploy(this.wallet)
328
+ .send({ from: this.defaultAccountAddress! })
329
+ .deployed();
287
330
  return { contractAddress: spamContract.address };
288
331
  },
289
- async ({ contractAddress }) => {
332
+ ({ contractAddress }) => {
290
333
  if (!this.wallet) {
291
334
  throw new Error('Call snapshot t.setupAccount before deploying account contract');
292
335
  }
293
- this.spamContract = await SpamContract.at(contractAddress, this.wallet);
336
+ this.spamContract = SpamContract.at(contractAddress, this.wallet);
337
+ return Promise.resolve();
294
338
  },
295
339
  );
296
340
  }
297
341
 
298
342
  async removeInitialNode() {
299
343
  await this.snapshotManager.snapshot(
300
- 'remove-inital-validator',
344
+ 'remove-initial-validator',
301
345
  async ({ deployL1ContractsValues, aztecNode, dateProvider }) => {
302
346
  // Send and await a tx to make sure we mine a block for the warp to correctly progress.
303
- const receipt = await deployL1ContractsValues.publicClient.waitForTransactionReceipt({
304
- hash: await deployL1ContractsValues.walletClient.sendTransaction({
305
- to: this.baseAccount.address,
306
- value: 1n,
307
- account: this.baseAccount,
308
- }),
309
- });
310
- const block = await deployL1ContractsValues.publicClient.getBlock({
347
+ const { receipt } = await this._sendDummyTx(deployL1ContractsValues.l1Client);
348
+ const block = await deployL1ContractsValues.l1Client.getBlock({
311
349
  blockNumber: receipt.blockNumber,
312
350
  });
313
351
  dateProvider.setTime(Number(block.timestamp) * 1000);
@@ -317,29 +355,30 @@ export class P2PNetworkTest {
317
355
  );
318
356
  }
319
357
 
358
+ async sendDummyTx() {
359
+ return await this._sendDummyTx(this.ctx.deployL1ContractsValues.l1Client);
360
+ }
361
+
362
+ private async _sendDummyTx(l1Client: ExtendedViemWalletClient) {
363
+ const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client);
364
+ return await l1TxUtils.sendAndMonitorTransaction({
365
+ to: l1Client.account!.address,
366
+ value: 1n,
367
+ });
368
+ }
369
+
320
370
  async setup() {
321
371
  this.ctx = await this.snapshotManager.setup();
322
372
 
323
- this.prefilledPublicData = (
324
- await getGenesisValues(this.ctx.initialFundedAccounts.map(a => a.address))
325
- ).prefilledPublicData;
373
+ const sponsoredFPCAddress = await getSponsoredFPCAddress();
374
+ const initialFundedAccounts = [...this.ctx.initialFundedAccounts.map(a => a.address), sponsoredFPCAddress];
326
375
 
327
- this.startSyncMockSystemTimeInterval();
376
+ const { prefilledPublicData } = await getGenesisValues(initialFundedAccounts);
377
+ this.prefilledPublicData = prefilledPublicData;
328
378
 
329
- this.gasUtils = new L1TxUtilsWithBlobs(
330
- this.ctx.deployL1ContractsValues.publicClient,
331
- this.ctx.deployL1ContractsValues.walletClient,
332
- this.logger,
333
- {
334
- gasLimitBufferPercentage: 20,
335
- maxGwei: 500n,
336
- maxAttempts: 3,
337
- checkIntervalMs: 100,
338
- stallTimeMs: 1000,
339
- },
340
- );
341
-
342
- this.monitor = new ChainMonitor(RollupContract.getFromL1ContractsValues(this.ctx.deployL1ContractsValues)).start();
379
+ const rollupContract = RollupContract.getFromL1ContractsValues(this.ctx.deployL1ContractsValues);
380
+ this.monitor = new ChainMonitor(rollupContract, this.ctx.dateProvider).start();
381
+ this.monitor.on('l1-block', ({ timestamp }) => this.ctx.dateProvider.setTime(Number(timestamp) * 1000));
343
382
  }
344
383
 
345
384
  async stopNodes(nodes: AztecNodeService[]) {
@@ -355,12 +394,83 @@ export class P2PNetworkTest {
355
394
  this.logger.info('Nodes stopped');
356
395
  }
357
396
 
397
+ /**
398
+ * Wait for P2P mesh to be fully formed across all nodes.
399
+ * This ensures that all nodes are connected to each other before proceeding,
400
+ * preventing race conditions where validators propose blocks before the network is ready.
401
+ *
402
+ * @param nodes - Array of nodes to check for P2P connectivity
403
+ * @param expectedNodeCount - Expected number of nodes in the network (defaults to nodes.length)
404
+ * @param timeoutSeconds - Maximum time to wait for connections (default: 30 seconds)
405
+ * @param checkIntervalSeconds - How often to check connectivity (default: 0.1 seconds)
406
+ */
407
+ async waitForP2PMeshConnectivity(
408
+ nodes: AztecNodeService[],
409
+ expectedNodeCount?: number,
410
+ timeoutSeconds = 30,
411
+ checkIntervalSeconds = 0.1,
412
+ ) {
413
+ const nodeCount = expectedNodeCount ?? nodes.length;
414
+ const minPeerCount = nodeCount - 1;
415
+
416
+ this.logger.warn(
417
+ `Waiting for all ${nodeCount} nodes to connect to P2P mesh (at least ${minPeerCount} peers each)...`,
418
+ );
419
+
420
+ await Promise.all(
421
+ nodes.map(async (node, index) => {
422
+ const p2p = node.getP2P();
423
+ await retryUntil(
424
+ async () => {
425
+ const peers = await p2p.getPeers();
426
+ // Each node should be connected to at least N-1 other nodes
427
+ return peers.length >= minPeerCount ? true : undefined;
428
+ },
429
+ `Node ${index} to connect to at least ${minPeerCount} peers`,
430
+ timeoutSeconds,
431
+ checkIntervalSeconds,
432
+ );
433
+ }),
434
+ );
435
+
436
+ this.logger.warn('All nodes connected to P2P mesh');
437
+ }
438
+
358
439
  async teardown() {
359
- this.monitor.stop();
360
- await this.bootstrapNode?.stop();
440
+ await this.monitor.stop();
441
+ await tryStop(this.bootstrapNode, this.logger);
361
442
  await this.snapshotManager.teardown();
362
- if (this.cleanupInterval) {
363
- clearInterval(this.cleanupInterval);
443
+ }
444
+
445
+ async getContracts(): Promise<{
446
+ rollup: RollupContract;
447
+ slasherContract: GetContractReturnType<typeof SlasherAbi, ViemClient>;
448
+ slashingProposer: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
449
+ slashFactory: SlashFactoryContract;
450
+ }> {
451
+ if (!this.ctx.deployL1ContractsValues) {
452
+ throw new Error('DeployL1ContractsValues not set');
364
453
  }
454
+
455
+ const rollup = new RollupContract(
456
+ this.ctx.deployL1ContractsValues!.l1Client,
457
+ this.ctx.deployL1ContractsValues!.l1ContractAddresses.rollupAddress,
458
+ );
459
+
460
+ const slasherContract = getContract({
461
+ address: getAddress(await rollup.getSlasherAddress()),
462
+ abi: SlasherAbi,
463
+ client: this.ctx.deployL1ContractsValues.l1Client,
464
+ });
465
+
466
+ // Get the actual slashing proposer from rollup (which handles both empire and tally)
467
+ const slashingProposer = await rollup.getSlashingProposer();
468
+
469
+ const slashFactory = new SlashFactoryContract(
470
+ this.ctx.deployL1ContractsValues.l1Client,
471
+ getAddress(this.ctx.deployL1ContractsValues.l1ContractAddresses.slashFactoryAddress!.toString()),
472
+ );
473
+
474
+ return { rollup, slasherContract, slashingProposer, slashFactory };
365
475
  }
366
476
  }