From 6672a3abc04b16cc754c51b5f4376eb96f64213b Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 21 Dec 2023 09:08:00 +0100 Subject: [PATCH 1/5] Proto/Dal: rename Dal_proofs module to Dal_helpers --- src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 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 c4adfc6644b4..82e87019f475 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml @@ -233,7 +233,7 @@ let check_inbox_proof snapshot serialized_inbox_proof (level, counter) = | Some inbox_proof -> Sc_rollup_inbox_repr.verify_proof (level, counter) snapshot inbox_proof -module Dal_proofs = struct +module Dal_helpers = struct (* FIXME/DAL: https://gitlab.com/tezos/tezos/-/issues/3997 The current DAL refutation integration is not resilient to DAL parameters changes when upgrading the protocol. The code needs to be adapted. *) @@ -336,7 +336,7 @@ let valid (type state proof output) | Some (Reveal_proof Metadata_proof) -> return_some (Sc_rollup_PVM_sig.Reveal (Metadata metadata)) | Some (Reveal_proof (Dal_page_proof {proof; page_id})) -> - Dal_proofs.verify + Dal_helpers.verify ~metadata dal_parameters ~dal_attestation_lag @@ -508,7 +508,7 @@ let produce ~metadata pvm_and_state commit_inbox_level ~is_reveal_enabled = Some Sc_rollup_PVM_sig.(Reveal (Metadata metadata)) ) | Needs_reveal (Request_dal_page page_id) -> let open Dal_with_history in - Dal_proofs.produce + Dal_helpers.produce ~metadata dal_parameters ~dal_attestation_lag -- GitLab From bffbac445325bf7abf5cf85393eaa791a13b188a Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 21 Dec 2023 09:42:44 +0100 Subject: [PATCH 2/5] Proto/Dal/Sc_rollup: refactoring&renaming before exporting the function --- .../lib_protocol/sc_rollup_proof_repr.ml | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 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 82e87019f475..43887edf97ba 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml @@ -237,28 +237,13 @@ module Dal_helpers = struct (* FIXME/DAL: https://gitlab.com/tezos/tezos/-/issues/3997 The current DAL refutation integration is not resilient to DAL parameters changes when upgrading the protocol. The code needs to be adapted. *) - (** Given a page, identified by its ID, we accept to produce or verify a - proof for it if, and only if, the page's level [page_published_level] - is in the following boundaries: - - page_published_level > origination_level: this means that the slot - of the page was published after the rollup origination ; - - page_published_level + dal_attestation_lag <= commit_level: this - means that the slot of the page has been confirmed before or at the - [commit_level]. According to the definition in - {!Sc_rollup_commitment_repr}, [commit_level] (aka inbox_level - in that module) is the level (included) up to which the PVM consumed - all messages and DAL/DAC inputs before producing the related commitment. - *) - let page_level_is_valid ~dal_attestation_lag ~origination_level - ~commit_inbox_level page_id = + let valid_published_level ~dal_attestation_lag ~origination_level + ~commit_inbox_level ~published_level = (* [dal_attestation_lag] is supposed to be positive. *) - let page_published_level = - Dal_slot_repr.(page_id.Page.slot_id.Header.published_level) - in let open Raw_level_repr in - let not_too_old = page_published_level > origination_level in + let not_too_old = published_level > origination_level in let not_too_recent = - add page_published_level dal_attestation_lag <= commit_inbox_level + add published_level dal_attestation_lag <= commit_inbox_level in not_too_old && not_too_recent @@ -266,11 +251,12 @@ module Dal_helpers = struct page_id dal_snapshot proof = let open Result_syntax in if - page_level_is_valid + valid_published_level ~origination_level:metadata.Sc_rollup_metadata_repr.origination_level ~dal_attestation_lag ~commit_inbox_level - page_id + ~published_level: + Dal_slot_repr.(page_id.Page.slot_id.Header.published_level) then let* input = Dal_slot_repr.History.verify_proof @@ -286,11 +272,12 @@ module Dal_helpers = struct page_id ~page_info ~get_history confirmed_slots_history = let open Lwt_result_syntax in if - page_level_is_valid + valid_published_level ~origination_level:metadata.Sc_rollup_metadata_repr.origination_level ~dal_attestation_lag ~commit_inbox_level - page_id + ~published_level: + Dal_slot_repr.(page_id.Page.slot_id.Header.published_level) then let* proof, content_opt = Dal_slot_repr.History.produce_proof -- GitLab From f546e5083a15609a98e06f4af775e79705dd5168 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 21 Dec 2023 09:45:52 +0100 Subject: [PATCH 3/5] Proto/Dal/Sc_rollup: export 'valid_published_level' with doc-string --- .../lib_protocol/sc_rollup_proof_repr.mli | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.mli index 5ce20e1d74b9..6da2f0be2653 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.mli @@ -265,6 +265,30 @@ val produce : is_reveal_enabled:Sc_rollup_PVM_sig.is_reveal_enabled -> serialized t tzresult Lwt.t +module Dal_helpers : sig + (** We consider that a DAL page or slot published at a level [published_level] + is valid, and produce or verify a proof for it if, and only if, the level + is in the following boundaries: + + - [published_level] > [origination_level]: this means that the slot of the + page was published after the rollup origination ; + + - [published_level] + [dal_attestation_lag] <= [commit_inbox_level]: this + means that the slot of the page has been attested before or at the + [commit_inbox_level]. + + According to the definition in {!Sc_rollup_commitment_repr}, + [commit_inbox_level] (aka inbox_level in that module) is the level + (included) up to which the PVM consumed all messages and DAL/DAC inputs + before producing the related commitment. *) + val valid_published_level : + dal_attestation_lag:int -> + origination_level:Raw_level_repr.t -> + commit_inbox_level:Raw_level_repr.t -> + published_level:Raw_level_repr.t -> + bool +end + (**/**) module Internal_for_tests : sig -- GitLab From c9737940311c314085643b44a61472209ca7233b Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 21 Dec 2023 09:49:16 +0100 Subject: [PATCH 4/5] Proto/Dal/Sc_rollup: export 'valid_published_level' in the alpha context --- src/proto_alpha/lib_protocol/alpha_context.mli | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 0b3c80c1e1ce..85408847597b 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3816,6 +3816,15 @@ module Sc_rollup : sig Raw_level.t -> is_reveal_enabled:is_reveal_enabled -> serialized t tzresult Lwt.t + + module Dal_helpers : sig + val valid_published_level : + dal_attestation_lag:int -> + origination_level:Raw_level.t -> + commit_inbox_level:Raw_level.t -> + published_level:Raw_level.t -> + bool + end end module Game : sig -- GitLab From 8478ced5ab279ea8a73e6ba87b4730a1660e1640 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 21 Dec 2023 09:54:20 +0100 Subject: [PATCH 5/5] Sc_rollup/Dal: reuse function 'valid_published_level' when feeding kernels --- .../lib_sc_rollup_node/dal_pages_request.ml | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 36222b5826fe..90bf14c8ff6d 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 @@ -110,16 +110,18 @@ let storage_invariant_broken published_level index = Raw_level.pp published_level -(** Should match the criteria defined in {!Sc_rollup_proof_repr.page_level_is_valid}. *) let page_level_is_valid ~dal_attestation_lag ~published_level ~origination_level ~inbox_level = - (* TODO: https://gitlab.com/tezos/tezos/-/issues/6263 - Share code with {!Sc_rollup_proof_repr.page_level_is_valid}. *) - let not_too_old = published_level > origination_level in - let not_too_recent = - Int32.(add published_level (of_int dal_attestation_lag) <= inbox_level) - in - not_too_old && not_too_recent + let origination_level_res = Raw_level.of_int32 origination_level in + let commit_inbox_level_res = Raw_level.of_int32 inbox_level in + match (origination_level_res, commit_inbox_level_res) with + | Ok origination_level, Ok commit_inbox_level -> + Alpha_context.Sc_rollup.Proof.Dal_helpers.valid_published_level + ~dal_attestation_lag + ~origination_level + ~commit_inbox_level + ~published_level + | _ -> false let slot_pages ~dal_attestation_lag ~inbox_level node_ctxt Dal.Slot.Header.{published_level; index} = @@ -131,7 +133,7 @@ let slot_pages ~dal_attestation_lag ~inbox_level node_ctxt not @@ page_level_is_valid ~dal_attestation_lag - ~published_level:(Raw_level.to_int32 published_level) + ~published_level ~origination_level ~inbox_level then return_none @@ -166,7 +168,7 @@ let page_content ~dal_attestation_lag ~inbox_level node_ctxt page_id = not @@ page_level_is_valid ~dal_attestation_lag - ~published_level:(Raw_level.to_int32 published_level) + ~published_level ~origination_level ~inbox_level then return_none -- GitLab