text
stringlengths
0
601k
let execute logger ctxt mode step_constants ~ entrypoint ~ internal unparsed_script cached_script arg : ( Script . expr * packed_internal_operation list * context * Lazy_storage . diffs option * ex_script * int ) tzresult Lwt . t = ( match cached_script with | None -> parse_script ctxt unparsed_script ~ legacy : true ~...
type execution_result = { ctxt : context ; storage : Script . expr ; lazy_storage_diff : Lazy_storage . diffs option ; operations : packed_internal_operation list ; }
let execute ? logger ctxt ~ cached_script mode step_constants ~ script ~ entrypoint ~ parameter ~ internal = execute logger ctxt mode step_constants ~ entrypoint ~ internal script cached_script ( Micheline . root parameter ) >|=? fun ( storage , operations , ctxt , lazy_storage_diff , ex_script , approx_size ) -> ( { c...
module Internals = struct let next logger g gas ks accu stack = let ks = match logger with None -> ks | Some logger -> KLog ( ks , logger ) in next g gas ks accu stack let step ( ctxt , step_constants ) gas ks accu stack = internal_step ctxt step_constants gas ks accu stack end
let cost_of_instr : type a s r f . ( a , s , r , f ) kinstr -> a -> s -> Gas . cost = fun i accu stack -> match i with | IList_map _ -> let list = accu in Interp_costs . list_map list | IList_iter _ -> let list = accu in Interp_costs . list_iter list | ISet_iter _ -> let set = accu in Interp_costs . set_iter set | ISet...
let cost_of_control : type a s r f . ( a , s , r , f ) continuation -> Gas . cost = fun ks -> match ks with | KLog _ -> Gas . free | KNil -> Interp_costs . Control . nil | KCons ( _ , _ ) -> Interp_costs . Control . cons | KReturn _ -> Interp_costs . Control . return | KMap_head ( _ , _ ) -> Interp_costs . Control . ma...
let consume_instr local_gas_counter k accu stack = let cost = cost_of_instr k accu stack in consume_opt local_gas_counter cost [ @@ ocaml . inline always ]
let consume_control local_gas_counter ks = let cost = cost_of_control ks in consume_opt local_gas_counter cost [ @@ ocaml . inline always ]
let log_entry logger ctxt gas k accu stack = let kinfo = kinfo_of_kinstr k in let ctxt = update_context gas ctxt in logger . log_entry k ctxt kinfo . iloc kinfo . kstack_ty ( accu , stack )
let log_exit logger ctxt gas kinfo_prev k accu stack = let kinfo = kinfo_of_kinstr k in let ctxt = update_context gas ctxt in logger . log_exit k ctxt kinfo_prev . iloc kinfo . kstack_ty ( accu , stack )
let log_control logger ks = logger . log_control ks
let get_log = function | None -> Lwt . return ( Ok None ) | Some logger -> logger . get_log ( ) [ @@ ocaml . inline always ]
let log_kinstr logger i = ILog ( kinfo_of_kinstr i , LogEntry , logger , i )
let log_next_kinstr logger i = let apply k = ILog ( kinfo_of_kinstr k , LogExit ( kinfo_of_kinstr i ) , logger , log_kinstr logger k ) in kinstr_rewritek i { apply }
let id x = x [ @@ inline ]
let rec kundip : type a s e z c u d w b t . ( a , s , e , z , c , u , d , w ) stack_prefix_preservation_witness -> c -> u -> ( d , w , b , t ) kinstr -> a * s * ( e , z , b , t ) kinstr = fun w accu stack k -> match w with | KPrefix ( kinfo , w ) -> let k = IConst ( kinfo , accu , k ) in let ( accu , stack ) = stack in...
let apply ctxt gas capture_ty capture lam = let ( Lam ( descr , expr ) ) = lam in let ( Item_t ( full_arg_ty , _ ) ) = descr . kbef in let ctxt = update_context gas ctxt in unparse_data ctxt Optimized capture_ty capture >>=? fun ( const_expr , ctxt ) -> let loc = Micheline . dummy_location in unparse_ty ~ loc ctxt capt...
let transfer ( ctxt , sc ) gas amount tp p destination entrypoint = let ctxt = update_context gas ctxt in collect_lazy_storage ctxt tp p >>?= fun ( to_duplicate , ctxt ) -> let to_update = no_lazy_storage_id in extract_lazy_storage_diff ctxt Optimized tp p ~ to_duplicate ~ to_update ~ temporary : true >>=? fun ( p , la...
let create_contract ( ctxt , sc ) gas storage_type param_type code views entrypoints delegate credit init = let ctxt = update_context gas ctxt in let loc = Micheline . dummy_location in unparse_parameter_ty ~ loc ctxt param_type ~ entrypoints >>?= fun ( unparsed_param_type , ctxt ) -> unparse_ty ~ loc ctxt storage_type...
let unpack ctxt ~ ty ~ bytes = Gas . consume ctxt ( Script . deserialization_cost_estimated_from_bytes ( Bytes . length bytes ) ) >>?= fun ctxt -> if Compare . Int . ( Bytes . length bytes >= 1 ) && Compare . Int . ( TzEndian . get_uint8 bytes 0 = 0x05 ) then let str = Bytes . sub_string bytes 1 ( Bytes . length bytes ...
let rec interp_stack_prefix_preserving_operation : type a s b t c u d w result . ( a -> s -> ( b * t ) * result ) -> ( a , s , b , t , c , u , d , w ) stack_prefix_preservation_witness -> c -> u -> ( d * w ) * result = fun f n accu stk -> match ( n , stk ) with | ( KPrefix ( _ , n ) , rest ) -> interp_stack_prefix_pres...
type ( ' a , ' s , ' b , ' t , ' r , ' f ) step_type = outdated_context * step_constants -> local_gas_counter -> ( ' a , ' s , ' b , ' t ) kinstr -> ( ' b , ' t , ' r , ' f ) continuation -> ' a -> ' s -> ( ' r * ' f * outdated_context * local_gas_counter ) tzresult Lwt . t
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h , ' m , ' n , ' o ) kmap_exit_type = ( ( ' c , ' d , ' e , ' f ) continuation -> ( ' a , ' b , ' g , ' h ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' m * ' n , ' c * ' d , ' o , ' c * ' d ) kinstr * ( ' m * ' n ) list * ( ' m , ' ...
type ( ' a , ' b , ' c , ' d , ' e , ' j , ' k ) kmap_enter_type = ( ( ' a , ' b * ' c , ' d , ' e ) continuation -> ( ' a , ' b * ' c , ' d , ' e ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' j * ' k , ' b * ' c , ' a , ' b * ' c ) kinstr * ( ' j * ' k ) list * ( ' j , ' a ) map -> ...
type ( ' a , ' b , ' c , ' d , ' i , ' j ) klist_exit_type = ( ( ' a , ' b , ' c , ' d ) continuation -> ( ' a , ' b , ' c , ' d ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' i , ' a * ' b , ' j , ' a * ' b ) kinstr * ' i list * ' j list * int -> ( ' j boxed_list , ' a * ' b , ' c , ...
type ( ' a , ' b , ' c , ' d , ' e , ' j ) klist_enter_type = ( ( ' b , ' a * ' c , ' d , ' e ) continuation -> ( ' b , ' a * ' c , ' d , ' e ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' j , ' a * ' c , ' b , ' a * ' c ) kinstr * ' j list * ' b list * int -> ( ' b boxed_list , ' a *...
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g ) kloop_in_left_type = outdated_context * step_constants -> local_gas_counter -> ( ' c , ' d , ' e , ' f ) continuation -> ( ' a , ' g , ' c , ' d ) kinstr -> ( ' b , ' g , ' e , ' f ) continuation -> ( ' a , ' b ) union -> ' g -> ( ' e * ' f * outdated_context * local_gas...
type ( ' a , ' b , ' c , ' r , ' f , ' s ) kloop_in_type = outdated_context * step_constants -> local_gas_counter -> ( ' b , ' c , ' r , ' f ) continuation -> ( ' a , ' s , ' b , ' c ) kinstr -> ( ' a , ' s , ' r , ' f ) continuation -> bool -> ' a * ' s -> ( ' r * ' f * outdated_context * local_gas_counter ) tzresult ...
type ( ' a , ' b , ' s , ' r , ' f ) kiter_type = ( ( ' a , ' s , ' r , ' f ) continuation -> ( ' a , ' s , ' r , ' f ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' b , ' a * ' s , ' a , ' s ) kinstr * ' b list -> ( ' a , ' s , ' r , ' f ) continuation -> ' a -> ' s -> ( ' r * ' f * o...
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h ) ilist_map_type = ( ( ' a , ' b , ' c , ' d ) continuation -> ( ' a , ' b , ' c , ' d ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' e , ' a * ' b , ' f , ' a * ' b ) kinstr * ( ' f boxed_list , ' a * ' b , ' g , ' h ) kinstr -> ( ...
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g ) ilist_iter_type = ( ( ' a , ' b , ' c , ' d ) continuation -> ( ' a , ' b , ' c , ' d ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' e , ' a * ' b , ' a , ' b ) kinstr * ( ' a , ' b , ' f , ' g ) kinstr -> ( ' f , ' g , ' c , ' d ) cont...
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g ) iset_iter_type = ( ( ' a , ' b , ' c , ' d ) continuation -> ( ' a , ' b , ' c , ' d ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' e , ' a * ' b , ' a , ' b ) kinstr * ( ' a , ' b , ' f , ' g ) kinstr -> ( ' f , ' g , ' c , ' d ) conti...
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h , ' i ) imap_map_type = ( ( ' a , ' b , ' c , ' d ) continuation -> ( ' a , ' b , ' c , ' d ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' e * ' f , ' a * ' b , ' g , ' a * ' b ) kinstr * ( ( ' e , ' g ) map , ' a * ' b , ' h , ' i ...
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h ) imap_iter_type = ( ( ' a , ' b , ' c , ' d ) continuation -> ( ' a , ' b , ' c , ' d ) continuation ) -> outdated_context * step_constants -> local_gas_counter -> ( ' e * ' f , ' a * ' b , ' a , ' b ) kinstr * ( ' a , ' b , ' g , ' h ) kinstr -> ( ' g , ' h , ' c ,...
type ( ' a , ' b , ' c , ' d , ' e , ' f ) imul_teznat_type = logger option -> outdated_context * step_constants -> local_gas_counter -> ( Tez . t , ' a ) kinfo * ( Tez . t , ' b , ' c , ' d ) kinstr -> ( ' c , ' d , ' e , ' f ) continuation -> Tez . t -> Script_int . n Script_int . num * ' b -> ( ' e * ' f * outdated_...
type ( ' a , ' b , ' c , ' d , ' e , ' f ) imul_nattez_type = logger option -> outdated_context * step_constants -> local_gas_counter -> ( Script_int . n Script_int . num , ' a ) kinfo * ( Tez . t , ' b , ' c , ' d ) kinstr -> ( ' c , ' d , ' e , ' f ) continuation -> Script_int . n Script_int . num -> Tez . t * ' b ->...
type ( ' a , ' b , ' c , ' d , ' e , ' f ) ilsl_nat_type = logger option -> outdated_context * step_constants -> local_gas_counter -> ( Script_int . n Script_int . num , ' a ) kinfo * ( Script_int . n Script_int . num , ' b , ' c , ' d ) kinstr -> ( ' c , ' d , ' e , ' f ) continuation -> Script_int . n Script_int . nu...
type ( ' a , ' b , ' c , ' d , ' e , ' f ) ilsr_nat_type = logger option -> outdated_context * step_constants -> local_gas_counter -> ( Script_int . n Script_int . num , ' a ) kinfo * ( Script_int . n Script_int . num , ' b , ' c , ' d ) kinstr -> ( ' c , ' d , ' e , ' f ) continuation -> Script_int . n Script_int . nu...
type ( ' a , ' b ) ifailwith_type = logger option -> outdated_context * step_constants -> local_gas_counter -> Script . location -> ' a ty -> ' a -> ( ' b , error trace ) result Lwt . t
type ( ' a , ' b , ' c , ' d , ' e , ' f , ' g ) iexec_type = logger option -> outdated_context * step_constants -> local_gas_counter -> ( ' a , ' b , ' c , ' d ) kinstr -> ( ' c , ' d , ' e , ' f ) continuation -> ' g -> ( ' g , ' a ) lambda * ' b -> ( ' e * ' f * outdated_context * local_gas_counter ) tzresult Lwt . ...
type ' t repr = Z . t
type ' t num = Num_tag of ' t repr [ @@ ocaml . unboxed ]
let compare ( Num_tag x ) ( Num_tag y ) = Z . compare x y
let zero = Num_tag Z . zero
let zero_n = Num_tag Z . zero
let one_n = Num_tag Z . one
let to_string ( Num_tag x ) = Z . to_string x
let of_string s = Option . catch ( fun ( ) -> Num_tag ( Z . of_string s ) )
let of_int32 n = Num_tag ( Z . of_int64 @@ Int64 . of_int32 n )
let to_int64 ( Num_tag x ) = Option . catch ( fun ( ) -> Z . to_int64 x )
let of_int64 n = Num_tag ( Z . of_int64 n )
let to_int ( Num_tag x ) = Option . catch ( fun ( ) -> Z . to_int x )
let of_int n = Num_tag ( Z . of_int n )
let of_zint x = Num_tag x
let to_zint ( Num_tag x ) = x
let add ( Num_tag x ) ( Num_tag y ) = Num_tag ( Z . add x y )
let sub ( Num_tag x ) ( Num_tag y ) = Num_tag ( Z . sub x y )
let mul ( Num_tag x ) ( Num_tag y ) = Num_tag ( Z . mul x y )
let ediv ( Num_tag x ) ( Num_tag y ) = let ediv_tagged x y = let ( quo , rem ) = Z . ediv_rem x y in ( Num_tag quo , Num_tag rem ) in Option . catch ( fun ( ) -> ediv_tagged x y )
let succ_n ( Num_tag x ) = Num_tag ( Z . succ x )
let abs ( Num_tag x ) = Num_tag ( Z . abs x )
let is_nat ( Num_tag x ) = if Compare . Z . ( x < Z . zero ) then None else Some ( Num_tag x )
let neg ( Num_tag x ) = Num_tag ( Z . neg x )
let int ( Num_tag x ) = Num_tag x
let shift_left ( Num_tag x ) ( Num_tag y ) = if Compare . Int . ( Z . compare y ( Z . of_int 256 ) > 0 ) then None else let y = Z . to_int y in Some ( Num_tag ( Z . shift_left x y ) )
let shift_right ( Num_tag x ) ( Num_tag y ) = if Compare . Int . ( Z . compare y ( Z . of_int 256 ) > 0 ) then None else let y = Z . to_int y in Some ( Num_tag ( Z . shift_right x y ) )
let logor ( Num_tag x ) ( Num_tag y ) = Num_tag ( Z . logor x y )
let logxor ( Num_tag x ) ( Num_tag y ) = Num_tag ( Z . logxor x y )
let logand ( Num_tag x ) ( Num_tag y ) = Num_tag ( Z . logand x y )
let lognot ( Num_tag x ) = Num_tag ( Z . lognot x )
let z_encoding : z num Data_encoding . encoding = Data_encoding . ( conv ( fun ( Num_tag z ) -> z ) ( fun z -> Num_tag z ) z )
let n_encoding : n num Data_encoding . encoding = Data_encoding . ( conv ( fun ( Num_tag n ) -> n ) ( fun n -> Num_tag n ) n )
type var_annot = Var_annot of Non_empty_string . t [ @@ ocaml . unboxed ]
type type_annot = Type_annot of Non_empty_string . t [ @@ ocaml . unboxed ]
type field_annot = Field_annot of Non_empty_string . t [ @@ ocaml . unboxed ]
module FOR_TESTS = struct let unsafe_field_annot_of_string s = Field_annot ( Non_empty_string . of_string_exn s ) end
let error_unexpected_annot loc annot = match annot with | [ ] -> Result . return_unit | _ :: _ -> error ( Unexpected_annotation loc )
let string_iter p s i = let len = String . length s in let rec aux i = if Compare . Int . ( i >= len ) then Result . return_unit else p s . [ i ] >>? fun ( ) -> aux ( i + 1 ) in aux i
let is_allowed_char = function | ' a ' . . ' z ' | ' A ' . . ' Z ' | ' _ ' | ' . ' | ' ' % | ' ' @ | ' 0 ' . . ' 9 ' -> true | _ -> false
let check_char loc c = if is_allowed_char c then Result . return_unit else error ( Unexpected_annotation loc )
type annot_opt = | Field_annot_opt of Non_empty_string . t option | Type_annot_opt of Non_empty_string . t option | Var_annot_opt of Non_empty_string . t option
let percent = Non_empty_string . of_string_exn " " %
let percent_percent = Non_empty_string . of_string_exn " " %%
let at = Non_empty_string . of_string_exn " " @
let parse_annots loc ( ? allow_special_var = false ) ( ? allow_special_field = false ) l = let sub_or_wildcard wrap s = match Non_empty_string . of_string s with | None -> ok @@ wrap None | Some s -> ( match ( s :> string ) . [ 0 ] with | ' a ' . . ' z ' | ' A ' . . ' Z ' | ' _ ' | ' 0 ' . . ' 9 ' -> string_iter ( chec...
let opt_var_of_var_opt = function None -> None | Some a -> Some ( Var_annot a )
let opt_field_of_field_opt = function | None -> None | Some a -> Some ( Field_annot a )
let opt_type_of_type_opt = function | None -> None | Some a -> Some ( Type_annot a )
let classify_annot loc l : ( var_annot option list * type_annot option list * field_annot option list ) tzresult = try let ( _ , rv , _ , rt , _ , rf ) = List . fold_left ( fun ( in_v , rv , in_t , rt , in_f , rf ) a -> match ( a , in_v , rv , in_t , rt , in_f , rf ) with | ( Var_annot_opt a , true , _ , _ , _ , _ , _ ...
let get_one_annot loc = function | [ ] -> Result . return_none | [ a ] -> ok a | _ -> error ( Unexpected_annotation loc )
let get_two_annot loc = function | [ ] -> ok ( None , None ) | [ a ] -> ok ( a , None ) | [ a ; b ] -> ok ( a , b ) | _ -> error ( Unexpected_annotation loc )
let check_type_annot : Script . location -> string list -> unit tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun ( vars , types , fields ) -> error_unexpected_annot loc vars >>? fun ( ) -> error_unexpected_annot loc fields >>? fun ( ) -> get_one_annot loc types >|? fun _a -> ( )
let check_composed_type_annot : Script . location -> string list -> unit tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun ( vars , types , fields ) -> error_unexpected_annot loc vars >>? fun ( ) -> get_one_annot loc types >>? fun _t -> get_two_annot loc fields >|? fun ( _f1 , _f2 ) -> (...
let parse_field_annot : Script . location -> string list -> field_annot option tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun ( vars , types , fields ) -> error_unexpected_annot loc vars >>? fun ( ) -> error_unexpected_annot loc types >>? fun ( ) -> get_one_annot loc fields
let is_field_annot loc a = parse_field_annot loc [ a ] >|? function | Some ( _a : field_annot ) -> true | None -> false
let extract_field_annot : Script . node -> ( Script . node * field_annot option ) tzresult = function | Prim ( loc , prim , args , annot ) -> let rec extract_first acc = function | [ ] -> ( None , annot ) | s :: rest -> if Compare . Int . ( String . length s > 0 ) && Compare . Char . ( s . [ 0 ] = ' ' ) % then ( Some s...
let has_field_annot node = extract_field_annot node >|? function | ( _node , Some _ ) -> true | ( _node , None ) -> false
let remove_field_annot node = extract_field_annot node >|? fun ( node , _a ) -> node
let extract_entrypoint_annot : Script . node -> ( Script . node * Entrypoint . t option ) tzresult = fun node -> extract_field_annot node >|? fun ( node , field_annot_opt ) -> ( node , Option . bind field_annot_opt ( fun ( Field_annot field_annot ) -> Entrypoint . of_annot_lax_opt field_annot ) )
let check_var_annot : Script . location -> string list -> unit tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun ( vars , types , fields ) -> error_unexpected_annot loc types >>? fun ( ) -> error_unexpected_annot loc fields >>? fun ( ) -> get_one_annot loc vars >|? fun ( _a : var_annot o...