diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index d8b739b95554e68c4983b28646278c9c9da84634..3c1a784dacedefa418af14c38ff02821c3954dd2 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1476,50 +1476,49 @@ module History = struct path) (dal_proof_error "verify_proof_repr: invalid inclusion Dal proof.") + type verify_proof_result = { + page_content_opt : Page.content option; + attestation_threshold_percent : int option; + commitment_publisher_opt : Contract_repr.t option; + } + let verify_proof_repr ?with_migration dal_params page_id snapshot proof = let open Result_syntax in let Page.{slot_id = Header.{published_level; index}; page_index = _} = page_id in - let* target_cell, inc_proof, page_proof_check = + (* With the recent refactoring of the skip list shape, we always have a + target cell and an inclusion proof in the provided proof, because the + skip list contains a cell for each slot index of each level. *) + let ( target_cell, + inc_proof, + attestation_threshold_percent, + commitment_publisher_opt ) = match proof with | Page_confirmed { target_cell; inc_proof; - page_data; - page_proof; - attestation_threshold_percent = _; - commitment_publisher = _; - (* TODO: Will be handled in the next MR *) + page_data = _; + page_proof = _; + attestation_threshold_percent; + commitment_publisher; } -> - let page_proof_check = - Some - (fun commitment -> - (* We check that the page indeed belongs to the target slot at the - given page index. *) - let* () = - check_page_proof - dal_params - page_proof - page_data - page_id - commitment - in - (* If the check succeeds, we return the data/content of the - page. *) - return page_data) - in - return (target_cell, inc_proof, page_proof_check) + ( target_cell, + inc_proof, + attestation_threshold_percent, + Some commitment_publisher ) | Page_unconfirmed { target_cell; inc_proof; - attestation_threshold_percent = _; - commitment_publisher_opt = _; - (* TODO: Will be handled in the next MR *) + attestation_threshold_percent; + commitment_publisher_opt; } -> - return (target_cell, inc_proof, None) + ( target_cell, + inc_proof, + attestation_threshold_percent, + commitment_publisher_opt ) in let cell_content = Skip_list.content target_cell in (* We check that the target cell has the same level and index than the @@ -1544,24 +1543,52 @@ module History = struct ~src:snapshot ~dest:target_cell in - match (page_proof_check, cell_content) with - | None, (Unpublished _ | Published {is_proto_attested = false; _}) -> - return_none - | ( Some page_proof_check, - Published {header = {commitment; id = _}; is_proto_attested = true; _} - ) -> - let* page_data = page_proof_check commitment in - return_some page_data - | Some _, (Unpublished _ | Published {is_proto_attested = false; _}) -> - error - @@ dal_proof_error - "verify_proof_repr: the unconfirmation proof contains the \ - target slot." - | None, Published {is_proto_attested = true; _} -> + let is_commitment_attested = + is_commitment_attested + ~attestation_threshold_percent + ~restricted_commitments_publishers: + (Option.map (fun e -> [e]) commitment_publisher_opt) + cell_content + in + match (proof, is_commitment_attested) with + | Page_unconfirmed _, Either.Right _ -> error @@ dal_proof_error "verify_proof_repr: the confirmation proof doesn't contain the \ attested slot." + | Page_unconfirmed _, Either.Left validated_commitment_publisher_opt -> + return + { + page_content_opt = None; + attestation_threshold_percent; + commitment_publisher_opt = validated_commitment_publisher_opt; + } + | Page_confirmed _, Either.Left _ -> + error + @@ dal_proof_error + "verify_proof_repr: the unconfirmation proof contains the \ + target slot." + | ( Page_confirmed + { + target_cell = _; + inc_proof = _; + page_data; + page_proof; + attestation_threshold_percent = _; + commitment_publisher = _; + }, + Either.Right (commitment, validated_commitment_publisher) ) -> + (* We check that the page indeed belongs to the target slot at the + given page index. *) + let* () = + check_page_proof dal_params page_proof page_data page_id commitment + in + return + { + page_content_opt = Some page_data; + attestation_threshold_percent; + commitment_publisher_opt = Some validated_commitment_publisher; + } let verify_proof ?with_migration dal_params page_id snapshot serialized_proof = diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 92a580de7c26880ea2279718eca24f28303c2cd3..b86a5520e0bdb4334e96d0d44169d682f69cfe9f 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -480,6 +480,23 @@ module History : sig t -> (proof * Page.content option) tzresult Lwt.t + (** The [verify_proof] function below returns three results: + + - A page content, which is [None] in case the slot related to the target + page is not attested; + + - Some attestation threshold percent in case the rollup uses Adjustable + DAL, or [None] otherwise; + + - Some contract address in case the slot related to the target page is + published, or [None] otherwise. + *) + type verify_proof_result = { + page_content_opt : Page.content option; + attestation_threshold_percent : int option; + commitment_publisher_opt : Contract_repr.t option; + } + (** [verify_proof ?with_migration dal_params page_id snapshot proof] verifies that the given [proof] is a valid proof to show that either: @@ -501,7 +518,7 @@ module History : sig Page.t -> t -> proof -> - Page.content option tzresult + verify_proof_result tzresult type error += Add_element_in_slots_skip_list_violates_ordering diff --git a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml index 4e23a46359cbb1588c352c97a8bd4a33e1a84a1f..a0b3b38530a97e939d04ee13e9f6c82b311c621d 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml @@ -304,8 +304,8 @@ module Dal_helpers = struct ~dal_number_of_slots page_id ~dal_attested_slots_validity_lag - then - let* input = + then ( + let* verify_proof_result = Dal_slot_repr.History.verify_proof ~with_migration:(protocol_activation_level, dal_attestation_lag) dal_parameters @@ -313,7 +313,18 @@ module Dal_helpers = struct dal_snapshot proof in - return_some (Sc_rollup_PVM_sig.Reveal (Dal_page input)) + let Dal_slot_repr.History. + { + page_content_opt = input; + attestation_threshold_percent; + commitment_publisher_opt; + } = + verify_proof_result + in + (* TODO: Check the ignored values below against the payload of + input_requested (Next MRs). *) + ignore (attestation_threshold_percent, commitment_publisher_opt) ; + return_some (Sc_rollup_PVM_sig.Reveal (Dal_page input))) else return_none let produce ~metadata ~dal_activation_level ~dal_attestation_lag diff --git a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml index de161b54386b2d8df65772ac977c56188a6932ca..c549ab2ef2bdf5736691e5fda476834cee50fa23 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml @@ -200,6 +200,20 @@ struct | Some check_verify -> let*? proof, _input_opt = res in let@ res = Hist.verify_proof params page_id skip_list proof in + let res = + match res with + | Error e -> Error e + | Ok + Dal_slot_repr.History. + { + page_content_opt; + attestation_threshold_percent; + commitment_publisher_opt = _; + } -> + (* These tests don't cover Adjustable DAL currently. *) + assert (Option.is_none attestation_threshold_percent) ; + Ok page_content_opt + in check_verify res page_info (* Some check functions. *)