From 7eea61dd05ea90c23cc611a1168a95ff3d5e8761 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 13:15:32 +0200 Subject: [PATCH 1/3] Proto: raw_originate expects an originated contract --- src/proto_alpha/lib_plugin/plugin.ml | 4 ++-- src/proto_alpha/lib_protocol/alpha_context.mli | 2 +- src/proto_alpha/lib_protocol/apply.ml | 2 +- src/proto_alpha/lib_protocol/bootstrap_storage.ml | 4 ++-- src/proto_alpha/lib_protocol/contract_storage.ml | 1 + src/proto_alpha/lib_protocol/contract_storage.mli | 2 +- src/proto_alpha/lib_protocol/liquidity_baking_migration.ml | 4 ++-- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index d810ee1c7fef..efb1ae450bda 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -2452,13 +2452,13 @@ module RPC = struct let ctxt = Origination_nonce.init ctxt Operation_hash.zero in Contract.fresh_contract_from_current_nonce ctxt >>?= fun (ctxt, dummy_contract_hash) -> - let dummy_contract = Contract.Originated dummy_contract_hash in Contract.raw_originate ctxt ~prepaid_bootstrap_storage:false - dummy_contract + dummy_contract_hash ~script:(script, None) >>=? fun ctxt -> + let dummy_contract = Contract.Originated dummy_contract_hash in Token.transfer ~origin:Simulation ctxt diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index dd2be744c943..c9f970fd2912 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1582,7 +1582,7 @@ module Contract : sig val raw_originate : context -> prepaid_bootstrap_storage:bool -> - t -> + Contract_hash.t -> script:Script.t * Lazy_storage.diffs option -> context tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index c297a43f71b4..523ac5e8d1bc 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1065,13 +1065,13 @@ let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract Gas.consume ctxt (Script.strip_locations_cost code) >>?= fun ctxt -> let code = Script.lazy_expr (Micheline.strip_locations code) in let script = {Script.code; storage} in - let contract = Contract.Originated contract in Contract.raw_originate ctxt ~prepaid_bootstrap_storage:false contract ~script:(script, lazy_storage_diff) >>=? fun ctxt -> + let contract = Contract.Originated contract in (match delegate with | None -> return ctxt | Some delegate -> Delegate.init ctxt contract delegate) diff --git a/src/proto_alpha/lib_protocol/bootstrap_storage.ml b/src/proto_alpha/lib_protocol/bootstrap_storage.ml index 62a38dae7711..ce7a64777383 100644 --- a/src/proto_alpha/lib_protocol/bootstrap_storage.ml +++ b/src/proto_alpha/lib_protocol/bootstrap_storage.ml @@ -52,14 +52,14 @@ let init_contract ~typecheck (ctxt, balance_updates) ({delegate; amount; script} : Parameters_repr.bootstrap_contract) = Contract_storage.fresh_contract_from_current_nonce ctxt >>?= fun (ctxt, contract_hash) -> - let contract = Contract_repr.Originated contract_hash in typecheck ctxt script >>=? fun (script, ctxt) -> Contract_storage.raw_originate ctxt ~prepaid_bootstrap_storage:true - contract + contract_hash ~script >>=? fun ctxt -> + let contract = Contract_repr.Originated contract_hash in (match delegate with | None -> return ctxt | Some delegate -> Delegate_storage.init ctxt contract delegate) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 8fc19e17cc91..39c197670228 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -405,6 +405,7 @@ let update_script_lazy_storage c = function let raw_originate c ~prepaid_bootstrap_storage (* Free space for bootstrap contracts *) contract ~script = + let contract = Contract_repr.Originated contract in Storage.Contract.Spendable_balance.init c contract Tez_repr.zero >>=? fun c -> let {Script_repr.code; storage}, lazy_storage_diff = script in Storage.Contract.Code.init c contract code >>=? fun (c, code_size) -> diff --git a/src/proto_alpha/lib_protocol/contract_storage.mli b/src/proto_alpha/lib_protocol/contract_storage.mli index 7c92fff7e9f0..ec287ace252e 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.mli +++ b/src/proto_alpha/lib_protocol/contract_storage.mli @@ -145,7 +145,7 @@ val spend_only_call_from_token : val raw_originate : Raw_context.t -> prepaid_bootstrap_storage:bool -> - Contract_repr.t -> + Contract_hash.t -> script:Script_repr.t * Lazy_storage_diff.diffs option -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml b/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml index 8e773910ffb2..4d0644ce0b9a 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml +++ b/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml @@ -112,13 +112,13 @@ let test_fa12_init_storage manager = [] ))) let originate ctxt address_hash ~balance script = - let address = Contract_repr.Originated address_hash in Contract_storage.raw_originate ctxt ~prepaid_bootstrap_storage:true - address + address_hash ~script >>=? fun ctxt -> + let address = Contract_repr.Originated address_hash in Contract_storage.used_storage_space ctxt address >>=? fun size -> Fees_storage.burn_origination_fees ~origin:Protocol_migration -- GitLab From c3ba76c5e98d8bdf78e04cacb4aca563dd6b01f3 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 13:20:34 +0200 Subject: [PATCH 2/3] Proto/Results: originated_contracts are originated contracts --- src/proto_alpha/lib_client/client_proto_context.ml | 2 +- src/proto_alpha/lib_client/client_proto_context.mli | 6 ++++-- src/proto_alpha/lib_client/client_proto_fa12.mli | 3 ++- .../lib_client/client_proto_multisig.mli | 6 ++++-- src/proto_alpha/lib_client/injection.ml | 2 +- src/proto_alpha/lib_client/injection.mli | 2 +- src/proto_alpha/lib_client/managed_contract.ml | 3 ++- src/proto_alpha/lib_client/managed_contract.mli | 3 ++- src/proto_alpha/lib_client/operation_result.ml | 4 ++-- src/proto_alpha/lib_protocol/alpha_context.mli | 2 +- src/proto_alpha/lib_protocol/apply.ml | 13 +++++-------- src/proto_alpha/lib_protocol/apply_results.ml | 8 ++++---- src/proto_alpha/lib_protocol/apply_results.mli | 4 ++-- .../lib_protocol/liquidity_baking_migration.ml | 2 +- src/proto_alpha/lib_protocol/migration_repr.ml | 7 +++++-- src/proto_alpha/lib_protocol/migration_repr.mli | 2 +- .../operations/test_combined_operations.ml | 4 +++- .../test/integration/test_liquidity_baking.ml | 2 +- 18 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 581634628ed0..e1e2baad06b7 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -408,7 +408,7 @@ let originate_contract (cctxt : #full) ~chain ~block ?confirmations ?dry_run return (oph, op, result)) >>=? fun res -> Lwt.return (Injection.originated_contracts ~force:false result) >>=? function - | [contract] -> return (res, contract) + | [contract] -> return (res, Contract.Originated contract) | contracts -> failwith "The origination introduced %d contracts instead of one." diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 63887eab680b..e4fe99e770b3 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -229,7 +229,8 @@ val transfer_with_script : fee_parameter:Injection.fee_parameter -> ?replace_by_fees:bool -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t val transfer : @@ -257,7 +258,8 @@ val transfer : fee_parameter:Injection.fee_parameter -> ?replace_by_fees:bool -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t val build_reveal_operation : diff --git a/src/proto_alpha/lib_client/client_proto_fa12.mli b/src/proto_alpha/lib_client/client_proto_fa12.mli index a8d4644848a9..5eaf1989abbc 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.mli +++ b/src/proto_alpha/lib_client/client_proto_fa12.mli @@ -109,7 +109,8 @@ val call_contract : ?counter:Z.t -> fee_parameter:Injection.fee_parameter -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t (** Single transfer operation. *) diff --git a/src/proto_alpha/lib_client/client_proto_multisig.mli b/src/proto_alpha/lib_client/client_proto_multisig.mli index 76543977831f..bd2f3d746552 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.mli +++ b/src/proto_alpha/lib_client/client_proto_multisig.mli @@ -120,7 +120,8 @@ val call_multisig : ?counter:Z.t -> fee_parameter:Injection.fee_parameter -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t (* Same as [call_multisig] but the action to be performed is reconstructed from @@ -146,5 +147,6 @@ val call_multisig_on_bytes : ?counter:Z.t -> fee_parameter:Injection.fee_parameter -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 9ab3b795ef02..c1ae74b26d7f 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -1051,7 +1051,7 @@ let inject_operation_internal (type kind) cctxt ~chain ~block ?confirmations Lwt.return (originated_contracts result.contents ~force) >>=? fun contracts -> List.iter_s - (fun c -> cctxt#message "New contract %a originated." Contract.pp c) + (fun c -> cctxt#message "New contract %a originated." Contract_hash.pp c) contracts >>= fun () -> (match confirmations with diff --git a/src/proto_alpha/lib_client/injection.mli b/src/proto_alpha/lib_client/injection.mli index fd1b1104a74b..d9e81c89e14d 100644 --- a/src/proto_alpha/lib_client/injection.mli +++ b/src/proto_alpha/lib_client/injection.mli @@ -119,4 +119,4 @@ val inject_manager_operation : by looking at the operation results. Fails if an operation in the batch is failed unless [force] is given. *) val originated_contracts : - force:bool -> 'kind contents_result_list -> Contract.t list tzresult + force:bool -> 'kind contents_result_list -> Contract_hash.t list tzresult diff --git a/src/proto_alpha/lib_client/managed_contract.ml b/src/proto_alpha/lib_client/managed_contract.ml index 96294964ec36..0696ec0cf423 100644 --- a/src/proto_alpha/lib_client/managed_contract.ml +++ b/src/proto_alpha/lib_client/managed_contract.ml @@ -290,7 +290,8 @@ let transfer (cctxt : #full) ~chain ~block ?confirmations ?dry_run ?verbose_signing ?simulation ?(force = false) ?branch ~source ~src_pk ~src_sk ~contract ~destination ?(entrypoint = Entrypoint.default) ?arg ~amount ?fee ?gas_limit ?storage_limit ?counter ~fee_parameter () : - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t = build_transaction_operation cctxt diff --git a/src/proto_alpha/lib_client/managed_contract.mli b/src/proto_alpha/lib_client/managed_contract.mli index 67c4a4226e98..e02cf3fa7aab 100644 --- a/src/proto_alpha/lib_client/managed_contract.mli +++ b/src/proto_alpha/lib_client/managed_contract.mli @@ -110,7 +110,8 @@ val transfer : ?counter:counter -> fee_parameter:Injection.fee_parameter -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t val build_lambda_for_set_delegate : delegate:public_key_hash option -> string diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index fdc7ce243ae0..0af57d8b6f85 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -474,7 +474,7 @@ let pp_manager_operation_contents_and_result ppf Format.fprintf ppf "@,@[Originated contracts:@,%a@]" - (Format.pp_print_list Contract.pp) + (Format.pp_print_list Contract_hash.pp) contracts) ; (match storage with | None -> () @@ -526,7 +526,7 @@ let pp_manager_operation_contents_and_result ppf Format.fprintf ppf "@,@[Originated contracts:@,%a@]" - (Format.pp_print_list Contract.pp) + (Format.pp_print_list Contract_hash.pp) contracts) ; if storage_size <> Z.zero then Format.fprintf ppf "@,Storage size: %s bytes" (Z.to_string storage_size) ; diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index c9f970fd2912..07627ae7e429 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3423,7 +3423,7 @@ end module Migration : sig type origination_result = { balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; storage_size : Z.t; paid_storage_size_diff : Z.t; } diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 523ac5e8d1bc..6d21dc7235c5 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -929,9 +929,6 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract_hash ~amount >>=? fun (ctxt, new_size, contract_paid_storage_size_diff) -> Contract.originated_from_current_nonce ~since:before_operation ~until:ctxt >>=? fun originated_contracts -> - let originated_contracts = - List.map (fun c -> Contract.Originated c) originated_contracts - in Lwt.return ( Script_cache.update ctxt @@ -1038,8 +1035,8 @@ let apply_transaction_to_tx_rollup ~ctxt ~parameters_ty ~parameters ~payer in return (ctxt, result, []) -let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract - ~delegate ~source ~credit ~before_operation = +let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code + ~contract:contract_hash ~delegate ~source ~credit ~before_operation = Script_ir_translator.collect_lazy_storage ctxt storage_type storage >>?= fun (to_duplicate, ctxt) -> let to_update = Script_ir_translator.no_lazy_storage_id in @@ -1068,10 +1065,10 @@ let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract Contract.raw_originate ctxt ~prepaid_bootstrap_storage:false - contract + contract_hash ~script:(script, lazy_storage_diff) >>=? fun ctxt -> - let contract = Contract.Originated contract in + let contract = Contract.Originated contract_hash in (match delegate with | None -> return ctxt | Some delegate -> Delegate.init ctxt contract delegate) @@ -1085,7 +1082,7 @@ let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract { lazy_storage_diff; balance_updates; - originated_contracts = [contract]; + originated_contracts = [contract_hash]; consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; storage_size = size; paid_storage_size_diff; diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index bd9911b11ee5..3743c02991f4 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -113,7 +113,7 @@ type successful_transaction_result = storage : Script.expr option; lazy_storage_diff : Lazy_storage.diffs option; balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; consumed_gas : Gas.Arith.fp; storage_size : Z.t; paid_storage_size_diff : Z.t; @@ -137,7 +137,7 @@ type _ successful_manager_operation_result = | Origination_result : { lazy_storage_diff : Lazy_storage.diffs option; balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; consumed_gas : Gas.Arith.fp; storage_size : Z.t; paid_storage_size_diff : Z.t; @@ -387,7 +387,7 @@ module Manager_result = struct (obj9 (opt "storage" Script.expr_encoding) (dft "balance_updates" Receipt.balance_updates_encoding []) - (dft "originated_contracts" (list Contract.encoding) []) + (dft "originated_contracts" (list Contract.originated_encoding) []) (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (dft "storage_size" z Z.zero) @@ -494,7 +494,7 @@ module Manager_result = struct ~encoding: (obj7 (dft "balance_updates" Receipt.balance_updates_encoding []) - (dft "originated_contracts" (list Contract.encoding) []) + (dft "originated_contracts" (list Contract.originated_encoding) []) (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (dft "storage_size" z Z.zero) diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index bf62d799c485..980e8cda1f62 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -141,7 +141,7 @@ and successful_transaction_result = storage : Script.expr option; lazy_storage_diff : Lazy_storage.diffs option; balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; consumed_gas : Gas.Arith.fp; storage_size : Z.t; paid_storage_size_diff : Z.t; @@ -167,7 +167,7 @@ and _ successful_manager_operation_result = | Origination_result : { lazy_storage_diff : Lazy_storage.diffs option; balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; consumed_gas : Gas.Arith.fp; storage_size : Z.t; paid_storage_size_diff : Z.t; diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml b/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml index 4d0644ce0b9a..4f4d13dfa38e 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml +++ b/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml @@ -146,7 +146,7 @@ let originate ctxt address_hash ~balance script = let result : Migration_repr.origination_result = { balance_updates; - originated_contracts = [address]; + originated_contracts = [address_hash]; storage_size = size; paid_storage_size_diff = size; } diff --git a/src/proto_alpha/lib_protocol/migration_repr.ml b/src/proto_alpha/lib_protocol/migration_repr.ml index 5d4d513caff1..0008eed3f778 100644 --- a/src/proto_alpha/lib_protocol/migration_repr.ml +++ b/src/proto_alpha/lib_protocol/migration_repr.ml @@ -25,7 +25,7 @@ type origination_result = { balance_updates : Receipt_repr.balance_updates; - originated_contracts : Contract_repr.t list; + originated_contracts : Contract_hash.t list; storage_size : Z.t; paid_storage_size_diff : Z.t; } @@ -57,6 +57,9 @@ let origination_result_list_encoding = }) (obj4 (dft "balance_updates" Receipt_repr.balance_updates_encoding []) - (dft "originated_contracts" (list Contract_repr.encoding) []) + (dft + "originated_contracts" + (list Contract_repr.originated_encoding) + []) (dft "storage_size" z Z.zero) (dft "paid_storage_size_diff" z Z.zero))) diff --git a/src/proto_alpha/lib_protocol/migration_repr.mli b/src/proto_alpha/lib_protocol/migration_repr.mli index ea34cb1b7ee6..1fb90c08c0d7 100644 --- a/src/proto_alpha/lib_protocol/migration_repr.mli +++ b/src/proto_alpha/lib_protocol/migration_repr.mli @@ -31,7 +31,7 @@ *) type origination_result = { balance_updates : Receipt_repr.balance_updates; - originated_contracts : Contract_repr.t list; + originated_contracts : Contract_hash.t list; storage_size : Z.t; paid_storage_size_diff : Z.t; } diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml index ea16261ab262..da6145768a97 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml @@ -149,7 +149,9 @@ let test_multiple_origination_and_delegation () = Assert.balance_was_debited ~loc:__LOC__ (I inc) c1 c1_old_balance total_cost >>=? fun () -> List.iter_es - (fun c -> Assert.balance_is ~loc:__LOC__ (I inc) c (Test_tez.of_int 10)) + (fun c -> + let c = Contract.Originated c in + Assert.balance_is ~loc:__LOC__ (I inc) c (Test_tez.of_int 10)) new_contracts let expect_failure = function diff --git a/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml b/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml index 4272ebd3f7b9..78c42d5fce1b 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml @@ -359,7 +359,7 @@ let get_lqt_result results = let get_address_in_result result = match result with | Apply_results.Origination_result {originated_contracts; _} -> ( - match originated_contracts with [Originated c] -> c | _ -> assert false) + match originated_contracts with [c] -> c | _ -> assert false) let get_balance_updates_in_result result = match result with -- GitLab From 4eed2284da518088a4202e7a90cdb9be2d441cd5 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 14:08:35 +0200 Subject: [PATCH 3/3] Proto/Michelson: self is an originated contract --- .../lib_benchmark/execution_context.ml | 4 +-- .../interpreter_benchmarks.ml | 2 +- .../sapling_benchmarks.ml | 2 +- .../sapling_generation.ml | 2 +- .../lib_client/client_proto_programs.ml | 2 +- .../lib_client/client_proto_programs.mli | 2 +- .../client_proto_programs_commands.ml | 2 +- src/proto_alpha/lib_plugin/plugin.ml | 25 ++++++++-------- src/proto_alpha/lib_protocol/apply.ml | 4 +-- .../lib_protocol/script_interpreter.ml | 30 +++++++++++-------- .../lib_protocol/script_interpreter.mli | 2 +- .../lib_protocol/script_interpreter_defs.ml | 5 ++-- .../lib_protocol/script_typed_ir.ml | 2 +- .../lib_protocol/script_typed_ir.mli | 2 +- .../test/helpers/contract_helpers.ml | 2 +- .../michelson/test_interpretation.ml | 2 +- .../integration/operations/test_transfer.ml | 2 +- 17 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/proto_alpha/lib_benchmark/execution_context.ml b/src/proto_alpha/lib_benchmark/execution_context.ml index ede85b37f8bb..86fbdd7278e7 100644 --- a/src/proto_alpha/lib_benchmark/execution_context.ml +++ b/src/proto_alpha/lib_benchmark/execution_context.ml @@ -58,10 +58,10 @@ let make ~rng_state = let level = Script_int.zero_n in let open Script_interpreter in (match context with - | `Mem_block (block, (bs1, bs2, bs3, _, _)) -> + | `Mem_block (block, (bs1, bs2, _, _, _)) -> let source = bs1 in let payer = bs2 in - let self = bs3 in + let self = Contract_helpers.default_self in let step_constants = { source; diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml index d934fca4a4aa..5e885fe2d41f 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml @@ -2867,7 +2867,7 @@ module Registration_section = struct { source = zero; payer = zero; - self = zero; + self = Contract_hash.zero; amount = Tez.zero; balance = Tez.zero; chain_id = Chain_id.zero; diff --git a/src/proto_alpha/lib_benchmarks_proto/sapling_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/sapling_benchmarks.ml index c1571830c6d4..53246451c72b 100644 --- a/src/proto_alpha/lib_benchmarks_proto/sapling_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/sapling_benchmarks.ml @@ -102,7 +102,7 @@ module Apply_diff_bench : Benchmark.S = struct Format.eprintf "tx hash: %d@." (Hashtbl.hash sapling_transition.sapling_tx) ; - let address = Alpha_context.Contract.to_b58check step_constants.self in + let address = Contract_hash.to_b58check step_constants.self in let chain_id = Environment.Chain_id.to_b58check step_constants.chain_id in diff --git a/src/proto_alpha/lib_benchmarks_proto/sapling_generation.ml b/src/proto_alpha/lib_benchmarks_proto/sapling_generation.ml index 15b69c5e1208..bbe1c2c2ec90 100644 --- a/src/proto_alpha/lib_benchmarks_proto/sapling_generation.ml +++ b/src/proto_alpha/lib_benchmarks_proto/sapling_generation.ml @@ -504,7 +504,7 @@ let generate (save_to : string) (tx_count : int) @@ Option.fold ~none:shared_seed ~some:(fun seed -> [|seed|]) seed in Execution_context.make ~rng_state >>=? fun (ctxt, step_constants) -> - let address = Alpha_context.Contract.to_b58check step_constants.self in + let address = Contract_hash.to_b58check step_constants.self in let chain_id = Environment.Chain_id.to_b58check step_constants.chain_id in diff --git a/src/proto_alpha/lib_client/client_proto_programs.ml b/src/proto_alpha/lib_client/client_proto_programs.ml index f79f858fee94..e2e7d31e3803 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.ml +++ b/src/proto_alpha/lib_client/client_proto_programs.ml @@ -150,7 +150,7 @@ type run_params = { program : Michelson_v1_parser.parsed; storage : Michelson_v1_parser.parsed; entrypoint : Entrypoint.t option; - self : Contract.t option; + self : Contract_hash.t option; } let run_view (cctxt : #Protocol_client_context.rpc_context) diff --git a/src/proto_alpha/lib_client/client_proto_programs.mli b/src/proto_alpha/lib_client/client_proto_programs.mli index 4276f29fc585..f24f4abeaa66 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.mli +++ b/src/proto_alpha/lib_client/client_proto_programs.mli @@ -66,7 +66,7 @@ type run_params = { program : Michelson_v1_parser.parsed; storage : Michelson_v1_parser.parsed; entrypoint : Entrypoint.t option; - self : Contract.t option; + self : Contract_hash.t option; } val run_view : diff --git a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml index b1124799d886..d82c6be1bc6c 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml @@ -97,7 +97,7 @@ let commands () = () in let self_arg = - ContractAlias.destination_arg + OriginatedContractAlias.destination_arg ~name:"self-address" ~doc:"address of the contract (i.e. SELF_ADDRESS) for the transaction" () diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index efb1ae450bda..a4e87f1dd557 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1711,7 +1711,7 @@ module RPC = struct (req "chain_id" Chain_id.encoding) (opt "source" Contract.encoding) (opt "payer" Contract.encoding) - (opt "self" Contract.encoding) + (opt "self" Contract.originated_encoding) (dft "entrypoint" Entrypoint.simple_encoding Entrypoint.default)) (obj4 (opt "unparsing_mode" unparsing_mode_encoding) @@ -2439,7 +2439,7 @@ module RPC = struct (* A convenience type for return values of [ensure_contracts_exist] below. *) type run_code_config = { balance : Tez.t; - self : Contract.t; + self : Contract_hash.t; payer : Contract.t; source : Contract.t; } @@ -2472,18 +2472,19 @@ module RPC = struct | None -> let balance = Option.value ~default:default_balance balance in originate_dummy_contract ctxt script balance - >>=? fun (ctxt, addr) -> - return (ctxt, Contract.Originated addr, balance) + >>=? fun (ctxt, addr) -> return (ctxt, addr, balance) | Some addr -> default_from_context ctxt - (fun c -> Contract.get_balance c addr) + (fun c -> Contract.get_balance c (Contract.Originated addr)) balance >>=? fun bal -> return (ctxt, addr, bal)) >>=? fun (ctxt, self, balance) -> let source, payer = match (src_opt, pay_opt) with - | None, None -> (self, self) + | None, None -> + let self = Contract.Originated self in + (self, self) | Some c, None | None, Some c -> (c, c) | Some src, Some pay -> (src, pay) in @@ -2669,7 +2670,7 @@ module RPC = struct (fun ctxt () - ( contract, + ( contract_hash, entrypoint, input, chain_id, @@ -2680,7 +2681,7 @@ module RPC = struct now, level ) -> - let contract = Contract.Originated contract in + let contract = Contract.Originated contract_hash in Contract.get_script ctxt contract >>=? fun (ctxt, script_opt) -> Option.fold ~some:ok @@ -2727,7 +2728,7 @@ module RPC = struct { source; payer; - self = contract; + self = contract_hash; amount = Tez.zero; balance; chain_id; @@ -2769,7 +2770,7 @@ module RPC = struct (fun ctxt () - ( ( contract, + ( ( contract_hash, view, input, unlimited_gas, @@ -2781,7 +2782,7 @@ module RPC = struct now ), level ) -> - let contract = Contract.Originated contract in + let contract = Contract.Originated contract_hash in Contract.get_script ctxt contract >>=? fun (ctxt, script_opt) -> Option.fold ~some:ok @@ -2828,7 +2829,7 @@ module RPC = struct { Script_interpreter.source; payer; - self = contract; + self = contract_hash; amount = Tez.zero; balance; chain_id; diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 6d21dc7235c5..b818245830e0 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -878,7 +878,7 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract_hash ~amount { source; payer = Contract.Implicit payer; - self = contract; + self = contract_hash; amount; chain_id; balance; @@ -3161,7 +3161,7 @@ let apply_liquidity_baking_subsidy ctxt ~toggle_vote = { source = liquidity_baking_cpmm_contract; payer = liquidity_baking_cpmm_contract; - self = liquidity_baking_cpmm_contract; + self = liquidity_baking_cpmm_contract_hash; amount = liquidity_baking_subsidy; balance; chain_id = Chain_id.zero; diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 48703975164b..49d2809b34e9 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -92,7 +92,7 @@ module S = Saturation_repr type step_constants = Script_typed_ir.step_constants = { source : Contract.t; payer : Contract.t; - self : Contract.t; + self : Contract_hash.t; amount : Tez.t; balance : Tez.t; chain_id : Chain_id.t; @@ -1040,7 +1040,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = match c with | Contract (Implicit _) | Tx_rollup _ | Sc_rollup _ -> (return_none [@ocaml.tailcall]) ctxt - | Contract (Originated _contract_hash as c) -> ( + | Contract (Originated contract_hash as c) -> ( Contract.get_script ctxt c >>=? fun (ctxt, script_opt) -> match script_opt with | None -> (return_none [@ocaml.tailcall]) ctxt @@ -1106,8 +1106,8 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = (step [@ocaml.tailcall]) ( ctxt, { - source = sc.self; - self = c; + source = Contract.Originated sc.self; + self = contract_hash; amount = Tez.zero; balance; (* The following remain unchanged, but let's @@ -1137,7 +1137,10 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let operation = Delegation delegate in let ctxt = update_context gas ctxt in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> - let piop = Internal_operation {source = sc.self; operation; nonce} in + let piop = + Internal_operation + {source = Contract.Originated sc.self; operation; nonce} + in let res = {piop; lazy_storage_diff = None} in let gas, ctxt = local_gas_counter_and_outdated_context ctxt in (step [@ocaml.tailcall]) (ctxt, sc) gas k ks res stack @@ -1188,12 +1191,12 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let res = {destination; entrypoint = Entrypoint.default} in (step [@ocaml.tailcall]) g gas k ks res (accu, stack) | ISelf (_, ty, entrypoint, k) -> - let destination : Destination.t = Contract sc.self in + let destination : Destination.t = Contract (Originated sc.self) in let address = {destination; entrypoint} in let res = Typed_contract {arg_ty = ty; address} in (step [@ocaml.tailcall]) g gas k ks res (accu, stack) | ISelf_address (_, k) -> - let destination : Destination.t = Contract sc.self in + let destination : Destination.t = Contract (Originated sc.self) in let res = {destination; entrypoint = Entrypoint.default} in (step [@ocaml.tailcall]) g gas k ks res (accu, stack) | IAmount (_, k) -> @@ -1249,7 +1252,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = | ISapling_verify_update (_, k) -> ( let transaction = accu in let state, stack = stack in - let address = Contract.to_b58check sc.self in + let address = Contract_hash.to_b58check sc.self in let sc_chain_id = Script_chain_id.make sc.chain_id in let chain_id = Script_chain_id.to_b58check sc_chain_id in let anti_replay = address ^ chain_id in @@ -1269,7 +1272,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = | ISapling_verify_update_deprecated (_, k) -> ( let transaction = accu in let state, stack = stack in - let address = Contract.to_b58check sc.self in + let address = Contract_hash.to_b58check sc.self in let sc_chain_id = Script_chain_id.make sc.chain_id in let chain_id = Script_chain_id.to_b58check sc_chain_id in let anti_replay = address ^ chain_id in @@ -1433,7 +1436,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = (* Tickets *) | ITicket (_, k) -> let contents = accu and amount, stack = stack in - let ticketer = sc.self in + let ticketer = Contract.Originated sc.self in let accu = {ticketer; contents; amount} in (step [@ocaml.tailcall]) g gas k ks accu stack | IRead_ticket (_, k) -> @@ -1729,11 +1732,12 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal entrypoints entrypoint) >>?= fun (r, ctxt) -> - record_trace (Bad_contract_parameter step_constants.self) r + let self_contract = Contract.Originated step_constants.self in + record_trace (Bad_contract_parameter self_contract) r >>?= fun (Ex_ty_cstr {ty = entrypoint_ty; construct; original_type_expr = _}) -> trace - (Bad_contract_parameter step_constants.self) + (Bad_contract_parameter self_contract) (lift_execution_arg ctxt ~internal entrypoint_ty construct arg) >>=? fun (arg, ctxt) -> Script_ir_translator.collect_lazy_storage ctxt arg_type arg @@ -1741,7 +1745,7 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal Script_ir_translator.collect_lazy_storage ctxt storage_type old_storage >>?= fun (to_update, ctxt) -> trace - (Runtime_contract_error step_constants.self) + (Runtime_contract_error self_contract) (interp logger (ctxt, step_constants) code (arg, old_storage)) >>=? fun ((ops, new_storage), ctxt) -> Script_ir_translator.extract_lazy_storage_diff diff --git a/src/proto_alpha/lib_protocol/script_interpreter.mli b/src/proto_alpha/lib_protocol/script_interpreter.mli index bd1ddafad9da..28e3a106e61b 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.mli +++ b/src/proto_alpha/lib_protocol/script_interpreter.mli @@ -62,7 +62,7 @@ type execution_result = { type step_constants = Script_typed_ir.step_constants = { source : Contract.t; payer : Contract.t; - self : Contract.t; + self : Contract_hash.t; amount : Tez.t; balance : Tez.t; chain_id : Chain_id.t; diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index 9aa149aef72a..e4b53ba12eed 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -625,7 +625,7 @@ let transfer (ctxt, sc) gas amount location parameters_ty parameters failwith "Transferring to smart-contract rollups is not yet supported") >>=? fun (operation, ctxt) -> fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> - let iop = {source = sc.self; operation; nonce} in + let iop = {source = Contract.Originated sc.self; operation; nonce} in let res = {piop = Internal_operation iop; lazy_storage_diff} in let gas, ctxt = local_gas_counter_and_outdated_context ctxt in return (res, ctxt, gas) @@ -664,7 +664,8 @@ let create_contract (ctxt, sc) gas storage_type code delegate credit init = Origination {origination; preorigination; storage_type; storage = init} in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> - let piop = Internal_operation {source = sc.self; operation; nonce} in + let source = Contract.Originated sc.self in + let piop = Internal_operation {source; operation; nonce} in let res = {piop; lazy_storage_diff} in let gas, ctxt = local_gas_counter_and_outdated_context ctxt in return (res, preorigination, ctxt, gas) diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 2d474f7207e7..dd097f86a232 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -43,7 +43,7 @@ type step_constants = { (** The address calling this contract, as returned by SENDER. *) payer : Contract.t; (** The address of the implicit account that initiated the chain of contract calls, as returned by SOURCE. *) - self : Contract.t; + self : Contract_hash.t; (** The address of the contract being executed, as returned by SELF and SELF_ADDRESS. Also used: - as ticketer in TICKET diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index c6cdfdd5929f..5d1bb7692169 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -32,7 +32,7 @@ open Dependent_bool type step_constants = { source : Contract.t; payer : Contract.t; - self : Contract.t; + self : Contract_hash.t; amount : Tez.t; balance : Tez.t; chain_id : Chain_id.t; diff --git a/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml index c5f774a91192..aced2a46bffc 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml @@ -67,7 +67,7 @@ let originate_contract file storage src b baker = let fake_KT1 = Contract_hash.of_b58check_exn "KT1FAKEFAKEFAKEFAKEFAKEFAKEFAKGGSE2x" -let default_self = Contract.Originated fake_KT1 +let default_self = fake_KT1 let default_source = Contract.Implicit Signature.Public_key_hash.zero diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml index d39adf2fcd75..7ff42e4752ff 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml @@ -80,7 +80,7 @@ let test_bad_contract_parameter () = | Error (Environment.Ecoproto_error (Bad_contract_parameter source') :: _) -> Alcotest.(check Testable.contract) "incorrect field in Bad_contract_parameter" - Contract_helpers.default_self + (Contract.Originated Contract_helpers.default_self) source' ; return_unit | Error errs -> diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml index 534f32f849e2..6a263f9ef124 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml @@ -586,7 +586,7 @@ let test_bad_parameter () = ~equal:( = ) (Environment.Ecoproto_error (Script_interpreter.Bad_contract_parameter - Contract_helpers.default_self)) + (Contract.Originated Contract_helpers.default_self))) lst -> return () | Error errs -> -- GitLab