diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index d4357ace7c520c2ba9b630463579b58a40a5f7d3..b93fcf10c081cd698116fbef5ecf3aa47baec877 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -47,9 +47,14 @@ Smart Rollups checks if it needs to upgrade to a new revision when it receives a ``Protocol_migration`` message. (MR :gl:`!7730`) -- Remove the failsafe mechanism in inbox construction, aimed at errors that can +- Remove the failsafe mechanism in inbox construction, aimed at errors that can never happen at begin application, block finalization, and migration. (MR :gl:`!7833`) +- The field ``commitment`` in the operation ``Sc_rollup_cement`` is now deprecated. + The protocol computes the valid candidate commitment to cement, and cements it. + The provided ``commitment`` is omitted by the protocol and unchecked with the + found one. (MR :gl:`!7316`) + Zero Knowledge Rollups (ongoing) -------------------------------- @@ -96,6 +101,10 @@ p256 (tz3) 1091 gas units bls (tz4) 1671 gas units ================ ============================ +- The operation's result ``Sc_rollup_cement_result`` now have a new field + ``commitment``, which is the commitment cemented by the application of + the operation ``Sc_rollup_cement``. (MR :gl:`!7316`) + RPC Changes ----------- diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index dcf4efccd306c73512a0abc7996836692ff8d6c8..4002faebb7da7f05fff15bbcdf40a31b6a6723f9 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -638,9 +638,15 @@ let pp_manager_operation_contents_result ppf op_result = pp_consumed_gas ppf consumed_gas in let pp_sc_rollup_cement_result - (Sc_rollup_cement_result {consumed_gas; inbox_level}) = + (Sc_rollup_cement_result {consumed_gas; inbox_level; commitment_hash}) = pp_consumed_gas ppf consumed_gas ; - Format.fprintf ppf "@,Inbox level: %a" Raw_level.pp inbox_level + Format.fprintf + ppf + "@,Inbox level: %a@,Commitment hash: %a" + Raw_level.pp + inbox_level + Sc_rollup.Commitment.Hash.pp + commitment_hash in let pp_sc_rollup_publish_result (Sc_rollup_publish_result diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 0ca0a7bb72d0d4464adc0a713f6010b9f10b8786..1a4e65e795415578106c68ef683474f6f6c53c87 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -2458,13 +2458,14 @@ module Sc_rollup = struct S.can_be_cemented (fun context rollup commitment_hash () () -> let open Lwt_result_syntax in - let*! res = - Sc_rollup.Stake_storage.cement_commitment - context - rollup - commitment_hash - in - match res with Ok _context -> return_true | Error _ -> return_false) + let*! res = Sc_rollup.Stake_storage.cement_commitment context rollup in + match res with + | Ok (_context, _cemented_commitment, cemented_commitment_hash) + when Sc_rollup.Commitment.Hash.equal + commitment_hash + cemented_commitment_hash -> + return_true + | Ok _ | Error _ -> return_false) let register () = register_kind () ; diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 56b0b87233ad8f8fcfd12fcf001430eddd0aae86..aca56e81eeb423f9682ba33b0b2549b1a2d5fa96 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4155,8 +4155,7 @@ module Sc_rollup : sig val cement_commitment : context -> t -> - Commitment.Hash.t -> - (context * Commitment.t) tzresult Lwt.t + (context * Commitment.t * Commitment.Hash.t) tzresult Lwt.t val withdraw_stake : context -> diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 6dc4e265141432f316b7cb7a60414544522a7f78..1f6f7ab75e98f44f1b01f31976cc71ee04132d1b 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1145,13 +1145,18 @@ let apply_manager_operation : let consumed_gas = Gas.consumed ~since:ctxt_before_op ~until:ctxt in let result = Sc_rollup_add_messages_result {consumed_gas} in return (ctxt, result, []) - | Sc_rollup_cement {rollup; commitment} -> - Sc_rollup.Stake_storage.cement_commitment ctxt rollup commitment - >>=? fun (ctxt, commitment) -> + | Sc_rollup_cement {rollup; commitment = _commitment_hash} -> + (* The field [commitment] is deprecated. It is not used during the + application of [Sc_rollup_cement]. The commitment to cement is + computed by the protocol. + + It is deprecated starting N, and can be removed in O. *) + Sc_rollup.Stake_storage.cement_commitment ctxt rollup + >>=? fun (ctxt, commitment, commitment_hash) -> let consumed_gas = Gas.consumed ~since:ctxt_before_op ~until:ctxt in let result = Sc_rollup_cement_result - {consumed_gas; inbox_level = commitment.inbox_level} + {consumed_gas; inbox_level = commitment.inbox_level; commitment_hash} in return (ctxt, result, []) | Sc_rollup_publish {rollup; commitment} -> diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index d012b62a4eee200d46a1afa00a9ddddbcaa01836..64c4e0d6c00a1e98f6e76f95e8c2dcb87ba5058d 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -97,6 +97,7 @@ type _ successful_manager_operation_result = | Sc_rollup_cement_result : { consumed_gas : Gas.Arith.fp; inbox_level : Raw_level.t; + commitment_hash : Sc_rollup.Commitment.Hash.t; } -> Kind.sc_rollup_cement successful_manager_operation_result | Sc_rollup_publish_result : { @@ -715,18 +716,20 @@ module Manager_result = struct make ~op_case:Operation.Encoding.Manager_operations.sc_rollup_cement_case ~encoding: - (obj2 + (obj3 (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) - (req "inbox_level" Raw_level.encoding)) + (req "inbox_level" Raw_level.encoding) + (req "commitment_hash" Sc_rollup.Commitment.Hash.encoding)) ~select:(function | Successful_manager_result (Sc_rollup_cement_result _ as op) -> Some op | _ -> None) ~proj:(function - | Sc_rollup_cement_result {consumed_gas; inbox_level} -> - (consumed_gas, inbox_level)) + | Sc_rollup_cement_result {consumed_gas; inbox_level; commitment_hash} + -> + (consumed_gas, inbox_level, commitment_hash)) ~kind:Kind.Sc_rollup_cement_manager_kind - ~inj:(fun (consumed_gas, inbox_level) -> - Sc_rollup_cement_result {consumed_gas; inbox_level}) + ~inj:(fun (consumed_gas, inbox_level, commitment_hash) -> + Sc_rollup_cement_result {consumed_gas; inbox_level; commitment_hash}) let sc_rollup_publish_case = make diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 2729970303a1cc9e6c9b0b9b3d06092a732334a1..6011179e6dd9236af91bcc7fbe9e7d13de8e3ae2 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -200,6 +200,7 @@ and _ successful_manager_operation_result = | Sc_rollup_cement_result : { consumed_gas : Gas.Arith.fp; inbox_level : Raw_level.t; + commitment_hash : Sc_rollup.Commitment.Hash.t; } -> Kind.sc_rollup_cement successful_manager_operation_result | Sc_rollup_publish_result : { diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 05a085383a5c895e86227b0027842b2ab76bcfb3..5d5d989b59ebfe97fdf3fd5f1ca07bd23052f0ad 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -897,7 +897,12 @@ module Encoding = struct encoding = obj2 (req "rollup" Sc_rollup_repr.encoding) - (req "commitment" Sc_rollup_commitment_repr.Hash.encoding); + (req + ~description: + "DEPRECATED: This field is not used anymore by the protocol \ + and will be removed in a future proposal." + "commitment" + Sc_rollup_commitment_repr.Hash.encoding); select = (function | Manager (Sc_rollup_cement _ as op) -> Some op | _ -> None); diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index c0fd76a16e8f7e13ea2712b0f0f644f0001f696b..14d1afd6eb8239e303ebfaf52b8ed082bc45627e 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -437,6 +437,11 @@ and _ manager_operation = | Sc_rollup_cement : { rollup : Sc_rollup_repr.t; commitment : Sc_rollup_commitment_repr.Hash.t; + (** The field [commitment] is deprecated. It is not used during the + application of [Sc_rollup_cement]. The commitment to cement is + computed by the protocol. + + It is deprecated starting N, and can be removed in O. *) } -> Kind.sc_rollup_cement manager_operation | Sc_rollup_publish : { diff --git a/src/proto_alpha/lib_protocol/sc_rollup_errors.ml b/src/proto_alpha/lib_protocol/sc_rollup_errors.ml index 80fbbbe59c3112eed75940032fed02b3c9e8c323..822040858a09c4769ac0c4b0f9c4c4077e7cc869 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_errors.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_errors.ml @@ -89,11 +89,6 @@ type error += | (* `Permanent *) Sc_rollup_wrong_staker_for_conflict_commitment of Signature.public_key_hash * Sc_rollup_commitment_repr.Hash.t - | (* `Permanent *) - Sc_rollup_invalid_commitment_to_cement of { - valid_candidate : Sc_rollup_commitment_repr.Hash.t; - invalid_candidate : Sc_rollup_commitment_repr.Hash.t; - } | (* `Permanent *) Sc_rollup_commitment_too_old of { last_cemented_inbox_level : Raw_level_repr.t; @@ -620,35 +615,6 @@ let () = | _ -> None) (fun (staker, commitment) -> Sc_rollup_wrong_staker_for_conflict_commitment (staker, commitment)) ; - let description = "Given commitment cannot be cemented" in - register_error_kind - `Permanent - ~id:"smart_rollup_invalid_commitment_to_cement" - ~title:description - ~pp:(fun ppf (valid_candidate, invalid_candidate) -> - Format.fprintf - ppf - "The commitment %a cannot be cemented. %a is a valid candidate to \ - cementation, but %a is not." - Sc_rollup_commitment_repr.Hash.pp - invalid_candidate - Sc_rollup_commitment_repr.Hash.pp - valid_candidate - Sc_rollup_commitment_repr.Hash.pp - invalid_candidate) - ~description - Data_encoding.( - obj2 - (req "valid_candidate" Sc_rollup_commitment_repr.Hash.encoding) - (req "invalid_candidate" Sc_rollup_commitment_repr.Hash.encoding)) - (function - | Sc_rollup_invalid_commitment_to_cement - {valid_candidate; invalid_candidate} -> - Some (valid_candidate, invalid_candidate) - | _ -> None) - (fun (valid_candidate, invalid_candidate) -> - Sc_rollup_invalid_commitment_to_cement - {valid_candidate; invalid_candidate}) ; let description = "Published commitment is too old" in register_error_kind 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 56c3a0e6180b99e1f877a7732eb2da98aee5e311..0d9e6eb38f996758b83cd49454758802da92ef33 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml @@ -600,107 +600,86 @@ let is_cementable_candidate_commitment ctxt rollup lcc commitment_hash = in (* The commitment is active if its predecessor is the LCC and at least one active steaker has staked on it. *) - return (ctxt, Compare.List_length_with.(active_stakers_index > 0)) + let commitment = + if Compare.List_length_with.(active_stakers_index > 0) then + Some commitment + else None + in + return (ctxt, commitment) else (* Dangling commitment. *) - return (ctxt, false) + return (ctxt, None) let cementable_candidate_commitments_of_inbox_level ctxt rollup ~old_lcc - ~new_lcc inbox_level = + inbox_level = let open Lwt_result_syntax in let* ctxt, commitments = Commitments_per_inbox_level.get ctxt rollup inbox_level in - match commitments with - | [candidate_commitment] when Commitment_hash.(new_lcc = candidate_commitment) - -> - (* The check that [new_lcc.predecessor = old] is done by the caller. - In 99.99% of cases there will be only one candidate commitment, - we minimize the cost in this case. *) - let* ctxt, stakers_on_commitment = - Commitment_stakers.get ctxt rollup candidate_commitment - in - let* ctxt, active_stakers_index_on_commitment = - active_stakers_index ctxt rollup stakers_on_commitment + List.fold_left_es + (fun (ctxt, candidate_commitments, dangling_commitments) commitment_hash -> + let* ctxt, candidate_commitment = + is_cementable_candidate_commitment ctxt rollup old_lcc commitment_hash in - if Compare.List_length_with.(active_stakers_index_on_commitment > 0) then - return (ctxt, [candidate_commitment], []) - else return (ctxt, [], [candidate_commitment]) - | commitments -> - List.fold_left_es - (fun (ctxt, candidate_commitments, dangling_commitments) commitment -> - let* ctxt, is_candidate = - is_cementable_candidate_commitment ctxt rollup old_lcc commitment - in - if is_candidate then - return - (ctxt, commitment :: candidate_commitments, dangling_commitments) - else - return - (ctxt, candidate_commitments, commitment :: dangling_commitments)) - (ctxt, [], []) - commitments - -(** [assert_cement_commitment_met ctxt rollup ~old_lcc new_lcc] asserts that - the following list of properties are respected: - + match candidate_commitment with + | Some commitment -> + return + ( ctxt, + (commitment, commitment_hash) :: candidate_commitments, + dangling_commitments ) + | None -> + return + ( ctxt, + candidate_commitments, + commitment_hash :: dangling_commitments )) + (ctxt, [], []) + commitments + +(** [find_commitment_to_cement ctxt rollup ~old_lcc new_lcc_level] tries to find + the commitment to cement at inbox level [new_lcc_level]. + + A commitment can be cemented if: {ol - {li The [new_lcc]'s predecessor is the LCC.} + {li The commitment's predecessor is the LCC.} {li The challenge window period is over.} - {li [new_lcc] is the only active commitment.} + {li The commitment is the only active commitment.} } *) -let assert_cement_commitment_met ctxt rollup ~old_lcc ~new_lcc = +let find_commitment_to_cement ctxt rollup ~old_lcc new_lcc_level = let open Lwt_result_syntax in - (* Checks that the commitment's predecessor is the LCC. *) - let* new_lcc_commitment, ctxt = - Commitment_storage.get_commitment_unsafe ctxt rollup new_lcc - in - let* () = - fail_unless - Commitment_hash.(new_lcc_commitment.predecessor = old_lcc) - Sc_rollup_parent_not_lcc - in - (* Checks that the commitment is past the challenge window. *) - let* ctxt, new_lcc_added = - Store.Commitment_added.get (ctxt, rollup) new_lcc - in - let* () = - let challenge_windows_in_blocks = - Constants_storage.sc_rollup_challenge_window_in_blocks ctxt - in - let current_level = (Raw_context.current_level ctxt).level in - let min_level = - Raw_level_repr.add new_lcc_added challenge_windows_in_blocks - in - fail_when - Raw_level_repr.(current_level < min_level) - (Sc_rollup_commitment_too_recent {current_level; min_level}) - in (* Checks that the commitment is the only active commitment. *) let* ctxt, candidate_commitments, dangling_commitments = cementable_candidate_commitments_of_inbox_level ctxt rollup ~old_lcc - ~new_lcc - new_lcc_commitment.inbox_level + new_lcc_level in match candidate_commitments with (* A commitment can be cemented if there is only one valid - commitment, and it matches the commitment provided. The - commitment provided is then not strictly required. *) - | [candidate_commitment] -> - if Commitment_hash.equal candidate_commitment new_lcc then - return (ctxt, new_lcc_commitment, dangling_commitments) - else - tzfail - (Sc_rollup_invalid_commitment_to_cement - { - valid_candidate = candidate_commitment; - invalid_candidate = new_lcc; - }) - | [] -> - tzfail (Sc_rollup_no_commitment_to_cement new_lcc_commitment.inbox_level) + commitment. *) + | [(candidate_commitment, candidate_commitment_hash)] -> + let* ctxt, candidate_commitment_added = + Store.Commitment_added.get (ctxt, rollup) candidate_commitment_hash + in + (* Checks that the commitment is past the challenge window. *) + let* () = + let challenge_windows_in_blocks = + Constants_storage.sc_rollup_challenge_window_in_blocks ctxt + in + let current_level = (Raw_context.current_level ctxt).level in + let min_level = + Raw_level_repr.add + candidate_commitment_added + challenge_windows_in_blocks + in + fail_when + Raw_level_repr.(current_level < min_level) + (Sc_rollup_commitment_too_recent {current_level; min_level}) + in + return + ( ctxt, + (candidate_commitment, candidate_commitment_hash), + dangling_commitments ) | _ -> tzfail Sc_rollup_disputed let deallocate_inbox_level ctxt rollup inbox_level new_lcc_hash @@ -749,18 +728,25 @@ let update_saved_cemented_commitments ctxt rollup old_lcc = rollup too_old_cemented_commitment_hash -let cement_commitment ctxt rollup new_lcc = +let cement_commitment ctxt rollup = let open Lwt_result_syntax in - let* old_lcc, ctxt = - Commitment_storage.last_cemented_commitment ctxt rollup + let* old_lcc, old_lcc_level, ctxt = + Commitment_storage.last_cemented_commitment_hash_with_level ctxt rollup + in + let sc_rollup_commitment_period = + Constants_storage.sc_rollup_commitment_period_in_blocks ctxt + in + let new_lcc_level = + Raw_level_repr.add old_lcc_level sc_rollup_commitment_period in (* Assert conditions to cement are met. *) - let* ctxt, new_lcc_commitment, dangling_commitments = - assert_cement_commitment_met ctxt rollup ~old_lcc ~new_lcc + let* ctxt, (new_lcc_commitment, new_lcc_commitment_hash), dangling_commitments + = + find_commitment_to_cement ctxt rollup ~old_lcc new_lcc_level in (* Update the LCC. *) let* ctxt, _size_diff = - Store.Last_cemented_commitment.update ctxt rollup new_lcc + Store.Last_cemented_commitment.update ctxt rollup new_lcc_commitment_hash in (* Clean the storage. *) let* ctxt = @@ -768,12 +754,12 @@ let cement_commitment ctxt rollup new_lcc = ctxt rollup new_lcc_commitment.inbox_level - new_lcc + new_lcc_commitment_hash dangling_commitments in (* Update the saved cemented commitments. *) let* ctxt = update_saved_cemented_commitments ctxt rollup old_lcc in - return (ctxt, new_lcc_commitment) + return (ctxt, new_lcc_commitment, new_lcc_commitment_hash) let remove_staker ctxt rollup staker = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.mli index afc6d1d56fba9ed28854a29881be49e114099f0e..43a13c71e3c1c89c0ff67890cd886cb691a9cb81 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.mli @@ -72,10 +72,12 @@ val publish_commitment : tzresult Lwt.t -(** [cement_commitment context rollup commitment] cements the given - commitment whose hash is given (and returns the corresponding commitment). +(** [cement context rollup] tries to cement the next inbox level commitment, + that is, the LCC's successor. Returns the cemented commitment hash and + its hash. - For cementing to succeed, the following must hold: + For cementing to succeed, we need to have **one** commitment respecting + the following properties: {ol {li The deadline for [commitment] must have passed.} {li The predecessor of [commitment] must be the Last Cemented Commitment.} @@ -83,7 +85,7 @@ val publish_commitment : {li All stakers must be indirectly staked on [commitment].} } - If successful, Last Cemented commitment is set to the given [commitment], + If successful, Last Cemented commitment is set to the found commitment, and deallocate the old cemented commitment accordingly to the number of stored cemented commitments. @@ -92,8 +94,11 @@ val publish_commitment : val cement_commitment : Raw_context.t -> Sc_rollup_repr.t -> - Sc_rollup_commitment_repr.Hash.t -> - (Raw_context.t * Sc_rollup_commitment_repr.t) tzresult Lwt.t + (Raw_context.t + * Sc_rollup_commitment_repr.t + * Sc_rollup_commitment_repr.Hash.t) + tzresult + Lwt.t (** [find_staker context rollup staker] returns the most recent commitment [staker] staked on, or [None] if its last staked commitment is older 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 9f034e3582b5543cc57d6d7315dd9ae3623a776d..dd7d62a3728b0c74e0b3ad68523449e94fbee8c9 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 @@ -417,27 +417,24 @@ let publish_commitments ctxt rollup staker commitments = ctxt commitments -let cement_commitment ctxt rollup commitment hash = +let cement_commitment ctxt rollup commitment = let open Lwt_result_syntax in let* ctxt = advance_level_for_cement ctxt rollup commitment in - let* ctxt, _commitment = - Sc_rollup_stake_storage.cement_commitment ctxt rollup hash + let* ctxt, _commitment, _commitment_hash = + Sc_rollup_stake_storage.cement_commitment ctxt rollup in return ctxt let cement_commitments ctxt rollup commitments = List.fold_left_es - (fun ctxt commitment -> - let hash = Commitment_repr.hash_uncarbonated commitment in - cement_commitment ctxt rollup commitment hash) + (fun ctxt commitment -> cement_commitment ctxt rollup commitment) ctxt commitments let publish_and_cement_commitment ctxt rollup staker commitment = let open Lwt_result_syntax in - let hash = Commitment_repr.hash_uncarbonated commitment in let* ctxt = publish_commitment ctxt rollup staker commitment in - cement_commitment ctxt rollup commitment hash + cement_commitment ctxt rollup commitment let publish_and_cement_commitments ctxt rollup staker commitments = List.fold_left_es @@ -893,7 +890,7 @@ module Stake_storage_tests = struct commitment ~predecessor:genesis_hash ~inbox_level:level1 () in let*@ ctxt = publish_commitment ctxt rollup staker commitment1 in - let*@ ctxt = cement_commitment ctxt rollup commitment1 hash in + let*@ ctxt = cement_commitment ctxt rollup commitment1 in let commitment2, _hash = commitment ~predecessor:hash ~inbox_level:level2 () in @@ -993,7 +990,7 @@ module Stake_storage_tests = struct let* ctxt, rollup, genesis_hash, staker = originate_rollup_and_deposit_with_one_staker () in - let commitment, hash = + let commitment, _hash = commitment ~predecessor:genesis_hash ~inbox_level:(valid_inbox_level ctxt 1l) @@ -1002,17 +999,14 @@ module Stake_storage_tests = struct let*@ ctxt = publish_commitment ctxt rollup staker commitment in let* () = assert_commitment_exists ctxt rollup commitment in let* () = assert_commitment_metadata_exists ctxt rollup commitment staker in - let*@ ctxt = cement_commitment ctxt rollup commitment hash in + let*@ ctxt = cement_commitment ctxt rollup commitment in assert_commitment_metadata_dont_exists ctxt rollup commitment (** Test that the entrypoint [cement] fails with a nice error if the rollup is missing. *) let test_cement_to_missing_rollup () = assert_fails_with_missing_rollup ~loc:__LOC__ (fun ctxt rollup -> - Sc_rollup_stake_storage.cement_commitment - ctxt - rollup - Zero.commitment_hash) + Sc_rollup_stake_storage.cement_commitment ctxt rollup) (** Test that if [n] stakers stake on the same commitment, it can be cemented. *) @@ -1021,7 +1015,7 @@ module Stake_storage_tests = struct let* ctxt, rollup, genesis_hash, stakers = originate_rollup_and_deposit_with_n_stakers 10 in - let commitment, hash = + let commitment, _hash = commitment ~predecessor:genesis_hash ~inbox_level:(valid_inbox_level ctxt 1l) @@ -1033,7 +1027,7 @@ module Stake_storage_tests = struct ctxt stakers in - let*@ ctxt = cement_commitment ctxt rollup commitment hash in + let*@ ctxt = cement_commitment ctxt rollup commitment in assert_commitment_metadata_dont_exists ctxt rollup commitment (** Create and cement three commitments: @@ -1058,10 +1052,9 @@ module Stake_storage_tests = struct in let*@ _ctxt, cemented_commitments = List.fold_left_es - (fun (ctxt, acc) commitment -> - let hash = Commitment_repr.hash_uncarbonated commitment in - let* ctxt, cemented_commitment = - Sc_rollup_stake_storage.cement_commitment ctxt rollup hash + (fun (ctxt, acc) _commitment -> + let* ctxt, cemented_commitment, _cemented_commitment_hash = + Sc_rollup_stake_storage.cement_commitment ctxt rollup in return (ctxt, cemented_commitment :: acc)) (ctxt, []) @@ -1167,14 +1160,12 @@ module Stake_storage_tests = struct (* No one can cement their branches. *) let cant_cement ctxt = List.iter_es (fun commitment -> - let hash = Commitment_repr.hash_uncarbonated commitment in assert_fails_with_f ~loc:__LOC__ - (cement_commitment ctxt rollup commitment hash) + (cement_commitment ctxt rollup commitment) (let open Sc_rollup_errors in function - | Sc_rollup_disputed | Sc_rollup_invalid_commitment_to_cement _ - | Sc_rollup_parent_not_lcc + | Sc_rollup_disputed | Sc_rollup_parent_not_lcc | Raw_context.Storage_error (Missing_key _) (* missing commitment *) -> true @@ -1196,9 +1187,7 @@ module Stake_storage_tests = struct in (* [staker1] can now cement its branch. The dishonest branch can not be cemented, before and after the honest branch was cemented. *) - let* () = cant_cement ctxt dishonest_commitments in - let*@ ctxt = cement_commitments ctxt rollup honest_commitments in - let* () = cant_cement ctxt dishonest_commitments in + let*@ _ctxt = cement_commitments ctxt rollup honest_commitments in return_unit (** {2. Withdraw unit tests.} *) @@ -1265,13 +1254,7 @@ module Stake_storage_tests = struct in let*@ ctxt = publish_commitment ctxt rollup staker1 commitment in let*@ ctxt = publish_commitments ctxt rollup staker2 commitments in - let*@ ctxt = - cement_commitment - ctxt - rollup - commitment - (Commitment_repr.hash_uncarbonated commitment) - in + let*@ ctxt = cement_commitment ctxt rollup commitment in let*@ ctxt = cement_commitments ctxt rollup commitments in let*@ _ctxt = withdraw ctxt rollup staker1 in return_unit @@ -1324,13 +1307,7 @@ module Stake_storage_tests = struct in let* () = assert_staker_exists ctxt rollup staker in (* Furthermore, the commitment can be cemented. *) - let*@ _ctxt = - cement_commitment - ctxt - rollup - commitment - (Commitment_repr.hash_uncarbonated new_commitment) - in + let*@ _ctxt = cement_commitment ctxt rollup commitment in return_unit let assert_balance_unchanged ctxt ctxt' account = @@ -1385,25 +1362,12 @@ module Stake_storage_tests = struct let open Lwt_result_syntax in match commitments with | [] -> return ctxt - | c :: commitments -> - let* ctxt, _commitment = - Sc_rollup_stake_storage.cement_commitment ctxt rollup c + | _c :: commitments -> + let* ctxt, _commitment, _commitment_hash = + Sc_rollup_stake_storage.cement_commitment ctxt rollup in cement_commitments ctxt commitments rollup - let test_cement_unknown_commitment_fails () = - let open Lwt_result_syntax in - let* ctxt, rollup, _genesis_hash, _staker = - originate_rollup_and_deposit_with_one_staker () - in - assert_fails_with - ~loc:__LOC__ - (Sc_rollup_stake_storage.cement_commitment - ctxt - rollup - Commitment_repr.Hash.zero) - (Sc_rollup_errors.Sc_rollup_unknown_commitment Commitment_repr.Hash.zero) - let test_cement_fail_too_recent () = let open Lwt_result_wrap_syntax in let* ctxt, rollup, genesis_hash, staker = @@ -1422,14 +1386,14 @@ module Stake_storage_tests = struct compressed_state = Sc_rollup_repr.State_hash.zero; } in - let*@ c1, level, ctxt = + let*@ _c1, level, ctxt = advance_level_n_refine_stake ctxt rollup staker commitment in let min_cementation_level = Raw_level_repr.add level challenge_window in let* () = assert_fails_with ~loc:__LOC__ - (Sc_rollup_stake_storage.cement_commitment ctxt rollup c1) + (Sc_rollup_stake_storage.cement_commitment ctxt rollup) (Sc_rollup_errors.Sc_rollup_commitment_too_recent {current_level = level; min_level = min_cementation_level}) in @@ -1439,7 +1403,7 @@ module Stake_storage_tests = struct let level = (Raw_context.current_level ctxt).level in assert_fails_with ~loc:__LOC__ - (Sc_rollup_stake_storage.cement_commitment ctxt rollup c1) + (Sc_rollup_stake_storage.cement_commitment ctxt rollup) (Sc_rollup_errors.Sc_rollup_commitment_too_recent {current_level = level; min_level = min_cementation_level}) @@ -1472,7 +1436,7 @@ module Stake_storage_tests = struct staker2 commitment in - let*@ _ctxt = Sc_rollup_stake_storage.cement_commitment ctxt rollup c1 in + let*@ _ctxt = Sc_rollup_stake_storage.cement_commitment ctxt rollup in assert_commitment_hash_equal ~loc:__LOC__ c1 c2 let test_last_cemented_commitment_hash_with_level () = @@ -1497,7 +1461,7 @@ module Stake_storage_tests = struct advance_level_n_refine_stake ctxt rollup staker commitment in let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in - let*@ ctxt, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup c1 in + let*@ ctxt, _, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup in let*@ c1', inbox_level', _ctxt = Sc_rollup_commitment_storage.last_cemented_commitment_hash_with_level ctxt @@ -1544,7 +1508,7 @@ module Stake_storage_tests = struct in let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in - let*@ ctxt = Sc_rollup_stake_storage.cement_commitment ctxt rollup c1 in + let*@ ctxt = Sc_rollup_stake_storage.cement_commitment ctxt rollup in assert_true ctxt let test_can_remove_staker () = @@ -1586,7 +1550,7 @@ module Stake_storage_tests = struct an active commitment. *) assert_fails ~loc:__LOC__ - (Sc_rollup_stake_storage.cement_commitment ctxt rollup c1) + (Sc_rollup_stake_storage.cement_commitment ctxt rollup) let test_can_remove_staker2 () = let open Lwt_result_wrap_syntax in @@ -1623,7 +1587,7 @@ module Stake_storage_tests = struct Constants_storage.sc_rollup_challenge_window_in_blocks ctxt in let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in - let*@ ctxt = Sc_rollup_stake_storage.cement_commitment ctxt rollup c1 in + let*@ ctxt = Sc_rollup_stake_storage.cement_commitment ctxt rollup in assert_true ctxt let test_removed_staker_can_not_withdraw () = @@ -1677,7 +1641,7 @@ module Stake_storage_tests = struct compressed_state = Sc_rollup_repr.State_hash.zero; } in - let*@ c1, _level, ctxt = + let*@ _c1, _level, ctxt = advance_level_n_refine_stake ctxt rollup staker1 commitment1 in let commitment2 = @@ -1702,48 +1666,9 @@ module Stake_storage_tests = struct let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in assert_fails_with ~loc:__LOC__ - (Sc_rollup_stake_storage.cement_commitment ctxt rollup c1) + (Sc_rollup_stake_storage.cement_commitment ctxt rollup) Sc_rollup_errors.Sc_rollup_disputed - let test_non_cemented_parent () = - let open Lwt_result_wrap_syntax in - let* ctxt, rollup, genesis_hash, staker1, staker2 = - originate_rollup_and_deposit_with_two_stakers () - in - let level = valid_inbox_level ctxt in - let commitment1 = - 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 = - advance_level_n_refine_stake ctxt rollup staker1 commitment1 - in - let commitment2 = - Commitment_repr. - { - predecessor = c1; - inbox_level = level 2l; - number_of_ticks = number_of_ticks_exn 1232909L; - compressed_state = Sc_rollup_repr.State_hash.zero; - } - in - let*@ c2, _level, ctxt = - advance_level_n_refine_stake ctxt rollup staker2 commitment2 - in - let challenge_window = - Constants_storage.sc_rollup_challenge_window_in_blocks ctxt - in - let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in - assert_fails_with - ~loc:__LOC__ - (Sc_rollup_stake_storage.cement_commitment ctxt rollup c2) - Sc_rollup_errors.Sc_rollup_parent_not_lcc - let test_finds_conflict_point_at_lcc () = let open Lwt_result_wrap_syntax in let* ctxt, rollup, genesis_hash, staker1, staker2 = @@ -2085,7 +2010,7 @@ module Stake_storage_tests = struct Constants_storage.sc_rollup_challenge_window_in_blocks ctxt in let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in - let*@ ctxt, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup c1 in + let*@ ctxt, _, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup in assert_fails_with ~loc:__LOC__ (Sc_rollup_refutation_storage.Internal_for_tests.get_conflict_point @@ -2109,7 +2034,7 @@ module Stake_storage_tests = struct compressed_state = Sc_rollup_repr.State_hash.zero; } in - let*@ c1, _level, ctxt = + let*@ _c1, _level, ctxt = advance_level_n_refine_stake ctxt rollup staker1 commitment1 in let*@ _node, _level, ctxt = @@ -2123,7 +2048,7 @@ module Stake_storage_tests = struct Constants_storage.sc_rollup_challenge_window_in_blocks ctxt in let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in - let*@ ctxt, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup c1 in + let*@ ctxt, _, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup in assert_fails_with ~loc:__LOC__ (Sc_rollup_refutation_storage.Internal_for_tests.get_conflict_point @@ -2231,7 +2156,7 @@ module Stake_storage_tests = struct } in let*@ c1, _ctxt = - let* c1, _level, ctxt = + let* _c1, _level, ctxt = advance_level_n_refine_stake before_ctxt rollup staker1 commitment in let* _c2, _level, ctxt = @@ -2247,11 +2172,11 @@ module Stake_storage_tests = struct let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in - let* ctxt, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup c1 in + let* ctxt, _, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup in Sc_rollup_commitment_storage.last_cemented_commitment ctxt rollup in let*@ c2, _ctxt = - let* c2, _level, ctxt = + let* _c2, _level, ctxt = advance_level_n_refine_stake before_ctxt rollup staker2 commitment in let* _c1, _level, ctxt = @@ -2267,7 +2192,7 @@ module Stake_storage_tests = struct let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in - let* ctxt, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup c2 in + let* ctxt, _, _ = Sc_rollup_stake_storage.cement_commitment ctxt rollup in Sc_rollup_commitment_storage.last_cemented_commitment ctxt rollup in assert_commitment_hash_equal ~loc:__LOC__ c1 c2 @@ -2700,10 +2625,6 @@ module Stake_storage_tests = struct let tests = tests @ [ - Tztest.tztest - "cement unknown commitment fails" - `Quick - test_cement_unknown_commitment_fails; Tztest.tztest "cement fails when too recent" `Quick @@ -2721,10 +2642,6 @@ module Stake_storage_tests = struct `Quick test_cement_with_two_stakers; Tztest.tztest "no cement on conflict" `Quick test_no_cement_on_conflict; - Tztest.tztest - "refuse cementing when parent commitment is not the LCC" - `Quick - test_non_cemented_parent; Tztest.tztest "finds conflict point at LCC" `Quick diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - recover bond of stakers.out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - recover bond of stakers.out index 044bdc40cddccb5a7238ccd7c62529cf893515bd..35efaae95fdabd4076fe3e692cafb82a141b8e96 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - recover bond of stakers.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - recover bond of stakers.out @@ -107,7 +107,7 @@ This sequence of operations was run: ./octez-client --wait none cement commitment '[SC_ROLLUP_COMMITMENT_HASH]' from bootstrap1 for smart rollup '[SMART_ROLLUP_HASH]' Node is bootstrapped. -Estimated gas: 4380.168 units (will add 100 for safety) +Estimated gas: 4840.322 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -118,19 +118,20 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000725 + Fee to the baker: ꜩ0.000771 Expected counter: 3 - Gas limit: 4481 + Gas limit: 4941 Storage limit: 0 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000725 - payload fees(the block proposer) ....... +ꜩ0.000725 + [PUBLIC_KEY_HASH] ... -ꜩ0.000771 + payload fees(the block proposer) ....... +ꜩ0.000771 Smart rollup commitment cementing: Address: [SMART_ROLLUP_HASH] Commitment: [SC_ROLLUP_COMMITMENT_HASH] This smart rollup commitment cementing was successfully applied - Consumed gas: 4380.102 + Consumed gas: 4840.256 Inbox level: 12 + Commitment hash: [SC_ROLLUP_COMMITMENT_HASH] ./octez-client --wait none recover bond of '[PUBLIC_KEY_HASH]' for smart rollup '[SMART_ROLLUP_HASH]' from '[PUBLIC_KEY_HASH]' --fee 1 diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 1467af424dc1ce5a06835e8a62f69e5097e4b34e..70d87f8ca637e857733cfcbdcb8d8887a12b1f47 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -149,12 +149,8 @@ let get_sc_rollup_constants client = let commit_too_recent = "Attempted to cement a commitment before its refutation deadline" -let parent_not_lcc = "Parent is not the last cemented commitment" - let disputed_commit = "Attempted to cement a disputed commitment" -let commit_doesnt_exit = "Commitment src\\w+\\sdoes not exist" - let register_test ?(regression = false) ~__FILE__ ~tags ~title f = let tags = "sc_rollup" :: tags in if regression then Protocol.register_regression_test ~__FILE__ ~title ~tags f @@ -3010,7 +3006,7 @@ let timeout ?expect_failure ~sc_rollup ~staker1 ~staker2 client = let test_no_cementation_if_parent_not_lcc_or_if_disputed_commit = test_forking_scenario ~variant:"publish, and cement on wrong commitment" @@ fun client _node ~sc_rollup ~operator1 ~operator2 commits level0 level1 -> - let c1, c2, c31, c32, c311, c321 = commits in + let c1, c2, c31, c32, c311, _c321 = commits in let* constants = get_sc_rollup_constants client in let challenge_window = constants.challenge_window_in_blocks in let cement = cement_commitments client sc_rollup in @@ -3028,15 +3024,10 @@ let test_no_cementation_if_parent_not_lcc_or_if_disputed_commit = (modulo cementation ordering & disputes resolution) *) repeat challenge_window (fun () -> Client.bake_for_and_wait client) in - (* We cannot cement any of the commitments before cementing c1 *) - let* () = cement [c2; c31; c32; c311; c321] ~fail:parent_not_lcc in - (* But, we can cement c1 and then c2, in this order *) + (* c1 and c2 will be cemented. *) let* () = cement [c1; c2] in (* We cannot cement c31 or c32 on top of c2 because they are disputed *) let* () = cement [c31; c32] ~fail:disputed_commit in - (* Of course, we cannot cement c311 or c321 because their parents are not - cemented. *) - let* () = cement ~fail:parent_not_lcc [c311; c321] in (* +++ dispute resolution +++ Let's resolve the dispute between operator1 and operator2 on the fork @@ -3071,9 +3062,7 @@ let test_no_cementation_if_parent_not_lcc_or_if_disputed_commit = client in (* Now, we can cement c31 on top of c2 and c311 on top of c31. *) - let* () = cement [c31; c311] in - (* Attempting to cement defeated branch will fail. *) - cement ~fail:commit_doesnt_exit [c32; c321] + cement [c31; c311] (** Given a commitment tree constructed by {test_forking_scenario}, this test starts a dispute and makes a first valid dissection move.