From 4053718aafeffe93d0e13d9573d80ad98b4f34fb Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Fri, 4 Mar 2022 14:02:25 +0100 Subject: [PATCH 01/12] Proto/Michelson: internal execute returns the execution_result. We'll share this internal function with yet another function (execute with typed parameters). --- .../lib_protocol/script_interpreter.ml | 52 +++++++------------ 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 8ccf59eaed14..1d5d97f4d11b 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1704,17 +1704,17 @@ let step logger ctxt step_constants descr stack = ==================== *) +type execution_result = { + ctxt : context; + storage : Script.expr; + lazy_storage_diff : Lazy_storage.diffs option; + operations : packed_internal_operation list; + ticket_diffs : Z.t Ticket_token_map.t; +} + let execute logger ctxt mode step_constants ~entrypoint ~internal unparsed_script cached_script arg : - (Script.expr - * packed_internal_operation list - * context - * Lazy_storage.diffs option - * ex_script - * int - * Z.t Ticket_token_map.t) - tzresult - Lwt.t = + (execution_result * (ex_script * int)) tzresult Lwt.t = (match cached_script with | None -> parse_script @@ -1772,7 +1772,7 @@ let execute logger ctxt mode step_constants ~entrypoint ~internal ) >>=? fun (unparsed_storage, ctxt) -> let op_to_couple op = (op.piop, op.lazy_storage_diff) in - let (op_elems, op_diffs) = + let (operations, op_diffs) = ops.elements |> List.map op_to_couple |> List.split in let lazy_storage_diff_all = @@ -1808,21 +1808,14 @@ let execute logger ctxt mode step_constants ~entrypoint ~internal let (size, cost) = Script_ir_translator.script_size script in Gas.consume ctxt cost >>?= fun ctxt -> return - ( unparsed_storage, - op_elems, - ctxt, - lazy_storage_diff_all, - script, - size, - ticket_diffs ) - -type execution_result = { - ctxt : context; - storage : Script.expr; - lazy_storage_diff : Lazy_storage.diffs option; - operations : packed_internal_operation list; - ticket_diffs : Z.t Ticket_token_map.t; -} + ( { + ctxt; + storage = unparsed_storage; + lazy_storage_diff = lazy_storage_diff_all; + operations; + ticket_diffs; + }, + (script, size) ) let execute ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint ~parameter ~internal = @@ -1836,15 +1829,6 @@ let execute ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint script cached_script (Micheline.root parameter) - >|=? fun ( storage, - operations, - ctxt, - lazy_storage_diff, - ex_script, - approx_size, - ticket_diffs ) -> - ( {ctxt; storage; lazy_storage_diff; operations; ticket_diffs}, - (ex_script, approx_size) ) (* -- GitLab From 78f0bdc3f96a95669b416920d22a6eb9929918bd Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Fri, 4 Mar 2022 14:10:42 +0100 Subject: [PATCH 02/12] Proto/Michelson: enrich internal execute's parameter. So that the function accepts both a typed or an untyped version of the parameter. This allows not having to re-parse the parameter if it was already parsed. Does not compile. --- .../lib_protocol/script_interpreter.ml | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 1d5d97f4d11b..b262fc60f0d2 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1704,6 +1704,10 @@ let step logger ctxt step_constants descr stack = ==================== *) +type execution_arg = + | Typed_arg : 'a Script_typed_ir.ty * 'a -> execution_arg + | Untyped_arg : Script.expr -> execution_arg + type execution_result = { ctxt : context; storage : Script.expr; @@ -1712,9 +1716,8 @@ type execution_result = { ticket_diffs : Z.t Ticket_token_map.t; } -let execute logger ctxt mode step_constants ~entrypoint ~internal - unparsed_script cached_script arg : - (execution_result * (ex_script * int)) tzresult Lwt.t = +let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal + unparsed_script cached_script arg = (match cached_script with | None -> parse_script @@ -1740,11 +1743,24 @@ let execute logger ctxt mode step_constants ~entrypoint ~internal >>?= fun (r, ctxt) -> record_trace (Bad_contract_parameter step_constants.self) r >>?= fun (Ex_ty_cstr (entrypoint_ty, box)) -> - trace - (Bad_contract_parameter step_constants.self) - (parse_data ctxt ~legacy:false ~allow_forged:internal entrypoint_ty arg) + (match arg with + | Untyped_arg arg -> + let arg = Micheline.root arg in + trace + (Bad_contract_parameter step_constants.self) + (parse_data ctxt ~legacy:false ~allow_forged:internal entrypoint_ty arg) + >>=? fun (parsed_arg, ctxt) -> return (box parsed_arg, ctxt) + | Typed_arg (parsed_arg_ty, parsed_arg) -> + Gas_monad.run + ctxt + (Script_ir_translator.ty_eq + ~error_details:Informative + Micheline.dummy_location + entrypoint_ty + parsed_arg_ty) + >>?= fun (res, ctxt) -> + res >>?= fun Eq -> return (box parsed_arg, ctxt)) >>=? 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 @@ -1819,7 +1835,7 @@ let execute logger ctxt mode step_constants ~entrypoint ~internal let execute ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint ~parameter ~internal = - execute + execute_any_arg logger ctxt mode @@ -1828,7 +1844,7 @@ let execute ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint ~internal script cached_script - (Micheline.root parameter) + (Untyped_arg parameter) (* -- GitLab From a3ee222048538767e8cee476ff165dc9e38087ee Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Fri, 4 Mar 2022 14:22:15 +0100 Subject: [PATCH 03/12] Proto/Michelson: execute with a typed parameter. --- .../lib_protocol/script_interpreter.ml | 13 +++++++++++++ .../lib_protocol/script_interpreter.mli | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index b262fc60f0d2..909da6b8fc08 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1833,6 +1833,19 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal }, (script, size) ) +let execute_with_typed_parameter ?logger ctxt ~cached_script mode step_constants + ~script ~entrypoint ~parameter_ty ~parameter ~internal = + execute_any_arg + logger + ctxt + mode + step_constants + ~entrypoint + ~internal + script + cached_script + (Typed_arg (parameter_ty, parameter)) + let execute ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint ~parameter ~internal = execute_any_arg diff --git a/src/proto_alpha/lib_protocol/script_interpreter.mli b/src/proto_alpha/lib_protocol/script_interpreter.mli index 36403a194732..d535db77bff3 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.mli +++ b/src/proto_alpha/lib_protocol/script_interpreter.mli @@ -111,6 +111,25 @@ val execute : internal:bool -> (execution_result * (Script_ir_translator.ex_script * int)) tzresult Lwt.t +(** [execute_with_typed_parameter ?logger ctxt ~cached_script mode + step_constant ~script ~entrypoint loc ~parameter_ty ~parameter ~internal] + interprets the [script]'s [entrypoint] for a given (typed) [parameter]. + + See {!execute} for more details about the function's arguments. +*) +val execute_with_typed_parameter : + ?logger:logger -> + Alpha_context.context -> + cached_script:Script_ir_translator.ex_script option -> + Script_ir_translator.unparsing_mode -> + step_constants -> + script:Script.t -> + entrypoint:Entrypoint.t -> + parameter_ty:'a Script_typed_ir.ty -> + parameter:'a -> + internal:bool -> + (execution_result * (Script_ir_translator.ex_script * int)) tzresult Lwt.t + (** [kstep logger ctxt step_constants kinstr accu stack] interprets the script represented by [kinstr] under the context [ctxt]. This will turn a stack whose topmost element is [accu] and remaining elements -- GitLab From ba4000860910dc801103aae676c13ab4cd327f85 Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Fri, 4 Mar 2022 15:10:09 +0100 Subject: [PATCH 04/12] Proto/Michelson: enrich the transaction application with a typed parameter. Does not compile. --- src/proto_alpha/lib_protocol/apply.ml | 76 +++++++++++++++++++-------- 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 15a84149bcf2..8405ccb8719b 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -876,16 +876,28 @@ let apply_delegation ~ctxt ~source ~delegate ~since = Delegate.set ctxt source delegate >|=? fun ctxt -> (ctxt, Delegation_result {consumed_gas = Gas.consumed ~since ~until:ctxt}, []) +type execution_arg = + | Typed_arg : 'a Script_typed_ir.ty * 'a -> execution_arg + | Untyped_arg : Script.expr -> execution_arg + let apply_transaction_to_implicit ~ctxt ~contract ~parameter ~entrypoint ~before_operation ~balance_updates ~allocated_destination_contract = + let is_unit = + match parameter with + | Typed_arg (Unit_t, ()) -> true + | Typed_arg _ -> false + | Untyped_arg parameter -> ( + match Micheline.root parameter with + | Prim (_, Michelson_v1_primitives.D_Unit, [], _) -> true + | _ -> false) + in ( (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) ) + if is_unit then + (* Only allow [Unit] parameter to implicit accounts. *) + ok ctxt + else error (Script_interpreter.Bad_contract_parameter contract) ) >|? fun ctxt -> let result = Transaction_result @@ -928,15 +940,28 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount level; } in - Script_interpreter.execute - ctxt - ~cached_script:(Some script_ir) - mode - step_constants - ~script - ~parameter - ~entrypoint - ~internal + (match parameter with + | Untyped_arg parameter -> + Script_interpreter.execute + ctxt + ~cached_script:(Some script_ir) + mode + step_constants + ~script + ~parameter + ~entrypoint + ~internal + | Typed_arg (parameter_ty, parameter) -> + Script_interpreter.execute_with_typed_parameter + ctxt + ~cached_script:(Some script_ir) + mode + step_constants + ~script + ~parameter_ty + ~parameter + ~entrypoint + ~internal) >>=? fun ( {ctxt; storage; lazy_storage_diff; operations; ticket_diffs}, (updated_cached_script, updated_size) ) -> update_script_storage_and_ticket_balances @@ -974,11 +999,8 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount 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) -> +let apply_transaction ~ctxt ~parameter ~source ~contract ~amount ~entrypoint + ~before_operation ~payer ~chain_id ~mode ~internal = (match Contract.is_implicit contract with | None -> (if Tez.(amount = zero) then @@ -1235,10 +1257,14 @@ let apply_internal_manager_operation_content : match operation with | Transaction {amount; parameters; destination = Contract contract; entrypoint} -> - apply_transaction + Script.force_decode_in_context ~consume_deserialization_gas + ctxt + parameters + >>?= fun (parameters, ctxt) -> + apply_transaction ~ctxt - ~parameters + ~parameter:(Untyped_arg parameters) ~source ~contract ~amount @@ -1315,10 +1341,14 @@ let apply_external_manager_operation_content : [] ) | Transaction {amount; parameters; destination = Contract contract; entrypoint} -> - apply_transaction + Script.force_decode_in_context ~consume_deserialization_gas + ctxt + parameters + >>?= fun (parameters, ctxt) -> + apply_transaction ~ctxt - ~parameters + ~parameter:(Untyped_arg parameters) ~source ~contract ~amount -- GitLab From 4f0de7cc4af75274e7dc5513be3d4eaf22366ecb Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Fri, 4 Mar 2022 15:52:26 +0100 Subject: [PATCH 05/12] Proto/Michelson: enrich the transaction internal operation. With the typed parameter of the transaction. Does not compile (tests to adapt). --- src/proto_alpha/lib_plugin/plugin.ml | 5 +- src/proto_alpha/lib_protocol/apply.ml | 70 +++++++++++-------- src/proto_alpha/lib_protocol/apply_results.ml | 2 +- .../lib_protocol/script_interpreter_defs.ml | 39 ++++++----- .../lib_protocol/script_typed_ir.ml | 7 +- .../lib_protocol/script_typed_ir.mli | 12 +++- .../lib_protocol/ticket_operations_diff.ml | 14 ++-- 7 files changed, 91 insertions(+), 58 deletions(-) diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index c97734653748..89ab27564a7a 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1465,7 +1465,10 @@ module View_helpers = struct match operations with | [ Script_typed_ir.Internal_operation - {operation = Transaction {destination; parameters; _}; _}; + { + operation = Transaction {transaction = {destination; parameters; _}; _}; + _; + }; ] when Destination.equal destination (Contract callback) -> ok parameters diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 8405ccb8719b..4048f05b5ae3 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1256,15 +1256,15 @@ let apply_internal_manager_operation_content : >>=? fun (ctxt, before_operation, consume_deserialization_gas) -> match operation with | Transaction - {amount; parameters; destination = Contract contract; entrypoint} -> - Script.force_decode_in_context - ~consume_deserialization_gas - ctxt - parameters - >>?= fun (parameters, ctxt) -> + { + transaction = + {amount; parameters = _; destination = Contract contract; entrypoint}; + parameters_ty; + parameters = typed_parameters; + } -> apply_transaction ~ctxt - ~parameter:(Untyped_arg parameters) + ~parameter:(Typed_arg (parameters_ty, typed_parameters)) ~source ~contract ~amount @@ -1278,7 +1278,13 @@ let apply_internal_manager_operation_content : ( ctxt, (manager_result : kind successful_manager_operation_result), operations ) - | Transaction {amount; parameters; destination = Tx_rollup dst; entrypoint} -> + | Transaction + { + transaction = + {amount; parameters; destination = Tx_rollup dst; entrypoint}; + parameters_ty = _; + parameters = _; + } -> apply_transaction_to_rollup ~consume_deserialization_gas ~ctxt @@ -1435,25 +1441,26 @@ let apply_external_manager_operation_content : this ticket is owns by the tx_rollup *) (* Now reconstruct the ticket sent as the parameter destination. *) - ( Script_ir_translator.parse_comparable_ty ctxt (Micheline.root ty) + Script_ir_translator.parse_comparable_ty ctxt (Micheline.root ty) >>?= fun (Ex_comparable_ty ty, ctxt) -> - Script_ir_translator.parse_comparable_data - ctxt - ty - (Micheline.root contents) - >>=? fun (contents, ctxt) -> - let amount = - Option.value - ~default:Script_int.zero_n - Script_int.(is_nat @@ of_int64 @@ Tx_rollup_l2_qty.to_int64 amount) - in - let ticket = Script_typed_ir.{ticketer; contents; amount} in - Script_typed_ir.ticket_t Micheline.dummy_location ty >>?= fun ty -> - return (ticket, ty, ctxt) >>=? fun (ticket, ticket_ty, ctxt) -> - Script_ir_translator.unparse_data ctxt Optimized ticket_ty ticket - >|=? fun (parameters, ctxt) -> - (Script.lazy_expr (Micheline.strip_locations parameters), ctxt) ) + Script_ir_translator.parse_comparable_data + ctxt + ty + (Micheline.root contents) + >>=? fun (contents, ctxt) -> + let amount = + Option.value + ~default:Script_int.zero_n + Script_int.(is_nat @@ of_int64 @@ Tx_rollup_l2_qty.to_int64 amount) + in + let ticket = Script_typed_ir.{ticketer; contents; amount} in + Script_typed_ir.ticket_t Micheline.dummy_location ty >>?= fun ty -> + return (ticket, ty, ctxt) >>=? fun (ticket, ticket_ty, ctxt) -> + Script_ir_translator.unparse_data ctxt Optimized ticket_ty ticket >>=? fun (parameters, ctxt) -> + let parameters = + Script.lazy_expr (Micheline.strip_locations parameters) + in (* FIXME/TORU: #2488 the returned op will fail when ticket hardening is merged, it must be commented or fixed *) let op = @@ -1465,10 +1472,15 @@ let apply_external_manager_operation_content : operation = Transaction { - amount = Tez.zero; - parameters; - destination = Contract destination; - entrypoint; + transaction = + { + amount = Tez.zero; + parameters; + destination = Contract destination; + entrypoint; + }; + parameters_ty = ticket_ty; + parameters = ticket; }; } in diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index fa162275d20a..68b4aafcdada 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -80,7 +80,7 @@ let contents_of_internal_operation (type kind) kind internal_contents = let operation : kind internal_manager_operation = match operation with - | Transaction transaction -> Transaction transaction + | Transaction {transaction; _} -> Transaction transaction | Origination origination -> Origination origination | Delegation delegate -> Delegation delegate in diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index bbd7c5a8a457..e9f2e0c1a4b3 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -500,11 +500,12 @@ let apply ctxt gas capture_ty capture lam = let (gas, ctxt) = local_gas_counter_and_outdated_context ctxt in return (lam', ctxt, gas) -(* [transfer (ctxt, sc) gas tez tp p destination entrypoint] +(* [transfer (ctxt, sc) gas tez parameters_ty parameters destination entrypoint] creates an operation that transfers an amount of [tez] to a contract determined by [(destination, entrypoint)] - instantiated with argument [p] of type [tp]. *) -let transfer (ctxt, sc) gas amount tp p destination entrypoint = + instantiated with argument [parameters] of type [parameters_ty]. *) +let transfer (ctxt, sc) gas amount parameters_ty parameters destination + entrypoint = (* [craft_transfer_parameters ctxt tp p] reorganizes, if need be, the parameters submitted by the interpreter to prepare them for the [Transaction] operation. *) @@ -548,29 +549,31 @@ let transfer (ctxt, sc) gas amount tp p destination entrypoint = in let ctxt = update_context gas ctxt in - collect_lazy_storage ctxt tp p >>?= fun (to_duplicate, ctxt) -> + collect_lazy_storage ctxt parameters_ty parameters + >>?= fun (to_duplicate, ctxt) -> let to_update = no_lazy_storage_id in extract_lazy_storage_diff ctxt Optimized - tp - p + parameters_ty + parameters ~to_duplicate ~to_update ~temporary:true - >>=? fun (p, lazy_storage_diff, ctxt) -> - unparse_data ctxt Optimized tp p >>=? fun (p, ctxt) -> - Gas.consume ctxt (Script.strip_locations_cost p) >>?= fun ctxt -> - craft_transfer_parameters ctxt tp p destination >>?= fun (p, ctxt) -> - let operation = - Transaction - { - amount; - destination; - entrypoint; - parameters = Script.lazy_expr (Micheline.strip_locations p); - } + >>=? fun (parameters, lazy_storage_diff, ctxt) -> + unparse_data ctxt Optimized parameters_ty parameters + >>=? fun (unparsed_parameters, ctxt) -> + Gas.consume ctxt (Script.strip_locations_cost unparsed_parameters) + >>?= fun ctxt -> + craft_transfer_parameters ctxt parameters_ty unparsed_parameters destination + >>?= fun (unparsed_parameters, ctxt) -> + let transaction = + let parameters = + Script.lazy_expr (Micheline.strip_locations unparsed_parameters) + in + {amount; destination; entrypoint; parameters} in + let operation = Transaction {transaction; parameters_ty; parameters} in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> let iop = {source = sc.self; operation; nonce} in let res = {piop = Internal_operation iop; lazy_storage_diff} in diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 98c5c1849ffc..1b4655d5ba53 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -1349,8 +1349,11 @@ and ('input, 'output) view_signature = -> ('input, 'output) view_signature and 'kind manager_operation = - | Transaction : - Alpha_context.transaction + | Transaction : { + transaction : Alpha_context.transaction; + parameters_ty : 'a ty; + parameters : 'a; + } -> Kind.transaction manager_operation | Origination : Alpha_context.origination diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index 05a9e889c05d..c75b9f4fe68a 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -1487,8 +1487,16 @@ and ('input, 'output) view_signature = -> ('input, 'output) view_signature and 'kind manager_operation = - | Transaction : - Alpha_context.transaction + | Transaction : { + (* The [transaction.parameters] field may seem useless since we have + access to a typed version of the field (with [parameters_ty] and + [parameters]), but we keep it so that we do not have to unparse the + typed version in order to produce the receipt + ([Apply_results.internal_manager_operation]). *) + transaction : Alpha_context.transaction; + parameters_ty : 'a ty; + parameters : 'a; + } -> Kind.transaction manager_operation | Origination : Alpha_context.origination diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 061acd015468..259fc484df74 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -247,13 +247,17 @@ let tickets_of_operation ctxt match operation with | Transaction { - amount = _; - parameters; - entrypoint; - destination = Destination.Contract destination; + transaction = + { + amount = _; + parameters; + entrypoint; + destination = Destination.Contract destination; + }; + _; } -> tickets_of_transaction ctxt ~destination ~parameters ~entrypoint - | Transaction {destination = Destination.Tx_rollup _; _} -> + | Transaction {transaction = {destination = Destination.Tx_rollup _; _}; _} -> (* TODO: #2488 The ticket accounting for the recipient of rollup transactions is currently done in the apply function, but should rather be -- GitLab From c30d7549675cad32c09b1296a16245817a6856d0 Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Fri, 4 Mar 2022 16:13:00 +0100 Subject: [PATCH 06/12] Proto/Tests: typed parameters in transactions. --- .../michelson/test_ticket_accounting.ml | 15 +- .../michelson/test_ticket_operations_diff.ml | 210 +++++++++++------- 2 files changed, 134 insertions(+), 91 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml index a6076037f8eb..a4cd8fb67821 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml @@ -372,11 +372,16 @@ let transfer_operation ctxt ~src ~destination ~arg_type ~arg = operation = Transaction { - amount = Tez.zero; - parameters = - Script.lazy_expr @@ Micheline.strip_locations params_node; - entrypoint = Entrypoint.default; - destination = Destination.Contract destination; + transaction = + { + amount = Tez.zero; + parameters = + Script.lazy_expr @@ Micheline.strip_locations params_node; + entrypoint = Entrypoint.default; + destination = Destination.Contract destination; + }; + parameters_ty = arg_type; + parameters = arg; }; nonce = 1; }, diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml index e5745ccabeca..dd01e8ef7b09 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml @@ -34,6 +34,7 @@ open Protocol open Alpha_context +open Script_typed_ir (** A local non-private type that mirrors [Ticket_operations_diff.ticket_token_diff]. *) @@ -259,20 +260,39 @@ let originate block ~src ~baker ~script ~storage ~forges_tickets = in return (orig_contract, incr) -let transfer_operation ~src ~destination ~parameters = - Script_typed_ir.Internal_operation - { - source = src; - operation = - Transaction - { - amount = Tez.zero; - parameters = Script.lazy_expr @@ Expr.from_string parameters; - entrypoint = Entrypoint.default; - destination = Destination.Contract destination; - }; - nonce = 1; - } +let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = + let open Lwt_tzresult_syntax in + let ctxt = Incremental.alpha_ctxt incr in + let* (params_node, ctxt) = + wrap + (Script_ir_translator.unparse_data + ctxt + Script_ir_translator.Readable + parameters_ty + parameters) + in + let incr = Incremental.set_alpha_ctxt incr ctxt in + return + ( Script_typed_ir.Internal_operation + { + source = src; + operation = + Transaction + { + transaction = + { + amount = Tez.zero; + parameters = + Script.lazy_expr @@ Micheline.strip_locations params_node; + entrypoint = Entrypoint.default; + destination = Destination.Contract destination; + }; + parameters_ty; + parameters; + }; + nonce = 1; + }, + incr ) let ticket_diffs_of_operations incr operations = wrap @@ -301,6 +321,24 @@ let ticket_big_map_script = code { CAR; NIL operation ; PAIR } } |} +let list_ticket_string_ty = + ticket_t Micheline.dummy_location string_key >>? fun ticket_ty -> + list_t Micheline.dummy_location ticket_ty + +let make_ticket (ticketer, contents, amount) = + Script_string.of_string contents >>?= fun contents -> + return {ticketer; contents; amount = nat amount} + +let make_tickets ts = + let* elements = List.map_es make_ticket ts in + return {elements; length = List.length elements} + +let transfer_tickets_operation ~incr ~src ~destination tickets = + let open Lwt_tzresult_syntax in + let*? parameters_ty = Environment.wrap_tzresult list_ticket_string_ty in + let* parameters = wrap @@ make_tickets tickets in + transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters + (** Test that no tickets are returned for operations that do not contain tickets. *) let test_non_ticket_operations () = @@ -322,8 +360,13 @@ let test_transfer_to_non_ticket_contract () = ~storage:"Unit" ~forges_tickets:false in - let operation = - transfer_operation ~src ~destination:orig_contract ~parameters:"Unit" + let* (operation, incr) = + transfer_operation + ~incr + ~src + ~destination:orig_contract + ~parameters_ty:unit_t + ~parameters:() in let* (ticket_diffs, ctxt) = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ ticket_diffs ~expected:[] @@ -340,8 +383,8 @@ let test_transfer_empty_ticket_list () = ~storage:"{}" ~forges_tickets:false in - let operation = - transfer_operation ~src ~destination:orig_contract ~parameters:"{}" + let* (operation, incr) = + transfer_tickets_operation ~incr ~src ~destination:orig_contract [] in let* (ticket_diffs, ctxt) = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ ticket_diffs ~expected:[] @@ -359,11 +402,12 @@ let test_transfer_one_ticket () = ~storage:"{}" ~forges_tickets:false in - let parameters = - Printf.sprintf {|{Pair %S "white" 1}|} (Contract.to_b58check ticketer) - in - let operation = - transfer_operation ~src ~destination:orig_contract ~parameters + let* (operation, incr) = + transfer_tickets_operation + ~incr + ~src + ~destination:orig_contract + [(ticketer, "white", 1)] in let* (ticket_diffs, ctxt) = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs @@ -392,22 +436,17 @@ let test_transfer_multiple_tickets () = ~storage:"{}" ~forges_tickets:false in - let operation = - let parameters = - let ticketer_addr = Contract.to_b58check ticketer in - Printf.sprintf - {|{ - Pair %S "red" 1; - Pair %S "blue" 2 ; - Pair %S "green" 3; - Pair %S "red" 4;} - |} - ticketer_addr - ticketer_addr - ticketer_addr - ticketer_addr - in - transfer_operation ~src ~destination:orig_contract ~parameters + let* (operation, incr) = + transfer_tickets_operation + ~incr + ~src + ~destination:orig_contract + [ + (ticketer, "red", 1); + (ticketer, "blue", 2); + (ticketer, "green", 3); + (ticketer, "red", 4); + ] in let* (ticket_diffs, ctxt) = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs @@ -437,31 +476,6 @@ let test_transfer_multiple_tickets () = let test_transfer_different_tickets () = let* (baker, src, block) = init () in let* (ticketer1, ticketer2) = two_ticketers block in - let parameters = - let ticketer1_addr = Contract.to_b58check ticketer1 in - let ticketer2_addr = Contract.to_b58check ticketer2 in - Printf.sprintf - {|{ - Pair %S "red" 1; - Pair %S "green" 1; - Pair %S "blue" 1; - Pair %S "red" 1; - Pair %S "green" 1; - Pair %S "blue" 1 ; - Pair %S "red" 1; - Pair %S "green" 1; - Pair %S "blue" 1; } - |} - ticketer1_addr - ticketer1_addr - ticketer1_addr - ticketer2_addr - ticketer2_addr - ticketer2_addr - ticketer1_addr - ticketer1_addr - ticketer1_addr - in let* (destination, incr) = originate block @@ -471,7 +485,23 @@ let test_transfer_different_tickets () = ~storage:"{}" ~forges_tickets:false in - let operation = transfer_operation ~src ~destination ~parameters in + let* (operation, incr) = + transfer_tickets_operation + ~incr + ~src + ~destination + [ + (ticketer1, "red", 1); + (ticketer1, "green", 1); + (ticketer1, "blue", 1); + (ticketer2, "red", 1); + (ticketer2, "green", 1); + (ticketer2, "blue", 1); + (ticketer1, "red", 1); + (ticketer1, "green", 1); + (ticketer1, "blue", 1); + ] + in let* (ticket_diffs, ctxt) = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt @@ -516,12 +546,7 @@ let test_transfer_to_two_contracts_with_different_tickets () = let* (baker, src, block) = init () in let* ticketer = one_ticketer block in let parameters = - let ticketer_addr = Contract.to_b58check ticketer in - Printf.sprintf - {|{Pair %S "red" 1; Pair %S "green" 1; Pair %S "blue" 1; }|} - ticketer_addr - ticketer_addr - ticketer_addr + [(ticketer, "red", 1); (ticketer, "green", 1); (ticketer, "blue", 1)] in let* (destination1, incr) = originate @@ -532,8 +557,8 @@ let test_transfer_to_two_contracts_with_different_tickets () = ~storage:"{}" ~forges_tickets:false in - let operation1 = - transfer_operation ~src ~destination:destination1 ~parameters + let* (operation1, incr) = + transfer_tickets_operation ~incr ~src ~destination:destination1 parameters in let* block = Incremental.finalize_block incr in let* (destination2, incr) = @@ -545,8 +570,8 @@ let test_transfer_to_two_contracts_with_different_tickets () = ~storage:"{}" ~forges_tickets:false in - let operation2 = - transfer_operation ~src ~destination:destination2 ~parameters + let* (operation2, incr) = + transfer_tickets_operation ~incr ~src ~destination:destination2 parameters in let* (ticket_diffs, ctxt) = ticket_diffs_of_operations incr [operation1; operation2] @@ -851,15 +876,12 @@ let test_originate_and_transfer () = ~storage:"{}" ~forges_tickets:false in - let parameters = - Printf.sprintf - {|{Pair %S "red" 1; Pair %S "green" 1; Pair %S "blue" 1; }|} - ticketer_addr - ticketer_addr - ticketer_addr - in - let operation2 = - transfer_operation ~src ~destination:destination2 ~parameters + let* (operation2, incr) = + transfer_tickets_operation + ~incr + ~src + ~destination:destination2 + [(ticketer, "red", 1); (ticketer, "green", 1); (ticketer, "blue", 1)] in let* (ticket_diffs, ctxt) = ticket_diffs_of_operations incr [operation1; operation2] @@ -976,13 +998,29 @@ let test_transfer_big_map_with_tickets () = ~storage:"{}" ~forges_tickets:false in + let open Lwt_tzresult_syntax in + let*? value_type = + Environment.wrap_tzresult @@ ticket_t Micheline.dummy_location string_key + in + let*? parameters_ty = + Environment.wrap_tzresult + @@ big_map_t Micheline.dummy_location int_key value_type + in let parameters = - Printf.sprintf "%d" @@ Z.to_int (Big_map.Id.unparse_to_z big_map_id) + Big_map + { + id = Some big_map_id; + diff = {map = Big_map_overlay.empty; size = 0}; + key_type = int_key; + value_type; + } in - let operation = + let* (operation, incr) = transfer_operation + ~incr ~src:ticketer_contract ~destination:orig_contract + ~parameters_ty ~parameters in let* (ticket_diffs, ctxt) = ticket_diffs_of_operations incr [operation] in -- GitLab From 97c9f560075827f1f41babe94ae03939c276f4d7 Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Fri, 4 Mar 2022 22:08:52 +0100 Subject: [PATCH 07/12] Proto/Michelson: optimize ticket_operations_diff. --- .../lib_protocol/ticket_operations_diff.ml | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 259fc484df74..87b26717488b 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -149,14 +149,28 @@ let parse_and_cache_script ctxt ~destination ~get_non_cached_script = Script_cache.insert ctxt destination (script, ex_script) size >>?= fun ctxt -> return (ex_script, ctxt) -let tickets_of_transaction ctxt ~destination ~parameters ~entrypoint = +let cast_transaction_parameter (type a b) ctxt location + (entry_arg_ty : a Script_typed_ir.ty) (parameters_ty : b Script_typed_ir.ty) + (parameters : b) : (a * context) tzresult Lwt.t = + Gas_monad.run + ctxt + (Script_ir_translator.ty_eq + ~error_details:Informative + location + entry_arg_ty + parameters_ty) + >>?= fun (res, ctxt) -> + res >>?= fun Script_ir_translator.Eq -> return ((parameters : a), ctxt) + +let tickets_of_transaction ctxt ~destination ~entrypoint ~parameters_ty + ~parameters = match Contract.is_implicit destination with | Some _ -> return (None, ctxt) | None -> - (* TODO: #2351 + (* TODO: #2653 Avoid having to load the script from the cache. - After internal operations are in place we should be able to use the - typed script directly. + This is currently in place to avoid regressions for type-checking + errors. We should be able to remove it. *) parse_and_cache_script ctxt @@ -181,22 +195,20 @@ let tickets_of_transaction ctxt ~destination ~parameters ~entrypoint = 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. *) - (* TODO: #2350 - Avoid having to decode and parse the [parameters] node. - After internal operations are in place we should be able to use the - typed script directly. - *) - Script.force_decode_in_context + (* Check that the parameter's type matches that of the entry-point, and + cast the parameter if this is the case. *) + cast_transaction_parameter ctxt - ~consume_deserialization_gas:When_needed + location + entry_arg_ty + parameters_ty parameters - >>?= fun (expr, ctxt) -> - Ticket_scanner.tickets_of_node + >>=? fun (parameters, ctxt) -> + Ticket_scanner.tickets_of_value ~include_lazy:true ctxt has_tickets - (Micheline.root expr) + parameters >>=? fun (tickets, ctxt) -> return (Some {destination; tickets}, ctxt) (** Extract tickets of an origination operation by scanning the storage. *) @@ -250,13 +262,19 @@ let tickets_of_operation ctxt transaction = { amount = _; - parameters; + parameters = _; entrypoint; destination = Destination.Contract destination; }; - _; + parameters_ty; + parameters; } -> - tickets_of_transaction ctxt ~destination ~parameters ~entrypoint + tickets_of_transaction + ctxt + ~destination + ~entrypoint + ~parameters_ty + ~parameters | Transaction {transaction = {destination = Destination.Tx_rollup _; _}; _} -> (* TODO: #2488 The ticket accounting for the recipient of rollup transactions -- GitLab From 507b79fa7562359d026420539dfb82d9d017fa6f Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Mon, 7 Mar 2022 09:52:14 +0100 Subject: [PATCH 08/12] Proto/Michelson: locations in internal transactions. --- src/proto_alpha/lib_protocol/apply.ml | 12 ++++++---- .../lib_protocol/script_interpreter.ml | 22 +++++++++++++------ .../lib_protocol/script_interpreter.mli | 1 + .../lib_protocol/script_interpreter_defs.ml | 6 +++-- .../lib_protocol/script_typed_ir.ml | 1 + .../lib_protocol/script_typed_ir.mli | 1 + .../michelson/test_ticket_accounting.ml | 1 + .../michelson/test_ticket_operations_diff.ml | 1 + .../lib_protocol/ticket_operations_diff.ml | 6 +++-- 9 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 4048f05b5ae3..e0496f5a908d 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -877,14 +877,14 @@ let apply_delegation ~ctxt ~source ~delegate ~since = (ctxt, Delegation_result {consumed_gas = Gas.consumed ~since ~until:ctxt}, []) type execution_arg = - | Typed_arg : 'a Script_typed_ir.ty * 'a -> execution_arg + | Typed_arg : Script.location * 'a Script_typed_ir.ty * 'a -> execution_arg | Untyped_arg : Script.expr -> execution_arg let apply_transaction_to_implicit ~ctxt ~contract ~parameter ~entrypoint ~before_operation ~balance_updates ~allocated_destination_contract = let is_unit = match parameter with - | Typed_arg (Unit_t, ()) -> true + | Typed_arg (_, Unit_t, ()) -> true | Typed_arg _ -> false | Untyped_arg parameter -> ( match Micheline.root parameter with @@ -951,13 +951,14 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount ~parameter ~entrypoint ~internal - | Typed_arg (parameter_ty, parameter) -> + | Typed_arg (location, parameter_ty, parameter) -> Script_interpreter.execute_with_typed_parameter ctxt ~cached_script:(Some script_ir) mode step_constants ~script + ~location ~parameter_ty ~parameter ~entrypoint @@ -1259,12 +1260,13 @@ let apply_internal_manager_operation_content : { transaction = {amount; parameters = _; destination = Contract contract; entrypoint}; + location; parameters_ty; parameters = typed_parameters; } -> apply_transaction ~ctxt - ~parameter:(Typed_arg (parameters_ty, typed_parameters)) + ~parameter:(Typed_arg (location, parameters_ty, typed_parameters)) ~source ~contract ~amount @@ -1282,6 +1284,7 @@ let apply_internal_manager_operation_content : { transaction = {amount; parameters; destination = Tx_rollup dst; entrypoint}; + location = _; parameters_ty = _; parameters = _; } -> @@ -1479,6 +1482,7 @@ let apply_external_manager_operation_content : destination = Contract destination; entrypoint; }; + location = Micheline.location ticketer_node; parameters_ty = ticket_ty; parameters = ticket; }; diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 909da6b8fc08..e98af7f9d1d1 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1009,11 +1009,19 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let accu = maybe_contract in (step [@ocaml.tailcall]) (ctxt, sc) gas k ks accu stack | None -> (step [@ocaml.tailcall]) (ctxt, sc) gas k ks None stack) - | ITransfer_tokens (_, k) -> + | ITransfer_tokens (kinfo, k) -> let p = accu in let (amount, (Typed_contract {arg_ty; address}, stack)) = stack in let {destination; entrypoint} = address in - transfer (ctxt, sc) gas amount arg_ty p destination entrypoint + transfer + (ctxt, sc) + gas + amount + kinfo.iloc + arg_ty + p + destination + entrypoint >>=? fun (accu, ctxt, gas) -> (step [@ocaml.tailcall]) (ctxt, sc) gas k ks accu stack | IImplicit_account (_, k) -> @@ -1705,7 +1713,7 @@ let step logger ctxt step_constants descr stack = *) type execution_arg = - | Typed_arg : 'a Script_typed_ir.ty * 'a -> execution_arg + | Typed_arg : Script.location * 'a Script_typed_ir.ty * 'a -> execution_arg | Untyped_arg : Script.expr -> execution_arg type execution_result = { @@ -1750,12 +1758,12 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal (Bad_contract_parameter step_constants.self) (parse_data ctxt ~legacy:false ~allow_forged:internal entrypoint_ty arg) >>=? fun (parsed_arg, ctxt) -> return (box parsed_arg, ctxt) - | Typed_arg (parsed_arg_ty, parsed_arg) -> + | Typed_arg (location, parsed_arg_ty, parsed_arg) -> Gas_monad.run ctxt (Script_ir_translator.ty_eq ~error_details:Informative - Micheline.dummy_location + location entrypoint_ty parsed_arg_ty) >>?= fun (res, ctxt) -> @@ -1834,7 +1842,7 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal (script, size) ) let execute_with_typed_parameter ?logger ctxt ~cached_script mode step_constants - ~script ~entrypoint ~parameter_ty ~parameter ~internal = + ~script ~entrypoint ~parameter_ty ~location ~parameter ~internal = execute_any_arg logger ctxt @@ -1844,7 +1852,7 @@ let execute_with_typed_parameter ?logger ctxt ~cached_script mode step_constants ~internal script cached_script - (Typed_arg (parameter_ty, parameter)) + (Typed_arg (location, parameter_ty, parameter)) let execute ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint ~parameter ~internal = diff --git a/src/proto_alpha/lib_protocol/script_interpreter.mli b/src/proto_alpha/lib_protocol/script_interpreter.mli index d535db77bff3..820c3ac7c1aa 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.mli +++ b/src/proto_alpha/lib_protocol/script_interpreter.mli @@ -126,6 +126,7 @@ val execute_with_typed_parameter : script:Script.t -> entrypoint:Entrypoint.t -> parameter_ty:'a Script_typed_ir.ty -> + location:Script.location -> parameter:'a -> internal:bool -> (execution_result * (Script_ir_translator.ex_script * int)) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index e9f2e0c1a4b3..2bd9dbf35d27 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -504,7 +504,7 @@ let apply ctxt gas capture_ty capture lam = creates an operation that transfers an amount of [tez] to a contract determined by [(destination, entrypoint)] instantiated with argument [parameters] of type [parameters_ty]. *) -let transfer (ctxt, sc) gas amount parameters_ty parameters destination +let transfer (ctxt, sc) gas amount location parameters_ty parameters destination entrypoint = (* [craft_transfer_parameters ctxt tp p] reorganizes, if need be, the parameters submitted by the interpreter to prepare them for the @@ -573,7 +573,9 @@ let transfer (ctxt, sc) gas amount parameters_ty parameters destination in {amount; destination; entrypoint; parameters} in - let operation = Transaction {transaction; parameters_ty; parameters} in + let operation = + Transaction {transaction; location; parameters_ty; parameters} + in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> let iop = {source = sc.self; operation; nonce} in let res = {piop = Internal_operation iop; lazy_storage_diff} in diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 1b4655d5ba53..38aeb1b605f2 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -1351,6 +1351,7 @@ and ('input, 'output) view_signature = and 'kind manager_operation = | Transaction : { transaction : Alpha_context.transaction; + location : Script.location; parameters_ty : 'a ty; parameters : 'a; } diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index c75b9f4fe68a..d7e8496272e2 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -1494,6 +1494,7 @@ and 'kind manager_operation = typed version in order to produce the receipt ([Apply_results.internal_manager_operation]). *) transaction : Alpha_context.transaction; + location : Script.location; parameters_ty : 'a ty; parameters : 'a; } diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml index a4cd8fb67821..86c5c4002d72 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml @@ -380,6 +380,7 @@ let transfer_operation ctxt ~src ~destination ~arg_type ~arg = entrypoint = Entrypoint.default; destination = Destination.Contract destination; }; + location = Micheline.dummy_location; parameters_ty = arg_type; parameters = arg; }; diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml index dd01e8ef7b09..04e7b5ca8f9d 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml @@ -287,6 +287,7 @@ let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = entrypoint = Entrypoint.default; destination = Destination.Contract destination; }; + location = Micheline.dummy_location; parameters_ty; parameters; }; diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 87b26717488b..25810b64df27 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -162,8 +162,8 @@ let cast_transaction_parameter (type a b) ctxt location >>?= fun (res, ctxt) -> res >>?= fun Script_ir_translator.Eq -> return ((parameters : a), ctxt) -let tickets_of_transaction ctxt ~destination ~entrypoint ~parameters_ty - ~parameters = +let tickets_of_transaction ctxt ~destination ~entrypoint ~location + ~parameters_ty ~parameters = match Contract.is_implicit destination with | Some _ -> return (None, ctxt) | None -> @@ -266,6 +266,7 @@ let tickets_of_operation ctxt entrypoint; destination = Destination.Contract destination; }; + location; parameters_ty; parameters; } -> @@ -273,6 +274,7 @@ let tickets_of_operation ctxt ctxt ~destination ~entrypoint + ~location ~parameters_ty ~parameters | Transaction {transaction = {destination = Destination.Tx_rollup _; _}; _} -> -- GitLab From 9d343db87bb6e39df6cc2a0ea0fd8e233474c098 Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Tue, 8 Mar 2022 13:28:00 +0100 Subject: [PATCH 09/12] Proto/Michelson-Plugin: change execution_result. --- src/proto_alpha/lib_plugin/plugin.ml | 47 +++++++++++++------ src/proto_alpha/lib_protocol/apply.ml | 16 +++++-- .../lib_protocol/script_interpreter.ml | 8 ++-- .../lib_protocol/script_interpreter.mli | 7 +-- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index 89ab27564a7a..8667af203ee0 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1466,8 +1466,17 @@ module View_helpers = struct | [ Script_typed_ir.Internal_operation { - operation = Transaction {transaction = {destination; parameters; _}; _}; - _; + operation = + Transaction + { + transaction = + {destination; parameters; entrypoint = _; amount = _}; + parameters = _; + parameters_ty = _; + location = _; + }; + source = _; + nonce = _; }; ] when Destination.equal destination (Contract callback) -> @@ -1930,11 +1939,10 @@ module RPC = struct ~entrypoint ~parameter ~internal:true - >>=? fun ( {ctxt; storage; lazy_storage_diff; operations; ticket_diffs}, - _ ) -> + >>=? fun res -> logger.get_log () >|=? fun trace -> let trace = Option.value ~default:[] trace in - ({ctxt; storage; lazy_storage_diff; operations; ticket_diffs}, trace) + (res, trace) end let typecheck_data : @@ -2300,7 +2308,8 @@ module RPC = struct ~parameter ~internal:true >|=? fun ( { - ctxt = _; + script = _; + code_size = _; Script_interpreter.storage; operations; lazy_storage_diff; @@ -2369,13 +2378,15 @@ module RPC = struct ~script:{storage; code} ~entrypoint ~parameter - >|=? fun ( { - ctxt = _; - Script_interpreter.storage; - operations; - lazy_storage_diff; - ticket_diffs = _; - }, + >|=? fun ( ( { + script = _; + code_size = _; + Script_interpreter.storage; + operations; + lazy_storage_diff; + ticket_diffs = _; + }, + _ctxt ), trace ) -> ( storage, Apply_results.contents_of_packed_internal_operations operations, @@ -2466,7 +2477,15 @@ module RPC = struct ~entrypoint ~parameter ~internal:true - >>=? fun ({Script_interpreter.operations; _}, (_, _)) -> + >>=? fun ( { + Script_interpreter.operations; + script = _; + code_size = _; + storage = _; + lazy_storage_diff = _; + ticket_diffs = _; + }, + _ctxt ) -> View_helpers.extract_parameter_from_operations entrypoint operations diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index e0496f5a908d..f1234499a3b6 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -963,8 +963,15 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount ~parameter ~entrypoint ~internal) - >>=? fun ( {ctxt; storage; lazy_storage_diff; operations; ticket_diffs}, - (updated_cached_script, updated_size) ) -> + >>=? fun ( { + script = updated_cached_script; + code_size = updated_size; + storage; + lazy_storage_diff; + operations; + ticket_diffs; + }, + ctxt ) -> update_script_storage_and_ticket_balances ctxt ~self:contract @@ -3083,13 +3090,14 @@ let apply_liquidity_baking_subsidy ctxt ~toggle_vote = ~entrypoint:Entrypoint.default ~internal:false >>=? fun ( { - ctxt; + script = updated_cached_script; + code_size = updated_size; storage; lazy_storage_diff; operations; ticket_diffs; }, - (updated_cached_script, updated_size) ) -> + ctxt ) -> match operations with | _ :: _ -> (* No internal operations are expected here. Something bad may be happening. *) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index e98af7f9d1d1..ab6303ee7bf3 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1717,7 +1717,8 @@ type execution_arg = | Untyped_arg : Script.expr -> execution_arg type execution_result = { - ctxt : context; + script : Script_ir_translator.ex_script; + code_size : int; storage : Script.expr; lazy_storage_diff : Lazy_storage.diffs option; operations : packed_internal_operation list; @@ -1833,13 +1834,14 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal Gas.consume ctxt cost >>?= fun ctxt -> return ( { - ctxt; + script; + code_size = size; storage = unparsed_storage; lazy_storage_diff = lazy_storage_diff_all; operations; ticket_diffs; }, - (script, size) ) + ctxt ) let execute_with_typed_parameter ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint ~parameter_ty ~location ~parameter ~internal = diff --git a/src/proto_alpha/lib_protocol/script_interpreter.mli b/src/proto_alpha/lib_protocol/script_interpreter.mli index 820c3ac7c1aa..bfbde28e35d1 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.mli +++ b/src/proto_alpha/lib_protocol/script_interpreter.mli @@ -51,7 +51,8 @@ type error += Cannot_serialize_storage type error += Michelson_too_many_recursive_calls type execution_result = { - ctxt : context; + script : Script_ir_translator.ex_script; + code_size : int; storage : Script.expr; lazy_storage_diff : Lazy_storage.diffs option; operations : packed_internal_operation list; @@ -109,7 +110,7 @@ val execute : entrypoint:Entrypoint.t -> parameter:Script.expr -> internal:bool -> - (execution_result * (Script_ir_translator.ex_script * int)) tzresult Lwt.t + (execution_result * context) tzresult Lwt.t (** [execute_with_typed_parameter ?logger ctxt ~cached_script mode step_constant ~script ~entrypoint loc ~parameter_ty ~parameter ~internal] @@ -129,7 +130,7 @@ val execute_with_typed_parameter : location:Script.location -> parameter:'a -> internal:bool -> - (execution_result * (Script_ir_translator.ex_script * int)) tzresult Lwt.t + (execution_result * context) tzresult Lwt.t (** [kstep logger ctxt step_constants kinstr accu stack] interprets the script represented by [kinstr] under the context [ctxt]. This will -- GitLab From 07c6506fe6dc9f310d94cc771efa8f06bd95826e Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Tue, 8 Mar 2022 22:12:27 +0100 Subject: [PATCH 10/12] Proto/Michelson: extract execute's parameter preparation. --- .../lib_protocol/script_interpreter.ml | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index ab6303ee7bf3..a066cc50351c 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1716,6 +1716,26 @@ type execution_arg = | Typed_arg : Script.location * 'a Script_typed_ir.ty * 'a -> execution_arg | Untyped_arg : Script.expr -> execution_arg +let lift_execution_arg (type a) ctxt ~internal (entrypoint_ty : a ty) + (box : a -> 'b) arg : ('b * context) tzresult Lwt.t = + (match arg with + | Untyped_arg arg -> + let arg = Micheline.root arg in + parse_data ctxt ~legacy:false ~allow_forged:internal entrypoint_ty arg + | Typed_arg (location, parsed_arg_ty, parsed_arg) -> + Gas_monad.run + ctxt + (Script_ir_translator.ty_eq + ~error_details:Informative + location + entrypoint_ty + parsed_arg_ty) + >>?= fun (res, ctxt) -> + res >>?= fun Eq -> + let parsed_arg : a = parsed_arg in + return (parsed_arg, ctxt)) + >>=? fun (entrypoint_arg, ctxt) -> return (box entrypoint_arg, ctxt) + type execution_result = { script : Script_ir_translator.ex_script; code_size : int; @@ -1752,23 +1772,9 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal >>?= fun (r, ctxt) -> record_trace (Bad_contract_parameter step_constants.self) r >>?= fun (Ex_ty_cstr (entrypoint_ty, box)) -> - (match arg with - | Untyped_arg arg -> - let arg = Micheline.root arg in - trace - (Bad_contract_parameter step_constants.self) - (parse_data ctxt ~legacy:false ~allow_forged:internal entrypoint_ty arg) - >>=? fun (parsed_arg, ctxt) -> return (box parsed_arg, ctxt) - | Typed_arg (location, parsed_arg_ty, parsed_arg) -> - Gas_monad.run - ctxt - (Script_ir_translator.ty_eq - ~error_details:Informative - location - entrypoint_ty - parsed_arg_ty) - >>?= fun (res, ctxt) -> - res >>?= fun Eq -> return (box parsed_arg, ctxt)) + trace + (Bad_contract_parameter step_constants.self) + (lift_execution_arg ctxt ~internal entrypoint_ty box arg) >>=? fun (arg, ctxt) -> Script_ir_translator.collect_lazy_storage ctxt arg_type arg >>?= fun (to_duplicate, ctxt) -> -- GitLab From 2ce28f5523226de014eb419263398bae0896b844 Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Fri, 11 Mar 2022 18:14:21 +0100 Subject: [PATCH 11/12] Proto/Michelson: factorize execute's application. --- src/proto_alpha/lib_protocol/apply.ml | 34 +++++++++------------------ 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index f1234499a3b6..0d578b622995 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -940,29 +940,17 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount level; } in - (match parameter with - | Untyped_arg parameter -> - Script_interpreter.execute - ctxt - ~cached_script:(Some script_ir) - mode - step_constants - ~script - ~parameter - ~entrypoint - ~internal - | Typed_arg (location, parameter_ty, parameter) -> - Script_interpreter.execute_with_typed_parameter - ctxt - ~cached_script:(Some script_ir) - mode - step_constants - ~script - ~location - ~parameter_ty - ~parameter - ~entrypoint - ~internal) + let execute = + match parameter with + | Untyped_arg parameter -> Script_interpreter.execute ~parameter + | Typed_arg (location, parameter_ty, parameter) -> + Script_interpreter.execute_with_typed_parameter + ~location + ~parameter_ty + ~parameter + in + let cached_script = Some script_ir in + execute ctxt ~cached_script mode step_constants ~script ~entrypoint ~internal >>=? fun ( { script = updated_cached_script; code_size = updated_size; -- GitLab From 91475ff1571e269c87863e8a1c40e5cd02abc570 Mon Sep 17 00:00:00 2001 From: Nicolas Ayache Date: Tue, 15 Mar 2022 14:35:35 +0100 Subject: [PATCH 12/12] Tests: update regression tests gas. --- ...ddressTransfer::test_send_self_address.out | 6 ++--- ...estContractOnchainOpcodes::test_source.out | 6 ++--- ...ctOnchainOpcodes::test_transfer_tokens.out | 22 +++++++++---------- ...roveTransferRemove::test_add_liquidity.out | 16 +++++++------- ...eTransferRemove::test_remove_liquidity.out | 16 +++++++------- ..._baking.TestTrades::test_add_liquidity.out | 16 +++++++------- ...uidity_baking.TestTrades::test_buy_tok.out | 14 ++++++------ ...idity_baking.TestTrades::test_sell_tok.out | 14 ++++++------ 8 files changed, 55 insertions(+), 55 deletions(-) diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSelfAddressTransfer::test_send_self_address.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSelfAddressTransfer::test_send_self_address.out index aacbe58ac6b4..ba446f3e7d4a 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSelfAddressTransfer::test_send_self_address.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSelfAddressTransfer::test_send_self_address.out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestSelfAddressTransfer::test_send_self_address Node is bootstrapped. -Estimated gas: 5195.305 units (will add 100 for safety) +Estimated gas: 5195.785 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -27,7 +27,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 82 bytes - Consumed gas: 3990.539 + Consumed gas: 3991.559 Internal operations: Transaction: Amount: ꜩ0 @@ -37,6 +37,6 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 83 bytes - Consumed gas: 1204.766 + Consumed gas: 1204.226 Injected block at minimal timestamp diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_source.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_source.out index 0b389ee47465..2e4c88afa6d4 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_source.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_source.out @@ -78,7 +78,7 @@ Injected block at minimal timestamp [CONTRACT_HASH] Node is bootstrapped. -Estimated gas: 4341.193 units (will add 100 for safety) +Estimated gas: 4341.893 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -104,7 +104,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 55 bytes - Consumed gas: 3127.533 + Consumed gas: 3128.113 Internal operations: Transaction: Amount: ꜩ0 @@ -113,7 +113,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: 0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c Storage size: 65 bytes - Consumed gas: 1213.660 + Consumed gas: 1213.780 Injected block at minimal timestamp "[CONTRACT_HASH]" diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_transfer_tokens.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_transfer_tokens.out index 10c08220eea0..b2eea4597340 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_transfer_tokens.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_transfer_tokens.out @@ -143,7 +143,7 @@ Injected block at minimal timestamp [CONTRACT_HASH] Node is bootstrapped. -Estimated gas: 5179.356 units (will add 100 for safety) +Estimated gas: 5180.056 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -154,13 +154,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000825 + Fee to the baker: ꜩ0.000826 Expected counter: [EXPECTED_COUNTER] - Gas limit: 5280 + Gas limit: 5281 Storage limit: 0 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000825 - payload fees(the block proposer) ....... +ꜩ0.000825 + [CONTRACT_HASH] ... -ꜩ0.000826 + payload fees(the block proposer) ....... +ꜩ0.000826 Transaction: Amount: ꜩ100 From: [CONTRACT_HASH] @@ -169,7 +169,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 66 bytes - Consumed gas: 3975.931 + Consumed gas: 3976.511 Balance updates: [CONTRACT_HASH] ... -ꜩ100 [CONTRACT_HASH] ... +ꜩ100 @@ -181,7 +181,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 38 bytes - Consumed gas: 1203.425 + Consumed gas: 1203.545 Balance updates: [CONTRACT_HASH] ... -ꜩ100 [CONTRACT_HASH] ... +ꜩ100 @@ -191,7 +191,7 @@ Injected block at minimal timestamp [CONTRACT_HASH] Node is bootstrapped. -Estimated gas: 4326.329 units (will add 100 for safety) +Estimated gas: 4327.029 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -204,7 +204,7 @@ This sequence of operations was run: From: [CONTRACT_HASH] Fee to the baker: ꜩ0.00074 Expected counter: [EXPECTED_COUNTER] - Gas limit: 4427 + Gas limit: 4428 Storage limit: 0 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.00074 @@ -217,7 +217,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 66 bytes - Consumed gas: 3122.904 + Consumed gas: 3123.484 Balance updates: [CONTRACT_HASH] ... -ꜩ100 [CONTRACT_HASH] ... +ꜩ100 @@ -229,7 +229,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 38 bytes - Consumed gas: 1203.425 + Consumed gas: 1203.545 Balance updates: [CONTRACT_HASH] ... -ꜩ100 [CONTRACT_HASH] ... +ꜩ100 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 e9ae9c33a18d..6c341efec4dd 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.290 units (will add 100 for safety) +Estimated gas: 9883.730 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]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001549 + Fee to the baker: ꜩ0.001354 Expected counter: [EXPECTED_COUNTER] - Gas limit: 11931 + Gas limit: 9984 Storage limit: 161 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001549 - payload fees(the block proposer) ....... +ꜩ0.001549 + [CONTRACT_HASH] ... -ꜩ0.001354 + payload fees(the block proposer) ....... +ꜩ0.001354 Transaction: Amount: ꜩ9001 From: [CONTRACT_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.049 + Consumed gas: 5091.529 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.576 + Consumed gas: 3097.176 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.665 + Consumed gas: 1695.025 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0175 storage fees ........................... +ꜩ0.0175 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 ed478c3e5efa..60f287e1ce24 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: 10541.746 units (will add 100 for safety) +Estimated gas: 8595.186 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]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001417 + Fee to the baker: ꜩ0.001222 Expected counter: [EXPECTED_COUNTER] - Gas limit: 10642 + Gas limit: 8696 Storage limit: 87 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001417 - payload fees(the block proposer) ....... +ꜩ0.001417 + [CONTRACT_HASH] ... -ꜩ0.001222 + payload fees(the block proposer) ....... +ꜩ0.001222 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01e927f00ef734dfc85919635e9afc9166c83ef9fc00 ; 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes - Consumed gas: 2917.676 + Consumed gas: 2920.156 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.739 + Consumed gas: 1875.099 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.331 + Consumed gas: 2379.931 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 c0262d3a125e..bf6e975dd8e5 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.290 units (will add 100 for safety) +Estimated gas: 9883.730 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]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001549 + Fee to the baker: ꜩ0.001354 Expected counter: [EXPECTED_COUNTER] - Gas limit: 11931 + Gas limit: 9984 Storage limit: 161 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001549 - payload fees(the block proposer) ....... +ꜩ0.001549 + [CONTRACT_HASH] ... -ꜩ0.001354 + payload fees(the block proposer) ....... +ꜩ0.001354 Transaction: Amount: ꜩ9001 From: [CONTRACT_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.049 + Consumed gas: 5091.529 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.576 + Consumed gas: 3097.176 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.665 + Consumed gas: 1695.025 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 6bc37f131318..8b0d852194af 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: 7504.968 units (will add 100 for safety) +Estimated gas: 6207.028 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]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001108 + Fee to the baker: ꜩ0.000978 Expected counter: [EXPECTED_COUNTER] - Gas limit: 7605 + Gas limit: 6308 Storage limit: 346 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001108 - payload fees(the block proposer) ....... +ꜩ0.001108 + [CONTRACT_HASH] ... -ꜩ0.000978 + payload fees(the block proposer) ....... +ꜩ0.000978 Transaction: Amount: ꜩ9001 From: [CONTRACT_HASH] @@ -34,7 +34,7 @@ This sequence of operations was run: 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4634 bytes Paid storage size diff: 1 bytes - Consumed gas: 2405.633 + Consumed gas: 2407.093 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.335 + Consumed gas: 2379.935 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 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 8aa45e2468de..26eb53804916 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.364 units (will add 100 for safety) +Estimated gas: 8525.424 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001338 + Fee to the baker: ꜩ0.001208 Expected counter: [EXPECTED_COUNTER] - Gas limit: 9924 + Gas limit: 8626 Storage limit: 0 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001338 - payload fees(the block proposer) ....... +ꜩ0.001338 + [CONTRACT_HASH] ... -ꜩ0.001208 + payload fees(the block proposer) ....... +ꜩ0.001208 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01e927f00ef734dfc85919635e9afc9166c83ef9fc00 ; 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes - Consumed gas: 2406.752 + Consumed gas: 2408.212 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.612 + Consumed gas: 3277.212 Transaction: Amount: ꜩ3891.966034 From: [CONTRACT_HASH] -- GitLab