diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 3c14dbbd460bbd95d84dc214e38004506de8f0ca..43b9fbb2ffb1e935a247654c25431694c1381b39 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -782,14 +782,12 @@ let apply_delegation ~ctxt ~source ~delegate ~before_operation = Delegate.set ctxt source delegate >|=? fun ctxt -> (ctxt, Gas.consumed ~since:before_operation ~until:ctxt, []) -type 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 ~source ~amount ~pkh ~parameter - ~entrypoint ~before_operation = +type 'loc execution_arg = + | Typed_arg : 'loc * ('a, _) Script_typed_ir.ty * 'a -> 'loc execution_arg + | Untyped_arg : Script.expr -> _ execution_arg + +let apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh ~untyped_parameter + ~external_entrypoint ~before_operation = let contract = Contract.Implicit pkh in (* Transfers of zero to implicit accounts are forbidden. *) error_when Tez.(amount = zero) (Empty_transaction contract) >>?= fun () -> @@ -798,38 +796,34 @@ let apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh ~parameter Contract.allocated ctxt contract >>= fun already_allocated -> Token.transfer ctxt (`Contract source) (`Contract contract) amount >>=? fun (ctxt, balance_updates) -> - 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) + (* Only allow [Unit] parameter to implicit accounts. *) + (match untyped_parameter with + | None -> Result.return_unit + | Some parameter -> ( + match Micheline.root parameter with + | Prim (_, Michelson_v1_primitives.D_Unit, [], _) -> Result.return_unit + | _ -> error (Script_interpreter.Bad_contract_parameter contract))) + >>?= fun () -> + (match external_entrypoint with + | None -> Result.return_unit + | Some entrypoint -> + if Entrypoint.is_default entrypoint then Result.return_unit + else error (Script_tc_errors.No_such_entrypoint entrypoint)) + >>?= fun () -> + let result = + Transaction_to_contract_result + { + storage = None; + lazy_storage_diff = None; + balance_updates; + originated_contracts = []; + consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; + storage_size = Z.zero; + paid_storage_size_diff = Z.zero; + allocated_destination_contract = not already_allocated; + } in - Lwt.return - ( ( (if Entrypoint.is_default entrypoint then Result.return_unit - else error (Script_tc_errors.No_such_entrypoint entrypoint)) - >>? fun () -> - 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_to_contract_result - { - storage = None; - lazy_storage_diff = None; - balance_updates; - originated_contracts = []; - consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; - storage_size = Z.zero; - paid_storage_size_diff = Z.zero; - allocated_destination_contract = not already_allocated; - } - in - (ctxt, result, []) ) + return (ctxt, result, []) let apply_transaction_to_smart_contract ~ctxt ~source ~contract_hash ~amount ~entrypoint ~before_operation ~payer ~chain_id ~internal ~parameter = @@ -1100,23 +1094,14 @@ let apply_internal_operation_contents : comparing it with the [ctxt] we will have at the end of the application). *) match operation with - | Transaction_to_implicit - { - destination = pkh; - amount; - unparsed_parameters = _; - entrypoint; - location; - parameters_ty; - parameters = typed_parameters; - } -> + | Transaction_to_implicit {destination = pkh; amount} -> apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh - ~parameter:(Typed_arg (location, parameters_ty, typed_parameters)) - ~entrypoint + ~untyped_parameter:None + ~external_entrypoint:None ~before_operation:ctxt_before_op >|=? fun (ctxt, res, ops) -> ( ctxt, @@ -1287,8 +1272,8 @@ let apply_manager_operation : ~source:source_contract ~amount ~pkh - ~parameter:(Untyped_arg parameters) - ~entrypoint + ~untyped_parameter:(Some parameters) + ~external_entrypoint:(Some entrypoint) ~before_operation:ctxt_before_op >|=? fun (ctxt, res, ops) -> (ctxt, Transaction_result res, ops) | Transaction diff --git a/src/proto_alpha/lib_protocol/apply_internal_results.ml b/src/proto_alpha/lib_protocol/apply_internal_results.ml index e625c311843b805d573f5c0bb769edbdc1c2b1cf..46f1239f13c3ba7942267a11e09d79547fbef400 100644 --- a/src/proto_alpha/lib_protocol/apply_internal_results.ml +++ b/src/proto_alpha/lib_protocol/apply_internal_results.ml @@ -70,14 +70,13 @@ let internal_operation (type kind) kind internal_operation = let operation : kind internal_operation_contents = match operation with - | Transaction_to_implicit - {destination; amount; entrypoint; unparsed_parameters; _} -> + | Transaction_to_implicit {destination; amount} -> Transaction { destination = Contract (Implicit destination); amount; - entrypoint; - parameters = Script.lazy_expr unparsed_parameters; + entrypoint = Entrypoint.default; + parameters = Script.unit_parameter; } | Transaction_to_smart_contract {destination; amount; entrypoint; unparsed_parameters; _} -> diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index d88d017df3d4af2092ee74f2d2bdef407d4ea23e..bff19c21f1c6670d4e6aba3b1827b8755a0b7878 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -559,25 +559,11 @@ let transfer (type t tc) (ctxt, sc) gas amount location >>=? fun (parameters, lazy_storage_diff, ctxt) -> (match destination with | Typed_implicit destination -> - 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_implicit - { - destination; - amount; - entrypoint; - location; - parameters_ty; - parameters; - unparsed_parameters; - }, - ctxt ) ) + let Unit_t = parameters_ty in + let () = parameters in + (if Entrypoint.is_default entrypoint then Result.return_unit + else error (Script_tc_errors.No_such_entrypoint entrypoint)) + >>?= fun () -> return (Transaction_to_implicit {destination; amount}, ctxt) | Typed_originated destination -> unparse_data ctxt Optimized parameters_ty parameters >>=? fun (unparsed_parameters, ctxt) -> diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 70b8a85d51ef093300733edf54a56877f1d6a127..fd4dc38337444cf9b89a8afc98047fe3b5743fa8 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -1350,11 +1350,6 @@ and 'kind internal_operation_contents = | 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 internal_operation_contents | Transaction_to_smart_contract : { diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index df36a40273641e92042babb380b8156a82444d43..2b7e742450d68af201076e476d9d0747f9155b77 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -1479,18 +1479,8 @@ and ('input, 'output) view_signature = and 'kind internal_operation_contents = | 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_internal_results.internal_operation_contents]). *) 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 internal_operation_contents | Transaction_to_smart_contract : { diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out index 9957977544435f3c81f0bfbf556c306313c514a1..16d12cdc9d92e0181d64bde2f19e80bbedae3502 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out @@ -1,7 +1,7 @@ tests_alpha/test_contract_onchain_opcodes.py::TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b75ba63500a5694fb2ffe174acc2de22d01ccb7259342437f05e1987949f0ad82e9f32e9a0b79cb252d7f7b8236ad728893f4e7150742eefdbeda254970f9fcd92c6228c178e1a923e5600758eb83f2a05edd0be7625657901f2ba81eaf145d003dbef78e33f43a32a3788bdf0501000000085341554349535345 "spsig1PPUFZucuAQybs5wsqsNQ68QNgFaBnVKMFaoZZfi1BtNnuCAWnmL9wVy5HfHkR6AeodjVGxpBVVSYcJKyMURn6K1yknYLm")] Node is bootstrapped. -Estimated gas: 3595.323 units (will add 100 for safety) +Estimated gas: 3595.227 units (will add 100 for safety) Estimated storage: 257 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -29,7 +29,7 @@ This sequence of operations was run: Updated storage: [OPERATION_HASH]48f709699019725ba Storage size: 578 bytes - Consumed gas: 2595.323 + Consumed gas: 2595.227 Internal operations: Internal Transaction: Amount: ꜩ1000 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 0acb80ccdd697333242016b7a3b57cdc1409b3df..c679ce44b3bd6711bc0035a93f929ba387e200d4 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: 7517.954 units (will add 100 for safety) +Estimated gas: 7517.858 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]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01e927f00ef734dfc85919635e9afc9166c83ef9fc00 ; 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes - Consumed gas: 2276.887 + Consumed gas: 2276.791 Internal operations: Internal Transaction: Amount: ꜩ0 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 bfdbdea6eb2dc96ce1962cbec753a9339213b32d..28fb91d67dcbeafd4383373f44a76312fff45c39 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: 5113.582 units (will add 100 for safety) +Estimated gas: 5113.486 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]' @@ -34,7 +34,7 @@ This sequence of operations was run: 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4634 bytes Paid storage size diff: 1 bytes - Consumed gas: 1745.741 + Consumed gas: 1745.645 Balance updates: [CONTRACT_HASH] ... -ꜩ0.00025 storage fees ........................... +ꜩ0.00025 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 fc6290f2a79f28d9f043492a8e28e4a3e697d623..a605e9bb3c96fb0ddf6c7b99d6634525a2b5561f 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: 7012.513 units (will add 100 for safety) +Estimated gas: 7012.321 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01e927f00ef734dfc85919635e9afc9166c83ef9fc00 ; 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes - Consumed gas: 1746.925 + Consumed gas: 1746.733 Internal operations: Internal Transaction: Amount: ꜩ0