From 582bda0aca8dcbd2d91f7ae258562fa8dbddccff Mon Sep 17 00:00:00 2001 From: Fedor Sheremetyev Date: Mon, 3 Oct 2022 21:16:37 +0000 Subject: [PATCH 1/6] Proto: update migration for Lima Stitching to Alpha now goes from Lima instead of Kathmandu. --- .../lib_parameters/default_parameters.ml | 18 + .../constants_parametric_previous_repr.ml | 155 +++-- .../constants_parametric_previous_repr.mli | 42 +- .../lib_protocol/delegate_cycles.ml | 32 - .../lib_protocol/delegate_cycles.mli | 4 - src/proto_alpha/lib_protocol/init_storage.ml | 41 +- .../lib_protocol/legacy_script_patches.ml | 16 +- src/proto_alpha/lib_protocol/raw_context.ml | 76 +-- src/proto_alpha/lib_protocol/raw_context.mli | 2 +- ...eaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.diff | 48 -- ...QsPFynyj3pCJ4mbzP26D4giEjQBwFb.original.tz | 630 ----------------- ...kQsPFynyj3pCJ4mbzP26D4giEjQBwFb.patched.tz | 634 ------------------ 12 files changed, 188 insertions(+), 1510 deletions(-) delete mode 100644 src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.diff delete mode 100644 src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.original.tz delete mode 100644 src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.patched.tz diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 42a0370eb1dc..1dd7e09f4f1f 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -237,8 +237,26 @@ let constants_mainnet = max_lookahead_in_blocks = 30_000l; max_active_outbox_levels = sc_rollup_max_active_outbox_levels; max_outbox_messages_per_level = sc_rollup_max_outbox_messages_per_level; + (* The default number of required sections in a dissection *) number_of_sections_in_dissection = 32; timeout_period_in_blocks = sc_rollup_timeout_period_in_blocks; + (* We store multiple cemented commitments because we want to + allow the execution of outbox messages against cemented + commitments that are older than the last cemented commitment. + The execution of an outbox message is a manager operation, + and manager operations are kept in the mempool for one + hour. Hence we only need to ensure that an outbox message + can be validated against a cemented commitment produced in the + last hour. If we assume that the rollup is operating without + issues, that is no commitments are being refuted and commitments + are published and cemented regularly by one rollup node, we can + expect commitments to be cemented approximately every 15 + minutes, or equivalently we can expect 5 commitments to be + published in one hour (at minutes 0, 15, 30, 45 and 60). + Therefore, we need to keep 5 cemented commitments to guarantee + that the execution of an outbox operation can always be + validated against a cemented commitment while it is in the + mempool. *) max_number_of_stored_cemented_commitments = 5; }); zk_rollup = diff --git a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml index 6d8678201e33..7f009a5d9a47 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml @@ -31,6 +31,9 @@ type dal = { number_of_shards : int; endorsement_lag : int; availability_threshold : int; + slot_size : int; + redundancy_factor : int; + page_size : int; } let dal_encoding = @@ -42,30 +45,45 @@ let dal_encoding = number_of_shards; endorsement_lag; availability_threshold; + slot_size; + redundancy_factor; + page_size; } -> ( feature_enable, number_of_slots, number_of_shards, endorsement_lag, - availability_threshold )) + availability_threshold, + slot_size, + redundancy_factor, + page_size )) (fun ( feature_enable, number_of_slots, number_of_shards, endorsement_lag, - availability_threshold ) -> + availability_threshold, + slot_size, + redundancy_factor, + page_size ) -> { feature_enable; number_of_slots; number_of_shards; endorsement_lag; availability_threshold; + slot_size; + redundancy_factor; + page_size; }) - (obj5 + (obj8 (req "feature_enable" Data_encoding.bool) (req "number_of_slots" Data_encoding.int16) (req "number_of_shards" Data_encoding.int16) (req "endorsement_lag" Data_encoding.int16) - (req "availability_threshold" Data_encoding.int16)) + (req "availability_threshold" Data_encoding.int16) + (req "slot_size" Data_encoding.int31) + (req "redundancy_factor" Data_encoding.uint8) + (req "page_size" Data_encoding.uint16)) (* The encoded representation of this type is stored in the context as bytes. Changing the encoding, or the value of these constants from @@ -98,12 +116,21 @@ type sc_rollup = { enable : bool; origination_size : int; challenge_window_in_blocks : int; - max_available_messages : int; + max_number_of_messages_per_commitment_period : int; stake_amount : Tez_repr.t; commitment_period_in_blocks : int; max_lookahead_in_blocks : int32; max_active_outbox_levels : int32; max_outbox_messages_per_level : int; + number_of_sections_in_dissection : int; + timeout_period_in_blocks : int; + max_number_of_stored_cemented_commitments : int; +} + +type zk_rollup = { + enable : bool; + origination_size : int; + min_pending_to_process : int; } type t = { @@ -116,7 +143,7 @@ type t = { hard_gas_limit_per_operation : Gas_limit_repr.Arith.integral; hard_gas_limit_per_block : Gas_limit_repr.Arith.integral; proof_of_work_threshold : int64; - tokens_per_roll : Tez_repr.t; + minimal_stake : Tez_repr.t; vdf_difficulty : int64; seed_nonce_revelation_tip : Tez_repr.t; origination_size : int; @@ -129,7 +156,6 @@ type t = { quorum_max : int32; min_proposal_quorum : int32; liquidity_baking_subsidy : Tez_repr.t; - liquidity_baking_sunset_level : int32; liquidity_baking_toggle_ema_threshold : int32; max_operations_time_to_live : int; minimal_block_delay : Period_repr.t; @@ -151,6 +177,7 @@ type t = { tx_rollup : tx_rollup; dal : dal; sc_rollup : sc_rollup; + zk_rollup : zk_rollup; } let tx_rollup_encoding = @@ -227,45 +254,80 @@ let sc_rollup_encoding = let open Data_encoding in conv (fun (c : sc_rollup) -> - ( c.enable, - c.origination_size, - c.challenge_window_in_blocks, - c.max_available_messages, - c.stake_amount, - c.commitment_period_in_blocks, - c.max_lookahead_in_blocks, - c.max_active_outbox_levels, - c.max_outbox_messages_per_level )) - (fun ( sc_rollup_enable, - sc_rollup_origination_size, - sc_rollup_challenge_window_in_blocks, - sc_rollup_max_available_messages, - sc_rollup_stake_amount, - sc_rollup_commitment_period_in_blocks, - sc_rollup_max_lookahead_in_blocks, - sc_rollup_max_active_outbox_levels, - sc_rollup_max_outbox_messages_per_level ) -> + ( ( c.enable, + c.origination_size, + c.challenge_window_in_blocks, + c.max_number_of_messages_per_commitment_period, + c.stake_amount, + c.commitment_period_in_blocks, + c.max_lookahead_in_blocks, + c.max_active_outbox_levels, + c.max_outbox_messages_per_level, + c.number_of_sections_in_dissection ), + (c.timeout_period_in_blocks, c.max_number_of_stored_cemented_commitments) + )) + (fun ( ( sc_rollup_enable, + sc_rollup_origination_size, + sc_rollup_challenge_window_in_blocks, + sc_rollup_max_number_of_messages_per_commitment_period, + sc_rollup_stake_amount, + sc_rollup_commitment_period_in_blocks, + sc_rollup_max_lookahead_in_blocks, + sc_rollup_max_active_outbox_levels, + sc_rollup_max_outbox_messages_per_level, + sc_rollup_number_of_sections_in_dissection ), + ( sc_rollup_timeout_period_in_blocks, + sc_rollup_max_number_of_cemented_commitments ) ) -> { enable = sc_rollup_enable; origination_size = sc_rollup_origination_size; challenge_window_in_blocks = sc_rollup_challenge_window_in_blocks; - max_available_messages = sc_rollup_max_available_messages; + max_number_of_messages_per_commitment_period = + sc_rollup_max_number_of_messages_per_commitment_period; stake_amount = sc_rollup_stake_amount; commitment_period_in_blocks = sc_rollup_commitment_period_in_blocks; max_lookahead_in_blocks = sc_rollup_max_lookahead_in_blocks; max_active_outbox_levels = sc_rollup_max_active_outbox_levels; max_outbox_messages_per_level = sc_rollup_max_outbox_messages_per_level; + number_of_sections_in_dissection = + sc_rollup_number_of_sections_in_dissection; + timeout_period_in_blocks = sc_rollup_timeout_period_in_blocks; + max_number_of_stored_cemented_commitments = + sc_rollup_max_number_of_cemented_commitments; + }) + (merge_objs + (obj10 + (req "sc_rollup_enable" bool) + (req "sc_rollup_origination_size" int31) + (req "sc_rollup_challenge_window_in_blocks" int31) + (req "sc_rollup_max_number_of_messages_per_commitment_period" int31) + (req "sc_rollup_stake_amount" Tez_repr.encoding) + (req "sc_rollup_commitment_period_in_blocks" int31) + (req "sc_rollup_max_lookahead_in_blocks" int32) + (req "sc_rollup_max_active_outbox_levels" int32) + (req "sc_rollup_max_outbox_messages_per_level" int31) + (req "sc_rollup_number_of_sections_in_dissection" uint8)) + (obj2 + (req "sc_rollup_timeout_period_in_blocks" int31) + (req "sc_rollup_max_number_of_cemented_commitments" int31))) + +let zk_rollup_encoding = + let open Data_encoding in + conv + (fun ({enable; origination_size; min_pending_to_process} : zk_rollup) -> + (enable, origination_size, min_pending_to_process)) + (fun ( zk_rollup_enable, + zk_rollup_origination_size, + zk_rollup_min_pending_to_process ) -> + { + enable = zk_rollup_enable; + origination_size = zk_rollup_origination_size; + min_pending_to_process = zk_rollup_min_pending_to_process; }) - (obj9 - (req "sc_rollup_enable" bool) - (req "sc_rollup_origination_size" int31) - (req "sc_rollup_challenge_window_in_blocks" int31) - (req "sc_rollup_max_available_messages" int31) - (req "sc_rollup_stake_amount" Tez_repr.encoding) - (req "sc_rollup_commitment_period_in_blocks" int31) - (req "sc_rollup_max_lookahead_in_blocks" int32) - (req "sc_rollup_max_active_outbox_levels" int32) - (req "sc_rollup_max_outbox_messages_per_level" int31)) + (obj3 + (req "zk_rollup_enable" bool) + (req "zk_rollup_origination_size" int31) + (req "zk_rollup_min_pending_to_process" int31)) let encoding = let open Data_encoding in @@ -280,7 +342,7 @@ let encoding = c.hard_gas_limit_per_operation, c.hard_gas_limit_per_block, c.proof_of_work_threshold, - c.tokens_per_roll ), + c.minimal_stake ), ( ( c.vdf_difficulty, c.seed_nonce_revelation_tip, c.origination_size, @@ -293,7 +355,6 @@ let encoding = ( ( c.quorum_max, c.min_proposal_quorum, c.liquidity_baking_subsidy, - c.liquidity_baking_sunset_level, c.liquidity_baking_toggle_ema_threshold, c.max_operations_time_to_live, c.minimal_block_delay, @@ -310,7 +371,7 @@ let encoding = ( ( c.cache_script_size, c.cache_stake_distribution_cycles, c.cache_sampler_state_cycles ), - (c.tx_rollup, (c.dal, c.sc_rollup)) ) ) ) ) )) + (c.tx_rollup, (c.dal, (c.sc_rollup, c.zk_rollup))) ) ) ) ) )) (fun ( ( preserved_cycles, blocks_per_cycle, blocks_per_commitment, @@ -320,7 +381,7 @@ let encoding = hard_gas_limit_per_operation, hard_gas_limit_per_block, proof_of_work_threshold, - tokens_per_roll ), + minimal_stake ), ( ( vdf_difficulty, seed_nonce_revelation_tip, origination_size, @@ -333,7 +394,6 @@ let encoding = ( ( quorum_max, min_proposal_quorum, liquidity_baking_subsidy, - liquidity_baking_sunset_level, liquidity_baking_toggle_ema_threshold, max_operations_time_to_live, minimal_block_delay, @@ -350,7 +410,7 @@ let encoding = ( ( cache_script_size, cache_stake_distribution_cycles, cache_sampler_state_cycles ), - (tx_rollup, (dal, sc_rollup)) ) ) ) ) ) -> + (tx_rollup, (dal, (sc_rollup, zk_rollup))) ) ) ) ) ) -> { preserved_cycles; blocks_per_cycle; @@ -361,7 +421,7 @@ let encoding = hard_gas_limit_per_operation; hard_gas_limit_per_block; proof_of_work_threshold; - tokens_per_roll; + minimal_stake; vdf_difficulty; seed_nonce_revelation_tip; origination_size; @@ -374,7 +434,6 @@ let encoding = quorum_max; min_proposal_quorum; liquidity_baking_subsidy; - liquidity_baking_sunset_level; liquidity_baking_toggle_ema_threshold; max_operations_time_to_live; minimal_block_delay; @@ -394,6 +453,7 @@ let encoding = tx_rollup; dal; sc_rollup; + zk_rollup; }) (merge_objs (obj10 @@ -410,7 +470,7 @@ let encoding = "hard_gas_limit_per_block" Gas_limit_repr.Arith.z_integral_encoding) (req "proof_of_work_threshold" int64) - (req "tokens_per_roll" Tez_repr.encoding)) + (req "minimal_stake" Tez_repr.encoding)) (merge_objs (obj9 (req "vdf_difficulty" int64) @@ -423,11 +483,10 @@ let encoding = (req "hard_storage_limit_per_operation" z) (req "quorum_min" int32)) (merge_objs - (obj10 + (obj9 (req "quorum_max" int32) (req "min_proposal_quorum" int32) (req "liquidity_baking_subsidy" Tez_repr.encoding) - (req "liquidity_baking_sunset_level" int32) (req "liquidity_baking_toggle_ema_threshold" int32) (req "max_operations_time_to_live" int16) (req "minimal_block_delay" Period_repr.encoding) @@ -454,4 +513,4 @@ let encoding = tx_rollup_encoding (merge_objs (obj1 (req "dal_parametric" dal_encoding)) - sc_rollup_encoding))))))) + (merge_objs sc_rollup_encoding zk_rollup_encoding)))))))) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli index 41a652bc63cb..db5c1c5ab07a 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli @@ -31,6 +31,9 @@ type dal = { number_of_shards : int; endorsement_lag : int; availability_threshold : int; + slot_size : int; + redundancy_factor : int; + page_size : int; } val dal_encoding : dal Data_encoding.t @@ -88,7 +91,7 @@ type sc_rollup = { enable : bool; origination_size : int; challenge_window_in_blocks : int; - max_available_messages : int; + max_number_of_messages_per_commitment_period : int; stake_amount : Tez_repr.t; (* The period with which commitments are made. *) commitment_period_in_blocks : int; @@ -100,6 +103,39 @@ type sc_rollup = { if it has an associated record of applied messages. *) max_active_outbox_levels : int32; max_outbox_messages_per_level : int; + (* The default number of required sections in a dissection *) + number_of_sections_in_dissection : int; + (* The timeout period for a player in a refutation game. + + Timeout logic is similar to a chess clock. Each player starts with the same + timeout = [timeout_period_in_blocks]. Each game move updates the timeout of + the current player by decreasing it by the amount of time she took to play, + i.e. number of blocks since the opponent last move. See + {!Sc_rollup_game_repr.timeout} and + {!Sc_rollup_refutation_storage.game_move} to see the implementation. + + Because of that [timeout_period_in_blocks] must be at least half the upper + bound number of blocks needed for a game to finish. This bound is + correlated to the maximum distance allowed between the first and last tick + of a dissection. For example, when the maximum distance allowed is half the + total distance [(last_tick - last_tick) / 2] then bound is [Log^2 + (Int64.max_int) + 2 = 65]. See {!Sc_rollup_game_repr.check_dissection} for + more information on the dissection logic. *) + timeout_period_in_blocks : int; + (* The maximum number of cemented commitments stored for a sc rollup. *) + max_number_of_stored_cemented_commitments : int; +} + +type zk_rollup = { + enable : bool; + origination_size : int; + (* Minimum number of pending operations that can be processed by a ZKRU + update, if available. + If the length of the pending list is less than [min_pending_to_process], + then an update needs to process all pending operations to be valid. + That is, every update must process at least + [min(length pending_list, min_pending_to_process)] pending operations. *) + min_pending_to_process : int; } type t = { @@ -112,7 +148,7 @@ type t = { hard_gas_limit_per_operation : Gas_limit_repr.Arith.integral; hard_gas_limit_per_block : Gas_limit_repr.Arith.integral; proof_of_work_threshold : int64; - tokens_per_roll : Tez_repr.t; + minimal_stake : Tez_repr.t; vdf_difficulty : int64; seed_nonce_revelation_tip : Tez_repr.t; origination_size : int; @@ -126,7 +162,6 @@ type t = { quorum_max : int32; min_proposal_quorum : int32; liquidity_baking_subsidy : Tez_repr.t; - liquidity_baking_sunset_level : int32; liquidity_baking_toggle_ema_threshold : int32; max_operations_time_to_live : int; minimal_block_delay : Period_repr.t; @@ -153,6 +188,7 @@ type t = { tx_rollup : tx_rollup; dal : dal; sc_rollup : sc_rollup; + zk_rollup : zk_rollup; } val encoding : t Data_encoding.encoding diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml index d64d8628a160..943467e4155d 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.ml +++ b/src/proto_alpha/lib_protocol/delegate_cycles.ml @@ -280,35 +280,3 @@ let init_first_cycles ctxt ~origin = >>=? fun ctxt -> let cycle = (Raw_context.current_level ctxt).cycle in freeze_deposits ~origin ~new_cycle:cycle ~balance_updates:[] ctxt - -module Migration_from_Kathmandu = struct - let update_delegate pkh ctxt = - let open Lwt_tzresult_syntax in - let*? ctxt = ctxt in - let* pk = Contract_manager_storage.get_manager_key ctxt pkh in - Delegate_consensus_key.init ctxt pkh pk - - let update ctxt = - let open Lwt_tzresult_syntax in - let* ctxt = - Delegate_storage.fold - ctxt - ~order:`Undefined - ~f:update_delegate - ~init:(ok ctxt) - in - let*! cycles = - Storage.Migration_from_Kathmandu.Delegate_sampler_state.keys ctxt - in - let*! ctxt = - Storage.Migration_from_Kathmandu.Delegate_sampler_state.clear ctxt - in - let*? ctxt = Raw_context.Migration_from_Kathmandu.reset_samplers ctxt in - let* ctxt = - List.fold_left_es - Delegate_sampler.Migration_from_Kathmandu.update_sampler - ctxt - cycles - in - return ctxt -end diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.mli b/src/proto_alpha/lib_protocol/delegate_cycles.mli index 679b87f5a745..1b7f8a87bad6 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.mli +++ b/src/proto_alpha/lib_protocol/delegate_cycles.mli @@ -49,7 +49,3 @@ val init_first_cycles : Raw_context.t -> origin:Receipt_repr.update_origin -> (Raw_context.t * Receipt_repr.balance_updates) tzresult Lwt.t - -module Migration_from_Kathmandu : sig - val update : Raw_context.t -> Raw_context.t tzresult Lwt.t -end diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index baa5f97efda0..8f5468040286 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -36,8 +36,6 @@ Do not fail if something goes wrong. *) -*) - let invoice_contract ctxt ~address ~amount_mutez = match Tez_repr.of_mutez amount_mutez with | None -> Lwt.return (ctxt, []) @@ -52,6 +50,7 @@ let invoice_contract ctxt ~address ~amount_mutez = >|= function | Ok res -> res | Error _ -> (ctxt, [])) +*) (* To patch code of legacy contracts you can add a helper function here and call @@ -104,27 +103,7 @@ let patch_script (address, hash, patched_code) ctxt = address ; return ctxt -module Patch_ghostnet = struct - let ghostnet_id = - let id = Chain_id.of_b58check_exn "NetXnHfVqm9iesp" in - if Chain_id.equal id Constants_repr.mainnet_id then assert false else id - - let patch chain_id ctxt level = - if Chain_id.equal chain_id ghostnet_id then - Raw_context.patch_constants ctxt (fun c -> - {c with vdf_difficulty = Int64.div c.vdf_difficulty 4L}) - >>= fun ctxt -> - Voting_period_storage.get_current ctxt >>=? fun current -> - let level = Raw_level_repr.to_int32 level in - if Compare.Int32.equal current.start_position level then - (* do nothing; the migration happens at the end of a voting - period, so the period has already been reset *) - return ctxt - else Voting_period_storage.reset ctxt - else return ctxt -end - -let prepare_first_block chain_id ctxt ~typecheck ~level ~timestamp = +let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp = Raw_context.prepare_first_block ~level ~timestamp ctxt >>=? fun (previous_protocol, ctxt) -> let parametric = Raw_context.constants ctxt in @@ -179,26 +158,14 @@ let prepare_first_block chain_id ctxt ~typecheck ~level ~timestamp = ( ctxt, commitments_balance_updates @ bootstrap_balance_updates @ deposits_balance_updates ) - | Kathmandu_014 + | Lima_015 (* Please update [next_protocol] and [previous_protocol] in [tezt/lib_tezos/protocol.ml] when you update this value. *) -> (* TODO (#2704): possibly handle endorsements for migration block (in bakers); if that is done, do not set Storage.Tenderbake.First_level_of_protocol. *) Raw_level_repr.of_int32 level >>?= fun level -> Storage.Tenderbake.First_level_of_protocol.update ctxt level - >>=? fun ctxt -> - Delegate_cycles.Migration_from_Kathmandu.update ctxt >>=? fun ctxt -> - Patch_ghostnet.patch chain_id ctxt level >>=? fun ctxt -> - invoice_contract - ctxt - ~address:"tz1X81bCXPtMiHu1d4UZF4GPhMPkvkp56ssb" - ~amount_mutez:15_000_000_000L - >>= fun (ctxt, bu1) -> - invoice_contract - ctxt - ~address:"tz1MidLyXXvKWMmbRvKKeusDtP95NDJ5gAUx" - ~amount_mutez:10_000_000_000L - >>= fun (ctxt, bu2) -> return (ctxt, bu1 @ bu2)) + >>=? fun ctxt -> return (ctxt, [])) >>=? fun (ctxt, balance_updates) -> List.fold_right_es patch_script Legacy_script_patches.addresses_to_patch ctxt >>=? fun ctxt -> diff --git a/src/proto_alpha/lib_protocol/legacy_script_patches.ml b/src/proto_alpha/lib_protocol/legacy_script_patches.ml index c233788a1593..de45c3d7fb9a 100644 --- a/src/proto_alpha/lib_protocol/legacy_script_patches.ml +++ b/src/proto_alpha/lib_protocol/legacy_script_patches.ml @@ -43,21 +43,7 @@ let bin_expr_exn hex = | Some expr -> expr | None -> raise (Failure "Decoding script failed.") -let patches = - [ - { - addresses = ["KT1SL6CGhjPUyLypDbFv9bXsNF2sHG7Fy3j9"]; - hash = - Script_expr_hash.of_b58check_exn - "exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb"; - patched_code = - (* This patched code was obtained by manually editing the Michelson code - of the smart contract and then converting the modified code to binary - representation using octez-client convert script command. *) - bin_expr_exn - "02000019c70500046c00000005256d61696e050108650861036e036a0000000b3a6465706f7369746f72730765046e00000006256f776e65720765046a0000000c256d696e5f6465706f736974076504620000000d2577697468647261775f666565076504620000000d25636f6c6c61745f636f6566660765046a0000000a256465706f73697465640765046a0000000925626f72726f7765640765046200000010256465706f7369746f72735f73697a65045d000000092564656c6567617465000000083a73746f72616765050202000018f80321051f02000000160417000000104073746f726167655f736c6173685f3104160000000a405f5f736c6173685f32084303620080897a0000000a406f6e655f70726563360931000000cf07650765036a03620362036a02000000be045800000021405f616d6f756e745f636f6566665f5f6f6e655f70726563365f736c6173685f380321041700000012406f6e655f70726563365f736c6173685f33051f02000000020321034c031604170000000640636f656666071f00020200000002032105700002031604160000000740616d6f756e74033a0322072f020000002b0743036801000000204469766973696f6e206572726f7220696e20606170706c795f636f656666602e032702000000020316051f020000000203200000000004420000000c406170706c795f636f6566660448000000074073656e64657204130000000740616d6f756e7404150000001140636f6e74726163745f62616c616e6365071f0005020000000e0421000000084073746f72616765057000050421000000024073020000000e0317041600000006256f776e6572071f0004020000000d0421000000074073656e646572057000040319033c0743036a0080897a071f0004020000000d04210000000740616d6f756e74057000040319032a0314072c02000004c90421000000024073020000002303170317041600000019406d696e5f6465706f73697420256d696e5f6465706f736974071f0003020000000d04210000000740616d6f756e740570000303190337072c020000002907430368010000001e4465706f736974656420616d6f756e7420697320746f6f20736d616c6c2e03270200000002034f0320042100000002407304160000000b256465706f7369746f7273071f0004020000000d0421000000074073656e646572057000040329072f02000001b90421000000024073032104160000000b256465706f7369746f7273034c03170321041600000006256f776e6572034c0317032104160000000c256d696e5f6465706f736974034c0317032104160000000d2577697468647261775f666565034c0317032104160000000d25636f6c6c61745f636f656666034c0317032104160000000a256465706f7369746564034c0317032104160000000925626f72726f776564034c03170417000000092564656c6567617465074303620001071f0009020000000804210000000240730570000902000000240317031703170317031703170317041600000010256465706f7369746f72735f73697a65031204420000001a256465706f7369746f72735f73697a65202564656c6567617465034c04420000000925626f72726f776564034c04420000000a256465706f7369746564034c04420000000d25636f6c6c61745f636f656666034c04420000000d2577697468647261775f666565034c04420000000c256d696e5f6465706f736974034c044200000006256f776e6572034c04420000000b256465706f7369746f7273071f0003020000000d04210000000740616d6f756e74057000030342020000004f051f02000000080421000000024073034c071f0004020000000d04210000000740616d6f756e7405700004071f00020200000008042100000002406205700002071f00030200000002032003120342045800000010405f757365725f62616c616e63655f730321041700000002407304210000000240730317051f02000000080421000000024073034c04160000000b256465706f7369746f7273071f0003020000000203210570000304160000000d40757365725f62616c616e6365071f0008020000000d0421000000074073656e64657205700008051f02000000020346035004420000000e407320256465706f7369746f72730421000000024073032104160000000b256465706f7369746f7273034c03170321041600000006256f776e6572034c0317032104160000000c256d696e5f6465706f736974034c0317032104160000000d2577697468647261775f666565034c0317032104160000000d25636f6c6c61745f636f656666034c03170317071f000b020000000d04210000000740616d6f756e740570000b071f00070200000008042100000002407305700007071f0008020000000405200003020000001a0317031703170317031704160000000a256465706f7369746564031204420000000a256465706f7369746564034c04420000000d25636f6c6c61745f636f656666034c04420000000d2577697468647261775f666565034c04420000000c256d696e5f6465706f736974034c044200000006256f776e6572034c04420000000e407320256465706f7369746f7273053d036d0342020000123b0421000000024073020000000e0317041600000006256f776e6572071f0004020000000d0421000000074073656e646572057000040319033c0743036a0080897a071f0004020000000d04210000000740616d6f756e7405700004031903320314072c02000006f7042100000002407304160000000b256465706f7369746f7273071f0004020000000d0421000000074073656e646572057000040329072f020000002807430368010000001d4f6e6c79206465706f7369746f72732063616e2077697468647261772e0327020000000004580000000d40757365725f62616c616e6365071f0002020000001704210000001140636f6e74726163745f62616c616e636505700002051f020000001304210000000d40757365725f62616c616e6365034c0319032a072c0200000041074303680100000036576974686472617720616d6f756e742067726561746572207468616e2063757272656e7420636f6e74726163742062616c616e63652e03270200000002034f0320051f02000000080421000000024073034c032104160000000b256465706f7369746f7273034c03170321041600000006256f776e6572034c0317032104160000000c256d696e5f6465706f736974034c0317032104160000000d2577697468647261775f666565034c0317032104160000000d25636f6c6c61745f636f656666034c03170317071f0006020000001304210000000d40757365725f62616c616e636505700006071f00080200000008042100000002407305700008020000001a0317031703170317031704160000000a256465706f73697465640393072f0200000004034f0327020000000004420000000a256465706f7369746564034c04420000000d25636f6c6c61745f636f656666034c04420000000d2577697468647261775f666565034c04420000000c256d696e5f6465706f736974034c044200000006256f776e6572034c04420000000e407320256465706f7369746f727304210000000240730317051f02000000080421000000024073034c04160000000b256465706f7369746f7273053e036a071f0008020000000d0421000000074073656e64657205700008035004420000000e407320256465706f7369746f72730421000000024073032104160000000b256465706f7369746f7273034c03170321041600000006256f776e6572034c0317032104160000000c256d696e5f6465706f736974034c0317032104160000000d2577697468647261775f666565034c0317032104160000000d25636f6c6c61745f636f656666034c0317032104160000000a256465706f7369746564034c0317032104160000000925626f72726f776564034c03170417000000092564656c6567617465074303620001071f0009020000000804210000000240730570000902000000240317031703170317031703170317041600000010256465706f7369746f72735f73697a65034b03210311034c0328072c0200000000020000002507430368010000001a4465706f7369746f727320636f756e74696e67206572726f722e032704420000001a256465706f7369746f72735f73697a65202564656c6567617465034c04420000000925626f72726f776564034c04420000000a256465706f7369746564034c04420000000d25636f6c6c61745f636f656666034c04420000000d2577697468647261775f666565034c04420000000c256d696e5f6465706f736974034c044200000006256f776e6572034c04420000000e407320256465706f7369746f7273071f0008020000001204210000000c406170706c795f636f65666605700008051f02000000080421000000024073034c020000001903170317031704160000000d2577697468647261775f666565071f0005020000001304210000000d40757365725f62616c616e6365057000050342051f020000000803210316034c0317034204260000000b406665655f616d6f756e74051f02000000080421000000024073034c053d036d071f000a020000000d0421000000074073656e6465720570000a0555036c072f020000003907430368010000002e4e6f20656e747279706f696e742064656661756c74207769746820706172616d65746572207479706520756e697403270200000000071f000a020000000d04210000000740616d6f756e740570000a071f0004020000001104210000000b406665655f616d6f756e7405700004071f0009020000001304210000000d40757365725f62616c616e6365057000090393072f0200000004034f032702000000000412000000104077697468647261775f616d6f756e74034f044d0000000c406f705f7769746864726177031b071f00030200000008042100000002407305700003020000000e0317041600000006256f776e65720555036c072f020000003907430368010000002e4e6f20656e747279706f696e742064656661756c74207769746820706172616d65746572207479706520756e697403270200000000071f0003020000001104210000000b406665655f616d6f756e7405700003071f0004020000000405200005034f044d00000007406f705f666565031b03420200000ad70421000000024073020000000e0317041600000006256f776e6572071f0004020000000d0421000000074073656e64657205700004031903250743036a0000071f0004020000000d04210000000740616d6f756e7405700004031903250314072c020000067d084303620080897a0000000a406f6e655f70726563360931000000c0076503620362036202000000b304580000001a40636f6566665f5f6f6e655f70726563365f736c6173685f3134032104160000000f40636f6566665f736c6173685f3135051f02000000020321034c041700000012406f6e655f70726563365f736c6173685f33034b03210311034c0328072c0200000000020000003a07430368010000002f496e76616c696420636f656666696369656e742076616c756520696e20606765745f636f6566665f636f6d706c602e0327051f0200000002032000000000044200000010406765745f636f6566665f636f6d706c071f0005020000001204210000000c406170706c795f636f656666057000050342051f02000000080421000000024073034c020000001b031703170317031704160000000d25636f6c6c61745f636f656666071f00020200000008042100000002407305700002020000001a0317031703170317031704160000000a256465706f7369746564034203420321020000001d0317041600000015406170706c795f636f6566665f736c6173685f3133051f02000000020321034c02000000210317041700000019406765745f636f6566665f636f6d706c5f736c6173685f3138071f00020200000002032105700002031604170000000d40636f6c6c61745f636f656666051f020000000803210316034c031703420326071f00020200000002032105700002031604160000000a406465706f73697465640342051f020000000803210316034c0317071f00030200000002032003420326051f02000000080421000000024073034c020000001b03170317031703170317031704160000000925626f72726f776564051f020000001404210000000e406d61785f626f72726f77696e67034c03190337072c020000004a07430368010000003f4e6f20617661696c61626c652066756e647320746f20626f72726f773a20636f6e747261637420697320756e6465722d636f6c6c61746572616c697a65642e03270200000002034f0320071f0002020000001704210000001140636f6e74726163745f62616c616e636505700002071f00020200000008042100000002407305700002020000001b03170317031703170317031704160000000925626f72726f776564071f0002020000001404210000000e406d61785f626f72726f77696e67057000020393072f0200000004034f03270200000000034203210416000000024061051f02000000020321034c04170000000240620421000000024062071f000202000000080421000000024061057000020319032a072c020000000804210000000240620200000011051f02000000080421000000024061034c051f0200000004052000030743036a0000051f020000001004210000000a40626f72726f77696e67034c03190325072c020000002807430368010000001d4e6f20617661696c61626c652066756e647320746f20626f72726f772e03270200000002034f0320071f00020200000008042100000002407305700002032104160000000b256465706f7369746f7273034c03170321041600000006256f776e6572034c0317032104160000000c256d696e5f6465706f736974034c0317032104160000000d2577697468647261775f666565034c0317032104160000000d25636f6c6c61745f636f656666034c0317032104160000000a256465706f7369746564034c03170317071f0007020000001004210000000a40626f72726f77696e6705700007071f000a020000000804210000000240730570000a020000001b03170317031703170317031704160000000925626f72726f776564031204420000000925626f72726f776564034c04420000000a256465706f7369746564034c04420000000d25636f6c6c61745f636f656666034c04420000000d2577697468647261775f666565034c04420000000c256d696e5f6465706f736974034c044200000006256f776e6572034c04420000000e407320256465706f7369746f72730421000000024073053d036d071f00020200000008042100000002407305700002020000000e0317041600000006256f776e65720555036c072f020000003907430368010000002e4e6f20656e747279706f696e742064656661756c74207769746820706172616d65746572207479706520756e697403270200000000071f0004020000001004210000000a40626f72726f77696e6705700004071f0004020000000405200003034f044d00000003406f70031b034202000003ef0421000000024073020000000e0317041600000006256f776e6572071f0004020000000d0421000000074073656e64657205700004031903250743036a00a0a233071f0004020000000d04210000000740616d6f756e7405700004031903250314072c02000000ec0421000000024073053d036d071f00020200000008042100000002407305700002020000001d03170317031703170317031703170417000000092564656c65676174650346044e00000010406f705f7365745f64656c6567617465031b071f00020200000008042100000002407305700002020000000e0317041600000006256f776e65720555036c072f020000003907430368010000002e4e6f20656e747279706f696e742064656661756c74207769746820706172616d65746572207479706520756e6974032702000000000743036a00a0a233034f044d0000000a406f705f726566756e64031b034202000002960421000000024073020000000e0317041600000006256f776e6572071f0004020000000d0421000000074073656e64657205700004031903250743036a0000071f0004020000000d04210000000740616d6f756e74057000040319032a0314072c020000020a0421000000024073020000002503170317031703170317031704160000001340626f72726f7765642025626f72726f776564071f0003020000000d04210000000740616d6f756e74057000030319032a072c020000002d07430368010000002243616e2774206f7665722d636f6c6c61746572616c697a6520636f6e74726163742e03270200000002034f03200421000000024073032104160000000b256465706f7369746f7273034c03170321041600000006256f776e6572034c0317032104160000000c256d696e5f6465706f736974034c0317032104160000000d2577697468647261775f666565034c0317032104160000000d25636f6c6c61745f636f656666034c0317032104160000000a256465706f7369746564034c03170317071f0009020000000d04210000000740616d6f756e7405700009071f00080200000008042100000002407305700008020000001b03170317031703170317031704160000000925626f72726f7765640393072f0200000004034f0327020000000004420000000925626f72726f776564034c04420000000a256465706f7369746564034c04420000000d25636f6c6c61745f636f656666034c04420000000d2577697468647261775f666565034c04420000000c256d696e5f6465706f736974034c044200000006256f776e6572034c04420000000e407320256465706f7369746f7273053d036d03420200000021074303680100000016596f752073686f756c646e277420626520686572652e0327051f020000000405200007"; - }; - ] +let patches = [] let addresses_to_patch = List.concat_map diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index e0816e4fcb95..0354a7336963 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -852,7 +852,7 @@ let prepare ~level ~predecessor_timestamp ~timestamp ctxt = }; } -type previous_protocol = Genesis of Parameters_repr.t | Kathmandu_014 +type previous_protocol = Genesis of Parameters_repr.t | Lima_015 let check_and_update_protocol_version ctxt = (Context.find ctxt version_key >>= function @@ -864,8 +864,7 @@ let check_and_update_protocol_version ctxt = failwith "Internal error: previously initialized context." else if Compare.String.(s = "genesis") then get_proto_param ctxt >|=? fun (param, ctxt) -> (Genesis param, ctxt) - else if Compare.String.(s = "kathmandu_014") then - return (Kathmandu_014, ctxt) + else if Compare.String.(s = "lima_015") then return (Lima_015, ctxt) else Lwt.return @@ storage_error (Incompatible_protocol_version s)) >>=? fun (previous_proto, ctxt) -> Context.add ctxt version_key (Bytes.of_string version_value) >|= fun ctxt -> @@ -916,7 +915,7 @@ let prepare_first_block ~level ~timestamp ctxt = Level_repr.create_cycle_eras [cycle_era] >>?= fun cycle_eras -> set_cycle_eras ctxt cycle_eras >>=? fun ctxt -> add_constants ctxt param.constants >|= ok - | Kathmandu_014 -> + | Lima_015 -> get_previous_protocol_constants ctxt >>= fun c -> let tx_rollup = Constants_parametric_repr. @@ -950,82 +949,43 @@ let prepare_first_block ~level ~timestamp ctxt = let dal = Constants_parametric_repr. { - feature_enable = false; - number_of_slots = 256; - endorsement_lag = 1; - availability_threshold = 50; + feature_enable = c.dal.feature_enable; + number_of_slots = c.dal.number_of_slots; + endorsement_lag = c.dal.endorsement_lag; + availability_threshold = c.dal.availability_threshold; cryptobox_parameters; } in - (* Inherit values that existed in previous protocol and haven't changed. - Assign values to new constants or those with new default value. *) let sc_rollup = Constants_parametric_repr. { enable = c.sc_rollup.enable; origination_size = c.sc_rollup.origination_size; challenge_window_in_blocks = c.sc_rollup.challenge_window_in_blocks; - (* - - The following value is chosen to limit the length of inbox - refutation proofs. In the worst case, the length of inbox - refutation proofs are logarithmic (in basis 2) in the - number of messages in the inboxes during the commitment - period. - - With the following value, an inbox refutation proof is - made of at most 35 hashes, hence a payload bounded by - 35 * 48 bytes, which far below than the 32kb of a Tezos - operations. - - *) max_number_of_messages_per_commitment_period = - c.sc_rollup.commitment_period_in_blocks * 10_000_000; + c.sc_rollup.max_number_of_messages_per_commitment_period; (* TODO: https://gitlab.com/tezos/tezos/-/issues/2756 The following constants need to be refined. *) - stake_amount = Tez_repr.of_mutez_exn 10_000_000_000L; + stake_amount = c.sc_rollup.stake_amount; commitment_period_in_blocks = c.sc_rollup.commitment_period_in_blocks; max_lookahead_in_blocks = c.sc_rollup.max_lookahead_in_blocks; - (* Number of active levels kept for executing outbox messages. - WARNING: Changing this value impacts the storage charge for - applying messages from the outbox. It also requires migration for - remapping existing active outbox levels to new indices. *) max_active_outbox_levels = c.sc_rollup.max_active_outbox_levels; - (* Maximum number of outbox messages per level. - WARNING: changing this value impacts the storage cost charged - for applying messages from the outbox. *) max_outbox_messages_per_level = c.sc_rollup.max_outbox_messages_per_level; - (* The default number of required sections in a dissection *) - number_of_sections_in_dissection = 32; - timeout_period_in_blocks = 20_160; - (* We store multiple cemented commitments because we want to - allow the execution of outbox messages against cemented - commitments that are older than the last cemented commitment. - The execution of an outbox message is a manager operation, - and manager operations are kept in the mempool for one - hour. Hence we only need to ensure that an outbox message - can be validated against a cemented commitment produced in the - last hour. If we assume that the rollup is operating without - issues, that is no commitments are being refuted and commitments - are published and cemented regularly by one rollup node, we can - expect commitments to be cemented approximately every 15 - minutes, or equivalently we can expect 5 commitments to be - published in one hour (at minutes 0, 15, 30, 45 and 60). - Therefore, we need to keep 5 cemented commitments to guarantee - that the execution of an outbox operation can always be - validated against a cemented commitment while it is in the - mempool. *) - max_number_of_stored_cemented_commitments = 5; + number_of_sections_in_dissection = + c.sc_rollup.number_of_sections_in_dissection; + timeout_period_in_blocks = c.sc_rollup.timeout_period_in_blocks; + max_number_of_stored_cemented_commitments = + c.sc_rollup.max_number_of_stored_cemented_commitments; } in let zk_rollup = Constants_parametric_repr. { - enable = false; - origination_size = 4_000; - min_pending_to_process = 10; + enable = c.zk_rollup.enable; + origination_size = c.zk_rollup.origination_size; + min_pending_to_process = c.zk_rollup.min_pending_to_process; } in let constants = @@ -1040,7 +1000,7 @@ let prepare_first_block ~level ~timestamp ctxt = hard_gas_limit_per_operation = c.hard_gas_limit_per_operation; hard_gas_limit_per_block = c.hard_gas_limit_per_block; proof_of_work_threshold = c.proof_of_work_threshold; - minimal_stake = c.tokens_per_roll; + minimal_stake = c.minimal_stake; vdf_difficulty = c.vdf_difficulty; seed_nonce_revelation_tip = c.seed_nonce_revelation_tip; origination_size = c.origination_size; diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index 858922d856ab..8fdc7c64c117 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -83,7 +83,7 @@ val prepare : Context.t -> t tzresult Lwt.t -type previous_protocol = Genesis of Parameters_repr.t | Kathmandu_014 +type previous_protocol = Genesis of Parameters_repr.t | Lima_015 val prepare_first_block : level:int32 -> diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.diff b/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.diff deleted file mode 100644 index 36e6e0aeca9c..000000000000 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.diff +++ /dev/null @@ -1,48 +0,0 @@ ---- patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.original.tz -+++ patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.patched.tz -@@ -1,4 +1,4 @@ --{ parameter %main unit ; -+{ parameter (unit %main) ; - storage - (pair :storage - (big_map :depositors address mutez) -@@ -241,7 +241,8 @@ - DIP 8 { DUP @s } ; - DIG 8 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CAR %deposited } ; -- SUB ; -+ SUB_MUTEZ ; -+ IF_NONE {UNIT ; FAILWITH} {}; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; -@@ -344,7 +345,8 @@ - DIG 4 ; - DIP 9 { DUP @user_balance } ; - DIG 9 ; -- SUB ; -+ SUB_MUTEZ ; -+ IF_NONE {UNIT ; FAILWITH} {}; - ADD @withdraw_amount ; - UNIT ; - TRANSFER_TOKENS @op_withdraw ; -@@ -444,7 +446,8 @@ - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - DIP 2 { DUP @max_borrowing } ; - DIG 2 ; -- SUB ; -+ SUB_MUTEZ ; -+ IF_NONE {UNIT ; FAILWITH} {} ; - PAIR ; - DUP ; - CAR @a ; -@@ -610,7 +613,8 @@ - DIP 8 { DUP @s } ; - DIG 8 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; -- SUB ; -+ SUB_MUTEZ ; -+ IF_NONE {UNIT ; FAILWITH} {} ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.original.tz b/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.original.tz deleted file mode 100644 index 20a7b76d0d4f..000000000000 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.original.tz +++ /dev/null @@ -1,630 +0,0 @@ -{ parameter %main unit ; - storage - (pair :storage - (big_map :depositors address mutez) - (pair (address %owner) - (pair (mutez %min_deposit) - (pair (nat %withdraw_fee) - (pair (nat %collat_coeff) - (pair (mutez %deposited) - (pair (mutez %borrowed) (pair (nat %depositors_size) (key_hash %delegate))))))))) ; - code { DUP ; - DIP { CDR @storage_slash_1 } ; - CAR @__slash_2 ; - PUSH @one_prec6 nat 1000000 ; - LAMBDA - (pair (pair mutez nat) nat) - mutez - { RENAME @_amount_coeff__one_prec6_slash_8 ; - DUP ; - CDR @one_prec6_slash_3 ; - DIP { DUP } ; - SWAP ; - CAR ; - CDR @coeff ; - DIP 2 { DUP } ; - DIG 2 ; - CAR ; - CAR @amount ; - MUL ; - EDIV ; - IF_NONE - { PUSH string "Division error in `apply_coeff`." ; FAILWITH } - { CAR } ; - DIP { DROP } } ; - PAIR @apply_coeff ; - SENDER @sender ; - AMOUNT @amount ; - BALANCE @contract_balance ; - DIP 5 { DUP @storage } ; - DIG 5 ; - DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - NEQ ; - PUSH mutez 1000000 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - GT ; - AND ; - IF { DUP @s ; - { CDR ; CDR ; CAR @min_deposit %min_deposit } ; - DIP 3 { DUP @amount } ; - DIG 3 ; - COMPARE ; - LT ; - IF { PUSH string "Deposited amount is too small." ; FAILWITH } { UNIT } ; - DROP ; - DUP @s ; - CAR %depositors ; - DIP 4 { DUP @sender } ; - DIG 4 ; - GET ; - IF_NONE - { DUP @s ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - DUP ; - CAR %deposited ; - SWAP ; - CDR ; - DUP ; - CAR %borrowed ; - SWAP ; - CDR ; - CDR %delegate ; - PUSH nat 1 ; - DIP 9 { DUP @s } ; - DIG 9 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %depositors_size } ; - ADD ; - PAIR %depositors_size %delegate ; - SWAP ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR %depositors ; - DIP 3 { DUP @amount } ; - DIG 3 ; - PAIR } - { DIP { DUP @s } ; - SWAP ; - DIP 4 { DUP @amount } ; - DIG 4 ; - DIP 2 { DUP @b } ; - DIG 2 ; - DIP 3 { DROP } ; - ADD ; - PAIR } ; - RENAME @_user_balance_s ; - DUP ; - CDR @s ; - DUP @s ; - CDR ; - DIP { DUP @s } ; - SWAP ; - CAR %depositors ; - DIP 3 { DUP } ; - DIG 3 ; - CAR @user_balance ; - DIP 8 { DUP @sender } ; - DIG 8 ; - DIP { SOME } ; - UPDATE ; - PAIR @s %depositors ; - DUP @s ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - CDR ; - DIP 11 { DUP @amount } ; - DIG 11 ; - DIP 7 { DUP @s } ; - DIG 7 ; - DIP 8 { DROP 3 } ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CAR %deposited } ; - ADD ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - NIL operation ; - PAIR } - { DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - NEQ ; - PUSH mutez 1000000 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - LE ; - AND ; - IF { DUP @s ; - CAR %depositors ; - DIP 4 { DUP @sender } ; - DIG 4 ; - GET ; - IF_NONE { PUSH string "Only depositors can withdraw." ; FAILWITH } {} ; - RENAME @user_balance ; - DIP 2 { DUP @contract_balance } ; - DIG 2 ; - DIP { DUP @user_balance } ; - SWAP ; - COMPARE ; - GT ; - IF { PUSH string "Withdraw amount greater than current contract balance." ; - FAILWITH } - { UNIT } ; - DROP ; - DIP { DUP @s } ; - SWAP ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - CDR ; - DIP 6 { DUP @user_balance } ; - DIG 6 ; - DIP 8 { DUP @s } ; - DIG 8 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CAR %deposited } ; - SUB ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - DUP @s ; - CDR ; - DIP { DUP @s } ; - SWAP ; - CAR %depositors ; - NONE mutez ; - DIP 8 { DUP @sender } ; - DIG 8 ; - UPDATE ; - PAIR @s %depositors ; - DUP @s ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - DUP ; - CAR %deposited ; - SWAP ; - CDR ; - DUP ; - CAR %borrowed ; - SWAP ; - CDR ; - CDR %delegate ; - PUSH nat 1 ; - DIP 9 { DUP @s } ; - DIG 9 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %depositors_size } ; - SUB ; - DUP ; - ABS ; - SWAP ; - GE ; - IF {} { PUSH string "Depositors counting error." ; FAILWITH } ; - PAIR %depositors_size %delegate ; - SWAP ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - DIP 8 { DUP @apply_coeff } ; - DIG 8 ; - DIP { DUP @s } ; - SWAP ; - { CDR ; CDR ; CDR ; CAR %withdraw_fee } ; - DIP 5 { DUP @user_balance } ; - DIG 5 ; - PAIR ; - DIP { DUP ; CAR ; SWAP ; CDR } ; - PAIR ; - EXEC @fee_amount ; - DIP { DUP @s } ; - SWAP ; - NIL operation ; - DIP 10 { DUP @sender } ; - DIG 10 ; - CONTRACT unit ; - IF_NONE - { PUSH string "No entrypoint default with parameter type unit" ; FAILWITH } - {} ; - DIP 10 { DUP @amount } ; - DIG 10 ; - DIP 4 { DUP @fee_amount } ; - DIG 4 ; - DIP 9 { DUP @user_balance } ; - DIG 9 ; - SUB ; - ADD @withdraw_amount ; - UNIT ; - TRANSFER_TOKENS @op_withdraw ; - CONS ; - DIP 3 { DUP @s } ; - DIG 3 ; - { CDR ; CAR %owner } ; - CONTRACT unit ; - IF_NONE - { PUSH string "No entrypoint default with parameter type unit" ; FAILWITH } - {} ; - DIP 3 { DUP @fee_amount } ; - DIG 3 ; - DIP 4 { DROP 5 } ; - UNIT ; - TRANSFER_TOKENS @op_fee ; - CONS ; - PAIR } - { DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - EQ ; - PUSH mutez 0 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - EQ ; - AND ; - IF { PUSH @one_prec6 nat 1000000 ; - LAMBDA - (pair nat nat) - nat - { RENAME @coeff__one_prec6_slash_14 ; - DUP ; - CAR @coeff_slash_15 ; - DIP { DUP } ; - SWAP ; - CDR @one_prec6_slash_3 ; - SUB ; - DUP ; - ABS ; - SWAP ; - GE ; - IF {} - { PUSH string "Invalid coefficient value in `get_coeff_compl`." ; FAILWITH } ; - DIP { DROP } } ; - PAIR @get_coeff_compl ; - DIP 5 { DUP @apply_coeff } ; - DIG 5 ; - PAIR ; - DIP { DUP @s } ; - SWAP ; - { CDR ; CDR ; CDR ; CDR ; CAR %collat_coeff } ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CAR %deposited } ; - PAIR ; - PAIR ; - DUP ; - { CDR ; CAR @apply_coeff_slash_13 } ; - DIP { DUP } ; - SWAP ; - { CDR ; CDR @get_coeff_compl_slash_18 } ; - DIP 2 { DUP } ; - DIG 2 ; - CAR ; - CDR @collat_coeff ; - DIP { DUP ; CAR ; SWAP ; CDR } ; - PAIR ; - EXEC ; - DIP 2 { DUP } ; - DIG 2 ; - CAR ; - CAR @deposited ; - PAIR ; - DIP { DUP ; CAR ; SWAP ; CDR } ; - DIP 3 { DROP } ; - PAIR ; - EXEC ; - DIP { DUP @s } ; - SWAP ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - DIP { DUP @max_borrowing } ; - SWAP ; - COMPARE ; - LT ; - IF { PUSH string "No available funds to borrow: contract is under-collateralized." ; - FAILWITH } - { UNIT } ; - DROP ; - DIP 2 { DUP @contract_balance } ; - DIG 2 ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - DIP 2 { DUP @max_borrowing } ; - DIG 2 ; - SUB ; - PAIR ; - DUP ; - CAR @a ; - DIP { DUP } ; - SWAP ; - CDR @b ; - DUP @b ; - DIP 2 { DUP @a } ; - DIG 2 ; - COMPARE ; - GT ; - IF { DUP @b } { DIP { DUP @a } ; SWAP } ; - DIP { DROP 3 } ; - PUSH mutez 0 ; - DIP { DUP @borrowing } ; - SWAP ; - COMPARE ; - EQ ; - IF { PUSH string "No available funds to borrow." ; FAILWITH } { UNIT } ; - DROP ; - DIP 2 { DUP @s } ; - DIG 2 ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - DUP ; - CAR %deposited ; - SWAP ; - CDR ; - CDR ; - DIP 7 { DUP @borrowing } ; - DIG 7 ; - DIP 10 { DUP @s } ; - DIG 10 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - ADD ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - DUP @s ; - NIL operation ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CAR %owner } ; - CONTRACT unit ; - IF_NONE - { PUSH string "No entrypoint default with parameter type unit" ; FAILWITH } - {} ; - DIP 4 { DUP @borrowing } ; - DIG 4 ; - DIP 4 { DROP 3 } ; - UNIT ; - TRANSFER_TOKENS @op ; - CONS ; - PAIR } - { DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - EQ ; - PUSH mutez 420000 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - EQ ; - AND ; - IF { DUP @s ; - NIL operation ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CDR %delegate } ; - SOME ; - SET_DELEGATE @op_set_delegate ; - CONS ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CAR %owner } ; - CONTRACT unit ; - IF_NONE - { PUSH string "No entrypoint default with parameter type unit" ; FAILWITH } - {} ; - PUSH mutez 420000 ; - UNIT ; - TRANSFER_TOKENS @op_refund ; - CONS ; - PAIR } - { DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - EQ ; - PUSH mutez 0 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - GT ; - AND ; - IF { DUP @s ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR @borrowed %borrowed } ; - DIP 3 { DUP @amount } ; - DIG 3 ; - COMPARE ; - GT ; - IF { PUSH string "Can't over-collateralize contract." ; FAILWITH } { UNIT } ; - DROP ; - DUP @s ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - DUP ; - CAR %deposited ; - SWAP ; - CDR ; - CDR ; - DIP 9 { DUP @amount } ; - DIG 9 ; - DIP 8 { DUP @s } ; - DIG 8 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - SUB ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - NIL operation ; - PAIR } - { PUSH string "You shouldn't be here." ; FAILWITH } } } } } ; - DIP { DROP 7 } } } diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.patched.tz b/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.patched.tz deleted file mode 100644 index cc733f4bc517..000000000000 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts/exprteUgjaxjf3jTheaj2fQkQsPFynyj3pCJ4mbzP26D4giEjQBwFb.patched.tz +++ /dev/null @@ -1,634 +0,0 @@ -{ parameter (unit %main) ; - storage - (pair :storage - (big_map :depositors address mutez) - (pair (address %owner) - (pair (mutez %min_deposit) - (pair (nat %withdraw_fee) - (pair (nat %collat_coeff) - (pair (mutez %deposited) - (pair (mutez %borrowed) (pair (nat %depositors_size) (key_hash %delegate))))))))) ; - code { DUP ; - DIP { CDR @storage_slash_1 } ; - CAR @__slash_2 ; - PUSH @one_prec6 nat 1000000 ; - LAMBDA - (pair (pair mutez nat) nat) - mutez - { RENAME @_amount_coeff__one_prec6_slash_8 ; - DUP ; - CDR @one_prec6_slash_3 ; - DIP { DUP } ; - SWAP ; - CAR ; - CDR @coeff ; - DIP 2 { DUP } ; - DIG 2 ; - CAR ; - CAR @amount ; - MUL ; - EDIV ; - IF_NONE - { PUSH string "Division error in `apply_coeff`." ; FAILWITH } - { CAR } ; - DIP { DROP } } ; - PAIR @apply_coeff ; - SENDER @sender ; - AMOUNT @amount ; - BALANCE @contract_balance ; - DIP 5 { DUP @storage } ; - DIG 5 ; - DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - NEQ ; - PUSH mutez 1000000 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - GT ; - AND ; - IF { DUP @s ; - { CDR ; CDR ; CAR @min_deposit %min_deposit } ; - DIP 3 { DUP @amount } ; - DIG 3 ; - COMPARE ; - LT ; - IF { PUSH string "Deposited amount is too small." ; FAILWITH } { UNIT } ; - DROP ; - DUP @s ; - CAR %depositors ; - DIP 4 { DUP @sender } ; - DIG 4 ; - GET ; - IF_NONE - { DUP @s ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - DUP ; - CAR %deposited ; - SWAP ; - CDR ; - DUP ; - CAR %borrowed ; - SWAP ; - CDR ; - CDR %delegate ; - PUSH nat 1 ; - DIP 9 { DUP @s } ; - DIG 9 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %depositors_size } ; - ADD ; - PAIR %depositors_size %delegate ; - SWAP ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR %depositors ; - DIP 3 { DUP @amount } ; - DIG 3 ; - PAIR } - { DIP { DUP @s } ; - SWAP ; - DIP 4 { DUP @amount } ; - DIG 4 ; - DIP 2 { DUP @b } ; - DIG 2 ; - DIP 3 { DROP } ; - ADD ; - PAIR } ; - RENAME @_user_balance_s ; - DUP ; - CDR @s ; - DUP @s ; - CDR ; - DIP { DUP @s } ; - SWAP ; - CAR %depositors ; - DIP 3 { DUP } ; - DIG 3 ; - CAR @user_balance ; - DIP 8 { DUP @sender } ; - DIG 8 ; - DIP { SOME } ; - UPDATE ; - PAIR @s %depositors ; - DUP @s ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - CDR ; - DIP 11 { DUP @amount } ; - DIG 11 ; - DIP 7 { DUP @s } ; - DIG 7 ; - DIP 8 { DROP 3 } ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CAR %deposited } ; - ADD ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - NIL operation ; - PAIR } - { DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - NEQ ; - PUSH mutez 1000000 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - LE ; - AND ; - IF { DUP @s ; - CAR %depositors ; - DIP 4 { DUP @sender } ; - DIG 4 ; - GET ; - IF_NONE { PUSH string "Only depositors can withdraw." ; FAILWITH } {} ; - RENAME @user_balance ; - DIP 2 { DUP @contract_balance } ; - DIG 2 ; - DIP { DUP @user_balance } ; - SWAP ; - COMPARE ; - GT ; - IF { PUSH string "Withdraw amount greater than current contract balance." ; - FAILWITH } - { UNIT } ; - DROP ; - DIP { DUP @s } ; - SWAP ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - CDR ; - DIP 6 { DUP @user_balance } ; - DIG 6 ; - DIP 8 { DUP @s } ; - DIG 8 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CAR %deposited } ; - SUB_MUTEZ ; - IF_NONE {UNIT ; FAILWITH} {}; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - DUP @s ; - CDR ; - DIP { DUP @s } ; - SWAP ; - CAR %depositors ; - NONE mutez ; - DIP 8 { DUP @sender } ; - DIG 8 ; - UPDATE ; - PAIR @s %depositors ; - DUP @s ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - DUP ; - CAR %deposited ; - SWAP ; - CDR ; - DUP ; - CAR %borrowed ; - SWAP ; - CDR ; - CDR %delegate ; - PUSH nat 1 ; - DIP 9 { DUP @s } ; - DIG 9 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %depositors_size } ; - SUB ; - DUP ; - ABS ; - SWAP ; - GE ; - IF {} { PUSH string "Depositors counting error." ; FAILWITH } ; - PAIR %depositors_size %delegate ; - SWAP ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - DIP 8 { DUP @apply_coeff } ; - DIG 8 ; - DIP { DUP @s } ; - SWAP ; - { CDR ; CDR ; CDR ; CAR %withdraw_fee } ; - DIP 5 { DUP @user_balance } ; - DIG 5 ; - PAIR ; - DIP { DUP ; CAR ; SWAP ; CDR } ; - PAIR ; - EXEC @fee_amount ; - DIP { DUP @s } ; - SWAP ; - NIL operation ; - DIP 10 { DUP @sender } ; - DIG 10 ; - CONTRACT unit ; - IF_NONE - { PUSH string "No entrypoint default with parameter type unit" ; FAILWITH } - {} ; - DIP 10 { DUP @amount } ; - DIG 10 ; - DIP 4 { DUP @fee_amount } ; - DIG 4 ; - DIP 9 { DUP @user_balance } ; - DIG 9 ; - SUB_MUTEZ ; - IF_NONE {UNIT ; FAILWITH} {}; - ADD @withdraw_amount ; - UNIT ; - TRANSFER_TOKENS @op_withdraw ; - CONS ; - DIP 3 { DUP @s } ; - DIG 3 ; - { CDR ; CAR %owner } ; - CONTRACT unit ; - IF_NONE - { PUSH string "No entrypoint default with parameter type unit" ; FAILWITH } - {} ; - DIP 3 { DUP @fee_amount } ; - DIG 3 ; - DIP 4 { DROP 5 } ; - UNIT ; - TRANSFER_TOKENS @op_fee ; - CONS ; - PAIR } - { DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - EQ ; - PUSH mutez 0 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - EQ ; - AND ; - IF { PUSH @one_prec6 nat 1000000 ; - LAMBDA - (pair nat nat) - nat - { RENAME @coeff__one_prec6_slash_14 ; - DUP ; - CAR @coeff_slash_15 ; - DIP { DUP } ; - SWAP ; - CDR @one_prec6_slash_3 ; - SUB ; - DUP ; - ABS ; - SWAP ; - GE ; - IF {} - { PUSH string "Invalid coefficient value in `get_coeff_compl`." ; FAILWITH } ; - DIP { DROP } } ; - PAIR @get_coeff_compl ; - DIP 5 { DUP @apply_coeff } ; - DIG 5 ; - PAIR ; - DIP { DUP @s } ; - SWAP ; - { CDR ; CDR ; CDR ; CDR ; CAR %collat_coeff } ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CAR %deposited } ; - PAIR ; - PAIR ; - DUP ; - { CDR ; CAR @apply_coeff_slash_13 } ; - DIP { DUP } ; - SWAP ; - { CDR ; CDR @get_coeff_compl_slash_18 } ; - DIP 2 { DUP } ; - DIG 2 ; - CAR ; - CDR @collat_coeff ; - DIP { DUP ; CAR ; SWAP ; CDR } ; - PAIR ; - EXEC ; - DIP 2 { DUP } ; - DIG 2 ; - CAR ; - CAR @deposited ; - PAIR ; - DIP { DUP ; CAR ; SWAP ; CDR } ; - DIP 3 { DROP } ; - PAIR ; - EXEC ; - DIP { DUP @s } ; - SWAP ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - DIP { DUP @max_borrowing } ; - SWAP ; - COMPARE ; - LT ; - IF { PUSH string "No available funds to borrow: contract is under-collateralized." ; - FAILWITH } - { UNIT } ; - DROP ; - DIP 2 { DUP @contract_balance } ; - DIG 2 ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - DIP 2 { DUP @max_borrowing } ; - DIG 2 ; - SUB_MUTEZ ; - IF_NONE {UNIT ; FAILWITH} {} ; - PAIR ; - DUP ; - CAR @a ; - DIP { DUP } ; - SWAP ; - CDR @b ; - DUP @b ; - DIP 2 { DUP @a } ; - DIG 2 ; - COMPARE ; - GT ; - IF { DUP @b } { DIP { DUP @a } ; SWAP } ; - DIP { DROP 3 } ; - PUSH mutez 0 ; - DIP { DUP @borrowing } ; - SWAP ; - COMPARE ; - EQ ; - IF { PUSH string "No available funds to borrow." ; FAILWITH } { UNIT } ; - DROP ; - DIP 2 { DUP @s } ; - DIG 2 ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - DUP ; - CAR %deposited ; - SWAP ; - CDR ; - CDR ; - DIP 7 { DUP @borrowing } ; - DIG 7 ; - DIP 10 { DUP @s } ; - DIG 10 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - ADD ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - DUP @s ; - NIL operation ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CAR %owner } ; - CONTRACT unit ; - IF_NONE - { PUSH string "No entrypoint default with parameter type unit" ; FAILWITH } - {} ; - DIP 4 { DUP @borrowing } ; - DIG 4 ; - DIP 4 { DROP 3 } ; - UNIT ; - TRANSFER_TOKENS @op ; - CONS ; - PAIR } - { DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - EQ ; - PUSH mutez 420000 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - EQ ; - AND ; - IF { DUP @s ; - NIL operation ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CDR %delegate } ; - SOME ; - SET_DELEGATE @op_set_delegate ; - CONS ; - DIP 2 { DUP @s } ; - DIG 2 ; - { CDR ; CAR %owner } ; - CONTRACT unit ; - IF_NONE - { PUSH string "No entrypoint default with parameter type unit" ; FAILWITH } - {} ; - PUSH mutez 420000 ; - UNIT ; - TRANSFER_TOKENS @op_refund ; - CONS ; - PAIR } - { DUP @s ; - { CDR ; CAR %owner } ; - DIP 4 { DUP @sender } ; - DIG 4 ; - COMPARE ; - EQ ; - PUSH mutez 0 ; - DIP 4 { DUP @amount } ; - DIG 4 ; - COMPARE ; - GT ; - AND ; - IF { DUP @s ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR @borrowed %borrowed } ; - DIP 3 { DUP @amount } ; - DIG 3 ; - COMPARE ; - GT ; - IF { PUSH string "Can't over-collateralize contract." ; FAILWITH } { UNIT } ; - DROP ; - DUP @s ; - DUP ; - CAR %depositors ; - SWAP ; - CDR ; - DUP ; - CAR %owner ; - SWAP ; - CDR ; - DUP ; - CAR %min_deposit ; - SWAP ; - CDR ; - DUP ; - CAR %withdraw_fee ; - SWAP ; - CDR ; - DUP ; - CAR %collat_coeff ; - SWAP ; - CDR ; - DUP ; - CAR %deposited ; - SWAP ; - CDR ; - CDR ; - DIP 9 { DUP @amount } ; - DIG 9 ; - DIP 8 { DUP @s } ; - DIG 8 ; - { CDR ; CDR ; CDR ; CDR ; CDR ; CDR ; CAR %borrowed } ; - SUB_MUTEZ ; - IF_NONE {UNIT ; FAILWITH} {} ; - PAIR %borrowed ; - SWAP ; - PAIR %deposited ; - SWAP ; - PAIR %collat_coeff ; - SWAP ; - PAIR %withdraw_fee ; - SWAP ; - PAIR %min_deposit ; - SWAP ; - PAIR %owner ; - SWAP ; - PAIR @s %depositors ; - NIL operation ; - PAIR } - { PUSH string "You shouldn't be here." ; FAILWITH } } } } } ; - DIP { DROP 7 } } } -- GitLab From b304cc2499b980cad0681b64829c0be2e01fd565 Mon Sep 17 00:00:00 2001 From: Fedor Sheremetyev Date: Mon, 3 Oct 2022 21:17:58 +0000 Subject: [PATCH 2/6] Tests/Tezt: test migration from Lima --- tezt/lib_tezos/protocol.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/lib_tezos/protocol.ml b/tezt/lib_tezos/protocol.ml index 5945af111279..fb9db1709da0 100644 --- a/tezt/lib_tezos/protocol.ml +++ b/tezt/lib_tezos/protocol.ml @@ -136,12 +136,12 @@ let write_parameter_file : Lwt.return overriden_parameters let next_protocol = function - | Kathmandu -> Some Alpha + | Kathmandu -> Some Lima | Lima -> Some Alpha | Alpha -> None let previous_protocol = function - | Alpha -> Some Kathmandu + | Alpha -> Some Lima | Lima -> Some Kathmandu | Kathmandu -> None -- GitLab From 205e8f0769731efff41e9cb28d5e18bc11f2a711 Mon Sep 17 00:00:00 2001 From: Fedor Sheremetyev Date: Mon, 3 Oct 2022 21:18:42 +0000 Subject: [PATCH 3/6] Tests/Python: test migration from Lima --- tests_python/tests_alpha/protocol.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests_python/tests_alpha/protocol.py b/tests_python/tests_alpha/protocol.py index d4e6e74c8306..c290e2a49e53 100644 --- a/tests_python/tests_alpha/protocol.py +++ b/tests_python/tests_alpha/protocol.py @@ -14,9 +14,9 @@ TENDERBAKE_PARAMETERS['consensus_committee_size'] = 67 FOLDER = constants.ALPHA_FOLDER -PREV_HASH = constants.KATHMANDU -PREV_DAEMON = constants.KATHMANDU_DAEMON -PREV_PARAMETERS = constants.KATHMANDU_PARAMETERS +PREV_HASH = constants.LIMA +PREV_DAEMON = constants.LIMA_DAEMON +PREV_PARAMETERS = constants.LIMA_PARAMETERS def activate( -- GitLab From 4b5e2cc74f65c59317d32dcd9123e14413d5f7c7 Mon Sep 17 00:00:00 2001 From: Fedor Sheremetyev Date: Mon, 17 Oct 2022 18:58:48 +0000 Subject: [PATCH 4/6] Tezt: update ghostnet dictator tests for Lima --- tezt/tests/ghostnet_dictator_migration.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/tests/ghostnet_dictator_migration.ml b/tezt/tests/ghostnet_dictator_migration.ml index a74c10c365b2..aa0c0daa633a 100644 --- a/tezt/tests/ghostnet_dictator_migration.ml +++ b/tezt/tests/ghostnet_dictator_migration.ml @@ -125,7 +125,7 @@ let register_migration_test chain_id = position = 2; remaining = 1; } ) - | Chain_id_ghostnet, _ -> + | Chain_id_ghostnet, Lima -> ( None, { Voting.index = 1; @@ -134,7 +134,7 @@ let register_migration_test chain_id = position = 7; remaining = 0; } ) - | Chain_id_mainnet, _ -> + | _, _ -> ( None, { Voting.index = 1; -- GitLab From 3e2b2bf5b58c47961c55d33f0dd4739f179ce2a9 Mon Sep 17 00:00:00 2001 From: Fedor Sheremetyev Date: Tue, 18 Oct 2022 17:07:24 +0000 Subject: [PATCH 5/6] Tezt: run tickets migration test on Lima --- tezt/tests/iticket_migration.ml | 10 +++++----- tezt/tests/main.ml | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tezt/tests/iticket_migration.ml b/tezt/tests/iticket_migration.ml index 0bddb3a7f69b..8121bfb7f8f4 100644 --- a/tezt/tests/iticket_migration.ml +++ b/tezt/tests/iticket_migration.ml @@ -27,7 +27,7 @@ ------- Component: Protocol Invocation: dune exec tezt/tests/main.exe -- --file iticket_migration.ml - Subject: Checks the migration of ITicket in protocol Alpha, to make sure + Subject: Checks the migration of ITicket in protocol Lima, to make sure that the old TICKET instruction is mapped to TICKET_DEPRECATED, and the old contracts continue to function provided that they avoid creating zero tickets. @@ -449,7 +449,7 @@ let test_ticket_migration_in_storage ~blocks_per_cycle ~migration_level in unit -(* This test activates Alpha protocol and asserts that it is impossible to +(* This test activates Lima protocol and asserts that it is impossible to originate contracts containing the deprecated TICKET instruction. *) let test_iticket_deprecation ~protocol = @@ -543,13 +543,13 @@ let register ~migrate_from ~migrate_to = let parameters = JSON.parse_file (Protocol.parameter_file migrate_to) in let blocks_per_cycle = JSON.(get "blocks_per_cycle" parameters |> as_int) in match migrate_to with - | Protocol.Alpha -> + | Protocol.Lima -> test_ticket_migration ~blocks_per_cycle ~migration_level:(2 * blocks_per_cycle) ~migrate_from ~migrate_to ; - test_iticket_deprecation ~protocol:Protocol.Alpha ; + test_iticket_deprecation ~protocol:Protocol.Lima ; test_ticket_migration_in_storage ~blocks_per_cycle ~migration_level:(2 * blocks_per_cycle) @@ -560,5 +560,5 @@ let register ~migrate_from ~migrate_to = ~migration_level:(2 * blocks_per_cycle) ~migrate_from ~migrate_to ; - test_iticket_after_migration ~protocol:Protocol.Alpha + test_iticket_after_migration ~protocol:Protocol.Lima | _ -> () diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 12efd8090360..577624899e9c 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -57,7 +57,6 @@ let register_protocol_independent_tests () = (* Tests related to protocol migration. *) let register_protocol_migration_tests () = let migrate_from = Option.get @@ Protocol.previous_protocol migrate_to in - Iticket_migration.register ~migrate_from ~migrate_to ; Mockup.register_constant_migration ~migrate_from ~migrate_to ; Protocol_migration.register ~migrate_from ~migrate_to ; Protocol_table_update.register ~migrate_from ~migrate_to ; @@ -78,6 +77,12 @@ let register_protocol_migration_tests () = ~to_protocol:Demo ~loser_protocols:[migrate_from] +(* Tests related to one-off protocol migrations used in the past. *) +let register_older_protocol_migration_tests () = + Iticket_migration.register + ~migrate_from:Protocol.Kathmandu + ~migrate_to:Protocol.Lima + (* Register tests that use [Protocol.register_test] and for which we rely on [?supports] to decide which protocols the tests should run on. As a consequence, all those tests should be registered with [Protocol.all] @@ -166,6 +171,7 @@ let register_protocol_specific_because_regression_tests () = let () = register_protocol_independent_tests () ; register_protocol_migration_tests () ; + register_older_protocol_migration_tests () ; register_protocol_tests_that_use_supports_correctly () ; register_protocol_specific_because_regression_tests () ; (* Test.run () should be the last statement, don't register afterwards! *) -- GitLab From 59c37bb91b21bdacc4452f3635f2f2ae0e2cec6b Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Wed, 19 Oct 2022 15:32:05 +0200 Subject: [PATCH 6/6] Proto: remove leftover from Kathmandu migration --- .../lib_protocol/delegate_sampler.ml | 18 ------------- .../lib_protocol/delegate_sampler.mli | 5 ---- src/proto_alpha/lib_protocol/raw_context.ml | 6 ----- src/proto_alpha/lib_protocol/raw_context.mli | 4 --- src/proto_alpha/lib_protocol/storage.ml | 26 ------------------- src/proto_alpha/lib_protocol/storage.mli | 9 ------- 6 files changed, 68 deletions(-) diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.ml b/src/proto_alpha/lib_protocol/delegate_sampler.ml index 827c81a7a9f0..0040d65f71e7 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.ml +++ b/src/proto_alpha/lib_protocol/delegate_sampler.ml @@ -237,21 +237,3 @@ let clear_outdated_sampling_data ctxt ~new_cycle = | Some outdated_cycle -> Delegate_sampler_state.remove_existing ctxt outdated_cycle >>=? fun ctxt -> Seed_storage.remove_for_cycle ctxt outdated_cycle - -module Migration_from_Kathmandu = struct - let update_sampler ctxt cycle = - let open Lwt_tzresult_syntax in - let* stakes = Stake_storage.get_selected_distribution ctxt cycle in - let* stakes_pk = - List.fold_left_es - (fun acc (delegate, stake) -> - Delegate_consensus_key.active_pubkey ctxt delegate >>=? fun pk -> - return ((pk, Tez_repr.to_mutez stake) :: acc)) - [] - stakes - in - let state = Sampler.create stakes_pk in - Delegate_sampler_state.init ctxt cycle state >>=? fun ctxt -> - Storage.Seed.For_cycle.get ctxt cycle >>=? fun seed -> - Lwt.return (Raw_context.init_sampler_for_cycle ctxt cycle seed state) -end diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.mli b/src/proto_alpha/lib_protocol/delegate_sampler.mli index 53a8386f1ec5..b398a9ca9464 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.mli +++ b/src/proto_alpha/lib_protocol/delegate_sampler.mli @@ -68,8 +68,3 @@ val clear_outdated_sampling_data : val select_distribution_for_cycle : Raw_context.t -> Cycle_repr.t -> Raw_context.t tzresult Lwt.t - -module Migration_from_Kathmandu : sig - val update_sampler : - Raw_context.t -> Cycle_repr.t -> Raw_context.t tzresult Lwt.t -end diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 0354a7336963..7bcef9f238a4 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1282,12 +1282,6 @@ let record_dictator_proposal_seen ctxt = update_dictator_proposal_seen ctxt true let dictator_proposal_seen ctxt = dictator_proposal_seen ctxt -module Migration_from_Kathmandu = struct - let reset_samplers ctxt = - let ctxt = update_sampler_state ctxt Cycle_repr.Map.empty in - ok ctxt -end - let init_sampler_for_cycle ctxt cycle seed state = let map = sampler_state ctxt in if Cycle_repr.Map.mem cycle map then error (Sampler_already_set cycle) diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index 8fdc7c64c117..719423626040 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -423,7 +423,3 @@ module Dal : sig [endorser] for the current level. *) val shards : t -> endorser:Signature.Public_key_hash.t -> int list end - -module Migration_from_Kathmandu : sig - val reset_samplers : t -> t tzresult -end diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 9b47de7bd99c..b1c5b774c43f 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -1009,27 +1009,6 @@ module Cycle = struct end) (Tez_repr) - module Migration_from_Kathmandu = struct - let public_key_with_ghost_hash_encoding = - Data_encoding.conv - fst - (fun x -> (x, Signature.Public_key.hash x)) - Signature.Public_key.encoding - - module Delegate_sampler_state = - Indexed_context.Make_map - (Ghost) - (struct - let name = ["delegate_sampler_state"] - end) - (struct - type t = - (Signature.Public_key.t * Signature.Public_key_hash.t) Sampler.t - - let encoding = Sampler.encoding public_key_with_ghost_hash_encoding - end) - end - module Delegate_sampler_state = Indexed_context.Make_map (Registered) @@ -2084,8 +2063,3 @@ module Zk_rollup = struct (option Ticket_hash_repr.encoding)) end) end - -module Migration_from_Kathmandu = struct - module Delegate_sampler_state = - Cycle.Migration_from_Kathmandu.Delegate_sampler_state -end diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index c7ae069a2062..a69a729c0a3f 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -947,12 +947,3 @@ module Zk_rollup : sig and type key = int64 and type value = Zk_rollup_operation_repr.t * Ticket_hash_repr.t option end - -module Migration_from_Kathmandu : sig - module Delegate_sampler_state : - Indexed_data_storage - with type key = Cycle_repr.t - and type value = - (Signature.Public_key.t * Signature.Public_key_hash.t) Sampler.t - and type t := Raw_context.t -end -- GitLab