diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 01986e45060ec5ef803e83f44ebf66f724681cfe..88edffccba01453023d3df99863235b839416bc8 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2995,9 +2995,6 @@ module Sc_rollup : sig val number_of_proof_steps : inclusion_proof -> int - val produce_inclusion_proof : - history -> history_proof -> history_proof -> inclusion_proof option - val verify_inclusion_proof : inclusion_proof -> history_proof -> history_proof -> bool @@ -3030,6 +3027,9 @@ module Sc_rollup : sig val history_at_genesis : capacity:int64 -> next_index:int64 -> history val history_hashes : history -> Hash.t list + + val produce_inclusion_proof : + history -> history_proof -> history_proof -> inclusion_proof option end end 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 1dd1bc29f4915369cebfba0365c7758349fd0940..070423ab855202e468a46c3ff6b2111a286f4558 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml @@ -448,9 +448,6 @@ module type Merkelized_operations = sig val number_of_proof_steps : inclusion_proof -> int - val produce_inclusion_proof : - history -> history_proof -> history_proof -> inclusion_proof option - val verify_inclusion_proof : inclusion_proof -> history_proof -> history_proof -> bool @@ -483,6 +480,9 @@ module type Merkelized_operations = sig val history_at_genesis : capacity:int64 -> next_index:int64 -> history val history_hashes : history -> Hash.t list + + val produce_inclusion_proof : + history -> history_proof -> history_proof -> inclusion_proof option end end @@ -829,22 +829,13 @@ struct let number_of_proof_steps proof = List.length proof - let lift_ptr_path history ptr_path = + let lift_ptr_path deref ptr_path = let rec aux accu = function | [] -> Some (List.rev accu) - | x :: xs -> Option.bind (history x) @@ fun c -> aux (c :: accu) xs + | x :: xs -> Option.bind (deref x) @@ fun c -> aux (c :: accu) xs in aux [] ptr_path - let produce_inclusion_proof history a b = - let cell_ptr = hash_skip_list_cell b in - let target_index = Skip_list.index a in - let history = remember cell_ptr b history in - let deref ptr = Hash.Map.find_opt ptr history.events in - Skip_list.back_path ~deref ~cell_ptr ~target_index - |> Option.map (lift_ptr_path deref) - |> Option.join - let verify_inclusion_proof proof a b = let assoc = List.map (fun c -> (hash_skip_list_cell c, c)) proof in let path = List.split assoc |> fst in @@ -1304,6 +1295,15 @@ struct in (* do a tail recursive concatenation lp @ ln *) List.rev_append (List.rev lp) ln + + let produce_inclusion_proof history a b = + let cell_ptr = hash_skip_list_cell b in + let target_index = Skip_list.index a in + let history = remember cell_ptr b history in + let deref ptr = Hash.Map.find_opt ptr history.events in + Skip_list.back_path ~deref ~cell_ptr ~target_index + |> Option.map (lift_ptr_path deref) + |> Option.join end end 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 74c5bbad7f44699a16f30fdb7a8618e39efff583..9940a5c91548711bbaa270ae777d93ba23984b39 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.mli @@ -343,11 +343,6 @@ module type Merkelized_operations = sig (** [number_of_proof_steps proof] returns the length of [proof]. *) val number_of_proof_steps : inclusion_proof -> int - (** [produce_inclusion_proof history a b] exploits [history] to produce - a self-contained proof that [a] is an older version of [b]. *) - val produce_inclusion_proof : - history -> history_proof -> history_proof -> inclusion_proof option - (** [verify_inclusion_proof proof a b] returns [true] iff [proof] is a minimal and valid proof that [a] is included in [b]. *) val verify_inclusion_proof : @@ -416,6 +411,11 @@ module type Merkelized_operations = sig (** [history_hashes history] returns the keys of the entries stored in [history] in the order of their insertions. *) val history_hashes : history -> Hash.t list + + (** [produce_inclusion_proof history a b] exploits [history] to produce + a self-contained proof that [a] is an older version of [b]. *) + val produce_inclusion_proof : + history -> history_proof -> history_proof -> inclusion_proof option end end 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 b14aa2dbc9492c49b3c0c60837605b4d495bbff6..7c9e8a005be2386563027a7da06758f60ea90493 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 @@ -141,7 +141,7 @@ let test_inclusion_proof_production (list_of_payloads, n) = @@ fun _ctxt _messages history _inbox inboxes -> let inbox = Stdlib.List.hd inboxes in let old_inbox = Stdlib.List.nth inboxes n in - produce_inclusion_proof + Internal_for_tests.produce_inclusion_proof history (old_levels_messages old_inbox) (old_levels_messages inbox) @@ -164,7 +164,7 @@ let test_inclusion_proof_verification (list_of_payloads, n) = @@ fun _ctxt _messages history _inbox inboxes -> let inbox = Stdlib.List.hd inboxes in let old_inbox = Stdlib.List.nth inboxes n in - produce_inclusion_proof + Internal_for_tests.produce_inclusion_proof history (old_levels_messages old_inbox) (old_levels_messages inbox) @@ -599,9 +599,15 @@ let test_inclusion_proofs_depending_on_history_capacity (* Producing inclusion proofs using history1 and history2 should succeeed. But, we should not be able to produce any proof with history0 as bound is 0. *) - let ip0 = I.produce_inclusion_proof history0 hp hp in - let*? ip1 = proof "history1" @@ I.produce_inclusion_proof history1 hp hp in - let*? ip2 = proof "history2" @@ I.produce_inclusion_proof history2 hp hp in + let ip0 = I.Internal_for_tests.produce_inclusion_proof history0 hp hp in + let*? ip1 = + proof "history1" + @@ I.Internal_for_tests.produce_inclusion_proof history1 hp hp + in + let*? ip2 = + proof "history2" + @@ I.Internal_for_tests.produce_inclusion_proof history2 hp hp + in let* () = fail_unless (Option.is_none ip0)