From c0a26fdb1a3b4c6af1dc139200ae9d7528af88c7 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Wed, 20 Nov 2024 12:59:33 +0100 Subject: [PATCH 1/3] DAL/Proto: prepare the `produce_proof` function to support ADAL We introduce two new arguments ~attestation_threshold_percent and ~restricted_commitments_publishers for this function. In case of default DAL, their values is None. In the `next commit`, we'll handle calling `produce_proof` from sc_rollup_proof_repr.ml in case of Request_adal_page. In the `next (next commit)`, we'll implement the expected logic in dal_slot_repr.ml. --- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 19 ++++++++++++++----- .../lib_protocol/dal_slot_repr.mli | 14 ++++++++++++-- .../lib_protocol/sc_rollup_proof_repr.ml | 10 ++++++++-- .../lib_protocol/test/helpers/dal_helpers.ml | 9 ++++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index a86489112f8d..075e29465892 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1240,8 +1240,9 @@ module History = struct Under these assumptions, we recall that we maintain an invariant ensuring that we a have a cell per slot index in the skip list at every level after DAL activation. *) - let produce_proof_repr dal_params page_id ~page_info ~get_history slots_hist - = + let produce_proof_repr dal_params ~attestation_threshold_percent:_ + ~restricted_commitments_publishers:_ page_id ~page_info ~get_history + slots_hist = let open Lwt_result_syntax in let Page.{slot_id = target_slot_id; page_index = _} = page_id in (* We first search for the slots attested at level [published_level]. *) @@ -1315,11 +1316,19 @@ module History = struct "The page ID's slot is not confirmed, but page content and \ proof are provided.") - let produce_proof dal_params page_id ~page_info ~get_history slots_hist : - (proof * Page.content option) tzresult Lwt.t = + let produce_proof dal_params ~attestation_threshold_percent + ~restricted_commitments_publishers page_id ~page_info ~get_history + slots_hist : (proof * Page.content option) tzresult Lwt.t = let open Lwt_result_syntax in let* proof_repr, page_data = - produce_proof_repr dal_params page_id ~page_info ~get_history slots_hist + produce_proof_repr + dal_params + ~attestation_threshold_percent + ~restricted_commitments_publishers + page_id + ~page_info + ~get_history + slots_hist in let*? serialized_proof = serialize_proof proof_repr in return (serialized_proof, page_data) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index f80275a69a99..ff9fe92c2967 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -434,11 +434,14 @@ module History : sig cell_content -> Commitment.t option - (** [produce_proof dal_parameters page_id page_info ~get_history slots_hist] + (** [produce_proof dal_parameters page_id ~attestation_threshold_percent + ~restricted_commitments_publishers page_info ~get_history slots_hist] produces a proof that either: + - there exists a confirmed slot in the skip list that contains the page identified by [page_id] whose data and slot inclusion proof are given by [page_info], or + - there cannot exist a confirmed slot in the skip list (whose head is given by [slots_hist]) containing the page identified by [page_id]. @@ -458,9 +461,16 @@ module History : sig [dal_parameters] is used when verifying that/if the page is part of the candidate slot (if any). - *) + + In case [attestation_threshold_percent] is set to some threshold, the + attestation threshold of the commitment is used instead of the Protocol's + flag to decide if the page's slot is attested. Furthermore, in case some + publishers are provided in [restricted_commitments_publishers], we also + check if the commitment's publisher is whitelisted in that list. *) val produce_proof : parameters -> + attestation_threshold_percent:int option -> + restricted_commitments_publishers:Contract_repr.t list option -> Page.t -> page_info:(Page.content * Page.proof) option -> get_history:(hash -> t option Lwt.t) -> 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 2b5f35ecac8d..e48d225fa19d 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml @@ -317,8 +317,10 @@ module Dal_helpers = struct else return_none let produce ~metadata ~dal_activation_level ~dal_attestation_lag - ~dal_number_of_slots ~commit_inbox_level dal_parameters page_id ~page_info - ~get_history confirmed_slots_history ~dal_attested_slots_validity_lag = + ~dal_number_of_slots ~commit_inbox_level dal_parameters + ~attestation_threshold_percent ~restricted_commitments_publishers page_id + ~page_info ~get_history confirmed_slots_history + ~dal_attested_slots_validity_lag = let open Lwt_result_syntax in if page_id_is_valid @@ -334,6 +336,8 @@ module Dal_helpers = struct let* proof, content_opt = Dal_slot_repr.History.produce_proof dal_parameters + ~attestation_threshold_percent + ~restricted_commitments_publishers page_id ~page_info ~get_history @@ -571,6 +575,8 @@ let produce ~metadata pvm_and_state commit_inbox_level ~is_reveal_enabled = dal_parameters ~dal_attestation_lag ~commit_inbox_level + ~attestation_threshold_percent:None + ~restricted_commitments_publishers:None page_id ~page_info ~get_history 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 d0c459b81386..de161b54386b 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml @@ -185,7 +185,14 @@ struct skip_list ~page_info ~page_id = let open Lwt_result_wrap_syntax in let*!@ res = - Hist.produce_proof params ~page_info page_id ~get_history skip_list + Hist.produce_proof + params + ~page_info + ~attestation_threshold_percent:None + ~restricted_commitments_publishers:None + page_id + ~get_history + skip_list in let* () = check_produce res page_info in match check_verify with -- GitLab From 584e42ca615e7ee002cf4c0ed6c8876e4ff1c5ed Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Wed, 20 Nov 2024 11:31:05 +0100 Subject: [PATCH 2/3] DAL/SR/Proto: Handle Request_adal_page in Sc_rollup_proof_repr.produce --- .../lib_protocol/sc_rollup_proof_repr.ml | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) 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 e48d225fa19d..4e23a46359cb 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml @@ -582,11 +582,31 @@ let produce ~metadata pvm_and_state commit_inbox_level ~is_reveal_enabled = ~get_history ~dal_attested_slots_validity_lag confirmed_slots_history - | Needs_reveal (Request_adal_page _info) -> - (* ADAL/FIXME: https://gitlab.com/tezos/tezos/-/milestones/410 - - Implement refutations for adaptive DAL *) - assert false + | Needs_reveal + (Request_adal_page + { + page_id; + attestation_threshold_percent; + restricted_commitments_publishers; + }) -> + let open Dal_with_history in + let attestation_threshold_percent = + Some attestation_threshold_percent + in + Dal_helpers.produce + ~dal_number_of_slots + ~metadata + ~dal_activation_level + dal_parameters + ~dal_attestation_lag + ~commit_inbox_level + ~attestation_threshold_percent + ~restricted_commitments_publishers + page_id + ~page_info + ~get_history + ~dal_attested_slots_validity_lag + confirmed_slots_history | Needs_reveal Reveal_dal_parameters -> let open Dal_with_history in return -- GitLab From cc9293e4d166f18e58287aefb432529d7580f710 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Wed, 20 Nov 2024 11:51:34 +0100 Subject: [PATCH 3/3] DAL/Proto: support ADAL in Dal_slot_repr.produce_proof --- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index 075e29465892..8958d5148fbf 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1240,8 +1240,8 @@ module History = struct Under these assumptions, we recall that we maintain an invariant ensuring that we a have a cell per slot index in the skip list at every level after DAL activation. *) - let produce_proof_repr dal_params ~attestation_threshold_percent:_ - ~restricted_commitments_publishers:_ page_id ~page_info ~get_history + let produce_proof_repr dal_params ~attestation_threshold_percent + ~restricted_commitments_publishers page_id ~page_info ~get_history slots_hist = let open Lwt_result_syntax in let Page.{slot_id = target_slot_id; page_index = _} = page_id in @@ -1274,11 +1274,14 @@ module History = struct produce proofs are supposed to be in the skip list." | Found target_cell -> ( let inc_proof = List.rev search_result.Skip_list.rev_path in - match (page_info, Skip_list.content target_cell) with - | ( Some (page_data, page_proof), - Published - {header = {commitment; id = _}; is_proto_attested = true; _} ) - -> + let is_commitment_attested = + Skip_list.content target_cell + |> is_commitment_attested + ~attestation_threshold_percent + ~restricted_commitments_publishers + in + match (page_info, is_commitment_attested) with + | Some (page_data, page_proof), Some commitment -> (* The case where the slot to which the page is supposed to belong is found and the page's information are given. *) let*? () = @@ -1294,21 +1297,20 @@ module History = struct return ( Page_confirmed {target_cell; inc_proof; page_data; page_proof}, Some page_data ) - | None, (Unpublished _ | Published {is_proto_attested = false; _}) -> + | None, None -> (* 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, Published {is_proto_attested = true; _} -> + | None, Some _ -> (* 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 _, (Unpublished _ | Published {is_proto_attested = false; _}) - -> + | Some _, None -> (* Mismatch: case where page information are given, but the slot is not attested. *) tzfail -- GitLab