@aztec/end-to-end 5.0.0-rc.2 → 5.0.0

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 (246) hide show
  1. package/README.md +215 -27
  2. package/dest/automine/automine_test_context.d.ts +85 -0
  3. package/dest/automine/automine_test_context.d.ts.map +1 -0
  4. package/dest/automine/automine_test_context.js +98 -0
  5. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts +2 -0
  6. package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  7. package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.d.ts +1 -1
  8. package/dest/automine/contracts/fixtures/storage_proof_fixture.d.ts.map +1 -0
  9. package/dest/automine/delivery/interactive_handshake_responder.d.ts +48 -0
  10. package/dest/automine/delivery/interactive_handshake_responder.d.ts.map +1 -0
  11. package/dest/automine/delivery/interactive_handshake_responder.js +76 -0
  12. package/dest/automine/delivery/onchain_delivery_harness.d.ts +19 -0
  13. package/dest/automine/delivery/onchain_delivery_harness.d.ts.map +1 -0
  14. package/dest/automine/delivery/onchain_delivery_harness.js +141 -0
  15. package/dest/automine/token/blacklist_token_contract_test.d.ts +49 -0
  16. package/dest/automine/token/blacklist_token_contract_test.d.ts.map +1 -0
  17. package/dest/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.js +17 -24
  18. package/dest/automine/token/token_contract_test.d.ts +40 -0
  19. package/dest/automine/token/token_contract_test.d.ts.map +1 -0
  20. package/dest/{e2e_token_contract → automine/token}/token_contract_test.js +22 -28
  21. package/dest/automine/token/token_test_helpers.d.ts +73 -0
  22. package/dest/automine/token/token_test_helpers.d.ts.map +1 -0
  23. package/dest/automine/token/token_test_helpers.js +97 -0
  24. package/dest/bench/client_flows/benchmark.d.ts +1 -1
  25. package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
  26. package/dest/bench/client_flows/benchmark.js +3 -1
  27. package/dest/bench/client_flows/client_flows_benchmark.d.ts +1 -1
  28. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  29. package/dest/bench/client_flows/client_flows_benchmark.js +16 -4
  30. package/dest/bench/utils.d.ts +1 -1
  31. package/dest/composed/ha/ha_full_setup.d.ts +77 -0
  32. package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
  33. package/dest/composed/ha/ha_full_setup.js +383 -0
  34. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
  35. package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
  36. package/dest/fixtures/e2e_prover_test.d.ts +10 -7
  37. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  38. package/dest/fixtures/e2e_prover_test.js +30 -11
  39. package/dest/fixtures/fixtures.d.ts +7 -5
  40. package/dest/fixtures/fixtures.d.ts.map +1 -1
  41. package/dest/fixtures/fixtures.js +6 -4
  42. package/dest/fixtures/ha_setup.d.ts +3 -3
  43. package/dest/fixtures/ha_setup.d.ts.map +1 -1
  44. package/dest/fixtures/ha_setup.js +4 -1
  45. package/dest/fixtures/index.d.ts +2 -1
  46. package/dest/fixtures/index.d.ts.map +1 -1
  47. package/dest/fixtures/index.js +1 -0
  48. package/dest/fixtures/setup.d.ts +32 -8
  49. package/dest/fixtures/setup.d.ts.map +1 -1
  50. package/dest/fixtures/setup.js +165 -160
  51. package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
  52. package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
  53. package/dest/fixtures/standard_contracts_genesis.js +25 -0
  54. package/dest/fixtures/timing.d.ts +42 -0
  55. package/dest/fixtures/timing.d.ts.map +1 -0
  56. package/dest/fixtures/timing.js +72 -0
  57. package/dest/fixtures/wait_helpers.d.ts +135 -0
  58. package/dest/fixtures/wait_helpers.d.ts.map +1 -0
  59. package/dest/fixtures/wait_helpers.js +154 -0
  60. package/dest/forward-compatibility/wallet_service.js +1 -1
  61. package/dest/multi-node/block-production/setup.d.ts +97 -0
  62. package/dest/multi-node/block-production/setup.d.ts.map +1 -0
  63. package/dest/multi-node/block-production/setup.js +158 -0
  64. package/dest/multi-node/governance/setup.d.ts +67 -0
  65. package/dest/multi-node/governance/setup.d.ts.map +1 -0
  66. package/dest/multi-node/governance/setup.js +126 -0
  67. package/dest/multi-node/multi_node_test_context.d.ts +212 -0
  68. package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
  69. package/dest/multi-node/multi_node_test_context.js +347 -0
  70. package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
  71. package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
  72. package/dest/multi-node/slashing/inactivity_setup.js +111 -0
  73. package/dest/multi-node/slashing/setup.d.ts +167 -0
  74. package/dest/multi-node/slashing/setup.d.ts.map +1 -0
  75. package/dest/multi-node/slashing/setup.js +275 -0
  76. package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +9 -1
  77. package/dest/p2p/p2p_network.d.ts.map +1 -0
  78. package/dest/{e2e_p2p → p2p}/p2p_network.js +26 -1
  79. package/dest/p2p/reqresp/utils.d.ts +19 -0
  80. package/dest/p2p/reqresp/utils.d.ts.map +1 -0
  81. package/dest/{e2e_p2p → p2p}/reqresp/utils.js +4 -15
  82. package/dest/p2p/shared.d.ts +72 -0
  83. package/dest/p2p/shared.d.ts.map +1 -0
  84. package/dest/p2p/shared.js +212 -0
  85. package/dest/shared/cross_chain_test_harness.d.ts +3 -3
  86. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  87. package/dest/shared/cross_chain_test_harness.js +24 -16
  88. package/dest/shared/gas_portal_test_harness.d.ts +1 -1
  89. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  90. package/dest/shared/gas_portal_test_harness.js +8 -5
  91. package/dest/shared/submit-transactions.d.ts +1 -1
  92. package/dest/shared/submit-transactions.d.ts.map +1 -1
  93. package/dest/shared/submit-transactions.js +12 -5
  94. package/dest/shared/timing_env.d.js +5 -0
  95. package/dest/shared/timing_env.js +158 -47
  96. package/dest/shared/wait_for_l1_to_l2_message.js +1 -1
  97. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
  98. package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
  99. package/dest/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.js +74 -26
  100. package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
  101. package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
  102. package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
  103. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
  104. package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
  105. package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +9 -6
  106. package/dest/single-node/fees/fees_test.d.ts +95 -0
  107. package/dest/single-node/fees/fees_test.d.ts.map +1 -0
  108. package/dest/{e2e_fees → single-node/fees}/fees_test.js +121 -45
  109. package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
  110. package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
  111. package/dest/single-node/l1-reorgs/setup.js +57 -0
  112. package/dest/single-node/partial-proofs/setup.d.ts +5 -0
  113. package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
  114. package/dest/single-node/partial-proofs/setup.js +5 -0
  115. package/dest/single-node/proving/setup.d.ts +5 -0
  116. package/dest/single-node/proving/setup.d.ts.map +1 -0
  117. package/dest/single-node/proving/setup.js +5 -0
  118. package/dest/single-node/recovery/setup.d.ts +5 -0
  119. package/dest/single-node/recovery/setup.d.ts.map +1 -0
  120. package/dest/single-node/recovery/setup.js +5 -0
  121. package/dest/single-node/setup.d.ts +49 -0
  122. package/dest/single-node/setup.d.ts.map +1 -0
  123. package/dest/single-node/setup.js +56 -0
  124. package/dest/single-node/single_node_test_context.d.ts +373 -0
  125. package/dest/single-node/single_node_test_context.d.ts.map +1 -0
  126. package/dest/single-node/single_node_test_context.js +845 -0
  127. package/dest/spartan/setup_test_wallets.d.ts +1 -1
  128. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  129. package/dest/spartan/setup_test_wallets.js +13 -7
  130. package/dest/spartan/tx_metrics.d.ts +10 -1
  131. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  132. package/dest/spartan/tx_metrics.js +32 -0
  133. package/dest/test-wallet/test_wallet.d.ts +23 -4
  134. package/dest/test-wallet/test_wallet.d.ts.map +1 -1
  135. package/dest/test-wallet/test_wallet.js +20 -4
  136. package/dest/test-wallet/utils.d.ts +36 -1
  137. package/dest/test-wallet/utils.d.ts.map +1 -1
  138. package/dest/test-wallet/utils.js +64 -4
  139. package/dest/test-wallet/wallet_worker_script.js +5 -2
  140. package/dest/test-wallet/worker_wallet.d.ts +5 -5
  141. package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
  142. package/dest/test-wallet/worker_wallet.js +2 -2
  143. package/dest/test-wallet/worker_wallet_schema.js +2 -1
  144. package/package.json +40 -40
  145. package/src/automine/README.md +60 -0
  146. package/src/automine/automine_test_context.ts +153 -0
  147. package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
  148. package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
  149. package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +19 -39
  150. package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +24 -43
  151. package/src/automine/token/token_test_helpers.ts +138 -0
  152. package/src/bench/client_flows/benchmark.ts +3 -1
  153. package/src/bench/client_flows/client_flows_benchmark.ts +17 -4
  154. package/src/composed/ha/ha_full_setup.ts +466 -0
  155. package/src/fixtures/e2e_prover_test.ts +36 -20
  156. package/src/fixtures/fixtures.ts +6 -4
  157. package/src/fixtures/ha_setup.ts +7 -3
  158. package/src/fixtures/index.ts +1 -0
  159. package/src/fixtures/setup.ts +202 -161
  160. package/src/fixtures/standard_contracts_genesis.ts +28 -0
  161. package/src/fixtures/timing.ts +97 -0
  162. package/src/fixtures/wait_helpers.ts +333 -0
  163. package/src/forward-compatibility/wallet_service.ts +2 -2
  164. package/src/infra/README.md +12 -0
  165. package/src/multi-node/README.md +96 -0
  166. package/src/multi-node/block-production/setup.ts +272 -0
  167. package/src/multi-node/governance/setup.ts +172 -0
  168. package/src/multi-node/multi_node_test_context.ts +447 -0
  169. package/src/multi-node/slashing/inactivity_setup.ts +139 -0
  170. package/src/multi-node/slashing/setup.ts +433 -0
  171. package/src/p2p/README.md +78 -0
  172. package/src/{e2e_p2p → p2p}/p2p_network.ts +26 -0
  173. package/src/{e2e_p2p → p2p}/reqresp/utils.ts +5 -14
  174. package/src/p2p/shared.ts +329 -0
  175. package/src/shared/cross_chain_test_harness.ts +22 -13
  176. package/src/shared/gas_portal_test_harness.ts +13 -5
  177. package/src/shared/submit-transactions.ts +13 -5
  178. package/src/shared/timing_env.d.mts +39 -0
  179. package/src/shared/timing_env.mjs +152 -48
  180. package/src/shared/wait_for_l1_to_l2_message.ts +1 -1
  181. package/src/single-node/README.md +66 -0
  182. package/src/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.ts +100 -38
  183. package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
  184. package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +11 -7
  185. package/src/{e2e_fees → single-node/fees}/fees_test.ts +132 -47
  186. package/src/single-node/l1-reorgs/setup.ts +93 -0
  187. package/src/single-node/partial-proofs/setup.ts +8 -0
  188. package/src/single-node/proving/setup.ts +15 -0
  189. package/src/single-node/recovery/setup.ts +8 -0
  190. package/src/single-node/setup.ts +63 -0
  191. package/src/single-node/single_node_test_context.ts +1054 -0
  192. package/src/spartan/setup_test_wallets.ts +19 -7
  193. package/src/spartan/tx_metrics.ts +26 -0
  194. package/src/test-wallet/test_wallet.ts +28 -6
  195. package/src/test-wallet/utils.ts +102 -5
  196. package/src/test-wallet/wallet_worker_script.ts +6 -3
  197. package/src/test-wallet/worker_wallet.ts +5 -9
  198. package/src/test-wallet/worker_wallet_schema.ts +1 -1
  199. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -56
  200. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
  201. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -59
  202. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
  203. package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -36
  204. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
  205. package/dest/e2e_deploy_contract/deploy_test.js +0 -42
  206. package/dest/e2e_epochs/epochs_test.d.ts +0 -137
  207. package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
  208. package/dest/e2e_epochs/epochs_test.js +0 -485
  209. package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
  210. package/dest/e2e_fees/fees_test.d.ts +0 -89
  211. package/dest/e2e_fees/fees_test.d.ts.map +0 -1
  212. package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
  213. package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
  214. package/dest/e2e_l1_publisher/write_json.js +0 -57
  215. package/dest/e2e_multi_validator/utils.d.ts +0 -12
  216. package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
  217. package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -22
  218. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
  219. package/dest/e2e_nested_contract/nested_contract_test.js +0 -40
  220. package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
  221. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
  222. package/dest/e2e_p2p/inactivity_slash_test.js +0 -138
  223. package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
  224. package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
  225. package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
  226. package/dest/e2e_p2p/shared.d.ts +0 -100
  227. package/dest/e2e_p2p/shared.d.ts.map +0 -1
  228. package/dest/e2e_p2p/shared.js +0 -257
  229. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
  230. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
  231. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
  232. package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
  233. package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
  234. package/src/e2e_deploy_contract/deploy_test.ts +0 -73
  235. package/src/e2e_epochs/epochs_test.ts +0 -596
  236. package/src/e2e_l1_publisher/write_json.ts +0 -78
  237. package/src/e2e_nested_contract/nested_contract_test.ts +0 -51
  238. package/src/e2e_p2p/inactivity_slash_test.ts +0 -181
  239. package/src/e2e_p2p/shared.ts +0 -391
  240. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
  241. /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
  242. /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
  243. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
  244. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
  245. /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
  246. /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
