diff --git a/src/proto_alpha/bin_tx_rollup_node/daemon.ml b/src/proto_alpha/bin_tx_rollup_node/daemon.ml index ec216e0ec5d01a465e5b7a975d541e2c9f062bf1..6e2e541906623824af15d2347d8bebfc1539c4ab 100644 --- a/src/proto_alpha/bin_tx_rollup_node/daemon.ml +++ b/src/proto_alpha/bin_tx_rollup_node/daemon.ml @@ -133,7 +133,7 @@ let extract_messages_from_block block_info rollup_id = source:public_key_hash -> kind manager_operation -> kind manager_operation_result -> - packed_internal_operation_result list -> + packed_internal_manager_operation_result list -> Tx_rollup_message.t list * int -> Tx_rollup_message.t list * int = fun ~source op result internal_operation_results (messages, cumulated_size) -> @@ -171,7 +171,8 @@ let extract_messages_from_block block_info rollup_id = in (* Add messages from internal operations *) List.fold_left - (fun acc (Internal_operation_result ({operation; _}, result)) -> + (fun acc (Internal_manager_operation_result ({operation; _}, result)) -> + let operation = manager_operation_of_internal_operation operation in get_messages ~source operation result [] acc) acc internal_operation_results diff --git a/src/proto_alpha/lib_client/client_proto_programs.ml b/src/proto_alpha/lib_client/client_proto_programs.ml index 518aa3c40677356220ef265c9306bbb784ce6a63..b483f29fe2201341c1c9232e0eea6cbb74b4641a 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.ml +++ b/src/proto_alpha/lib_client/client_proto_programs.ml @@ -86,7 +86,7 @@ let print_run_result (cctxt : #Client_context.printer) ~show_source ~parsed = %a@]@]@." print_expr storage - (Format.pp_print_list Operation_result.pp_internal_operation) + (Format.pp_print_list Operation_result.pp_internal_operation_result) operations (fun ppf -> function | None -> () @@ -109,7 +109,7 @@ let print_trace_result (cctxt : #Client_context.printer) ~show_source ~parsed = %a@]@]@." print_expr storage - (Format.pp_print_list Operation_result.pp_internal_operation) + (Format.pp_print_list Operation_result.pp_internal_operation_result) operations (fun ppf -> function | None -> () diff --git a/src/proto_alpha/lib_client/client_proto_programs.mli b/src/proto_alpha/lib_client/client_proto_programs.mli index a2e74ec6208055f6d9712a24fe01f68b23432bdc..f8d8e2ac720094e63a946471738d5a2800ee34db 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.mli +++ b/src/proto_alpha/lib_client/client_proto_programs.mli @@ -73,7 +73,9 @@ val run : chain:Shell_services.chain -> block:Shell_services.block -> run_params -> - (Script.expr * packed_internal_operation list * Lazy_storage.diffs option) + (Script.expr + * Apply_results.packed_internal_contents list + * Lazy_storage.diffs option) tzresult Lwt.t @@ -83,7 +85,7 @@ val trace : block:Shell_services.block -> run_params -> (Script.expr - * packed_internal_operation list + * Apply_results.packed_internal_contents list * Script_typed_ir.execution_trace * Lazy_storage.diffs option) tzresult @@ -99,7 +101,7 @@ val print_run_result : show_source:bool -> parsed:Michelson_v1_parser.parsed -> (Script_repr.expr - * packed_internal_operation list + * Apply_results.packed_internal_contents list * Lazy_storage.diffs option) tzresult -> unit tzresult Lwt.t @@ -109,7 +111,7 @@ val print_trace_result : show_source:bool -> parsed:Michelson_v1_parser.parsed -> (Script_repr.expr - * packed_internal_operation list + * Apply_results.packed_internal_contents list * Script_typed_ir.execution_trace * Lazy_storage.diffs option) tzresult -> diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 3dc1a15926c31c755863749111606fb021a6ae13..69ab31da28eb85dc05502766bcd62c50e5d19efa 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -349,7 +349,7 @@ let estimated_gas_single (type kind) in consumed_gas operation_result >>? fun gas -> List.fold_left_e - (fun acc (Internal_operation_result (_, r)) -> + (fun acc (Internal_manager_operation_result (_, r)) -> consumed_gas r >>? fun gas -> Ok (Gas.Arith.add acc gas)) gas internal_operation_results @@ -402,7 +402,7 @@ let estimated_storage_single (type kind) ~tx_rollup_origination_size in storage_size_diff operation_result >>? fun storage -> List.fold_left_e - (fun acc (Internal_operation_result (_, r)) -> + (fun acc (Internal_manager_operation_result (_, r)) -> storage_size_diff r >>? fun storage -> Ok (Z.add acc storage)) storage internal_operation_results @@ -462,7 +462,7 @@ let originated_contracts_single (type kind) originated_contracts operation_result >>? fun contracts -> let contracts = List.rev contracts in List.fold_left_e - (fun acc (Internal_operation_result (_, r)) -> + (fun acc (Internal_manager_operation_result (_, r)) -> originated_contracts r >>? fun contracts -> Ok (List.rev_append contracts acc)) contracts @@ -508,7 +508,8 @@ let detect_script_failure : type kind. kind operation_metadata -> _ = in detect_script_failure operation_result >>? fun () -> List.iter_e - (fun (Internal_operation_result (_, r)) -> detect_script_failure r) + (fun (Internal_manager_operation_result (_, r)) -> + detect_script_failure r) internal_operation_results in function diff --git a/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml b/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml index 4a339b9c935fe13ea38bc906645274f0ea934799..9510cf87059b4fbc19390cd75d98bddb5df3a545 100644 --- a/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml +++ b/src/proto_alpha/lib_client/michelson_v1_error_reporter.ml @@ -403,7 +403,7 @@ let report_errors ~details ~show_source ?parsed ppf errs = Format.fprintf ppf "@[Internal operation replay attempt:@,%a@]" - Operation_result.pp_internal_operation + Operation_result.pp_internal_operation_result op ; if rest <> [] then Format.fprintf ppf "@," ; print_trace locations rest diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index d449b7169a065d57c9e9f84cbd20457df1766c22..b0e7580f858fec2460c5430e79ba0ada937e5370 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -790,13 +790,17 @@ let pp_manager_operation_contents_and_result ppf Format.fprintf ppf "@,@[Internal operations:@ %a@]" - (Format.pp_print_list (fun ppf (Internal_operation_result (op, res)) -> + (Format.pp_print_list + (fun ppf (Internal_manager_operation_result (op, res)) -> + let operation = + manager_operation_of_internal_operation op.operation + in pp_manager_operation_content op.source false pp_result ppf - (op.operation, res))) + (operation, res))) internal_operation_results) ; Format.fprintf ppf "@]" @@ -958,11 +962,15 @@ let pp_operation_result ppf pp_contents_and_result_list ppf contents_and_result_list ; Format.fprintf ppf "@]@." -let pp_internal_operation ppf - (Internal_operation {source; operation; nonce = _}) = +let pp_internal_operation_result ppf (Apply_results.Internal_contents op) = + let operation = manager_operation_of_internal_operation op.operation in pp_manager_operation_content - source + op.source true (fun _ppf () -> ()) ppf (operation, ()) + +let pp_internal_operation ppf (Internal_operation op) = + let op = contents_of_internal_operation op in + pp_internal_operation_result ppf (Internal_contents op) diff --git a/src/proto_alpha/lib_client/operation_result.mli b/src/proto_alpha/lib_client/operation_result.mli index cc03abfcd36b557649a201ff65bf21831488fbd0..38c62136d8938e66153fa9ad64d95b85b8f678f2 100644 --- a/src/proto_alpha/lib_client/operation_result.mli +++ b/src/proto_alpha/lib_client/operation_result.mli @@ -29,6 +29,9 @@ open Alpha_context val pp_internal_operation : Format.formatter -> packed_internal_operation -> unit +val pp_internal_operation_result : + Format.formatter -> Apply_results.packed_internal_contents -> unit + val pp_operation_result : Format.formatter -> 'kind contents_list * 'kind Apply_results.contents_result_list -> diff --git a/src/proto_alpha/lib_client/protocol_client_context.ml b/src/proto_alpha/lib_client/protocol_client_context.ml index 511a6d937f85cea6e851a86d246c98262adefdf6..886d256b9c0b4369ea34a4d68bff7f789224b580 100644 --- a/src/proto_alpha/lib_client/protocol_client_context.ml +++ b/src/proto_alpha/lib_client/protocol_client_context.ml @@ -206,7 +206,7 @@ let () = @@ def "operation" ["internal"] - Protocol.Alpha_context.Operation.internal_operation_encoding ; + Protocol.Apply_results.internal_contents_encoding ; register @@ def "operation" diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index 575751da8dee25090864d46594a2bbb6df8a5ad7..db7cf947a4cc614944ae5fbb8c28add4b5e3af38 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1619,7 +1619,7 @@ module RPC = struct (storage, operations, lazy_storage_diff)) (obj3 (req "storage" Script.expr_encoding) - (req "operations" (list Operation.internal_operation_encoding)) + (req "operations" (list Apply_results.internal_contents_encoding)) (opt "lazy_storage_diff" Lazy_storage.encoding)) let trace_code_input_encoding = run_code_input_encoding @@ -1639,7 +1639,7 @@ module RPC = struct (storage, operations, trace, lazy_storage_diff)) (obj4 (req "storage" Script.expr_encoding) - (req "operations" (list Operation.internal_operation_encoding)) + (req "operations" (list Apply_results.internal_contents_encoding)) (req "trace" trace_encoding) (opt "lazy_storage_diff" Lazy_storage.encoding)) @@ -2229,7 +2229,7 @@ module RPC = struct entrypoints entrypoint >>? fun (r, ctxt) -> - r >>? fun (_f, Ex_ty ty) -> + r >>? fun (Ex_ty_cstr (ty, _)) -> unparse_ty ~loc:() ctxt ty >|? fun (ty_node, _) -> Micheline.strip_locations ty_node ) in @@ -2298,7 +2298,10 @@ module RPC = struct lazy_storage_diff; ticket_diffs = _; }, - _ ) -> (storage, operations, lazy_storage_diff)) ; + _ ) -> + ( storage, + Apply_results.contents_of_packed_internal_operations operations, + lazy_storage_diff )) ; Registration.register0 ~chunked:true S.trace_code @@ -2365,7 +2368,11 @@ module RPC = struct lazy_storage_diff; ticket_diffs = _; }, - trace ) -> (storage, operations, trace, lazy_storage_diff)) ; + trace ) -> + ( storage, + Apply_results.contents_of_packed_internal_operations operations, + trace, + lazy_storage_diff )) ; Registration.register0 ~chunked:true S.run_view diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index c796e1aca48e7e522b270e829781f0e07a0a84a5..a81068387341627996b19433700ccf70c88ca9d2 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -139,6 +139,7 @@ "Michelson_v1_gas", "Script_list", "Script_tc_context", + "Apply_results", "Script_ir_translator", "Script_cache", "Script_tc_errors_registration", @@ -161,7 +162,6 @@ "Baking", "Amendment", - "Apply_results", "Apply", "Services_registration", diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 525b248cb1cbf22218702e237ad70023765c94e4..39eb316d442533b6f0ab6bbef87e028cf5490c98 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2547,6 +2547,20 @@ val consensus_content_encoding : consensus_content Data_encoding.t val pp_consensus_content : Format.formatter -> consensus_content -> unit +type transaction = { + amount : Tez.tez; + parameters : Script.lazy_expr; + entrypoint : Entrypoint.t; + destination : Destination.t; +} + +type origination = { + delegate : Signature.Public_key_hash.t option; + script : Script.t; + credit : Tez.tez; + preorigination : Contract.t option; +} + type 'kind operation = { shell : Operation.shell_header; protocol_data : 'kind protocol_data; @@ -2617,20 +2631,8 @@ and _ contents = and _ manager_operation = | Reveal : Signature.Public_key.t -> Kind.reveal manager_operation - | Transaction : { - amount : Tez.tez; - parameters : Script.lazy_expr; - entrypoint : Entrypoint.t; - destination : Destination.t; - } - -> Kind.transaction manager_operation - | Origination : { - delegate : Signature.Public_key_hash.t option; - script : Script.t; - credit : Tez.tez; - preorigination : Contract.t option; - } - -> Kind.origination manager_operation + | Transaction : transaction -> Kind.transaction manager_operation + | Origination : origination -> Kind.origination manager_operation | Delegation : Signature.Public_key_hash.t option -> Kind.delegation manager_operation @@ -2775,9 +2777,6 @@ module Operation : sig val internal_operation_encoding : packed_internal_operation Data_encoding.t - val packed_internal_operation_in_memory_size : - packed_internal_operation -> Cache_memory_helpers.nodes_and_size - val pack : 'kind operation -> packed_operation type ('a, 'b) eq = Eq : ('a, 'a) eq @@ -2870,10 +2869,16 @@ module Operation : sig val reveal_case : Kind.reveal case + val transaction_tag : int + val transaction_case : Kind.transaction case + val origination_tag : int + val origination_case : Kind.origination case + val delegation_tag : int + val delegation_case : Kind.delegation case val register_global_constant_case : Kind.register_global_constant case diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 90cfe7d2e6dc2f205b27089735f019f6446c62f3..7d1910d650a9789edf0cf4870fb98a141e3387e6 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -576,7 +576,9 @@ type error += | (* `Temporary *) Wrong_voting_period of {expected : int32; provided : int32} type error += - | (* `Permanent *) Internal_operation_replay of packed_internal_operation + | (* `Permanent *) + Internal_operation_replay of + Apply_results.packed_internal_contents type denunciation_kind = Preendorsement | Endorsement | Block @@ -658,12 +660,12 @@ let () = ~id:"internal_operation_replay" ~title:"Internal operation replay" ~description:"An internal operation was emitted twice by a script" - ~pp:(fun ppf (Internal_operation {nonce; _}) -> + ~pp:(fun ppf (Apply_results.Internal_contents {nonce; _}) -> Format.fprintf ppf "Internal operation %d was emitted twice by a script" nonce) - Operation.internal_operation_encoding + Apply_results.internal_contents_encoding (function Internal_operation_replay op -> Some op | _ -> None) (fun op -> Internal_operation_replay op) ; register_error_kind @@ -870,6 +872,290 @@ let update_script_storage_and_ticket_balances ctxt ~self storage >>=? fun ctxt -> Ticket_accounting.update_ticket_balances ctxt ~self ~ticket_diffs operations +let apply_delegation ~ctxt ~source ~delegate ~since = + Delegate.set ctxt source delegate >|=? fun ctxt -> + (ctxt, Delegation_result {consumed_gas = Gas.consumed ~since ~until:ctxt}, []) + +let apply_transaction_to_implicit ~ctxt ~contract ~parameter ~entrypoint + ~before_operation ~balance_updates ~allocated_destination_contract = + ( (if Entrypoint.is_default entrypoint then Result.return_unit + else error (Script_tc_errors.No_such_entrypoint entrypoint)) + >>? fun () -> + match Micheline.root parameter with + | Prim (_, Michelson_v1_primitives.D_Unit, [], _) -> + (* Allow [Unit] parameter to non-scripted contracts. *) + ok ctxt + | _ -> error (Script_interpreter.Bad_contract_parameter contract) ) + >|? fun ctxt -> + let result = + Transaction_result + (Transaction_to_contract_result + { + storage = None; + lazy_storage_diff = None; + balance_updates; + originated_contracts = []; + consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; + storage_size = Z.zero; + paid_storage_size_diff = Z.zero; + allocated_destination_contract; + }) + in + (ctxt, result) + +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. *) + Contract.get_balance ctxt contract >>=? fun balance -> + let now = Script_timestamp.now ctxt in + let level = + (Level.current ctxt).level |> Raw_level.to_int32 |> Script_int.of_int32 + |> Script_int.abs + in + let step_constants = + let open Script_interpreter in + { + source; + payer = Contract.implicit_contract payer; + self = contract; + amount; + chain_id; + balance; + now; + level; + } + in + Script_interpreter.execute + ctxt + ~cached_script:(Some script_ir) + mode + step_constants + ~script + ~parameter + ~entrypoint + ~internal + >>=? fun ( {ctxt; storage; lazy_storage_diff; operations; ticket_diffs}, + (updated_cached_script, updated_size) ) -> + update_script_storage_and_ticket_balances + ctxt + ~self:contract + storage + lazy_storage_diff + ticket_diffs + operations + >>=? fun (ticket_table_size_diff, ctxt) -> + Fees.record_paid_storage_space ctxt contract ~ticket_table_size_diff + >>=? fun (ctxt, new_size, paid_storage_size_diff) -> + Contract.originated_from_current_nonce ~since:before_operation ~until:ctxt + >>=? fun originated_contracts -> + Lwt.return + ( Script_cache.update + ctxt + cache_key + ({script with storage = Script.lazy_expr storage}, updated_cached_script) + updated_size + >|? fun ctxt -> + let result = + Transaction_result + (Transaction_to_contract_result + { + storage = Some storage; + lazy_storage_diff; + balance_updates; + originated_contracts; + consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; + storage_size = new_size; + paid_storage_size_diff; + allocated_destination_contract; + }) + in + (ctxt, result, operations) ) + +let apply_transaction ~consume_deserialization_gas ~ctxt ~parameters ~source + ~contract ~amount ~entrypoint ~before_operation ~payer ~chain_id ~mode + ~internal = + Script.force_decode_in_context ~consume_deserialization_gas ctxt parameters + >>?= fun (parameter, ctxt) -> + (match Contract.is_implicit contract with + | None -> + (if Tez.(amount = zero) then + (* Detect potential call to non existent contract. *) + Contract.must_exist ctxt contract + else return_unit) + >>=? fun () -> + (* Since the contract is originated, nothing will be allocated + or the next transfer of tokens will fail. *) + return_false + | Some _ -> + (* Transfers of zero to implicit accounts are forbidden. *) + error_when Tez.(amount = zero) (Empty_transaction contract) >>?= fun () -> + (* If the implicit contract is not yet allocated at this point then + the next transfer of tokens will allocate it. *) + Contract.allocated ctxt contract >|=? not) + >>=? fun allocated_destination_contract -> + Token.transfer ctxt (`Contract source) (`Contract contract) amount + >>=? fun (ctxt, balance_updates) -> + Script_cache.find ctxt contract >>=? fun (ctxt, cache_key, script) -> + match script with + | None -> + apply_transaction_to_implicit + ~ctxt + ~contract + ~parameter + ~entrypoint + ~before_operation + ~balance_updates + ~allocated_destination_contract + >>?= fun (ctxt, result) -> return (ctxt, result, []) + | Some (script, script_ir) -> + 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 + +let apply_transaction_to_rollup ~consume_deserialization_gas ~ctxt ~parameters + ~amount ~entrypoint ~payer ~dst_rollup ~since = + assert_tx_rollup_feature_enabled ctxt >>=? fun () -> + fail_unless Tez.(amount = zero) Tx_rollup_invalid_transaction_amount + >>=? fun () -> + if Entrypoint.(entrypoint = Tx_rollup.deposit_entrypoint) then + Script.force_decode_in_context ~consume_deserialization_gas ctxt parameters + >>?= fun (parameters, ctxt) -> + Script_ir_translator.parse_tx_rollup_deposit_parameters ctxt parameters + >>?= fun (Tx_rollup.{ticketer; contents; ty; amount; destination}, ctxt) -> + Tx_rollup.hash_ticket ctxt dst_rollup ~contents ~ticketer ~ty + >>?= fun (ticket_hash, ctxt) -> + (* The deposit is returned to the [payer] as a withdrawal if it fails due to + a Balance_overflow in the recipient. The recipient of withdrawals are + always implicit. We set the withdrawal recipient to [payer]. *) + let (deposit, message_size) = + Tx_rollup_message.make_deposit payer destination ticket_hash amount + in + Tx_rollup_state.get ctxt dst_rollup >>=? fun (ctxt, state) -> + Tx_rollup_state.burn_cost ~limit:None state message_size >>?= fun cost -> + Token.transfer + ctxt + (`Contract (Contract.implicit_contract payer)) + `Burned + cost + >>=? fun (ctxt, balance_updates) -> + Tx_rollup_inbox.append_message ctxt dst_rollup state deposit + >>=? fun (ctxt, state) -> + Tx_rollup_state.update ctxt dst_rollup state >>=? fun ctxt -> + (* TODO: https://gitlab.com/tezos/tezos/-/issues/2339 + Storage fees for transaction rollup. + We need to charge for newly allocated storage (as we do for + Michelson’s big map). This also means taking into account + the global table of tickets. *) + let result = + Transaction_result + (Transaction_to_tx_rollup_result + { + balance_updates; + consumed_gas = Gas.consumed ~since ~until:ctxt; + ticket_hash; + }) + in + 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 = + Script.force_decode_in_context + ~consume_deserialization_gas + 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) -> + let views_result = + Script_ir_translator.typecheck_views + ctxt + ~legacy:false + parsed_script.storage_type + parsed_script.views + in + trace (Script_tc_errors.Ill_typed_contract (unparsed_code, [])) views_result + >>=? fun ctxt -> + Script_ir_translator.collect_lazy_storage + ctxt + parsed_script.storage_type + parsed_script.storage + >>?= fun (to_duplicate, ctxt) -> + let to_update = Script_ir_translator.no_lazy_storage_id in + Script_ir_translator.extract_lazy_storage_diff + ctxt + Optimized + parsed_script.storage_type + parsed_script.storage + ~to_duplicate + ~to_update + ~temporary:false + >>=? fun (storage, lazy_storage_diff, ctxt) -> + Script_ir_translator.unparse_data + ctxt + Optimized + parsed_script.storage_type + storage + >>=? fun (storage, ctxt) -> + let storage = Script.lazy_expr (Micheline.strip_locations storage) in + let script = {script with 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 + contract + ~script:(script, lazy_storage_diff) + >>=? fun ctxt -> + (match delegate with + | None -> return ctxt + | Some delegate -> Delegate.init ctxt contract delegate) + >>=? fun ctxt -> + Token.transfer ctxt (`Contract source) (`Contract contract) credit + >>=? fun (ctxt, balance_updates) -> + Fees.record_paid_storage_space ctxt contract ~ticket_table_size_diff:Z.zero + >|=? fun (ctxt, size, paid_storage_size_diff) -> + let result = + Origination_result + { + lazy_storage_diff; + balance_updates; + originated_contracts = [contract]; + consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; + storage_size = size; + paid_storage_size_diff; + } + in + (ctxt, result, []) + (** Retrieving the source code of a contract from its address is costly @@ -929,282 +1215,48 @@ let apply_manager_operation_content : : kind successful_manager_operation_result), [] ) | Transaction - {amount; parameters; destination = Contract destination; entrypoint} -> ( - Script.force_decode_in_context + {amount; parameters; destination = Contract contract; entrypoint} -> + apply_transaction ~consume_deserialization_gas - ctxt - parameters - >>?= fun (parameter, ctxt) -> - (match Contract.is_implicit destination with - | None -> - (if Tez.(amount = zero) then - (* Detect potential call to non existent contract. *) - Contract.must_exist ctxt destination - else return_unit) - >>=? fun () -> - (* Since the contract is originated, nothing will be allocated - or the next transfer of tokens will fail. *) - return_false - | Some _ -> - (* Transfers of zero to implicit accounts are forbidden. *) - error_when Tez.(amount = zero) (Empty_transaction destination) - >>?= fun () -> - (* If the implicit contract is not yet allocated at this point then - the next transfer of tokens will allocate it. *) - Contract.allocated ctxt destination >|=? not) - >>=? fun allocated_destination_contract -> - Token.transfer ctxt (`Contract source) (`Contract destination) amount - >>=? fun (ctxt, balance_updates) -> - Script_cache.find ctxt destination >>=? fun (ctxt, cache_key, script) -> - match script with - | None -> - Lwt.return - ( ( (if Entrypoint.is_default entrypoint then Result.return_unit - else error (Script_tc_errors.No_such_entrypoint entrypoint)) - >>? fun () -> - match Micheline.root parameter with - | Prim (_, D_Unit, [], _) -> - (* Allow [Unit] parameter to non-scripted contracts. *) - ok ctxt - | _ -> - error - (Script_interpreter.Bad_contract_parameter destination) ) - >|? fun ctxt -> - let result = - Transaction_result - (Transaction_to_contract_result - { - storage = None; - lazy_storage_diff = None; - balance_updates; - originated_contracts = []; - consumed_gas = - Gas.consumed ~since:before_operation ~until:ctxt; - storage_size = Z.zero; - paid_storage_size_diff = Z.zero; - allocated_destination_contract; - }) - in - (ctxt, result, []) ) - | Some (script, script_ir) -> - (* Token.transfer which is being called above already loads this - value into the Irmin cache, so no need to burn gas for it. *) - Contract.get_balance ctxt destination >>=? fun balance -> - let now = Script_timestamp.now ctxt in - let level = - (Level.current ctxt).level |> Raw_level.to_int32 - |> Script_int.of_int32 |> Script_int.abs - in - let step_constants = - let open Script_interpreter in - { - source; - payer = Contract.implicit_contract payer; - self = destination; - amount; - chain_id; - balance; - now; - level; - } - in - Script_interpreter.execute - ctxt - ~cached_script:(Some script_ir) - mode - step_constants - ~script - ~parameter - ~entrypoint - ~internal - >>=? fun ( {ctxt; storage; lazy_storage_diff; operations; ticket_diffs}, - (updated_cached_script, updated_size) ) -> - update_script_storage_and_ticket_balances - ctxt - ~self:destination - storage - lazy_storage_diff - ticket_diffs - operations - >>=? fun (ticket_table_size_diff, ctxt) -> - Fees.record_paid_storage_space - ctxt - destination - ~ticket_table_size_diff - >>=? fun (ctxt, new_size, paid_storage_size_diff) -> - Contract.originated_from_current_nonce - ~since:before_operation - ~until:ctxt - >>=? fun originated_contracts -> - Lwt.return - ( Script_cache.update - ctxt - cache_key - ( {script with storage = Script.lazy_expr storage}, - updated_cached_script ) - updated_size - >|? fun ctxt -> - let result = - Transaction_result - (Transaction_to_contract_result - { - storage = Some storage; - lazy_storage_diff; - balance_updates; - originated_contracts; - consumed_gas = - Gas.consumed ~since:before_operation ~until:ctxt; - storage_size = new_size; - paid_storage_size_diff; - allocated_destination_contract; - }) - in - (ctxt, result, operations) )) + ~ctxt + ~parameters + ~source + ~contract + ~amount + ~entrypoint + ~before_operation + ~payer + ~chain_id + ~mode + ~internal | Transaction {amount; parameters; destination = Tx_rollup dst; entrypoint} -> - assert_tx_rollup_feature_enabled ctxt >>=? fun () -> - fail_unless Tez.(amount = zero) Tx_rollup_invalid_transaction_amount - >>=? fun () -> - if Entrypoint.(entrypoint = Tx_rollup.deposit_entrypoint) then - Script.force_decode_in_context - ~consume_deserialization_gas - ctxt - parameters - >>?= fun (parameters, ctxt) -> - Script_ir_translator.parse_tx_rollup_deposit_parameters ctxt parameters - >>?= fun (Tx_rollup.{ticketer; contents; ty; amount; destination}, ctxt) - -> - Tx_rollup.hash_ticket ctxt dst ~contents ~ticketer ~ty - >>?= fun (ticket_hash, ctxt) -> - (* The deposit is returned to the [payer] as a withdrawal - if it fails due to a Balance_overflow in the - recipient. The recipient of withdrawals are always - implicit. We set the withdrawal recipient to [payer]. *) - let (deposit, message_size) = - Tx_rollup_message.make_deposit payer destination ticket_hash amount - in - Tx_rollup_state.get ctxt dst >>=? fun (ctxt, state) -> - Tx_rollup_state.burn_cost ~limit:None state message_size - >>?= fun cost -> - Token.transfer - ctxt - (`Contract (Contract.implicit_contract payer)) - `Burned - cost - >>=? fun (ctxt, balance_updates) -> - Tx_rollup_inbox.append_message ctxt dst state deposit - >>=? fun (ctxt, state) -> - Tx_rollup_state.update ctxt dst state >>=? fun ctxt -> - (* TODO: https://gitlab.com/tezos/tezos/-/issues/2339 - Storage fees for transaction rollup. - We need to charge for newly allocated storage (as we do for - Michelson’s big map). This also means taking into account - the global table of tickets. *) - let result = - Transaction_result - (Transaction_to_tx_rollup_result - { - balance_updates; - consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; - ticket_hash; - }) - in - return (ctxt, result, []) - else fail (Script_tc_errors.No_such_entrypoint entrypoint) + apply_transaction_to_rollup + ~consume_deserialization_gas + ~ctxt + ~parameters + ~amount + ~entrypoint + ~payer + ~dst_rollup:dst + ~since:before_operation | Origination {delegate; script; preorigination; credit} -> Script.force_decode_in_context ~consume_deserialization_gas ctxt - script.storage + script.Script.storage >>?= fun (_unparsed_storage, ctxt) -> - Script.force_decode_in_context + apply_origination ~consume_deserialization_gas - ctxt - 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) -> - let views_result = - Script_ir_translator.typecheck_views - ctxt - ~legacy:false - parsed_script.storage_type - parsed_script.views - in - trace - (Script_tc_errors.Ill_typed_contract (unparsed_code, [])) - views_result - >>=? fun ctxt -> - Script_ir_translator.collect_lazy_storage - ctxt - parsed_script.storage_type - parsed_script.storage - >>?= fun (to_duplicate, ctxt) -> - let to_update = Script_ir_translator.no_lazy_storage_id in - Script_ir_translator.extract_lazy_storage_diff - ctxt - Optimized - parsed_script.storage_type - parsed_script.storage - ~to_duplicate - ~to_update - ~temporary:false - >>=? fun (storage, lazy_storage_diff, ctxt) -> - Script_ir_translator.unparse_data - ctxt - Optimized - parsed_script.storage_type - storage - >>=? fun (storage, ctxt) -> - let storage = Script.lazy_expr (Micheline.strip_locations storage) in - let script = {script with 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 - contract - ~script:(script, lazy_storage_diff) - >>=? fun ctxt -> - (match delegate with - | None -> return ctxt - | Some delegate -> Delegate.init ctxt contract delegate) - >>=? fun ctxt -> - Token.transfer ctxt (`Contract source) (`Contract contract) credit - >>=? fun (ctxt, balance_updates) -> - Fees.record_paid_storage_space - ctxt - contract - ~ticket_table_size_diff:Z.zero - >|=? fun (ctxt, size, paid_storage_size_diff) -> - let result = - Origination_result - { - lazy_storage_diff; - balance_updates; - originated_contracts = [contract]; - consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; - storage_size = size; - paid_storage_size_diff; - } - in - (ctxt, result, []) + ~ctxt + ~script + ~internal + ~preorigination + ~delegate + ~source + ~credit + ~before_operation | Delegation delegate -> - Delegate.set ctxt source delegate >|=? fun ctxt -> - ( ctxt, - Delegation_result - {consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt}, - [] ) + apply_delegation ~ctxt ~source ~delegate ~since:before_operation | Register_global_constant {value} -> (* Decode the value and consume gas appropriately *) Script.force_decode_in_context ~consume_deserialization_gas ctxt value @@ -1438,8 +1490,9 @@ let apply_internal_manager_operations ctxt mode ~payer ~chain_id ops = match worklist with | [] -> Lwt.return (Success ctxt, List.rev applied) | Internal_operation ({source; operation; nonce} as op) :: rest -> ( + let op_res = Apply_results.contents_of_internal_operation op in (if internal_nonce_already_recorded ctxt nonce then - fail (Internal_operation_replay (Internal_operation op)) + fail (Internal_operation_replay (Internal_contents op_res)) else let ctxt = record_internal_nonce ctxt nonce in apply_manager_operation_content @@ -1454,21 +1507,24 @@ let apply_internal_manager_operations ctxt mode ~payer ~chain_id ops = >>= function | Error errors -> let result = - Internal_operation_result - (op, Failed (manager_kind op.operation, errors)) + pack_internal_manager_operation_result + op + (Failed (manager_kind op.operation, errors)) in let skipped = List.rev_map (fun (Internal_operation op) -> - Internal_operation_result - (op, Skipped (manager_kind op.operation))) + pack_internal_manager_operation_result + op + (Skipped (manager_kind op.operation))) rest in Lwt.return (Failure, List.rev (skipped @ result :: applied)) | Ok (ctxt, result, emitted) -> apply ctxt - (Internal_operation_result (op, Applied result) :: applied) + (pack_internal_manager_operation_result op (Applied result) + :: applied) (emitted @ rest)) in apply ctxt [] ops @@ -1695,7 +1751,7 @@ let apply_manager_contents (type kind) ctxt mode chain_id ~gas_consumed_in_precheck (op : kind Kind.manager contents) : (success_or_failure * kind manager_operation_result - * packed_internal_operation_result list) + * packed_internal_manager_operation_result list) Lwt.t = let[@coq_match_with_default] (Manager_operation { @@ -1735,17 +1791,17 @@ let apply_manager_contents (type kind) ctxt mode chain_id >>= function | Ok (ctxt, storage_limit, operation_results) -> ( List.fold_left_es - (fun (ctxt, storage_limit, res) iopr -> - let (Internal_operation_result (op, mopr)) = iopr in + (fun (ctxt, storage_limit, res) imopr -> + let (Internal_manager_operation_result (op, mopr)) = imopr in match mopr with | Applied smopr -> burn_storage_fees ctxt smopr ~storage_limit ~payer >>=? fun (ctxt, storage_limit, smopr) -> - let iopr = - Internal_operation_result (op, Applied smopr) + let imopr = + Internal_manager_operation_result (op, Applied smopr) in - return (ctxt, storage_limit, iopr :: res) - | _ -> return (ctxt, storage_limit, iopr :: res)) + return (ctxt, storage_limit, imopr :: res) + | _ -> return (ctxt, storage_limit, imopr :: res)) (ctxt, storage_limit, []) internal_operations_results >|= function @@ -2002,9 +2058,10 @@ let mark_backtracked results = op.internal_operation_results; }, mark_contents_list rest ) - and mark_internal_operation_results (Internal_operation_result (kind, result)) - = - Internal_operation_result (kind, mark_manager_operation_result result) + and mark_internal_operation_results + (Internal_manager_operation_result (kind, result)) = + Internal_manager_operation_result + (kind, mark_manager_operation_result result) and mark_manager_operation_result : type kind. kind manager_operation_result -> kind manager_operation_result = function diff --git a/src/proto_alpha/lib_protocol/apply.mli b/src/proto_alpha/lib_protocol/apply.mli index bc0455817382ca4a2f403c41df0488b3773b68db..60d9cc778bb80e8ec5b5bd8fcfedf5fe5c411503 100644 --- a/src/proto_alpha/lib_protocol/apply.mli +++ b/src/proto_alpha/lib_protocol/apply.mli @@ -37,7 +37,8 @@ open Alpha_context open Apply_results type error += - | (* `Permanent *) Internal_operation_replay of packed_internal_operation + | (* `Permanent *) + Internal_operation_replay of packed_internal_contents type error += (* Permanent *) Gas_quota_exceeded_init_deserialize diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 062942918a8da06ae6c751a623d8fa86ca8e86a2..97ca524bc38379f912adf1a756b9caca2caac92f 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -46,6 +46,55 @@ let error_encoding = let trace_encoding = make_trace_encoding error_encoding +type 'kind internal_manager_operation = + | Transaction : transaction -> Kind.transaction internal_manager_operation + | Origination : origination -> Kind.origination internal_manager_operation + | Delegation : + Signature.Public_key_hash.t option + -> Kind.delegation internal_manager_operation + +type packed_internal_manager_operation = + | Manager : + 'kind internal_manager_operation + -> packed_internal_manager_operation + +type 'kind internal_contents = { + source : Contract.contract; + operation : 'kind internal_manager_operation; + nonce : int; +} + +type packed_internal_contents = + | Internal_contents : 'kind internal_contents -> packed_internal_contents + +let manager_operation_of_internal_operation (type kind) + (operation : kind internal_manager_operation) : kind manager_operation = + match operation with + | Transaction transaction -> Transaction transaction + | Origination origination -> Origination origination + | Delegation delegate -> Delegation delegate + +let contents_of_internal_operation (type kind) + ({source; operation; nonce} : kind internal_operation) : + kind internal_contents = + let operation : kind internal_manager_operation = + match operation with + | Transaction transaction -> Transaction transaction + | Origination origination -> Origination origination + | Delegation delegate -> Delegation delegate + (* This function will be used on internal operations only. + TODO (MR comment !4291): the branch will be removed when internal + operations are strictly defined. *) + | _ -> assert false + in + {source; operation; nonce} + +let contents_of_packed_internal_operation (Internal_operation op) = + Internal_contents (contents_of_internal_operation op) + +let contents_of_packed_internal_operations = + List.map contents_of_packed_internal_operation + type successful_transaction_result = | Transaction_to_contract_result of { storage : Script.expr option; @@ -188,10 +237,16 @@ type 'kind manager_operation_result = | Skipped : 'kind Kind.manager -> 'kind manager_operation_result [@@coq_force_gadt] -type packed_internal_operation_result = - | Internal_operation_result : - 'kind internal_operation * 'kind manager_operation_result - -> packed_internal_operation_result +type packed_internal_manager_operation_result = + | Internal_manager_operation_result : + 'kind internal_contents * 'kind manager_operation_result + -> packed_internal_manager_operation_result + +let pack_internal_manager_operation_result (type kind) + (internal_op : kind internal_operation) + (manager_op : kind manager_operation_result) = + let internal_op = contents_of_internal_operation internal_op in + Internal_manager_operation_result (internal_op, manager_op) module Manager_result = struct type 'kind case = @@ -199,9 +254,6 @@ module Manager_result = struct op_case : 'kind Operation.Encoding.Manager_operations.case; encoding : 'a Data_encoding.t; kind : 'kind Kind.manager; - iselect : - packed_internal_operation_result -> - ('kind internal_operation * 'kind manager_operation_result) option; select : packed_successful_manager_operation_result -> 'kind successful_manager_operation_result option; @@ -211,7 +263,7 @@ module Manager_result = struct } -> 'kind case - let make ~op_case ~encoding ~kind ~iselect ~select ~proj ~inj = + let make ~op_case ~encoding ~kind ~select ~proj ~inj = let (Operation.Encoding.Manager_operations.MCase {name; _}) = op_case in let t = def (Format.asprintf "operation.alpha.operation_result.%s" name) @@ -262,7 +314,7 @@ module Manager_result = struct (fun (((), errs), x) -> Backtracked (inj x, errs)); ] in - MCase {op_case; encoding; kind; iselect; select; proj; inj; t} + MCase {op_case; encoding; kind; select; proj; inj; t} let[@coq_axiom_with_reason "gadt"] reveal_case = make @@ -272,10 +324,6 @@ module Manager_result = struct obj2 (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero)) - ~iselect:(function - | Internal_operation_result (({operation = Reveal _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Reveal_result _ as op) -> Some op | _ -> None) @@ -374,11 +422,6 @@ module Manager_result = struct make ~op_case:Operation.Encoding.Manager_operations.transaction_case ~encoding:transaction_contract_variant_cases - ~iselect:(function - | Internal_operation_result (({operation = Transaction _; _} as op), res) - -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Transaction_result _ as op) -> Some op | _ -> None) @@ -398,11 +441,6 @@ module Manager_result = struct (dft "storage_size" z Z.zero) (dft "paid_storage_size_diff" z Z.zero) (opt "lazy_storage_diff" Lazy_storage.encoding)) - ~iselect:(function - | Internal_operation_result (({operation = Origination _; _} as op), res) - -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Origination_result _ as op) -> Some op | _ -> None) @@ -454,11 +492,6 @@ module Manager_result = struct (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (dft "storage_size" z Z.zero) (req "global_address" Script_expr_hash.encoding)) - ~iselect:(function - | Internal_operation_result - (({operation = Register_global_constant _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Register_global_constant_result _ as op) -> Some op @@ -495,11 +528,6 @@ module Manager_result = struct obj2 (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero)) - ~iselect:(function - | Internal_operation_result (({operation = Delegation _; _} as op), res) - -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Delegation_result _ as op) -> Some op | _ -> None) @@ -519,11 +547,6 @@ module Manager_result = struct obj2 (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero)) - ~iselect:(function - | Internal_operation_result - (({operation = Set_deposits_limit _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Set_deposits_limit_result _ as op) -> Some op @@ -546,11 +569,6 @@ module Manager_result = struct (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (req "originated_rollup" Tx_rollup.encoding)) - ~iselect:(function - | Internal_operation_result - (({operation = Tx_rollup_origination; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Tx_rollup_origination_result _ as op) -> Some op @@ -585,11 +603,6 @@ module Manager_result = struct (req "balance_updates" Receipt.balance_updates_encoding) (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero)) - ~iselect:(function - | Internal_operation_result - (({operation = Tx_rollup_submit_batch _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Tx_rollup_submit_batch_result _ as op) -> Some op @@ -612,11 +625,6 @@ module Manager_result = struct (req "balance_updates" Receipt.balance_updates_encoding) (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero)) - ~iselect:(function - | Internal_operation_result - (({operation = Tx_rollup_commit _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Tx_rollup_commit_result _ as op) -> Some op | _ -> None) @@ -638,11 +646,6 @@ module Manager_result = struct (req "balance_updates" Receipt.balance_updates_encoding) (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero)) - ~iselect:(function - | Internal_operation_result - (({operation = Tx_rollup_return_bond _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Tx_rollup_return_bond_result _ as op) -> Some op @@ -667,11 +670,6 @@ module Manager_result = struct (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (req "level" Tx_rollup_level.encoding)) - ~iselect:(function - | Internal_operation_result - (({operation = Tx_rollup_finalize_commitment _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Tx_rollup_finalize_commitment_result _ as op) -> @@ -698,11 +696,6 @@ module Manager_result = struct (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (req "level" Tx_rollup_level.encoding)) - ~iselect:(function - | Internal_operation_result - (({operation = Tx_rollup_remove_commitment _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Tx_rollup_remove_commitment_result _ as op) -> @@ -727,11 +720,6 @@ module Manager_result = struct (req "balance_updates" Receipt.balance_updates_encoding) (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero)) - ~iselect:(function - | Internal_operation_result - (({operation = Tx_rollup_rejection _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Tx_rollup_rejection_result _ as op) -> Some op @@ -755,11 +743,6 @@ module Manager_result = struct (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (req "size" z)) - ~iselect:(function - | Internal_operation_result - (({operation = Sc_rollup_originate _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Sc_rollup_originate_result _ as op) -> Some op @@ -787,11 +770,6 @@ module Manager_result = struct (req "consumed_gas" Gas.Arith.n_integral_encoding) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (req "inbox_after" Sc_rollup.Inbox.encoding)) - ~iselect:(function - | Internal_operation_result - (({operation = Sc_rollup_add_messages _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Sc_rollup_add_messages_result _ as op) -> Some op @@ -812,11 +790,6 @@ module Manager_result = struct (obj2 (req "consumed_gas" Gas.Arith.n_integral_encoding) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero)) - ~iselect:(function - | Internal_operation_result - (({operation = Sc_rollup_cement _; _} as op), res) -> - Some (op, res) - | _ -> None) ~select:(function | Successful_manager_result (Sc_rollup_cement_result _ as op) -> Some op | _ -> None) @@ -829,10 +802,165 @@ module Manager_result = struct Sc_rollup_cement_result {consumed_gas = consumed_milligas}) end -let internal_operation_result_encoding : - packed_internal_operation_result Data_encoding.t = +type 'kind iselect = + packed_internal_manager_operation_result -> + ('kind internal_contents * 'kind manager_operation_result) option + +module Internal_result = struct + open Data_encoding + + type 'kind case = + | MCase : { + tag : int; + name : string; + encoding : 'a Data_encoding.t; + iselect : 'kind iselect; + select : + packed_internal_manager_operation -> + 'kind internal_manager_operation option; + proj : 'kind internal_manager_operation -> 'a; + inj : 'a -> 'kind internal_manager_operation; + } + -> 'kind case + [@@coq_force_gadt] + + let[@coq_axiom_with_reason "gadt"] transaction_case = + MCase + { + tag = Operation.Encoding.Manager_operations.transaction_tag; + name = "transaction"; + encoding = + obj3 + (req "amount" Tez.encoding) + (req "destination" Destination.encoding) + (opt + "parameters" + (obj2 + (req "entrypoint" Entrypoint.smart_encoding) + (req "value" Script.lazy_expr_encoding))); + iselect : Kind.transaction iselect = + (function + | Internal_manager_operation_result + (({operation = Transaction _; _} as op), res) -> + Some (op, res) + | _ -> None); + select = + (function Manager (Transaction _ as op) -> Some op | _ -> None); + proj = + (function + | Transaction {amount; destination; parameters; entrypoint} -> + let parameters = + if + Script_repr.is_unit_parameter parameters + && Entrypoint.is_default entrypoint + then None + else Some (entrypoint, parameters) + in + (amount, destination, parameters)); + inj = + (fun (amount, destination, parameters) -> + let (entrypoint, parameters) = + match parameters with + | None -> (Entrypoint.default, Script.unit_parameter) + | Some (entrypoint, value) -> (entrypoint, value) + in + Transaction {amount; destination; parameters; entrypoint}); + } + + let[@coq_axiom_with_reason "gadt"] origination_case = + MCase + { + tag = Operation.Encoding.Manager_operations.origination_tag; + name = "origination"; + encoding = + obj3 + (req "balance" Tez.encoding) + (opt "delegate" Signature.Public_key_hash.encoding) + (req "script" Script.encoding); + iselect : Kind.origination iselect = + (function + | Internal_manager_operation_result + (({operation = Origination _; _} as op), res) -> + Some (op, res) + | _ -> None); + select = + (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)); + inj = + (fun (credit, delegate, script) -> + Origination {credit; delegate; script; preorigination = None}); + } + + let[@coq_axiom_with_reason "gadt"] delegation_case = + MCase + { + tag = Operation.Encoding.Manager_operations.delegation_tag; + name = "delegation"; + encoding = obj1 (opt "delegate" Signature.Public_key_hash.encoding); + iselect : Kind.delegation iselect = + (function + | Internal_manager_operation_result + (({operation = Delegation _; _} as op), res) -> + Some (op, res) + | _ -> None); + select = + (function Manager (Delegation _ as op) -> Some op | _ -> None); + proj = (function Delegation key -> key); + inj = (fun key -> Delegation key); + } + + let case tag name args proj inj = + case + tag + ~title:(String.capitalize_ascii name) + (merge_objs (obj1 (req "kind" (constant name))) args) + (fun x -> match proj x with None -> None | Some x -> Some ((), x)) + (fun ((), x) -> inj x) + + let encoding = + let make (MCase {tag; name; encoding; iselect = _; select; proj; inj}) = + case + (Tag tag) + name + encoding + (fun o -> match select o with None -> None | Some o -> Some (proj o)) + (fun x -> Manager (inj x)) + in + union + ~tag_size:`Uint8 + [make transaction_case; make origination_case; make delegation_case] +end + +let internal_contents_encoding : packed_internal_contents Data_encoding.t = + def "apply_results.alpha.internal_operation_result" + @@ conv + (fun (Internal_contents {source; operation; nonce}) -> + ((source, nonce), Manager operation)) + (fun ((source, nonce), Manager operation) -> + Internal_contents {source; operation; nonce}) + (merge_objs + (obj2 (req "source" Contract.encoding) (req "nonce" uint16)) + Internal_result.encoding) + +let internal_manager_operation_result_encoding : + packed_internal_manager_operation_result Data_encoding.t = let make (type kind) - (Manager_result.MCase res_case : kind Manager_result.case) = + (Manager_result.MCase res_case : kind Manager_result.case) + (Internal_result.MCase ires_case : kind Internal_result.case) = let (Operation.Encoding.Manager_operations.MCase op_case) = res_case.op_case in @@ -844,30 +972,22 @@ let internal_operation_result_encoding : (req "kind" (constant op_case.name)) (req "source" Contract.encoding) (req "nonce" uint16)) - (merge_objs op_case.encoding (obj1 (req "result" res_case.t)))) + (merge_objs ires_case.encoding (obj1 (req "result" res_case.t)))) (fun op -> - match res_case.iselect op with + match ires_case.iselect op with | Some (op, res) -> - Some (((), op.source, op.nonce), (op_case.proj op.operation, res)) + Some (((), op.source, op.nonce), (ires_case.proj op.operation, res)) | None -> None) (fun (((), source, nonce), (op, res)) -> - let op = {source; operation = op_case.inj op; nonce} in - Internal_operation_result (op, res)) + let op = {source; operation = ires_case.inj op; nonce} in + Internal_manager_operation_result (op, res)) in - def "operation.alpha.internal_operation_result" + def "apply_results.alpha.operation_result" @@ union [ - make Manager_result.reveal_case; - make Manager_result.transaction_case; - make Manager_result.origination_case; - make Manager_result.delegation_case; - make Manager_result.register_global_constant_case; - make Manager_result.set_deposits_limit_case; - make Manager_result.tx_rollup_origination_case; - make Manager_result.tx_rollup_submit_batch_case; - make Manager_result.sc_rollup_originate_case; - make Manager_result.sc_rollup_add_messages_case; - make Manager_result.sc_rollup_cement_case; + make Manager_result.transaction_case Internal_result.transaction_case; + make Manager_result.origination_case Internal_result.origination_case; + make Manager_result.delegation_case Internal_result.delegation_case; ] let successful_manager_operation_result_encoding : @@ -931,7 +1051,7 @@ type 'kind contents_result = | Manager_operation_result : { balance_updates : Receipt.balance_updates; operation_result : 'kind manager_operation_result; - internal_operation_results : packed_internal_operation_result list; + internal_operation_results : packed_internal_manager_operation_result list; } -> 'kind Kind.manager contents_result @@ -1223,7 +1343,7 @@ module Encoding = struct (req "operation_result" res_case.t) (dft "internal_operation_results" - (list internal_operation_result_encoding) + (list internal_manager_operation_result_encoding) []); select = (function diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index cfe57099a9a3dc1d625a0363cf79726b8e52cf24..ae940158f86dc793af0ac5647f525ba08e4037f3 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -33,6 +33,35 @@ open Alpha_context +type 'kind internal_manager_operation = + | Transaction : + Alpha_context.transaction + -> Kind.transaction internal_manager_operation + | Origination : + Alpha_context.origination + -> Kind.origination internal_manager_operation + | Delegation : + Signature.Public_key_hash.t option + -> Kind.delegation internal_manager_operation + +val manager_operation_of_internal_operation : + 'kind internal_manager_operation -> 'kind manager_operation + +type 'kind internal_contents = { + source : Contract.contract; + operation : 'kind internal_manager_operation; + nonce : int; +} + +type packed_internal_contents = + | Internal_contents : 'kind internal_contents -> packed_internal_contents + +val contents_of_packed_internal_operation : + packed_internal_operation -> packed_internal_contents + +val contents_of_packed_internal_operations : + packed_internal_operation list -> packed_internal_contents list + (** Result of applying a {!Operation.t}. Follows the same structure. *) type 'kind operation_metadata = {contents : 'kind contents_result_list} @@ -87,7 +116,7 @@ and 'kind contents_result = | Manager_operation_result : { balance_updates : Receipt.balance_updates; operation_result : 'kind manager_operation_result; - internal_operation_results : packed_internal_operation_result list; + internal_operation_results : packed_internal_manager_operation_result list; } -> 'kind Kind.manager contents_result @@ -232,10 +261,20 @@ and packed_successful_manager_operation_result = 'kind successful_manager_operation_result -> packed_successful_manager_operation_result -and packed_internal_operation_result = - | Internal_operation_result : - 'kind internal_operation * 'kind manager_operation_result - -> packed_internal_operation_result +and packed_internal_manager_operation_result = + | Internal_manager_operation_result : + 'kind internal_contents * 'kind manager_operation_result + -> packed_internal_manager_operation_result + +val contents_of_internal_operation : + 'kind internal_operation -> 'kind internal_contents + +val pack_internal_manager_operation_result : + 'kind internal_operation -> + 'kind manager_operation_result -> + packed_internal_manager_operation_result + +val internal_contents_encoding : packed_internal_contents Data_encoding.t val pack_migration_operation_results : Migration.origination_result list -> diff --git a/src/proto_alpha/lib_protocol/contract_services.ml b/src/proto_alpha/lib_protocol/contract_services.ml index 5d1420e5cab1ecb2412056c14751e7aa49dc3a62..a69fa5d69b334fccacbfc79c1875a3930ad517c9 100644 --- a/src/proto_alpha/lib_protocol/contract_services.ml +++ b/src/proto_alpha/lib_protocol/contract_services.ml @@ -377,7 +377,7 @@ let[@coq_axiom_with_reason "gadt"] register () = entrypoint >>? fun (r, ctxt) -> r |> function - | Ok (_f, Ex_ty ty) -> + | Ok (Ex_ty_cstr (ty, _)) -> unparse_ty ~loc:() ctxt ty >|? fun (ty_node, _) -> Some (Micheline.strip_locations ty_node) | Error _ -> Result.return_none )) ; diff --git a/src/proto_alpha/lib_protocol/dune.inc b/src/proto_alpha/lib_protocol/dune.inc index 99343fa12de8c54bb1dd70d4d315f4f6e25d7f65..b4ed318d9b39059debc3c2314c7622234c3f77d8 100644 --- a/src/proto_alpha/lib_protocol/dune.inc +++ b/src/proto_alpha/lib_protocol/dune.inc @@ -155,6 +155,7 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end michelson_v1_gas.mli michelson_v1_gas.ml script_list.mli script_list.ml script_tc_context.mli script_tc_context.ml + apply_results.mli apply_results.ml script_ir_translator.mli script_ir_translator.ml script_cache.mli script_cache.ml script_tc_errors_registration.mli script_tc_errors_registration.ml @@ -174,7 +175,6 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end sc_rollups.mli sc_rollups.ml baking.mli baking.ml amendment.mli amendment.ml - apply_results.mli apply_results.ml apply.mli apply.ml services_registration.mli services_registration.ml constants_services.mli constants_services.ml @@ -320,6 +320,7 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end michelson_v1_gas.mli michelson_v1_gas.ml script_list.mli script_list.ml script_tc_context.mli script_tc_context.ml + apply_results.mli apply_results.ml script_ir_translator.mli script_ir_translator.ml script_cache.mli script_cache.ml script_tc_errors_registration.mli script_tc_errors_registration.ml @@ -339,7 +340,6 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end sc_rollups.mli sc_rollups.ml baking.mli baking.ml amendment.mli amendment.ml - apply_results.mli apply_results.ml apply.mli apply.ml services_registration.mli services_registration.ml constants_services.mli constants_services.ml @@ -485,6 +485,7 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end michelson_v1_gas.mli michelson_v1_gas.ml script_list.mli script_list.ml script_tc_context.mli script_tc_context.ml + apply_results.mli apply_results.ml script_ir_translator.mli script_ir_translator.ml script_cache.mli script_cache.ml script_tc_errors_registration.mli script_tc_errors_registration.ml @@ -504,7 +505,6 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end sc_rollups.mli sc_rollups.ml baking.mli baking.ml amendment.mli amendment.ml - apply_results.mli apply_results.ml apply.mli apply.ml services_registration.mli services_registration.ml constants_services.mli constants_services.ml @@ -672,6 +672,7 @@ include Tezos_raw_protocol_alpha.Main Michelson_v1_gas Script_list Script_tc_context + Apply_results Script_ir_translator Script_cache Script_tc_errors_registration @@ -691,7 +692,6 @@ include Tezos_raw_protocol_alpha.Main Sc_rollups Baking Amendment - Apply_results Apply Services_registration Constants_services @@ -878,6 +878,7 @@ include Tezos_raw_protocol_alpha.Main michelson_v1_gas.mli michelson_v1_gas.ml script_list.mli script_list.ml script_tc_context.mli script_tc_context.ml + apply_results.mli apply_results.ml script_ir_translator.mli script_ir_translator.ml script_cache.mli script_cache.ml script_tc_errors_registration.mli script_tc_errors_registration.ml @@ -897,7 +898,6 @@ include Tezos_raw_protocol_alpha.Main sc_rollups.mli sc_rollups.ml baking.mli baking.ml amendment.mli amendment.ml - apply_results.mli apply_results.ml apply.mli apply.ml services_registration.mli services_registration.ml constants_services.mli constants_services.ml diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 3497b3a2983c6eb7d9bf280d8a0f6b467a192eaa..52b3b0b8059cdfb48c75378b4c1c987532bf8cd6 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -193,6 +193,20 @@ type raw = Operation.t = {shell : Operation.shell_header; proto : bytes} let raw_encoding = Operation.encoding +type transaction = { + amount : Tez_repr.tez; + parameters : Script_repr.lazy_expr; + entrypoint : Entrypoint_repr.t; + destination : Destination_repr.t; +} + +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 = { shell : Operation.shell_header; protocol_data : 'kind protocol_data; @@ -263,20 +277,8 @@ and _ contents = and _ manager_operation = | Reveal : Signature.Public_key.t -> Kind.reveal manager_operation - | Transaction : { - amount : Tez_repr.tez; - parameters : Script_repr.lazy_expr; - entrypoint : Entrypoint_repr.t; - destination : Destination_repr.t; - } - -> Kind.transaction manager_operation - | Origination : { - delegate : Signature.Public_key_hash.t option; - script : Script_repr.t; - credit : Tez_repr.tez; - preorigination : Contract_repr.t option; - } - -> Kind.origination manager_operation + | Transaction : transaction -> Kind.transaction manager_operation + | Origination : origination -> Kind.origination manager_operation | Delegation : Signature.Public_key_hash.t option -> Kind.delegation manager_operation @@ -477,10 +479,12 @@ module Encoding = struct inj = (fun pkh -> Reveal pkh); } + let transaction_tag = 1 + let[@coq_axiom_with_reason "gadt"] transaction_case = MCase { - tag = 1; + tag = transaction_tag; name = "transaction"; encoding = obj3 @@ -514,10 +518,12 @@ module Encoding = struct Transaction {amount; destination; parameters; entrypoint}); } + let origination_tag = 2 + let[@coq_axiom_with_reason "gadt"] origination_case = MCase { - tag = 2; + tag = origination_tag; name = "origination"; encoding = obj3 @@ -545,10 +551,12 @@ module Encoding = struct Origination {credit; delegate; script; preorigination = None}); } + let delegation_tag = 3 + let[@coq_axiom_with_reason "gadt"] delegation_case = MCase { - tag = 3; + tag = delegation_tag; name = "delegation"; encoding = obj1 (opt "delegate" Signature.Public_key_hash.encoding); select = @@ -1464,83 +1472,3 @@ let equal : type a b. a operation -> b operation -> (a, b) eq option = equal_contents_kind_list op1.protocol_data.contents op2.protocol_data.contents - -open Cache_memory_helpers - -let script_lazy_expr_size (expr : Script_repr.lazy_expr) = - let fun_value expr = ret_adding (expr_size expr) word_size in - let fun_bytes bytes = (Nodes.zero, word_size +! bytes_size bytes) in - let fun_combine expr_size bytes_size = expr_size ++ bytes_size in - ret_adding - (Data_encoding.apply_lazy ~fun_value ~fun_bytes ~fun_combine expr) - header_size - -let script_repr_size ({code; storage} : Script_repr.t) = - ret_adding (script_lazy_expr_size code ++ script_lazy_expr_size storage) h2w - -let internal_manager_operation_size (type a) (op : a manager_operation) = - match op with - | Transaction {amount = _; parameters; entrypoint; destination} -> - ret_adding - (script_lazy_expr_size parameters) - (h4w +! int64_size - +! Entrypoint_repr.in_memory_size entrypoint - +! Destination_repr.in_memory_size destination) - | Origination {delegate; script; credit = _; preorigination} -> - ret_adding - (script_repr_size script) - (h4w - +! option_size - (fun _ -> Contract_repr.public_key_hash_in_memory_size) - delegate - +! int64_size - +! option_size Contract_repr.in_memory_size preorigination) - | Delegation pkh_opt -> - ( Nodes.zero, - h1w - +! option_size - (fun _ -> Contract_repr.public_key_hash_in_memory_size) - pkh_opt ) - | Sc_rollup_originate _ -> (Nodes.zero, h2w) - | Sc_rollup_add_messages _ -> (Nodes.zero, h2w) - | Sc_rollup_cement _ -> (Nodes.zero, h2w) - | Reveal _ -> - (* Reveals can't occur as internal operations *) - assert false - | Register_global_constant _ -> - (* Global constant registrations can't occur as internal operations *) - assert false - | Set_deposits_limit _ -> - (* Set_deposits_limit can't occur as internal operations *) - assert false - | Tx_rollup_origination -> - (* Tx_rollup_origination operation can’t occur as internal operations *) - assert false - | Tx_rollup_submit_batch _ -> - (* Tx_rollup_submit_batch operation can’t occur as internal operations *) - assert false - | Tx_rollup_commit _ -> - (* Tx_rollup_commit operation can’t occur as internal operations *) - assert false - | Tx_rollup_return_bond _ -> - (* Tx_rollup_return_bond operation can’t occur as internal operations *) - assert false - | Tx_rollup_finalize_commitment _ -> - (* Tx_rollup_finalize_commitment operation can’t occur as internal operations *) - assert false - | Tx_rollup_remove_commitment _ -> - (* Tx_rollup_remove_commitment operation can’t occur as internal operations *) - assert false - | Tx_rollup_rejection _ -> - (* Tx_rollup_rejection_commitment operation can’t occur as internal operations *) - assert false - -let packed_internal_operation_in_memory_size : - packed_internal_operation -> nodes_and_size = function - | Internal_operation iop -> - let {source; operation; nonce = _} = iop in - let source_size = Contract_repr.in_memory_size source in - let nonce_size = word_size in - ret_adding - (internal_manager_operation_size operation) - (h2w +! source_size +! nonce_size) diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 38b8012836183b7dbc98eaee70fda28797323dee..2b8c0a531effcd87fc657e97a86b4788aac08c64 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -172,6 +172,20 @@ type raw = Operation.t = {shell : Operation.shell_header; proto : bytes} val raw_encoding : raw Data_encoding.t +type transaction = { + amount : Tez_repr.tez; + parameters : Script_repr.lazy_expr; + entrypoint : Entrypoint_repr.t; + destination : Destination_repr.t; +} + +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] and all data related to the operation itself in [protocol_data]. *) type 'kind operation = { @@ -290,22 +304,10 @@ and _ manager_operation = | Reveal : Signature.Public_key.t -> Kind.reveal manager_operation (* [Transaction] of some amount to some destination contract. It can also be used to execute/call smart-contracts. *) - | Transaction : { - amount : Tez_repr.tez; - parameters : Script_repr.lazy_expr; - entrypoint : Entrypoint_repr.t; - destination : Destination_repr.t; - } - -> Kind.transaction manager_operation + | Transaction : transaction -> Kind.transaction manager_operation (* [Origination] of a contract using a smart-contract [script] and initially credited with the amount [credit]. *) - | Origination : { - delegate : Signature.Public_key_hash.t option; - script : Script_repr.t; - credit : Tez_repr.tez; - preorigination : Contract_repr.t option; - } - -> Kind.origination manager_operation + | Origination : origination -> Kind.origination manager_operation (* [Delegation] to some staking contract (designated by its public key hash). When this value is None, delegation is reverted as it is set to nobody. *) @@ -457,9 +459,6 @@ type ('a, 'b) eq = Eq : ('a, 'a) eq val equal : 'a operation -> 'b operation -> ('a, 'b) eq option -val packed_internal_operation_in_memory_size : - packed_internal_operation -> Cache_memory_helpers.nodes_and_size - module Encoding : sig type 'b case = | Case : { @@ -544,10 +543,16 @@ module Encoding : sig val reveal_case : Kind.reveal case + val transaction_tag : int + val transaction_case : Kind.transaction case + val origination_tag : int + val origination_case : Kind.origination case + val delegation_tag : int + val delegation_case : Kind.delegation case val register_global_constant_case : Kind.register_global_constant case diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index d55590ed0a743137917fe257032e24fa1eeab674..c4a7ffe231dc34d8dfaeebe96085cabd325be28e 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1719,11 +1719,12 @@ let execute logger ctxt mode step_constants ~entrypoint ~internal (find_entrypoint ~error_details:Informative arg_type entrypoints entrypoint) >>?= fun (r, ctxt) -> record_trace (Bad_contract_parameter step_constants.self) r - >>?= fun (box, _) -> + >>?= fun (Ex_ty_cstr (entrypoint_ty, box)) -> trace (Bad_contract_parameter step_constants.self) - (parse_data ctxt ~legacy:false ~allow_forged:internal arg_type (box arg)) + (parse_data ctxt ~legacy:false ~allow_forged:internal entrypoint_ty arg) >>=? fun (arg, ctxt) -> + let arg = box arg in Script_ir_translator.collect_lazy_storage ctxt arg_type arg >>?= fun (to_duplicate, ctxt) -> Script_ir_translator.collect_lazy_storage ctxt storage_type old_storage diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 1ce2ac73e2435beaaf6f2b4ca784585bdeb7721a..85c997b9a33d588a37777726f7d2dabacd2325f4 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -1898,36 +1898,36 @@ let rec make_comb_set_proof_argument : let whole_stack = serialize_stack_for_error ctxt stack_ty in error (Bad_stack (loc, I_UPDATE, 2, whole_stack)) +type 'a ex_ty_cstr = Ex_ty_cstr : 'b ty * ('b -> 'a) -> 'a ex_ty_cstr + let find_entrypoint (type full error_trace) ~(error_details : error_trace error_details) (full : full ty) (entrypoints : full entrypoints) entrypoint : - ((Script.node -> Script.node) * ex_ty, error_trace) Gas_monad.t = + (full ex_ty_cstr, error_trace) Gas_monad.t = let open Gas_monad.Syntax in - let loc = Micheline.dummy_location in let rec find_entrypoint : type t. - t ty -> - t entrypoints -> - Entrypoint.t -> - ((Script.node -> Script.node) * ex_ty, unit) Gas_monad.t = + t ty -> t entrypoints -> Entrypoint.t -> (t ex_ty_cstr, unit) Gas_monad.t + = fun ty entrypoints entrypoint -> let* () = Gas_monad.consume_gas Typecheck_costs.find_entrypoint_cycle in match (ty, entrypoints) with | (_, {name = Some name; _}) when Entrypoint.(name = entrypoint) -> - return ((fun e -> e), Ex_ty ty) + return (Ex_ty_cstr (ty, fun e -> e)) | (Union_t (tl, tr, _), {nested = Entrypoints_Union {left; right}; _}) -> ( Gas_monad.bind_recover (find_entrypoint tl left entrypoint) @@ function - | Ok (f, t) -> return ((fun e -> Prim (loc, D_Left, [f e], [])), t) + | Ok (Ex_ty_cstr (t, f)) -> return (Ex_ty_cstr (t, fun e -> L (f e))) | Error () -> - let+ (f, t) = find_entrypoint tr right entrypoint in - ((fun e -> Prim (loc, D_Right, [f e], [])), t)) + let+ (Ex_ty_cstr (t, f)) = find_entrypoint tr right entrypoint in + Ex_ty_cstr (t, fun e -> R (f e))) | (_, {nested = Entrypoints_None; _}) -> Gas_monad.of_result (Error ()) in Gas_monad.bind_recover (find_entrypoint full entrypoints entrypoint) @@ function | Ok f_t -> return f_t | Error () -> - if Entrypoint.is_default entrypoint then return ((fun e -> e), Ex_ty full) + if Entrypoint.is_default entrypoint then + return (Ex_ty_cstr (full, fun e -> e)) else Gas_monad.of_result @@ Error @@ -1941,7 +1941,7 @@ let find_entrypoint_for_type (type full exp error_trace) ~error_details let open Gas_monad.Syntax in let* res = find_entrypoint ~error_details full entrypoints entrypoint in match res with - | (_, Ex_ty ty) -> ( + | Ex_ty_cstr (ty, _) -> ( match entrypoints.name with | Some e when Entrypoint.is_root e && Entrypoint.is_default entrypoint -> Gas_monad.bind_recover @@ -4651,7 +4651,7 @@ and[@coq_axiom_with_reason "gadt"] parse_instr : entrypoints entrypoint >>? fun (r, ctxt) -> - r >>? fun (_, Ex_ty param_type) -> + r >>? fun (Ex_ty_cstr (param_type, _)) -> contract_t loc param_type >>? fun res_ty -> let instr = { @@ -5317,6 +5317,25 @@ let parse_contract_for_script : | (ctxt, None) -> (ctxt, None)) | _ -> return (ctxt, None)) +let view_size view = + let open Script_typed_ir_size in + node_size view.view_code ++ node_size view.input_ty + ++ node_size view.output_ty + +let code_size ctxt code views = + let open Script_typed_ir_size in + let views_size = Script_map.fold (fun _ v s -> view_size v ++ s) views zero in + (* The size of the storage_type and the arg_type is counted by + [lambda_size]. *) + let ir_size = lambda_size code in + let (nodes, code_size) = views_size ++ ir_size in + (* We consume gas after the fact in order to not have to instrument + [node_size] (for efficiency). + This is safe, as we already pay gas proportional to [views_size] and + [ir_size] during their typechecking. *) + Gas.consume ctxt (Script_typed_ir_size_costs.nodes_cost ~nodes) + >|? fun ctxt -> (code_size, ctxt) + let parse_code : ?type_logger:type_logger -> context -> @@ -5358,28 +5377,11 @@ let parse_code : code_field) >>=? fun (code, ctxt) -> Lwt.return - (let open Script_typed_ir_size in - let view_size view = - node_size view.view_code ++ node_size view.input_ty - ++ node_size view.output_ty - in - let views_size = - Script_map.fold (fun _ v s -> view_size v ++ s) views zero - in - (* The size of the storage_type and the arg_type is counted by - [lambda_size]. *) - let ir_size = lambda_size code in - let (nodes, code_size) = views_size ++ ir_size in - (* We consume gas after the fact in order to not have to instrument - [node_size] (for efficiency). - This is safe, as we already pay gas proportional to [views_size] - and [ir_size] during their typechecking. *) - Gas.consume ctxt (Script_typed_ir_size_costs.nodes_cost ~nodes) - >>? fun ctxt -> - ok - ( Ex_code - (Code {code; arg_type; storage_type; views; entrypoints; code_size}), - ctxt )) + ( code_size ctxt code views >>? fun (code_size, ctxt) -> + ok + ( Ex_code + (Code {code; arg_type; storage_type; views; entrypoints; code_size}), + ctxt ) ) let parse_storage : ?type_logger:type_logger -> diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.mli b/src/proto_alpha/lib_protocol/script_ir_translator.mli index cfeea77563982f6c9d8dfa8425fe3a0b63265414..abc745a7aad191d3bfcf1b1512073886c4b9ce09 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.mli +++ b/src/proto_alpha/lib_protocol/script_ir_translator.mli @@ -431,12 +431,19 @@ val parse_contract_for_script : val parse_tx_rollup_deposit_parameters : context -> Script.expr -> (Tx_rollup.deposit_parameters * context) tzresult +(** ['a ex_ty_cstr] is like [ex_ty], but also adds to the existential a function + used to reconstruct a value of type ['a] from the internal type of the + existential. Typically, it will be used to go from the type of an + entry-point to the full type of a contract. *) +type 'a ex_ty_cstr = + | Ex_ty_cstr : 'b Script_typed_ir.ty * ('b -> 'a) -> 'a ex_ty_cstr + val find_entrypoint : error_details:'error_trace error_details -> 't Script_typed_ir.ty -> 't Script_typed_ir.entrypoints -> Entrypoint.t -> - ((Script.node -> Script.node) * ex_ty, 'error_trace) Gas_monad.t + ('t ex_ty_cstr, 'error_trace) Gas_monad.t val list_entrypoints : context -> @@ -509,6 +516,14 @@ val get_single_sapling_state : 'a -> (Sapling.Id.t option * context) tzresult +(** [code_size ctxt code views] returns an overapproximation of the size of + the in-memory representation of [code] and [views] in the context [ctxt]. *) +val code_size : + context -> + ('a, 'b) Script_typed_ir.lambda -> + Script_typed_ir.view_map -> + (Cache_memory_helpers.sint * context) tzresult + (** [script_size script] returns an overapproximation of the size of the in-memory representation of [script] as well as the cost associated to computing that overapproximation. *) diff --git a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml index 303cba4c5527f55a729fdfc5bd02745c7f8b8a0f..3856d3a341973303bd98c7d5f4d14f6bb559ad30 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml @@ -198,12 +198,6 @@ let sapling_state_size {Sapling.id; diff; memo_size = _} = +! Sapling.diff_in_memory_size diff +! sapling_memo_size_size -let operation_size {piop; lazy_storage_diff} = - ret_adding - (Operation.packed_internal_operation_in_memory_size piop - ++ option_size_vec Lazy_storage.diffs_in_memory_size lazy_storage_diff) - h2w - let chain_id_size = h1w +? Chain_id.size (* [contents] is handle by the recursion scheme in [value_size] *) @@ -313,7 +307,10 @@ let rec value_size : | Sapling_transaction_t _ -> ret_succ_adding accu (Sapling.transaction_in_memory_size x) | Sapling_state_t _ -> ret_succ_adding accu (sapling_state_size x) - | Operation_t -> ret_succ (accu ++ operation_size x) + (* Operations are neither storable nor pushable, so they can appear neither + in the storage nor in the script. Hence they cannot appear in the cache + and we never need to measure their size. *) + | Operation_t -> assert false | Chain_id_t -> ret_succ_adding accu chain_id_size | Never_t -> ( match x with _ -> .) | Bls12_381_g1_t -> ret_succ_adding accu !!Bls12_381.G1.size_in_memory diff --git a/src/proto_alpha/lib_protocol/test/helpers/incremental.ml b/src/proto_alpha/lib_protocol/test/helpers/incremental.ml index d53c8a63ec7a981cf2ffa7c1dcbece6a02628a4e..179bc2d1d055aa30eeb6f0090240493656a47453 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/incremental.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/incremental.ml @@ -143,7 +143,8 @@ let detect_script_failure : in detect_script_failure operation_result >>? fun () -> List.iter_e - (fun (Internal_operation_result (_, r)) -> detect_script_failure r) + (fun (Internal_manager_operation_result (_, r)) -> + detect_script_failure r) internal_operation_results in function diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 49953bc63b1af7f8719d282edfbe3e3388584cc6..6381cb0903d5483ed10869e8e139c46c81685b49 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -178,7 +178,7 @@ let tickets_of_transaction ctxt ~destination ~parameters ~entrypoint = entrypoints entrypoint) >>?= fun (res, ctxt) -> - res >>?= fun (_f, Ex_ty entry_arg_ty) -> + res >>?= fun (Ex_ty_cstr (entry_arg_ty, _f)) -> Ticket_scanner.type_has_tickets ctxt entry_arg_ty >>?= fun (has_tickets, ctxt) -> (* Load the tickets from the parameters. *) diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[self_with_default_entrypoint.tz-Unit-Unit-Unit].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[self_with_default_entrypoint.tz-Unit-Unit-Unit].out index 3e0a8c97f48339ce3d09cc65584c7b0bf780065a..ad21c5d7bdb2dd4596c14cff073be1f177083b25 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[self_with_default_entrypoint.tz-Unit-Unit-Unit].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[self_with_default_entrypoint.tz-Unit-Unit-Unit].out @@ -7,41 +7,41 @@ emitted operations big_map diff trace - - location: 13 (remaining gas: 1039982.600 units remaining) + - location: 13 (remaining gas: 1039982.800 units remaining) [ (Pair (Right (Left Unit)) Unit) ] - - location: 13 (remaining gas: 1039982.590 units remaining) + - location: 13 (remaining gas: 1039982.790 units remaining) [ ] - - location: 14 (remaining gas: 1039982.575 units remaining) + - location: 14 (remaining gas: 1039982.775 units remaining) [ "KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi" ] - - location: 15 (remaining gas: 1039982.565 units remaining) + - location: 15 (remaining gas: 1039982.765 units remaining) [ ] - - location: 16 (remaining gas: 1039982.550 units remaining) + - location: 16 (remaining gas: 1039982.750 units remaining) [ "KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi%A" ] - - location: 17 (remaining gas: 1039982.540 units remaining) + - location: 17 (remaining gas: 1039982.740 units remaining) [ ] - - location: 18 (remaining gas: 1039982.525 units remaining) + - location: 18 (remaining gas: 1039982.725 units remaining) [ "KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi" ] - - location: 19 (remaining gas: 1039971.572 units remaining) + - location: 19 (remaining gas: 1039971.772 units remaining) [ 0x050a00000016011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600 ] - - location: 20 (remaining gas: 1039971.557 units remaining) + - location: 20 (remaining gas: 1039971.757 units remaining) [ "KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi" 0x050a00000016011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600 ] - - location: 21 (remaining gas: 1039960.604 units remaining) + - location: 21 (remaining gas: 1039960.804 units remaining) [ 0x050a00000016011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600 0x050a00000016011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600 ] - - location: 24 (remaining gas: 1039960.569 units remaining) + - location: 24 (remaining gas: 1039960.769 units remaining) [ 0 ] - - location: 25 (remaining gas: 1039960.554 units remaining) + - location: 25 (remaining gas: 1039960.754 units remaining) [ True ] - - location: 26 (remaining gas: 1039960.544 units remaining) + - location: 26 (remaining gas: 1039960.744 units remaining) [ ] - - location: 26 (remaining gas: 1039960.529 units remaining) + - location: 26 (remaining gas: 1039960.729 units remaining) [ ] - - location: 32 (remaining gas: 1039960.519 units remaining) + - location: 32 (remaining gas: 1039960.719 units remaining) [ Unit ] - - location: 33 (remaining gas: 1039960.504 units remaining) + - location: 33 (remaining gas: 1039960.704 units remaining) [ {} Unit ] - - location: 35 (remaining gas: 1039960.489 units remaining) + - location: 35 (remaining gas: 1039960.689 units remaining) [ (Pair {} Unit) ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out index f0c9e2a43e3b496d37d65f4cd0bdc7892b94bae4..e9ae9c33a18da0a299b95352c42d5a07f19e8903 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_add_liquidity Node is bootstrapped. -Estimated gas: 11830.990 units (will add 100 for safety) +Estimated gas: 11830.290 units (will add 100 for safety) Estimated storage: 141 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -34,7 +34,7 @@ This sequence of operations was run: 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes Paid storage size diff: 3 bytes - Consumed gas: 5089.349 + Consumed gas: 5089.049 Balance updates: [CONTRACT_HASH] ... -ꜩ0.00075 storage fees ........................... +ꜩ0.00075 @@ -58,7 +58,7 @@ This sequence of operations was run: Set map(0)[0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600] to 721 Storage size: 2263 bytes Paid storage size diff: 68 bytes - Consumed gas: 4396.776 + Consumed gas: 4396.576 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 @@ -75,7 +75,7 @@ This sequence of operations was run: Set map(2)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 72007 Storage size: 2048 bytes Paid storage size diff: 70 bytes - Consumed gas: 2344.865 + Consumed gas: 2344.665 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0175 storage fees ........................... +ꜩ0.0175 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approval.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approval.out index e24b47a18766d86702bfc55217f4072451588e7b..859d237f03396446e170190238244418000ed056 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approval.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approval.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_approval Node is bootstrapped. -Estimated gas: 2377.468 units (will add 100 for safety) +Estimated gas: 2377.168 units (will add 100 for safety) Estimated storage: 68 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c)] to 1000 Storage size: 2116 bytes Paid storage size diff: 68 bytes - Consumed gas: 2377.468 + Consumed gas: 2377.168 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approved_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approved_transfer.out index 0c954d2bcd92a7d67175bc8cc372316c5d599584..43b37978175a81e3242e7ccc034f54ae48e6e634 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approved_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approved_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_approved_transfer Node is bootstrapped. -Estimated gas: 4368.520 units (will add 100 for safety) +Estimated gas: 4368.320 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -36,6 +36,6 @@ This sequence of operations was run: Set map(2)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 71007 Set map(2)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] to 1000 Storage size: 2116 bytes - Consumed gas: 4368.520 + Consumed gas: 4368.320 Injected block at minimal timestamp diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve1.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve1.out index 2de3ceaa0a7330abceb3d466dfc4d20030f1c040..aafc2045db4345bf901d784f7765f5af5bd25a69 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve1.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve1.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_call_approve1 Node is bootstrapped. -Estimated gas: 2377.544 units (will add 100 for safety) +Estimated gas: 2377.244 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2053 bytes Paid storage size diff: 71 bytes - Consumed gas: 2377.544 + Consumed gas: 2377.244 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve2.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve2.out index a642cb254c37b5c54dd199a1f2209688c6b9e4b4..c697c412973e801b4abd57e56e7c1dac6b8ff3c9 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve2.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve2.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_call_approve2 Node is bootstrapped. -Estimated gas: 2377.544 units (will add 100 for safety) +Estimated gas: 2377.244 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2124 bytes Paid storage size diff: 71 bytes - Consumed gas: 2377.544 + Consumed gas: 2377.244 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve3.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve3.out index dbedcb7a3a55d9054bf16cf568cf4cd96afde3a5..7cfa8f6be507c82f93ec7972b835633d747fa1ce 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve3.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve3.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_call_approve3 Node is bootstrapped. -Estimated gas: 2377.544 units (will add 100 for safety) +Estimated gas: 2377.244 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2195 bytes Paid storage size diff: 71 bytes - Consumed gas: 2377.544 + Consumed gas: 2377.244 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_mint_or_burn.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_mint_or_burn.out index 565a58c688ee6ee9892a15f69666e7d76a9f1bc7..1fc2cd7e5b86a6d4802435f424f8c91a7be8722c 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_mint_or_burn.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_mint_or_burn.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_call_mint_or_burn Node is bootstrapped. -Estimated gas: 4518.822 units (will add 100 for safety) +Estimated gas: 4518.622 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -32,7 +32,7 @@ This sequence of operations was run: Set map(0)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 100000000 Storage size: 1982 bytes Paid storage size diff: 71 bytes - Consumed gas: 4519.506 + Consumed gas: 4519.306 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out index 395c54d7140a4fee9642c7e14ea79e1e3f3264df..ed478c3e5efa9c39f7caf2b52e4cb15e9354e9bd 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_remove_liquidity Node is bootstrapped. -Estimated gas: 10542.446 units (will add 100 for safety) +Estimated gas: 10541.746 units (will add 100 for safety) Estimated storage: 67 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.001417 Expected counter: [EXPECTED_COUNTER] - Gas limit: 10643 + Gas limit: 10642 Storage limit: 87 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.001417 @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01e927f00ef734dfc85919635e9afc9166c83ef9fc00 ; 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes - Consumed gas: 2917.976 + Consumed gas: 2917.676 Internal operations: Transaction: Amount: ꜩ0 @@ -47,7 +47,7 @@ This sequence of operations was run: Updated big_maps: Unset map(2)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] Storage size: 2048 bytes - Consumed gas: 2524.939 + Consumed gas: 2524.739 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -63,7 +63,7 @@ This sequence of operations was run: Set map(0)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] to 10 Storage size: 2330 bytes Paid storage size diff: 67 bytes - Consumed gas: 3679.531 + Consumed gas: 3679.331 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01675 storage fees ........................... +ꜩ0.01675 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out index f630fc2be196dc8f9ad24466cf32f80bbc283038..c0262d3a125e5ee1addd19f151fe6c919eaa702e 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_add_liquidity Node is bootstrapped. -Estimated gas: 11830.990 units (will add 100 for safety) +Estimated gas: 11830.290 units (will add 100 for safety) Estimated storage: 141 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -34,7 +34,7 @@ This sequence of operations was run: 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes Paid storage size diff: 3 bytes - Consumed gas: 5089.349 + Consumed gas: 5089.049 Balance updates: [CONTRACT_HASH] ... -ꜩ0.00075 storage fees ........................... +ꜩ0.00075 @@ -58,7 +58,7 @@ This sequence of operations was run: Set map(0)[0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600] to 721 Storage size: 2263 bytes Paid storage size diff: 68 bytes - Consumed gas: 4396.776 + Consumed gas: 4396.576 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 @@ -75,7 +75,7 @@ This sequence of operations was run: Set map(2)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 72007 Storage size: 2048 bytes Paid storage size diff: 70 bytes - Consumed gas: 2344.865 + Consumed gas: 2344.665 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0175 storage fees ........................... +ꜩ0.0175 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out index 47944510c68684022d6b3f549cf4236551e8ed01..6bc37f131318a4cc959899a3ac57f25ddc5ca04d 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_buy_tok Node is bootstrapped. -Estimated gas: 7505.368 units (will add 100 for safety) +Estimated gas: 7504.968 units (will add 100 for safety) Estimated storage: 326 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.001108 Expected counter: [EXPECTED_COUNTER] - Gas limit: 7606 + Gas limit: 7605 Storage limit: 346 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.001108 @@ -34,7 +34,7 @@ This sequence of operations was run: 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4634 bytes Paid storage size diff: 1 bytes - Consumed gas: 2405.833 + Consumed gas: 2405.633 Balance updates: [CONTRACT_HASH] ... -ꜩ0.00025 storage fees ........................... +ꜩ0.00025 @@ -56,7 +56,7 @@ This sequence of operations was run: Set map(0)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] to 360 Storage size: 2331 bytes Paid storage size diff: 68 bytes - Consumed gas: 3679.535 + Consumed gas: 3679.335 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve1.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve1.out index 1006debacc4e7c3b883ccd87f3055ef1bf2c8ae7..5aeb323a1116504391b7771564f14550d78deea3 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve1.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve1.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_call_approve1 Node is bootstrapped. -Estimated gas: 2377.544 units (will add 100 for safety) +Estimated gas: 2377.244 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2053 bytes Paid storage size diff: 71 bytes - Consumed gas: 2377.544 + Consumed gas: 2377.244 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve2.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve2.out index a2309d6cfb171cc85bf552eae7d199daebc7b928..d63593dabe5a5f298b4d1544c1f7253026a2e2c0 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve2.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve2.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_call_approve2 Node is bootstrapped. -Estimated gas: 2377.544 units (will add 100 for safety) +Estimated gas: 2377.244 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2124 bytes Paid storage size diff: 71 bytes - Consumed gas: 2377.544 + Consumed gas: 2377.244 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve3.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve3.out index 87720f944c7c1484a5ed81df41d225f80dd28682..6e34c7523d6947f656cb55a7617237a874e8e296 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve3.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve3.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_call_approve3 Node is bootstrapped. -Estimated gas: 2377.544 units (will add 100 for safety) +Estimated gas: 2377.244 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2195 bytes Paid storage size diff: 71 bytes - Consumed gas: 2377.544 + Consumed gas: 2377.244 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_mint_or_burn.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_mint_or_burn.out index 31fa8112fb713973cc502fc0d5fa826ab110c943..e8c3e919cd29305d58a5483159fbdb7fec4809f7 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_mint_or_burn.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_mint_or_burn.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_call_mint_or_burn Node is bootstrapped. -Estimated gas: 4518.822 units (will add 100 for safety) +Estimated gas: 4518.622 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -32,7 +32,7 @@ This sequence of operations was run: Set map(0)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 100000000 Storage size: 1982 bytes Paid storage size diff: 71 bytes - Consumed gas: 4519.506 + Consumed gas: 4519.306 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out index fd868f48f8a5b01a30424230d9b810132d09aa35..8aa45e2468de512f1a89035d09690a4d9d2db8a3 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_sell_tok Node is bootstrapped. -Estimated gas: 9823.764 units (will add 100 for safety) +Estimated gas: 9823.364 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01e927f00ef734dfc85919635e9afc9166c83ef9fc00 ; 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes - Consumed gas: 2406.952 + Consumed gas: 2406.752 Internal operations: Transaction: Amount: ꜩ0 @@ -51,7 +51,7 @@ This sequence of operations was run: Unset map(0)[0x0000dac9f52543da1aed0bc1d6b46bf7c10db7014cd6] Set map(0)[0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600] to 461 Storage size: 2331 bytes - Consumed gas: 4576.812 + Consumed gas: 4576.612 Transaction: Amount: ꜩ3891.966034 From: [CONTRACT_HASH] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_transfer.out index cce867ef6dc04d390d88a1b53ba61f2aa2b4d687..18a5cec83b7e70feefa8751356b63c366e18dfa1 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_transfer Node is bootstrapped. -Estimated gas: 3681.435 units (will add 100 for safety) +Estimated gas: 3681.235 units (will add 100 for safety) Estimated storage: 68 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -35,7 +35,7 @@ This sequence of operations was run: Set map(0)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] to 260 Storage size: 2399 bytes Paid storage size diff: 68 bytes - Consumed gas: 3681.435 + Consumed gas: 3681.235 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 diff --git a/tezt/_regressions/encoding/alpha.operation.internal.out b/tezt/_regressions/encoding/alpha.operation.internal.out index b327bf07706d751ef5225b5d258fc261820c6d97..857939586d515d34eaa0877e0a019be8f8375b77 100644 --- a/tezt/_regressions/encoding/alpha.operation.internal.out +++ b/tezt/_regressions/encoding/alpha.operation.internal.out @@ -103,19 +103,6 @@ tezt/_regressions/encoding/alpha.operation.internal.out { "prim": "PAIR" } ] ] } ], "storage": [ { "string": "test" } ] } } -./tezos-codec encode alpha.operation.internal from '{ - "source": "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx", - "nonce": 0, - "kind": "reveal", - "public_key": "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" -}' -000002298c03ed7d454a101eb7022bc95f7e5f41ac78000000004798d2cc98473d7e250c898885718afd2e4efbcb1a1595ab9730761ed830de0f - -./tezos-codec decode alpha.operation.internal from 000002298c03ed7d454a101eb7022bc95f7e5f41ac78000000004798d2cc98473d7e250c898885718afd2e4efbcb1a1595ab9730761ed830de0f -{ "source": "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx", "nonce": 0, - "kind": "reveal", - "public_key": "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" } - ./tezos-codec encode alpha.operation.internal from '{ "source": "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx", "nonce": 3, diff --git a/tezt/tests/encoding_samples/alpha/operation.internal/operation.internal-reveal.sample.json b/tezt/tests/encoding_samples/alpha/operation.internal/operation.internal-reveal.sample.json deleted file mode 100644 index af4f48ec57541738b51772a3216aaa74c769bae0..0000000000000000000000000000000000000000 --- a/tezt/tests/encoding_samples/alpha/operation.internal/operation.internal-reveal.sample.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "source": "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx", - "nonce": 0, - "kind": "reveal", - "public_key": "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" -}