@aztec/p2p 0.0.1-commit.f504929 → 0.0.1-commit.f5d02921e
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 +129 -3
- package/dest/client/factory.d.ts +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +25 -11
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +3 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +37 -36
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +17 -6
- package/dest/config.d.ts +24 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +66 -7
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +4 -4
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -5
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +9 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +25 -10
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +38 -11
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -43
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +21 -6
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
- package/dest/msg_validators/clock_tolerance.d.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +4 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +5 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +5 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +12 -9
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +51 -49
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +21 -32
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +23 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +36 -10
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +13 -4
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +39 -9
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +49 -2
- package/dest/services/dummy_service.d.ts +5 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +5 -1
- package/dest/services/encoding.d.ts +5 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -1
- package/dest/services/libp2p/libp2p_service.d.ts +14 -11
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +146 -74
- package/dest/services/peer-manager/peer_manager.d.ts +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +22 -8
- package/dest/services/peer-manager/peer_scoring.d.ts +5 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +28 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +69 -65
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +17 -9
- package/dest/services/service.d.ts +5 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +57 -73
- package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +39 -29
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.js +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +3 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.d.ts +6 -5
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +9 -7
- package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +22 -3
- package/dest/testbench/p2p_client_testbench_worker.js +46 -16
- package/dest/testbench/worker_client_manager.d.ts +3 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -3
- package/dest/util.d.ts +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +43 -14
- package/src/client/interface.ts +9 -1
- package/src/client/p2p_client.ts +39 -36
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
- package/src/config.ts +92 -4
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +7 -5
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/tx_pool_v2/README.md +9 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/interfaces.ts +9 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +59 -13
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +13 -1
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +23 -6
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
- package/src/msg_validators/clock_tolerance.ts +4 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +13 -3
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +19 -6
- package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -53
- package/src/msg_validators/tx_validator/README.md +5 -1
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +16 -35
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/factory.ts +43 -3
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +41 -8
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/phases_validator.ts +60 -1
- package/src/services/dummy_service.ts +7 -2
- package/src/services/encoding.ts +9 -1
- package/src/services/libp2p/libp2p_service.ts +147 -87
- package/src/services/peer-manager/peer_manager.ts +26 -8
- package/src/services/peer-manager/peer_scoring.ts +21 -5
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
- package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/reqresp.ts +19 -11
- package/src/services/service.ts +6 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +1 -1
- package/src/services/tx_collection/tx_collection.ts +3 -5
- package/src/services/tx_collection/tx_source.ts +8 -7
- package/src/test-helpers/make-test-p2p-clients.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/test-helpers/testbench-utils.ts +29 -3
- package/src/testbench/p2p_client_testbench_worker.ts +45 -15
- package/src/testbench/worker_client_manager.ts +13 -6
- package/src/util.ts +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -24
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -378
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
- package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -373
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import type { CheckpointProposal, P2PValidator } from '@aztec/stdlib/p2p';
|
|
2
|
+
import type { CheckpointProposal, P2PValidator, ValidationResult } from '@aztec/stdlib/p2p';
|
|
3
3
|
|
|
4
4
|
import { ProposalValidator } from '../proposal_validator/proposal_validator.js';
|
|
5
5
|
|
|
6
|
-
export class CheckpointProposalValidator
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{
|
|
6
|
+
export class CheckpointProposalValidator implements P2PValidator<CheckpointProposal> {
|
|
7
|
+
private proposalValidator: ProposalValidator;
|
|
8
|
+
|
|
10
9
|
constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean; maxTxsPerBlock?: number }) {
|
|
11
|
-
|
|
10
|
+
this.proposalValidator = new ProposalValidator(epochCache, opts, 'p2p:checkpoint_proposal_validator');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async validate(proposal: CheckpointProposal): Promise<ValidationResult> {
|
|
14
|
+
const headerResult = await this.proposalValidator.validate(proposal);
|
|
15
|
+
if (headerResult.result !== 'accept') {
|
|
16
|
+
return headerResult;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const blockProposal = proposal.getBlockProposal();
|
|
20
|
+
if (blockProposal) {
|
|
21
|
+
return this.proposalValidator.validateTxs(blockProposal);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { result: 'accept' };
|
|
12
25
|
}
|
|
13
26
|
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type BlockProposal,
|
|
6
|
+
type CheckpointProposalCore,
|
|
7
|
+
PeerErrorSeverity,
|
|
8
|
+
type ValidationResult,
|
|
9
|
+
} from '@aztec/stdlib/p2p';
|
|
5
10
|
|
|
6
11
|
import { isWithinClockTolerance } from '../clock_tolerance.js';
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
/** Validates header-level and tx-level fields of block and checkpoint proposals. */
|
|
14
|
+
export class ProposalValidator {
|
|
15
|
+
private epochCache: EpochCacheInterface;
|
|
16
|
+
private logger: Logger;
|
|
17
|
+
private txsPermitted: boolean;
|
|
18
|
+
private maxTxsPerBlock?: number;
|
|
13
19
|
|
|
14
20
|
constructor(
|
|
15
21
|
epochCache: EpochCacheInterface,
|
|
@@ -22,15 +28,17 @@ export abstract class ProposalValidator<TProposal extends BlockProposal | Checkp
|
|
|
22
28
|
this.logger = createLogger(loggerName);
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
/** Validates header-level fields: slot, signature, and proposer. */
|
|
32
|
+
public async validate(proposal: BlockProposal | CheckpointProposalCore): Promise<ValidationResult> {
|
|
26
33
|
try {
|
|
27
|
-
// Slot check
|
|
28
|
-
const {
|
|
34
|
+
// Slot check: use target slots since proposals target pipeline slots (slot + 1 when pipelining)
|
|
35
|
+
const { targetSlot, nextSlot } = this.epochCache.getTargetAndNextSlot();
|
|
36
|
+
|
|
29
37
|
const slotNumber = proposal.slotNumber;
|
|
30
|
-
if (slotNumber !==
|
|
38
|
+
if (slotNumber !== targetSlot && slotNumber !== nextSlot) {
|
|
31
39
|
// Check if message is for previous slot and within clock tolerance
|
|
32
|
-
if (!isWithinClockTolerance(slotNumber,
|
|
33
|
-
this.logger.warn(`Penalizing peer for invalid slot number ${slotNumber}`, {
|
|
40
|
+
if (!isWithinClockTolerance(slotNumber, targetSlot, this.epochCache)) {
|
|
41
|
+
this.logger.warn(`Penalizing peer for invalid slot number ${slotNumber}`, { targetSlot, nextSlot });
|
|
34
42
|
return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
|
|
35
43
|
}
|
|
36
44
|
this.logger.verbose(`Ignoring proposal for previous slot ${slotNumber} within clock tolerance`);
|
|
@@ -44,38 +52,6 @@ export abstract class ProposalValidator<TProposal extends BlockProposal | Checkp
|
|
|
44
52
|
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
// Transactions permitted check
|
|
48
|
-
const embeddedTxCount = proposal.txs?.length ?? 0;
|
|
49
|
-
if (!this.txsPermitted && (proposal.txHashes.length > 0 || embeddedTxCount > 0)) {
|
|
50
|
-
this.logger.warn(
|
|
51
|
-
`Penalizing peer for proposal with ${proposal.txHashes.length} transaction(s) when transactions are not permitted`,
|
|
52
|
-
);
|
|
53
|
-
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Max txs per block check
|
|
57
|
-
if (this.maxTxsPerBlock !== undefined && proposal.txHashes.length > this.maxTxsPerBlock) {
|
|
58
|
-
this.logger.warn(
|
|
59
|
-
`Penalizing peer for proposal with ${proposal.txHashes.length} transaction(s) when max is ${this.maxTxsPerBlock}`,
|
|
60
|
-
);
|
|
61
|
-
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Embedded txs must be listed in txHashes
|
|
65
|
-
const hashSet = new Set(proposal.txHashes.map(h => h.toString()));
|
|
66
|
-
const missingTxHashes =
|
|
67
|
-
embeddedTxCount > 0
|
|
68
|
-
? proposal.txs!.filter(tx => !hashSet.has(tx.getTxHash().toString())).map(tx => tx.getTxHash().toString())
|
|
69
|
-
: [];
|
|
70
|
-
if (embeddedTxCount > 0 && missingTxHashes.length > 0) {
|
|
71
|
-
this.logger.warn('Penalizing peer for embedded transaction(s) not included in txHashes', {
|
|
72
|
-
embeddedTxCount,
|
|
73
|
-
txHashesLength: proposal.txHashes.length,
|
|
74
|
-
missingTxHashes,
|
|
75
|
-
});
|
|
76
|
-
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
55
|
// Proposer check
|
|
80
56
|
const expectedProposer = await this.epochCache.getProposerAttesterAddressInSlot(slotNumber);
|
|
81
57
|
if (expectedProposer !== undefined && !proposer.equals(expectedProposer)) {
|
|
@@ -86,15 +62,6 @@ export abstract class ProposalValidator<TProposal extends BlockProposal | Checkp
|
|
|
86
62
|
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
87
63
|
}
|
|
88
64
|
|
|
89
|
-
// Validate tx hashes for all txs embedded in the proposal
|
|
90
|
-
if (!(await Promise.all(proposal.txs?.map(tx => tx.validateTxHash()) ?? [])).every(v => v)) {
|
|
91
|
-
this.logger.warn(`Penalizing peer for invalid tx hashes in proposal`, {
|
|
92
|
-
proposer,
|
|
93
|
-
slotNumber,
|
|
94
|
-
});
|
|
95
|
-
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
65
|
return { result: 'accept' };
|
|
99
66
|
} catch (e) {
|
|
100
67
|
if (e instanceof NoCommitteeError) {
|
|
@@ -103,4 +70,47 @@ export abstract class ProposalValidator<TProposal extends BlockProposal | Checkp
|
|
|
103
70
|
throw e;
|
|
104
71
|
}
|
|
105
72
|
}
|
|
73
|
+
|
|
74
|
+
/** Validates transaction-related fields of a block proposal. */
|
|
75
|
+
public async validateTxs(proposal: BlockProposal): Promise<ValidationResult> {
|
|
76
|
+
// Transactions permitted check
|
|
77
|
+
const embeddedTxCount = proposal.txs?.length ?? 0;
|
|
78
|
+
if (!this.txsPermitted && (proposal.txHashes.length > 0 || embeddedTxCount > 0)) {
|
|
79
|
+
this.logger.warn(
|
|
80
|
+
`Penalizing peer for proposal with ${proposal.txHashes.length} transaction(s) when transactions are not permitted`,
|
|
81
|
+
);
|
|
82
|
+
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Max txs per block check
|
|
86
|
+
if (this.maxTxsPerBlock !== undefined && proposal.txHashes.length > this.maxTxsPerBlock) {
|
|
87
|
+
this.logger.warn(
|
|
88
|
+
`Penalizing peer for proposal with ${proposal.txHashes.length} transaction(s) when max is ${this.maxTxsPerBlock}`,
|
|
89
|
+
);
|
|
90
|
+
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Embedded txs must be listed in txHashes
|
|
94
|
+
const hashSet = new Set(proposal.txHashes.map(h => h.toString()));
|
|
95
|
+
const missingTxHashes =
|
|
96
|
+
embeddedTxCount > 0
|
|
97
|
+
? proposal.txs!.filter(tx => !hashSet.has(tx.getTxHash().toString())).map(tx => tx.getTxHash().toString())
|
|
98
|
+
: [];
|
|
99
|
+
if (embeddedTxCount > 0 && missingTxHashes.length > 0) {
|
|
100
|
+
this.logger.warn('Penalizing peer for embedded transaction(s) not included in txHashes', {
|
|
101
|
+
embeddedTxCount,
|
|
102
|
+
txHashesLength: proposal.txHashes.length,
|
|
103
|
+
missingTxHashes,
|
|
104
|
+
});
|
|
105
|
+
return { result: 'reject', severity: PeerErrorSeverity.MidToleranceError };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Validate tx hashes for all txs embedded in the proposal
|
|
109
|
+
if (!(await Promise.all(proposal.txs?.map(tx => tx.validateTxHash()) ?? [])).every(v => v)) {
|
|
110
|
+
this.logger.warn(`Penalizing peer for invalid tx hashes in proposal`);
|
|
111
|
+
return { result: 'reject', severity: PeerErrorSeverity.LowToleranceError };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { result: 'accept' };
|
|
115
|
+
}
|
|
106
116
|
}
|
|
@@ -75,10 +75,12 @@ This validator is invoked on **every** transaction potentially entering the pend
|
|
|
75
75
|
- Startup hydration — revalidating persisted non-mined txs on node restart
|
|
76
76
|
|
|
77
77
|
Runs:
|
|
78
|
-
- DoubleSpend, BlockHeader, GasLimits, Timestamp
|
|
78
|
+
- DoubleSpend, BlockHeader, GasLimits, Timestamp, AllowedSetupCalls
|
|
79
79
|
|
|
80
80
|
Operates on `TxMetaData` (pre-built by the pool) rather than full `Tx` objects.
|
|
81
81
|
|
|
82
|
+
The `AllowedSetupCallsMetaValidator` checks a precomputed boolean flag (`TxMetaData.allowedSetupCalls`) rather than re-running the full `PhasesTxValidator`. This flag is computed by `createCheckAllowedSetupCalls` when the tx first enters the pool (via `addProtectedTxs` or startup hydration), so the pool migration validator can reject txs with disallowed setup calls without needing the full `Tx` object or its dependencies.
|
|
83
|
+
|
|
82
84
|
## Individual Validators
|
|
83
85
|
|
|
84
86
|
| Validator | What it checks | Benchmarked verification duration |
|
|
@@ -92,6 +94,7 @@ Operates on `TxMetaData` (pre-built by the pool) rather than full `Tx` objects.
|
|
|
92
94
|
| `GasTxValidator` | Gas limits are within bounds (delegates to `GasLimitsValidator`), max fee per gas meets current block fees, and fee payer has sufficient FeeJuice balance | 1.02 ms |
|
|
93
95
|
| `GasLimitsValidator` | Gas limits are >= fixed minimums and <= AVM max processable L2 gas. Used standalone in pool migration; also called internally by `GasTxValidator` | 3–10 us |
|
|
94
96
|
| `PhasesTxValidator` | Public function calls in setup phase are on the allow list | 10.12–13.12 us |
|
|
97
|
+
| `AllowedSetupCallsMetaValidator` | Checks the precomputed `allowedSetupCalls` flag on `TxMetaData`. Used in pool migration instead of the full `PhasesTxValidator` | — |
|
|
95
98
|
| `BlockHeaderTxValidator` | Transaction's anchor block hash exists in the archive tree | 98.88 us |
|
|
96
99
|
| `TxProofValidator` | Client proof verifies correctly | ~250ms |
|
|
97
100
|
|
|
@@ -108,6 +111,7 @@ Operates on `TxMetaData` (pre-built by the pool) rather than full `Tx` objects.
|
|
|
108
111
|
| Gas (balance + limits) | Stage 1 | Optional* | — | Yes | — |
|
|
109
112
|
| GasLimits (standalone) | — | — | — | — | Yes |
|
|
110
113
|
| Phases | Stage 1 | Yes | — | Yes | — |
|
|
114
|
+
| AllowedSetupCalls | — | — | — | — | Yes |
|
|
111
115
|
| BlockHeader | Stage 1 | Yes | — | Yes | Yes |
|
|
112
116
|
| Proof | Stage 2 | Optional** | Yes | — | — |
|
|
113
117
|
|
|
@@ -1,49 +1,30 @@
|
|
|
1
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
2
1
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { AuthRegistryArtifact } from '@aztec/protocol-contracts/auth-registry';
|
|
3
|
+
import { FeeJuiceArtifact } from '@aztec/protocol-contracts/fee-juice';
|
|
5
4
|
import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
|
|
6
5
|
|
|
6
|
+
import { buildAllowedElement } from './allowed_setup_helpers.js';
|
|
7
|
+
|
|
7
8
|
let defaultAllowedSetupFunctions: AllowedElement[] | undefined;
|
|
8
9
|
|
|
9
10
|
/** Returns the default list of functions allowed to run in the setup phase of a transaction. */
|
|
10
11
|
export async function getDefaultAllowedSetupFunctions(): Promise<AllowedElement[]> {
|
|
11
12
|
if (defaultAllowedSetupFunctions === undefined) {
|
|
12
|
-
|
|
13
|
-
const setAuthorizedInternalSelector = await FunctionSelector.fromSignature('_set_authorized((Field),Field,bool)');
|
|
14
|
-
const setAuthorizedSelector = await FunctionSelector.fromSignature('set_authorized(Field,bool)');
|
|
15
|
-
const increaseBalanceSelector = await FunctionSelector.fromSignature('_increase_public_balance((Field),u128)');
|
|
16
|
-
const transferInPublicSelector = await FunctionSelector.fromSignature(
|
|
17
|
-
'transfer_in_public((Field),(Field),u128,Field)',
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
defaultAllowedSetupFunctions = [
|
|
13
|
+
defaultAllowedSetupFunctions = await Promise.all([
|
|
21
14
|
// AuthRegistry: needed for authwit support via private path (set_authorized_private enqueues _set_authorized)
|
|
22
|
-
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
15
|
+
buildAllowedElement(AuthRegistryArtifact, { address: ProtocolContractAddress.AuthRegistry }, '_set_authorized', {
|
|
16
|
+
onlySelf: true,
|
|
17
|
+
rejectNullMsgSender: true,
|
|
18
|
+
}),
|
|
26
19
|
// AuthRegistry: needed for authwit support via public path (PublicFeePaymentMethod calls set_authorized directly)
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
20
|
+
buildAllowedElement(AuthRegistryArtifact, { address: ProtocolContractAddress.AuthRegistry }, 'set_authorized', {
|
|
21
|
+
rejectNullMsgSender: true,
|
|
22
|
+
}),
|
|
31
23
|
// FeeJuice: needed for claiming on the same tx as a spend (claim_and_end_setup enqueues this)
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// Token: needed for private transfers via FPC (transfer_to_public enqueues this)
|
|
37
|
-
{
|
|
38
|
-
classId: tokenClassId,
|
|
39
|
-
selector: increaseBalanceSelector,
|
|
40
|
-
},
|
|
41
|
-
// Token: needed for public transfers via FPC (fee_entrypoint_public enqueues this)
|
|
42
|
-
{
|
|
43
|
-
classId: tokenClassId,
|
|
44
|
-
selector: transferInPublicSelector,
|
|
45
|
-
},
|
|
46
|
-
];
|
|
24
|
+
buildAllowedElement(FeeJuiceArtifact, { address: ProtocolContractAddress.FeeJuice }, '_increase_public_balance', {
|
|
25
|
+
onlySelf: true,
|
|
26
|
+
}),
|
|
27
|
+
]);
|
|
47
28
|
}
|
|
48
29
|
return defaultAllowedSetupFunctions;
|
|
49
30
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { FunctionSelector, countArgumentsSize, getAllFunctionAbis } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Builds an AllowedElement from a contract artifact, deriving both the function selector
|
|
9
|
+
* and calldata length from the artifact instead of hardcoding signature strings.
|
|
10
|
+
*/
|
|
11
|
+
export async function buildAllowedElement(
|
|
12
|
+
artifact: ContractArtifact,
|
|
13
|
+
target: { address: AztecAddress } | { classId: Fr },
|
|
14
|
+
functionName: string,
|
|
15
|
+
opts?: { onlySelf?: boolean; rejectNullMsgSender?: boolean },
|
|
16
|
+
): Promise<AllowedElement> {
|
|
17
|
+
const allFunctions = getAllFunctionAbis(artifact);
|
|
18
|
+
const fn = allFunctions.find(f => f.name === functionName);
|
|
19
|
+
if (!fn) {
|
|
20
|
+
throw new Error(`Unknown function ${functionName} in artifact ${artifact.name}`);
|
|
21
|
+
}
|
|
22
|
+
const selector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
23
|
+
const calldataLength = 1 + countArgumentsSize(fn);
|
|
24
|
+
return {
|
|
25
|
+
...target,
|
|
26
|
+
selector,
|
|
27
|
+
calldataLength,
|
|
28
|
+
...(opts?.onlySelf ? { onlySelf: true } : {}),
|
|
29
|
+
...(opts?.rejectNullMsgSender ? { rejectNullMsgSender: true } : {}),
|
|
30
|
+
} as AllowedElement;
|
|
31
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
3
|
+
import { computeContractAddressFromInstance } from '@aztec/stdlib/contract';
|
|
4
|
+
import {
|
|
5
|
+
TX_ERROR_INCORRECT_CONTRACT_ADDRESS,
|
|
6
|
+
TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG,
|
|
7
|
+
type Tx,
|
|
8
|
+
type TxValidationResult,
|
|
9
|
+
type TxValidator,
|
|
10
|
+
} from '@aztec/stdlib/tx';
|
|
11
|
+
|
|
12
|
+
/** Validates that contract instance deployment logs contain correct addresses. */
|
|
13
|
+
export class ContractInstanceTxValidator implements TxValidator<Tx> {
|
|
14
|
+
#log: Logger;
|
|
15
|
+
|
|
16
|
+
constructor(bindings?: LoggerBindings) {
|
|
17
|
+
this.#log = createLogger('p2p:tx_validator:contract_instance', bindings);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
21
|
+
const reason = await this.#hasCorrectContractInstanceAddresses(tx);
|
|
22
|
+
return reason ? { result: 'invalid', reason: [reason] } : { result: 'valid' };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async #hasCorrectContractInstanceAddresses(tx: Tx): Promise<string | undefined> {
|
|
26
|
+
const privateLogs = tx.data.getNonEmptyPrivateLogs();
|
|
27
|
+
for (const log of privateLogs) {
|
|
28
|
+
if (!ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let event;
|
|
33
|
+
try {
|
|
34
|
+
event = ContractInstancePublishedEvent.fromLog(log);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to parse contract instance event: ${e}`);
|
|
37
|
+
return TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const instance = event.toContractInstance();
|
|
42
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
43
|
+
if (!computedAddress.equals(instance.address)) {
|
|
44
|
+
this.#log.warn(
|
|
45
|
+
`Rejecting tx ${tx.getTxHash()}: contract instance address mismatch. Claimed ${instance.address}, computed ${computedAddress}`,
|
|
46
|
+
);
|
|
47
|
+
return TX_ERROR_INCORRECT_CONTRACT_ADDRESS;
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to compute contract instance address: ${e}`);
|
|
51
|
+
return TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS } from '@aztec/constants';
|
|
2
2
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
4
|
+
import { computeContractClassId } from '@aztec/stdlib/contract';
|
|
3
5
|
import { computeCalldataHash } from '@aztec/stdlib/hash';
|
|
4
6
|
import {
|
|
5
7
|
TX_ERROR_CALLDATA_COUNT_MISMATCH,
|
|
@@ -9,7 +11,9 @@ import {
|
|
|
9
11
|
TX_ERROR_CONTRACT_CLASS_LOG_LENGTH,
|
|
10
12
|
TX_ERROR_CONTRACT_CLASS_LOG_SORTING,
|
|
11
13
|
TX_ERROR_INCORRECT_CALLDATA,
|
|
14
|
+
TX_ERROR_INCORRECT_CONTRACT_CLASS_ID,
|
|
12
15
|
TX_ERROR_INCORRECT_HASH,
|
|
16
|
+
TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG,
|
|
13
17
|
Tx,
|
|
14
18
|
type TxValidationResult,
|
|
15
19
|
type TxValidator,
|
|
@@ -26,7 +30,8 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
26
30
|
const reason =
|
|
27
31
|
(await this.#hasCorrectHash(tx)) ??
|
|
28
32
|
(await this.#hasCorrectCalldata(tx)) ??
|
|
29
|
-
(await this.#hasCorrectContractClassLogs(tx))
|
|
33
|
+
(await this.#hasCorrectContractClassLogs(tx)) ??
|
|
34
|
+
(await this.#hasCorrectContractClassIds(tx));
|
|
30
35
|
return reason ? { result: 'invalid', reason: [reason] } : { result: 'valid' };
|
|
31
36
|
}
|
|
32
37
|
|
|
@@ -127,4 +132,40 @@ export class DataTxValidator implements TxValidator<Tx> {
|
|
|
127
132
|
|
|
128
133
|
return undefined;
|
|
129
134
|
}
|
|
135
|
+
|
|
136
|
+
async #hasCorrectContractClassIds(tx: Tx): Promise<string | undefined> {
|
|
137
|
+
const contractClassLogs = tx.getContractClassLogs();
|
|
138
|
+
for (const log of contractClassLogs) {
|
|
139
|
+
if (!ContractClassPublishedEvent.isContractClassPublishedEvent(log)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let event;
|
|
144
|
+
try {
|
|
145
|
+
event = ContractClassPublishedEvent.fromLog(log);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to parse contract class event: ${e}`);
|
|
148
|
+
return TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
const { publicBytecodeCommitment } = await event.toContractClassPublicWithBytecodeCommitment();
|
|
153
|
+
const computedClassId = await computeContractClassId({
|
|
154
|
+
artifactHash: event.artifactHash,
|
|
155
|
+
privateFunctionsRoot: event.privateFunctionsRoot,
|
|
156
|
+
publicBytecodeCommitment,
|
|
157
|
+
});
|
|
158
|
+
if (!computedClassId.equals(event.contractClassId)) {
|
|
159
|
+
this.#log.warn(
|
|
160
|
+
`Rejecting tx ${tx.getTxHash()}: contract class id mismatch. Claimed ${event.contractClassId}, computed ${computedClassId}`,
|
|
161
|
+
);
|
|
162
|
+
return TX_ERROR_INCORRECT_CONTRACT_CLASS_ID;
|
|
163
|
+
}
|
|
164
|
+
} catch (e) {
|
|
165
|
+
this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to compute contract class id: ${e}`);
|
|
166
|
+
return TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
130
171
|
}
|
|
@@ -53,12 +53,13 @@ import type { TxMetaData } from '../../mem_pools/tx_pool_v2/tx_metadata.js';
|
|
|
53
53
|
import { AggregateTxValidator } from './aggregate_tx_validator.js';
|
|
54
54
|
import { ArchiveCache } from './archive_cache.js';
|
|
55
55
|
import { type ArchiveSource, BlockHeaderTxValidator } from './block_header_validator.js';
|
|
56
|
+
import { ContractInstanceTxValidator } from './contract_instance_validator.js';
|
|
56
57
|
import { DataTxValidator } from './data_validator.js';
|
|
57
58
|
import { DoubleSpendTxValidator, type NullifierSource } from './double_spend_validator.js';
|
|
58
59
|
import { GasLimitsValidator, GasTxValidator } from './gas_validator.js';
|
|
59
60
|
import { MetadataTxValidator } from './metadata_validator.js';
|
|
60
61
|
import { NullifierCache } from './nullifier_cache.js';
|
|
61
|
-
import { PhasesTxValidator } from './phases_validator.js';
|
|
62
|
+
import { AllowedSetupCallsMetaValidator, PhasesTxValidator } from './phases_validator.js';
|
|
62
63
|
import { SizeTxValidator } from './size_validator.js';
|
|
63
64
|
import { TimestampTxValidator } from './timestamp_validator.js';
|
|
64
65
|
import { TxPermittedValidator } from './tx_permitted_validator.js';
|
|
@@ -97,6 +98,7 @@ export function createFirstStageTxValidationsForGossipedTransactions(
|
|
|
97
98
|
txsPermitted: boolean,
|
|
98
99
|
allowedInSetup: AllowedElement[] = [],
|
|
99
100
|
bindings?: LoggerBindings,
|
|
101
|
+
gasLimitOpts?: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number },
|
|
100
102
|
): Record<string, TransactionValidator> {
|
|
101
103
|
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
102
104
|
|
|
@@ -158,6 +160,7 @@ export function createFirstStageTxValidationsForGossipedTransactions(
|
|
|
158
160
|
ProtocolContractAddress.FeeJuice,
|
|
159
161
|
gasFees,
|
|
160
162
|
bindings,
|
|
163
|
+
gasLimitOpts,
|
|
161
164
|
),
|
|
162
165
|
severity: PeerErrorSeverity.MidToleranceError,
|
|
163
166
|
},
|
|
@@ -165,6 +168,10 @@ export function createFirstStageTxValidationsForGossipedTransactions(
|
|
|
165
168
|
validator: new DataTxValidator(bindings),
|
|
166
169
|
severity: PeerErrorSeverity.MidToleranceError,
|
|
167
170
|
},
|
|
171
|
+
contractInstanceValidator: {
|
|
172
|
+
validator: new ContractInstanceTxValidator(bindings),
|
|
173
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
174
|
+
},
|
|
168
175
|
};
|
|
169
176
|
}
|
|
170
177
|
|
|
@@ -216,6 +223,7 @@ function createTxValidatorForMinimumTxIntegrityChecks(
|
|
|
216
223
|
),
|
|
217
224
|
new SizeTxValidator(bindings),
|
|
218
225
|
new DataTxValidator(bindings),
|
|
226
|
+
new ContractInstanceTxValidator(bindings),
|
|
219
227
|
new TxProofValidator(verifier, bindings),
|
|
220
228
|
);
|
|
221
229
|
}
|
|
@@ -278,6 +286,9 @@ export function createTxValidatorForAcceptingTxsOverRPC(
|
|
|
278
286
|
timestamp,
|
|
279
287
|
blockNumber,
|
|
280
288
|
txsPermitted,
|
|
289
|
+
rollupManaLimit,
|
|
290
|
+
maxBlockL2Gas,
|
|
291
|
+
maxBlockDAGas,
|
|
281
292
|
}: {
|
|
282
293
|
l1ChainId: number;
|
|
283
294
|
rollupVersion: number;
|
|
@@ -287,6 +298,9 @@ export function createTxValidatorForAcceptingTxsOverRPC(
|
|
|
287
298
|
timestamp: UInt64;
|
|
288
299
|
blockNumber: BlockNumber;
|
|
289
300
|
txsPermitted: boolean;
|
|
301
|
+
rollupManaLimit: number;
|
|
302
|
+
maxBlockL2Gas?: number;
|
|
303
|
+
maxBlockDAGas?: number;
|
|
290
304
|
},
|
|
291
305
|
bindings?: LoggerBindings,
|
|
292
306
|
): TxValidator<Tx> {
|
|
@@ -313,11 +327,16 @@ export function createTxValidatorForAcceptingTxsOverRPC(
|
|
|
313
327
|
new BlockHeaderTxValidator(new ArchiveCache(db), bindings),
|
|
314
328
|
new DoubleSpendTxValidator(new NullifierCache(db), bindings),
|
|
315
329
|
new DataTxValidator(bindings),
|
|
330
|
+
new ContractInstanceTxValidator(bindings),
|
|
316
331
|
];
|
|
317
332
|
|
|
318
333
|
if (!skipFeeEnforcement) {
|
|
319
334
|
validators.push(
|
|
320
|
-
new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees, bindings
|
|
335
|
+
new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees, bindings, {
|
|
336
|
+
rollupManaLimit,
|
|
337
|
+
maxBlockL2Gas,
|
|
338
|
+
maxBlockDAGas,
|
|
339
|
+
}),
|
|
321
340
|
);
|
|
322
341
|
}
|
|
323
342
|
|
|
@@ -403,6 +422,7 @@ export async function createTxValidatorForTransactionsEnteringPendingTxPool(
|
|
|
403
422
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
404
423
|
timestamp: bigint,
|
|
405
424
|
blockNumber: BlockNumber,
|
|
425
|
+
gasLimitOpts: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number },
|
|
406
426
|
bindings?: LoggerBindings,
|
|
407
427
|
): Promise<TxValidator<TxMetaData>> {
|
|
408
428
|
await worldStateSynchronizer.syncImmediate();
|
|
@@ -419,9 +439,29 @@ export async function createTxValidatorForTransactionsEnteringPendingTxPool(
|
|
|
419
439
|
},
|
|
420
440
|
};
|
|
421
441
|
return new AggregateTxValidator<TxMetaData>(
|
|
422
|
-
new GasLimitsValidator<TxMetaData>(bindings),
|
|
442
|
+
new GasLimitsValidator<TxMetaData>({ ...gasLimitOpts, bindings }),
|
|
423
443
|
new TimestampTxValidator<TxMetaData>({ timestamp, blockNumber }, bindings),
|
|
424
444
|
new DoubleSpendTxValidator<TxMetaData>(nullifierSource, bindings),
|
|
425
445
|
new BlockHeaderTxValidator<TxMetaData>(archiveSource, bindings),
|
|
446
|
+
new AllowedSetupCallsMetaValidator<TxMetaData>(bindings),
|
|
426
447
|
);
|
|
427
448
|
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Creates a function that checks whether a tx's setup-phase calls are on the allow list.
|
|
452
|
+
*
|
|
453
|
+
* Uses the `PhasesTxValidator` on the full Tx. The result is stored as a boolean
|
|
454
|
+
* flag in `TxMetaData.allowedSetupCalls` at receipt time, so the pending pool
|
|
455
|
+
* migration validator can check it without needing the full Tx or its dependencies.
|
|
456
|
+
*/
|
|
457
|
+
export function createCheckAllowedSetupCalls(
|
|
458
|
+
contractDataSource: ContractDataSource,
|
|
459
|
+
setupAllowList: AllowedElement[],
|
|
460
|
+
getTimestamp: () => UInt64,
|
|
461
|
+
): (tx: Tx) => Promise<boolean> {
|
|
462
|
+
return async (tx: Tx) => {
|
|
463
|
+
const validator = new PhasesTxValidator(contractDataSource, setupAllowList, getTimestamp());
|
|
464
|
+
const result = await validator.validateTx(tx);
|
|
465
|
+
return result.result === 'valid';
|
|
466
|
+
};
|
|
467
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { FeeJuiceArtifact } from '@aztec/protocol-contracts/fee-juice';
|
|
1
2
|
import { getCallRequestsWithCalldataByPhase } from '@aztec/simulator/server';
|
|
2
|
-
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import { FunctionSelector, getAllFunctionAbis } from '@aztec/stdlib/abi';
|
|
3
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
import { type Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
@@ -8,7 +9,10 @@ export type FeePayerBalanceDelta = {
|
|
|
8
9
|
claimAmount: bigint;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
const increasePublicBalanceSelectorPromise =
|
|
12
|
+
const increasePublicBalanceSelectorPromise = (() => {
|
|
13
|
+
const fn = getAllFunctionAbis(FeeJuiceArtifact).find(f => f.name === '_increase_public_balance')!;
|
|
14
|
+
return FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
15
|
+
})();
|
|
12
16
|
|
|
13
17
|
export function getTxFeeLimit(tx: Tx): bigint {
|
|
14
18
|
return tx.data.constants.txContext.gasSettings.getFeeLimit().toBigInt();
|