Alpha: raise permanent error on gas exhaustion in precheck
This commit is contained in:
parent
0dee466736
commit
8648555f01
@ -70,12 +70,6 @@ module Voting_period = Voting_period_repr
|
||||
module Gas = struct
|
||||
include Gas_limit_repr
|
||||
type error += Gas_limit_too_high = Raw_context.Gas_limit_too_high
|
||||
type error += Not_enough_gas_minimal_deserialize_parameters =
|
||||
Script_repr.Not_enough_gas_minimal_deserialize_parameters
|
||||
type error += Not_enough_gas_minimal_deserialize_storage =
|
||||
Script_repr.Not_enough_gas_minimal_deserialize_storage
|
||||
type error += Not_enough_gas_minimal_serialize_storage =
|
||||
Script_repr.Not_enough_gas_minimal_deserialize_storage
|
||||
let check_limit = Raw_context.check_gas_limit
|
||||
let set_limit = Raw_context.set_gas_limit
|
||||
let set_unlimited = Raw_context.set_gas_unlimited
|
||||
|
@ -124,9 +124,6 @@ module Gas : sig
|
||||
type error += Block_quota_exceeded (* `Temporary *)
|
||||
type error += Operation_quota_exceeded (* `Temporary *)
|
||||
type error += Gas_limit_too_high (* `Permanent *)
|
||||
type error += Not_enough_gas_minimal_deserialize_parameters (* `Permanent *)
|
||||
type error += Not_enough_gas_minimal_deserialize_storage (* `Temporary *)
|
||||
type error += Not_enough_gas_minimal_serialize_storage (* `Temporary *)
|
||||
|
||||
val free : cost
|
||||
val step_cost : int -> cost
|
||||
|
@ -41,6 +41,7 @@ type error += Outdated_double_baking_evidence
|
||||
of { level: Raw_level.t ; last: Raw_level.t } (* `Permanent *)
|
||||
type error += Invalid_activation of { pkh : Ed25519.Public_key_hash.t }
|
||||
type error += Multiple_revelation
|
||||
type error += Gas_quota_exceeded_init_deserialize (* Permanent *)
|
||||
|
||||
let () =
|
||||
register_error_kind
|
||||
@ -318,7 +319,16 @@ let () =
|
||||
"Multiple revelations were included in a manager operation")
|
||||
Data_encoding.empty
|
||||
(function Multiple_revelation -> Some () | _ -> None)
|
||||
(fun () -> Multiple_revelation)
|
||||
(fun () -> Multiple_revelation) ;
|
||||
register_error_kind
|
||||
`Permanent
|
||||
~id:"gas_exhausted.init_deserialize"
|
||||
~title:"Not enough gas for initial deserialization of parameters"
|
||||
~description:"Gas quota was not enough to deserialize the transaction \
|
||||
parameters in precheck"
|
||||
Data_encoding.empty
|
||||
(function Gas_quota_exceeded_init_deserialize -> Some () | _ -> None)
|
||||
(fun () -> Gas_quota_exceeded_init_deserialize)
|
||||
|
||||
open Apply_results
|
||||
|
||||
@ -502,26 +512,23 @@ let precheck_manager_contents
|
||||
Contract.reveal_manager_key ctxt source pk
|
||||
| Transaction { parameters = Some arg ; _ } ->
|
||||
(* Fail if not enough gas for minimal deserialization cost *)
|
||||
begin match Gas.consume ctxt (Script.minimal_deserialize_cost arg) with
|
||||
| Ok _ -> return ctxt
|
||||
| Error _ -> fail Gas.Not_enough_gas_minimal_deserialize_parameters
|
||||
end >>=? fun ctxt ->
|
||||
Lwt.return @@ record_trace Gas_quota_exceeded_init_deserialize @@
|
||||
Gas.consume ctxt (Script.minimal_deserialize_cost arg) >>=? fun _ ->
|
||||
Lwt.return @@ Script.force_decode arg >>=? fun (_arg, cost_arg) ->
|
||||
Lwt.return @@ Gas.consume ctxt cost_arg
|
||||
Lwt.return @@ record_trace Gas_quota_exceeded_init_deserialize @@
|
||||
Gas.consume ctxt cost_arg
|
||||
| Origination { script = Some script ; _ } ->
|
||||
(* Fail if not enough gas for minimal deserialization cost *)
|
||||
begin
|
||||
match
|
||||
Gas.consume ctxt (Script.minimal_deserialize_cost script.code) >>? fun ctxt ->
|
||||
Gas.consume ctxt (Script.minimal_deserialize_cost script.storage)
|
||||
with
|
||||
| Ok _ -> return ctxt
|
||||
| Error _ -> fail Gas.Not_enough_gas_minimal_deserialize_parameters
|
||||
end >>=? fun ctxt ->
|
||||
Lwt.return @@ record_trace Gas_quota_exceeded_init_deserialize @@
|
||||
(Gas.consume ctxt (Script.minimal_deserialize_cost script.code) >>? fun ctxt ->
|
||||
Gas.consume ctxt (Script.minimal_deserialize_cost script.storage))
|
||||
>>=? fun _ ->
|
||||
Lwt.return @@ Script.force_decode script.code >>=? fun (_code, cost_code) ->
|
||||
Lwt.return @@ Gas.consume ctxt cost_code >>=? fun ctxt ->
|
||||
Lwt.return @@ record_trace Gas_quota_exceeded_init_deserialize @@
|
||||
Gas.consume ctxt cost_code >>=? fun ctxt ->
|
||||
Lwt.return @@ Script.force_decode script.storage >>=? fun (_storage, cost_storage) ->
|
||||
Lwt.return @@ Gas.consume ctxt cost_storage
|
||||
Lwt.return @@ record_trace Gas_quota_exceeded_init_deserialize @@
|
||||
Gas.consume ctxt cost_storage
|
||||
| _ -> return ctxt
|
||||
end >>=? fun ctxt ->
|
||||
Contract.get_manager_key ctxt source >>=? fun public_key ->
|
||||
|
@ -25,9 +25,6 @@ let expr_encoding =
|
||||
Michelson_v1_primitives.prim_encoding
|
||||
|
||||
type error += Lazy_script_decode (* `Permanent *)
|
||||
type error += Not_enough_gas_minimal_deserialize_parameters (* `Permanent *)
|
||||
type error += Not_enough_gas_minimal_deserialize_storage (* `Temporary *)
|
||||
type error += Not_enough_gas_minimal_serialize_storage (* `Temporary *)
|
||||
|
||||
let () =
|
||||
register_error_kind `Permanent
|
||||
@ -37,34 +34,7 @@ let () =
|
||||
from its binary representation"
|
||||
Data_encoding.empty
|
||||
(function Lazy_script_decode -> Some () | _ -> None)
|
||||
(fun () -> Lazy_script_decode) ;
|
||||
register_error_kind
|
||||
`Permanent
|
||||
~id:"gas_exhausted.minimal_deserialization_parameters"
|
||||
~title:"Not enough gas for minimal deserialization of transaction parameters"
|
||||
~description:"Gas quota is not enough for deserializing the transaction \
|
||||
parameters, even for the cheapest case"
|
||||
Data_encoding.empty
|
||||
(function Not_enough_gas_minimal_deserialize_parameters -> Some () | _ -> None)
|
||||
(fun () -> Not_enough_gas_minimal_deserialize_parameters) ;
|
||||
register_error_kind
|
||||
`Temporary
|
||||
~id:"gas_exhausted.minimal_deserialization_storage"
|
||||
~title:"Not enough gas for minimal deserialization of contract storage"
|
||||
~description:"Gas quota is not enough for deserializing the contract \
|
||||
storage or code, even for the cheapest case"
|
||||
Data_encoding.empty
|
||||
(function Not_enough_gas_minimal_deserialize_storage -> Some () | _ -> None)
|
||||
(fun () -> Not_enough_gas_minimal_deserialize_storage) ;
|
||||
register_error_kind
|
||||
`Temporary
|
||||
~id:"gas_exhausted.minimal_serialization_storage"
|
||||
~title:"Not enough gas for minimal serialization of contract storage"
|
||||
~description:"Gas quota is not enough for serializing the contract \
|
||||
storage or code, even for the cheapest case"
|
||||
Data_encoding.empty
|
||||
(function Not_enough_gas_minimal_deserialize_storage -> Some () | _ -> None)
|
||||
(fun () -> Not_enough_gas_minimal_deserialize_storage)
|
||||
(fun () -> Lazy_script_decode)
|
||||
|
||||
let lazy_expr_encoding =
|
||||
Data_encoding.lazy_encoding expr_encoding
|
||||
|
@ -14,9 +14,6 @@ type annot = Micheline.annot
|
||||
type expr = Michelson_v1_primitives.prim Micheline.canonical
|
||||
|
||||
type error += Lazy_script_decode (* `Permanent *)
|
||||
type error += Not_enough_gas_minimal_deserialize_parameters (* `Permanent *)
|
||||
type error += Not_enough_gas_minimal_deserialize_storage (* `Temporary *)
|
||||
type error += Not_enough_gas_minimal_serialize_storage (* `Temporary *)
|
||||
|
||||
type lazy_expr = expr Data_encoding.lazy_t
|
||||
|
||||
|
@ -152,24 +152,16 @@ module Contract = struct
|
||||
end)
|
||||
|
||||
let consume_deserialize_gas ctxt value =
|
||||
begin match Raw_context.consume_gas ctxt (Script_repr.minimal_deserialize_cost value) with
|
||||
| Ok _ -> return ctxt
|
||||
| Error _ ->
|
||||
fail Script_repr.Not_enough_gas_minimal_deserialize_storage
|
||||
end >>=? fun ctxt ->
|
||||
Lwt.return @@
|
||||
(Script_repr.force_decode value >>? fun (_value, value_cost) ->
|
||||
(Raw_context.consume_gas ctxt (Script_repr.minimal_deserialize_cost value) >>? fun _ ->
|
||||
Script_repr.force_decode value >>? fun (_value, value_cost) ->
|
||||
Raw_context.consume_gas ctxt value_cost)
|
||||
|
||||
let consume_serialize_gas ctxt value =
|
||||
begin match Raw_context.consume_gas ctxt (Script_repr.minimal_serialize_cost value) with
|
||||
| Ok _ -> return ctxt
|
||||
| Error _ ->
|
||||
fail Script_repr.Not_enough_gas_minimal_serialize_storage
|
||||
end >>=? fun ctxt ->
|
||||
Lwt.return @@
|
||||
(Script_repr.force_bytes value >>? fun (_value, value_cost) ->
|
||||
Raw_context.consume_gas ctxt value_cost)
|
||||
( Raw_context.consume_gas ctxt (Script_repr.minimal_serialize_cost value) >>? fun _ ->
|
||||
Script_repr.force_bytes value >>? fun (_value, value_cost) ->
|
||||
Raw_context.consume_gas ctxt value_cost)
|
||||
|
||||
let get ctxt contract =
|
||||
get ctxt contract >>=? fun (ctxt, value) ->
|
||||
|
Loading…
Reference in New Issue
Block a user