diff --git a/src/proto_alpha/lib_protocol/sc_rollup_costs.ml b/src/proto_alpha/lib_protocol/sc_rollup_costs.ml index b8730fe59aa43edbb99f180e282af7a10b6f0fec..9751714933c2de2596164da327ac85a0369e4e50 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_costs.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_costs.ml @@ -155,3 +155,6 @@ let cost_check_dissection ~number_of_states ~tick_size ~hash_size = let open S_syntax in cost_search_in_tick_list number_of_states tick_size + (S.safe_int 2 * cost_compare hash_size hash_size) + +let cost_find_tick ~number_of_sections ~tick_size = + cost_search_in_tick_list number_of_sections tick_size diff --git a/src/proto_alpha/lib_protocol/sc_rollup_costs.mli b/src/proto_alpha/lib_protocol/sc_rollup_costs.mli index f4c05fe05e46c4387efeda7c1d6c1237d4ec7693..a252b2030ba2b393601ddd7651ede55a81986b25 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_costs.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_costs.mli @@ -88,3 +88,8 @@ val cost_hash_bytes : bytes_len:int -> Gas_limit_repr.cost [hash_size]. *) val cost_check_dissection : number_of_states:int -> tick_size:int -> hash_size:int -> Gas_limit_repr.cost + +(** [cost_find_tick ~number_of_sections ~tick_size] is the cost of searching + for a tick of a give [tick_size] within a given [number_of_sections]. *) +val cost_find_tick : + number_of_sections:int -> tick_size:int -> Gas_limit_repr.cost 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 795b37cc9b5ce95af1e977aa81795a265881a72b..d7d6bdb4f6549ed56be0330d270606ae34f5f6d7 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml @@ -819,17 +819,23 @@ let loser_of_results ~alice_result ~bob_result = (* TODO: https://gitlab.com/tezos/tezos/-/issues/2926 This function is incomplete and needs to account for additional gas. *) -let cost_play _game refutation = - match refutation.step with - | Dissection states -> - let number_of_states = List.length states in - let hash_size = State_hash.size in - let tick_size = Sc_rollup_tick_repr.size_in_bytes refutation.choice in - Sc_rollup_costs.cost_check_dissection - ~number_of_states - ~tick_size - ~hash_size - | Proof _proof -> Gas_limit_repr.free +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 -> + 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 -> Gas_limit_repr.free + in + Gas_limit_repr.(cost_find_tick +@ cost_refutation) let play dal_parameters ~dal_attestation_lag ~stakers metadata game refutation = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.mli index 0043e309c4b2220cdc1901040c51809b180399a8..f3f9b57fa98e26e85bb1997e32fbb9f0b6fbab8d 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.mli @@ -410,9 +410,9 @@ type timeout = { val timeout_encoding : timeout Data_encoding.t -(** [cost_play game refutation] returns the gas cost of [play] applied with [game] - and [refutation]. *) -val cost_play : t -> refutation -> Gas_limit_repr.cost +(** [cost_play ~number_of_sections game refutation] returns the gas cost of + [play] applied with [game] and [refutation]. *) +val cost_play : number_of_sections:int -> t -> refutation -> Gas_limit_repr.cost module Internal_for_tests : sig (** Checks that the tick count chosen by the current move is one of diff --git a/src/proto_alpha/lib_protocol/sc_rollup_refutation_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_refutation_storage.ml index 75cb7b984a3daa250fc1bc0dba51aa4adfdac2f8..ccbae7af815d67afc68a717333814b4059e6676c 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_refutation_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_refutation_storage.ml @@ -295,7 +295,12 @@ let game_move ctxt rollup ~player ~opponent refutation = in let* ctxt, metadata = Sc_rollup_storage.get_metadata ctxt rollup in let dal = (Constants_storage.parametric ctxt).dal in - let play_cost = Sc_rollup_game_repr.cost_play game refutation in + let number_of_sections = + (Raw_context.sc_rollup ctxt).number_of_sections_in_dissection + in + let play_cost = + Sc_rollup_game_repr.cost_play ~number_of_sections game refutation + in let*? ctxt = Raw_context.consume_gas ctxt play_cost in let* move_result = Sc_rollup_game_repr.play