@aztec/end-to-end 5.0.0-rc.2 → 5.0.1
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.
- package/README.md +215 -27
- package/dest/automine/automine_test_context.d.ts +85 -0
- package/dest/automine/automine_test_context.d.ts.map +1 -0
- package/dest/automine/automine_test_context.js +98 -0
- package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts +2 -0
- package/dest/automine/contracts/fixtures/storage_proof_fetcher.d.ts.map +1 -0
- package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.d.ts +1 -1
- package/dest/automine/contracts/fixtures/storage_proof_fixture.d.ts.map +1 -0
- package/dest/automine/delivery/interactive_handshake_responder.d.ts +48 -0
- package/dest/automine/delivery/interactive_handshake_responder.d.ts.map +1 -0
- package/dest/automine/delivery/interactive_handshake_responder.js +76 -0
- package/dest/automine/delivery/onchain_delivery_harness.d.ts +19 -0
- package/dest/automine/delivery/onchain_delivery_harness.d.ts.map +1 -0
- package/dest/automine/delivery/onchain_delivery_harness.js +141 -0
- package/dest/automine/token/blacklist_token_contract_test.d.ts +49 -0
- package/dest/automine/token/blacklist_token_contract_test.d.ts.map +1 -0
- package/dest/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.js +17 -24
- package/dest/automine/token/token_contract_test.d.ts +40 -0
- package/dest/automine/token/token_contract_test.d.ts.map +1 -0
- package/dest/{e2e_token_contract → automine/token}/token_contract_test.js +22 -28
- package/dest/automine/token/token_test_helpers.d.ts +73 -0
- package/dest/automine/token/token_test_helpers.d.ts.map +1 -0
- package/dest/automine/token/token_test_helpers.js +97 -0
- package/dest/bench/client_flows/benchmark.d.ts +1 -1
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/benchmark.js +3 -1
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +16 -4
- package/dest/bench/utils.d.ts +1 -1
- package/dest/composed/ha/ha_full_setup.d.ts +77 -0
- package/dest/composed/ha/ha_full_setup.d.ts.map +1 -0
- package/dest/composed/ha/ha_full_setup.js +383 -0
- package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts +12 -0
- package/dest/composed/web3signer/multi_validator_keystore_utils.d.ts.map +1 -0
- package/dest/fixtures/e2e_prover_test.d.ts +10 -7
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.js +30 -11
- package/dest/fixtures/fixtures.d.ts +9 -6
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +11 -7
- package/dest/fixtures/ha_setup.d.ts +3 -3
- package/dest/fixtures/ha_setup.d.ts.map +1 -1
- package/dest/fixtures/ha_setup.js +4 -1
- package/dest/fixtures/index.d.ts +2 -1
- package/dest/fixtures/index.d.ts.map +1 -1
- package/dest/fixtures/index.js +1 -0
- package/dest/fixtures/setup.d.ts +34 -9
- package/dest/fixtures/setup.d.ts.map +1 -1
- package/dest/fixtures/setup.js +165 -160
- package/dest/fixtures/standard_contracts_genesis.d.ts +16 -0
- package/dest/fixtures/standard_contracts_genesis.d.ts.map +1 -0
- package/dest/fixtures/standard_contracts_genesis.js +25 -0
- package/dest/fixtures/timing.d.ts +42 -0
- package/dest/fixtures/timing.d.ts.map +1 -0
- package/dest/fixtures/timing.js +72 -0
- package/dest/fixtures/wait_helpers.d.ts +135 -0
- package/dest/fixtures/wait_helpers.d.ts.map +1 -0
- package/dest/fixtures/wait_helpers.js +154 -0
- package/dest/forward-compatibility/wallet_service.js +1 -1
- package/dest/multi-node/block-production/setup.d.ts +97 -0
- package/dest/multi-node/block-production/setup.d.ts.map +1 -0
- package/dest/multi-node/block-production/setup.js +158 -0
- package/dest/multi-node/governance/setup.d.ts +67 -0
- package/dest/multi-node/governance/setup.d.ts.map +1 -0
- package/dest/multi-node/governance/setup.js +126 -0
- package/dest/multi-node/multi_node_test_context.d.ts +212 -0
- package/dest/multi-node/multi_node_test_context.d.ts.map +1 -0
- package/dest/multi-node/multi_node_test_context.js +347 -0
- package/dest/multi-node/slashing/inactivity_setup.d.ts +27 -0
- package/dest/multi-node/slashing/inactivity_setup.d.ts.map +1 -0
- package/dest/multi-node/slashing/inactivity_setup.js +111 -0
- package/dest/multi-node/slashing/setup.d.ts +167 -0
- package/dest/multi-node/slashing/setup.d.ts.map +1 -0
- package/dest/multi-node/slashing/setup.js +275 -0
- package/dest/{e2e_p2p → p2p}/p2p_network.d.ts +9 -1
- package/dest/p2p/p2p_network.d.ts.map +1 -0
- package/dest/{e2e_p2p → p2p}/p2p_network.js +26 -1
- package/dest/p2p/reqresp/utils.d.ts +19 -0
- package/dest/p2p/reqresp/utils.d.ts.map +1 -0
- package/dest/{e2e_p2p → p2p}/reqresp/utils.js +4 -15
- package/dest/p2p/shared.d.ts +72 -0
- package/dest/p2p/shared.d.ts.map +1 -0
- package/dest/p2p/shared.js +212 -0
- package/dest/shared/cross_chain_test_harness.d.ts +3 -3
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +24 -16
- package/dest/shared/gas_portal_test_harness.d.ts +1 -1
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +8 -5
- package/dest/shared/submit-transactions.d.ts +1 -1
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +12 -5
- package/dest/shared/timing_env.d.js +5 -0
- package/dest/shared/timing_env.js +158 -47
- package/dest/shared/wait_for_l1_to_l2_message.js +1 -1
- package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts +75 -0
- package/dest/single-node/cross-chain/cross_chain_messaging_test.d.ts.map +1 -0
- package/dest/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.js +74 -26
- package/dest/single-node/cross-chain/message_test_helpers.d.ts +38 -0
- package/dest/single-node/cross-chain/message_test_helpers.d.ts.map +1 -0
- package/dest/single-node/cross-chain/message_test_helpers.js +70 -0
- package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.d.ts +1 -1
- package/dest/single-node/fees/bridging_race.notest.d.ts.map +1 -0
- package/dest/{e2e_fees → single-node/fees}/bridging_race.notest.js +9 -6
- package/dest/single-node/fees/fees_test.d.ts +95 -0
- package/dest/single-node/fees/fees_test.d.ts.map +1 -0
- package/dest/{e2e_fees → single-node/fees}/fees_test.js +121 -45
- package/dest/single-node/l1-reorgs/setup.d.ts +42 -0
- package/dest/single-node/l1-reorgs/setup.d.ts.map +1 -0
- package/dest/single-node/l1-reorgs/setup.js +57 -0
- package/dest/single-node/partial-proofs/setup.d.ts +5 -0
- package/dest/single-node/partial-proofs/setup.d.ts.map +1 -0
- package/dest/single-node/partial-proofs/setup.js +5 -0
- package/dest/single-node/proving/setup.d.ts +5 -0
- package/dest/single-node/proving/setup.d.ts.map +1 -0
- package/dest/single-node/proving/setup.js +5 -0
- package/dest/single-node/recovery/setup.d.ts +5 -0
- package/dest/single-node/recovery/setup.d.ts.map +1 -0
- package/dest/single-node/recovery/setup.js +5 -0
- package/dest/single-node/setup.d.ts +49 -0
- package/dest/single-node/setup.d.ts.map +1 -0
- package/dest/single-node/setup.js +56 -0
- package/dest/single-node/single_node_test_context.d.ts +374 -0
- package/dest/single-node/single_node_test_context.d.ts.map +1 -0
- package/dest/single-node/single_node_test_context.js +847 -0
- package/dest/spartan/setup_test_wallets.d.ts +1 -1
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +13 -7
- package/dest/spartan/tx_metrics.d.ts +10 -1
- package/dest/spartan/tx_metrics.d.ts.map +1 -1
- package/dest/spartan/tx_metrics.js +32 -0
- package/dest/test-wallet/test_wallet.d.ts +23 -4
- package/dest/test-wallet/test_wallet.d.ts.map +1 -1
- package/dest/test-wallet/test_wallet.js +20 -4
- package/dest/test-wallet/utils.d.ts +36 -1
- package/dest/test-wallet/utils.d.ts.map +1 -1
- package/dest/test-wallet/utils.js +64 -4
- package/dest/test-wallet/wallet_worker_script.js +5 -2
- package/dest/test-wallet/worker_wallet.d.ts +5 -5
- package/dest/test-wallet/worker_wallet.d.ts.map +1 -1
- package/dest/test-wallet/worker_wallet.js +2 -2
- package/dest/test-wallet/worker_wallet_schema.js +2 -1
- package/package.json +40 -40
- package/src/automine/README.md +60 -0
- package/src/automine/automine_test_context.ts +153 -0
- package/src/automine/delivery/interactive_handshake_responder.ts +125 -0
- package/src/automine/delivery/onchain_delivery_harness.ts +213 -0
- package/src/{e2e_blacklist_token_contract → automine/token}/blacklist_token_contract_test.ts +19 -39
- package/src/{e2e_token_contract → automine/token}/token_contract_test.ts +24 -43
- package/src/automine/token/token_test_helpers.ts +138 -0
- package/src/bench/client_flows/benchmark.ts +3 -1
- package/src/bench/client_flows/client_flows_benchmark.ts +17 -4
- package/src/composed/ha/ha_full_setup.ts +466 -0
- package/src/fixtures/e2e_prover_test.ts +36 -20
- package/src/fixtures/fixtures.ts +11 -7
- package/src/fixtures/ha_setup.ts +7 -3
- package/src/fixtures/index.ts +1 -0
- package/src/fixtures/setup.ts +204 -162
- package/src/fixtures/standard_contracts_genesis.ts +28 -0
- package/src/fixtures/timing.ts +97 -0
- package/src/fixtures/wait_helpers.ts +333 -0
- package/src/forward-compatibility/wallet_service.ts +2 -2
- package/src/infra/README.md +12 -0
- package/src/multi-node/README.md +96 -0
- package/src/multi-node/block-production/setup.ts +272 -0
- package/src/multi-node/governance/setup.ts +172 -0
- package/src/multi-node/multi_node_test_context.ts +447 -0
- package/src/multi-node/slashing/inactivity_setup.ts +139 -0
- package/src/multi-node/slashing/setup.ts +433 -0
- package/src/p2p/README.md +78 -0
- package/src/{e2e_p2p → p2p}/p2p_network.ts +26 -0
- package/src/{e2e_p2p → p2p}/reqresp/utils.ts +5 -14
- package/src/p2p/shared.ts +329 -0
- package/src/shared/cross_chain_test_harness.ts +22 -13
- package/src/shared/gas_portal_test_harness.ts +13 -5
- package/src/shared/submit-transactions.ts +13 -5
- package/src/shared/timing_env.d.mts +39 -0
- package/src/shared/timing_env.mjs +152 -48
- package/src/shared/wait_for_l1_to_l2_message.ts +1 -1
- package/src/single-node/README.md +66 -0
- package/src/{e2e_cross_chain_messaging → single-node/cross-chain}/cross_chain_messaging_test.ts +100 -38
- package/src/single-node/cross-chain/message_test_helpers.ts +125 -0
- package/src/{e2e_fees → single-node/fees}/bridging_race.notest.ts +11 -7
- package/src/{e2e_fees → single-node/fees}/fees_test.ts +132 -47
- package/src/single-node/l1-reorgs/setup.ts +93 -0
- package/src/single-node/partial-proofs/setup.ts +8 -0
- package/src/single-node/proving/setup.ts +15 -0
- package/src/single-node/recovery/setup.ts +8 -0
- package/src/single-node/setup.ts +63 -0
- package/src/single-node/single_node_test_context.ts +1058 -0
- package/src/spartan/setup_test_wallets.ts +19 -7
- package/src/spartan/tx_metrics.ts +26 -0
- package/src/test-wallet/test_wallet.ts +28 -6
- package/src/test-wallet/utils.ts +102 -5
- package/src/test-wallet/wallet_worker_script.ts +6 -3
- package/src/test-wallet/worker_wallet.ts +5 -9
- package/src/test-wallet/worker_wallet_schema.ts +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +0 -56
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +0 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -59
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +0 -1
- package/dest/e2e_deploy_contract/deploy_test.d.ts +0 -36
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +0 -1
- package/dest/e2e_deploy_contract/deploy_test.js +0 -42
- package/dest/e2e_epochs/epochs_test.d.ts +0 -137
- package/dest/e2e_epochs/epochs_test.d.ts.map +0 -1
- package/dest/e2e_epochs/epochs_test.js +0 -485
- package/dest/e2e_fees/bridging_race.notest.d.ts.map +0 -1
- package/dest/e2e_fees/fees_test.d.ts +0 -89
- package/dest/e2e_fees/fees_test.d.ts.map +0 -1
- package/dest/e2e_l1_publisher/write_json.d.ts +0 -11
- package/dest/e2e_l1_publisher/write_json.d.ts.map +0 -1
- package/dest/e2e_l1_publisher/write_json.js +0 -57
- package/dest/e2e_multi_validator/utils.d.ts +0 -12
- package/dest/e2e_multi_validator/utils.d.ts.map +0 -1
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +0 -22
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +0 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +0 -40
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +0 -31
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +0 -1
- package/dest/e2e_p2p/inactivity_slash_test.js +0 -138
- package/dest/e2e_p2p/p2p_network.d.ts.map +0 -1
- package/dest/e2e_p2p/reqresp/utils.d.ts +0 -22
- package/dest/e2e_p2p/reqresp/utils.d.ts.map +0 -1
- package/dest/e2e_p2p/shared.d.ts +0 -100
- package/dest/e2e_p2p/shared.d.ts.map +0 -1
- package/dest/e2e_p2p/shared.js +0 -257
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +0 -2
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +0 -1
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +0 -1
- package/dest/e2e_token_contract/token_contract_test.d.ts +0 -44
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +0 -1
- package/src/e2e_deploy_contract/deploy_test.ts +0 -73
- package/src/e2e_epochs/epochs_test.ts +0 -596
- package/src/e2e_l1_publisher/write_json.ts +0 -78
- package/src/e2e_nested_contract/nested_contract_test.ts +0 -51
- package/src/e2e_p2p/inactivity_slash_test.ts +0 -181
- package/src/e2e_p2p/shared.ts +0 -391
- /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.js +0 -0
- /package/dest/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.js +0 -0
- /package/dest/{e2e_multi_validator/utils.js → composed/web3signer/multi_validator_keystore_utils.js} +0 -0
- /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof.json +0 -0
- /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fetcher.ts +0 -0
- /package/src/{e2e_storage_proof → automine/contracts}/fixtures/storage_proof_fixture.ts +0 -0
- /package/src/{e2e_multi_validator/utils.ts → composed/web3signer/multi_validator_keystore_utils.ts} +0 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import type { AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
|
|
2
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import { RollupContract, type SlashingProposerContract } from '@aztec/ethereum/contracts';
|
|
5
|
+
import type { Operator } from '@aztec/ethereum/deploy-aztec-l1-contracts';
|
|
6
|
+
import type { ViemClient } from '@aztec/ethereum/types';
|
|
7
|
+
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
8
|
+
import { times } from '@aztec/foundation/collection';
|
|
9
|
+
import { SecretValue } from '@aztec/foundation/config';
|
|
10
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
11
|
+
import { bufferToHex } from '@aztec/foundation/string';
|
|
12
|
+
import { SlasherAbi } from '@aztec/l1-artifacts';
|
|
13
|
+
import type { L2Tips } from '@aztec/stdlib/block';
|
|
14
|
+
import type { AztecNode, BlockResponse } from '@aztec/stdlib/interfaces/client';
|
|
15
|
+
import type { Offense } from '@aztec/stdlib/slashing';
|
|
16
|
+
import { createSharedSlashingProtectionDb } from '@aztec/validator-ha-signer/factory';
|
|
17
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
18
|
+
|
|
19
|
+
import { type GetContractReturnType, getAddress, getContract } from 'viem';
|
|
20
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
21
|
+
|
|
22
|
+
import { testSpan } from '../fixtures/timing.js';
|
|
23
|
+
import { getPrivateKeyFromIndex } from '../fixtures/utils.js';
|
|
24
|
+
import { NO_REORG_SUBMISSION_EPOCHS } from '../single-node/setup.js';
|
|
25
|
+
import {
|
|
26
|
+
SingleNodeTestContext,
|
|
27
|
+
type SingleNodeTestOpts,
|
|
28
|
+
type TrackedSequencerEvent,
|
|
29
|
+
} from '../single-node/single_node_test_context.js';
|
|
30
|
+
|
|
31
|
+
export { NO_REORG_SUBMISSION_EPOCHS, PROVING_SLOT_TIMING } from '../single-node/setup.js';
|
|
32
|
+
export {
|
|
33
|
+
WORLD_STATE_CHECKPOINT_HISTORY,
|
|
34
|
+
WORLD_STATE_BLOCK_CHECK_INTERVAL,
|
|
35
|
+
ARCHIVER_POLL_INTERVAL,
|
|
36
|
+
DEFAULT_L1_BLOCK_TIME,
|
|
37
|
+
REORG_TIMING_BASE,
|
|
38
|
+
FAST_REORG_TIMING,
|
|
39
|
+
MULTI_VALIDATOR_REORG_TIMING,
|
|
40
|
+
MULTI_VALIDATOR_BLOCK_PRODUCTION_TIMING,
|
|
41
|
+
WIDE_SLOT_TIMING,
|
|
42
|
+
type BlockProposedEvent,
|
|
43
|
+
type TrackedSequencerEvent,
|
|
44
|
+
type SingleNodeTestOpts,
|
|
45
|
+
} from '../single-node/single_node_test_context.js';
|
|
46
|
+
|
|
47
|
+
/** Options for {@link MultiNodeTestContext.setup} — superset of {@link SingleNodeTestOpts}. */
|
|
48
|
+
export type MultiNodeTestOpts = SingleNodeTestOpts;
|
|
49
|
+
|
|
50
|
+
/** A registered validator with its on-chain operator data and the L1 private key its node signs with. */
|
|
51
|
+
export type RegisteredValidator = Operator & { privateKey: `0x${string}` };
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Builds the deterministic validator set used across the multi-validator tests: `count` validators
|
|
55
|
+
* keyed from `getPrivateKeyFromIndex(i + 3)` (indices 0..2 are reserved for the setup account,
|
|
56
|
+
* bootstrap node, and prover node, matching the `P2PNetworkTest` convention). This replaces the
|
|
57
|
+
* `times(N, i => ({ attester, withdrawer, privateKey, bn254SecretKey }))` block copy-pasted in every
|
|
58
|
+
* direct multi-validator test.
|
|
59
|
+
*/
|
|
60
|
+
export function buildMockGossipValidators(count: number): RegisteredValidator[] {
|
|
61
|
+
return times(count, i => {
|
|
62
|
+
const privateKey = bufferToHex(getPrivateKeyFromIndex(i + 3)!);
|
|
63
|
+
const attester = EthAddress.fromString(privateKeyToAccount(privateKey).address);
|
|
64
|
+
return { attester, withdrawer: attester, privateKey, bn254SecretKey: new SecretValue(Fr.random().toBigInt()) };
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The shared `setup` cluster for the multi-validator tests that run a tight committee on the
|
|
70
|
+
* in-memory mock-gossip bus without a prover (block-production / recovery tests). Spread into the `setup`
|
|
71
|
+
* call alongside `initialValidators` (from {@link buildMockGossipValidators}). Tests that want a
|
|
72
|
+
* prover (MBPS / HA-sync) leave `startProverNode` explicit rather than adopting this preset's `false`.
|
|
73
|
+
*/
|
|
74
|
+
export const MOCK_GOSSIP_MULTI_VALIDATOR_OPTS = {
|
|
75
|
+
mockGossipSubNetwork: true,
|
|
76
|
+
skipInitialSequencer: true,
|
|
77
|
+
startProverNode: false,
|
|
78
|
+
aztecProofSubmissionEpochs: NO_REORG_SUBMISSION_EPOCHS,
|
|
79
|
+
numberOfAccounts: 0,
|
|
80
|
+
} as const;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The `setup` preset for a slasher-enabled committee on the in-memory mock-gossip bus, used by the
|
|
84
|
+
* offense-detection tests (`slashing/`). Mirrors {@link MOCK_GOSSIP_MULTI_VALIDATOR_OPTS} but turns
|
|
85
|
+
* the slasher on; spread alongside `initialValidators` (from {@link buildMockGossipValidators}) and
|
|
86
|
+
* the per-test slashing-round/penalty config.
|
|
87
|
+
*/
|
|
88
|
+
export const SLASHER_ENABLED_MULTI_VALIDATOR_OPTS = {
|
|
89
|
+
mockGossipSubNetwork: true,
|
|
90
|
+
skipInitialSequencer: true,
|
|
91
|
+
slasherEnabled: true,
|
|
92
|
+
} as const;
|
|
93
|
+
|
|
94
|
+
/** The slasher and slashing-proposer L1 contracts a slashing test interacts with. */
|
|
95
|
+
export type SlashingContracts = {
|
|
96
|
+
rollup: RollupContract;
|
|
97
|
+
slasherContract: GetContractReturnType<typeof SlasherAbi, ViemClient>;
|
|
98
|
+
slashingProposer: SlashingProposerContract | undefined;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** The per-offense penalty knobs a slashing test tunes; all default to a single `unit`. */
|
|
102
|
+
export type SlashingPenalties = {
|
|
103
|
+
slashInactivityPenalty: bigint;
|
|
104
|
+
slashDataWithholdingPenalty: bigint;
|
|
105
|
+
slashBroadcastedInvalidBlockPenalty: bigint;
|
|
106
|
+
slashBroadcastedInvalidCheckpointProposalPenalty: bigint;
|
|
107
|
+
slashDuplicateProposalPenalty: bigint;
|
|
108
|
+
slashDuplicateAttestationPenalty: bigint;
|
|
109
|
+
slashProposeInvalidAttestationsPenalty: bigint;
|
|
110
|
+
slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty: bigint;
|
|
111
|
+
slashAttestInvalidCheckpointProposalPenalty: bigint;
|
|
112
|
+
slashUnknownPenalty: bigint;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** The names of every per-offense penalty knob, in declaration order. */
|
|
116
|
+
const SLASHING_PENALTY_KEYS: (keyof SlashingPenalties)[] = [
|
|
117
|
+
'slashInactivityPenalty',
|
|
118
|
+
'slashDataWithholdingPenalty',
|
|
119
|
+
'slashBroadcastedInvalidBlockPenalty',
|
|
120
|
+
'slashBroadcastedInvalidCheckpointProposalPenalty',
|
|
121
|
+
'slashDuplicateProposalPenalty',
|
|
122
|
+
'slashDuplicateAttestationPenalty',
|
|
123
|
+
'slashProposeInvalidAttestationsPenalty',
|
|
124
|
+
'slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty',
|
|
125
|
+
'slashAttestInvalidCheckpointProposalPenalty',
|
|
126
|
+
'slashUnknownPenalty',
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Returns every per-offense slashing penalty set to `unit` (default `1e14` — small enough not to
|
|
131
|
+
* kick a validator out). Spread alongside the slashing-round/quorum config in a slashing test's
|
|
132
|
+
* `setup`.
|
|
133
|
+
*/
|
|
134
|
+
export function defaultSlashingPenalties(unit: bigint = BigInt(1e14)): SlashingPenalties {
|
|
135
|
+
return Object.fromEntries(SLASHING_PENALTY_KEYS.map(key => [key, unit])) as SlashingPenalties;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns the penalties with only `offense` set to `unit` and every other offense zeroed out, so a
|
|
140
|
+
* test isolates a single slashing offense. Names the test's intent (which offense is under test) and
|
|
141
|
+
* replaces the ~9-line manual zero-out block.
|
|
142
|
+
*/
|
|
143
|
+
export function withOnlyOffense(offense: keyof SlashingPenalties, unit: bigint = BigInt(1e14)): SlashingPenalties {
|
|
144
|
+
return Object.fromEntries(SLASHING_PENALTY_KEYS.map(key => [key, key === offense ? unit : 0n])) as SlashingPenalties;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** One HA pair: its two member nodes, the two shared validator keys, and the per-node coinbases. */
|
|
148
|
+
export type HaPairNodes = {
|
|
149
|
+
nodes: [AztecNodeService, AztecNodeService];
|
|
150
|
+
privateKeys: [`0x${string}`, `0x${string}`];
|
|
151
|
+
coinbases: [EthAddress, EthAddress];
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Stands up two HA pairs from the first four registered validators: nodes[0]/nodes[1] share keys
|
|
156
|
+
* pk1+pk2, nodes[2]/nodes[3] share pk3+pk4. Each pair shares an in-memory slashing-protection DB (so
|
|
157
|
+
* only one peer signs per duty) and each node gets a distinct coinbase. Encapsulates the ~40-line
|
|
158
|
+
* pair-wiring duplicated by both HA tests; the per-test divergence (publishing disabled vs. enabled,
|
|
159
|
+
* empty-checkpoint building) is passed through `baseOpts`.
|
|
160
|
+
* @returns The four nodes flat, plus the two `HaPairNodes` descriptors.
|
|
161
|
+
*/
|
|
162
|
+
export async function setupHaPairs(
|
|
163
|
+
test: MultiNodeTestContext,
|
|
164
|
+
validators: RegisteredValidator[],
|
|
165
|
+
opts: { baseOpts?: Partial<AztecNodeConfig> & { dontStartSequencer?: boolean }; coinbases?: EthAddress[] } = {},
|
|
166
|
+
): Promise<{ nodes: AztecNodeService[]; pairs: [HaPairNodes, HaPairNodes] }> {
|
|
167
|
+
const baseOpts = opts.baseOpts ?? {};
|
|
168
|
+
const coinbases = opts.coinbases ?? [1, 2, 3, 4].map(n => EthAddress.fromNumber(n));
|
|
169
|
+
const [pk1, pk2, pk3, pk4] = validators.map(v => v.privateKey);
|
|
170
|
+
const sharedDb1 = await createSharedSlashingProtectionDb(test.context.dateProvider);
|
|
171
|
+
const sharedDb2 = await createSharedSlashingProtectionDb(test.context.dateProvider);
|
|
172
|
+
|
|
173
|
+
const nodes = [
|
|
174
|
+
await test.createValidatorNode([pk1, pk2], {
|
|
175
|
+
...baseOpts,
|
|
176
|
+
coinbase: coinbases[0],
|
|
177
|
+
slashingProtectionDb: sharedDb1,
|
|
178
|
+
}),
|
|
179
|
+
await test.createValidatorNode([pk1, pk2], {
|
|
180
|
+
...baseOpts,
|
|
181
|
+
coinbase: coinbases[1],
|
|
182
|
+
slashingProtectionDb: sharedDb1,
|
|
183
|
+
}),
|
|
184
|
+
await test.createValidatorNode([pk3, pk4], {
|
|
185
|
+
...baseOpts,
|
|
186
|
+
coinbase: coinbases[2],
|
|
187
|
+
slashingProtectionDb: sharedDb2,
|
|
188
|
+
}),
|
|
189
|
+
await test.createValidatorNode([pk3, pk4], {
|
|
190
|
+
...baseOpts,
|
|
191
|
+
coinbase: coinbases[3],
|
|
192
|
+
slashingProtectionDb: sharedDb2,
|
|
193
|
+
}),
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
const pairs: [HaPairNodes, HaPairNodes] = [
|
|
197
|
+
{ nodes: [nodes[0], nodes[1]], privateKeys: [pk1, pk2], coinbases: [coinbases[0], coinbases[1]] },
|
|
198
|
+
{ nodes: [nodes[2], nodes[3]], privateKeys: [pk3, pk4], coinbases: [coinbases[2], coinbases[3]] },
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
return { nodes, pairs };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Multi-validator test base: N validator nodes sharing the in-memory `MockGossipSubNetwork` bus, with
|
|
206
|
+
* fast block times and short epochs. Extends {@link SingleNodeTestContext} with validator-node
|
|
207
|
+
* spawning and the convergence helpers (`waitForAllNodes*`, `findSlotsWithProposers`) that only make
|
|
208
|
+
* sense across a committee. The environment, prover lifecycle, and reorg/proving waiters live on the
|
|
209
|
+
* parent so the single-node-topology tests share them.
|
|
210
|
+
*/
|
|
211
|
+
export class MultiNodeTestContext extends SingleNodeTestContext {
|
|
212
|
+
/**
|
|
213
|
+
* The validators registered on-chain at genesis (from `opts.initialValidators`). Tests spawn nodes
|
|
214
|
+
* for whichever validators they want online via {@link createValidatorNodeAt}; the rest stay
|
|
215
|
+
* registered-but-offline. Empty for single-validator-less topologies.
|
|
216
|
+
*/
|
|
217
|
+
public validators: RegisteredValidator[] = [];
|
|
218
|
+
|
|
219
|
+
public override async setup(opts: MultiNodeTestOpts = {}) {
|
|
220
|
+
this.validators = (opts.initialValidators as RegisteredValidator[] | undefined) ?? [];
|
|
221
|
+
await super.setup(opts);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public createValidatorNode(
|
|
225
|
+
privateKeys: `0x${string}`[],
|
|
226
|
+
opts: Partial<AztecNodeConfig> & {
|
|
227
|
+
dontStartSequencer?: boolean;
|
|
228
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
229
|
+
} = {},
|
|
230
|
+
) {
|
|
231
|
+
this.logger.warn('Creating and syncing a validator node...');
|
|
232
|
+
return this.createNode({ ...opts, disableValidator: false, validatorPrivateKeys: new SecretValue(privateKeys) });
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Returns the validator registered at on-chain index `index` (0-based into {@link validators}). */
|
|
236
|
+
public validatorAt(index: number): RegisteredValidator {
|
|
237
|
+
return this.validators[index];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** The L1 attester address of the validator registered at `index`. */
|
|
241
|
+
public addressAt(index: number): EthAddress {
|
|
242
|
+
return this.validators[index].attester;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** The L1 signing key of the validator registered at `index`. */
|
|
246
|
+
public privateKeyAt(index: number): `0x${string}` {
|
|
247
|
+
return this.validators[index].privateKey;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Spawns a validator node on the mock-gossip bus signing with the validator registered at `index`.
|
|
252
|
+
* Pass the same `index` to two calls (with different `coinbase`) to model an equivocating proposer
|
|
253
|
+
* that shares a key across two nodes.
|
|
254
|
+
*/
|
|
255
|
+
public createValidatorNodeAt(
|
|
256
|
+
index: number,
|
|
257
|
+
opts: Partial<AztecNodeConfig> & { dontStartSequencer?: boolean } = {},
|
|
258
|
+
): Promise<AztecNodeService> {
|
|
259
|
+
return this.createValidatorNode([this.privateKeyAt(index)], opts);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Resolves the rollup, slasher, and slashing-proposer L1 contracts a slashing test interacts with. */
|
|
263
|
+
public async getSlashingContracts(): Promise<SlashingContracts> {
|
|
264
|
+
const rollup = this.rollup;
|
|
265
|
+
const slasherContract = getContract({
|
|
266
|
+
address: getAddress((await rollup.getSlasherAddress()).toString()),
|
|
267
|
+
abi: SlasherAbi,
|
|
268
|
+
client: this.l1Client,
|
|
269
|
+
});
|
|
270
|
+
const slashingProposer = await rollup.getSlashingProposer();
|
|
271
|
+
return { rollup, slasherContract, slashingProposer };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Polls every node until `predicate(tips, node)` holds for all of them. The multi-node
|
|
276
|
+
* generalization of {@link SingleNodeTestContext.waitForNodeToSync} — replaces hand-rolled
|
|
277
|
+
* `Promise.all(this.nodes.map(node => retryUntil(...)))` fan-out blocks.
|
|
278
|
+
* @param nodes - Nodes to poll; defaults to all validator nodes (`this.nodes`).
|
|
279
|
+
*/
|
|
280
|
+
public async waitForAllNodes(
|
|
281
|
+
predicate: (tips: L2Tips, node: AztecNode) => boolean | Promise<boolean>,
|
|
282
|
+
opts: { nodes?: AztecNode[]; timeout?: number; interval?: number; description?: string } = {},
|
|
283
|
+
): Promise<void> {
|
|
284
|
+
const nodes = opts.nodes ?? this.nodes;
|
|
285
|
+
const timeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 4;
|
|
286
|
+
const interval = opts.interval ?? 0.5;
|
|
287
|
+
const description = opts.description ?? 'all nodes to reach target';
|
|
288
|
+
await Promise.all(
|
|
289
|
+
nodes.map((node, idx) =>
|
|
290
|
+
retryUntil(
|
|
291
|
+
async () => {
|
|
292
|
+
const tips = await node.getChainTips();
|
|
293
|
+
return (await predicate(tips, node)) || undefined;
|
|
294
|
+
},
|
|
295
|
+
`node ${idx} ${description}`,
|
|
296
|
+
timeout,
|
|
297
|
+
interval,
|
|
298
|
+
),
|
|
299
|
+
),
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Waits until every node's proven checkpoint tip reaches `target`. */
|
|
304
|
+
public waitForAllNodesToReachProvenCheckpoint(
|
|
305
|
+
target: CheckpointNumber,
|
|
306
|
+
opts: { nodes?: AztecNode[]; timeout?: number; interval?: number } = {},
|
|
307
|
+
): Promise<void> {
|
|
308
|
+
return testSpan('wait:proven-checkpoint', () =>
|
|
309
|
+
this.waitForAllNodes(tips => tips.proven.checkpoint.number >= target, {
|
|
310
|
+
...opts,
|
|
311
|
+
description: `proven checkpoint >= ${target}`,
|
|
312
|
+
}),
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Waits until every node's checkpointed checkpoint tip reaches `target`. */
|
|
317
|
+
public waitForAllNodesToReachCheckpoint(
|
|
318
|
+
target: CheckpointNumber,
|
|
319
|
+
opts: { nodes?: AztecNode[]; timeout?: number; interval?: number } = {},
|
|
320
|
+
): Promise<void> {
|
|
321
|
+
return testSpan('wait:checkpoint', () =>
|
|
322
|
+
this.waitForAllNodes(tips => tips.checkpointed.checkpoint.number >= target, {
|
|
323
|
+
...opts,
|
|
324
|
+
description: `checkpointed checkpoint >= ${target}`,
|
|
325
|
+
}),
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Waits until every node's `proposed` or `checkpointed` tip points at a block whose slot
|
|
331
|
+
* satisfies `match` (defaults to "slot equals `slot`"). Polls the block referenced by the tip.
|
|
332
|
+
*/
|
|
333
|
+
public waitForAllNodesToReachBlockAtSlot(
|
|
334
|
+
slot: SlotNumber,
|
|
335
|
+
tag: 'proposed' | 'checkpointed',
|
|
336
|
+
match: (block: BlockResponse) => boolean = block => block.header.globalVariables.slotNumber === slot,
|
|
337
|
+
opts: { nodes?: AztecNode[]; timeout?: number; interval?: number } = {},
|
|
338
|
+
): Promise<void> {
|
|
339
|
+
return testSpan('wait:block', () =>
|
|
340
|
+
this.waitForAllNodes(
|
|
341
|
+
async (tips, node) => {
|
|
342
|
+
const blockNumber = tag === 'proposed' ? tips.proposed.number : tips.checkpointed.block.number;
|
|
343
|
+
if (blockNumber === 0) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
const block = await node.getBlock(blockNumber);
|
|
347
|
+
return !!block && match(block);
|
|
348
|
+
},
|
|
349
|
+
{ ...opts, description: `${tag} block at slot ${slot}` },
|
|
350
|
+
),
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Finds `count` consecutive slots (starting from `opts.fromSlot` or the current slot plus a
|
|
356
|
+
* margin) whose proposers satisfy `predicate`, warping the L1 clock forward one epoch and
|
|
357
|
+
* retrying when the rollup reports `ValidatorSelection__EpochNotStable` for a future epoch.
|
|
358
|
+
* Returns the matched slots and their proposer addresses. Encapsulates the slot-search loop
|
|
359
|
+
* duplicated across the multi-validator tests.
|
|
360
|
+
*/
|
|
361
|
+
public findSlotsWithProposers(
|
|
362
|
+
count: number,
|
|
363
|
+
predicate: (proposers: EthAddress[]) => boolean,
|
|
364
|
+
opts: { fromSlot?: SlotNumber; margin?: number; maxAttempts?: number } = {},
|
|
365
|
+
): Promise<{ slots: SlotNumber[]; proposers: EthAddress[] }> {
|
|
366
|
+
return testSpan('warp:find-proposer', async () => {
|
|
367
|
+
const margin = opts.margin ?? 4;
|
|
368
|
+
const maxAttempts = opts.maxAttempts ?? 200;
|
|
369
|
+
let candidate = opts.fromSlot ?? SlotNumber(Number(this.epochCache.getEpochAndSlotNow().slot) + margin);
|
|
370
|
+
|
|
371
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
372
|
+
try {
|
|
373
|
+
const slots = Array.from({ length: count }, (_, i) => SlotNumber(candidate + i));
|
|
374
|
+
const maybeProposers = await Promise.all(
|
|
375
|
+
slots.map(slot => this.epochCache.getProposerAttesterAddressInSlot(slot)),
|
|
376
|
+
);
|
|
377
|
+
if (maybeProposers.every((p): p is EthAddress => p !== undefined) && predicate(maybeProposers)) {
|
|
378
|
+
return { slots, proposers: maybeProposers };
|
|
379
|
+
}
|
|
380
|
+
candidate = SlotNumber(candidate + 1);
|
|
381
|
+
} catch (err) {
|
|
382
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
383
|
+
if (!msg.includes('EpochNotStable')) {
|
|
384
|
+
throw err;
|
|
385
|
+
}
|
|
386
|
+
const block = await this.l1Client.getBlock({ includeTransactions: false });
|
|
387
|
+
const warpBy = this.epochDuration * this.L2_SLOT_DURATION_IN_S;
|
|
388
|
+
const newTs = Number(block.timestamp) + warpBy;
|
|
389
|
+
this.logger.warn(
|
|
390
|
+
`Hit EpochNotStable at candidate ${candidate}, warping L1 forward by ${warpBy}s to ${newTs}`,
|
|
391
|
+
);
|
|
392
|
+
await this.context.cheatCodes.eth.warp(newTs, { resetBlockInterval: true });
|
|
393
|
+
const newCurrentSlot = Number(this.epochCache.getEpochAndSlotNow().slot);
|
|
394
|
+
if (candidate < newCurrentSlot + margin) {
|
|
395
|
+
candidate = SlotNumber(newCurrentSlot + margin);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
throw new Error(
|
|
400
|
+
`Could not find ${count} consecutive slots matching the proposer predicate after ${maxAttempts} attempts`,
|
|
401
|
+
);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Watches the sequencers of `nodes` via {@link SingleNodeTestContext.watchSequencerEvents}, pulling
|
|
407
|
+
* the {@link SequencerClient} off each node first. `getMetadata` tags each captured event; it
|
|
408
|
+
* defaults to `{ validator: this.validators[i].attester }`. Pass an override for tests that label
|
|
409
|
+
* their nodes differently (e.g. `['A','B','C'][i]`).
|
|
410
|
+
*/
|
|
411
|
+
public watchNodeSequencerEvents(
|
|
412
|
+
nodes: AztecNodeService[],
|
|
413
|
+
getMetadata: (i: number) => Record<string, any> = i => ({ validator: this.validators[i].attester }),
|
|
414
|
+
): { failEvents: TrackedSequencerEvent[]; stateChanges: TrackedSequencerEvent[] } {
|
|
415
|
+
return this.watchSequencerEvents(this.getSequencers(nodes), getMetadata);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Waits until matching slash offenses have converged across `nodes`, polling `getSlashOffenses`.
|
|
420
|
+
* With `opts.mode === 'all'` (the default) every node must record a matching offense; with `'any'`
|
|
421
|
+
* a single node suffices. Resolves with all matching offenses collected across the polled nodes.
|
|
422
|
+
*/
|
|
423
|
+
public waitForOffenseOnNodes(
|
|
424
|
+
nodes: AztecNodeService[],
|
|
425
|
+
match: (offense: Offense) => boolean,
|
|
426
|
+
opts: { mode?: 'all' | 'any'; timeout?: number; interval?: number } = {},
|
|
427
|
+
): Promise<Offense[]> {
|
|
428
|
+
const mode = opts.mode ?? 'all';
|
|
429
|
+
const timeout = opts.timeout ?? this.L2_SLOT_DURATION_IN_S * 4;
|
|
430
|
+
const interval = opts.interval ?? 0.5;
|
|
431
|
+
return testSpan('wait:offense', () =>
|
|
432
|
+
retryUntil(
|
|
433
|
+
async () => {
|
|
434
|
+
const perNode = await Promise.all(
|
|
435
|
+
nodes.map(node => node.getSlashOffenses('all').then(os => os.filter(match))),
|
|
436
|
+
);
|
|
437
|
+
const converged =
|
|
438
|
+
mode === 'all' ? perNode.every(matches => matches.length > 0) : perNode.some(m => m.length > 0);
|
|
439
|
+
return converged ? perNode.flat() : undefined;
|
|
440
|
+
},
|
|
441
|
+
`offense on ${mode} node(s)`,
|
|
442
|
+
timeout,
|
|
443
|
+
interval,
|
|
444
|
+
),
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { AztecNodeService } from '@aztec/aztec-node';
|
|
2
|
+
import type { EthAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
MultiNodeTestContext,
|
|
7
|
+
SLASHER_ENABLED_MULTI_VALIDATOR_OPTS,
|
|
8
|
+
buildMockGossipValidators,
|
|
9
|
+
} from '../multi_node_test_context.js';
|
|
10
|
+
|
|
11
|
+
const NUM_NODES = 6;
|
|
12
|
+
const NUM_VALIDATORS = NUM_NODES;
|
|
13
|
+
const COMMITTEE_SIZE = NUM_VALIDATORS;
|
|
14
|
+
const SLASHING_QUORUM = 3;
|
|
15
|
+
const EPOCH_DURATION = 2;
|
|
16
|
+
const SLASHING_ROUND_SIZE_IN_EPOCHS = 2;
|
|
17
|
+
const ETHEREUM_SLOT_DURATION = process.env.CI ? 8 : 4;
|
|
18
|
+
const AZTEC_SLOT_DURATION = ETHEREUM_SLOT_DURATION * 2;
|
|
19
|
+
const SLASHING_UNIT = BigInt(1e18);
|
|
20
|
+
const SLASHING_AMOUNT = SLASHING_UNIT * 3n;
|
|
21
|
+
|
|
22
|
+
// How many epochs it may take to set everything up, so we dont slash during this period
|
|
23
|
+
const SETUP_EPOCH_DURATION = 8;
|
|
24
|
+
|
|
25
|
+
/** Stateful fixture for the inactivity-slash suites: a slasher-enabled committee on the mock-gossip bus. */
|
|
26
|
+
export class InactivityTest {
|
|
27
|
+
public test!: MultiNodeTestContext;
|
|
28
|
+
public nodes!: AztecNodeService[];
|
|
29
|
+
public activeNodes!: AztecNodeService[];
|
|
30
|
+
public inactiveNodes!: AztecNodeService[];
|
|
31
|
+
public offlineValidators!: EthAddress[];
|
|
32
|
+
|
|
33
|
+
private inactiveNodeCount: number;
|
|
34
|
+
|
|
35
|
+
constructor(opts: { inactiveNodeCount: number }) {
|
|
36
|
+
this.inactiveNodeCount = opts.inactiveNodeCount;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static async setup(opts: {
|
|
40
|
+
slashInactivityConsecutiveEpochThreshold: number;
|
|
41
|
+
inactiveNodeCount: number;
|
|
42
|
+
}): Promise<InactivityTest> {
|
|
43
|
+
const inactivityTest = new InactivityTest(opts);
|
|
44
|
+
await inactivityTest.run(opts);
|
|
45
|
+
return inactivityTest;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private async run(opts: { slashInactivityConsecutiveEpochThreshold: number; inactiveNodeCount: number }) {
|
|
49
|
+
this.test = await MultiNodeTestContext.setup({
|
|
50
|
+
...SLASHER_ENABLED_MULTI_VALIDATOR_OPTS,
|
|
51
|
+
inboxLag: 2,
|
|
52
|
+
anvilSlotsInAnEpoch: 4,
|
|
53
|
+
// A fake prover node is started by the context (realProofs:false); give it the multi-epoch
|
|
54
|
+
// proving delay the inactivity scenario relied on, and keep enough broker history.
|
|
55
|
+
proverNodeConfig: { proverNodeEpochProvingDelayMs: AZTEC_SLOT_DURATION * 1000 },
|
|
56
|
+
proverBrokerMaxEpochsToKeepResultsFor: 20,
|
|
57
|
+
aztecTargetCommitteeSize: COMMITTEE_SIZE,
|
|
58
|
+
aztecSlotDuration: AZTEC_SLOT_DURATION,
|
|
59
|
+
ethereumSlotDuration: ETHEREUM_SLOT_DURATION,
|
|
60
|
+
aztecProofSubmissionEpochs: 1024, // effectively do not reorg
|
|
61
|
+
listenAddress: '127.0.0.1',
|
|
62
|
+
minTxsPerBlock: 0,
|
|
63
|
+
aztecEpochDuration: EPOCH_DURATION,
|
|
64
|
+
sentinelEnabled: true,
|
|
65
|
+
slashingQuorum: SLASHING_QUORUM,
|
|
66
|
+
slashingRoundSizeInEpochs: SLASHING_ROUND_SIZE_IN_EPOCHS,
|
|
67
|
+
slashInactivityTargetPercentage: 0.8,
|
|
68
|
+
slashGracePeriodL2Slots: SETUP_EPOCH_DURATION * EPOCH_DURATION, // do not slash during setup
|
|
69
|
+
slashAmountSmall: SLASHING_UNIT,
|
|
70
|
+
slashAmountMedium: SLASHING_UNIT * 2n,
|
|
71
|
+
slashAmountLarge: SLASHING_UNIT * 3n,
|
|
72
|
+
slashInactivityConsecutiveEpochThreshold: opts.slashInactivityConsecutiveEpochThreshold,
|
|
73
|
+
slashInactivityPenalty: SLASHING_AMOUNT,
|
|
74
|
+
initialValidators: buildMockGossipValidators(NUM_VALIDATORS),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const { rollup } = await this.test.getSlashingContracts();
|
|
78
|
+
const [activationThreshold, ejectionThreshold, localEjectionThreshold] = await Promise.all([
|
|
79
|
+
rollup.getActivationThreshold(),
|
|
80
|
+
rollup.getEjectionThreshold(),
|
|
81
|
+
rollup.getLocalEjectionThreshold(),
|
|
82
|
+
]);
|
|
83
|
+
const biggestEjection = ejectionThreshold > localEjectionThreshold ? ejectionThreshold : localEjectionThreshold;
|
|
84
|
+
expect(activationThreshold - SLASHING_AMOUNT).toBeLessThan(biggestEjection);
|
|
85
|
+
|
|
86
|
+
// Create all active nodes (running sequencer) plus the inactive ones (sequencer disabled).
|
|
87
|
+
const activeCount = NUM_NODES - this.inactiveNodeCount;
|
|
88
|
+
this.activeNodes = await Promise.all(
|
|
89
|
+
Array.from({ length: activeCount }, (_, i) => this.test.createValidatorNodeAt(i)),
|
|
90
|
+
);
|
|
91
|
+
this.inactiveNodes = await Promise.all(
|
|
92
|
+
Array.from({ length: this.inactiveNodeCount }, (_, i) =>
|
|
93
|
+
this.test.createValidatorNodeAt(activeCount + i, { dontStartSequencer: true }),
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
this.nodes = [...this.activeNodes, ...this.inactiveNodes];
|
|
98
|
+
|
|
99
|
+
if (this.nodes.length !== NUM_NODES) {
|
|
100
|
+
throw new Error(`Expected ${NUM_NODES} nodes but got ${this.nodes.length}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.offlineValidators = this.test.validators
|
|
104
|
+
.slice(this.test.validators.length - this.inactiveNodeCount)
|
|
105
|
+
.map(v => v.attester);
|
|
106
|
+
|
|
107
|
+
this.test.logger.warn(`Setup complete. Offline validators are ${this.offlineValidators.join(', ')}.`, {
|
|
108
|
+
validators: this.test.validators,
|
|
109
|
+
offlineValidators: this.offlineValidators,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
this.test.logger.warn(`Advancing to epoch ${SETUP_EPOCH_DURATION - 1} (slashing will start after it is completed)`);
|
|
113
|
+
await this.test.context.cheatCodes.rollup.advanceToEpoch(EpochNumber(SETUP_EPOCH_DURATION - 1));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public async teardown() {
|
|
117
|
+
await this.test.teardown();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public get rollup() {
|
|
121
|
+
return this.test.rollup;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public get logger() {
|
|
125
|
+
return this.test.logger;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public get config() {
|
|
129
|
+
return this.test.context.config;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public get monitor() {
|
|
133
|
+
return this.test.monitor;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public get slashingAmount() {
|
|
137
|
+
return SLASHING_AMOUNT;
|
|
138
|
+
}
|
|
139
|
+
}
|