diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml index c17d05536da3c3a49c4b1febd4f7bf8ba770254b..22650f4a9bc50db076202eed6585cb101d76ab78 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml @@ -3252,7 +3252,6 @@ module Registration_section = struct ty = unit_t; k = halt; loc = dummy_loc; - addr = Contract_event_repr.Hash.zero; tag = Entrypoint_repr.default; }) () diff --git a/src/proto_alpha/lib_client/client_proto_programs.ml b/src/proto_alpha/lib_client/client_proto_programs.ml index 73b4710ffb9552da22dbb64e51e609f594626266..e2e7d31e3803719f9df725ee37a1a49f05879354 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.ml +++ b/src/proto_alpha/lib_client/client_proto_programs.ml @@ -388,7 +388,3 @@ let print_unreachables (cctxt : #Client_context.printer) ~emacs ?script_name ?script_name ~on_errors:(print_errors cctxt ~show_source ~parsed) ty - -let get_event_address cctxt ~chain ~block ~ty = - Plugin.RPC.Scripts.get_event_address cctxt (chain, block) ~ty - >>=? fun address -> return address diff --git a/src/proto_alpha/lib_client/client_proto_programs.mli b/src/proto_alpha/lib_client/client_proto_programs.mli index ce698a75ab678790a72f00447ef0bc21dfa8ea64..c18ecad250bbcaa3d57b7efc0d73e4e14ed55ffa 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.mli +++ b/src/proto_alpha/lib_client/client_proto_programs.mli @@ -234,12 +234,3 @@ val print_unreachables : parsed:Michelson_v1_parser.parsed -> Michelson_v1_primitives.prim list list tzresult -> unit tzresult Lwt.t - -(** A service implementation to compute the event address - for a given event tag and a Michelson event type definition *) -val get_event_address : - #Protocol_client_context.rpc_context -> - chain:Chain_services.chain -> - block:Block_services.block -> - ty:Alpha_context.Script.expr -> - Alpha_context.Contract_event.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index cee64993f065097dc5036a65c3ff86b00c7e7685..56ab154b1309ab91797d72fed17243e218786130 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -103,14 +103,14 @@ let pp_internal_operation ppf (Internal_contents {operation; source; _}) = match delegate_opt with | None -> Format.pp_print_string ppf "nobody" | Some delegate -> Signature.Public_key_hash.pp ppf delegate) - | Event {addr; tag; payload} -> + | Event {ty; tag; payload} -> Format.fprintf ppf - "Event:@,From: %a@,To: %a" + "Event:@,From: %a@,Type: %a" Contract.pp source - Contract_event.pp - addr ; + pp_micheline_expr + ty ; if not (Entrypoint.is_default tag) then Format.fprintf ppf "@,Tag: %a" Entrypoint.pp tag ; Format.fprintf ppf "@,Payload: %a" pp_micheline_expr payload) ; diff --git a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml index 1f12d3a964e87cf04e465c71c27b0ed2ee75b5c5..d82c6be1bc6c8e9a372a055057149908d1129358 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml @@ -1049,23 +1049,4 @@ let commands () = unlimited_gas; } >>= fun res -> print_view_result cctxt res); - command - ~group - ~desc:"Compute the event address associated with a tag and a data type." - no_options - (prefixes ["get"; "event"; "address"] - @@ param ~name:"type" ~desc:"the type of the event data" data_parameter - @@ stop) - (fun () ty cctxt -> - Client_proto_programs.get_event_address - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~ty:ty.expanded - >>=? fun addr -> - cctxt#message - "@[Event address: @,%a@]@." - Contract_event_repr.pp - addr - >|= ok); ] diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index dd9c58546ded1363bb253e5ac59a241bc13a5715..b50281b9a827183f7fa68eed6cd97ffbf181867d 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -459,16 +459,6 @@ module Scripts = struct []) (req "entrypoints" (assoc Script.expr_encoding))) RPC_path.(path / "entrypoints") - - (** [get_event_address] is a RPC service to compute the contract event address - for the input tag and Michelson event type definition. *) - let get_event_address = - RPC_service.post_service - ~description:"Return the event address for the given tag and data type" - ~input:(obj1 (req "type" Script.expr_encoding)) - ~output:(obj1 (req "address" Contract_event.Hash.encoding)) - ~query:RPC_query.empty - RPC_path.(path / "event_address") end module type UNPARSING_MODE = sig @@ -1503,14 +1493,7 @@ module Scripts = struct Micheline.strip_locations original_type_expr ) :: acc) map - [] ) )) ; - Registration.register0 - ~chunked:false - S.get_event_address - (fun ctxt () ty_node -> - let ctxt = Gas.set_unlimited ctxt in - Script_ir_translator.hash_event_ty ctxt (Micheline.root ty_node) - >>?= fun (address, _) -> return address) + [] ) )) let run_code ?unparsing_mode ?gas ?(entrypoint = Entrypoint.default) ?balance ~script ~storage ~input ~amount ~chain_id ~source ~payer ~self ~now ~level @@ -1651,10 +1634,6 @@ module Scripts = struct let list_entrypoints ctxt block ~script = RPC_context.make_call0 S.list_entrypoints ctxt block () script - - (** [get_event_address] makes a call to the service to compute an event address *) - let get_event_address ~ty ctxt block = - RPC_context.make_call0 S.get_event_address ctxt block () ty end module Contract = struct diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index fe26d8b662419b38c292a7a815745e1618427804..d2721dc3416603c37b385b3bd699f8347a06b319 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -58,7 +58,6 @@ "Sc_rollup_commitment_repr", "Sc_rollup_proof_repr", "Sc_rollup_game_repr", - "Contract_event_repr", "Tx_rollup_level_repr", "Tx_rollup_l2_proof", "Tx_rollup_l2_address", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 7be3af7d02c0105a52cdc03ab247208ed3ae2398..04b2d6c0abaeaa327f795f351068cdef9e3ade2d 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -259,8 +259,6 @@ module Script = struct Gas.consume_from available_gas gas_cost end -module Contract_event = Contract_event_repr - module Level = struct include Level_repr include Level_storage diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 07bf0c12bb43f5085434517541446b4357bbbe59..78c2da2971faa8f899958ddd6c103896a5fd6a37 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2345,19 +2345,6 @@ module Bond_id : sig end end -(** Contract_event exposes fields for event data access. See [Contract_event_repr]. *) -module Contract_event : sig - module Hash : module type of Contract_event_repr.Hash - - type t = Hash.t - - val in_memory_size : t -> Cache_memory_helpers.sint - - val to_b58check : t -> string - - val pp : Format.formatter -> t -> unit -end - (** This module re-exports definitions from {!Receipt_repr}. *) module Receipt : sig type balance = diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index d4d67dd761faa55559c2f60b1646eeff8d13ba65..b6fc73d5b79997badef41351ca5f47b2d9cf9fae 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1187,7 +1187,7 @@ let apply_internal_manager_operation_content : Transaction_to_sc_rollup_result {consumed_gas; inbox_after} in (ctxt, ITransaction_result result, []) - | Event {addr = _; unparsed_data = _; tag = _} -> + | Event {ty = _; unparsed_data = _; tag = _} -> return ( ctxt, IEvent_result diff --git a/src/proto_alpha/lib_protocol/apply_internal_results.ml b/src/proto_alpha/lib_protocol/apply_internal_results.ml index ae4687d5e89dcb79c7f0203815cf7c8c3533e182..09d5f14bc5e58f5a19368dba541a8fe9403f2d2a 100644 --- a/src/proto_alpha/lib_protocol/apply_internal_results.ml +++ b/src/proto_alpha/lib_protocol/apply_internal_results.ml @@ -45,7 +45,7 @@ type 'kind internal_manager_operation = Signature.Public_key_hash.t option -> Kind.delegation internal_manager_operation | Event : { - addr : Contract_event.t; + ty : Script.expr; tag : Entrypoint.t; payload : Script.expr; } @@ -106,8 +106,7 @@ let contents_of_internal_operation (type kind) entrypoint; parameters = Script.lazy_expr unparsed_parameters; } - | Event {addr; tag; unparsed_data} -> - Event {addr; tag; payload = unparsed_data} + | Event {ty; tag; unparsed_data} -> Event {ty; tag; payload = unparsed_data} | Origination {delegate; code; unparsed_storage; credit; _} -> let script = { @@ -425,7 +424,7 @@ module Internal_result = struct name = "event"; encoding = obj3 - (req "addr" Contract_event.Hash.encoding) + (req "type" Script.expr_encoding) (opt "tag" Entrypoint.smart_encoding) (opt "payload" Script.expr_encoding); iselect : Kind.event iselect = @@ -437,17 +436,17 @@ module Internal_result = struct select = (function Manager (Event _ as op) -> Some op | _ -> None); proj = (function - | Event {addr; tag; payload} -> + | Event {ty; tag; payload} -> let tag = if Entrypoint.is_default tag then None else Some tag in let payload = if Script_repr.is_unit payload then None else Some payload in - (addr, tag, payload)); + (ty, tag, payload)); inj = - (fun (addr, tag, payload) -> + (fun (ty, tag, payload) -> let tag = Option.value ~default:Entrypoint.default tag in let payload = Option.value ~default:Script_repr.unit payload in - Event {addr; tag; payload}); + Event {ty; tag; payload}); } let case tag name args proj inj = diff --git a/src/proto_alpha/lib_protocol/apply_internal_results.mli b/src/proto_alpha/lib_protocol/apply_internal_results.mli index 0fe963b67a78f4bada6f0e3e48fa87f215983d19..a827d2a18035de9277ebb106fb742f834ddc1c08 100644 --- a/src/proto_alpha/lib_protocol/apply_internal_results.mli +++ b/src/proto_alpha/lib_protocol/apply_internal_results.mli @@ -48,7 +48,7 @@ type 'kind internal_manager_operation = Signature.Public_key_hash.t option -> Kind.delegation internal_manager_operation | Event : { - addr : Contract_event.t; + ty : Script.expr; tag : Entrypoint.t; payload : Script.expr; } diff --git a/src/proto_alpha/lib_protocol/contract_event_repr.ml b/src/proto_alpha/lib_protocol/contract_event_repr.ml deleted file mode 100644 index 639f4c01ede04d5abbb06f9a637c629a737e62e0..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_protocol/contract_event_repr.ml +++ /dev/null @@ -1,68 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Marigold *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -type error += (* `Permanent *) Invalid_event_notation of string - -module Hash = struct - let prefix = "\058\017\082" (* "ev1" (32) *) - - module H = - Blake2B.Make - (Base58) - (struct - let name = "Event" - - let title = "Event sink" - - let b58check_prefix = prefix - - let size = None - end) - - include H - - let () = Base58.check_encoded_prefix b58check_encoding "ev1" 53 - - include Path_encoding.Make_hex (H) -end - -type t = Hash.t - -let of_b58data = function Hash.Data hash -> Some hash | _ -> None - -let pp = Hash.pp - -let of_b58check_opt s = Option.bind (Base58.decode s) of_b58data - -let of_b58check s = - match of_b58check_opt s with - | Some hash -> ok hash - | None -> error (Invalid_event_notation s) - -let to_b58check hash = Hash.to_b58check hash - -let in_memory_size _ = - let open Cache_memory_helpers in - h1w +! string_size_gen Hash.size diff --git a/src/proto_alpha/lib_protocol/contract_event_repr.mli b/src/proto_alpha/lib_protocol/contract_event_repr.mli deleted file mode 100644 index adeeff40a82955255a174499f6966cbabe23f2d0..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_protocol/contract_event_repr.mli +++ /dev/null @@ -1,54 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Marigold *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -module Hash : sig - val prefix : string - - include S.HASH -end - -type t = Hash.t - -(** [in_memory_size event_addr] returns the number of bytes [event_addr] - uses in RAM. *) -val in_memory_size : t -> Cache_memory_helpers.sint - -(** [to_b58check addr] converts the event address [addr] to the Base58Check string representation *) -val to_b58check : t -> string - -(** Pretty printer for contract events *) -val pp : Format.formatter -> t -> unit - -(** [of_b58data data] tries to decode a contract event from a Base58 [data] and - return [None] if conversion fails *) -val of_b58data : Base58.data -> t option - -(** [of_b58check addr] tries to decode a contract event from a Base58Check string [addr] *) -val of_b58check : string -> t tzresult - -(** [of_b58check_opt addr] tries to - decode a contract event from a Base58Check string [addr] - and return [None] if conversion fails *) -val of_b58check_opt : string -> t option diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index fd50f9e81e573ebaf68523473cf1ef7159e6de08..3cdca5d6ad10f91b37aa7b9569cdf1c0ff0b8248 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -87,7 +87,6 @@ Sc_rollup_commitment_repr Sc_rollup_proof_repr Sc_rollup_game_repr - Contract_event_repr Tx_rollup_level_repr Tx_rollup_l2_proof Tx_rollup_l2_address @@ -329,7 +328,6 @@ sc_rollup_commitment_repr.ml sc_rollup_commitment_repr.mli sc_rollup_proof_repr.ml sc_rollup_proof_repr.mli sc_rollup_game_repr.ml sc_rollup_game_repr.mli - contract_event_repr.ml contract_event_repr.mli tx_rollup_level_repr.ml tx_rollup_level_repr.mli tx_rollup_l2_proof.ml tx_rollup_l2_proof.mli tx_rollup_l2_address.ml tx_rollup_l2_address.mli @@ -552,7 +550,6 @@ sc_rollup_commitment_repr.ml sc_rollup_commitment_repr.mli sc_rollup_proof_repr.ml sc_rollup_proof_repr.mli sc_rollup_game_repr.ml sc_rollup_game_repr.mli - contract_event_repr.ml contract_event_repr.mli tx_rollup_level_repr.ml tx_rollup_level_repr.mli tx_rollup_l2_proof.ml tx_rollup_l2_proof.mli tx_rollup_l2_address.ml tx_rollup_l2_address.mli @@ -780,7 +777,6 @@ sc_rollup_commitment_repr.ml sc_rollup_commitment_repr.mli sc_rollup_proof_repr.ml sc_rollup_proof_repr.mli sc_rollup_game_repr.ml sc_rollup_game_repr.mli - contract_event_repr.ml contract_event_repr.mli tx_rollup_level_repr.ml tx_rollup_level_repr.mli tx_rollup_l2_proof.ml tx_rollup_l2_proof.mli tx_rollup_l2_address.ml tx_rollup_l2_address.mli diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 257f9ff67e5b1a6003c144333abd52677ede4048..e533fad48ef34c823dbc0ae0923fc9bd3ba54c55 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1532,9 +1532,9 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = | Bogus_opening -> R true) in (step [@ocaml.tailcall]) g gas k ks accu stack - | IEmit {tag; ty = event_type; k; addr = event_address; loc = _} -> + | IEmit {tag; ty = event_type; k; loc} -> let event_data = accu in - emit_event (ctxt, sc) gas ~event_address ~event_type ~tag ~event_data + emit_event (ctxt, sc) gas ~loc ~event_type ~tag ~event_data >>=? fun (accu, ctxt, gas) -> (step [@ocaml.tailcall]) (ctxt, sc) gas k ks accu stack) diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index a996197f4412db4c0b5dc07888cb4713acfdf05b..0343f9bebbda87ea23b5244c34061d2464ea38ea 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -566,8 +566,8 @@ let make_transaction_to_sc_rollup ctxt ~destination ~amount ~entrypoint (** [emit_event] generates an internal operation that will effect an event emission if the contract code returns this successfully. *) -let emit_event (type t tc) (ctxt, sc) gas ~event_address - ~(event_type : (t, tc) ty) ~tag ~(event_data : t) = +let emit_event (type t tc) (ctxt, sc) gas ~loc ~(event_type : (t, tc) ty) ~tag + ~(event_data : t) = let ctxt = update_context gas ctxt in (* No need to take care of lazy storage as only packable types are allowed *) let lazy_storage_diff = None in @@ -576,7 +576,10 @@ let emit_event (type t tc) (ctxt, sc) gas ~event_address Gas.consume ctxt (Script.strip_locations_cost unparsed_data) >>?= fun ctxt -> let unparsed_data = Micheline.strip_locations unparsed_data in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> - let operation = Event {addr = event_address; tag; unparsed_data} in + unparse_ty ~loc ctxt event_type >>?= fun (unparsed_ty, ctxt) -> + Gas.consume ctxt (Script.strip_locations_cost unparsed_ty) >>?= fun ctxt -> + let unparsed_ty = Micheline.strip_locations unparsed_ty in + let operation = Event {ty = unparsed_ty; tag; unparsed_data} in let iop = {source = Contract.Originated sc.self; operation; nonce} in let res = {piop = Internal_operation iop; lazy_storage_diff} in let gas, ctxt = local_gas_counter_and_outdated_context ctxt in diff --git a/src/proto_alpha/lib_protocol/script_interpreter_logging.ml b/src/proto_alpha/lib_protocol/script_interpreter_logging.ml index 1a325f56c5d28c75196244a0b8a68f96c643b443..ef7a267712ddaae66df3e1be88099f071cb578b2 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_logging.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_logging.ml @@ -1586,14 +1586,14 @@ let kinstr_split : continuation = k; reconstruct = (fun k -> IMin_block_time (loc, k)); } - | IEmit {loc; ty; addr; tag; k}, Item_t (_, s) -> + | IEmit {loc; ty; tag; k}, Item_t (_, s) -> let s = Item_t (operation_t, s) in ok @@ Ex_split_kinstr { cont_init_stack = s; continuation = k; - reconstruct = (fun k -> IEmit {loc; ty; addr; tag; k}); + reconstruct = (fun k -> IEmit {loc; ty; tag; k}); } | IEmit _, Bot_t -> . | IHalt loc, _s -> ok @@ Ex_split_halt loc diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 153be876f8fe4ffe77f5f2de0917f188e1bbc224..7dcabe585ff4cf693ae98b18085c0de1a3cf62a6 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -593,11 +593,6 @@ let hash_comparable_data ctxt ty data = pack_comparable_data ctxt ty data >>=? fun (bytes, ctxt) -> Lwt.return @@ hash_bytes ctxt bytes -let hash_event_ty ctxt unparsed = - pack_node unparsed ctxt >>? fun (bytes, ctxt) -> - Gas.consume ctxt (Michelson_v1_gas.Cost_of.Interpreter.blake2b bytes) - >|? fun ctxt -> (Contract_event.Hash.hash_bytes [bytes], ctxt) - (* ---- Tickets ------------------------------------------------------------ *) (* @@ -4650,8 +4645,7 @@ and[@coq_axiom_with_reason "gadt"] parse_instr : >>?= fun (Ex_ty ty, ctxt) -> check_item_ty ctxt ty data loc I_EMIT 1 2 >>?= fun (Eq, ctxt) -> parse_entrypoint_annot_strict loc annot >>?= fun tag -> - hash_event_ty ctxt ty_node >>?= fun (addr, ctxt) -> - let instr = {apply = (fun k -> IEmit {loc; tag; ty = data; addr; k})} in + let instr = {apply = (fun k -> IEmit {loc; tag; ty = data; k})} in typed ctxt loc instr (Item_t (Operation_t, rest)) (* Primitive parsing errors *) | ( Prim diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.mli b/src/proto_alpha/lib_protocol/script_ir_translator.mli index 995a6aa199650148a4fe299a333dd8fd2e1fa2c2..cd0e7a8e8bdd662643cc015844a84536835f72fa 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.mli +++ b/src/proto_alpha/lib_protocol/script_ir_translator.mli @@ -427,12 +427,6 @@ val hash_data : 'a -> (Script_expr_hash.t * context) tzresult Lwt.t -(** [hash_event_ty ctxt ty_node] generates a contract event address - from the original Michelson type as specified by - the original node [ty_node] while accounting for the necessary gas *) -val hash_event_ty : - context -> Script.node -> (Contract_event.t * context) tzresult - type lazy_storage_ids val no_lazy_storage_id : lazy_storage_ids diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index f3d48409dfe3741d7c4b8f6b6fb835bf48eb9c0b..c4c3c4ab5c6a6e0436be68b6d99b60320d5fb4b0 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -1085,7 +1085,6 @@ and ('before_top, 'before, 'result_top, 'result) kinstr = kinstr | IEmit : { loc : Script.location; - addr : Contract_event.t; tag : Entrypoint.t; ty : ('a, _) ty; k : (operation, 's, 'r, 'f) kinstr; @@ -1376,7 +1375,7 @@ and 'kind manager_operation = } -> Kind.transaction manager_operation | Event : { - addr : Contract_event.t; + ty : Script.expr; tag : Entrypoint.t; unparsed_data : Script.expr; } diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index 584078aa6e8d5a47b0d75c504c3742dbdc172db6..229a60e7d7b4935e0afcf2dc72133f5c222e2429 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -1082,7 +1082,6 @@ and ('before_top, 'before, 'result_top, 'result) kinstr = kinstr | IEmit : { loc : Script.location; - addr : Contract_event.t; tag : Entrypoint.t; ty : ('a, _) ty; k : (operation, 's, 'r, 'f) kinstr; @@ -1517,7 +1516,7 @@ and 'kind manager_operation = } -> Kind.transaction manager_operation | Event : { - addr : Contract_event.t; + ty : Script.expr; tag : Entrypoint.t; unparsed_data : Script.expr; } diff --git a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml index 7b52a9c2c836d1a638ccd64798794cfb604fcaef..6b7bfc56d22d64ee5b8b73c63f318f22c56aaf77 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml @@ -615,13 +615,10 @@ and kinstr_size : | IJoin_tickets (loc, cty, k) -> ret_succ_adding (accu ++ ty_size cty) (base1 loc k +! word_size) | IOpen_chest (loc, k) -> ret_succ_adding accu (base1 loc k) - | IEmit {loc; tag; ty; addr; k} -> + | IEmit {loc; tag; ty; k} -> ret_succ_adding (accu ++ ty_size ty) - (base1 loc k - +! Entrypoint.in_memory_size tag - +! (word_size *? 3) - +! Contract_event.in_memory_size addr) + (base1 loc k +! Entrypoint.in_memory_size tag +! (word_size *? 2)) | IHalt loc -> ret_succ_adding accu (base0 loc) | ILog _ -> (* This instruction is ignored because it is only used for testing. diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_contract_event.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_contract_event.ml index fb4fbbe0714a88e40143d206b93656f679530644..217f9eb453065abfda00800d7bd5d366846214b0 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_contract_event.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_contract_event.ml @@ -85,14 +85,14 @@ let contract_test () = Internal_manager_operation_result ( { operation = - Event {tag = tag1; payload = data1; addr = addr1}; + Event {tag = tag1; payload = data1; ty = ty1}; _; }, Applied (IEvent_result _) ); Internal_manager_operation_result ( { operation = - Event {tag = tag2; payload = data2; addr = addr2}; + Event {tag = tag2; payload = data2; ty = ty2}; _; }, Applied (IEvent_result _) ); @@ -109,12 +109,18 @@ let contract_test () = match root data2 with | Prim (_, D_Left, [Int (_, n)], _) -> assert (Z.to_int n = 2) | _ -> assert false) ; - let addr1 = Contract_event.to_b58check addr1 in - let addr2 = Contract_event.to_b58check addr2 in assert (Entrypoint.to_string tag1 = "tag1") ; assert (Entrypoint.to_string tag2 = "tag2") ; - assert (addr1 = "ev12m5E1yW14mc9rsrcdGAWVfDSdmRGuctykrVU55bHZBGv9kmdhW") ; - assert (addr2 = "ev12m5E1yW14mc9rsrcdGAWVfDSdmRGuctykrVU55bHZBGv9kmdhW") ; + (match root ty1 with + | Prim (_, T_or, [Prim (_, T_nat, [], []); Prim (_, T_string, [], [])], []) + -> + () + | _ -> assert false) ; + (match root ty2 with + | Prim (_, T_or, [Prim (_, T_nat, [], []); Prim (_, T_string, [], [])], []) + -> + () + | _ -> assert false) ; return_unit | _ -> assert false diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml index 6ede9e83c71528283a89288e684e65b40496a104..fe813692e223d0ff580085609a31ed928ba56a20 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml @@ -967,14 +967,7 @@ let check_kinstr_size () = Kinstr ("IOpen_chest", IOpen_chest (loc, halt ())); Kinstr ( "IEmit", - IEmit - { - loc; - addr = Contract_event_repr.Hash.zero; - tag = entrypoint "entry"; - ty = Unit_t; - k = halt (); - } ); + IEmit {loc; tag = entrypoint "entry"; ty = Unit_t; k = halt ()} ); Kinstr ("IHalt ()", halt ()); ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--emit.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--emit.tz].out index 06520e911c7ba97ecd1b7b8bec24cf538fedf162..79ab213c7a63df1a8a2f6c2a66a30b52676fe611 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--emit.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--emit.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[opcodes/emit.tz] Well typed -Gas remaining: 1039987.674 units remaining +Gas remaining: 1039990.816 units remaining { parameter unit ; storage unit ; code { DROP diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[emit.tz-Unit-Unit-Unit].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[emit.tz-Unit-Unit-Unit].out index c281318efaa184081fdcf81ce43799ed1f5bc7cb..e86c69bed686810759bf4b261d69d697af65e571 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[emit.tz-Unit-Unit-Unit].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[emit.tz-Unit-Unit-Unit].out @@ -5,68 +5,68 @@ storage emitted operations Internal Event: From: KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi - To: ev13o2yWTf9YocjZXWyyHhuTDzoeDuKKe2RmKp9sBnPFeywtpdFsp + Type: (or nat string) Tag: event Payload: (Left 10) Internal Event: From: KT1BEqzn5Wx8uJrZNvuS9DVHmLvG9td3fDLi - To: ev13o2yWTf9YocjZXWyyHhuTDzoeDuKKe2RmKp9sBnPFeywtpdFsp + Type: (or nat string) Tag: event Payload: (Right "lorem ipsum") big_map diff trace - - location: 7 (remaining gas: 1039983.624 units remaining) + - location: 7 (remaining gas: 1039986.766 units remaining) [ (Pair Unit Unit) ] - - location: 7 (remaining gas: 1039983.614 units remaining) + - location: 7 (remaining gas: 1039986.756 units remaining) [ ] - - location: 8 (remaining gas: 1039983.604 units remaining) + - location: 8 (remaining gas: 1039986.746 units remaining) [ Unit ] - - location: 9 (remaining gas: 1039983.594 units remaining) + - location: 9 (remaining gas: 1039986.736 units remaining) [ 10 Unit ] - - location: 12 (remaining gas: 1039983.584 units remaining) + - location: 12 (remaining gas: 1039986.726 units remaining) [ (Left 10) Unit ] - - location: 14 (remaining gas: 1039983.362 units remaining) - [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a + - location: 14 (remaining gas: 1039986.291 units remaining) + [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a Unit ] - - location: 18 (remaining gas: 1039983.352 units remaining) + - location: 18 (remaining gas: 1039986.281 units remaining) [ "lorem ipsum" - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a Unit ] - - location: 21 (remaining gas: 1039983.342 units remaining) + - location: 21 (remaining gas: 1039986.271 units remaining) [ (Right "lorem ipsum") - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a Unit ] - - location: 23 (remaining gas: 1039983.120 units remaining) - [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0508010000000b6c6f72656d20697073756d - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a + - location: 23 (remaining gas: 1039985.836 units remaining) + [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104076403620368ffff056576656e74ff0508010000000b6c6f72656d20697073756d + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a Unit ] - - location: 27 (remaining gas: 1039983.110 units remaining) + - location: 27 (remaining gas: 1039985.826 units remaining) [ {} - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0508010000000b6c6f72656d20697073756d - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104076403620368ffff056576656e74ff0508010000000b6c6f72656d20697073756d + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a Unit ] - - location: 29 (remaining gas: 1039983.100 units remaining) - [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0508010000000b6c6f72656d20697073756d + - location: 29 (remaining gas: 1039985.816 units remaining) + [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104076403620368ffff056576656e74ff0508010000000b6c6f72656d20697073756d {} - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a Unit ] - - location: 30 (remaining gas: 1039983.090 units remaining) - [ { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0508010000000b6c6f72656d20697073756d } - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a + - location: 30 (remaining gas: 1039985.806 units remaining) + [ { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104076403620368ffff056576656e74ff0508010000000b6c6f72656d20697073756d } + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a Unit ] - - location: 31 (remaining gas: 1039983.080 units remaining) - [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a - { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0508010000000b6c6f72656d20697073756d } + - location: 31 (remaining gas: 1039985.796 units remaining) + [ 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a + { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104076403620368ffff056576656e74ff0508010000000b6c6f72656d20697073756d } Unit ] - - location: 32 (remaining gas: 1039983.070 units remaining) - [ { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a ; - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0508010000000b6c6f72656d20697073756d } + - location: 32 (remaining gas: 1039985.786 units remaining) + [ { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a ; + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104076403620368ffff056576656e74ff0508010000000b6c6f72656d20697073756d } Unit ] - - location: 33 (remaining gas: 1039983.060 units remaining) - [ (Pair { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0505000a ; - 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104ac785bfba0f68d61a64f5baa2d45550f6494440a2831f1387df36f41dd770fddffff056576656e74ff0508010000000b6c6f72656d20697073756d } + - location: 33 (remaining gas: 1039985.776 units remaining) + [ (Pair { 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000004076403620368ffff056576656e74ff0505000a ; + 0x011d23c1d3d2f8a4ea5e8784b8f7ecf2ad304c0fe600000104076403620368ffff056576656e74ff0508010000000b6c6f72656d20697073756d } Unit) ] diff --git a/tezt/tests/events.ml b/tezt/tests/events.ml index 584e237332b25be73979de93e8d101b989c7cc92..bf06f4379ccc40ef900bb9a5a0da1751cbf4cffd 100644 --- a/tezt/tests/events.ml +++ b/tezt/tests/events.ml @@ -72,18 +72,21 @@ let test_emit_event protocol = |-> "internal_operation_results" in let event = events |=> 0 in - assert ( - event |-> "addr" |> as_string - = "ev12m5E1yW14mc9rsrcdGAWVfDSdmRGuctykrVU55bHZBGv9kmdhW") ; + let assert_type event = + let ty = event |-> "type" in + assert (ty |-> "prim" |> as_string = "or") ; + let args = ty |-> "args" in + assert (args |=> 0 |-> "prim" |> as_string = "nat") ; + assert (args |=> 1 |-> "prim" |> as_string = "string") + in + assert_type event ; let data = event |-> "payload" in assert (data |-> "prim" |> as_string = "Right") ; assert (data |-> "args" |=> 0 |-> "string" |> as_string = "right") ; let tag = event |-> "tag" |> as_string in assert (tag = "tag1") ; let event = events |=> 1 in - assert ( - event |-> "addr" |> as_string - = "ev12m5E1yW14mc9rsrcdGAWVfDSdmRGuctykrVU55bHZBGv9kmdhW") ; + assert_type event ; let data = event |-> "payload" in assert (data |-> "prim" |> as_string = "Left") ; assert (data |-> "args" |=> 0 |-> "int" |> as_string = "2") ;