From 1e77bd82c8a254da59f1bbbd290d6fe9775c50d3 Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Thu, 5 Mar 2020 10:27:25 -0600 Subject: [PATCH 1/3] Revert "Use unlimited gas for typechecking contract" This reverts commit 97aad1c5ea65375d464a278495cb3dc696c28c70. --- vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml b/vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml index 06b740983..a8f5aa468 100644 --- a/vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml +++ b/vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml @@ -1111,8 +1111,7 @@ type typecheck_res = let typecheck_contract contract = let contract' = Tezos_micheline.Micheline.strip_locations contract in - let ctxt = Raw_context.set_gas_unlimited dummy_environment.tezos_context in - Script_ir_translator.typecheck_code ctxt contract' >>= fun x -> + Script_ir_translator.typecheck_code dummy_environment.tezos_context contract' >>= fun x -> match x with | Ok _res -> return Type_checked | Error (Script_tc_errors.Ill_formed_type (Some "parameter", _code, _)::_) -> return Err_parameter From fe84d2120836786e61eaf0e8a1dde0495f5e570f Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Thu, 5 Mar 2020 10:27:34 -0600 Subject: [PATCH 2/3] Hack: don't log types in Michelson typecheck_code --- vendors/ligo-utils/tezos-protocol-alpha/script_ir_translator.ml | 2 -- 1 file changed, 2 deletions(-) diff --git a/vendors/ligo-utils/tezos-protocol-alpha/script_ir_translator.ml b/vendors/ligo-utils/tezos-protocol-alpha/script_ir_translator.ml index df884eb02..a369758f4 100644 --- a/vendors/ligo-utils/tezos-protocol-alpha/script_ir_translator.ml +++ b/vendors/ligo-utils/tezos-protocol-alpha/script_ir_translator.ml @@ -5325,8 +5325,6 @@ let typecheck_code : }) ctxt ~legacy - ~type_logger:(fun loc bef aft -> - type_map := (loc, (bef, aft)) :: !type_map) (arg_type_full, None) ret_type_full code_field From d10b95357fb817d4770d0fd983f5b45ec089ed66 Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Thu, 5 Mar 2020 10:30:44 -0600 Subject: [PATCH 3/3] Detect gas exhaustion while typechecking --- src/main/compile/of_michelson.ml | 4 ++++ vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main/compile/of_michelson.ml b/src/main/compile/of_michelson.ml index 87cfbb5a7..3602a495e 100644 --- a/src/main/compile/of_michelson.ml +++ b/src/main/compile/of_michelson.ml @@ -23,6 +23,9 @@ module Errors = struct let code = Format.asprintf "%a" Michelson.pp c in "bad contract type\n"^code in error title_type_check_msg message + let ran_out_of_gas () = + let message () = "Ran out of gas!" in + error title_type_check_msg message let unknown () = let message () = "unknown error" in @@ -47,6 +50,7 @@ let build_contract : Compiler.compiled_expression -> Michelson.michelson result | Err_parameter -> fail @@ Errors.bad_parameter contract () | Err_storage -> fail @@ Errors.bad_storage contract () | Err_contract -> fail @@ Errors.bad_contract contract () + | Err_gas -> fail @@ Errors.ran_out_of_gas () | Err_unknown -> fail @@ Errors.unknown () type check_type = Check_parameter | Check_storage diff --git a/vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml b/vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml index a8f5aa468..d5d1b3ab7 100644 --- a/vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml +++ b/vendors/ligo-utils/proto-alpha-utils/x_memory_proto_alpha.ml @@ -1107,6 +1107,7 @@ let unparse_ty_michelson ty = type typecheck_res = | Type_checked | Err_parameter | Err_storage | Err_contract + | Err_gas | Err_unknown let typecheck_contract contract = @@ -1116,6 +1117,7 @@ let typecheck_contract contract = | Ok _res -> return Type_checked | Error (Script_tc_errors.Ill_formed_type (Some "parameter", _code, _)::_) -> return Err_parameter | Error (Script_tc_errors.Ill_formed_type (Some "storage", _code, _)::_) -> return Err_storage + | Error (Script_tc_errors.Ill_typed_contract _ :: Script_tc_errors.Cannot_serialize_error :: []) -> return @@ Err_gas | Error (Script_tc_errors.Ill_typed_contract (_code, _)::_) -> return @@ Err_contract | Error _ -> return Err_unknown