@@ -0,0 +1,347 @@
1
+ import { EthAddress } from '@aztec/aztec.js/addresses';
2
+ import { Fr } from '@aztec/aztec.js/fields';
3
+ import { SlotNumber } from '@aztec/foundation/branded-types';
4
+ import { times } from '@aztec/foundation/collection';
5
+ import { SecretValue } from '@aztec/foundation/config';
6
+ import { retryUntil } from '@aztec/foundation/retry';
7
+ import { bufferToHex } from '@aztec/foundation/string';
8
+ import { SlasherAbi } from '@aztec/l1-artifacts';
9
+ import { createSharedSlashingProtectionDb } from '@aztec/validator-ha-signer/factory';
10
+ import { getAddress, getContract } from 'viem';
11
+ import { privateKeyToAccount } from 'viem/accounts';
12
+ import { testSpan } from '../fixtures/timing.js';
13
+ import { getPrivateKeyFromIndex } from '../fixtures/utils.js';
14
+ import { NO_REORG_SUBMISSION_EPOCHS } from '../single-node/setup.js';
15
+ import { SingleNodeTestContext } from '../single-node/single_node_test_context.js';
16
+ export { NO_REORG_SUBMISSION_EPOCHS, PROVING_SLOT_TIMING } from '../single-node/setup.js';
17
+ export { WORLD_STATE_CHECKPOINT_HISTORY, WORLD_STATE_BLOCK_CHECK_INTERVAL, ARCHIVER_POLL_INTERVAL, DEFAULT_L1_BLOCK_TIME, REORG_TIMING_BASE, FAST_REORG_TIMING, MULTI_VALIDATOR_REORG_TIMING, MULTI_VALIDATOR_BLOCK_PRODUCTION_TIMING, WIDE_SLOT_TIMING } from '../single-node/single_node_test_context.js';
18
+ /**
19
+ * Builds the deterministic validator set used across the multi-validator tests: `count` validators
20
+ * keyed from `getPrivateKeyFromIndex(i + 3)` (indices 0..2 are reserved for the setup account,
21
+ * bootstrap node, and prover node, matching the `P2PNetworkTest` convention). This replaces the
22
+ * `times(N, i => ({ attester, withdrawer, privateKey, bn254SecretKey }))` block copy-pasted in every
23
+ * direct multi-validator test.
24
+ */ export function buildMockGossipValidators(count) {
25
+ return times(count, (i)=>{
26
+ const privateKey = bufferToHex(getPrivateKeyFromIndex(i + 3));
27
+ const attester = EthAddress.fromString(privateKeyToAccount(privateKey).address);
28
+ return {
29
+ attester,
30
+ withdrawer: attester,
31
+ privateKey,
32
+ bn254SecretKey: new SecretValue(Fr.random().toBigInt())
33
+ };
34
+ });
35
+ }
36
+ /**
37
+ * The shared `setup` cluster for the multi-validator tests that run a tight committee on the
38
+ * in-memory mock-gossip bus without a prover (block-production / recovery tests). Spread into the `setup`
39
+ * call alongside `initialValidators` (from {@link buildMockGossipValidators}). Tests that want a
40
+ * prover (MBPS / HA-sync) leave `startProverNode` explicit rather than adopting this preset's `false`.
41
+ */ export const MOCK_GOSSIP_MULTI_VALIDATOR_OPTS = {
42
+ mockGossipSubNetwork: true,
43
+ skipInitialSequencer: true,
44
+ startProverNode: false,
45
+ aztecProofSubmissionEpochs: NO_REORG_SUBMISSION_EPOCHS,
46
+ numberOfAccounts: 0
47
+ };
48
+ /**
49
+ * The `setup` preset for a slasher-enabled committee on the in-memory mock-gossip bus, used by the
50
+ * offense-detection tests (`slashing/`). Mirrors {@link MOCK_GOSSIP_MULTI_VALIDATOR_OPTS} but turns
51
+ * the slasher on; spread alongside `initialValidators` (from {@link buildMockGossipValidators}) and
52
+ * the per-test slashing-round/penalty config.
53
+ */ export const SLASHER_ENABLED_MULTI_VALIDATOR_OPTS = {
54
+ mockGossipSubNetwork: true,
55
+ skipInitialSequencer: true,
56
+ slasherEnabled: true
57
+ };
58
+ /** The names of every per-offense penalty knob, in declaration order. */ const SLASHING_PENALTY_KEYS = [
59
+ 'slashInactivityPenalty',
60
+ 'slashDataWithholdingPenalty',
61
+ 'slashBroadcastedInvalidBlockPenalty',
62
+ 'slashBroadcastedInvalidCheckpointProposalPenalty',
63
+ 'slashDuplicateProposalPenalty',
64
+ 'slashDuplicateAttestationPenalty',
65
+ 'slashProposeInvalidAttestationsPenalty',
66
+ 'slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty',
67
+ 'slashAttestInvalidCheckpointProposalPenalty',
68
+ 'slashUnknownPenalty'
69
+ ];
70
+ /**
71
+ * Returns every per-offense slashing penalty set to `unit` (default `1e14` — small enough not to
72
+ * kick a validator out). Spread alongside the slashing-round/quorum config in a slashing test's
73
+ * `setup`.
74
+ */ export function defaultSlashingPenalties(unit = BigInt(1e14)) {
75
+ return Object.fromEntries(SLASHING_PENALTY_KEYS.map((key)=>[
76
+ key,
77
+ unit
78
+ ]));
79
+ }
80
+ /**
81
+ * Returns the penalties with only `offense` set to `unit` and every other offense zeroed out, so a
82
+ * test isolates a single slashing offense. Names the test's intent (which offense is under test) and
83
+ * replaces the ~9-line manual zero-out block.
84
+ */ export function withOnlyOffense(offense, unit = BigInt(1e14)) {
85
+ return Object.fromEntries(SLASHING_PENALTY_KEYS.map((key)=>[
86
+ key,
87
+ key === offense ? unit : 0n
88
+ ]));
89
+ }
90
+ /**
91
+ * Stands up two HA pairs from the first four registered validators: nodes[0]/nodes[1] share keys
92
+ * pk1+pk2, nodes[2]/nodes[3] share pk3+pk4. Each pair shares an in-memory slashing-protection DB (so
93
+ * only one peer signs per duty) and each node gets a distinct coinbase. Encapsulates the ~40-line
94
+ * pair-wiring duplicated by both HA tests; the per-test divergence (publishing disabled vs. enabled,
95
+ * empty-checkpoint building) is passed through `baseOpts`.
96
+ * @returns The four nodes flat, plus the two `HaPairNodes` descriptors.
97
+ */ export async function setupHaPairs(test, validators, opts = {}) {
98
+ const baseOpts = opts.baseOpts ?? {};
99
+ const coinbases = opts.coinbases ?? [
100
+ 1,
101
+ 2,
102
+ 3,
103
+ 4
104
+ ].map((n)=>EthAddress.fromNumber(n));
105
+ const [pk1, pk2, pk3, pk4] = validators.map((v)=>v.privateKey);
106
+ const sharedDb1 = await createSharedSlashingProtectionDb(test.context.dateProvider);
107
+ const sharedDb2 = await createSharedSlashingProtectionDb(test.context.dateProvider);
108
+ const nodes = [
109
+ await test.createValidatorNode([
110
+ pk1,
111
+ pk2
112
+ ], {
113
+ ...baseOpts,
114
+ coinbase: coinbases[0],
115
+ slashingProtectionDb: sharedDb1
116
+ }),
117
+ await test.createValidatorNode([
118
+ pk1,
119
+ pk2
120
+ ], {
121
+ ...baseOpts,
122
+ coinbase: coinbases[1],
123
+ slashingProtectionDb: sharedDb1
124
+ }),
125
+ await test.createValidatorNode([
126
+ pk3,
127
+ pk4
128
+ ], {
129
+ ...baseOpts,
130
+ coinbase: coinbases[2],
131
+ slashingProtectionDb: sharedDb2
132
+ }),
133
+ await test.createValidatorNode([
134
+ pk3,
135
+ pk4
136
+ ], {
137
+ ...baseOpts,
138
+ coinbase: coinbases[3],
139
+ slashingProtectionDb: sharedDb2
140
+ })
141
+ ];
142
+ const pairs = [
143
+ {
144
+ nodes: [
145
+ nodes[0],
146
+ nodes[1]
147
+ ],
148
+ privateKeys: [
149
+ pk1,
150
+ pk2
151
+ ],
152
+ coinbases: [
153
+ coinbases[0],
154
+ coinbases[1]
155
+ ]
156
+ },
157
+ {
158
+ nodes: [
159
+ nodes[2],
160
+ nodes[3]
161
+ ],
162
+ privateKeys: [
163
+ pk3,
164
+ pk4
165
+ ],
166
+ coinbases: [
167
+ coinbases[2],
168
+ coinbases[3]
169
+ ]
170
+ }
171
+ ];
172
+ return {
173
+ nodes,
174
+ pairs
175
+ };
176
+ }
177
+ /**
178
+ * Multi-validator test base: N validator nodes sharing the in-memory `MockGossipSubNetwork` bus, with
179
+ * fast block times and short epochs. Extends {@link SingleNodeTestContext} with validator-node
180
+ * spawning and the convergence helpers (`waitForAllNodes*`, `findSlotsWithProposers`) that only make
181
+ * sense across a committee. The environment, prover lifecycle, and reorg/proving waiters live on the
182
+ * parent so the single-node-topology tests share them.
183
+ */ export class MultiNodeTestContext extends SingleNodeTestContext {
184
+ /**
185
+ * The validators registered on-chain at genesis (from `opts.initialValidators`). Tests spawn nodes
186
+ * for whichever validators they want online via {@link createValidatorNodeAt}; the rest stay
187
+ * registered-but-offline. Empty for single-validator-less topologies.
188
+ */ validators = [];
189
+ async setup(opts = {}) {
190
+ this.validators = opts.initialValidators ?? [];
191
+ await super.setup(opts);
192
+ }
193
+ createValidatorNode(privateKeys, opts = {}) {
194
+ this.logger.warn('Creating and syncing a validator node...');
195
+ return this.createNode({
196
+ ...opts,
197
+ disableValidator: false,
198
+ validatorPrivateKeys: new SecretValue(privateKeys)
199
+ });
200
+ }
201
+ /** Returns the validator registered at on-chain index `index` (0-based into {@link validators}). */ validatorAt(index) {
202
+ return this.validators[index];
203
+ }
204
+ /** The L1 attester address of the validator registered at `index`. */ addressAt(index) {
205
+ return this.validators[index].attester;
206
+ }
207
+ /** The L1 signing key of the validator registered at `index`. */ privateKeyAt(index) {
208
+ return this.validators[index].privateKey;
209
+ }
210
+ /**
211
+ * Spawns a validator node on the mock-gossip bus signing with the validator registered at `index`.
212
+ * Pass the same `index` to two calls (with different `coinbase`) to model an equivocating proposer
213
+ * that shares a key across two nodes.
214
+ */ createValidatorNodeAt(index, opts = {}) {
215
+ return this.createValidatorNode([
216
+ this.privateKeyAt(index)
217
+ ], opts);
218
+ }
219
+ /** Resolves the rollup, slasher, and slashing-proposer L1 contracts a slashing test interacts with. */ async getSlashingContracts() {
220
+ const rollup = this.rollup;
221
+ const slasherContract = getContract({
222
+ address: getAddress((await rollup.getSlasherAddress()).toString()),
223
+ abi: SlasherAbi,
224
+ client: this.l1Client
225
+ });
226
+ const slashingProposer = await rollup.getSlashingProposer();
227
+ return {
228
+ rollup,
229
+ slasherContract,
230
+ slashingProposer
231
+ };
232
+ }
233
+ /**
234
+ * Polls every node until `predicate(tips, node)` holds for all of them. The multi-node
235
+ * generalization of {@link SingleNodeTestContext.waitForNodeToSync} — replaces hand-rolled
236
+ * `Promise.all(this.nodes.map(node => retryUntil(...)))` fan-out blocks.
237
+ * @param nodes - Nodes to poll; defaults to all validator nodes (`this.nodes`).
238
+ */ async waitForAllNodes(predicate, opts = {}) {
239
+ const nodes = opts.nodes ?? this.nodes;
240
+ const timeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 4;
241
+ const interval = opts.interval ?? 0.5;
242
+ const description = opts.description ?? 'all nodes to reach target';
243
+ await Promise.all(nodes.map((node, idx)=>retryUntil(async ()=>{
244
+ const tips = await node.getChainTips();
245
+ return await predicate(tips, node) || undefined;
246
+ }, `node ${idx} ${description}`, timeout, interval)));
247
+ }
248
+ /** Waits until every node's proven checkpoint tip reaches `target`. */ waitForAllNodesToReachProvenCheckpoint(target, opts = {}) {
249
+ return testSpan('wait:proven-checkpoint', ()=>this.waitForAllNodes((tips)=>tips.proven.checkpoint.number >= target, {
250
+ ...opts,
251
+ description: `proven checkpoint >= ${target}`
252
+ }));
253
+ }
254
+ /** Waits until every node's checkpointed checkpoint tip reaches `target`. */ waitForAllNodesToReachCheckpoint(target, opts = {}) {
255
+ return testSpan('wait:checkpoint', ()=>this.waitForAllNodes((tips)=>tips.checkpointed.checkpoint.number >= target, {
256
+ ...opts,
257
+ description: `checkpointed checkpoint >= ${target}`
258
+ }));
259
+ }
260
+ /**
261
+ * Waits until every node's `proposed` or `checkpointed` tip points at a block whose slot
262
+ * satisfies `match` (defaults to "slot equals `slot`"). Polls the block referenced by the tip.
263
+ */ waitForAllNodesToReachBlockAtSlot(slot, tag, match = (block)=>block.header.globalVariables.slotNumber === slot, opts = {}) {
264
+ return testSpan('wait:block', ()=>this.waitForAllNodes(async (tips, node)=>{
265
+ const blockNumber = tag === 'proposed' ? tips.proposed.number : tips.checkpointed.block.number;
266
+ if (blockNumber === 0) {
267
+ return false;
268
+ }
269
+ const block = await node.getBlock(blockNumber);
270
+ return !!block && match(block);
271
+ }, {
272
+ ...opts,
273
+ description: `${tag} block at slot ${slot}`
274
+ }));
275
+ }
276
+ /**
277
+ * Finds `count` consecutive slots (starting from `opts.fromSlot` or the current slot plus a
278
+ * margin) whose proposers satisfy `predicate`, warping the L1 clock forward one epoch and
279
+ * retrying when the rollup reports `ValidatorSelection__EpochNotStable` for a future epoch.
280
+ * Returns the matched slots and their proposer addresses. Encapsulates the slot-search loop
281
+ * duplicated across the multi-validator tests.
282
+ */ findSlotsWithProposers(count, predicate, opts = {}) {
283
+ return testSpan('warp:find-proposer', async ()=>{
284
+ const margin = opts.margin ?? 4;
285
+ const maxAttempts = opts.maxAttempts ?? 200;
286
+ let candidate = opts.fromSlot ?? SlotNumber(Number(this.epochCache.getEpochAndSlotNow().slot) + margin);
287
+ for(let attempt = 0; attempt < maxAttempts; attempt++){
288
+ try {
289
+ const slots = Array.from({
290
+ length: count
291
+ }, (_, i)=>SlotNumber(candidate + i));
292
+ const maybeProposers = await Promise.all(slots.map((slot)=>this.epochCache.getProposerAttesterAddressInSlot(slot)));
293
+ if (maybeProposers.every((p)=>p !== undefined) && predicate(maybeProposers)) {
294
+ return {
295
+ slots,
296
+ proposers: maybeProposers
297
+ };
298
+ }
299
+ candidate = SlotNumber(candidate + 1);
300
+ } catch (err) {
301
+ const msg = err instanceof Error ? err.message : String(err);
302
+ if (!msg.includes('EpochNotStable')) {
303
+ throw err;
304
+ }
305
+ const block = await this.l1Client.getBlock({
306
+ includeTransactions: false
307
+ });
308
+ const warpBy = this.epochDuration * this.L2_SLOT_DURATION_IN_S;
309
+ const newTs = Number(block.timestamp) + warpBy;
310
+ this.logger.warn(`Hit EpochNotStable at candidate ${candidate}, warping L1 forward by ${warpBy}s to ${newTs}`);
311
+ await this.context.cheatCodes.eth.warp(newTs, {
312
+ resetBlockInterval: true
313
+ });
314
+ const newCurrentSlot = Number(this.epochCache.getEpochAndSlotNow().slot);
315
+ if (candidate < newCurrentSlot + margin) {
316
+ candidate = SlotNumber(newCurrentSlot + margin);
317
+ }
318
+ }
319
+ }
320
+ throw new Error(`Could not find ${count} consecutive slots matching the proposer predicate after ${maxAttempts} attempts`);
321
+ });
322
+ }
323
+ /**
324
+ * Watches the sequencers of `nodes` via {@link SingleNodeTestContext.watchSequencerEvents}, pulling
325
+ * the {@link SequencerClient} off each node first. `getMetadata` tags each captured event; it
326
+ * defaults to `{ validator: this.validators[i].attester }`. Pass an override for tests that label
327
+ * their nodes differently (e.g. `['A','B','C'][i]`).
328
+ */ watchNodeSequencerEvents(nodes, getMetadata = (i)=>({
329
+ validator: this.validators[i].attester
330
+ })) {
331
+ return this.watchSequencerEvents(this.getSequencers(nodes), getMetadata);
332
+ }
333
+ /**
334
+ * Waits until matching slash offenses have converged across `nodes`, polling `getSlashOffenses`.
335
+ * With `opts.mode === 'all'` (the default) every node must record a matching offense; with `'any'`
336
+ * a single node suffices. Resolves with all matching offenses collected across the polled nodes.
337
+ */ waitForOffenseOnNodes(nodes, match, opts = {}) {
338
+ const mode = opts.mode ?? 'all';
339
+ const timeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 4;
340
+ const interval = opts.interval ?? 0.5;
341
+ return testSpan('wait:offense', ()=>retryUntil(async ()=>{
342
+ const perNode = await Promise.all(nodes.map((node)=>node.getSlashOffenses('all').then((os)=>os.filter(match))));
343
+ const converged = mode === 'all' ? perNode.every((matches)=>matches.length > 0) : perNode.some((m)=>m.length > 0);
344
+ return converged ? perNode.flat() : undefined;
345
+ }, `offense on ${mode} node(s)`, timeout, interval));
346
+ }
347
+ }
@@ -0,0 +1,27 @@
1
+ import type { AztecNodeService } from '@aztec/aztec-node';
2
+ import type { EthAddress } from '@aztec/aztec.js/addresses';
3
+ import { MultiNodeTestContext } from '../multi_node_test_context.js';
4
+ /** Stateful fixture for the inactivity-slash suites: a slasher-enabled committee on the mock-gossip bus. */
5
+ export declare class InactivityTest {
6
+ test: MultiNodeTestContext;
7
+ nodes: AztecNodeService[];
8
+ activeNodes: AztecNodeService[];
9
+ inactiveNodes: AztecNodeService[];
10
+ offlineValidators: EthAddress[];
11
+ private inactiveNodeCount;
12
+ constructor(opts: {
13
+ inactiveNodeCount: number;
14
+ });
15
+ static setup(opts: {
16
+ slashInactivityConsecutiveEpochThreshold: number;
17
+ inactiveNodeCount: number;
18
+ }): Promise<InactivityTest>;
19
+ private run;
20
+ teardown(): Promise<void>;
21
+ get rollup(): import("@aztec/ethereum/contracts").RollupContract;
22
+ get logger(): import("@aztec/foundation/log").Logger;
23
+ get config(): import("@aztec/aztec-node").AztecNodeConfig;
24
+ get monitor(): import("@aztec/ethereum/test").ChainMonitor;
25
+ get slashingAmount(): bigint;
26
+ }
27
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5hY3Rpdml0eV9zZXR1cC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL211bHRpLW5vZGUvc2xhc2hpbmcvaW5hY3Rpdml0eV9zZXR1cC50cyJdLCJuY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,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EACL,oBAAoB,EAGrB,MAAM,+BAA+B,CAAC;AAgBvC,4GAA4G;AAC5G,qBAAa,cAAc;IAClB,IAAI,EAAG,oBAAoB,CAAC;IAC5B,KAAK,EAAG,gBAAgB,EAAE,CAAC;IAC3B,WAAW,EAAG,gBAAgB,EAAE,CAAC;IACjC,aAAa,EAAG,gBAAgB,EAAE,CAAC;IACnC,iBAAiB,EAAG,UAAU,EAAE,CAAC;IAExC,OAAO,CAAC,iBAAiB,CAAS;IAElC,YAAY,IAAI,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE,EAE9C;IAED,OAAa,KAAK,CAAC,IAAI,EAAE;QACvB,wCAAwC,EAAE,MAAM,CAAC;QACjD,iBAAiB,EAAE,MAAM,CAAC;KAC3B,GAAG,OAAO,CAAC,cAAc,CAAC,CAI1B;YAEa,GAAG;IAoEJ,QAAQ,kBAEpB;IAED,IAAW,MAAM,uDAEhB;IAED,IAAW,MAAM,2CAEhB;IAED,IAAW,MAAM,gDAEhB;IAED,IAAW,OAAO,gDAEjB;IAED,IAAW,cAAc,WAExB;CACF"}
@@ -0,0 +1,111 @@
1
+ import { EpochNumber } from '@aztec/foundation/branded-types';
2
+ import { MultiNodeTestContext, SLASHER_ENABLED_MULTI_VALIDATOR_OPTS, buildMockGossipValidators } from '../multi_node_test_context.js';
3
+ const NUM_NODES = 6;
4
+ const NUM_VALIDATORS = NUM_NODES;
5
+ const COMMITTEE_SIZE = NUM_VALIDATORS;
6
+ const SLASHING_QUORUM = 3;
7
+ const EPOCH_DURATION = 2;
8
+ const SLASHING_ROUND_SIZE_IN_EPOCHS = 2;
9
+ const ETHEREUM_SLOT_DURATION = process.env.CI ? 8 : 4;
10
+ const AZTEC_SLOT_DURATION = ETHEREUM_SLOT_DURATION * 2;
11
+ const SLASHING_UNIT = BigInt(1e18);
12
+ const SLASHING_AMOUNT = SLASHING_UNIT * 3n;
13
+ // How many epochs it may take to set everything up, so we dont slash during this period
14
+ const SETUP_EPOCH_DURATION = 8;
15
+ /** Stateful fixture for the inactivity-slash suites: a slasher-enabled committee on the mock-gossip bus. */ export class InactivityTest {
16
+ test;
17
+ nodes;
18
+ activeNodes;
19
+ inactiveNodes;
20
+ offlineValidators;
21
+ inactiveNodeCount;
22
+ constructor(opts){
23
+ this.inactiveNodeCount = opts.inactiveNodeCount;
24
+ }
25
+ static async setup(opts) {
26
+ const inactivityTest = new InactivityTest(opts);
27
+ await inactivityTest.run(opts);
28
+ return inactivityTest;
29
+ }
30
+ async run(opts) {
31
+ this.test = await MultiNodeTestContext.setup({
32
+ ...SLASHER_ENABLED_MULTI_VALIDATOR_OPTS,
33
+ inboxLag: 2,
34
+ anvilSlotsInAnEpoch: 4,
35
+ // A fake prover node is started by the context (realProofs:false); give it the multi-epoch
36
+ // proving delay the inactivity scenario relied on, and keep enough broker history.
37
+ proverNodeConfig: {
38
+ proverNodeEpochProvingDelayMs: AZTEC_SLOT_DURATION * 1000
39
+ },
40
+ proverBrokerMaxEpochsToKeepResultsFor: 20,
41
+ aztecTargetCommitteeSize: COMMITTEE_SIZE,
42
+ aztecSlotDuration: AZTEC_SLOT_DURATION,
43
+ ethereumSlotDuration: ETHEREUM_SLOT_DURATION,
44
+ aztecProofSubmissionEpochs: 1024,
45
+ listenAddress: '127.0.0.1',
46
+ minTxsPerBlock: 0,
47
+ aztecEpochDuration: EPOCH_DURATION,
48
+ sentinelEnabled: true,
49
+ slashingQuorum: SLASHING_QUORUM,
50
+ slashingRoundSizeInEpochs: SLASHING_ROUND_SIZE_IN_EPOCHS,
51
+ slashInactivityTargetPercentage: 0.8,
52
+ slashGracePeriodL2Slots: SETUP_EPOCH_DURATION * EPOCH_DURATION,
53
+ slashAmountSmall: SLASHING_UNIT,
54
+ slashAmountMedium: SLASHING_UNIT * 2n,
55
+ slashAmountLarge: SLASHING_UNIT * 3n,
56
+ slashInactivityConsecutiveEpochThreshold: opts.slashInactivityConsecutiveEpochThreshold,
57
+ slashInactivityPenalty: SLASHING_AMOUNT,
58
+ initialValidators: buildMockGossipValidators(NUM_VALIDATORS)
59
+ });
60
+ const { rollup } = await this.test.getSlashingContracts();
61
+ const [activationThreshold, ejectionThreshold, localEjectionThreshold] = await Promise.all([
62
+ rollup.getActivationThreshold(),
63
+ rollup.getEjectionThreshold(),
64
+ rollup.getLocalEjectionThreshold()
65
+ ]);
66
+ const biggestEjection = ejectionThreshold > localEjectionThreshold ? ejectionThreshold : localEjectionThreshold;
67
+ expect(activationThreshold - SLASHING_AMOUNT).toBeLessThan(biggestEjection);
68
+ // Create all active nodes (running sequencer) plus the inactive ones (sequencer disabled).
69
+ const activeCount = NUM_NODES - this.inactiveNodeCount;
70
+ this.activeNodes = await Promise.all(Array.from({
71
+ length: activeCount
72
+ }, (_, i)=>this.test.createValidatorNodeAt(i)));
73
+ this.inactiveNodes = await Promise.all(Array.from({
74
+ length: this.inactiveNodeCount
75
+ }, (_, i)=>this.test.createValidatorNodeAt(activeCount + i, {
76
+ dontStartSequencer: true
77
+ })));
78
+ this.nodes = [
79
+ ...this.activeNodes,
80
+ ...this.inactiveNodes
81
+ ];
82
+ if (this.nodes.length !== NUM_NODES) {
83
+ throw new Error(`Expected ${NUM_NODES} nodes but got ${this.nodes.length}`);
84
+ }
85
+ this.offlineValidators = this.test.validators.slice(this.test.validators.length - this.inactiveNodeCount).map((v)=>v.attester);
86
+ this.test.logger.warn(`Setup complete. Offline validators are ${this.offlineValidators.join(', ')}.`, {
87
+ validators: this.test.validators,
88
+ offlineValidators: this.offlineValidators
89
+ });
90
+ this.test.logger.warn(`Advancing to epoch ${SETUP_EPOCH_DURATION - 1} (slashing will start after it is completed)`);
91
+ await this.test.context.cheatCodes.rollup.advanceToEpoch(EpochNumber(SETUP_EPOCH_DURATION - 1));
92
+ }
93
+ async teardown() {
94
+ await this.test.teardown();
95
+ }
96
+ get rollup() {
97
+ return this.test.rollup;
98
+ }
99
+ get logger() {
100
+ return this.test.logger;
101
+ }
102
+ get config() {
103
+ return this.test.context.config;
104
+ }
105
+ get monitor() {
106
+ return this.test.monitor;
107
+ }
108
+ get slashingAmount() {
109
+ return SLASHING_AMOUNT;
110
+ }
111
+ }
@@ -0,0 +1,167 @@
1
+ import type { AztecNodeService } from '@aztec/aztec-node';
2
+ import type { Logger } from '@aztec/aztec.js/log';
3
+ import type { RollupCheatCodes } from '@aztec/aztec/testing';
4
+ import type { EpochCacheInterface } from '@aztec/epoch-cache';
5
+ import type { RollupContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
6
+ import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
7
+ import { EthAddress } from '@aztec/foundation/eth-address';
8
+ import { type OffenseType } from '@aztec/slasher';
9
+ import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
10
+ import type { TxHash } from '@aztec/stdlib/tx';
11
+ import { jest } from '@jest/globals';
12
+ import type { MultiNodeTestContext } from '../multi_node_test_context.js';
13
+ export declare const NUM_VALIDATORS = 4;
14
+ export declare const COMMITTEE_SIZE = 4;
15
+ export declare const ETHEREUM_SLOT_DURATION = 8;
16
+ export declare const AZTEC_SLOT_DURATION: number;
17
+ export declare const BLOCK_DURATION = 4;
18
+ export declare const slashingUnit: bigint;
19
+ export declare const slashingQuorum = 3;
20
+ export declare const slashingRoundSize = 4;
21
+ export declare const aztecEpochDuration = 2;
22
+ /**
23
+ * The shared per-test slashing config for the offense-detection suites (`duplicate_proposal`,
24
+ * `duplicate_attestation`). Spread into a {@link MultiNodeTestContext.setup} call alongside
25
+ * {@link SLASHER_ENABLED_MULTI_VALIDATOR_OPTS} and `initialValidators` (from `buildMockGossipValidators`).
26
+ */
27
+ export declare const baseSlashingOpts: {
28
+ anvilSlotsInAnEpoch: number;
29
+ listenAddress: string;
30
+ aztecEpochDuration: number;
31
+ ethereumSlotDuration: number;
32
+ aztecSlotDuration: number;
33
+ aztecTargetCommitteeSize: number;
34
+ aztecProofSubmissionEpochs: number;
35
+ slashInactivityConsecutiveEpochThreshold: number;
36
+ minTxsPerBlock: number;
37
+ slashingQuorum: number;
38
+ slashingRoundSizeInEpochs: number;
39
+ slashAmountSmall: bigint;
40
+ slashAmountMedium: bigint;
41
+ slashAmountLarge: bigint;
42
+ blockDurationMs: number;
43
+ slashDuplicateProposalPenalty: bigint;
44
+ slashingOffsetInRounds: number;
45
+ };
46
+ /**
47
+ * The fast slot timing shared by the sentinel-observation suites (`sentinel_status_slash`,
48
+ * `validators_sentinel`, `multiple_validators_sentinel`, `slash_veto_demo`). Slots are 8s (eth 4s ×
49
+ * epoch 2), which fit a checkpoint comfortably at the fast mocked-p2p operational budgets used at
50
+ * eth<8, keeping wall-clock down for tests whose bodies advance through real L2 slots. Spread into a
51
+ * {@link MultiNodeTestContext.setup} call alongside {@link SLASHER_ENABLED_MULTI_VALIDATOR_OPTS},
52
+ * `initialValidators`, and the per-test slash/penalty config. Non-sentinel offense-detection files
53
+ * that only need the same fast timing spread this and override `sentinelEnabled: false`.
54
+ */
55
+ export declare const SENTINEL_TIMING: {
56
+ readonly anvilSlotsInAnEpoch: 4;
57
+ readonly listenAddress: "127.0.0.1";
58
+ readonly ethereumSlotDuration: 4;
59
+ readonly aztecSlotDuration: 8;
60
+ readonly aztecEpochDuration: 2;
61
+ readonly sentinelEnabled: true;
62
+ };
63
+ /** A single detected slash offense as returned by {@link AztecNodeService.getSlashOffenses}. */
64
+ export type SlashOffense = Awaited<ReturnType<AztecNodeService['getSlashOffenses']>>[number];
65
+ /** Looks up the offense recorded for `validator` of `offenseType` at `slot`, if any. */
66
+ export declare function findSlashOffense(offenses: SlashOffense[], validator: EthAddress, offenseType: OffenseType, slot: SlotNumber): SlashOffense | undefined;
67
+ export declare function awaitProposalExecution(slashingProposer: SlashingProposerContract, timeoutSeconds: number, logger: Logger): Promise<bigint>;
68
+ export declare function awaitCommitteeExists({ rollup, logger }: {
69
+ rollup: RollupContract;
70
+ logger: Logger;
71
+ }): Promise<readonly `0x${string}`[]>;
72
+ /**
73
+ * Scans L2 slots forward from `minLeadSlots` ahead of the current slot, returning the first slot in
74
+ * which `targetProposer` is the proposer.
75
+ *
76
+ * Scanning starts at `currentSlot + minLeadSlots` and only ever moves forward, so every returned slot
77
+ * is at least `minLeadSlots` ahead — a caller can safely warp to `targetSlot - minLeadSlots` for a
78
+ * settle buffer without risking a backwards warp. Stepping by a single slot examines both epoch
79
+ * parities, which matters because the per-slot proposer is a different RANDAO-shuffled committee
80
+ * member: searching only a fixed offset within each epoch can leave a 1-of-N target unexamined when
81
+ * the epoch is short. A candidate in an epoch whose committee isn't sampled yet makes the proposer
82
+ * lookup revert with EpochNotStable; this warps one epoch forward and continues, keeping the
83
+ * candidate at least `minLeadSlots` ahead of the new current slot. Throws after `maxSlotsToScan`.
84
+ *
85
+ * Unlike {@link advanceToEpochBeforeProposer}, this does not stop an epoch early — callers that want
86
+ * to warp close to the target (rather than stage sequencers an epoch ahead) use this and warp the
87
+ * final `minLeadSlots` in themselves.
88
+ */
89
+ export declare function findUpcomingProposerSlot({ epochCache, cheatCodes, targetProposer, logger, minLeadSlots, maxSlotsToScan }: {
90
+ epochCache: EpochCacheInterface;
91
+ cheatCodes: RollupCheatCodes;
92
+ targetProposer: EthAddress;
93
+ logger: Logger;
94
+ minLeadSlots: number;
95
+ maxSlotsToScan?: number;
96
+ }): Promise<SlotNumber>;
97
+ /**
98
+ * Advance epochs until we find one where the target proposer is selected for a slot at least
99
+ * `warmupSlots` into the epoch, then stop one epoch before it. This leaves time for the caller to
100
+ * start sequencers before warping to the target epoch, avoiding the race where the target epoch
101
+ * passes before sequencers are ready.
102
+ *
103
+ * The first `warmupSlots` slots of the epoch are skipped on purpose. Callers warp to one slot
104
+ * before the target epoch and, under proposer pipelining, the proposer begins building one slot
105
+ * before its proposal slot. If the proposer were in the first slot of the epoch, that build would
106
+ * begin at the exact instant of the warp, leaving the freshly-started sequencer no warm-up margin;
107
+ * it then serializes its (often AVM-heavy) proposal past the slot boundary and honest receivers
108
+ * reject it as late. Picking a slot at least `warmupSlots` into the epoch guarantees that many full
109
+ * slots of wall-clock between the warp and the start of the proposer's build.
110
+ *
111
+ * Returns the target epoch and the concrete target slot so the caller can warp to it after starting
112
+ * sequencers.
113
+ *
114
+ * The default `maxAttempts` accounts for the worst-case caller: with a 2-slot epoch and
115
+ * `warmupSlots = 1`, each attempt checks a single slot, and with a 4-member committee the target is
116
+ * the proposer with probability 1/4 per attempt (proposer index is keccak(epoch, slot, seed) mod
117
+ * committee size, so attempts are independent). 50 attempts bound the miss probability at
118
+ * (3/4)^50 ≈ 6e-7; each attempt is just a committee query plus an anvil warp, so the extra headroom
119
+ * costs almost nothing.
120
+ */
121
+ export declare function advanceToEpochBeforeProposer({ epochCache, cheatCodes, targetProposer, logger, maxAttempts, warmupSlots }: {
122
+ epochCache: EpochCacheInterface;
123
+ cheatCodes: RollupCheatCodes;
124
+ targetProposer: EthAddress;
125
+ logger: Logger;
126
+ maxAttempts?: number;
127
+ warmupSlots?: number;
128
+ }): Promise<{
129
+ targetEpoch: EpochNumber;
130
+ targetSlot: SlotNumber;
131
+ }>;
132
+ export declare function awaitOffenseDetected({ logger, nodeAdmin, slashingRoundSize, epochDuration, waitUntilOffenseCount, timeoutSeconds }: {
133
+ nodeAdmin: AztecNodeAdmin;
134
+ logger: Logger;
135
+ slashingRoundSize: number;
136
+ epochDuration: number;
137
+ waitUntilOffenseCount?: number;
138
+ timeoutSeconds?: number;
139
+ }): Promise<import("@aztec/slasher").Offense[]>;
140
+ /**
141
+ * Await the committee to be slashed out of the validator set.
142
+ * Currently assumes that the committee is the same size as the validator set.
143
+ */
144
+ export declare function awaitCommitteeKicked({ rollup, cheatCodes, committee, slashingProposer, slashingRoundSize, aztecSlotDuration, aztecEpochDuration, logger, offenseEpoch }: {
145
+ rollup: RollupContract;
146
+ cheatCodes: RollupCheatCodes;
147
+ committee: readonly `0x${string}`[];
148
+ slashingProposer: SlashingProposerContract | undefined;
149
+ slashingRoundSize: number;
150
+ aztecSlotDuration: number;
151
+ aztecEpochDuration: number;
152
+ logger: Logger;
153
+ offenseEpoch: number;
154
+ }): Promise<void>;
155
+ /** Resolves the slot at which `node` includes `txHash`, by reading the tx receipt and block header. */
156
+ export declare function getMinedSlot(node: AztecNodeService, txHash: {
157
+ toString(): string;
158
+ }): Promise<number>;
159
+ /**
160
+ * Submits `numTxs` account-deployment transactions through `node`, paying with the funded hardcoded
161
+ * account (`context.accounts[0]`). Repoints the context wallet at `node` so the txs land in that node's
162
+ * mempool. The mock-gossip equivalent of the old `submitTransactions(logger, node, numTxs, fundedAccount)`
163
+ * helper, which built a fresh wallet from the funded account.
164
+ */
165
+ export declare function submitTxsThroughNode(test: MultiNodeTestContext, node: AztecNodeService, numTxs: number): Promise<TxHash[]>;
166
+ export { jest };
167
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0dXAuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9tdWx0aS1ub2RlL3NsYXNoaW5nL3NldHVwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDMUQsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbEQsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUM3RCxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSx3QkFBd0IsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQzFGLE9BQU8sRUFBRSxXQUFXLEVBQU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