From 2908aaa4f2e81b8c37409b168d8fd334d66775e6 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Fri, 9 Feb 2024 11:05:01 +0100 Subject: [PATCH] DAL/Test: check the case attester not in the DAL committee --- .../lib_protocol/test/helpers/block.ml | 24 ++++--- .../lib_protocol/test/helpers/block.mli | 2 + .../lib_protocol/test/helpers/context.ml | 7 +- .../lib_protocol/test/helpers/context.mli | 1 + .../integration/consensus/test_attestation.ml | 72 +++++++++++++++++++ 5 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index 7be51053a55a..28d784014b69 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -544,8 +544,9 @@ let validate_bootstrap_accounts least minimal_stake") (function Exit -> return_unit | exc -> Lwt.reraise exc) -let prepare_initial_context_params ?consensus_threshold ?min_proposal_quorum - ?level ?cost_per_byte ?issuance_weights ?origination_size ?blocks_per_cycle +let prepare_initial_context_params ?consensus_committee_size + ?consensus_threshold ?min_proposal_quorum ?level ?cost_per_byte + ?issuance_weights ?origination_size ?blocks_per_cycle ?cycles_per_voting_period ?sc_rollup_arith_pvm_enable ?sc_rollup_private_enable ?sc_rollup_riscv_pvm_enable ?dal_enable ?zk_rollup_enable ?hard_gas_limit_per_block ?nonce_revelation_threshold ?dal @@ -576,6 +577,11 @@ let prepare_initial_context_params ?consensus_threshold ?min_proposal_quorum let consensus_threshold = Option.value ~default:constants.consensus_threshold consensus_threshold in + let consensus_committee_size = + Option.value + ~default:constants.consensus_committee_size + consensus_committee_size + in let sc_rollup_arith_pvm_enable = Option.value ~default:constants.sc_rollup.arith_pvm_enable @@ -621,6 +627,7 @@ let prepare_initial_context_params ?consensus_threshold ?min_proposal_quorum cycles_per_voting_period; min_proposal_quorum; cost_per_byte; + consensus_committee_size; consensus_threshold; sc_rollup = { @@ -661,17 +668,18 @@ let prepare_initial_context_params ?consensus_threshold ?min_proposal_quorum (* if no parameter file is passed we check in the current directory where the test is run *) -let genesis ?commitments ?consensus_threshold ?min_proposal_quorum - ?bootstrap_contracts ?level ?cost_per_byte ?issuance_weights - ?origination_size ?blocks_per_cycle ?cycles_per_voting_period - ?sc_rollup_arith_pvm_enable ?sc_rollup_private_enable - ?sc_rollup_riscv_pvm_enable ?dal_enable ?zk_rollup_enable - ?hard_gas_limit_per_block ?nonce_revelation_threshold ?dal +let genesis ?commitments ?consensus_committee_size ?consensus_threshold + ?min_proposal_quorum ?bootstrap_contracts ?level ?cost_per_byte + ?issuance_weights ?origination_size ?blocks_per_cycle + ?cycles_per_voting_period ?sc_rollup_arith_pvm_enable + ?sc_rollup_private_enable ?sc_rollup_riscv_pvm_enable ?dal_enable + ?zk_rollup_enable ?hard_gas_limit_per_block ?nonce_revelation_threshold ?dal ?adaptive_issuance (bootstrap_accounts : Parameters.bootstrap_account list) = let open Lwt_result_syntax in let* constants, shell, hash = prepare_initial_context_params + ?consensus_committee_size ?consensus_threshold ?min_proposal_quorum ?level diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index 5f78b0e5257f..0256dfe6c7a4 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/block.mli @@ -126,6 +126,7 @@ val check_constants_consistency : Constants.Parametric.t -> unit tzresult Lwt.t *) val genesis : ?commitments:Commitment.t list -> + ?consensus_committee_size:int -> ?consensus_threshold:int -> ?min_proposal_quorum:int32 -> ?bootstrap_contracts:Parameters.bootstrap_contract list -> @@ -381,6 +382,7 @@ val bake_until_cycle : (** Common util function to create parameters for [initial_context] function *) val prepare_initial_context_params : + ?consensus_committee_size:int -> ?consensus_threshold:int -> ?min_proposal_quorum:int32 -> ?level:int32 -> diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 15422e52dc2f..3231e3cf60b2 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -642,9 +642,9 @@ let tup_get : type a r. (a, r) tup -> a list -> r = | _ -> assert false let init_gen tup ?rng_state ?commitments ?bootstrap_balances - ?bootstrap_delegations ?bootstrap_consensus_keys ?consensus_threshold - ?min_proposal_quorum ?bootstrap_contracts ?level ?cost_per_byte - ?issuance_weights ?origination_size ?blocks_per_cycle + ?bootstrap_delegations ?bootstrap_consensus_keys ?consensus_committee_size + ?consensus_threshold ?min_proposal_quorum ?bootstrap_contracts ?level + ?cost_per_byte ?issuance_weights ?origination_size ?blocks_per_cycle ?cycles_per_voting_period ?sc_rollup_arith_pvm_enable ?sc_rollup_private_enable ?sc_rollup_riscv_pvm_enable ?dal_enable ?zk_rollup_enable ?hard_gas_limit_per_block ?nonce_revelation_threshold ?dal @@ -665,6 +665,7 @@ let init_gen tup ?rng_state ?commitments ?bootstrap_balances let+ blk = Block.genesis ?commitments + ?consensus_committee_size ?consensus_threshold ?min_proposal_quorum ?bootstrap_contracts diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 50311775faf0..a90a8ba85b3d 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -347,6 +347,7 @@ type 'accounts init := ?bootstrap_balances:int64 list -> ?bootstrap_delegations:Signature.Public_key_hash.t option list -> ?bootstrap_consensus_keys:Signature.Public_key.t option list -> + ?consensus_committee_size:int -> ?consensus_threshold:int -> ?min_proposal_quorum:int32 -> ?bootstrap_contracts:Parameters.bootstrap_contract list -> diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_attestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_attestation.ml index 33b64939edd9..c68976596572 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_attestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_attestation.ml @@ -678,6 +678,74 @@ let test_two_attestations_with_same_attester () = in Assert.proto_error ~loc:__LOC__ res error +(* Check that if an attester includes some DAL content but is not in the DAL + committee, then an error is returned at block validation. + + Note that we change the value of [consensus_committee_size] because with the + default test parameters, [consensus_committee_size = 25 < 32 = + number_of_shards], so that test would not work! *) +let test_attester_not_in_dal_committee () = + let open Lwt_result_syntax in + let bal_high = 80_000_000_000L in + let bal_low = 08_000_000_000L in + (* Create many accounts with balance [bal_high] and one with [bal_low]. *) + let n = 10 in + let bootstrap_balances = bal_low :: Stdlib.List.init n (fun _ -> bal_high) in + let* genesis, contracts = + Context.init_gen + ~dal_enable:true + ~consensus_committee_size:100 + ~consensus_threshold:0 + ~bootstrap_balances + (Context.TList (n + 1)) + () + in + let pkh = Stdlib.List.hd contracts |> Context.Contract.pkh in + let rec iter b i = + let* committee = Context.get_attesters (B b) in + let* dal_committee = Context.Dal.shards (B b) () in + let in_committee = + List.exists + (fun del -> + Signature.Public_key_hash.equal pkh del.RPC.Validators.delegate) + committee + in + let in_dal_committee = + List.mem_assoc ~equal:Signature.Public_key_hash.equal pkh dal_committee + in + if in_committee && not in_dal_committee then + let dal_content = {attestation = Dal.Attestation.empty} in + let* op = Op.attestation ~delegate:pkh ~dal_content b in + let* ctxt = Incremental.begin_construction b in + let expect_apply_failure = function + | [ + Environment.Ecoproto_error + (Alpha_context.Dal_errors + .Dal_data_availibility_attester_not_in_committee + {attester; level}); + ] + when Signature.Public_key_hash.equal attester pkh + && Raw_level.to_int32 level = b.header.shell.level -> + return_unit + | errs -> + failwith + "Error trace:@, %a does not match the expected one" + Error_monad.pp_print_trace + errs + in + Incremental.add_operation ctxt op ~expect_failure:expect_apply_failure + else + let* b = Block.bake b in + if i = 100 then + failwith + "The account is in all DAL committees for 100 levels! The test needs \ + to be adapted." + else iter b (i + 1) + in + let* b = Block.bake genesis in + let* _ = iter b 0 in + return_unit + let tests = [ (* Positive tests *) @@ -733,6 +801,10 @@ let tests = "two attestations with same attester in a block" `Quick test_two_attestations_with_same_attester; + Tztest.tztest + "attester not in DAL committee" + `Quick + test_attester_not_in_dal_committee; ] let () = -- GitLab