2019-09-05 17:21:01 +04:00
|
|
|
(*****************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Open Source License *)
|
|
|
|
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* 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. *)
|
|
|
|
(* *)
|
|
|
|
(*****************************************************************************)
|
|
|
|
|
|
|
|
open Alpha_context
|
|
|
|
open Script
|
|
|
|
open Script_tc_errors
|
|
|
|
|
|
|
|
(* Helpers for encoding *)
|
|
|
|
let type_map_enc =
|
|
|
|
let open Data_encoding in
|
|
|
|
let stack_enc = list (tup2 Script.expr_encoding (list string)) in
|
|
|
|
list
|
|
|
|
(conv
|
|
|
|
(fun (loc, (bef, aft)) -> (loc, bef, aft))
|
|
|
|
(fun (loc, bef, aft) -> (loc, (bef, aft)))
|
|
|
|
(obj3
|
|
|
|
(req "location" Script.location_encoding)
|
|
|
|
(req "stack_before" stack_enc)
|
|
|
|
(req "stack_after" stack_enc)))
|
|
|
|
|
|
|
|
let stack_ty_enc =
|
|
|
|
let open Data_encoding in
|
2020-02-12 20:40:17 +04:00
|
|
|
list (obj2 (req "type" Script.expr_encoding) (dft "annots" (list string) []))
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(* main registration *)
|
|
|
|
let () =
|
|
|
|
let open Data_encoding in
|
|
|
|
let located enc =
|
2020-02-12 20:40:17 +04:00
|
|
|
merge_objs (obj1 (req "location" Script.location_encoding)) enc
|
|
|
|
in
|
|
|
|
let arity_enc = int8 in
|
2019-09-05 17:21:01 +04:00
|
|
|
let namespace_enc =
|
2020-02-12 20:40:17 +04:00
|
|
|
def
|
|
|
|
"primitiveNamespace"
|
|
|
|
~title:"Primitive namespace"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"One of the three possible namespaces of primitive (data constructor, \
|
|
|
|
type name or instruction)."
|
|
|
|
@@ string_enum
|
|
|
|
[ ("type", Type_namespace);
|
|
|
|
("constant", Constant_namespace);
|
|
|
|
("instruction", Instr_namespace) ]
|
|
|
|
in
|
2019-09-05 17:21:01 +04:00
|
|
|
let kind_enc =
|
2020-02-12 20:40:17 +04:00
|
|
|
def
|
|
|
|
"expressionKind"
|
|
|
|
~title:"Expression kind"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"One of the four possible kinds of expression (integer, string, \
|
|
|
|
primitive application or sequence)."
|
|
|
|
@@ string_enum
|
|
|
|
[ ("integer", Int_kind);
|
|
|
|
("string", String_kind);
|
|
|
|
("bytes", Bytes_kind);
|
|
|
|
("primitiveApplication", Prim_kind);
|
|
|
|
("sequence", Seq_kind) ]
|
|
|
|
in
|
2019-09-05 17:21:01 +04:00
|
|
|
(* -- Structure errors ---------------------- *)
|
|
|
|
(* Invalid arity *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_arity"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid arity"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"In a script or data expression, a primitive was applied to an \
|
|
|
|
unsupported number of arguments."
|
|
|
|
(located
|
|
|
|
(obj3
|
|
|
|
(req "primitive_name" Script.prim_encoding)
|
|
|
|
(req "expected_arity" arity_enc)
|
|
|
|
(req "wrong_arity" arity_enc)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
|
|
|
| Invalid_arity (loc, name, exp, got) ->
|
|
|
|
Some (loc, (name, exp, got))
|
2020-02-12 20:40:17 +04:00
|
|
|
| _ ->
|
|
|
|
None)
|
|
|
|
(fun (loc, (name, exp, got)) -> Invalid_arity (loc, name, exp, got)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Missing field *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.missing_script_field"
|
|
|
|
~title:"Script is missing a field (parse error)"
|
2020-02-12 20:40:17 +04:00
|
|
|
~description:"When parsing script, a field was expected, but not provided"
|
2019-09-05 17:21:01 +04:00
|
|
|
(obj1 (req "prim" prim_encoding))
|
|
|
|
(function Missing_field prim -> Some prim | _ -> None)
|
|
|
|
(fun prim -> Missing_field prim) ;
|
|
|
|
(* Invalid primitive *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_primitive"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid primitive"
|
|
|
|
~description:"In a script or data expression, a primitive was unknown."
|
|
|
|
(located
|
|
|
|
(obj2
|
|
|
|
(dft "expected_primitive_names" (list prim_encoding) [])
|
|
|
|
(req "wrong_primitive_name" prim_encoding)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Invalid_primitive (loc, exp, got) -> Some (loc, (exp, got)) | _ -> None)
|
|
|
|
(fun (loc, (exp, got)) -> Invalid_primitive (loc, exp, got)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Invalid kind *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_expression_kind"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid expression kind"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
|
|
|
"In a script or data expression, an expression was of the wrong kind \
|
|
|
|
(for instance a string where only a primitive applications can appear)."
|
2020-02-12 20:40:17 +04:00
|
|
|
(located
|
|
|
|
(obj2 (req "expected_kinds" (list kind_enc)) (req "wrong_kind" kind_enc)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Invalid_kind (loc, exp, got) -> Some (loc, (exp, got)) | _ -> None)
|
|
|
|
(fun (loc, (exp, got)) -> Invalid_kind (loc, exp, got)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Invalid namespace *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_primitive_namespace"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid primitive namespace"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
|
|
|
"In a script or data expression, a primitive was of the wrong namespace."
|
2020-02-12 20:40:17 +04:00
|
|
|
(located
|
|
|
|
(obj3
|
|
|
|
(req "primitive_name" prim_encoding)
|
|
|
|
(req "expected_namespace" namespace_enc)
|
|
|
|
(req "wrong_namespace" namespace_enc)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Invalid_namespace (loc, name, exp, got) ->
|
|
|
|
Some (loc, (name, exp, got))
|
|
|
|
| _ ->
|
|
|
|
None)
|
|
|
|
(fun (loc, (name, exp, got)) -> Invalid_namespace (loc, name, exp, got)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Duplicate field *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.duplicate_script_field"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Script has a duplicated field (parse error)"
|
|
|
|
~description:"When parsing script, a field was found more than once"
|
|
|
|
(obj2 (req "loc" location_encoding) (req "prim" prim_encoding))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function Duplicate_field (loc, prim) -> Some (loc, prim) | _ -> None)
|
|
|
|
(fun (loc, prim) -> Duplicate_field (loc, prim)) ;
|
|
|
|
(* Unexpected big_map *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.unexpected_bigmap"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Big map in unauthorized position (type error)"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"When parsing script, a big_map type was found in a position where it \
|
|
|
|
could end up stored inside a big_map, which is forbidden for now."
|
|
|
|
(obj1 (req "loc" location_encoding))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function Unexpected_big_map loc -> Some loc | _ -> None)
|
|
|
|
(fun loc -> Unexpected_big_map loc) ;
|
|
|
|
(* Unexpected operation *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.unexpected_operation"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Operation in unauthorized position (type error)"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"When parsing script, an operation type was found in the storage or \
|
|
|
|
parameter field."
|
|
|
|
(obj1 (req "loc" location_encoding))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function Unexpected_operation loc -> Some loc | _ -> None)
|
|
|
|
(fun loc -> Unexpected_operation loc) ;
|
2019-10-17 13:45:27 +04:00
|
|
|
(* No such entrypoint *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.no_such_entrypoint"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"No such entrypoint (type error)"
|
|
|
|
~description:"An entrypoint was not found when calling a contract."
|
|
|
|
(obj1 (req "entrypoint" string))
|
2019-10-17 13:45:27 +04:00
|
|
|
(function No_such_entrypoint entrypoint -> Some entrypoint | _ -> None)
|
|
|
|
(fun entrypoint -> No_such_entrypoint entrypoint) ;
|
|
|
|
(* Unreachable entrypoint *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.unreachable_entrypoint"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Unreachable entrypoint (type error)"
|
|
|
|
~description:"An entrypoint in the contract is not reachable."
|
|
|
|
(obj1 (req "path" (list prim_encoding)))
|
2019-10-17 13:45:27 +04:00
|
|
|
(function Unreachable_entrypoint path -> Some path | _ -> None)
|
|
|
|
(fun path -> Unreachable_entrypoint path) ;
|
|
|
|
(* Duplicate entrypoint *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.duplicate_entrypoint"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Duplicate entrypoint (type error)"
|
|
|
|
~description:"Two entrypoints have the same name."
|
|
|
|
(obj1 (req "path" string))
|
2019-10-17 13:45:27 +04:00
|
|
|
(function Duplicate_entrypoint entrypoint -> Some entrypoint | _ -> None)
|
|
|
|
(fun entrypoint -> Duplicate_entrypoint entrypoint) ;
|
|
|
|
(* Entrypoint name too long *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.entrypoint_name_too_long"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Entrypoint name too long (type error)"
|
2019-10-17 13:45:27 +04:00
|
|
|
~description:
|
|
|
|
"An entrypoint name exceeds the maximum length of 31 characters."
|
2020-02-12 20:40:17 +04:00
|
|
|
(obj1 (req "name" string))
|
|
|
|
(function
|
|
|
|
| Entrypoint_name_too_long entrypoint -> Some entrypoint | _ -> None)
|
2019-10-17 13:45:27 +04:00
|
|
|
(fun entrypoint -> Entrypoint_name_too_long entrypoint) ;
|
|
|
|
(* Unexpected contract *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.unexpected_contract"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Contract in unauthorized position (type error)"
|
2019-10-17 13:45:27 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"When parsing script, a contract type was found in the storage or \
|
|
|
|
parameter field."
|
|
|
|
(obj1 (req "loc" location_encoding))
|
2019-10-17 13:45:27 +04:00
|
|
|
(function Unexpected_contract loc -> Some loc | _ -> None)
|
|
|
|
(fun loc -> Unexpected_contract loc) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* -- Value typing errors ---------------------- *)
|
|
|
|
(* Unordered map keys *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.unordered_map_literal"
|
|
|
|
~title:"Invalid map key order"
|
|
|
|
~description:"Map keys must be in strictly increasing order"
|
|
|
|
(obj2
|
|
|
|
(req "location" Script.location_encoding)
|
|
|
|
(req "item" Script.expr_encoding))
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Unordered_map_keys (loc, expr) -> Some (loc, expr) | _ -> None)
|
|
|
|
(fun (loc, expr) -> Unordered_map_keys (loc, expr)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Duplicate map keys *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.duplicate_map_keys"
|
|
|
|
~title:"Duplicate map keys"
|
|
|
|
~description:"Map literals cannot contain duplicated keys"
|
|
|
|
(obj2
|
|
|
|
(req "location" Script.location_encoding)
|
|
|
|
(req "item" Script.expr_encoding))
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Duplicate_map_keys (loc, expr) -> Some (loc, expr) | _ -> None)
|
|
|
|
(fun (loc, expr) -> Duplicate_map_keys (loc, expr)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Unordered set values *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.unordered_set_literal"
|
|
|
|
~title:"Invalid set value order"
|
|
|
|
~description:"Set values must be in strictly increasing order"
|
|
|
|
(obj2
|
|
|
|
(req "location" Script.location_encoding)
|
|
|
|
(req "value" Script.expr_encoding))
|
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Unordered_set_values (loc, expr) -> Some (loc, expr) | _ -> None)
|
|
|
|
(fun (loc, expr) -> Unordered_set_values (loc, expr)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Duplicate set values *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.duplicate_set_values_in_literal"
|
|
|
|
~title:"Sets literals cannot contain duplicate elements"
|
2020-02-12 20:40:17 +04:00
|
|
|
~description:
|
|
|
|
"Set literals cannot contain duplicate elements, but a duplicae was \
|
|
|
|
found while parsing."
|
2019-09-05 17:21:01 +04:00
|
|
|
(obj2
|
|
|
|
(req "location" Script.location_encoding)
|
|
|
|
(req "value" Script.expr_encoding))
|
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Duplicate_set_values (loc, expr) -> Some (loc, expr) | _ -> None)
|
|
|
|
(fun (loc, expr) -> Duplicate_set_values (loc, expr)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* -- Instruction typing errors ------------- *)
|
|
|
|
(* Fail not in tail position *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.fail_not_in_tail_position"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"FAIL not in tail position"
|
|
|
|
~description:"There is non trivial garbage code after a FAIL instruction."
|
2019-09-05 17:21:01 +04:00
|
|
|
(located empty)
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Fail_not_in_tail_position loc -> Some (loc, ()) | _ -> None)
|
|
|
|
(fun (loc, ()) -> Fail_not_in_tail_position loc) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Undefined binary operation *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.undefined_binop"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Undefined binop"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"A binary operation is called on operands of types over which it is not \
|
|
|
|
defined."
|
|
|
|
(located
|
|
|
|
(obj3
|
|
|
|
(req "operator_name" prim_encoding)
|
|
|
|
(req "wrong_left_operand_type" Script.expr_encoding)
|
|
|
|
(req "wrong_right_operand_type" Script.expr_encoding)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
|
|
|
| Undefined_binop (loc, n, tyl, tyr) ->
|
|
|
|
Some (loc, (n, tyl, tyr))
|
2020-02-12 20:40:17 +04:00
|
|
|
| _ ->
|
|
|
|
None)
|
|
|
|
(fun (loc, (n, tyl, tyr)) -> Undefined_binop (loc, n, tyl, tyr)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Undefined unary operation *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.undefined_unop"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Undefined unop"
|
|
|
|
~description:
|
|
|
|
"A unary operation is called on an operand of type over which it is not \
|
|
|
|
defined."
|
|
|
|
(located
|
|
|
|
(obj2
|
|
|
|
(req "operator_name" prim_encoding)
|
|
|
|
(req "wrong_operand_type" Script.expr_encoding)))
|
|
|
|
(function Undefined_unop (loc, n, ty) -> Some (loc, (n, ty)) | _ -> None)
|
|
|
|
(fun (loc, (n, ty)) -> Undefined_unop (loc, n, ty)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Bad return *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.bad_return"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Bad return"
|
|
|
|
~description:"Unexpected stack at the end of a lambda or script."
|
|
|
|
(located
|
|
|
|
(obj2
|
|
|
|
(req "expected_return_type" Script.expr_encoding)
|
|
|
|
(req "wrong_stack_type" stack_ty_enc)))
|
|
|
|
(function Bad_return (loc, sty, ty) -> Some (loc, (ty, sty)) | _ -> None)
|
|
|
|
(fun (loc, (ty, sty)) -> Bad_return (loc, sty, ty)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Bad stack *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.bad_stack"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Bad stack"
|
|
|
|
~description:"The stack has an unexpected length or contents."
|
|
|
|
(located
|
|
|
|
(obj3
|
|
|
|
(req "primitive_name" prim_encoding)
|
|
|
|
(req "relevant_stack_portion" int16)
|
|
|
|
(req "wrong_stack_type" stack_ty_enc)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Bad_stack (loc, name, s, sty) -> Some (loc, (name, s, sty)) | _ -> None)
|
|
|
|
(fun (loc, (name, s, sty)) -> Bad_stack (loc, name, s, sty)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Inconsistent annotations *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.inconsistent_annotations"
|
|
|
|
~title:"Annotations inconsistent between branches"
|
|
|
|
~description:"The annotations on two types could not be merged"
|
2020-02-12 20:40:17 +04:00
|
|
|
(obj2 (req "annot1" string) (req "annot2" string))
|
|
|
|
(function
|
|
|
|
| Inconsistent_annotations (annot1, annot2) ->
|
|
|
|
Some (annot1, annot2)
|
|
|
|
| _ ->
|
|
|
|
None)
|
2019-09-05 17:21:01 +04:00
|
|
|
(fun (annot1, annot2) -> Inconsistent_annotations (annot1, annot2)) ;
|
|
|
|
(* Inconsistent field annotations *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.inconsistent_field_annotations"
|
|
|
|
~title:"Annotations for field accesses is inconsistent"
|
2020-02-12 20:40:17 +04:00
|
|
|
~description:
|
|
|
|
"The specified field does not match the field annotation in the type"
|
|
|
|
(obj2 (req "annot1" string) (req "annot2" string))
|
|
|
|
(function
|
|
|
|
| Inconsistent_field_annotations (annot1, annot2) ->
|
|
|
|
Some (annot1, annot2)
|
|
|
|
| _ ->
|
|
|
|
None)
|
2019-09-05 17:21:01 +04:00
|
|
|
(fun (annot1, annot2) -> Inconsistent_field_annotations (annot1, annot2)) ;
|
|
|
|
(* Inconsistent type annotations *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.inconsistent_type_annotations"
|
|
|
|
~title:"Types contain inconsistent annotations"
|
|
|
|
~description:"The two types contain annotations that do not match"
|
2020-02-12 20:40:17 +04:00
|
|
|
(located
|
|
|
|
(obj2
|
|
|
|
(req "type1" Script.expr_encoding)
|
|
|
|
(req "type2" Script.expr_encoding)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Inconsistent_type_annotations (loc, ty1, ty2) ->
|
|
|
|
Some (loc, (ty1, ty2))
|
|
|
|
| _ ->
|
|
|
|
None)
|
2019-09-05 17:21:01 +04:00
|
|
|
(fun (loc, (ty1, ty2)) -> Inconsistent_type_annotations (loc, ty1, ty2)) ;
|
|
|
|
(* Unexpected annotation *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.unexpected_annotation"
|
|
|
|
~title:"An annotation was encountered where no annotation is expected"
|
|
|
|
~description:"A node in the syntax tree was impropperly annotated"
|
|
|
|
(located empty)
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Unexpected_annotation loc -> Some (loc, ()) | _ -> None)
|
|
|
|
(fun (loc, ()) -> Unexpected_annotation loc) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Ungrouped annotations *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.ungrouped_annotations"
|
|
|
|
~title:"Annotations of the same kind were found spread apart"
|
|
|
|
~description:"Annotations of the same kind must be grouped"
|
|
|
|
(located empty)
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Ungrouped_annotations loc -> Some (loc, ()) | _ -> None)
|
|
|
|
(fun (loc, ()) -> Ungrouped_annotations loc) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Unmatched branches *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.unmatched_branches"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Unmatched branches"
|
|
|
|
~description:
|
|
|
|
"At the join point at the end of two code branches the stacks have \
|
|
|
|
inconsistent lengths or contents."
|
|
|
|
(located
|
|
|
|
(obj2
|
|
|
|
(req "first_stack_type" stack_ty_enc)
|
|
|
|
(req "other_stack_type" stack_ty_enc)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
|
|
|
| Unmatched_branches (loc, stya, styb) ->
|
|
|
|
Some (loc, (stya, styb))
|
2020-02-12 20:40:17 +04:00
|
|
|
| _ ->
|
|
|
|
None)
|
|
|
|
(fun (loc, (stya, styb)) -> Unmatched_branches (loc, stya, styb)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Bad stack item *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.bad_stack_item"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Bad stack item"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"The type of a stack item is unexpected (this error is always \
|
|
|
|
accompanied by a more precise one)."
|
2019-09-05 17:21:01 +04:00
|
|
|
(obj1 (req "item_level" int16))
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Bad_stack_item n -> Some n | _ -> None)
|
|
|
|
(fun n -> Bad_stack_item n) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* SELF in lambda *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.self_in_lambda"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"SELF instruction in lambda"
|
|
|
|
~description:"A SELF instruction was encountered in a lambda expression."
|
2019-09-05 17:21:01 +04:00
|
|
|
(located empty)
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Self_in_lambda loc -> Some (loc, ()) | _ -> None)
|
|
|
|
(fun (loc, ()) -> Self_in_lambda loc) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Bad stack length *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.inconsistent_stack_lengths"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Inconsistent stack lengths"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"A stack was of an unexpected length (this error is always in the \
|
|
|
|
context of a located error)."
|
2019-09-05 17:21:01 +04:00
|
|
|
empty
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Bad_stack_length -> Some () | _ -> None)
|
|
|
|
(fun () -> Bad_stack_length) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* -- Value typing errors ------------------- *)
|
|
|
|
(* Invalid constant *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_constant"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid constant"
|
|
|
|
~description:"A data expression was invalid for its expected type."
|
|
|
|
(located
|
|
|
|
(obj2
|
|
|
|
(req "expected_type" Script.expr_encoding)
|
|
|
|
(req "wrong_expression" Script.expr_encoding)))
|
2019-09-05 17:21:01 +04:00
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Invalid_constant (loc, expr, ty) -> Some (loc, (ty, expr)) | _ -> None)
|
|
|
|
(fun (loc, (ty, expr)) -> Invalid_constant (loc, expr, ty)) ;
|
2019-10-17 13:45:27 +04:00
|
|
|
(* Invalid syntactic constant *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"invalidSyntacticConstantError"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid constant (parse error)"
|
|
|
|
~description:"A compile-time constant was invalid for its expected form."
|
|
|
|
(located
|
|
|
|
(obj2
|
|
|
|
(req "expectedForm" Script.expr_encoding)
|
|
|
|
(req "wrongExpression" Script.expr_encoding)))
|
2019-10-17 13:45:27 +04:00
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Invalid_constant (loc, expr, ty) -> Some (loc, (ty, expr)) | _ -> None)
|
|
|
|
(fun (loc, (ty, expr)) -> Invalid_constant (loc, expr, ty)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Invalid contract *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_contract"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid contract"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"A script or data expression references a contract that does not exist \
|
|
|
|
or assumes a wrong type for an existing contract."
|
2019-09-05 17:21:01 +04:00
|
|
|
(located (obj1 (req "contract" Contract.encoding)))
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Invalid_contract (loc, c) -> Some (loc, c) | _ -> None)
|
|
|
|
(fun (loc, c) -> Invalid_contract (loc, c)) ;
|
2019-10-17 13:45:27 +04:00
|
|
|
(* Invalid big_map *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_big_map"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid big_map"
|
2019-10-17 13:45:27 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"A script or data expression references a big_map that does not exist \
|
|
|
|
or assumes a wrong type for an existing big_map."
|
2019-10-17 13:45:27 +04:00
|
|
|
(located (obj1 (req "big_map" z)))
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Invalid_big_map (loc, c) -> Some (loc, c) | _ -> None)
|
|
|
|
(fun (loc, c) -> Invalid_big_map (loc, c)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Comparable type expected *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.comparable_type_expected"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Comparable type expected"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"A non comparable type was used in a place where only comparable types \
|
|
|
|
are accepted."
|
2019-09-05 17:21:01 +04:00
|
|
|
(located (obj1 (req "wrong_type" Script.expr_encoding)))
|
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Comparable_type_expected (loc, ty) -> Some (loc, ty) | _ -> None)
|
|
|
|
(fun (loc, ty) -> Comparable_type_expected (loc, ty)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Inconsistent types *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.inconsistent_types"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Inconsistent types"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"This is the basic type clash error, that appears in several places \
|
|
|
|
where the equality of two types have to be proven, it is always \
|
|
|
|
accompanied with another error that provides more context."
|
2019-09-05 17:21:01 +04:00
|
|
|
(obj2
|
|
|
|
(req "first_type" Script.expr_encoding)
|
|
|
|
(req "other_type" Script.expr_encoding))
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Inconsistent_types (tya, tyb) -> Some (tya, tyb) | _ -> None)
|
2019-09-05 17:21:01 +04:00
|
|
|
(fun (tya, tyb) -> Inconsistent_types (tya, tyb)) ;
|
|
|
|
(* -- Instruction typing errors ------------------- *)
|
|
|
|
(* Invalid map body *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_map_body"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Invalid map body"
|
|
|
|
~description:"The body of a map block did not match the expected type"
|
|
|
|
(obj2 (req "loc" Script.location_encoding) (req "body_type" stack_ty_enc))
|
|
|
|
(function Invalid_map_body (loc, stack) -> Some (loc, stack) | _ -> None)
|
2019-09-05 17:21:01 +04:00
|
|
|
(fun (loc, stack) -> Invalid_map_body (loc, stack)) ;
|
|
|
|
(* Invalid map block FAIL *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_map_block_fail"
|
|
|
|
~title:"FAIL instruction occurred as body of map block"
|
2020-02-12 20:40:17 +04:00
|
|
|
~description:
|
|
|
|
"FAIL cannot be the only instruction in the body. The propper type of \
|
|
|
|
the return list cannot be inferred."
|
2019-09-05 17:21:01 +04:00
|
|
|
(obj1 (req "loc" Script.location_encoding))
|
2020-02-12 20:40:17 +04:00
|
|
|
(function Invalid_map_block_fail loc -> Some loc | _ -> None)
|
2019-09-05 17:21:01 +04:00
|
|
|
(fun loc -> Invalid_map_block_fail loc) ;
|
|
|
|
(* Invalid ITER body *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.invalid_iter_body"
|
|
|
|
~title:"ITER body returned wrong stack type"
|
2020-02-12 20:40:17 +04:00
|
|
|
~description:
|
|
|
|
"The body of an ITER instruction must result in the same stack type as \
|
|
|
|
before the ITER."
|
2019-09-05 17:21:01 +04:00
|
|
|
(obj3
|
|
|
|
(req "loc" Script.location_encoding)
|
|
|
|
(req "bef_stack" stack_ty_enc)
|
|
|
|
(req "aft_stack" stack_ty_enc))
|
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Invalid_iter_body (loc, bef, aft) -> Some (loc, bef, aft) | _ -> None)
|
2019-09-05 17:21:01 +04:00
|
|
|
(fun (loc, bef, aft) -> Invalid_iter_body (loc, bef, aft)) ;
|
|
|
|
(* Type too large *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.type_too_large"
|
|
|
|
~title:"Stack item type too large"
|
|
|
|
~description:"An instruction generated a type larger than the limit."
|
|
|
|
(obj3
|
|
|
|
(req "loc" Script.location_encoding)
|
|
|
|
(req "type_size" uint16)
|
|
|
|
(req "maximum_type_size" uint16))
|
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Type_too_large (loc, ts, maxts) -> Some (loc, ts, maxts) | _ -> None)
|
2019-09-05 17:21:01 +04:00
|
|
|
(fun (loc, ts, maxts) -> Type_too_large (loc, ts, maxts)) ;
|
|
|
|
(* -- Toplevel errors ------------------- *)
|
|
|
|
(* Ill typed data *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.ill_typed_data"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Ill typed data"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"The toplevel error thrown when trying to typecheck a data expression \
|
|
|
|
against a given type (always followed by more precise errors)."
|
2019-09-05 17:21:01 +04:00
|
|
|
(obj3
|
|
|
|
(opt "identifier" string)
|
|
|
|
(req "expected_type" Script.expr_encoding)
|
|
|
|
(req "ill_typed_expression" Script.expr_encoding))
|
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Ill_typed_data (name, expr, ty) -> Some (name, ty, expr) | _ -> None)
|
|
|
|
(fun (name, ty, expr) -> Ill_typed_data (name, expr, ty)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Ill formed type *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.ill_formed_type"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Ill formed type"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
|
|
|
"The toplevel error thrown when trying to parse a type expression \
|
|
|
|
(always followed by more precise errors)."
|
|
|
|
(obj3
|
|
|
|
(opt "identifier" string)
|
|
|
|
(req "ill_formed_expression" Script.expr_encoding)
|
|
|
|
(req "location" Script.location_encoding))
|
|
|
|
(function
|
2020-02-12 20:40:17 +04:00
|
|
|
| Ill_formed_type (name, expr, loc) -> Some (name, expr, loc) | _ -> None)
|
|
|
|
(fun (name, expr, loc) -> Ill_formed_type (name, expr, loc)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Ill typed contract *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.ill_typed_contract"
|
2020-02-12 20:40:17 +04:00
|
|
|
~title:"Ill typed contract"
|
2019-09-05 17:21:01 +04:00
|
|
|
~description:
|
2020-02-12 20:40:17 +04:00
|
|
|
"The toplevel error thrown when trying to typecheck a contract code \
|
|
|
|
against given input, output and storage types (always followed by more \
|
|
|
|
precise errors)."
|
2019-09-05 17:21:01 +04:00
|
|
|
(obj2
|
|
|
|
(req "ill_typed_code" Script.expr_encoding)
|
|
|
|
(req "type_map" type_map_enc))
|
|
|
|
(function
|
|
|
|
| Ill_typed_contract (expr, type_map) ->
|
|
|
|
Some (expr, type_map)
|
2020-02-12 20:40:17 +04:00
|
|
|
| _ ->
|
|
|
|
None)
|
|
|
|
(fun (expr, type_map) -> Ill_typed_contract (expr, type_map)) ;
|
2019-09-05 17:21:01 +04:00
|
|
|
(* Cannot serialize error *)
|
|
|
|
register_error_kind
|
|
|
|
`Temporary
|
|
|
|
~id:"michelson_v1.cannot_serialize_error"
|
|
|
|
~title:"Not enough gas to serialize error"
|
2020-02-12 20:40:17 +04:00
|
|
|
~description:"The error was too big to be serialized with the provided gas"
|
2019-09-05 17:21:01 +04:00
|
|
|
Data_encoding.empty
|
|
|
|
(function Cannot_serialize_error -> Some () | _ -> None)
|
2019-10-17 13:45:27 +04:00
|
|
|
(fun () -> Cannot_serialize_error) ;
|
|
|
|
(* Deprecated instruction *)
|
|
|
|
register_error_kind
|
|
|
|
`Permanent
|
|
|
|
~id:"michelson_v1.deprecated_instruction"
|
|
|
|
~title:"Script is using a deprecated instruction"
|
|
|
|
~description:
|
|
|
|
"A deprecated instruction usage is disallowed in newly created contracts"
|
|
|
|
(obj1 (req "prim" prim_encoding))
|
|
|
|
(function Deprecated_instruction prim -> Some prim | _ -> None)
|
2020-02-12 20:40:17 +04:00
|
|
|
(fun prim -> Deprecated_instruction prim)
|