From 5e2165cd109192d5b4330508d2d73515f8ba9689 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 14 Apr 2022 19:28:59 +0200 Subject: [PATCH 1/7] Proto/Tx_rollup_ticket: parse_ticket_and_operation allow only originated contracts as destination --- src/proto_alpha/lib_protocol/apply.ml | 64 +++++++++---------- .../lib_protocol/tx_rollup_ticket.ml | 2 +- .../lib_protocol/tx_rollup_ticket.mli | 2 +- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index c9c5fe2456a8..b996e1234f64 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1406,44 +1406,44 @@ let apply_external_manager_operation_content : } in return (ctxt, result, []) - | Transfer_ticket {contents; ty; ticketer; amount; destination; entrypoint} -> + | Transfer_ticket {contents; ty; ticketer; amount; destination; entrypoint} + -> ( (* The encoding ensures that the amount is in a natural number. Here is mainly to check that it is non-zero.*) error_when Compare.Z.(amount <= Z.zero) Ticket_scanner.Forbidden_zero_ticket_quantity >>?= fun () -> - error_when - (match destination with Implicit _ -> true | Originated _ -> false) - Cannot_transfer_ticket_to_implicit - >>?= fun () -> - Tx_rollup_ticket.parse_ticket_and_operation - ~consume_deserialization_gas - ~ticketer - ~contents - ~ty - ~source:source_contract - ~destination - ~entrypoint - ~amount - ctxt - >>=? fun (ctxt, ticket_token, op) -> - Tx_rollup_ticket.transfer_ticket - ctxt - ~src:(Contract source_contract) - ~dst:(Contract destination) - ticket_token - amount - >>=? fun (ctxt, paid_storage_size_diff) -> - let result = - Transfer_ticket_result - { - balance_updates = []; - consumed_gas = Gas.consumed ~since:ctxt_before_op ~until:ctxt; - paid_storage_size_diff; - } - in - return (ctxt, result, [op]) + match destination with + | Implicit _ -> fail Cannot_transfer_ticket_to_implicit + | Originated destination_hash -> + Tx_rollup_ticket.parse_ticket_and_operation + ~consume_deserialization_gas + ~ticketer + ~contents + ~ty + ~source:source_contract + ~destination:destination_hash + ~entrypoint + ~amount + ctxt + >>=? fun (ctxt, ticket_token, op) -> + Tx_rollup_ticket.transfer_ticket + ctxt + ~src:(Contract source_contract) + ~dst:(Contract destination) + ticket_token + amount + >>=? fun (ctxt, paid_storage_size_diff) -> + let result = + Transfer_ticket_result + { + balance_updates = []; + consumed_gas = Gas.consumed ~since:ctxt_before_op ~until:ctxt; + paid_storage_size_diff; + } + in + return (ctxt, result, [op])) | Origination {delegate; script; credit} -> (* Internal originations have their address generated in the interpreter so that the script can use it immediately. diff --git a/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml b/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml index d4549894b9f7..d7907b674b03 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml +++ b/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml @@ -82,7 +82,7 @@ let parse_ticket_and_operation ~consume_deserialization_gas ~ticketer ~contents { amount = Tez.zero; unparsed_parameters; - destination; + destination = Contract.Originated destination; entrypoint; location = Micheline.location parameters_expr; parameters_ty = ticket_ty; diff --git a/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli b/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli index 281fb79289e6..77865d9e7dca 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli +++ b/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli @@ -48,7 +48,7 @@ val parse_ticket_and_operation : contents:Script.lazy_expr -> ty:Script.lazy_expr -> source:Contract.t -> - destination:Contract.t -> + destination:Contract_hash.t -> entrypoint:Entrypoint.t -> amount:Z.t -> context -> -- GitLab From 3ab1bc79661a2a1ec735b5e0f1b1d139be59372c Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 14 Apr 2022 19:28:59 +0200 Subject: [PATCH 2/7] Proto/Tests/Tickets: specialize helpers to originated contracts originate returns an originated contract transaction takes an originated contract --- .../michelson/test_ticket_accounting.ml | 33 ++++++------- .../michelson/test_ticket_operations_diff.ml | 47 ++++++++++--------- 2 files changed, 41 insertions(+), 39 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 ca3b2d839afc..11d81e61170f 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 @@ -396,7 +396,7 @@ let transfer_operation ctxt ~src ~destination ~arg_type ~arg = amount = Tez.zero; unparsed_parameters = Micheline.strip_locations params_node; entrypoint = Entrypoint.default; - destination; + destination = Contract.Originated destination; location = Micheline.dummy_location; parameters_ty = arg_type; parameters = arg; @@ -882,7 +882,6 @@ let test_update_invalid_transfer () = ~storage:"{}" ~forges_tickets:false in - let destination = Contract.Originated destination in let ctxt = Incremental.alpha_ctxt incr in let arg_type = ticket_string_list_type in let arg = @@ -954,7 +953,6 @@ let test_update_self_ticket_transfer () = ~storage:"{}" ~forges_tickets:false in - let ticket_receiver = Contract.Originated ticket_receiver in (* Ticket is self. That means we can transfer an unlimited amounts of such ticket-tokens. *) let ticketer = Contract.to_b58check self in @@ -994,7 +992,7 @@ let test_update_self_ticket_transfer () = wrap @@ Ticket_balance_key.of_ex_token ctxt - ~owner:(Destination.Contract ticket_receiver) + ~owner:(Destination.Contract (Originated ticket_receiver)) red_token in assert_balance ~loc:__LOC__ ctxt red_receiver_token_hash (Some 10) @@ -1014,7 +1012,6 @@ let test_update_valid_transfer () = ~storage:"{}" ~forges_tickets:false in - let destination = Contract.Originated destination in let ticketer = "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" in assert (ticketer <> Contract.to_b58check self) ; let ctxt = Incremental.alpha_ctxt incr in @@ -1030,7 +1027,7 @@ let test_update_valid_transfer () = wrap @@ Ticket_balance_key.of_ex_token ctxt - ~owner:(Destination.Contract destination) + ~owner:(Destination.Contract (Originated destination)) red_token in (* Set up the balance so that the self contract owns one ticket. *) @@ -1068,7 +1065,7 @@ let test_update_valid_transfer () = let test_update_transfer_tickets_to_self () = let open Lwt_result_syntax in let* baker, src, block = init_for_operation () in - let* self, _script, incr = + let* self_hash, _script, incr = originate block ~src @@ -1078,8 +1075,8 @@ let test_update_transfer_tickets_to_self () = ~forges_tickets:false in let ticketer = "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" in - assert (ticketer <> Contract_hash.to_b58check self) ; - let self = Contract.Originated self in + assert (ticketer <> Contract_hash.to_b58check self_hash) ; + let self = Contract.Originated self_hash in let ctxt = Incremental.alpha_ctxt incr in let* red_token = string_ticket_token ticketer "red" in let* red_self_token_hash, ctxt = @@ -1100,7 +1097,7 @@ let test_update_transfer_tickets_to_self () = let* operation, ctxt = let arg_type = ticket_string_list_type in let arg = boxed_list [string_ticket ticketer "red" 1] in - transfer_operation ctxt ~src:self ~destination:self ~arg_type ~arg + transfer_operation ctxt ~src:self ~destination:self_hash ~arg_type ~arg in let* _, ctxt = (* Ticket diff removes 5 tickets. *) @@ -1128,7 +1125,7 @@ let test_update_transfer_tickets_to_self () = let test_update_invalid_origination () = let open Lwt_result_syntax in let* baker, src, block = init_for_operation () in - let* destination, script, incr = + let* orig_contract, script, incr = let storage = let ticketer = "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" in Printf.sprintf @@ -1147,7 +1144,7 @@ let test_update_invalid_origination () = in let ctxt = Incremental.alpha_ctxt incr in let* operation, ctxt = - origination_operation ctxt ~src ~orig_contract:destination ~script + origination_operation ctxt ~src ~orig_contract ~script in assert_fail_with ~loc:__LOC__ @@ -1167,7 +1164,7 @@ let test_update_valid_origination () = let* baker, self, block = init_for_operation () in let ticketer = "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" in assert (ticketer <> Contract.to_b58check self) ; - let* originated, script, incr = + let* orig_contract, script, incr = let storage = Printf.sprintf {|{ Pair %S "red" 1; }|} ticketer in originate block @@ -1191,7 +1188,7 @@ let test_update_valid_origination () = wrap @@ Ticket_balance.adjust_balance ctxt red_self_token_hash ~delta:Z.one in let* operation, ctxt = - origination_operation ctxt ~src:self ~orig_contract:originated ~script + origination_operation ctxt ~src:self ~orig_contract ~script in let* _, ctxt = let* ticket_diffs, ctxt = @@ -1214,7 +1211,7 @@ let test_update_valid_origination () = wrap @@ Ticket_balance_key.of_ex_token ctxt - ~owner:(Destination.Contract (Originated originated)) + ~owner:(Destination.Contract (Originated orig_contract)) red_token in assert_balance ~loc:__LOC__ ctxt red_originated_token_hash (Some 1) @@ -1223,7 +1220,7 @@ let test_update_self_origination () = let open Lwt_result_syntax in let* baker, self, block = init_for_operation () in let ticketer = Contract.to_b58check self in - let* originated, script, incr = + let* orig_contract, script, incr = let storage = Printf.sprintf {|{ Pair %S "red" 1; }|} ticketer in originate block @@ -1239,11 +1236,11 @@ let test_update_self_origination () = wrap @@ Ticket_balance_key.of_ex_token ctxt - ~owner:(Destination.Contract (Originated originated)) + ~owner:(Destination.Contract (Originated orig_contract)) red_token in let* operation, ctxt = - origination_operation ctxt ~src:self ~orig_contract:originated ~script + origination_operation ctxt ~src:self ~orig_contract ~script in let* _, ctxt = wrap 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 b035358a3686..cb03583c9f40 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 @@ -301,7 +301,7 @@ let originate block ~src ~baker ~script ~storage ~forges_tickets = let* incr = Incremental.begin_construction ~policy:Block.(By_account baker) block in - return (Contract.Originated orig_contract, incr) + return (orig_contract, incr) let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = let open Lwt_result_syntax in @@ -325,7 +325,7 @@ let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = amount = Tez.zero; unparsed_parameters = Micheline.strip_locations params_node; entrypoint = Entrypoint.default; - destination; + destination = Contract.Originated destination; location = Micheline.dummy_location; parameters_ty; parameters; @@ -497,7 +497,8 @@ let test_transfer_one_ticket () = { ticket_token = string_token ~ticketer "white"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = + [(Destination.Contract (Originated orig_contract), nat 1)]; }; ] @@ -528,6 +529,7 @@ let test_transfer_multiple_tickets () = (ticketer, "red", 4); ] in + let orig_contract = Contract.Originated orig_contract in let test allow_zero_amount_tickets = let* ticket_diffs, ctxt = ticket_diffs_of_operations incr ~allow_zero_amount_tickets [operation] @@ -589,6 +591,7 @@ let test_transfer_different_tickets () = (ticketer1, "blue", 1); ] in + let destination = Destination.Contract (Originated destination) in let* ticket_diffs, ctxt = ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] in @@ -601,32 +604,32 @@ let test_transfer_different_tickets () = { ticket_token = string_token ~ticketer:ticketer1 "red"; total_amount = nat 2; - destinations = [(Destination.Contract destination, nat 2)]; + destinations = [(destination, nat 2)]; }; { ticket_token = string_token ~ticketer:ticketer1 "green"; total_amount = nat 2; - destinations = [(Destination.Contract destination, nat 2)]; + destinations = [(destination, nat 2)]; }; { ticket_token = string_token ~ticketer:ticketer1 "blue"; total_amount = nat 2; - destinations = [(Destination.Contract destination, nat 2)]; + destinations = [(destination, nat 2)]; }; { ticket_token = string_token ~ticketer:ticketer2 "red"; total_amount = nat 1; - destinations = [(Destination.Contract destination, nat 1)]; + destinations = [(destination, nat 1)]; }; { ticket_token = string_token ~ticketer:ticketer2 "green"; total_amount = nat 1; - destinations = [(Destination.Contract destination, nat 1)]; + destinations = [(destination, nat 1)]; }; { ticket_token = string_token ~ticketer:ticketer2 "blue"; total_amount = nat 1; - destinations = [(Destination.Contract destination, nat 1)]; + destinations = [(destination, nat 1)]; }; ] @@ -679,8 +682,8 @@ let test_transfer_to_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract destination2, nat 1); - (Destination.Contract destination1, nat 1); + (Destination.Contract (Originated destination2), nat 1); + (Destination.Contract (Originated destination1), nat 1); ]; }; { @@ -688,8 +691,8 @@ let test_transfer_to_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract destination2, nat 1); - (Destination.Contract destination1, nat 1); + (Destination.Contract (Originated destination2), nat 1); + (Destination.Contract (Originated destination1), nat 1); ]; }; { @@ -697,8 +700,8 @@ let test_transfer_to_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract destination2, nat 1); - (Destination.Contract destination1, nat 1); + (Destination.Contract (Originated destination2), nat 1); + (Destination.Contract (Originated destination1), nat 1); ]; }; ] @@ -1029,7 +1032,7 @@ let test_originate_and_transfer () = total_amount = nat 2; destinations = [ - (Destination.Contract destination2, nat 1); + (Destination.Contract (Originated destination2), nat 1); (Destination.Contract orig_contract1, nat 1); ]; }; @@ -1038,7 +1041,7 @@ let test_originate_and_transfer () = total_amount = nat 2; destinations = [ - (Destination.Contract destination2, nat 1); + (Destination.Contract (Originated destination2), nat 1); (Destination.Contract orig_contract1, nat 1); ]; }; @@ -1047,7 +1050,7 @@ let test_originate_and_transfer () = total_amount = nat 2; destinations = [ - (Destination.Contract destination2, nat 1); + (Destination.Contract (Originated destination2), nat 1); (Destination.Contract orig_contract1, nat 1); ]; }; @@ -1172,6 +1175,7 @@ let test_transfer_big_map_with_tickets () = let* ticket_diffs, ctxt = ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] in + let destination = Destination.Contract (Originated orig_contract) in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -1181,17 +1185,17 @@ let test_transfer_big_map_with_tickets () = { ticket_token = string_token ~ticketer:ticketer_contract "red"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(destination, nat 1)]; }; { ticket_token = string_token ~ticketer:ticketer_contract "green"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(destination, nat 1)]; }; { ticket_token = string_token ~ticketer:ticketer_contract "blue"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(destination, nat 1)]; }; ] @@ -1284,6 +1288,7 @@ let test_transfer_multiple_zero_tickets () = let* ticket_diffs, ctxt = ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] in + let orig_contract = Contract.Originated orig_contract in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ -- GitLab From db88e38c1930f9bfa92e37597c5149ef936f7eba Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Sat, 11 Jun 2022 18:34:40 +0200 Subject: [PATCH 3/7] Proto/Apply_results: split transaction to contract --- .../lib_protocol/apply_internal_results.ml | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply_internal_results.ml b/src/proto_alpha/lib_protocol/apply_internal_results.ml index 2a4ddcf7d2e8..e3676907b011 100644 --- a/src/proto_alpha/lib_protocol/apply_internal_results.ml +++ b/src/proto_alpha/lib_protocol/apply_internal_results.ml @@ -65,10 +65,31 @@ let contents_of_internal_operation (type kind) let operation : kind internal_manager_operation = match operation with | Transaction_to_contract - {destination; amount; entrypoint; unparsed_parameters; _} -> + { + destination = Implicit destination; + amount; + entrypoint; + unparsed_parameters; + _; + } -> Transaction { - destination = Contract destination; + destination = Contract (Implicit destination); + amount; + entrypoint; + parameters = Script.lazy_expr unparsed_parameters; + } + | Transaction_to_contract + { + destination = Originated destination; + amount; + entrypoint; + unparsed_parameters; + _; + } -> + Transaction + { + destination = Contract (Originated destination); amount; entrypoint; parameters = Script.lazy_expr unparsed_parameters; -- GitLab From 125b8693edae89f261ce0f66730a698a5234c332 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Sat, 11 Jun 2022 18:36:33 +0200 Subject: [PATCH 4/7] Proto/Michelson: split transaction to contract --- .../lib_protocol/script_interpreter_defs.ml | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index 15655fe1757f..eb8b49e43be4 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -479,25 +479,39 @@ let apply ctxt gas capture_ty capture lam = let gas, ctxt = local_gas_counter_and_outdated_context ctxt in return (lam', ctxt, gas) -let make_transaction_to_contract ctxt ~destination ~amount ~entrypoint ~location - ~parameters_ty ~parameters = +let make_transaction_to_contract ctxt ~(destination : Contract.t) ~amount + ~entrypoint ~location ~parameters_ty ~parameters = unparse_data ctxt Optimized parameters_ty parameters >>=? fun (unparsed_parameters, ctxt) -> Lwt.return ( Gas.consume ctxt (Script.strip_locations_cost unparsed_parameters) >|? fun ctxt -> let unparsed_parameters = Micheline.strip_locations unparsed_parameters in - ( Transaction_to_contract - { - destination; - amount; - entrypoint; - location; - parameters_ty; - parameters; - unparsed_parameters; - }, - ctxt ) ) + match destination with + | Implicit _ -> + ( Transaction_to_contract + { + destination; + amount; + entrypoint; + location; + parameters_ty; + parameters; + unparsed_parameters; + }, + ctxt ) + | Originated _ -> + ( Transaction_to_contract + { + destination; + amount; + entrypoint; + location; + parameters_ty; + parameters; + unparsed_parameters; + }, + ctxt ) ) let make_transaction_to_tx_rollup (type t tc) ctxt ~destination ~amount ~entrypoint ~(parameters_ty : (t, tc) ty) ~parameters = -- GitLab From 05739bdf55d93e019686652a3a212144e276f1d5 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 27 Jun 2022 19:08:28 +0200 Subject: [PATCH 5/7] Proto/Tests/Sc_rollup: originate_contract returns a contract hash --- .../integration/operations/test_sc_rollup.ml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml index c3fc19848a93..8e50f18e51dc 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -331,9 +331,9 @@ let verify_execute_outbox_message_operations incr ~loc ~source ~operations (Expr.to_string p) in let transactions_data = - let data_of_transaction (ty, entrypoint, params) = + let data_of_transaction (contract, entrypoint, params) = let params = Expr.from_string params in - (ty, entrypoint, params) + (Contract.Originated contract, entrypoint, params) in List.map data_of_transaction expected_transactions in @@ -350,12 +350,6 @@ let make_output ~outbox_level ~message_index transactions = let transactions = List.map (fun (destination, entrypoint, parameters) -> - let destination = - match destination with - | Contract.Originated ch -> ch - | Contract.Implicit _ -> - Stdlib.failwith "Expected an originated contract." - in let unparsed_parameters = Expr.from_string parameters in {Sc_rollup.Outbox.Message.unparsed_parameters; destination; entrypoint}) transactions @@ -381,7 +375,7 @@ let string_ticket_token ticketer content = let originate_contract incr ~script ~baker ~storage ~source_contract = let* block = Incremental.finalize_block incr in let* contract, _, block = - Contract_helpers.originate_contract_from_string + Contract_helpers.originate_contract_from_string_hash ~script ~storage ~source_contract @@ -895,7 +889,7 @@ let test_single_transaction_batch () = ~loc:__LOC__ incr red_token - (Destination.Contract ticket_receiver) + (Destination.Contract (Originated ticket_receiver)) (Some 1) let test_multi_transaction_batch () = @@ -981,7 +975,7 @@ let test_multi_transaction_batch () = ~loc:__LOC__ incr red_token - (Destination.Contract ticket_receiver) + (Destination.Contract (Originated ticket_receiver)) (Some 10) (** Test that executing an L2 to L1 transaction that involves an invalid -- GitLab From a5cb074bf754a2a0f4233610df32b94ee079ad3f Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 27 Jun 2022 18:43:06 +0200 Subject: [PATCH 6/7] Proto/Tests/Scoru: validate_and_extract_operation_params returns a contract hash --- .../integration/operations/test_sc_rollup.ml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml index 8e50f18e51dc..0cfe9d1210d0 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -238,7 +238,7 @@ let verify_execute_outbox_message_operations incr ~loc ~source ~operations operation = Transaction_to_contract { - destination; + destination = Originated destination; amount; entrypoint; location = _; @@ -264,13 +264,8 @@ let verify_execute_outbox_message_operations incr ~loc ~source ~operations (* Load the arg-type and entrypoints of the destination script. *) let* ( Script_ir_translator.Ex_script (Script {arg_type; entrypoints; _}), ctxt ) = - let* contract_hash = - match destination with - | Contract.Originated ch -> return ch - | _ -> failwith "Expected originated contract at %s" loc - in let* ctxt, _cache_key, cached = - wrap @@ Script_cache.find ctxt contract_hash + wrap @@ Script_cache.find ctxt destination in match cached with | Some (_script, ex_script) -> return (ex_script, ctxt) @@ -309,14 +304,15 @@ let verify_execute_outbox_message_operations incr ~loc ~source ~operations return (ctxt, (destination, entrypoint, unparsed_parameters)) | _ -> failwith - "Expected an internal transaction operation, called from %s" + "Expected an internal transaction operation to a smart-contract, \ + called from %s" loc in let* _ctxt, operations_data = List.fold_left_map_es validate_and_extract_operation_params ctxt operations in let compare_data (d1, e1, p1) (d2, e2, p2) = - Contract.equal d1 d2 + Contract_hash.equal d1 d2 && Entrypoint_repr.(e1 = e2) && String.equal (Expr.to_string p1) (Expr.to_string p2) in @@ -324,7 +320,7 @@ let verify_execute_outbox_message_operations incr ~loc ~source ~operations Format.fprintf fmt "(%a, %a, %s)" - Contract.pp + Contract_hash.pp d Entrypoint_repr.pp e @@ -333,7 +329,7 @@ let verify_execute_outbox_message_operations incr ~loc ~source ~operations let transactions_data = let data_of_transaction (contract, entrypoint, params) = let params = Expr.from_string params in - (Contract.Originated contract, entrypoint, params) + (contract, entrypoint, params) in List.map data_of_transaction expected_transactions in -- GitLab From df8243a2bcbbc5f0a8c15a04acb22deee3e8e509 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 14 Apr 2022 19:28:59 +0200 Subject: [PATCH 7/7] Proto: split Transaction_to_contract Fix #2803 --- src/proto_alpha/lib_plugin/view_helpers.ml | 4 ++-- src/proto_alpha/lib_protocol/apply.ml | 8 ++++---- .../lib_protocol/apply_internal_results.ml | 20 ++++--------------- .../lib_protocol/sc_rollup_operations.ml | 4 ++-- .../lib_protocol/script_interpreter_defs.ml | 8 ++++---- .../lib_protocol/script_typed_ir.ml | 17 +++++++++++++--- .../lib_protocol/script_typed_ir.mli | 19 ++++++++++++++++-- .../michelson/test_ticket_accounting.ml | 4 ++-- .../michelson/test_ticket_operations_diff.ml | 4 ++-- .../integration/operations/test_sc_rollup.ml | 4 ++-- .../lib_protocol/ticket_operations_diff.ml | 8 ++++---- .../lib_protocol/tx_rollup_ticket.ml | 4 ++-- 12 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/proto_alpha/lib_plugin/view_helpers.ml b/src/proto_alpha/lib_plugin/view_helpers.ml index b04bbcaf9f1f..29074e758af2 100644 --- a/src/proto_alpha/lib_plugin/view_helpers.ml +++ b/src/proto_alpha/lib_plugin/view_helpers.ml @@ -220,9 +220,9 @@ let extract_parameter_from_operations entrypoint operations callback = Script_typed_ir.Internal_operation { operation = - Transaction_to_contract + Transaction_to_smart_contract { - destination = Originated destination; + destination; unparsed_parameters; entrypoint = _; amount = _; diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index b996e1234f64..3462c7fb0d97 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1098,9 +1098,9 @@ let apply_internal_manager_operation_content : comparing it with the [ctxt] we will have at the end of the application). *) match operation with - | Transaction_to_contract + | Transaction_to_implicit { - destination = Implicit pkh; + destination = pkh; amount; unparsed_parameters = _; entrypoint; @@ -1121,10 +1121,10 @@ let apply_internal_manager_operation_content : (ITransaction_result res : kind successful_internal_manager_operation_result), ops ) - | Transaction_to_contract + | Transaction_to_smart_contract { amount; - destination = Originated contract_hash; + destination = contract_hash; entrypoint; location; parameters_ty; diff --git a/src/proto_alpha/lib_protocol/apply_internal_results.ml b/src/proto_alpha/lib_protocol/apply_internal_results.ml index e3676907b011..01dc7fd8a2da 100644 --- a/src/proto_alpha/lib_protocol/apply_internal_results.ml +++ b/src/proto_alpha/lib_protocol/apply_internal_results.ml @@ -64,14 +64,8 @@ let contents_of_internal_operation (type kind) kind internal_contents = let operation : kind internal_manager_operation = match operation with - | Transaction_to_contract - { - destination = Implicit destination; - amount; - entrypoint; - unparsed_parameters; - _; - } -> + | Transaction_to_implicit + {destination; amount; entrypoint; unparsed_parameters; _} -> Transaction { destination = Contract (Implicit destination); @@ -79,14 +73,8 @@ let contents_of_internal_operation (type kind) entrypoint; parameters = Script.lazy_expr unparsed_parameters; } - | Transaction_to_contract - { - destination = Originated destination; - amount; - entrypoint; - unparsed_parameters; - _; - } -> + | Transaction_to_smart_contract + {destination; amount; entrypoint; unparsed_parameters; _} -> Transaction { destination = Contract (Originated destination); diff --git a/src/proto_alpha/lib_protocol/sc_rollup_operations.ml b/src/proto_alpha/lib_protocol/sc_rollup_operations.ml index 378b2891d3fa..607bd36b690e 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_operations.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_operations.ml @@ -200,9 +200,9 @@ let to_transaction_operation ctxt ~source *) let* ctxt = validate_parameters_ty ctxt parameters_ty in let operation = - Script_typed_ir.Transaction_to_contract + Script_typed_ir.Transaction_to_smart_contract { - destination = Contract.Originated destination; + destination; amount = Tez.zero; entrypoint; location = Micheline.dummy_location; diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index eb8b49e43be4..bb8b2c51d31a 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -488,8 +488,8 @@ let make_transaction_to_contract ctxt ~(destination : Contract.t) ~amount >|? fun ctxt -> let unparsed_parameters = Micheline.strip_locations unparsed_parameters in match destination with - | Implicit _ -> - ( Transaction_to_contract + | Implicit destination -> + ( Transaction_to_implicit { destination; amount; @@ -500,8 +500,8 @@ let make_transaction_to_contract ctxt ~(destination : Contract.t) ~amount unparsed_parameters; }, ctxt ) - | Originated _ -> - ( Transaction_to_contract + | Originated destination -> + ( Transaction_to_smart_contract { destination; amount; diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index cc5879aa236b..acf49b862290 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -1340,8 +1340,18 @@ and ('input, 'output) view_signature = -> ('input, 'output) view_signature and 'kind manager_operation = - | Transaction_to_contract : { - destination : Contract.t; + | Transaction_to_implicit : { + destination : Signature.Public_key_hash.t; + amount : Tez.tez; + entrypoint : Entrypoint.t; + location : Script.location; + parameters_ty : ('a, _) ty; + parameters : 'a; + unparsed_parameters : Script.expr; + } + -> Kind.transaction manager_operation + | Transaction_to_smart_contract : { + destination : Contract_hash.t; amount : Tez.tez; entrypoint : Entrypoint.t; location : Script.location; @@ -1424,7 +1434,8 @@ type packed_manager_operation = let manager_kind : type kind. kind manager_operation -> kind Kind.manager = function - | Transaction_to_contract _ -> Kind.Transaction_manager_kind + | Transaction_to_implicit _ -> Kind.Transaction_manager_kind + | Transaction_to_smart_contract _ -> Kind.Transaction_manager_kind | Transaction_to_tx_rollup _ -> Kind.Transaction_manager_kind | Transaction_to_sc_rollup _ -> Kind.Transaction_manager_kind | Transaction_to_event _ -> Kind.Transaction_manager_kind diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index 35eee3e9b30a..51b35351a73f 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -1471,13 +1471,28 @@ and ('input, 'output) view_signature = -> ('input, 'output) view_signature and 'kind manager_operation = - | Transaction_to_contract : { + | Transaction_to_implicit : { (* The [unparsed_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]). *) - destination : Contract.t; + destination : Signature.Public_key_hash.t; + amount : Tez.tez; + entrypoint : Entrypoint.t; + location : Script.location; + parameters_ty : ('a, _) ty; + parameters : 'a; + unparsed_parameters : Script.expr; + } + -> Kind.transaction manager_operation + | Transaction_to_smart_contract : { + (* The [unparsed_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]). *) + destination : Contract_hash.t; amount : Tez.tez; entrypoint : Entrypoint.t; location : Script.location; 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 11d81e61170f..61068795b30a 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 @@ -391,12 +391,12 @@ let transfer_operation ctxt ~src ~destination ~arg_type ~arg = { source = src; operation = - Transaction_to_contract + Transaction_to_smart_contract { amount = Tez.zero; unparsed_parameters = Micheline.strip_locations params_node; entrypoint = Entrypoint.default; - destination = Contract.Originated destination; + 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 cb03583c9f40..2080c05f9014 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 @@ -320,12 +320,12 @@ let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = { source = src; operation = - Transaction_to_contract + Transaction_to_smart_contract { amount = Tez.zero; unparsed_parameters = Micheline.strip_locations params_node; entrypoint = Entrypoint.default; - destination = Contract.Originated destination; + destination; location = Micheline.dummy_location; parameters_ty; parameters; diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml index 0cfe9d1210d0..c3286cc863d8 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -236,9 +236,9 @@ let verify_execute_outbox_message_operations incr ~loc ~source ~operations { source = op_source; operation = - Transaction_to_contract + Transaction_to_smart_contract { - destination = Originated destination; + destination; amount; entrypoint; location = _; diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index d965bb84155a..4608d462c314 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -174,13 +174,13 @@ let tickets_of_origination ctxt ~allow_zero_amount_tickets ~preorigination let tickets_of_operation ctxt ~allow_zero_amount_tickets (Script_typed_ir.Internal_operation {source = _; operation; nonce = _}) = match operation with - | Transaction_to_contract {destination = Implicit _; _} -> return (None, ctxt) - | Transaction_to_contract + | Transaction_to_implicit _ -> return (None, ctxt) + | Transaction_to_smart_contract { amount = _; unparsed_parameters = _; entrypoint = _; - destination = Originated _ as contract; + destination; location = _; parameters_ty; parameters; @@ -188,7 +188,7 @@ let tickets_of_operation ctxt ~allow_zero_amount_tickets tickets_of_transaction ctxt ~allow_zero_amount_tickets - ~destination:(Destination.Contract contract) + ~destination:(Destination.Contract (Originated destination)) ~parameters_ty ~parameters | Transaction_to_tx_rollup diff --git a/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml b/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml index d7907b674b03..368d6b904559 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml +++ b/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml @@ -78,11 +78,11 @@ let parse_ticket_and_operation ~consume_deserialization_gas ~ticketer ~contents source; nonce; operation = - Transaction_to_contract + Transaction_to_smart_contract { amount = Tez.zero; unparsed_parameters; - destination = Contract.Originated destination; + destination; entrypoint; location = Micheline.location parameters_expr; parameters_ty = ticket_ty; -- GitLab