From bb59de1e81965476b0b6d438909d2c3461674810 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 27 Jun 2024 08:56:29 +0200 Subject: [PATCH 1/2] [POC] Hackish: attach attested DAL slots to EOL messages, lib_protocol --- .../lib_protocol/alpha_context.mli | 11 ++- src/proto_alpha/lib_protocol/apply.ml | 4 +- .../lib_protocol/sc_rollup_arith.ml | 2 +- .../lib_protocol/sc_rollup_costs.ml | 2 +- .../sc_rollup_inbox_message_repr.ml | 21 +++-- .../sc_rollup_inbox_message_repr.mli | 5 +- .../lib_protocol/sc_rollup_inbox_repr.ml | 29 +++++-- .../lib_protocol/sc_rollup_inbox_repr.mli | 6 +- .../lib_protocol/sc_rollup_inbox_storage.ml | 7 +- .../lib_protocol/sc_rollup_inbox_storage.mli | 5 +- .../test/helpers/sc_rollup_helpers.ml | 80 ++++++++++++++----- .../integration/operations/test_sc_rollup.ml | 15 +++- .../test/pbt/test_refutation_game.ml | 11 ++- .../test/pbt/test_sc_rollup_encoding.ml | 15 +++- .../test/unit/test_sc_rollup_inbox.ml | 31 ++++++- .../test/unit/test_sc_rollup_inbox_legacy.ml | 4 + .../test_sc_rollup_management_protocol.ml | 21 ++++- .../test/unit/test_sc_rollup_wasm.ml | 7 +- 18 files changed, 215 insertions(+), 61 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 6f2a371cc7df..67a71bb12c2e 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3135,7 +3135,7 @@ module Sc_rollup : sig destination : t; } | Start_of_level - | End_of_level + | End_of_level of Dal.Slot.Header.extended list | Info_per_level of { predecessor_timestamp : Time.t; predecessor : Block_hash.t; @@ -3328,6 +3328,7 @@ module Sc_rollup : sig History.t -> t -> Inbox_message.t list -> + Dal.Slot.Header.extended list -> (Inbox_merkelized_payload_hashes.History.t * History.t * t @@ -3366,7 +3367,10 @@ module Sc_rollup : sig (proof * inbox_message option) tzresult Lwt.t val finalize_inbox_level_no_history : - t -> Inbox_merkelized_payload_hashes.t -> t + t -> + Dal.Slot.Header.extended list -> + Inbox_merkelized_payload_hashes.t -> + t val init_witness_no_history : Inbox_merkelized_payload_hashes.t @@ -3440,7 +3444,8 @@ module Sc_rollup : sig destination:rollup -> context tzresult Lwt.t - val finalize_inbox_level : context -> context tzresult Lwt.t + val finalize_inbox_level : + context -> Dal.Slot.Header.extended list -> context tzresult Lwt.t val add_level_info : predecessor:Block_hash.t -> context -> context tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index f6ca4b4cd882..32d631e81c0e 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -3050,10 +3050,10 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash in let* ctxt = Amendment.may_start_new_voting_period ctxt in (* TODO: push _attested_slot_headers into rollups' inbox *) - let* ctxt, dal_attestation, _attested_slot_headers = + let* ctxt, dal_attestation, attested_slot_headers = Dal_apply.finalisation ctxt in - let* ctxt = Sc_rollup.Inbox.finalize_inbox_level ctxt in + let* ctxt = Sc_rollup.Inbox.finalize_inbox_level ctxt attested_slot_headers in let balance_updates = migration_balance_updates @ baking_receipts @ cycle_end_balance_updates in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml index 6962e7fec37d..011c89792049 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml @@ -1169,7 +1169,7 @@ module Make (Context : Sc_rollup_PVM_sig.Generic_pvm_context_sig) : | Ok (Internal Start_of_level) -> let* () = incr_internal_message_counter in return None - | Ok (Internal End_of_level) -> + | Ok (Internal (End_of_level _)) -> let* () = incr_internal_message_counter in return None | Ok (Internal (Info_per_level _)) -> diff --git a/src/proto_alpha/lib_protocol/sc_rollup_costs.ml b/src/proto_alpha/lib_protocol/sc_rollup_costs.ml index 17354d9db833..458a6d70566f 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_costs.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_costs.ml @@ -82,7 +82,7 @@ let cost_serialize_internal_inbox_message expr_cost + Constants.cost_decoding_contract_optimized + Constants.cost_decoding_key_hash_optimized) | Start_of_level -> Saturation_repr.zero - | End_of_level -> Saturation_repr.zero + | End_of_level _ -> Saturation_repr.zero | Protocol_migration _ -> Saturation_repr.zero | Info_per_level _ -> Saturation_repr.zero diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml index e8a6f5e7be1d..c74ccfffd893 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml @@ -62,7 +62,7 @@ type internal_inbox_message = destination : Sc_rollup_repr.Address.t; } | Start_of_level - | End_of_level + | End_of_level of Dal_slot_repr.Header.extended list | Info_per_level of { predecessor_timestamp : Time.t; predecessor : Block_hash.t; @@ -98,9 +98,16 @@ let internal_inbox_message_encoding = case (Tag 2) ~title:"End_of_level" - (obj1 (kind "end_of_level")) - (function End_of_level -> Some () | _ -> None) - (fun () -> End_of_level); + (obj2 + (kind "end_of_level") + (req + "attested_dal_slots" + (list Dal_slot_repr.Header.extended_encoding))) + (function + | End_of_level attested_slot_headers -> + Some ((), attested_slot_headers) + | _ -> None) + (fun ((), attested_slot_headers) -> End_of_level attested_slot_headers); case (Tag 3) ~title:"Info_per_level" @@ -200,10 +207,12 @@ let start_of_level_serialized = startup time as we are defining a top-level value. *) Data_encoding.Binary.to_string_exn encoding (Internal Start_of_level) -let end_of_level_serialized = +let end_of_level_serialized attested_slot_headers = (* If [End_of_level] cannot be serialized, this will be detected at startup time as we are defining a top-level value. *) - Data_encoding.Binary.to_string_exn encoding (Internal End_of_level) + Data_encoding.Binary.to_string_exn + encoding + (Internal (End_of_level attested_slot_headers)) let info_per_level_serialized ~predecessor_timestamp ~predecessor = match diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli index c4873becc4ea..df4a6d7d19d4 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli @@ -60,7 +60,8 @@ type internal_inbox_message = } | Start_of_level (** Internal message put at the beginning of each inbox's level. *) - | End_of_level (** Internal message put at the end of each inbox's level. *) + | End_of_level of Dal_slot_repr.Header.extended list + (** Internal message put at the end of each inbox's level. *) | Info_per_level of { predecessor_timestamp : Time.t; (** Timestamp of the predecessor block where this message is @@ -100,7 +101,7 @@ val hash_serialized_message : serialized -> Hash.t val start_of_level_serialized : serialized (** {!serialized} representation of [Internal [End_of_level]]. *) -val end_of_level_serialized : serialized +val end_of_level_serialized : Dal_slot_repr.Header.extended list -> serialized (** {!info_per_level_serialized ~predecessor_timestamp ~predecessor} is the serialized representation of the internal message for {!Info_per_level}. *) val info_per_level_serialized : diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml index aba4043dde4b..fb56138ac698 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml @@ -711,24 +711,29 @@ let add_info_per_level_no_history ~predecessor_timestamp ~predecessor witness = in add_protocol_internal_message_no_history info_per_level witness -let finalize_inbox_level payloads_history history inbox witness = +let finalize_inbox_level payloads_history history inbox attested_slot_headers + witness = let open Result_syntax in let inbox = {inbox with level = Raw_level_repr.succ inbox.level} in - let eol = Sc_rollup_inbox_message_repr.end_of_level_serialized in + let eol = + Sc_rollup_inbox_message_repr.end_of_level_serialized attested_slot_headers + in let* payloads_history, witness = add_protocol_internal_message eol payloads_history witness in let* history, inbox = archive history inbox witness in return (payloads_history, history, witness, inbox) -let finalize_inbox_level_no_history inbox witness = +let finalize_inbox_level_no_history inbox attested_slot_headers witness = let inbox = {inbox with level = Raw_level_repr.succ inbox.level} in - let eol = Sc_rollup_inbox_message_repr.end_of_level_serialized in + let eol = + Sc_rollup_inbox_message_repr.end_of_level_serialized attested_slot_headers + in let witness = add_protocol_internal_message_no_history eol witness in archive_no_history inbox witness let add_all_messages ~protocol_migration_message ~predecessor_timestamp - ~predecessor history inbox messages = + ~predecessor history inbox messages attested_slot_headers = let open Result_syntax in let* payloads = List.map_e Sc_rollup_inbox_message_repr.serialize messages in let is_first_block = Option.is_some protocol_migration_message in @@ -769,7 +774,12 @@ let add_all_messages ~protocol_migration_message ~predecessor_timestamp | payloads -> add_messages payloads_history payloads witness in let* payloads_history, history, witness, inbox = - finalize_inbox_level payloads_history history inbox witness + finalize_inbox_level + payloads_history + history + inbox + attested_slot_headers + witness in (* Wrap the messages so the caller can execute every actual messages @@ -786,7 +796,7 @@ let add_all_messages ~protocol_migration_message ~predecessor_timestamp ~some:(fun x -> [Internal x]) protocol_migration_message in - let eol = Internal End_of_level in + let eol = Internal (End_of_level attested_slot_headers) in [sol] @ [info_per_level] @ migration @ messages @ [eol] in @@ -804,7 +814,10 @@ let genesis ~protocol_migration_message ~predecessor_timestamp ~predecessor in (* 2. Add [EOL]. *) - let eol = Sc_rollup_inbox_message_repr.end_of_level_serialized in + let attested_slot_headers = [] in + let eol = + Sc_rollup_inbox_message_repr.end_of_level_serialized attested_slot_headers + in let witness = add_protocol_internal_message_no_history eol witness in let level_proof = diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli index e728ce8ff858..b88319f00778 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli @@ -246,6 +246,7 @@ val add_all_messages : History.t -> t -> Sc_rollup_inbox_message_repr.t list -> + Dal_slot_repr.Header.extended list -> (Sc_rollup_inbox_merkelized_payload_hashes_repr.History.t * History.t * t @@ -336,7 +337,10 @@ val add_info_per_level_no_history : the current inbox's level witness by adding [EOL], and archives the current level. *) val finalize_inbox_level_no_history : - t -> Sc_rollup_inbox_merkelized_payload_hashes_repr.t -> t + t -> + Dal_slot_repr.Header.extended list -> + Sc_rollup_inbox_merkelized_payload_hashes_repr.t -> + t (** [genesis ~protocol_migration_message ~timestamp ~predecessor level] initializes the inbox at some given [level] with: [SOL], diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml index 356f90bc52eb..cd88254bdf78 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.ml @@ -113,12 +113,15 @@ let add_deposit ctxt ~payload ~sender ~source ~destination = in add_internal_message ctxt internal_message -let finalize_inbox_level ctxt = +let finalize_inbox_level ctxt attested_slot_headers = let open Lwt_result_syntax in let* inbox, ctxt = get_inbox ctxt in let witness = Raw_context.Sc_rollup_in_memory_inbox.current_messages ctxt in let inbox = - Sc_rollup_inbox_repr.finalize_inbox_level_no_history inbox witness + Sc_rollup_inbox_repr.finalize_inbox_level_no_history + inbox + attested_slot_headers + witness in Store.Inbox.update ctxt inbox diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli index 6f7fed515f16..51b6dd6b401e 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli @@ -60,4 +60,7 @@ val add_level_info : (** [finalize_inbox_level ctxt] ends the internal representation for the block. *) -val finalize_inbox_level : Raw_context.t -> Raw_context.t tzresult Lwt.t +val finalize_inbox_level : + Raw_context.t -> + Dal_slot_repr.Header.extended list -> + Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml index 133a589ecd60..2838191d2edf 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml @@ -155,8 +155,10 @@ let make_sol ~inbox_level = let payload = make_internal_inbox_message Start_of_level in make_input ~inbox_level ~message_counter:Z.zero payload -let make_eol ~inbox_level ~message_counter = - let payload = make_internal_inbox_message End_of_level in +let make_eol ~inbox_level ~message_counter attested_slot_headers = + let payload = + make_internal_inbox_message @@ End_of_level attested_slot_headers + in make_input ~inbox_level ~message_counter payload let make_info_per_level ~inbox_level ~predecessor_timestamp ~predecessor = @@ -202,6 +204,7 @@ type message = { *) type payloads_per_level = { messages : string list; (** List of external messages. *) + attested_slot_headers : Dal.Slot.Header.extended list; payloads : Sc_rollup.Inbox_message.serialized list; (** List of external serialized messages. *) predecessor_timestamp : Time.Protocol.t; @@ -251,7 +254,7 @@ let strs_to_inputs inbox_level messages = (** Transform the list of all inputs the PVM should read. *) let make_inputs ~first_block predecessor_timestamp predecessor messages - inbox_level = + attested_slot_headers inbox_level = (* SOL is at index 0. *) let sol = make_sol ~inbox_level in (* Info_per_level is at index 1. *) @@ -277,7 +280,7 @@ let make_inputs ~first_block predecessor_timestamp predecessor messages let message_counter = Z.of_int (2 + List.length mig + List.length messages) in - make_eol ~inbox_level ~message_counter + make_eol ~inbox_level ~message_counter attested_slot_headers in [sol; info_per_level] @ mig @ external_inputs @ [eol] @@ -290,8 +293,8 @@ let predecessor_timestamp_and_hash_from_level level = (** Wrap messages, predecessor_timestamp and predecessor of a level into a [payloads_per_level] .*) let wrap_messages level - ?(pred_info = predecessor_timestamp_and_hash_from_level level) messages : - payloads_per_level = + ?(pred_info = predecessor_timestamp_and_hash_from_level level) messages + attested_slot_headers : payloads_per_level = let predecessor_timestamp, predecessor = pred_info in let payloads = List.map make_external_inbox_message messages in let inputs = @@ -300,21 +303,37 @@ let wrap_messages level predecessor_timestamp predecessor messages + attested_slot_headers level in - {payloads; predecessor_timestamp; predecessor; messages; level; inputs} + { + payloads; + predecessor_timestamp; + predecessor; + messages; + level; + inputs; + attested_slot_headers; + } (** An empty inbox level is a SOL,IPL and EOL. *) let make_empty_level ?pred_info inbox_level = - wrap_messages ?pred_info inbox_level [] + wrap_messages ?pred_info inbox_level [] [] -let gen_messages ?pred_info inbox_level gen_message = +let gen_messages ?pred_info inbox_level gen_message gen_attested_slot_headers = let open QCheck2.Gen in let* input = gen_message in let* inputs = small_list gen_message in - return (wrap_messages ?pred_info inbox_level (input :: inputs)) - -let gen_payloads_for_levels ~start_level ~max_level gen_message = + let* attested_slot_headers = gen_attested_slot_headers in + return + (wrap_messages + ?pred_info + inbox_level + (input :: inputs) + attested_slot_headers) + +let gen_payloads_for_levels ~start_level ~max_level gen_message + gen_attested_slot_headers = let open QCheck2.Gen in let rec aux acc n = match n with @@ -329,7 +348,7 @@ let gen_payloads_for_levels ~start_level ~max_level gen_message = let* empty_level = bool in let* level_messages = if empty_level then return (make_empty_level inbox_level) - else gen_messages inbox_level gen_message + else gen_messages inbox_level gen_message gen_attested_slot_headers in aux (level_messages :: acc) (n - 1) in @@ -359,8 +378,10 @@ let make_sol_repr ~inbox_level = let payload = make_internal_inbox_message_repr Start_of_level in make_input_repr ~inbox_level ~message_counter:Z.zero payload -let make_eol_repr ~inbox_level ~message_counter = - let payload = make_internal_inbox_message_repr End_of_level in +let make_eol_repr ~inbox_level ~message_counter attested_slot_headers = + let payload = + make_internal_inbox_message_repr @@ End_of_level attested_slot_headers + in make_input_repr ~inbox_level ~message_counter payload (** Message is the combination of a [message] and its associated [input]. @@ -403,9 +424,11 @@ let pp_message_repr fmt {input_repr; message_repr} = (** An empty inbox level is a SOL,IPL and EOL. *) let make_empty_level_repr inbox_level = let sol = {input_repr = make_sol_repr ~inbox_level; message_repr = `SOL} in + let attested_slot_headers = [] in let eol = { - input_repr = make_eol_repr ~inbox_level ~message_counter:Z.one; + input_repr = + make_eol_repr ~inbox_level ~message_counter:Z.one attested_slot_headers; message_repr = `EOL; } in @@ -424,7 +447,7 @@ let strs_to_input_reprs_repr inbox_level message_reprs = message_reprs (** Transform message_reprs into input_reprs and wrap them between SOL and EOL. *) -let wrap_message_reprs_repr inbox_level strs = +let wrap_message_reprs_repr inbox_level strs attested_slot_headers = let sol = {input_repr = make_sol_repr ~inbox_level; message_repr = `SOL} in let rev_input_reprs, message_counter = strs_to_input_reprs_repr inbox_level strs @@ -432,13 +455,15 @@ let wrap_message_reprs_repr inbox_level strs = let input_reprs = List.rev rev_input_reprs in let eol = { - input_repr = make_eol_repr ~inbox_level ~message_counter; + input_repr = + make_eol_repr ~inbox_level ~message_counter attested_slot_headers; message_repr = `EOL; } in (sol :: input_reprs) @ [eol] -let gen_message_reprs_for_levels_repr ~start_level ~max_level gen_message_repr = +let gen_message_reprs_for_levels_repr ~start_level ~max_level gen_message_repr + gen_attested_slot_headers = let open QCheck2.Gen in let rec aux acc n = match n with @@ -451,13 +476,18 @@ let gen_message_reprs_for_levels_repr ~start_level ~max_level gen_message_repr = let* level_message_reprs = if empty_level then return (make_empty_level_repr inbox_level) else + let* attested_slot_headers = gen_attested_slot_headers in let* message_reprs = let* input_repr = gen_message_repr in let* input_reprs = small_list gen_message_repr in return (input_repr :: input_reprs) in return - (inbox_level, wrap_message_reprs_repr inbox_level message_reprs) + ( inbox_level, + wrap_message_reprs_repr + inbox_level + message_reprs + attested_slot_headers ) in aux (level_message_reprs :: acc) (n - 1) | _ -> @@ -581,6 +611,7 @@ module Node_inbox = struct predecessor_timestamp; predecessor; messages; + attested_slot_headers; level; inputs = _; } : @@ -599,6 +630,7 @@ module Node_inbox = struct history inbox messages + attested_slot_headers in (* Store in the history this archived level. *) let witness_hash = @@ -685,6 +717,7 @@ module Protocol_inbox = struct predecessor_timestamp; predecessor; messages; + attested_slot_headers; level; inputs = _; } : @@ -703,14 +736,17 @@ module Protocol_inbox = struct (Sc_rollup.Inbox.History.empty ~capacity:1000L) inbox payloads + attested_slot_headers in aux inbox rst in aux inbox payloads_per_levels - let add_new_level ?pred_info inbox messages = + let add_new_level ?pred_info inbox messages attested_slot_headers = let next_level = Raw_level.succ @@ Sc_rollup.Inbox.inbox_level inbox in - let messages_per_level = wrap_messages ?pred_info next_level messages in + let messages_per_level = + wrap_messages ?pred_info next_level messages attested_slot_headers + in fill_inbox inbox [messages_per_level] let add_new_empty_level ?pred_info inbox = diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml index ac873a87cbbc..c1000c7385d9 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -2653,12 +2653,12 @@ let test_refute_invalid_reveal () = test_refute_set_input p1_info p2_info make_state_before let full_history_inbox (genesis_predecessor_timestamp, genesis_predecessor) - all_external_messages = + all_external_messages attested_slot_headers = let open Sc_rollup_helpers in let payloads_per_levels = List.map (fun (pred_info, level, external_messages) -> - wrap_messages ~pred_info level external_messages) + wrap_messages ~pred_info level external_messages attested_slot_headers) all_external_messages in Sc_rollup_helpers.Node_inbox.construct_inbox @@ -2708,6 +2708,9 @@ let test_automatically_added_internal_messages () = input in + (* TODO: should we inject and attest some DAL slots? *) + let attested_slot_headers = [] in + let assert_sol ~snapshot ~full_history_inbox ~inbox_level = let sol = Sc_rollup_helpers.make_sol ~inbox_level in assert_input_included @@ -2744,7 +2747,12 @@ let test_automatically_added_internal_messages () = in let assert_eol ~snapshot ~full_history_inbox ~inbox_level ~message_counter = - let eol = Sc_rollup_helpers.make_eol ~inbox_level ~message_counter in + let eol = + Sc_rollup_helpers.make_eol + ~inbox_level + ~message_counter + attested_slot_headers + in assert_input_included ~snapshot ~full_history_inbox @@ -2793,6 +2801,7 @@ let test_automatically_added_internal_messages () = full_history_inbox level_zero_info [(level_one_info, level_one, []); (level_two_info, level_two, ["foo"])] + attested_slot_headers in (* Assertions about level 0. *) diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml b/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml index 6acfc9d58ebd..ea85ea3ecd9c 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml @@ -313,6 +313,10 @@ let gen_wasm_pvm_dissection_boundaries kind = in (start_chunk, stop_chunk) +let gen_attested_slot_headers = + let open QCheck2.Gen in + return [] + (** [gen_arith_pvm_messages ~gen_size] is a `correct list` generator. It generates a list of strings that are either integers or `+` to be consumed by the arithmetic PVM. @@ -365,6 +369,7 @@ let gen_arith_pvm_payloads_for_levels ~start_level ~max_level = ~start_level ~max_level (gen_arith_pvm_messages ~gen_size:(QCheck2.Gen.pure 0)) + gen_attested_slot_headers (** Dissection helpers and tests *) module Dissection = struct @@ -1063,8 +1068,12 @@ module Player_client = struct let* messages = small_list (gen_arith_pvm_messages ~gen_size:(pure 0)) in + let* attested_slot_headers = gen_attested_slot_headers in let payloads_at_origination = - Sc_rollup_helpers.wrap_messages metadata.origination_level messages + Sc_rollup_helpers.wrap_messages + metadata.origination_level + messages + attested_slot_headers in let new_payloads_per_levels = payloads_at_origination :: payloads_per_levels diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml index befd6e8f0515..73062c78d838 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml @@ -83,12 +83,18 @@ let gen_versioned_commitment = let gen_player = Gen.oneofl Sc_rollup_game_repr.[Alice; Bob] +(* TODO *) +let gen_attested_slot_headers = + let open Gen in + return [] + let gen_inbox level = let open Gen in let gen_msg = small_string ~gen:printable in let* hd = gen_msg in let* tail = small_list gen_msg in let payloads = hd :: tail in + let* attested_slot_headers = gen_attested_slot_headers in let witness_and_inbox = let open Result_wrap_syntax in let inbox = Sc_rollup_helpers.dumb_init_repr level in @@ -109,7 +115,11 @@ let gen_inbox level = let* witness = Sc_rollup_inbox_repr.add_messages_no_history input_messages witness in - return (Sc_rollup_inbox_repr.finalize_inbox_level_no_history inbox witness) + return + (Sc_rollup_inbox_repr.finalize_inbox_level_no_history + inbox + attested_slot_headers + witness) in return @@ (witness_and_inbox |> function @@ -277,8 +287,9 @@ let gen_inbox_message = let+ s = small_string ~gen:printable in External s in + let attested_slot_headers = [] in let gen_sol = return (Internal Start_of_level) in - let gen_eol = return (Internal End_of_level) in + let gen_eol = return (Internal (End_of_level attested_slot_headers)) in let gen_deposit = (* We won't test the encoding of these values. It's out of scope. *) let payload = Script_repr.unit in diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox.ml index 99a4f2a8c555..05fa68d0ebc3 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox.ml @@ -148,6 +148,11 @@ let gen_payload_string = let open QCheck2.Gen in string_size gen_payload_size +(* TODO *) +let gen_attested_slot_headers = + let open QCheck2.Gen in + return [] + let gen_payload = let open QCheck2.Gen in let+ payload = gen_payload_string in @@ -170,7 +175,7 @@ let gen_payloads_and_index ?min_size ?max_size ?max_index_offset () = return (payloads, index) let gen_payloads_for_level ?(inbox_level = Raw_level.(succ root)) () = - gen_messages inbox_level gen_payload_string + gen_messages inbox_level gen_payload_string gen_attested_slot_headers let gen_level ?(inbox_creation_level = 0) ~max_level () = let open QCheck2.Gen in @@ -195,6 +200,7 @@ let gen_payloads_for_levels ?(inbox_creation_level = 0) ?(max_level = 15) () = ~start_level:(inbox_creation_level + 1) ~max_level gen_payload_string + gen_attested_slot_headers let gen_payloads_for_levels_and_level ?inbox_creation_level ?max_level ?(level_offset = 1) () = @@ -463,8 +469,14 @@ let test_inclusion_proof_verification (payloads_for_levels, level) = let* proof, _node_old_level_messages = Node_inbox.produce_inclusion_proof node_inbox node_inbox_snapshot level in + let attested_slot_headers = [] in + let messages = [] in let*? proto_inbox = - Protocol_inbox.add_new_level ~inbox_creation_level proto_inbox [] + Protocol_inbox.add_new_level + ~inbox_creation_level + proto_inbox + messages + attested_slot_headers in (* This snapshot is not the same one as node_inbox_snapshot because we added an empty level. *) @@ -539,8 +551,14 @@ let test_payloads_proof_invalid_inbox_snapshot (payloads, message_counter) = node_head_cell_hash message_counter in + let mesages = [] in + let attested_slot_headers = [] in let*? proto_inbox = - Protocol_inbox.add_new_level ~inbox_creation_level proto_inbox [] + Protocol_inbox.add_new_level + ~inbox_creation_level + proto_inbox + mesages + attested_slot_headers in (* As we added one level in the [proto_inbox], it is one level further than the [node_inbox]. The proof will not match the history. *) @@ -644,7 +662,10 @@ let test_payloads_proof_incorrect_payload payloads = message_counter in let invalid_proof = - let payload = Some (make_internal_inbox_message End_of_level) in + let attested_slot_headers = [] in + let payload = + Some (make_internal_inbox_message (End_of_level attested_slot_headers)) + in Inbox.Internal_for_tests.{proof with payload} in let head_cell_hash = latest_level_proof_hash proto_inbox in @@ -792,6 +813,7 @@ let test_messages_are_correctly_added_in_history let open Lwt_result_wrap_syntax in let inbox = dumb_init Raw_level.root in let messages = List.map (fun message -> Message.External message) messages in + let attested_slot_headers = [] in let*?@ payloads_history, _history, _inbox, witness, messages = Inbox.add_all_messages ~first_block:false @@ -800,6 +822,7 @@ let test_messages_are_correctly_added_in_history (Inbox.History.empty ~capacity:0L) inbox messages + attested_slot_headers in List.iteri_es (fun i message -> diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox_legacy.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox_legacy.ml index 5bd8daa150a8..5ece5f465ebf 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox_legacy.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_inbox_legacy.ml @@ -74,6 +74,7 @@ let populate_inboxes level history inbox inboxes list_of_messages = let rec aux level history payloads_histories inbox inboxes witness = function | [] -> return (payloads_histories, witness, history, inbox, inboxes) | messages :: ps -> + let attested_slot_headers = [] in let*@ payloads_history, history, inbox, witness, _messages = add_all_messages ~protocol_migration_message:None @@ -82,6 +83,7 @@ let populate_inboxes level history inbox inboxes list_of_messages = history inbox messages + attested_slot_headers in let witness_hash = Sc_rollup_inbox_merkelized_payload_hashes_repr.hash witness @@ -149,6 +151,7 @@ let setup_node_inbox_with_messages list_of_messages f = let rec aux level history payloads_histories inbox inboxes witness = function | [] -> return (payloads_histories, witness, history, inbox, inboxes) | messages :: ps -> + let attested_slot_headers = [] in let*?@ payloads_history, history, inbox, witness, _messages = add_all_messages ~protocol_migration_message:None @@ -157,6 +160,7 @@ let setup_node_inbox_with_messages list_of_messages f = history inbox messages + attested_slot_headers in let witness_hash = Sc_rollup_inbox_merkelized_payload_hashes_repr.hash witness diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml index 84b2f084a82d..f072aa9195e6 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml @@ -166,7 +166,26 @@ let test_encode_decode_internal_inbox_message_sol () = check_encode_decode_inbox_message sol let test_encode_decode_internal_inbox_message_eol () = - let eol = Sc_rollup.Inbox_message.(Internal End_of_level) in + let eol = + Sc_rollup.Inbox_message.( + Internal + (End_of_level + [ + Dal.Slot.Header. + { + source = Signature.Public_key_hash.zero; + header = + { + id = + { + published_level = Raw_level.root; + index = Dal.Slot_index.zero; + }; + commitment = Dal.Slot.Commitment.zero; + }; + }; + ])) + in check_encode_decode_inbox_message eol let test_encode_decode_external_inbox_message () = diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml index be0312e6bf1c..007f6a72cbd1 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml @@ -112,8 +112,13 @@ let test_l1_input_kind () = assert (msg = expected) ; return_unit in + let attested_slot_headers = [] in let* () = check_msg (Internal Start_of_level) (Internal Start_of_level) in - let* () = check_msg (Internal End_of_level) (Internal End_of_level) in + let* () = + check_msg + (Internal (End_of_level attested_slot_headers)) + (Internal End_of_level) + in let* () = check_msg (External "payload") External in return_unit -- GitLab From 5299e84a38fae8d7a898b4e01ef0cc743ece3bec Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 28 Jun 2024 08:04:40 +0200 Subject: [PATCH 2/2] WIP: versionning a little bit complicated --- src/lib_smart_rollup/dal.ml | 42 +++++++++++++++++++ src/lib_smart_rollup_node/pvm_plugin_sig.ml | 2 +- src/proto_alpha/lib_sc_rollup_node/inbox.ml | 15 +++++-- src/proto_alpha/lib_sc_rollup_node/inbox.mli | 3 ++ .../lib_sc_rollup_node/pvm_plugin.ml | 7 +++- .../test/test_octez_conversions.ml | 12 +++++- 6 files changed, 73 insertions(+), 8 deletions(-) diff --git a/src/lib_smart_rollup/dal.ml b/src/lib_smart_rollup/dal.ml index 6fe9eaefb1e6..4106af07d0f1 100644 --- a/src/lib_smart_rollup/dal.ml +++ b/src/lib_smart_rollup/dal.ml @@ -89,6 +89,48 @@ module Slot_header = struct let to_versioned header = V1 header [@@inline] end +module _Extended_sSlot_header = struct + module V1 = struct + type id = {published_level : int32; index : Slot_index.t} + + type t = {id : id; commitment : Commitment.t} + + let id_encoding = + let open Data_encoding in + conv + (fun {published_level; index} -> (published_level, index)) + (fun (published_level, index) -> {published_level; index}) + (obj2 (req "level" int32) (req "index" Slot_index.encoding)) + + let encoding = + let open Data_encoding in + conv + (fun {id; commitment} -> (id, commitment)) + (fun (id, commitment) -> {id; commitment}) + (merge_objs id_encoding (obj1 (req "commitment" Commitment.encoding))) + end + + type versioned = V1 of V1.t + + let versioned_encoding = + let open Data_encoding.V1 in + union + [ + case + ~title:"smart_rollup_dal_slot_header.v1" + (Tag 0) + V1.encoding + (function V1 header -> Some header) + (fun header -> V1 header); + ] + + include V1 + + let of_versioned = function V1 header -> header [@@inline] + + let to_versioned header = V1 header [@@inline] +end + module Slot_history = struct module V1 = struct (* Serialized representation for protocol agnostic slot history *) diff --git a/src/lib_smart_rollup_node/pvm_plugin_sig.ml b/src/lib_smart_rollup_node/pvm_plugin_sig.ml index 4546474e249b..5ed7831aaf38 100644 --- a/src/lib_smart_rollup_node/pvm_plugin_sig.ml +++ b/src/lib_smart_rollup_node/pvm_plugin_sig.ml @@ -118,7 +118,7 @@ module type S = sig val start_of_level_serialized : string - val end_of_level_serialized : string + val end_of_level_serialized : unit list -> string val protocol_migration_serialized : string option diff --git a/src/proto_alpha/lib_sc_rollup_node/inbox.ml b/src/proto_alpha/lib_sc_rollup_node/inbox.ml index 96147fd257f9..d648e4a257d1 100644 --- a/src/proto_alpha/lib_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/lib_sc_rollup_node/inbox.ml @@ -103,7 +103,7 @@ let same_as_layer_1 node_ctxt head_hash inbox = (Sc_rollup_node_errors.Inconsistent_inbox {layer1_inbox; inbox}) let add_messages ~is_first_block ~predecessor_timestamp ~predecessor inbox - messages = + messages attested_slot_headers = let open Lwt_result_syntax in let no_history = Sc_rollup.Inbox.History.empty ~capacity:0L in lift @@ -119,6 +119,7 @@ let add_messages ~is_first_block ~predecessor_timestamp ~predecessor inbox no_history inbox messages + attested_slot_headers in let witness_hash = Sc_rollup.Inbox_merkelized_payload_hashes.hash witness @@ -130,7 +131,8 @@ let add_messages ~is_first_block ~predecessor_timestamp ~predecessor inbox messages_with_protocol_internal_messages ) let process_messages (node_ctxt : _ Node_context.t) ~is_first_block - ~(predecessor : Layer1.header) (head : Layer1.header) messages = + ~(predecessor : Layer1.header) (head : Layer1.header) messages + attested_slot_headers = let open Lwt_result_syntax in let level = head.level in let* inbox = @@ -157,6 +159,7 @@ let process_messages (node_ctxt : _ Node_context.t) ~is_first_block ~predecessor:predecessor.hash inbox messages + attested_slot_headers in Metrics.Inbox.Stats.set messages_with_protocol_internal_messages @@ -187,8 +190,10 @@ let process_messages (node_ctxt : _ Node_context.t) ~is_first_block return (inbox_hash, inbox, witness_hash, messages_with_protocol_internal_messages) +(*attested_slot_headers could be provided by Plugin.Dal_slots_tracker.process_head in + rollup_node_daemon.ml *) let process_head (node_ctxt : _ Node_context.t) ~(predecessor : Layer1.header) - (head : Layer1.header) = + (head : Layer1.header) attested_slot_headers = let open Lwt_result_syntax in let first_inbox_level = node_ctxt.genesis_info.level |> Int32.succ in if head.level >= first_inbox_level then @@ -210,6 +215,7 @@ let process_head (node_ctxt : _ Node_context.t) ~(predecessor : Layer1.header) ~predecessor head collected_messages + attested_slot_headers else let* inbox = Layer1_helpers.genesis_inbox @@ -230,7 +236,7 @@ let process_head (node_ctxt : _ Node_context.t) ~(predecessor : Layer1.header) return (inbox_hash, inbox, witness, []) let payloads_history_of_messages ~is_first_block ~predecessor - ~predecessor_timestamp messages = + ~predecessor_timestamp messages attested_slot_headers = let open Result_syntax in let dummy_inbox = (* The inbox is not necessary to compute the payloads *) @@ -259,6 +265,7 @@ let payloads_history_of_messages ~is_first_block ~predecessor (Sc_rollup.Inbox.History.empty ~capacity:0L) dummy_inbox messages + attested_slot_headers in payloads_history diff --git a/src/proto_alpha/lib_sc_rollup_node/inbox.mli b/src/proto_alpha/lib_sc_rollup_node/inbox.mli index 88766f4b65ba..f25d5627fb55 100644 --- a/src/proto_alpha/lib_sc_rollup_node/inbox.mli +++ b/src/proto_alpha/lib_sc_rollup_node/inbox.mli @@ -44,6 +44,7 @@ val process_head : Node_context.rw -> predecessor:Layer1.header -> Layer1.header -> + Dal.Slot.Header.extended list -> (Octez_smart_rollup.Inbox.Hash.t * Octez_smart_rollup.Inbox.t * Merkelized_payload_hashes_hash.t @@ -60,6 +61,7 @@ val add_messages : predecessor:Block_hash.t -> Inbox.t -> Inbox_message.t list -> + Dal.Slot.Header.extended list -> (Inbox_merkelized_payload_hashes.History.t * Inbox_merkelized_payload_hashes.Hash.t * Inbox.t @@ -77,6 +79,7 @@ val payloads_history_of_messages : predecessor:Block_hash.t -> predecessor_timestamp:Timestamp.time -> string list -> + Dal.Slot.Header.extended list -> Sc_rollup.Inbox_merkelized_payload_hashes.History.t tzresult (** [payloads_history_of_all_messages messages] builds the merkelized payloads diff --git a/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml index 32c81255578e..2bd5ab443a8c 100644 --- a/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml @@ -95,9 +95,12 @@ let start_of_level_serialized = let open Sc_rollup_inbox_message_repr in unsafe_to_string start_of_level_serialized -let end_of_level_serialized = +let end_of_level_serialized attested_slot_headers = + ignore attested_slot_headers ; + (* TODO: Should have a non-proto dependant type for attested_slot_headers ...*) + let attested_slot_headers = assert false in let open Sc_rollup_inbox_message_repr in - unsafe_to_string end_of_level_serialized + unsafe_to_string @@ end_of_level_serialized attested_slot_headers let protocol_migration_serialized = let open Sc_rollup_inbox_message_repr in diff --git a/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml b/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml index d8f5db8cac62..76ecb433ab87 100644 --- a/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml +++ b/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml @@ -146,6 +146,11 @@ let gen_refutation = let+ step = gen_step in Octez_smart_rollup.Game.Move {choice; step} +(* TODO *) +let gen_attested_slot_headers = + let open QCheck2.Gen in + return [] + let gen_inbox = let open Protocol in let open Alpha_context in @@ -156,6 +161,7 @@ let gen_inbox = let payloads = hd :: tail in let* level = gen_level in let level = Raw_level.of_int32_exn level in + let* attested_slot_headers = gen_attested_slot_headers in let witness_and_inbox = let open Result_syntax in let inbox = @@ -181,7 +187,11 @@ let gen_inbox = let* witness = Sc_rollup.Inbox.add_messages_no_history input_messages witness in - return (Sc_rollup.Inbox.finalize_inbox_level_no_history inbox witness) + return + (Sc_rollup.Inbox.finalize_inbox_level_no_history + inbox + attested_slot_headers + witness) in return @@ (witness_and_inbox |> function -- GitLab