diff --git a/src/proto_alpha/lib_protocol/dal_apply.ml b/src/proto_alpha/lib_protocol/dal_apply.ml index 08aa72783d7072817cd6e3f062b9bf0d743a7b7b..d9387a71ba3113d319000a93e25dabd929b9f5e2 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.ml +++ b/src/proto_alpha/lib_protocol/dal_apply.ml @@ -53,7 +53,7 @@ let slot_of_int_e ~number_of_slots n = let pkh_of_consensus_key (consensus_key : Consensus_key.pk) = consensus_key.delegate -let validate_attestation ctxt level consensus_key attestation = +let validate_block_attestation ctxt level consensus_key attestation = let open Lwt_result_syntax in let*? () = assert_dal_feature_enabled ctxt in let number_of_slots = Dal.number_of_slots ctxt in @@ -70,6 +70,17 @@ let validate_attestation ctxt level consensus_key attestation = (Option.is_none @@ Dal.Attestation.shards_of_attester ctxt ~attester) (Dal_data_availibility_attester_not_in_committee {attester; level}) +let validate_mempool_attestation ctxt attestation = + let open Lwt_result_syntax in + let*? () = assert_dal_feature_enabled ctxt in + let number_of_slots = Dal.number_of_slots ctxt in + let*? max_index = number_of_slots - 1 |> slot_of_int_e ~number_of_slots in + let maximum_size = Dal.Attestation.expected_size_in_bits ~max_index in + let size = Dal.Attestation.occupied_size_in_bits attestation in + fail_unless + Compare.Int.(size <= maximum_size) + (Dal_attestation_size_limit_exceeded {maximum_size; got = size}) + let validate_dal_attestation ctxt get_consensus_key_and_round_opt op = let open Lwt_result_syntax in let*? () = assert_dal_feature_enabled ctxt in diff --git a/src/proto_alpha/lib_protocol/dal_apply.mli b/src/proto_alpha/lib_protocol/dal_apply.mli index 7ea682789ed9c85b000854c497421f616c3ad070..3b0ecec076da2579bbed8f83b3b5e8bbb3a665a3 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.mli +++ b/src/proto_alpha/lib_protocol/dal_apply.mli @@ -28,22 +28,32 @@ open Alpha_context -(** [validate_attestation ctxt level consensus_key attestation] checks whether - the DAL attestation [attestation] emitted at given [level] by the attester - with the given [consensus_key] is valid. If an [Error _] is returned, the - [op] is not valid. The checks made are: +(** [validate_block_attestation ctxt level consensus_key attestation] checks + whether the DAL attestation [attestation] emitted at given [level] by the + attester with the given [consensus_key] is valid for block inclusion. If an + [Error _] is returned, the [op] is not valid. The checks made are: * the attestation size does not exceed the maximum; * the delegate is in the DAL committee. These are checks done for the DAL part alone, checks on other fields of an attestation (like level, round, slot) are done by the caller. *) -val validate_attestation : +val validate_block_attestation : t -> Raw_level.t -> Consensus_key.pk -> Dal.Attestation.t -> unit tzresult Lwt.t +(** [validate_mempool_attestation ctxt level consensus_key attestation] checks + whether the DAL attestation [attestation] is valid for the mempool. It is + similar to [check_block_attestion], but it performs only the check on the + size, as [consensus_key] is not available. If an [Error _] is returned, the + [op] is not valid. + + These are checks done for the DAL part alone, checks on other fields of an + attestation (like level, round, slot) are done by the caller. *) +val validate_mempool_attestation : t -> Dal.Attestation.t -> unit tzresult Lwt.t + (** [validate_dal_attestation ctxt get_consensus_key_and_round op] checks whether the DAL attestation [op] is valid. If an [Error _] is returned, the [op] is not valid. The checks made are: diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index d0231f2afc09faad36af363ab595465b4076ed5d..ee449695c4752b4df8d6c34004da693783978e7e 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -724,7 +724,7 @@ module Consensus = struct Option.fold ~none:return_unit ~some:(fun dal -> - Dal_apply.validate_attestation + Dal_apply.validate_block_attestation vi.ctxt level consensus_key @@ -753,6 +753,13 @@ module Consensus = struct consensus_content dal_content | Mempool -> + let* () = + Option.fold + ~none:return_unit + ~some:(fun dal -> + Dal_apply.validate_mempool_attestation vi.ctxt dal.attestation) + dal_content + in check_mempool_consensus vi consensus_info