diff --git a/src/proto_alpha/lib_protocol/sc_rollup_errors.ml b/src/proto_alpha/lib_protocol/sc_rollup_errors.ml index d3200e2c7d5f15c0280dc38c21cab9e9cbfd6721..2dde9a810fb32bf3419581fe96e0a4f1eca19cb9 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_errors.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_errors.ml @@ -61,7 +61,6 @@ type error += | (* `Temporary *) Sc_rollup_invalid_outbox_message_index | (* `Temporary *) Sc_rollup_outbox_level_expired | (* `Temporary *) Sc_rollup_outbox_message_already_applied - | (* `Temporary *) Sc_rollup_state_change_on_zero_tick_commitment | (* `Temporary *) Sc_rollup_staker_funds_too_low of { staker : Signature.public_key_hash; @@ -71,6 +70,7 @@ type error += } | (* `Temporary *) Sc_rollup_bad_commitment_serialization | (* `Permanent *) Sc_rollup_address_generation + | (* `Permanent *) Sc_rollup_zero_tick_commitment let () = register_error_kind @@ -403,17 +403,6 @@ let () = Data_encoding.empty (function Sc_rollup_outbox_message_already_applied -> Some () | _ -> None) (fun () -> Sc_rollup_outbox_message_already_applied) ; - let description = "Attempt to commit zero ticks with state change" in - register_error_kind - `Temporary - ~id:"Sc_rollup_state_change_on_zero_tick_commitment" - ~title:description - ~description - ~pp:(fun ppf () -> Format.fprintf ppf "%s" description) - Data_encoding.empty - (function - | Sc_rollup_state_change_on_zero_tick_commitment -> Some () | _ -> None) - (fun () -> Sc_rollup_state_change_on_zero_tick_commitment) ; register_error_kind `Temporary ~id:"Sc_rollup_staker_funds_too_low" @@ -468,4 +457,14 @@ let () = ~description Data_encoding.empty (function Sc_rollup_address_generation -> Some () | _ -> None) - (fun () -> Sc_rollup_address_generation) + (fun () -> Sc_rollup_address_generation) ; + let description = "Tried to publish a 0 tick commitment" in + register_error_kind + `Permanent + ~id:"Sc_rollup_zero_tick_commitment" + ~title:description + ~pp:(fun ppf () -> Format.fprintf ppf "%s" description) + ~description + Data_encoding.empty + (function Sc_rollup_zero_tick_commitment -> Some () | _ -> None) + (fun () -> Sc_rollup_zero_tick_commitment) 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 9a3223f557b7b1868e2cec14d8d0c0ef5a81a6e6..b491d5a689b89ce6b3cdb06c125dc549c1633fc8 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_game_repr.ml @@ -695,23 +695,15 @@ let initial inbox dal_snapshot ~start_level ~pvm_name let alice_to_play = Staker.equal alice refuter in let open Sc_rollup_tick_repr in let tick = of_number_of_ticks child.number_of_ticks in - (* TODO: https://gitlab.com/tezos/tezos/-/issues/3974 - 0 tick commitments are impossible with SOL/EOL. *) let game_state = Dissecting { dissection = - (if equal tick initial then - [ - make_chunk (Some child.compressed_state) initial; - make_chunk None (next initial); - ] - else - [ - make_chunk (Some parent.compressed_state) initial; - make_chunk (Some child.compressed_state) tick; - make_chunk None (next tick); - ]); + [ + make_chunk (Some parent.compressed_state) initial; + make_chunk (Some child.compressed_state) tick; + make_chunk None (next tick); + ]; default_number_of_sections; } in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml index 6c388cb6304441d01c79cde4604eb3efc229f572..af8bb11b7ec42dfcd3d5b2ab5183594136ea4efc 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml @@ -169,18 +169,6 @@ let assert_commitment_period ctxt rollup commitment = in return ctxt -let assert_same_hash_as_predecessor ctxt rollup (commitment : Commitment.t) = - let open Lwt_tzresult_syntax in - let* pred, ctxt = - Commitment_storage.get_commitment_unsafe ctxt rollup commitment.predecessor - in - if - Sc_rollup_repr.State_hash.equal - pred.compressed_state - commitment.compressed_state - then return ctxt - else fail Sc_rollup_state_change_on_zero_tick_commitment - (** Check invariants on [inbox_level], enforcing overallocation of storage and regularity of block production. @@ -192,12 +180,7 @@ let assert_refine_conditions_met ctxt rollup lcc commitment = let open Lwt_tzresult_syntax in let* ctxt = assert_commitment_not_too_far_ahead ctxt rollup lcc commitment in let* ctxt = assert_commitment_period ctxt rollup commitment in - if - Sc_rollup_repr.Number_of_ticks.equal - Commitment.(commitment.number_of_ticks) - Sc_rollup_repr.Number_of_ticks.zero - then assert_same_hash_as_predecessor ctxt rollup commitment - else return ctxt + return ctxt let get_commitment_stake_count ctxt rollup node = let open Lwt_tzresult_syntax in @@ -338,6 +321,12 @@ let refine_stake ctxt rollup staker staked_on commitment = let publish_commitment ctxt rollup staker commitment = let open Lwt_tzresult_syntax in + let* () = + fail_when + Sc_rollup_repr.Number_of_ticks.( + commitment.Commitment.number_of_ticks = zero) + Sc_rollup_zero_tick_commitment + in let* ctxt, staked_on_opt = Store.Stakers.find (ctxt, rollup) staker in let* ctxt, balance_updates, staked_on = match staked_on_opt with 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 65804d4e1f74d08068f320f280eda697706b9030..35ad222bcecb92b08a4a9626c30897b9a40e0140 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 @@ -2047,6 +2047,30 @@ let test_sol_and_eol () = return_unit +(** With [Start_of_level] and [End_of_level] inbox messages in each inbox level, + it's impossible to give a valid commitment with 0 ticks. *) +let test_zero_tick_commitment_fails () = + let* ctxt, contract, rollup = init_and_originate Context.T1 "unit" in + let* incr = Incremental.begin_construction ctxt in + let* commitment = dummy_commitment (I incr) rollup in + let commitment = {commitment with number_of_ticks = number_of_ticks_exn 0L} in + let* publish_commitment = + Op.sc_rollup_publish (B ctxt) contract rollup commitment + in + let expect_apply_failure = function + | Environment.Ecoproto_error + (Sc_rollup_errors.Sc_rollup_zero_tick_commitment as e) + :: _ -> + Assert.test_error_encodings e ; + return_unit + | _ -> + failwith "It should have failed with [Sc_rollup_zero_tick_commitment]" + in + let* _incr = + Incremental.add_operation ~expect_apply_failure incr publish_commitment + in + return_unit + let tests = [ Tztest.tztest @@ -2160,4 +2184,8 @@ let tests = "Test that SOL/EOL are added in the inbox" `Quick test_sol_and_eol; + Tztest.tztest + "0-tick commitments are forbidden" + `Quick + test_zero_tick_commitment_fails; ] diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml index 515c13c7834df01038ab604e633650b27953ba21..d9145581820d516dbc943814a482271dee7de979 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml @@ -2312,51 +2312,6 @@ let test_concurrent_refinement_cement () = in assert_commitment_hash_equal ~loc:__LOC__ ctxt c1 c2 -let test_zero_tick_commitment_cannot_change_state () = - let* ctxt, rollup, genesis_hash, staker = - originate_rollup_and_deposit_with_one_staker () - in - let level = valid_inbox_level ctxt in - let commitment = - Commitment_repr. - { - predecessor = genesis_hash; - inbox_level = level 1l; - number_of_ticks = number_of_ticks_exn 1232909L; - compressed_state = Sc_rollup_repr.State_hash.zero; - } - in - let* c1, _level, ctxt = - lift - @@ Sc_rollup_stake_storage.Internal_for_tests.refine_stake - ctxt - rollup - staker - commitment - in - let commitment = - Commitment_repr. - { - predecessor = c1; - inbox_level = level 2l; - number_of_ticks = number_of_ticks_exn 0L; - compressed_state = - Sc_rollup_repr.State_hash.context_hash_to_state_hash - (Context_hash.hash_string ["wxyz"]); - } - in - let* () = - assert_fails_with - ~loc:__LOC__ - (Sc_rollup_stake_storage.Internal_for_tests.refine_stake - ctxt - rollup - staker - commitment) - Sc_rollup_errors.Sc_rollup_state_change_on_zero_tick_commitment - in - assert_true ctxt - let check_gas_consumed ~since ~until = let open Raw_context in let as_cost = Gas_limit_repr.cost_of_gas @@ gas_consumed ~since ~until in @@ -2823,10 +2778,6 @@ let tests = "Refinement operations are commutative (cement)" `Quick test_concurrent_refinement_cement; - Tztest.tztest - "A commitment with zero ticks shouldn't change the state" - `Quick - test_zero_tick_commitment_cannot_change_state; (* TODO: https://gitlab.com/tezos/tezos/-/issues/3978 The number of messages during commitment period is broken with the