text
stringlengths
0
601k
let iter f l = Seq . iter f ( seq l )
let fold f acc l = Seq . fold_left f acc ( seq l )
let update_rec_next rs rem = match rs with | Types . Trec_next -> rem | Types . ( Trec_first | Trec_not ) -> match rem with | Types . Sig_type ( id , decl , Trec_next , priv ) :: rem -> Types . Sig_type ( id , decl , rs , priv ) :: rem | Types . Sig_module ( id , pres , mty , Trec_next , priv ) :: rem -> Types . Sig_mo...
type in_place_patch = { ghosts : Types . signature ; replace_by : Types . signature_item option ; }
let replace_in_place f sg = let rec next_group f before signature = match next signature with | None -> None | Some ( item , sg ) -> core_group f ~ before ~ ghosts : item . pre_ghosts ~ before_group [ ] : ( rec_items item . group ) ~ sg and core_group f ~ before ~ ghosts ~ before_group current ~ sg = let commit ghosts ...
type parameter_info = { label : Asttypes . arg_label ; param_start : int ; param_end : int ; argument : Typedtree . expression option }
type application_signature = { function_name : string option ; function_position : Msource . position ; signature : string ; parameters : parameter_info list ; active_param : int option }
let extract_ident ( exp_desc : Typedtree . expression_desc ) = let rec longident ppf : Longident . t -> unit = function | Lident s -> fprintf ppf " % s " ( Completion . parenthesize_name s ) | Ldot ( p , s ) -> fprintf ppf " % a . % s " longident p ( Completion . parenthesize_name s ) | Lapply ( p1 , p2 ) -> fprintf pp...
let pp_type env ppf ty = let module Printtyp = Type_utils . Printtyp in Printtyp . wrap_printing_env env ~ verbosity : 0 ( fun ( ) -> Printtyp . mark_loops ty ; Printtyp . type_sch ppf ty )
let pp_parameter_type env ppf ty = match ty with | { Types . desc = Tarrow _ ; _ } as ty -> Format . fprintf ppf " ( % a ) " ( pp_type env ) ty | ty -> pp_type env ppf ty
let pp_parameter env label ppf ty = match label with | Asttypes . Nolabel -> pp_parameter_type env ppf ty | Asttypes . Labelled l -> Format . fprintf ppf " % s :% a " l ( pp_parameter_type env ) ty | Asttypes . Optional l -> let unwrap_option ty = match ( Ctype . repr ty ) . Types . desc with | Types . Tconstr ( path ,...
let print_parameter_offset ? arg : argument ppf buffer env label ty = let param_start = Buffer . length buffer in Format . fprintf ppf " % a " %! ( pp_parameter env label ) ty ; let param_end = Buffer . length buffer in Format . pp_print_string ppf " -> " ; Format . pp_print_flush ppf ( ) ; { label ; param_start ; para...
let separate_function_signature ~ args ( e : Typedtree . expression ) = Type_utils . Printtyp . reset ( ) ; let buffer = Buffer . create 16 in let ppf = Format . formatter_of_buffer buffer in let rec separate ( ? i = 0 ) ( ? parameters [ ] ) = args ty = match ( args , ty ) with | ( l , arg ) :: args , { Types . desc = ...
let active_parameter_by_arg ~ arg params = let find_by_arg = function | { argument = Some a ; _ } when a == arg -> true | _ -> false in try Some ( List . index params ~ f : find_by_arg ) with Not_found -> None
let active_parameter_by_prefix ~ prefix params = let common = function | Asttypes . Nolabel -> Some 0 | l when String . is_prefixed ~ by " " :~ prefix || String . is_prefixed ~ by " " :? prefix -> Some ( String . common_prefix_len ( Btype . prefixed_label_name l ) prefix ) | _ -> None in let rec find_by_prefix ( ? i = ...
let application_signature ~ prefix = function | ( _ , Expression arg ) :: ( _ , Expression { exp_desc = Texp_apply ( { exp_type = { desc = Tarrow _ ; _ } ; _ } as e , args ) ; _ } ) :: _ -> let result = separate_function_signature e ~ args in let active_param = active_parameter_by_arg ~ arg result . parameters in let a...
module type Infix = sig type t include Unsigned . Infix with type t := t val ( asr ) : t -> int -> t end
module type S = sig type t module Infix : Infix with type t := t include Unsigned . S with type t := t with module Infix := Infix val neg : t -> t val abs : t -> t val minus_one : t val min_int : t val shift_right_logical : t -> int -> t val of_nativeint : nativeint -> t val to_nativeint : t -> nativeint val of_int64 :...
module type Basics = sig type t val add : t -> t -> t val sub : t -> t -> t val mul : t -> t -> t val div : t -> t -> t val rem : t -> t -> t val logand : t -> t -> t val logor : t -> t -> t val logxor : t -> t -> t val shift_left : t -> int -> t val shift_right : t -> int -> t val shift_right_logical : t -> int -> t e...
module MakeInfix ( S : Basics ) = struct open S let ( ) + = add let ( ) - = sub let ( * ) = mul let ( ) / = div let ( mod ) = rem let ( land ) = logand let ( lor ) = logor let ( lxor ) = logxor let ( lsl ) = shift_left let ( lsr ) = shift_right_logical let ( asr ) = shift_right end
module Int = struct module Basics = struct type t = int let add = ( + ) let sub = ( - ) let mul = ( * ) let div = ( / ) let rem = ( mod ) let max_int = Stdlib . max_int let min_int = Stdlib . min_int let logand = ( land ) let logor = ( lor ) let logxor = ( lxor ) let shift_left = ( lsl ) let shift_right = ( asr ) let s...
module Int32 = struct [ @@@ ocaml . warning " - 32 " ] let equal ( x : int32 ) ( y : int32 ) = x = y let of_string_opt s = try Some ( Int32 . of_string s ) with Failure _ -> None include Int32 module Infix = MakeInfix ( Int32 ) let of_nativeint = Nativeint . to_int32 let to_nativeint = Nativeint . of_int32 let of_int64...
module Int64 = struct [ @@@ ocaml . warning " - 32 " ] let equal ( x : int64 ) ( y : int64 ) = x = y let of_string_opt s = try Some ( Int64 . of_string s ) with Failure _ -> None include Int64 module Infix = MakeInfix ( Int64 ) let of_int64 x = x let to_int64 x = x let max = Stdlib . max let min = Stdlib . min let pp f...
let of_byte_size : int -> ( module S ) = function | 4 -> ( module Int32 ) | 8 -> ( module Int64 ) | _ -> invalid_arg " Signed . of_byte_size "
module SInt = ( val of_byte_size ( int_size ( ) ) )
module Long = ( val of_byte_size ( long_size ( ) ) )
module LLong = ( val of_byte_size ( llong_size ( ) ) )
module Poly = struct [ %% versioned module Stable = struct module V1 = struct type ( ' payload , ' pk , ' signature ) ' signature t = { payload : ' payload ; signer : ' pk ; signature : ' signature } [ @@ deriving compare , sexp , hash , yojson , equal ] equal end end ] end end [ %% versioned
module Stable = struct module V2 = struct type t = ( Payload . Stable . V2 . t , Public_key . Stable . V1 . t , Signature . Stable . V1 . t ) Poly . Stable . V1 . t [ @@ deriving compare , sexp , hash , yojson ] yojson let to_latest = Fn . id let description = " User command " let version_byte = Base58_check . Version_...
type _unused = unit constraint ( Payload . t , Public_key . t , Signature . t ) t Poly . t = t
let payload Poly { . payload ; _ } = payload
let fee = Fn . compose Payload . fee payload
let nonce = Fn . compose Payload . nonce payload
let has_insufficient_fee t = Currency . Fee ( . fee t < minimum_fee ) minimum_fee
let signer { Poly . signer ; _ } = signer
let fee_token ( _ : t ) t = Token_id . default
let fee_payer_pk ( { payload ; _ } : t ) t = Payload . fee_payer_pk payload
let fee_payer ( { payload ; _ } : t ) t = Payload . fee_payer payload
let fee_excess ( { payload ; _ } : t ) t = Payload . fee_excess payload
let token ( { payload ; _ } : t ) t = Payload . token payload
let source_pk ( { payload ; _ } : t ) t = Payload . source_pk payload
let source ( { payload ; _ } : t ) t = Payload . source payload
let receiver_pk ( { payload ; _ } : t ) t = Payload . receiver_pk payload
let receiver ( { payload ; _ } : t ) t = Payload . receiver payload
let amount = Fn . compose Payload . amount payload
let memo = Fn . compose Payload . memo payload
let valid_until = Fn . compose Payload . valid_until payload
let tag ( { payload ; _ } : t ) t = Payload . tag payload
let tag_string ( t : t ) t = match t . payload . body with | Payment _ -> " payment " | Stake_delegation _ -> " delegation "
let to_input_legacy ( payload : Payload . t ) t = Transaction_union_payload ( . to_input_legacy ( of_user_command_payload payload ) payload ) payload
let sign_payload ? signature_kind ( private_key : Signature_lib . Private_key . t ) t ( payload : Payload . t ) t : Signature . t = Signature_lib . Schnorr . Legacy . sign ? signature_kind private_key ( to_input_legacy payload ) payload
let sign ? signature_kind ( kp : Signature_keypair . t ) t ( payload : Payload . t ) t : t = { payload ; signer = kp . public_key ; signature = sign_payload ? signature_kind kp . private_key payload }
module For_tests = struct let fake_sign ? signature_kind : _ ( kp : Signature_keypair . t ) t ( payload : Payload . t ) t : t = { payload ; signer = kp . public_key ; signature = Signature . dummy } end
module Gen = struct let gen_inner ( sign ' : Signature_lib . Keypair . t -> Payload . t -> t ) t ~ key_gen ( ? nonce = Account_nonce . zero ) zero ~ fee_range create_body = let open Quickcheck . Generator . Let_syntax in let min_fee = Fee . to_int Mina_compile_config . minimum_user_command_fee in let max_fee = min_fee ...
module With_valid_signature = struct [ %% versioned module Stable = struct module V2 = struct type t = Stable . V2 . t [ @@ deriving sexp , equal , yojson , hash ] hash let to_latest = Stable . V2 . to_latest let compare = Stable . V2 . compare let equal = Stable . V2 . equal module Gen = Gen end end ] end module Gen =...
let to_valid_unsafe t = ` If_this_is_used_it_should_have_a_comment_justifying_it t
module Base58_check = Codable . Make_base58_check ( Stable . Latest ) Latest [ %% define_locally
let check_signature ? signature_kind ( { payload ; signer ; signature } : t ) t = Signature_lib . Schnorr . Legacy . verify ? signature_kind signature ( Snark_params . Tick . Inner_curve . of_affine signer ) signer ( to_input_legacy payload ) payload
let public_keys t = let fee_payer = fee_payer_pk t in let source = source_pk t in let receiver = receiver_pk t in [ fee_payer ; source ; receiver ]
let check_valid_keys t = List . for_all ( public_keys t ) t ~ f ( : fun pk -> Option . is_some ( Public_key . decompress pk ) pk )
let create_with_signature_checked ? signature_kind signature signer payload = let open Option . Let_syntax in let % bind signer = Public_key . decompress signer in let t = Poly { . payload ; signature ; signer } in Option . some_if ( check_signature ? signature_kind t && check_valid_keys t ) t t
let gen_test = let open Quickcheck . Let_syntax in let % bind keys = Quickcheck . Generator . list_with_length 2 Signature_keypair . gen in Gen . payment_with_random_participants ~ sign_type ` : Real ~ keys ( : Array . of_list keys ) keys ~ max_amount : 10000 ~ fee_range : 1000 ( ) Quickcheck . test ~ trials : 20 gen_t...
let check t = Option . some_if ( check_signature t && check_valid_keys t ) t t
let check_only_for_signature t = Option . some_if ( check_signature t ) t t
let forget_check t = t
let filter_by_participant user_commands public_key = List . filter user_commands ~ f ( : fun user_command -> Core_kernel . List . exists ( accounts_accessed user_command ) user_command ~ f : ( Fn . compose ( Public_key . Compressed . equal public_key ) public_key Account_id . public_key ) )
module type Gen_intf = sig type t module Gen : sig val payment : ? sign_type [ : ` Fake | ` Real ] -> key_gen : ( Signature_keypair . t * Signature_keypair . t ) t Quickcheck . Generator . t -> ? nonce : Account_nonce . t -> ? min_amount : int -> max_amount : int -> fee_range : int -> unit -> t Quickcheck . Generator ....
module type S = sig type t [ @@ deriving sexp , yojson , hash ] hash include Comparable . S with type t := t include Hashable . S with type t := t val payload : t -> Signed_command_payload . t val fee : t -> Currency . Fee . t val nonce : t -> Account_nonce . t val signer : t -> Public_key . t val fee_token : t -> Toke...
module Stable = struct module V1 = struct type t = string [ @@ deriving sexp , equal , compare , hash ] hash let to_latest = Fn . id module Base58_check = Base58_check . Make ( struct let description = " User command memo " let version_byte = Base58_check . Version_bytes . user_command_memo end ) end let to_base58_chec...
let digest_length_byte = Char . of_int_exn digest_length
let memo_length = digest_length + 2
let tag ( memo : t ) t = memo [ . tag_index ] tag_index
let length memo = Char . to_int memo [ . length_index ] length_index
let is_bytes memo = Char . equal ( tag memo ) memo bytes_tag
let is_digest memo = Char . equal ( tag memo ) memo digest_tag
let is_valid memo = Int ( . String . length memo = memo_length ) memo_length && let length = length memo in if is_digest memo then Int ( . length = digest_length ) digest_length else Char . equal ( tag memo ) memo bytes_tag && Int ( . length <= digest_length ) digest_length && let padded = String . sub memo ~ pos ( : l...
let create_by_digesting_string_exn s = if Int ( . String . length s > max_digestible_string_length ) max_digestible_string_length then raise Too_long_digestible_string ; let digest = Blake2 ( . to_raw_string ( digest_string s ) s ) s in String . init memo_length ~ f ( : fun ndx -> if Int ( . ndx = tag_index ) tag_index...
let create_by_digesting_string ( s : string ) string = try Ok ( create_by_digesting_string_exn s ) s with Too_long_digestible_string -> Or_error . error_string " create_by_digesting_string : string too long "
module type Memoable = sig type t val length : t -> int val get : t -> int -> char end
let create_from_value_exn ( type t ) t ( module M : Memoable with type t = t ) t ( value : t ) t = let len = M . length value in if Int ( . len > max_input_length ) max_input_length then raise Too_long_user_memo_input ; String . init memo_length ~ f ( : fun ndx -> if Int ( . ndx = tag_index ) tag_index then bytes_tag e...
let create_from_bytes_exn bytes = create_from_value_exn ( module Bytes ) Bytes bytes
let create_from_bytes bytes = try Ok ( create_from_bytes_exn bytes ) bytes with Too_long_user_memo_input -> Or_error . error_string ( sprintf " create_from_bytes : length exceeds % d " max_input_length ) max_input_length
let create_from_string_exn s = create_from_value_exn ( module String ) String s
let create_from_string s = try Ok ( create_from_string_exn s ) s with Too_long_user_memo_input -> Or_error . error_string ( sprintf " create_from_string : length exceeds % d " max_input_length ) max_input_length
let dummy = ( create_by_digesting_string_exn " " :> t ) t
let empty = create_from_string_exn " "
type raw = Digest of string | Bytes of string
let to_raw_exn memo = let tag = tag memo in if Char . equal tag digest_tag then Digest ( to_base58_check memo ) memo else if Char . equal tag bytes_tag then let len = length memo in Bytes ( String . init len ~ f ( : fun idx -> memo [ . idx - 2 ] 2 ) 2 ) 2 else failwithf " Unknown memo tag % c " tag ( )
let to_raw_bytes_exn memo = match to_raw_exn memo with | Digest _ -> failwith " Cannot convert a digest to raw bytes " | Bytes str -> str
let of_raw_exn = function | Digest base58_check -> of_base58_check_exn base58_check | Bytes str -> of_base58_check_exn str
let fold_bits t = { Fold_lib . Fold . fold = ( fun ~ init ~ f -> let n = 8 * String . length t in let rec go acc i = if i = n then acc else let b = ( Char . to_int t [ . i / 8 ] 8 lsr ( i mod 8 ) 8 ) 8 land 1 = 1 in go ( f acc b ) b ( i + 1 ) 1 in go init 0 ) }
let to_bits t = Fold_lib . Fold . to_list ( fold_bits t ) t
let gen = Quickcheck . Generator . map String . quickcheck_generator ~ f : create_by_digesting_string_exn
let hash memo = Random_oracle . hash ~ init : Hash_prefix . zkapp_memo ( Random_oracle . Legacy . pack_input ( Random_oracle_input . Legacy . bitstring ( to_bits memo ) memo ) memo )
let to_plaintext ( memo : t ) t : string Or_error . t = if is_bytes memo then Ok ( String . sub memo ~ pos : 2 ~ len ( : length memo ) memo ) memo else Error ( Error . of_string " Memo does not contain text bytes ) "
let to_digest ( memo : t ) t : string Or_error . t = if is_digest memo then Ok ( String . sub memo ~ pos : 2 ~ len : digest_length ) digest_length else Error ( Error . of_string " Memo does not contain a digest ) "
let to_string_hum ( memo : t ) t = match to_plaintext memo with | Ok text -> text | Error _ -> ( match to_digest memo with | Ok digest -> sprintf " 0x % s " ( Hex . encode digest ) digest | Error _ -> ( " Invalid memo , neither text nor a digest ) digest " )
module Checked = struct type unchecked = t type t = Boolean . var array let constant unchecked = assert ( Int ( . String . length ( unchecked :> string ) string = memo_length ) memo_length ) memo_length ; Array . map ( Blake2 . string_to_bits ( unchecked :> string ) string ) string ~ f : Boolean . var_of_value end
let length_in_bits = 8 * memo_length
let typ : ( Checked . t , t ) t Typ . t = Typ . transport ( Typ . array ~ length : length_in_bits Boolean . typ ) typ ~ there ( : fun ( t : t ) t -> Blake2 . string_to_bits ( t :> string ) string ) string ~ back ( : fun bs -> ( Blake2 . bits_to_string bs :> t ) t ) t [ %% endif ] endif