From 436d22add1839e3d81960792eb3c613feaa58765 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Sun, 22 Dec 2024 08:36:52 +0100 Subject: [PATCH 1/2] DAL/Proto: extend is_commitment_attested to return the publisher, when possible --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 +- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 13 ++++++++----- src/proto_alpha/lib_protocol/dal_slot_repr.mli | 9 ++++++--- .../lib_sc_rollup_node/dal_pages_request.ml | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index e1f7465add02..f12c981df6bd 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3008,7 +3008,7 @@ module Dal : sig attestation_threshold_percent:int option -> restricted_commitments_publishers:Contract.t list option -> cell_content -> - Slot.Commitment.t option + (Contract.t option, Slot.Commitment.t * Contract.t) Either.t type proof end diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index 8958d5148fbf..496194243c31 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1210,9 +1210,12 @@ module History = struct ~restricted_commitments_publishers cell_content = let open Content_v2 in match (cell_content, attestation_threshold_percent) with - | Unpublished _, _ -> None - | Published {header = {commitment; id = _}; is_proto_attested; _}, None -> - if is_proto_attested then Some commitment else None + | Unpublished _, _ -> Either.Left None + | ( Published + {header = {commitment; id = _}; is_proto_attested; publisher; _}, + None ) -> + if is_proto_attested then Either.Right (commitment, publisher) + else Either.Left (Some publisher) | ( Published { header = {commitment; id = _}; @@ -1230,8 +1233,8 @@ module History = struct && allowed_commitments_publisher publisher restricted_commitments_publishers - then Some commitment - else None + then Either.Right (commitment, publisher) + else Either.Left (Some publisher) (** The [produce_proof_repr] function assumes that some invariants hold, such as: - The DAL has been activated, diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index ff9fe92c2967..92a580de7c26 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -420,8 +420,11 @@ module History : sig print the serialized version of the proof (i.e. a sequence of bytes). *) val pp_proof : serialized:bool -> Format.formatter -> proof -> unit - (** This function returns some commitment if and only if the skip list cell - whose content is given is supposed to be attested. + (** This function returns a commitment and its publisher (wrapped in + Either.Right if and only if the skip list cell whose content is given is + attested. In case the commitment is not attested, the + function returns the publisher if the slot is published or None otherwise + (wrapped in Either.Left). Attestation status is either checked by inspecting the protocol's boolean flag stored in the content if [attestation_threshold_percent] is None @@ -432,7 +435,7 @@ module History : sig attestation_threshold_percent:int option -> restricted_commitments_publishers:Contract_repr.t list option -> cell_content -> - Commitment.t option + (Contract_repr.t option, Commitment.t * Contract_repr.t) Either.t (** [produce_proof dal_parameters page_id ~attestation_threshold_percent ~restricted_commitments_publishers page_info ~get_history slots_hist] diff --git a/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml b/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml index 98a289fee361..a3396b1050ee 100644 --- a/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml +++ b/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml @@ -208,13 +208,13 @@ let slot_attestation_status ?attestation_threshold_percent let* cell_content = dal_skip_list_cell_content_of_slot_id node_ctxt dal_constants slot_id in - let commitment_opt = + let commitment_res = Dal.Slots_history.is_commitment_attested ~attestation_threshold_percent ~restricted_commitments_publishers cell_content in - return @@ if Option.is_some commitment_opt then `Attested else `Unattested + return @@ if Either.is_right commitment_res then `Attested else `Unattested let get_page node_ctxt ~inbox_level page_id = let open Lwt_result_syntax in -- GitLab From 50c4bd1eadf002399a269b9261de2472733902f8 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 6 Jan 2025 18:03:58 +0100 Subject: [PATCH 2/2] Proto/DAL: Remember ADAL attestation threshold & publisher in refutation games --- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 183 +++++++++++++++--- 1 file changed, 157 insertions(+), 26 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index 496194243c31..d8b739b95554 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -997,8 +997,28 @@ module History = struct [page_data] is actually the [page_id.page_index]th page of the slot stored in [target_cell] and identified by [page_id.slot_id]. *) + attestation_threshold_percent : int option; + (** In case of Adjustable DAL, [attestation_threshold_percent] is set + to some attestation threshold defined by the rollup kernel. For + regular DAL, it's set to None. *) + commitment_publisher : Contract_repr.t; + (** In case of confirmation proof, we also remember the + commitment publisher. It will be needed in case of Adjustable DAL + to check that the publisher is whitelised, if needed. *) } (** The case where the slot's page is confirmed/attested on L1. *) - | Page_unconfirmed of {target_cell : history; inc_proof : inclusion_proof} + | Page_unconfirmed of { + target_cell : history; + inc_proof : inclusion_proof; + attestation_threshold_percent : int option; + (** In case of Adjustable DAL, [attestation_threshold_percent] is set + to some attestation threshold defined by the rollup kernel. For + regular DAL, it's set to None. *) + commitment_publisher_opt : Contract_repr.t option; + (** In case of an unconfirmation proof, we remember the commitment + publisher if the slot is published. It will be needed in case of + Adjustable DAL to check that the publisher is whitelisted, if + needed. *) + } (** The case where the slot's page doesn't exist or is not confirmed on L1. The fields are similar to {!Page_confirmed} case except that we don't have a page data or proof to check. @@ -1015,32 +1035,86 @@ module History = struct case ~title:"confirmed dal page proof representation" (Tag 0) - (obj5 + (obj7 (req "kind" (constant "confirmed")) (req "target_cell" history_encoding) (req "inc_proof" (list history_encoding)) (req "page_data" (bytes Hex)) - (req "page_proof" Page.proof_encoding)) + (req "page_proof" Page.proof_encoding) + (opt "attestation_threshold_percent" uint8) + (req "commitment_publisher" Contract_repr.encoding)) (function - | Page_confirmed {target_cell; inc_proof; page_data; page_proof} -> - Some ((), target_cell, inc_proof, page_data, page_proof) + | Page_confirmed + { + target_cell; + inc_proof; + page_data; + page_proof; + attestation_threshold_percent; + commitment_publisher; + } -> + Some + ( (), + target_cell, + inc_proof, + page_data, + page_proof, + attestation_threshold_percent, + commitment_publisher ) | _ -> None) - (fun ((), target_cell, inc_proof, page_data, page_proof) -> - Page_confirmed {target_cell; inc_proof; page_data; page_proof}) + (fun ( (), + target_cell, + inc_proof, + page_data, + page_proof, + attestation_threshold_percent, + commitment_publisher ) -> + Page_confirmed + { + target_cell; + inc_proof; + page_data; + page_proof; + attestation_threshold_percent; + commitment_publisher; + }) and case_page_unconfirmed = case ~title:"unconfirmed dal page proof representation" (Tag 1) - (obj3 + (obj5 (req "kind" (constant "unconfirmed")) (req "target_cell" history_encoding) - (req "inc_proof" (list history_encoding))) + (req "inc_proof" (list history_encoding)) + (opt "attestation_threshold_percent" uint8) + (opt "commitment_publisher" Contract_repr.encoding)) (function - | Page_unconfirmed {target_cell; inc_proof} -> - Some ((), target_cell, inc_proof) + | Page_unconfirmed + { + target_cell; + inc_proof; + attestation_threshold_percent; + commitment_publisher_opt; + } -> + Some + ( (), + target_cell, + inc_proof, + attestation_threshold_percent, + commitment_publisher_opt ) | _ -> None) - (fun ((), target_cell, inc_proof) -> - Page_unconfirmed {target_cell; inc_proof}) + (fun ( (), + target_cell, + inc_proof, + attestation_threshold_percent, + commitment_publisher_opt ) -> + Page_unconfirmed + { + target_cell; + inc_proof; + attestation_threshold_percent; + commitment_publisher_opt; + }) in union [case_page_confirmed; case_page_unconfirmed] @@ -1101,11 +1175,20 @@ module History = struct | Error msg -> Error_monad.pp_trace fmt msg | Ok proof -> ( match proof with - | Page_confirmed {target_cell; inc_proof; page_data; page_proof} -> + | Page_confirmed + { + target_cell; + inc_proof; + page_data; + page_proof; + attestation_threshold_percent; + commitment_publisher; + } -> Format.fprintf fmt "Page_confirmed (target_cell=%a, data=%s,@ \ - inc_proof:[size=%d |@ path=%a]@ page_proof:%a)" + inc_proof:[size=%d |@ path=%a]@ page_proof:%a@ \ + attestation_threshold_percent:%a@ commitment_publisher:%a)" pp_history target_cell (Bytes.to_string page_data) @@ -1114,16 +1197,31 @@ module History = struct inc_proof Page.pp_proof page_proof - | Page_unconfirmed {target_cell; inc_proof} -> + (Format.pp_print_option Format.pp_print_int) + attestation_threshold_percent + Contract_repr.pp_short + commitment_publisher + | Page_unconfirmed + { + target_cell; + inc_proof; + attestation_threshold_percent; + commitment_publisher_opt; + } -> Format.fprintf fmt "Page_unconfirmed (target_cell = %a | inc_proof:[size=%d@ | \ - path=%a])" + path=%a]@ attestation_threshold_percent:%a@ \ + commitment_publisher:%a)" pp_history target_cell (List.length inc_proof) pp_inclusion_proof - inc_proof) + inc_proof + (Format.pp_print_option Format.pp_print_int) + attestation_threshold_percent + (Format.pp_print_option Contract_repr.pp_short) + commitment_publisher_opt) type error += | Dal_page_proof_error of string @@ -1284,7 +1382,8 @@ module History = struct ~restricted_commitments_publishers in match (page_info, is_commitment_attested) with - | Some (page_data, page_proof), Some commitment -> + | ( Some (page_data, page_proof), + Either.Right (commitment, commitment_publisher) ) -> (* The case where the slot to which the page is supposed to belong is found and the page's information are given. *) let*? () = @@ -1298,22 +1397,38 @@ module History = struct in (* All checks succeeded. We return a `Page_confirmed` proof. *) return - ( Page_confirmed {target_cell; inc_proof; page_data; page_proof}, + ( Page_confirmed + { + target_cell; + inc_proof; + page_data; + page_proof; + attestation_threshold_percent; + commitment_publisher; + }, Some page_data ) - | None, None -> + | None, Either.Left commitment_publisher_opt -> (* The slot corresponding to the given page's index is not found in the attested slots of the page's level, and no information is given for that page. So, we produce a proof that the page is not attested. *) - return (Page_unconfirmed {target_cell; inc_proof}, None) - | None, Some _ -> + return + ( Page_unconfirmed + { + target_cell; + inc_proof; + attestation_threshold_percent; + commitment_publisher_opt; + }, + None ) + | None, Either.Right _ -> (* Mismatch: case where no page information are given, but the slot is attested. *) tzfail @@ dal_proof_error "The page ID's slot is confirmed, but no page content and \ proof are provided." - | Some _, None -> + | Some _, Either.Left _ -> (* Mismatch: case where page information are given, but the slot is not attested. *) tzfail @@ -1368,7 +1483,16 @@ module History = struct in let* target_cell, inc_proof, page_proof_check = match proof with - | Page_confirmed {target_cell; inc_proof; page_data; page_proof} -> + | Page_confirmed + { + target_cell; + inc_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 -> @@ -1387,7 +1511,14 @@ module History = struct return page_data) in return (target_cell, inc_proof, page_proof_check) - | Page_unconfirmed {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) in let cell_content = Skip_list.content target_cell in -- GitLab