text
stringlengths
0
601k
let check_output verification_ctx cv commitment epk output_proof = RS . sapling_check_output verification_ctx ( Ctypes . ocaml_bytes_start ( of_cv cv ) ) ( Ctypes . ocaml_bytes_start ( of_commitment commitment ) ) ( Ctypes . ocaml_bytes_start ( of_epk epk ) ) ( Ctypes . ocaml_bytes_start ( of_output_proof output_proof ...
let final_check ctx balance binding_sig sighash = if not ( valid_balance balance ) then invalid_arg " balance " else RS . sapling_final_check ctx balance ( Ctypes . ocaml_bytes_start ( of_binding_sig binding_sig ) ) ( Ctypes . ocaml_bytes_start ( of_sighash sighash ) )
let zip32_xsk_master seed = assert ( Bytes . length seed = 32 ) ; let res = Bytes . create 169 in RS . zip32_xsk_master ( Ctypes . ocaml_bytes_start seed ) ( Unsigned . Size_t . of_int 32 ) ( Ctypes . ocaml_bytes_start res ) ; to_zip32_expanded_spending_key res
let zip32_xfvk_address xfvk j = let j_ret = Bytes . create 11 in let addr = Bytes . create 43 in let bytes_xfvk = of_zip32_full_viewing_key xfvk in let res = RS . zip32_xfvk_address ( Ctypes . ocaml_bytes_start bytes_xfvk ) ( Ctypes . ocaml_bytes_start ( of_diversifier_index j ) ) ( Ctypes . ocaml_bytes_start j_ret ) (...
let to_scalar input = assert ( Bytes . length input = 64 ) ; let res = Bytes . create 32 in RS . to_scalar ( Ctypes . ocaml_bytes_start input ) ( Ctypes . ocaml_bytes_start res ) ; res
let zip32_xsk_derive parent index = let bytes_parent = of_zip32_expanded_spending_key parent in assert ( Bytes . length bytes_parent = 169 ) ; assert ( Int32 . compare index Int32 . zero >= 0 ) ; let res = Bytes . create 169 in RS . zip32_xsk_derive ( Ctypes . ocaml_bytes_start bytes_parent ) ( Unsigned . UInt32 . of_i...
let zip32_xfvk_derive parent index = let bytes_parent = of_zip32_full_viewing_key parent in assert ( Bytes . length bytes_parent = 169 ) ; assert ( Int32 . compare index Int32 . zero >= 0 ) ; let derived = Bytes . create 169 in let res = RS . zip32_xfvk_derive ( Ctypes . ocaml_bytes_start bytes_parent ) ( Unsigned . UI...
let ( ) = Printexc . register_printer @@ function | Params_not_found locations -> let locations = List . sort_uniq String . compare locations in Some ( Format . asprintf " [ @< v > cannot find Zcash params in any of , :@\ % a @ You may download them using \ https :// raw . githubusercontent . com / zcash / zcash / mast...
type parameter_files = { spend_path : string ; output_path : string }
let find_params ( ? getenv_opt = Sys . getenv_opt ) ( ? getcwd = Sys . getcwd ) ( ? file_exists = Sys . file_exists ) ( ) = let ( // ) = Filename . concat in let env ? split name path = match getenv_opt name with | None -> [ ] | Some value -> ( match split with | None -> [ Filename . concat value path ] | Some char -> ...
let init_params ( ) = let { spend_path ; output_path } = find_params ( ) in let spend_hash = " 8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c \ 000 " in let output_hash = " 657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf...
let init_params_lazy = Lazy . from_fun init_params
let with_proving_ctx f = let ( ) = Lazy . force init_params_lazy in let ctx = proving_ctx_init ( ) in Fun . protect ~ finally ( : fun ( ) -> proving_ctx_free ctx ) ( fun ( ) -> f ctx )
let with_verification_ctx f = let ( ) = Lazy . force init_params_lazy in let ctx = verification_ctx_init ( ) in Fun . protect ~ finally ( : fun ( ) -> verification_ctx_free ctx ) ( fun ( ) -> f ctx )
module Bindings ( F : Cstubs . FOREIGN ) = struct open F let codeunit = uint8_t let init_zksnark_params = foreign " librustzcash_init_zksnark_params " ( ocaml_bytes @-> size_t @-> ocaml_string @-> ocaml_bytes @-> size_t @-> ocaml_string @-> ptr uchar @-> size_t @-> ocaml_string @-> returning void ) let nsk_to_nk = fore...
module type T = sig type ask type ak type nsk type nk type ovk type diversifier type pkd type nullifier type commitment type epk type symkey type sighash type spend_sig type hash type cv type rk type spend_proof type binding_sig type output_proof type ivk type ar type rcm type esk type diversifier_index val compare_div...
let step1_link = Github . URI . authorize ~ state " : TODO " ~ scopes ~ client_id ( )
module Resp = struct let wrap_html s = sprintf " < html >< body >% s </ body ></ html " > s let not_found _req err = let status = ` Not_found in let headers = Header . of_list [ " Cache - control " , " no - cache " ] in let body = sprintf " < html >< body >< h1 > Error </ h1 >< p >% s </ p ></ body ></ html " > err in ...
let callback _conn_id req _body = let uri = Request . uri req in let path = Uri . path uri in printf " % s % s [ % s ] \ n " %! ( Code . string_of_method ( Request . meth req ) ) path ( String . concat " , " ( List . map ( fun ( h , v ) -> sprintf " % s =% s " h ( String . concat " , " v ) ) ( Uri . query uri ) ) ) ; l...
let server_t = let port = 8080 in let conn_closed _conn_id = ( ) in let spec = Cohttp_lwt_unix . Server . make ~ callback ~ conn_closed ( ) in let ctx = Cohttp_lwt_unix . Net . init ( ) in let mode = ` TCP ( ` Port port ) in Cohttp_lwt_unix . Server . create ~ ctx ~ mode spec
let _ = Lwt_main . run server_t
let file_contents ( filename : Lwt_io . file_name ) : string Lwt . t = Lwt_io . with_file ~ mode : Lwt_io . input filename ( fun channel -> Lwt_io . read channel )
let save ( filename : Lwt_io . file_name ) ( ~ contents : string ) : unit Lwt . t = Lwt_io . with_file ~ mode : Lwt_io . output filename ( fun channel -> Lwt_io . write channel contents )
let uppercase_file ( filename : Lwt_io . file_name ) : unit Lwt . t = let % lwt text = file_contents filename in save filename ~ contents ( : String . uppercase_ascii text )
let count_lines ( filename : Lwt_io . file_name ) : int Lwt . t = let % lwt text = file_contents filename in String . split_on_char ' \ n ' text |> List . length |> Lwt . return
module type Delayer_intf = sig type t val create : float -> t val schedule : t -> ( unit -> ' a Lwt . t ) -> ' a Lwt . t end
module Delayer : Delayer_intf = struct type t = { delay : float ; jobs : ( unit -> unit ) Queue . t } let create ( delay : float ) : t = { delay ; jobs = Queue . create ( ) } let schedule ( t : t ) ( thunk : unit -> ' a Lwt . t ) : ' a Lwt . t = let waiter , wakener = Lwt . wait ( ) in Queue . add ( fun ( ) -> Lwt . on...
let rec copy_blocks ( buffer : bytes ) ( r : Lwt_io . input_channel ) ( w : Lwt_io . output_channel ) : unit Lwt . t = match % lwt Lwt_io . read_into r buffer 0 ( Bytes . length buffer ) with | 0 -> Lwt . return_unit | bytes_read -> let % lwt ( ) = Lwt_io . write_from_exactly w buffer 0 bytes_read in copy_blocks buffer...
let never_terminate : ' a . ' a Lwt . t = fst ( Lwt . wait ( ) )
let run ( uppercase : bool ) ( port : int ) : unit Lwt . t = let % lwt server = Lwt_io . establish_server ( Lwt_unix . ADDR_INET ( Unix . inet_addr_any , port ) ) ( fun ( r , w ) -> Lwt_io . read_chars r |> ( if uppercase then Lwt_stream . map Char . uppercase_ascii else fun x -> x ) |> Lwt_io . write_chars w ) in ( se...
let get_definition_from_json ( json : string ) : string option = match Yojson . Safe . from_string json with | ` Assoc kv_list -> let find key = match List . assoc key kv_list with | exception Not_found -> None | ` String " " -> None | s -> Some ( Yojson . Safe . to_string s ) in begin match find " Abstract " with | So...
let ( ) = let words = ref [ ] in let usage = " Usage : " ^ Sys . executable_name ^ " [ word . . . ] " in Arg . parse [ ] ( fun w -> words := w :: ! words ) usage ; words := List . rev ! words ; ( try Lwt_engine . set ( new Lwt_engine . libev ( ) ) with Lwt_sys . Not_available _ -> ( ) ) ; Lwt_main . run ( search_and_pr...
let query_uri ( ~ server : string ) ( query : string ) : Uri . t = let base_uri = Uri . of_string ( String . concat " " [ " https " ; :// server ; " /? format = json " ] ) in Uri . add_query_param base_uri ( " q " , [ query ] )
let print_result ( ( word , definition ) : string * ( string option , string ) result ) : unit Lwt . t = Lwt_io . printf " % s \ n % s \ n \ n % s \ n \ n " word ( String . init ( String . length word ) ( fun _ -> ' ' ) ) - ( match definition with | Error s -> " DuckDuckGo query failed : " ^ s | Ok None -> " No definit...
let get_definition ( ~ server : string ) ( word : string ) : ( string * ( string option , exn ) result ) Lwt . t = try % lwt let % lwt _resp , body = Cohttp_lwt_unix . Client . get ( query_uri ~ server word ) in let % lwt body ' = Cohttp_lwt_body . to_string body in Lwt . return ( word , Ok ( get_definition_from_json b...
let get_definition_with_timeout ( ~ server : string ) ( timeout : float ) ( word : string ) : ( string * ( string option , string ) result ) Lwt . t = Lwt . pick [ ( let % lwt ( ) = Lwt_unix . sleep timeout in Lwt . return ( word , Error " Timed out " ) ) ; ( let % lwt word , result = get_definition ~ server word in le...
let search_and_print ( ~ servers : string list ) ( timeout : float ) ( words : string list ) : unit Lwt . t = let servers = Array . of_list servers in let % lwt results = Lwt_list . mapi_p ( fun i word -> let server = servers . ( i mod Array . length servers ) in get_definition_with_timeout ~ server timeout word ) word...
let rec every ( ? stop : unit Lwt . t = never_terminate ) ( span : float ) ( f : unit -> unit Lwt . t ) : unit Lwt . t = if Lwt . is_sleeping stop then let % lwt ( ) = f ( ) in let % lwt ( ) = Lwt . pick [ Lwt_unix . sleep span ; Lwt . protected stop ] in every ~ stop span f else Lwt . return_unit
let log_delays ( thunk : unit -> unit Lwt . t ) : unit Lwt . t = let start = Unix . gettimeofday ( ) in let print_time ( ) = let diff = Unix . gettimeofday ( ) . - start in Lwt_io . printf " % f , " diff in let d = thunk ( ) in let % lwt ( ) = every 0 . 1 ~ stop : d print_time in let % lwt ( ) = d in let % lwt ( ) = pr...
let noalloc_busy_loop ( ) : unit = for _i = 0 to 10_000_000_000 do ( ) done
let ( ) = Lwt_main . run @@ log_delays ( fun ( ) -> Lwt_preemptive . detach noalloc_busy_loop ( ) )
module List = ListLabels ; ;
type ' a expr = | Base of ' a | Const of bool | And of ' a expr list | Or of ' a expr list | Not of ' a expr ; ;
let rec eval expr base_eval = let eval ' expr = eval expr base_eval in match expr with | Base base -> base_eval base | Const bool -> bool | And exprs -> List . for_all exprs ~ f : eval ' | Or exprs -> List . exists exprs ~ f : eval ' | Not expr -> not ( eval ' expr ) ; ;
let and_ l = if List . exists l ~ f ( : function Const false -> true | _ -> false ) then Const false else match List . filter l ~ f ( : function Const true -> false | _ -> true ) with | [ ] -> Const true | [ x ] -> x | l -> And l ; ;
let or_ l = if List . exists l ~ f ( : function Const true -> true | _ -> false ) then Const true else match List . filter l ~ f ( : function Const false -> false | _ -> true ) with | [ ] -> Const false | [ x ] -> x | l -> Or l ; ;
let not_ = function | Const b -> Const ( not b ) | e -> Not e ; ;
let rec simplify = function | Base _ | Const _ as x -> x | And l -> and_ ( List . map ~ f : simplify l ) | Or l -> or_ ( List . map ~ f : simplify l ) | Not e -> not_ ( simplify e ) ; ; ; ;
let ( ) = Printexc . record_backtrace true
let reporter ppf = let report src level ~ over k msgf = let k _ = over ( ) ; k ( ) in let with_metadata header _tags k ppf fmt = Format . kfprintf k ppf ( " % a [ % a ] : " ^^ fmt ^^ " \ n " ) %! Logs_fmt . pp_header ( level , header ) Fmt . ( styled ` Magenta string ) ( Logs . Src . name src ) in msgf @@ fun ? header ...
let ( ) = Fmt_tty . setup_std_outputs ~ style_renderer ` : Ansi_tty ~ utf_8 : true ( )
let ( ) = Logs . set_reporter ( reporter Fmt . stdout )
let ( ) = Logs . set_level ~ all : true ( Some Logs . Debug )
let insert state key value = let th0 = let open Part in insert key value in match Part . run state th0 with | state , ( ) -> state | exception Rowex . Duplicate -> Fmt . pr " # % S already exists . \ n " %! ( key :> string ) ; state
let lookup state key = let th0 = let open Part in find key in match Part . run state th0 with | state , value -> Fmt . pr " > % S => % 10d . \ n " %! ( key :> string ) value ; state | exception Not_found -> Fmt . pr " > % S does not exists . \ n " %! ( key :> string ) ; state
let parse_key key = try Ok ( Rowex . key key ) with _ -> Error ` Invalid_key
let parse_value value = try Ok ( int_of_string value ) with _ -> Error ` Invalid_value
let read_eval_print_loop path = let rec loop state = Fmt . pr " : " %! ; match Astring . String . cuts ~ sep " : " ( input_line stdin ) with | [ " insert " ; key ; value ; ] -> ( match parse_key key , parse_value value with | Ok key , Ok value -> let state = insert state key value in loop state | Error _ , _ -> Fmt . p...
let create path len = let th0 = let open Part in create ~ len path in match Part . ( run closed th0 ) with | _closed , Ok ( ) -> ( ) | _closed , Error ( ` Msg err ) -> Fmt . epr " % s . " err
let size_of_string str = let open Astring in let m , n = match String . head ~ rev : true str with | Some ' K ' | Some ' k ' -> 1_024 , 1 | Some ' M ' | Some ' m ' -> 1_048_576 , 1_024 | _ -> 1 , 0 in match String . cut ~ sep " . " : str with | Some ( a , b ) -> let a = int_of_string a in let b = int_of_string ( String...
let ( ) = match Sys . argv with | [ | _ ; path ; ] | when Sys . file_exists path -> read_eval_print_loop path | [ | _ ; " create " ; len ; path ] | -> let len = size_of_string len in create path len | _ -> Format . eprintf " % s [ create < len ] > < filename >\ n " %! Sys . argv . ( 0 )
module Q = struct include Q let any = " any " |> Symbol . intern let anything = " anything " |> Symbol . intern let line_end = " line - end " |> Symbol . intern let line_start = " line - start " |> Symbol . intern let not_ = " not " |> Symbol . intern let one_or_more = " one - or - more " |> Symbol . intern let or_ = "...
module Char_class = struct include Char_class let to_form t = match ( t : t ) with | Chars_in string -> Form . string string | Range ( c1 , c2 ) -> Form . string ( sprintf " % c -% c " c1 c2 ) ; ; let dash_char_set = Char . Set . singleton ' ' - let to_forms ts = let chars , other_ts = List . partition_map ts ~ f ( : f...
let label symbol args = Form . list ( Form . symbol symbol :: args )
let rec to_forms ts = List . map ts ~ f : to_form match ( t : t ) with | Any_char -> Form . symbol Q . anything | Any_in char_classes -> label Q . any ( Char_class . to_forms char_classes ) | Exactly string -> Form . string string | Line End -> Form . symbol Q . line_end | Line Start -> Form . symbol Q . line_start | N...
let rx_to_string = Funcall . Wrap . ( " rx - to - string " <: Form . t @-> return string )
let pattern t = rx_to_string ( to_form t )
module Char_class = struct type t = | Chars_in of string | Range of char * char [ @@ deriving sexp_of ] end
module Start_or_end = struct type t = | End | Start [ @@ deriving sexp_of ] end
module T = struct type t = | Any_char | Any_in of Char_class . t list | Exactly of string | Line of Start_or_end . t | None_in of Char_class . t list | One_or_more of t | Or of t list | Pattern of string | Point | Repeat of { min : int ; max : int option ; t : t } | Seq of t list | Submatch of t | Submatch_n of { index...
module type Rx = sig module Char_class : module type of struct include Char_class end module Start_or_end : module type of struct include Start_or_end end include module type of T with type t = T . t val pattern : t -> string end
EXTEND GLOBAL : expr ; expr : LEVEL " simple " [ [ " FOO " → <: expr < 1 >> | " { " | ; e = expr ; " } " | -> e ] ] ; END ; " expr - 1 " >:: ( fun [ _ -> assert_equal { ~ msg " = should be equal " } { ~ cmp = Reloc . eq_expr } <: expr < 1 >> ( expr_top " 1 " ) ] ) ; " do - 1 " >:: ( fun [ _ -> assert_equal { ~ msg " = ...
let make xs = Template_dsl . ( seq ~ sep " :\ n " xs )
let source s = Template_dsl . string s
let dest = Template_dsl . ( quote ~ using ' " ' : dest )
let tmp = Template_dsl . ( quote ~ using ' " ' : tmp )
let string s = Template_dsl . ( quote ~ using ' " ' : ( string s ) )
let int i = Template_dsl . int i
let float f = Template_dsl . float f
let dep w = Template_dsl . ( quote ~ using ' " ' : ( dep w ) )
let call_gen fn arg xs = let open Template_dsl in seq ~ sep " " : [ string fn ; string " ( " ; list ~ sep " , " : arg xs ; string " ) " ; ]
let call fn args = call_gen fn Fn . id args
let vector f xs = call_gen " c " f xs
let ints xs = vector Template_dsl . int xs
let string_call_gen fn arg xs = List . map xs ~ f : arg |> String . concat ~ sep " , " : |> Printf . sprintf " % s ( % s ) " fn
let ints_dep w = Workflow . ( app ( pure ( string_call_gen " c " Int . to_string ) ~ id " : r_script . ints " ) w ) |> Template_dsl . string_dep
let floats xs = vector Template_dsl . float xs
let floats_dep w = Workflow . ( app ( pure ( string_call_gen " c " Float . to_string ) ~ id " : r_script . floats " ) w ) |> Template_dsl . string_dep
let strings xs = vector string xs
let strings_dep w = Workflow . ( app ( pure ( string_call_gen " c " ( Printf . sprintf " % S " ) ) ~ id " : r_script . strings " ) w ) |> Template_dsl . string_dep
let deps xs = vector dep xs
let arg ? l e = let open Template_dsl in match l with | None -> e | Some label -> seq ~ sep " " : [ string label ; string " " = ; e ]
let assign var e = let open Template_dsl in seq ~ sep " : " [ string var ; string " " <- ; e ]
let workflow ? descr ? np ? mem ? img script = Workflow . shell ? descr ? img ? np ? mem Shell_dsl . [ cmd " Rscript " [ file_dump script ] ; ]
let workflow ' ? descr ? np ? mem ? img exprs = workflow ? descr ? np ? mem ? img ( make exprs )
with_buffer_formatter Pprintast . toplevel_phrase t ; let open Lexing in let pos = lb . lex_curr_pos in let len = lb . lex_buffer_len - lb . lex_curr_pos in ( Bytes . to_string ( Bytes . sub lb . lex_buffer pos len ) ) ; let lb = Lexing . from_string s in let rv = wrapped_toplevel_phrase lb in let rvs = pr rv in ( rvs ...
module type SET = sig type elt type t val empty : t val is_empty : t -> bool val mem : elt -> t -> bool val add : elt -> t -> t val singleton : elt -> t val remove : elt -> t -> t val union : t -> t -> t val inter : t -> t -> t val diff : t -> t -> t val compare : t -> t -> int val equal : t -> t -> bool val subset : t...
module type MAP = sig type key type ' + a t val empty : ' a t val is_empty : ' a t -> bool val mem : key -> ' a t -> bool val add : key -> ' a -> ' a t -> ' a t val update : key -> ( ' a option -> ' a option ) -> ' a t -> ' a t val singleton : key -> ' a -> ' a t val remove : key -> ' a t -> ' a t val merge : ( key -> ...
type token = | TIMES of ( int -> int -> int ) | RPAREN | PLUS of ( int -> int -> int ) | MINUS of ( int -> int -> int ) | LPAREN | INT of ( int ) int | EOL | DIV of ( int -> int -> int ) _menhir_lexer : Lexing . lexbuf -> token ; _menhir_lexbuf : Lexing . lexbuf ; mutable _menhir_token : token ; mutable _menhir_startp ...
let rec _menhir_run5 : _menhir_env -> ' ttv_tail * _menhir_state * ( int ) int -> ( int -> int -> int ) -> ' ttv_return = fun _menhir_env _menhir_stack _v -> let _menhir_stack = ( _menhir_stack , _v ) _v in let _tok = _menhir_discard _menhir_env in match _tok with | INT _v -> _menhir_run3 _menhir_env ( Obj . magic _men...