diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 6054f274554cded4eb3a82584e232195756ebd24..c2d7e384b84a174c491c1cdf230e111cf66dedbd 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -360,13 +360,7 @@ let build_origination_operation ?fee ?gas_limit ?storage_limit ~initial_storage >>=? fun {Michelson_v1_parser.expanded = storage; _} -> let code = Script.lazy_expr code and storage = Script.lazy_expr storage in let origination = - Origination - { - delegate; - script = {code; storage}; - credit = balance; - preorigination = None; - } + Origination {delegate; script = {code; storage}; credit = balance} in return (Injection.prepare_manager_operation diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index 61d8654bbe3465ca311e9bbfef2204f39d12e0ab..e815e7589e524a482b1ac10eb4e73b1492780b51 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -58,8 +58,7 @@ let pp_manager_operation_content (type kind) source internal pp_result ppf expr) ; pp_result ppf result ; Format.fprintf ppf "@]" - | Origination {delegate; credit; script = {code; storage}; preorigination = _} - -> + | Origination {delegate; credit; script = {code; storage}} -> Format.fprintf ppf "@[%s:@,From: %a@,Credit: %s%a" diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index 5d5426addd998ab0b5fe7d5571343219dfd09972..1f24ac2e8b915e850509b79a6bf7b3afe2f41189 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -2537,15 +2537,16 @@ module RPC = struct >>=? fun (storage, _) -> let script = Script_ir_translator.Ex_script - { - code; - arg_type; - storage_type; - views; - entrypoints; - code_size; - storage; - } + (Script + { + code; + arg_type; + storage_type; + views; + entrypoints; + code_size; + storage; + }) in let (size, cost) = Script_ir_translator.script_size script in Gas.consume ctxt cost >>?= fun _ctxt -> return @@ size) ; @@ -3201,13 +3202,7 @@ module RPC = struct ~storage_limit [ Manager - (Origination - { - delegate = delegatePubKey; - script; - credit = balance; - preorigination = None; - }); + (Origination {delegate = delegatePubKey; script; credit = balance}); ] let delegation ctxt block ~branch ~source ?sourcePubKey ~counter ~fee diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 96cf61a3465983af6d4cc99891866e028fff9b96..65c1ca14bab9456f5f5a7dc133abaa48a17267d7 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2688,7 +2688,6 @@ type origination = { delegate : Signature.Public_key_hash.t option; script : Script.t; credit : Tez.tez; - preorigination : Contract.t option; } type 'kind operation = { diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 5cd883a31ac73832a247a953306fd24d4b8ee3a8..d03767acb89d81d83a09bee047d04d864a885a86 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -921,8 +921,8 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount ~entrypoint ~before_operation ~payer ~chain_id ~mode ~internal ~script_ir ~script ~parameter ~cache_key ~balance_updates ~allocated_destination_contract = - (* Token.transfer which is being called above already loads this - value into the Irmin cache, so no need to burn gas for it. *) + (* Token.transfer which is being called before already loads this value into + the Irmin cache, so no need to burn gas for it. *) Contract.get_balance ctxt contract >>=? fun balance -> let now = Script_timestamp.now ctxt in let level = @@ -1140,8 +1140,8 @@ let apply_transaction_to_tx_rollup ~ctxt ~parameters_ty ~parameters ~amount return (ctxt, result, []) else fail (Script_tc_errors.No_such_entrypoint entrypoint) -let apply_origination ~consume_deserialization_gas ~ctxt ~script ~internal - ~preorigination ~delegate ~source ~credit ~before_operation = +let apply_origination ~consume_deserialization_gas ~ctxt ~parsed_script ~script + ~internal ~contract ~delegate ~source ~credit ~before_operation = Script.force_decode_in_context ~consume_deserialization_gas ctxt @@ -1152,12 +1152,16 @@ let apply_origination ~consume_deserialization_gas ~ctxt ~script ~internal ctxt script.Script.code >>?= fun (unparsed_code, ctxt) -> - Script_ir_translator.parse_script - ctxt - ~legacy:false - ~allow_forged_in_storage:internal - script - >>=? fun (Ex_script parsed_script, ctxt) -> + (match parsed_script with + | None -> + Script_ir_translator.parse_script + ctxt + ~legacy:false + ~allow_forged_in_storage:internal + script + | Some parsed_script -> + return (Script_ir_translator.Ex_script parsed_script, ctxt)) + >>=? fun (Ex_script (Script parsed_script), ctxt) -> let views_result = Script_ir_translator.typecheck_views ctxt @@ -1199,15 +1203,6 @@ let apply_origination ~consume_deserialization_gas ~ctxt ~script ~internal 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 - (match preorigination with - | Some contract -> - assert internal ; - (* The preorigination field is only used to early return the address of - an originated contract in Michelson. - It cannot come from the outside. *) - ok (ctxt, contract) - | None -> Contract.fresh_contract_from_current_nonce ctxt) - >>?= fun (ctxt, contract) -> Contract.raw_originate ctxt ~prepaid_bootstrap_storage:false @@ -1335,13 +1330,19 @@ let apply_internal_manager_operation_content : ~payer ~dst_rollup:dst ~since:before_operation - | Origination {delegate; script; preorigination; credit} -> + | Origination + { + origination = {delegate; script; credit}; + preorigination = contract; + script = parsed_script; + } -> apply_origination ~consume_deserialization_gas ~ctxt + ~parsed_script:(Some parsed_script) ~script ~internal - ~preorigination + ~contract ~delegate ~source ~credit @@ -1550,13 +1551,19 @@ let apply_external_manager_operation_content : } in return (ctxt, result, [op]) - | Origination {delegate; script; preorigination; credit} -> + | Origination {delegate; script; credit} -> + (* The contract is only used to early return the address of an originated + contract in Michelson. + It cannot come from the outside. *) + Contract.fresh_contract_from_current_nonce ctxt + >>?= fun (ctxt, contract) -> apply_origination ~consume_deserialization_gas ~ctxt + ~parsed_script:None ~script ~internal - ~preorigination + ~contract ~delegate ~source ~credit diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 92c1f4a586b747d9c01375b34ef93ba5f736c6c8..623b28c9effcc9a70fbb13aea7959bc59e5aaa4f 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -81,7 +81,7 @@ let contents_of_internal_operation (type kind) let operation : kind internal_manager_operation = match operation with | Transaction {transaction; _} -> Transaction transaction - | Origination origination -> Origination origination + | Origination {origination; _} -> Origination origination | Delegation delegate -> Delegation delegate in {source; operation; nonce} @@ -926,22 +926,10 @@ module Internal_result = struct (function Manager (Origination _ as op) -> Some op | _ -> None); proj = (function - | Origination - { - credit; - delegate; - script; - preorigination = - _ - (* the hash is only used internally - when originating from smart - contracts, don't serialize it *); - _; - } -> - (credit, delegate, script)); + | Origination {credit; delegate; script} -> (credit, delegate, script)); inj = (fun (credit, delegate, script) -> - Origination {credit; delegate; script; preorigination = None}); + Origination {credit; delegate; script}); } let[@coq_axiom_with_reason "gadt"] delegation_case = diff --git a/src/proto_alpha/lib_protocol/contract_services.ml b/src/proto_alpha/lib_protocol/contract_services.ml index 042fdc86d68cc9a285106d06e81a67c69891547f..784582bc518df25da43fffe4f7f6dffbeb0f6954 100644 --- a/src/proto_alpha/lib_protocol/contract_services.ml +++ b/src/proto_alpha/lib_protocol/contract_services.ml @@ -243,7 +243,7 @@ module S = struct ~allow_forged_in_storage:true script >|= fun tzresult -> - tzresult >>? fun (Ex_script script, ctxt) -> + tzresult >>? fun (Ex_script (Script script), ctxt) -> Script_ir_translator.get_single_sapling_state ctxt script.storage_type @@ -454,7 +454,7 @@ let[@coq_axiom_with_reason "gadt"] register () = let ctxt = Gas.set_unlimited ctxt in let open Script_ir_translator in parse_script ctxt ~legacy:true ~allow_forged_in_storage:true script - >>=? fun (Ex_script script, ctxt) -> + >>=? fun (Ex_script (Script script), ctxt) -> Script_ir_translator.collect_lazy_storage ctxt script.storage_type diff --git a/src/proto_alpha/lib_protocol/main.ml b/src/proto_alpha/lib_protocol/main.ml index da097a31fc14498ecd8b2f70ffa80803ae25ef23..3301fa37610b8b2af5220b545d8528b2db6acd90 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -742,7 +742,7 @@ let init ctxt block_header = ~legacy:true ~allow_forged_in_storage script - >>=? fun (Ex_script parsed_script, ctxt) -> + >>=? fun (Ex_script (Script parsed_script), ctxt) -> Script_ir_translator.extract_lazy_storage_diff ctxt Optimized diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 24cf9a9377656c603cc355c0b9cec8bc82e26e68..6fc002bf5aa28b0915421eeae6b2bbd2d738a936 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -207,7 +207,6 @@ type origination = { delegate : Signature.Public_key_hash.t option; script : Script_repr.t; credit : Tez_repr.tez; - preorigination : Contract_repr.t option; } type 'kind operation = { @@ -547,21 +546,11 @@ module Encoding = struct (function Manager (Origination _ as op) -> Some op | _ -> None); proj = (function - | Origination - { - credit; - delegate; - script; - preorigination = - _ - (* the hash is only used internally - when originating from smart - contracts, don't serialize it *); - } -> + | Origination {credit; delegate; script} -> (credit, delegate, script)); inj = (fun (credit, delegate, script) -> - Origination {credit; delegate; script; preorigination = None}); + Origination {credit; delegate; script}); } let delegation_tag = 3 diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 19d787633d9b15c34fc44794a9e72f4c60a2dc71..6eab5947cb1a35449e12a0dfe24d8c0a91dec0a8 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -188,7 +188,6 @@ type origination = { delegate : Signature.Public_key_hash.t option; script : Script_repr.t; credit : Tez_repr.tez; - preorigination : Contract_repr.t option; } (** An [operation] contains the operation header information in [shell] diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 70fb97fca2c445301a2ffeaa2df508d0ef48408c..9fdafa8e945343b3067d489bad498f3a88ada506 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1055,8 +1055,8 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = ~allow_forged_in_storage:true ctxt script - >>=? fun (Ex_script {storage; storage_type; views; _}, ctxt) - -> + >>=? fun ( Ex_script (Script {storage; storage_type; views; _}), + ctxt ) -> Gas.consume ctxt (Interp_costs.view_get name views) >>?= fun ctxt -> match Script_map.get name views with @@ -1138,15 +1138,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = (EmptyCell, EmptyCell)))))) | Tx_rollup _ -> (return_none [@ocaml.tailcall]) ctxt) | ICreate_contract - { - storage_type; - arg_type; - lambda = Lam (_, code); - views; - entrypoints; - k; - _; - } -> + {storage_type; arg_type; lambda; views; entrypoints; k; _} -> (* Removed the instruction's arguments manager, spendable and delegatable *) let delegate = accu in let (credit, (init, stack)) = stack in @@ -1155,7 +1147,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = gas storage_type arg_type - code + lambda views entrypoints delegate @@ -1759,15 +1751,16 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal ~allow_forged_in_storage:true | Some ex_script -> return (ex_script, ctxt)) >>=? fun ( Ex_script - { - code_size; - code; - arg_type; - storage = old_storage; - storage_type; - entrypoints; - views; - }, + (Script + { + code_size; + code; + arg_type; + storage = old_storage; + storage_type; + entrypoints; + views; + }), ctxt ) -> Gas_monad.run ctxt @@ -1819,7 +1812,8 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal in let script = Ex_script - {code_size; code; arg_type; storage; storage_type; entrypoints; views} + (Script + {code_size; code; arg_type; storage; storage_type; entrypoints; views}) in Ticket_scanner.type_has_tickets ctxt arg_type >>?= fun (arg_type_has_tickets, ctxt) -> diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index 7dbabb9d1c80a13138c4f774f769f1350a34f3e0..6a19b414337926ac63cf5122cb7805c5d6af885e 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -591,7 +591,7 @@ let transfer (ctxt, sc) gas amount location parameters_ty parameters destination (* TODO: https://gitlab.com/tezos/tezos/-/issues/1688 Refactor the sharing part of unparse_script and create_contract *) -let create_contract (ctxt, sc) gas storage_type param_type code views +let create_contract (ctxt, sc) gas storage_type param_type lambda views entrypoints delegate credit init = let ctxt = update_context gas ctxt in let loc = Micheline.dummy_location in @@ -612,7 +612,8 @@ let create_contract (ctxt, sc) gas storage_type param_type code views [] ) :: views in - let views = Script_map.fold view views [] |> List.rev in + let view_list = Script_map.fold view views [] |> List.rev in + let (Lam (_, code)) = lambda in let code = strip_locations (Seq @@ -622,7 +623,7 @@ let create_contract (ctxt, sc) gas storage_type param_type code views Prim (loc, K_storage, [unparsed_storage_type], []); Prim (loc, K_code, [code], []); ] - @ views )) + @ view_list )) in collect_lazy_storage ctxt storage_type init >>?= fun (to_duplicate, ctxt) -> let to_update = no_lazy_storage_id in @@ -639,16 +640,30 @@ let create_contract (ctxt, sc) gas storage_type param_type code views Gas.consume ctxt (Script.strip_locations_cost storage) >>?= fun ctxt -> let storage = strip_locations storage in Contract.fresh_contract_from_current_nonce ctxt >>?= fun (ctxt, contract) -> - let operation = - Origination + let origination = + { + credit; + delegate; + script = + {code = Script.lazy_expr code; storage = Script.lazy_expr storage}; + } + in + Script_ir_translator.code_size ctxt lambda views >>?= fun (code_size, ctxt) -> + let script = + Script { - credit; - delegate; - preorigination = Some contract; - script = - {code = Script.lazy_expr code; storage = Script.lazy_expr storage}; + code = lambda; + arg_type = param_type; + storage = init; + storage_type; + views; + entrypoints; + code_size; } in + let operation = + Origination {origination; preorigination = contract; script} + in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> let piop = Internal_operation {source = sc.self; operation; nonce} in let res = {piop; lazy_storage_diff} in diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 5e1d452a1be8b97741a0eae1d06bb97eeef96165..dcef099c0b7f2a914614e386debcee1977e73b41 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -1801,23 +1801,7 @@ type ('arg, 'storage) code = } -> ('arg, 'storage) code -type ex_script = - | Ex_script : { - code : - (('arg, 'storage) pair, (operation boxed_list, 'storage) pair) lambda; - arg_type : ('arg, _) ty; - storage : 'storage; - storage_type : ('storage, _) ty; - views : view_map; - entrypoints : 'arg entrypoints; - code_size : Cache_memory_helpers.sint; - (* This is an over-approximation of the value size in memory, in - bytes, of the contract's static part, that is its source - code. This includes the code of the contract as well as the code - of the views. The storage size is not taken into account by this - field as it has a dynamic size. *) - } - -> ex_script +type ex_script = Ex_script : ('a, 'c) Script_typed_ir.script -> ex_script type ex_code = Ex_code : ('a, 'c) code -> ex_code @@ -5490,7 +5474,8 @@ let[@coq_axiom_with_reason "gadt"] parse_script : ~storage >|=? fun (storage, ctxt) -> ( Ex_script - {code_size; code; arg_type; storage; storage_type; views; entrypoints}, + (Script + {code_size; code; arg_type; storage; storage_type; views; entrypoints}), ctxt ) let typecheck_code : @@ -5868,7 +5853,8 @@ and[@coq_axiom_with_reason "gadt"] unparse_code ctxt ~stack_depth mode code = (* TODO: https://gitlab.com/tezos/tezos/-/issues/1688 Refactor the sharing part of unparse_script and create_contract *) let unparse_script ctxt mode - (Ex_script {code; arg_type; storage; storage_type; entrypoints; views; _}) = + (Ex_script + (Script {code; arg_type; storage; storage_type; entrypoints; views; _})) = let (Lam (_, original_code)) = code in Gas.consume ctxt Unparse_costs.unparse_script >>?= fun ctxt -> unparse_code ctxt ~stack_depth:0 mode original_code >>=? fun (code, ctxt) -> @@ -6467,15 +6453,16 @@ let[@coq_axiom_with_reason "gadt"] get_single_sapling_state ctxt ty x = *) let script_size (Ex_script - { - code_size; - code = _; - arg_type = _; - storage; - storage_type; - entrypoints = _; - views = _; - }) = + (Script + { + code_size; + code = _; + arg_type = _; + storage; + storage_type; + entrypoints = _; + views = _; + })) = let (nodes, storage_size) = Script_typed_ir_size.value_size storage_type storage in diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.mli b/src/proto_alpha/lib_protocol/script_ir_translator.mli index 975e66406b7829547d33370d5a258b927100fffe..61bc87b46faa84dbacb25ad53d5370e50df3780d 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.mli +++ b/src/proto_alpha/lib_protocol/script_ir_translator.mli @@ -82,22 +82,7 @@ type ex_parameter_ty_and_entrypoints = type ex_stack_ty = | Ex_stack_ty : ('a, 's) Script_typed_ir.stack_ty -> ex_stack_ty -type ex_script = - | Ex_script : { - code : - ( ('arg, 'storage) Script_typed_ir.pair, - ( Script_typed_ir.operation Script_typed_ir.boxed_list, - 'storage ) - Script_typed_ir.pair ) - Script_typed_ir.lambda; - arg_type : ('arg, _) Script_typed_ir.ty; - storage : 'storage; - storage_type : ('storage, _) Script_typed_ir.ty; - views : Script_typed_ir.view_map; - entrypoints : 'arg Script_typed_ir.entrypoints; - code_size : Cache_memory_helpers.sint; - } - -> ex_script +type ex_script = Ex_script : ('a, 'b) Script_typed_ir.script -> ex_script type toplevel = { code_field : Script.node; diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 8734cd25e5dc8018aedbfc1f907948ff51e37b98..ce2142c54a6ff553c733b4435de988cba5783d34 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -468,8 +468,26 @@ and 'arg nested_entrypoints = let no_entrypoints = {name = None; nested = Entrypoints_None} +type ('arg, 'storage) script = + | Script : { + code : + (('arg, 'storage) pair, (operation boxed_list, 'storage) pair) lambda; + arg_type : ('arg, _) ty; + storage : 'storage; + storage_type : ('storage, _) ty; + views : view_map; + entrypoints : 'arg entrypoints; + code_size : Cache_memory_helpers.sint; + (* This is an over-approximation of the value size in memory, in + bytes, of the contract's static part, that is its source + code. This includes the code of the contract as well as the code + of the views. The storage size is not taken into account by this + field as it has a dynamic size. *) + } + -> ('arg, 'storage) script + (* ---- Instructions --------------------------------------------------------*) -type ('before_top, 'before, 'result_top, 'result) kinstr = +and ('before_top, 'before, 'result_top, 'result) kinstr = (* Stack ----- @@ -1377,8 +1395,11 @@ and 'kind manager_operation = parameters : 'a; } -> Kind.transaction manager_operation - | Origination : - Alpha_context.origination + | Origination : { + origination : Alpha_context.origination; + preorigination : Contract.t; + script : ('arg, 'storage) script; + } -> Kind.origination manager_operation | Delegation : Signature.Public_key_hash.t option diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index 102d0a36b48e687deb238550749458f52fd16cc4..2caa8f18942dd8e79f1b03b4a42281f22a83f775 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -335,6 +335,19 @@ and 'arg nested_entrypoints = (** [no_entrypoints] is [{name = None; nested = Entrypoints_None}] *) val no_entrypoints : _ entrypoints +type ('arg, 'storage) script = + | Script : { + code : + (('arg, 'storage) pair, (operation boxed_list, 'storage) pair) lambda; + arg_type : ('arg, _) ty; + storage : 'storage; + storage_type : ('storage, _) ty; + views : view_map; + entrypoints : 'arg entrypoints; + code_size : Cache_memory_helpers.sint; + } + -> ('arg, 'storage) script + (* ---- Instructions --------------------------------------------------------*) (* @@ -436,7 +449,7 @@ val no_entrypoints : _ entrypoints [1]: http://www.complang.tuwien.ac.at/projects/interpreters.html *) -type ('before_top, 'before, 'result_top, 'result) kinstr = +and ('before_top, 'before, 'result_top, 'result) kinstr = (* Stack ----- @@ -1520,8 +1533,11 @@ and 'kind manager_operation = parameters : 'a; } -> Kind.transaction manager_operation - | Origination : - Alpha_context.origination + | Origination : { + origination : Alpha_context.origination; + preorigination : Contract.t; + script : ('arg, 'storage) script; + } -> Kind.origination manager_operation | Delegation : Signature.Public_key_hash.t option diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index d6452b8edf008289b4d47b4689a70f34b866dc92..9cdf37f75e0b6123eaf3fde1a24f237a43335157 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -324,7 +324,7 @@ let initial_alpha_context ?(commitments = []) constants ~legacy:true ~allow_forged_in_storage script - >>=? fun (Ex_script parsed_script, ctxt) -> + >>=? fun (Ex_script (Script parsed_script), ctxt) -> Script_ir_translator.extract_lazy_storage_diff ctxt Optimized diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index 8dcfec4200e8efdbe01de16554df0cc81ee23c15..b7971edb3c4847f3feec64f37093a51f643b18d7 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -310,15 +310,15 @@ let originated_contract op = exception Impossible -let contract_origination ?counter ?delegate ~script ?(preorigination = None) - ?public_key ?credit ?fee ?gas_limit ?storage_limit ctxt source = +let contract_origination ?counter ?delegate ~script ?public_key ?credit ?fee + ?gas_limit ?storage_limit ctxt source = Context.Contract.manager ctxt source >>=? fun account -> let default_credit = Tez.of_mutez @@ Int64.of_int 1000001 in let default_credit = WithExceptions.Option.to_exn ~none:Impossible default_credit in let credit = Option.value ~default:default_credit credit in - let operation = Origination {delegate; script; credit; preorigination} in + let operation = Origination {delegate; script; credit} in manager_operation ?counter ?public_key diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index 267f8579970d64e4cc8b3454c9eb17a43c33ee3b..f5ce0225825817c32bb529d2cc2a961f9993f6c6 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/op.mli @@ -119,7 +119,6 @@ val contract_origination : ?counter:Z.t -> ?delegate:public_key_hash -> script:Script.t -> - ?preorigination:Contract.contract option -> ?public_key:public_key -> ?credit:Tez.tez -> ?fee:Tez.tez -> diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml index 4e9918de5dbb1e9db4201588c37e33f431446adb..53da0dca16e01e19db653dfc11a4118e29fc79e9 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml @@ -951,7 +951,7 @@ module Interpreter_tests = struct ~allow_forged_in_storage:true script >>= wrap - >>=? fun (Ex_script script, ctxt) -> + >>=? fun (Ex_script (Script script), ctxt) -> Script_ir_translator.get_single_sapling_state ctxt script.storage_type diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml index cd0edb8952f0698bbc579165d9408bc9192a4b13..9b4125d93baa10e776da40e7082dc289203b7d4b 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml @@ -206,17 +206,17 @@ let test_update_modifies_cached_contract () = originate_contract "contracts/int-store.tz" "36" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> - find ctxt addr >>=? fun (ctxt, identifier, script, Ex_script ir) -> + find ctxt addr >>=? fun (ctxt, identifier, script, Ex_script (Script ir)) -> match ir.storage_type with | Int_t -> let storage' = Script_int.(add ir.storage (Script_int.of_int 1)) in let cached_contract' = - (script, Ex_script {ir with storage = storage'}) + (script, Ex_script (Script {ir with storage = storage'})) in Script_cache.update ctxt identifier cached_contract' 1 |> Environment.wrap_tzresult >>?= fun ctxt -> - find ctxt addr >>=? fun (_, _, _, Ex_script ir') -> + find ctxt addr >>=? fun (_, _, _, Ex_script (Script ir')) -> let storage = value_as_int ir'.storage_type ir'.storage in fail_unless (Script_int.compare storage storage' = 0) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml index 507558a491809d9c71282b0b5dcfffea8331dcd2..dd0c4884842c604cd1f22cd3801224e0a1c18976 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml @@ -330,20 +330,31 @@ let originate_script block ~script ~storage ~src ~baker ~forges_tickets = in Incremental.finalize_block incr >|=? fun block -> (destination, script, block) -let origination_operation ~src ~script ~orig_contract = - Internal_operation - { - source = src; - operation = - Origination - { - delegate = None; - script; - credit = Tez.one; - preorigination = Some orig_contract; - }; - nonce = 1; - } +let origination_operation ctxt ~src ~script ~orig_contract = + let open Lwt_tzresult_syntax in + let* (Script_ir_translator.Ex_script parsed_script, ctxt) = + wrap + @@ Script_ir_translator.parse_script + ctxt + ~legacy:true + ~allow_forged_in_storage:true + script + in + let operation = + Internal_operation + { + source = src; + operation = + Origination + { + origination = {delegate = None; script; credit = Tez.one}; + preorigination = orig_contract; + script = parsed_script; + }; + nonce = 1; + } + in + return (operation, ctxt) let originate block ~src ~baker ~script ~storage ~forges_tickets = let open Lwt_tzresult_syntax in @@ -1140,8 +1151,8 @@ let test_update_invalid_origination () = ~forges_tickets:true in let ctxt = Incremental.alpha_ctxt incr in - let operation = - origination_operation ~src ~orig_contract:destination ~script + let* (operation, ctxt) = + origination_operation ctxt ~src ~orig_contract:destination ~script in assert_fail_with ~loc:__LOC__ @@ -1184,8 +1195,8 @@ let test_update_valid_origination () = let* (_, ctxt) = wrap @@ Ticket_balance.adjust_balance ctxt red_self_token_hash ~delta:Z.one in - let operation = - origination_operation ~src:self ~orig_contract:originated ~script + let* (operation, ctxt) = + origination_operation ctxt ~src:self ~orig_contract:originated ~script in let* (_, ctxt) = let* (ticket_diffs, ctxt) = @@ -1236,8 +1247,8 @@ let test_update_self_origination () = ~owner:(Destination.Contract originated) red_token in - let operation = - origination_operation ~src:self ~orig_contract:originated ~script + let* (operation, ctxt) = + origination_operation ctxt ~src:self ~orig_contract:originated ~script in let* (_, ctxt) = wrap diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml index 5a79954135086a67ea4821c27e2714a4f933b95a..252e84bb0df6c05b475c6b16e75170a234aca7a6 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml @@ -84,7 +84,8 @@ let ticket_balance_of_storage ctxt contract = match script with | None -> return ([], ctxt) | Some script -> - let* (Script_ir_translator.Ex_script {storage; storage_type; _}, ctxt) = + let* ( Script_ir_translator.Ex_script (Script {storage; storage_type; _}), + ctxt ) = wrap (Script_ir_translator.parse_script ctxt diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml index 36db4c333d5cfd5878de019d70e4283bf7340392..ccab86761563d9e0ef5cdacb0c4fe2bc219cf804 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml @@ -231,6 +231,15 @@ let origination_operation block ~src ~baker ~script ~storage ~forges_tickets = let* incr = Incremental.begin_construction ~policy:Block.(By_account baker) block in + let ctxt = Incremental.alpha_ctxt incr in + let* (Script_ir_translator.Ex_script parsed_script, ctxt) = + wrap + @@ Script_ir_translator.parse_script + ctxt + ~legacy:true + ~allow_forged_in_storage:true + script + in let operation = Script_typed_ir.Internal_operation { @@ -238,14 +247,14 @@ let origination_operation block ~src ~baker ~script ~storage ~forges_tickets = operation = Origination { - delegate = None; - script; - credit = Tez.one; - preorigination = Some orig_contract; + origination = {delegate = None; script; credit = Tez.one}; + preorigination = orig_contract; + script = parsed_script; }; nonce = 1; } in + let incr = Incremental.set_alpha_ctxt incr ctxt in return (orig_contract, operation, incr) let delegation_operation ~src = diff --git a/src/proto_alpha/lib_protocol/ticket_balance_migration_for_j.ml b/src/proto_alpha/lib_protocol/ticket_balance_migration_for_j.ml index 096d4efe96aa66a6f0468bf614eff2b1ac09f31b..e595f431b2fc7513fa61bbd272a5d2be5009b6a9 100644 --- a/src/proto_alpha/lib_protocol/ticket_balance_migration_for_j.ml +++ b/src/proto_alpha/lib_protocol/ticket_balance_migration_for_j.ml @@ -48,7 +48,7 @@ let update_contract_tickets ctxt contract = ~allow_forged_in_storage:true script >>=? fun (ex_script, ctxt) -> - let (Ex_script {storage_type; storage; _}) = ex_script in + let (Ex_script (Script {storage_type; storage; _})) = ex_script in Ticket_scanner.type_has_tickets ctxt storage_type >>?= fun (has_tickets, ctxt) -> Ticket_scanner.tickets_of_value diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index ef51b6aec250d3838951e80e0132af4031060f5e..8109390b6e30107c1c74f31fce96bc6c103aa7b2 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -187,8 +187,9 @@ let tickets_of_transaction ctxt ~destination ~entrypoint ~location match script_opt with | None -> fail (Failed_to_get_script destination) | Some script -> return (script, ctxt)) - >>=? fun (Script_ir_translator.Ex_script {arg_type; entrypoints; _}, ctxt) - -> + >>=? fun ( Script_ir_translator.Ex_script + (Script {arg_type; entrypoints; _}), + ctxt ) -> (* Find the entrypoint type for the given entrypoint. *) Gas_monad.run ctxt @@ -219,43 +220,24 @@ let tickets_of_transaction ctxt ~destination ~entrypoint ~location return (Some {destination = Contract destination; tickets}, ctxt) (** Extract tickets of an origination operation by scanning the storage. *) -let tickets_of_origination ctxt ~preorigination script = - match preorigination with - | None -> fail Contract_not_originated - | Some contract -> - (* TODO: #2351 - Avoid having to parse the script here. - We're not able to rely on caching due to issues with lazy storage. - After internal operations are in place we should be able to use the - typed script directly. - *) - Script_ir_translator.parse_script - ctxt - ~legacy:true - ~allow_forged_in_storage:true - script - >>=? fun ( Script_ir_translator.Ex_script - { - storage; - storage_type; - code = _; - arg_type = _; - views = _; - entrypoints = _; - code_size = _; - }, - ctxt ) -> - (* Extract any tickets from the storage. Note that if the type of the - contract storage does not contain tickets, storage is not scanned. *) - Ticket_scanner.type_has_tickets ctxt storage_type - >>?= fun (has_tickets, ctxt) -> - Ticket_scanner.tickets_of_value - ctxt - ~include_lazy:true - has_tickets - storage - >|=? fun (tickets, ctxt) -> - (Some {tickets; destination = Destination.Contract contract}, ctxt) +let tickets_of_origination ctxt ~preorigination + (Script_typed_ir.Script + { + storage_type; + storage; + code = _; + arg_type = _; + views = _; + entrypoints = _; + code_size = _; + }) = + (* Extract any tickets from the storage. Note that if the type of the contract + storage does not contain tickets, storage is not scanned. *) + Ticket_scanner.type_has_tickets ctxt storage_type + >>?= fun (has_tickets, ctxt) -> + Ticket_scanner.tickets_of_value ctxt ~include_lazy:true has_tickets storage + >|=? fun (tickets, ctxt) -> + (Some {tickets; destination = Destination.Contract preorigination}, ctxt) let tickets_of_operation ctxt (Script_typed_ir.Internal_operation {source = _; operation; nonce = _}) = @@ -304,7 +286,12 @@ let tickets_of_operation ctxt }, ctxt ) else return (None, ctxt) - | Origination {delegate = _; script; credit = _; preorigination} -> + | Origination + { + origination = {delegate = _; script = _; credit = _}; + preorigination; + script; + } -> tickets_of_origination ctxt ~preorigination script | Delegation _ -> return (None, ctxt) diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestOriginateContractFromContract::test_originate_contract_from_contract_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestOriginateContractFromContract::test_originate_contract_from_contract_transfer.out index c3db7f879e3bb3b5e1ed3fbc200445833a81a618..42bff6c96faa27bd6ceebff0ec561301aa19e202 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestOriginateContractFromContract::test_originate_contract_from_contract_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestOriginateContractFromContract::test_originate_contract_from_contract_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestOriginateContractFromContract::test_originate_contract_from_contract_transfer Node is bootstrapped. -Estimated gas: 3477.065 units (will add 100 for safety) +Estimated gas: 3470.319 units (will add 100 for safety) Estimated storage: 295 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -14,7 +14,7 @@ This sequence of operations was run: From: [CONTRACT_HASH] Fee to the baker: ꜩ0.000607 Expected counter: [EXPECTED_COUNTER] - Gas limit: 3578 + Gas limit: 3571 Storage limit: 315 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.000607 @@ -26,7 +26,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 93 bytes - Consumed gas: 2069.085 + Consumed gas: 2066.252 Internal operations: Origination: From: [CONTRACT_HASH] @@ -40,7 +40,7 @@ This sequence of operations was run: [CONTRACT_HASH] Storage size: 38 bytes Paid storage size diff: 38 bytes - Consumed gas: 1407.980 + Consumed gas: 1404.067 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0095 storage fees ........................... +ꜩ0.0095 diff --git "a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[create_contract.tz-None-Unit-(Some \"KT1Mjjcb6tmSsLm7Cb3.c3984fbc14.out" "b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[create_contract.tz-None-Unit-(Some \"KT1Mjjcb6tmSsLm7Cb3.c3984fbc14.out" index 4b98d5ac09ecaff8db1244cb7e9f5a67e11b7127..edceebcd11243b01a973aa36c83e0fcd56b62e73 100644 --- "a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[create_contract.tz-None-Unit-(Some \"KT1Mjjcb6tmSsLm7Cb3.c3984fbc14.out" +++ "b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[create_contract.tz-None-Unit-(Some \"KT1Mjjcb6tmSsLm7Cb3.c3984fbc14.out" @@ -26,24 +26,24 @@ emitted operations [ None 50000 Unit ] - - location: 13 (remaining gas: 1039983.548 units remaining) + - location: 13 (remaining gas: 1039982.468 units remaining) [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000002d08603000000001c02000000170500036c0501036c050202000000080317053d036d034200000002030b "KT1Mjjcb6tmSsLm7Cb3DSQszePjfchPM4Uxm" ] - - location: 25 (remaining gas: 1039983.533 units remaining) + - location: 25 (remaining gas: 1039982.453 units remaining) [ "KT1Mjjcb6tmSsLm7Cb3DSQszePjfchPM4Uxm" ] - - location: 27 (remaining gas: 1039983.518 units remaining) + - location: 27 (remaining gas: 1039982.438 units remaining) [ (Some "KT1Mjjcb6tmSsLm7Cb3DSQszePjfchPM4Uxm") ] - - location: 28 (remaining gas: 1039983.503 units remaining) + - location: 28 (remaining gas: 1039982.423 units remaining) [ {} (Some "KT1Mjjcb6tmSsLm7Cb3DSQszePjfchPM4Uxm") ] - - location: 25 (remaining gas: 1039983.473 units remaining) + - location: 25 (remaining gas: 1039982.393 units remaining) [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000002d08603000000001c02000000170500036c0501036c050202000000080317053d036d034200000002030b {} (Some "KT1Mjjcb6tmSsLm7Cb3DSQszePjfchPM4Uxm") ] - - location: 30 (remaining gas: 1039983.458 units remaining) + - location: 30 (remaining gas: 1039982.378 units remaining) [ { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000002d08603000000001c02000000170500036c0501036c050202000000080317053d036d034200000002030b } (Some "KT1Mjjcb6tmSsLm7Cb3DSQszePjfchPM4Uxm") ] - - location: 31 (remaining gas: 1039983.443 units remaining) + - location: 31 (remaining gas: 1039982.363 units remaining) [ (Pair { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000002d08603000000001c02000000170500036c0501036c050202000000080317053d036d034200000002030b } (Some "KT1Mjjcb6tmSsLm7Cb3DSQszePjfchPM4Uxm")) ]