From 9b20e156285af78dae3050ff0f950eb929efa8b4 Mon Sep 17 00:00:00 2001 From: Joel Bjornson Date: Thu, 24 Nov 2022 13:11:53 +0000 Subject: [PATCH] Proto/SCORU: carbonate proof valid --- .../lib_protocol/sc_rollup_game_repr.ml | 14 ++++--- .../lib_protocol/sc_rollup_proof_repr.ml | 37 +++++++++++++++++++ .../lib_protocol/sc_rollup_proof_repr.mli | 4 ++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml index 5a7cdeddd2a9..2f218ea465ca 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml @@ -824,23 +824,27 @@ let cost_check_proof_start_stop = (* TODO: https://gitlab.com/tezos/tezos/-/issues/2926 This function is incomplete and needs to account for additional gas. *) -let cost_play ~number_of_sections _game refutation = +let cost_play ~number_of_sections game refutation = let tick_size = Sc_rollup_tick_repr.size_in_bytes refutation.choice in let cost_find_tick = Sc_rollup_costs.cost_find_tick ~number_of_sections ~tick_size in let cost_refutation = - match refutation.step with - | Dissection states -> + match (refutation.step, game.game_state) with + | Dissection states, Dissecting _ -> let number_of_states = List.length states in let hash_size = State_hash.size in Sc_rollup_costs.cost_check_dissection ~number_of_states ~tick_size ~hash_size - | Proof _proof -> cost_check_proof_start_stop + | Proof proof, Dissecting _ -> + let cost_valid = + Sc_rollup_proof_repr.cost_valid proof proof.input_proof + in + Gas_limit_repr.(cost_valid +@ cost_check_proof_start_stop) + | _ -> Gas_limit_repr.free in - Gas_limit_repr.(cost_find_tick +@ cost_refutation) let play dal_parameters ~dal_attestation_lag ~stakers metadata game refutation = 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 4dd15a754a49..287704dd1447 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml @@ -347,6 +347,43 @@ let valid ~metadata snapshot commit_level dal_snapshot dal_parameters in return (input, input_requested) +(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3290 + This needs to implemented. *) +let cost_check_inbox_proof _inbox_proof = Gas_limit_repr.free + +(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3290 + This needs to implemented. *) +let cost_verify_dal_proof _proof = Gas_limit_repr.free + +(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3290 + This needs to implemented. *) +let cost_verify_proof _proof = Gas_limit_repr.free + +let cost_valid_input_proof input_proof_opt = + match input_proof_opt with + | Some (Inbox_proof {level = _; message_counter = _; proof}) -> + cost_check_inbox_proof proof + | Some First_inbox_message -> Gas_limit_repr.free + | Some (Reveal_proof (Raw_data_proof _)) -> Gas_limit_repr.free + | Some (Reveal_proof Metadata_proof) -> Gas_limit_repr.free + | Some (Reveal_proof (Dal_page_proof {proof; page_id = _})) -> + cost_verify_dal_proof proof + | None -> Gas_limit_repr.free + +(* The cost is calculated by mirroring the structure of [valid]. *) +let cost_valid proof input_proof_opt = + let (module P) = Sc_rollups.wrapped_proof_module proof.pvm_step in + let cost_valid_input_proof = cost_valid_input_proof input_proof_opt in + let cost_verify_proof = cost_verify_proof P.proof in + (* FIXME: https://gitlab.com/tezos/tezos/-/issues/3290 + Here we also need to account for work involved in validating input proof + and input request. In particular hashing reveal hash data. However we + need to know the input proof here which we do not have access to. + Possible solution: split [valid] in two parts. *) + let cost_valid_input = Gas_limit_repr.free in + Gas_limit_repr.( + cost_valid_input_proof +@ cost_valid_input +@ cost_verify_proof) + module type PVM_with_context_and_state = sig include Sc_rollups.PVM.S 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 652b28109f4e..e11386e993f4 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.mli @@ -146,6 +146,10 @@ val valid : (Sc_rollup_PVM_sig.input option * Sc_rollup_PVM_sig.input_request) tzresult Lwt.t +(** [cost_valid history_proof level ~pvm_name proof inbox_proof] + returns the cost of refutation proof validation. *) +val cost_valid : t -> input_proof option -> Gas_limit_repr.cost + module type PVM_with_context_and_state = sig include Sc_rollups.PVM.S -- GitLab