From 81657cfb9563cd36d844c8090dc2a29ca2f323f9 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 7 Jan 2025 11:52:27 +0100 Subject: [PATCH 1/3] DAL/Proto: refactor verify_proof function (get (target_cell, inc_proof)) For further simplifications in the upcoming commits, we separate information retrieval from the provided proof and the page_proof_check function construction. The latter could be inlined in the commits which will follow --- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index d8b739b95554..6d9b1a71eeab 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1481,45 +1481,29 @@ module History = struct 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 = match proof with | Page_confirmed { target_cell; inc_proof; - page_data; - page_proof; + page_data = _; + page_proof = _; attestation_threshold_percent = _; commitment_publisher = _; - (* TODO: Will be handled in the next MR *) } -> - 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) | Page_unconfirmed { target_cell; inc_proof; attestation_threshold_percent = _; commitment_publisher_opt = _; - (* TODO: Will be handled in the next MR *) } -> - return (target_cell, inc_proof, None) + (target_cell, inc_proof) 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,20 +1528,36 @@ module History = struct ~src:snapshot ~dest:target_cell in - match (page_proof_check, cell_content) with - | None, (Unpublished _ | Published {is_proto_attested = false; _}) -> + match (proof, cell_content) with + | ( Page_unconfirmed _, + (Unpublished _ | Published {is_proto_attested = false; _}) ) -> return_none - | ( Some page_proof_check, + | ( Page_confirmed + { + target_cell = _; + inc_proof = _; + page_data; + page_proof; + attestation_threshold_percent = _; + commitment_publisher = _; + }, Published {header = {commitment; id = _}; is_proto_attested = true; _} ) -> - let* page_data = page_proof_check commitment in + (* 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_some page_data - | Some _, (Unpublished _ | Published {is_proto_attested = false; _}) -> + | ( Page_confirmed _, + (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; _} -> + | Page_unconfirmed _, Published {is_proto_attested = true; _} -> error @@ dal_proof_error "verify_proof_repr: the confirmation proof doesn't contain the \ -- GitLab From a3cbcea164e9e41eca9294f286ca7f71334a5ee1 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 7 Jan 2025 12:59:51 +0100 Subject: [PATCH 2/3] Proto/DAL: adapt verify_proof to use ADAL fields of the proof --- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 86 +++++++++++++------ 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index 6d9b1a71eeab..fc076b31b41e 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1476,6 +1476,12 @@ 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 = _} = @@ -1484,7 +1490,10 @@ module History = struct (* 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 = + let ( target_cell, + inc_proof, + attestation_threshold_percent, + commitment_publisher_opt ) = match proof with | Page_confirmed { @@ -1492,18 +1501,24 @@ module History = struct inc_proof; page_data = _; page_proof = _; - attestation_threshold_percent = _; - commitment_publisher = _; + attestation_threshold_percent; + commitment_publisher; } -> - (target_cell, inc_proof) + ( target_cell, + inc_proof, + attestation_threshold_percent, + Some commitment_publisher ) | Page_unconfirmed { target_cell; inc_proof; - attestation_threshold_percent = _; - commitment_publisher_opt = _; + attestation_threshold_percent; + commitment_publisher_opt; } -> - (target_cell, inc_proof) + ( 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 @@ -1528,10 +1543,31 @@ module History = struct ~src:snapshot ~dest:target_cell in - match (proof, cell_content) with - | ( Page_unconfirmed _, - (Unpublished _ | Published {is_proto_attested = false; _}) ) -> - return_none + 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 = _; @@ -1541,33 +1577,27 @@ module History = struct attestation_threshold_percent = _; commitment_publisher = _; }, - Published {header = {commitment; id = _}; is_proto_attested = true; _} - ) -> + 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 - (* If the check succeeds, we return the data/content of the - page. *) - return_some page_data - | ( Page_confirmed _, - (Unpublished _ | Published {is_proto_attested = false; _}) ) -> - error - @@ dal_proof_error - "verify_proof_repr: the unconfirmation proof contains the \ - target slot." - | Page_unconfirmed _, Published {is_proto_attested = true; _} -> - error - @@ dal_proof_error - "verify_proof_repr: the confirmation proof doesn't contain the \ - attested slot." + 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 = let open Result_syntax in let* proof_repr = deserialize_proof serialized_proof in - verify_proof_repr ?with_migration dal_params page_id snapshot proof_repr + let* res = + verify_proof_repr ?with_migration dal_params page_id snapshot proof_repr + in + return res.page_content_opt let hash = hash ?with_migration:None -- GitLab From 379cf7a95f770fd90d40f3f61004cdfaacc06f66 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 7 Jan 2025 13:07:36 +0100 Subject: [PATCH 3/3] Proto/DAL: returns the ADAL fields to Sc_rollup_proof_repr for validation The validation will be done in a next MR. --- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 5 +---- .../lib_protocol/dal_slot_repr.mli | 19 ++++++++++++++++++- .../lib_protocol/sc_rollup_proof_repr.ml | 17 ++++++++++++++--- .../lib_protocol/test/helpers/dal_helpers.ml | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index fc076b31b41e..3c1a784daced 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1594,10 +1594,7 @@ module History = struct serialized_proof = let open Result_syntax in let* proof_repr = deserialize_proof serialized_proof in - let* res = - verify_proof_repr ?with_migration dal_params page_id snapshot proof_repr - in - return res.page_content_opt + verify_proof_repr ?with_migration dal_params page_id snapshot proof_repr let hash = hash ?with_migration:None diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 92a580de7c26..b86a5520e0bd 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 4e23a46359cb..a0b3b38530a9 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 de161b54386b..c549ab2ef2bd 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. *) -- GitLab