text
stringlengths
12
786k
let ( & ) x y = and32 x y
let ( ^^ ) = ( ^ )
let ( ^ ) x y = xor32 x y
type ctx = { k : Int32 . t array ; s : Int32 . t array array }
let q0 = [ | 0xA9 ; 0x67 ; 0xB3 ; 0xE8 ; 0x04 ; 0xFD ; 0xA3 ; 0x76 ; 0x9A ; 0x92 ; 0x80 ; 0x78 ; 0xE4 ; 0xDD ; 0xD1 ; 0x38 ; 0x0D ; 0xC6 ; 0x35 ; 0x98 ; 0x18 ; 0xF7 ; 0xEC ; 0x6C ; 0x43 ; 0x75 ; 0x37 ; 0x26 ; 0xFA ; 0x13 ; 0x9...
let q1 = [ | 0x75 ; 0xF3 ; 0xC6 ; 0xF4 ; 0xDB ; 0x7B ; 0xFB ; 0xC8 ; 0x4A ; 0xD3 ; 0xE6 ; 0x6B ; 0x45 ; 0x7D ; 0xE8 ; 0x4B ; 0xD6 ; 0x32 ; 0xD8 ; 0xFD ; 0x37 ; 0x71 ; 0xF1 ; 0xE1 ; 0x30 ; 0x0F ; 0xF8 ; 0x1B ; 0x87 ; 0xFA ; 0x0...
let m0 = [ | 0xBCBC3275l ; 0xECEC21F3l ; 0x202043C6l ; 0xB3B3C9F4l ; 0xDADA03DBl ; 0x02028B7Bl ; 0xE2E22BFBl ; 0x9E9EFAC8l ; 0xC9C9EC4Al ; 0xD4D409D3l ; 0x18186BE6l ; 0x1E1E9F6Bl ; 0x98980E45l ; 0xB2B2387Dl ; 0xA6A6D2E8l ; 0x2626B74Bl ; 0x3C3C57D6l ; 0x93938A32l ;...
let m1 = [ | 0xA9D93939l ; 0x67901717l ; 0xB3719C9Cl ; 0xE8D2A6A6l ; 0x04050707l ; 0xFD985252l ; 0xA3658080l ; 0x76DFE4E4l ; 0x9A084545l ; 0x92024B4Bl ; 0x80A0E0E0l ; 0x78665A5Al ; 0xE4DDAFAFl ; 0xDDB06A6Al ; 0xD1BF6363l ; 0x38362A2Al ; 0x0D54E6E6l ; 0xC6432020l ;...
let m2 = [ | 0xBC75BC32l ; 0xECF3EC21l ; 0x20C62043l ; 0xB3F4B3C9l ; 0xDADBDA03l ; 0x027B028Bl ; 0xE2FBE22Bl ; 0x9EC89EFAl ; 0xC94AC9ECl ; 0xD4D3D409l ; 0x18E6186Bl ; 0x1E6B1E9Fl ; 0x9845980El ; 0xB27DB238l ; 0xA6E8A6D2l ; 0x264B26B7l ; 0x3CD63C57l ; 0x9332938Al ;...
let m3 = [ | 0xD939A9D9l ; 0x90176790l ; 0x719CB371l ; 0xD2A6E8D2l ; 0x05070405l ; 0x9852FD98l ; 0x6580A365l ; 0xDFE476DFl ; 0x08459A08l ; 0x024B9202l ; 0xA0E080A0l ; 0x665A7866l ; 0xDDAFE4DDl ; 0xB06ADDB0l ; 0xBF63D1BFl ; 0x362A3836l ; 0x54E60D54l ; 0x4320C643l ;...
let ord c = int_of_char c
let ord32 c = Int32 . of_int ( ord c )
let unpack_longs s n = let slen = Bytes . length s in if slen / 4 < n then failwith ( " unpack_longs : asked to unpack " ^^ string_of_int n ^^ " longs from \ n string length " ^^ string_of_int slen ) else ( let rec unpack_long i accum = if i == n then List . rev accum else ( let a = ord...
let chr x = char_of_int x
let chr32 x = chr ( Int32 . to_int x )
let pack_long b x = Buffer . add_char b ( chr32 ( and32 ( x >> 0 ) 0xFFl ) ) ; Buffer . add_char b ( chr32 ( and32 ( x >> 8 ) 0xFFl ) ) ; Buffer . add_char b ( chr32 ( and32 ( x >> 16 ) 0xFFl ) ) ; Buffer . add_char b ( chr32 ( and32 ( x >> 24 ) 0xFF...
let pack_longs a = let b = Buffer . create 4 in for i = 0 to Array . length a - 1 do pack_long b a . ( i ) done ; Buffer . to_bytes b
let string_map f s = let string_len = Bytes . length s in let rec apply i = if i = string_len then [ ] else f ( Bytes . get s i ) :: apply ( i + 1 ) in apply 0
let mds_rem a b = let ( << ) x y = Int64 . shift_left x y in let ( >> ) x y = Int64 . shift_right_logical x y in let ( ^ ) x y = Int64 . logxor x y in let ( & ) x y = Int64 . logand x y in let ( -|- ) x y = Int64 . logor x y in let ff x = x & 0xFFL in let ffi x = Int64 . t...
let init key = let keylength = Bytes . length key in if keylength != 32 then failwith ( " init : key length must be 32 , got key length " ^^ string_of_int keylength ) else ( let le_longs = unpack_longs key 8 in let sf , se , sd , sc = mds_rem le_longs . ( 0 ) le_longs . ( 1 ) ...
let encrypt ctx text = let words = unpack_longs text 4 in let k = ctx . k in let r0 = xor32 k . ( 0 ) words . ( 0 ) in let r1 = xor32 k . ( 1 ) words . ( 1 ) in let r2 = xor32 k . ( 2 ) words . ( 2 ) in let r3 = xor32 k . ( 3 ) words . ( 3 ) in let s = ...
let decrypt ctx text = let words = unpack_longs text 4 in let k = ctx . k in let r0 = xor32 k . ( 4 ) words . ( 0 ) in let r1 = xor32 k . ( 5 ) words . ( 1 ) in let r2 = xor32 k . ( 6 ) words . ( 2 ) in let r3 = xor32 k . ( 7 ) words . ( 3 ) in let s = ...
let sigm a = 1 . 0 . / ( 1 . 0 . + exp ( . ~- a ) )
let sigmv v = Vec . map sigm v
let sigmdv v = let ones = Vec . make1 ( Vec . dim v ) in Vec . mul v ( Vec . sub ones v )
let exec w1 w2 b1 b2 x = let y = sigmv ( gemv ~ trans : normal w1 x ~ beta : 1 . 0 ~ y ( : Vec . copy b1 ) ) in let z = sigmv ( gemv ~ trans : normal w2 y ~ beta : 1 . 0 ~ y ( : Vec . copy b2 ) ) in z
let check_gradient delta1 w2 b2 w1 b1 x t = let epsilon = 1e - 4 in let check_4digits dE1 dE2 = let abs_dE1 = abs_float dE1 in if abs_dE1 < 1e - 9 then abs_float dE2 < 1e - 9 else begin let diff = ( dE1 . - dE2 ) . * ( 0 . 1 ** ( floor ( log10 abs_dE1 ) . + 1 . 0 ) ) in...
let train eta w1 w2 b1 b2 x t = let y = sigmv ( gemv ~ trans : normal w1 x ~ beta : 1 . 0 ~ y ( : Vec . copy b1 ) ) in let z = sigmv ( gemv ~ trans : normal w2 y ~ beta : 1 . 0 ~ y ( : Vec . copy b2 ) ) in let delta2 = Vec . mul ( Vec . sub z t ) ( sigmdv z ) in l...
let main ( ) = Random . self_init ( ) ; let input_dim = two in let hidden_dim = five in let output_dim = one in let samples = [ | ( Vec . of_array_dyn input_dim [ | 1 . 0 ; 1 . 0 ] , | Vec . make output_dim 0 . 0 ) ; ( Vec . of_array_dyn input_dim [ | 1 . 0 ...
let ( ) = main ( )
let amount_check ( ? max_money = 2100000000000000L ) am = am >= Int64 . zero && am <= max_money ; ;
module In = struct } ; ; ; ; ; ; in ; ; in } ) ) ; ; ; ; end
module Out = struct } ; ; ; ; in ; ; ; ; ; ; end
module Witness = struct } in ; ; end
type t = { } ; ;
let serialize_legacy ( ? hex = false ) tx = ; ;
let serialize ( ? hex = false ) tx = match tx . witness with ; ;
let parse_legacy ( ? coinbase = false ) ( ? hex = false ) data = } ) ) ; ;
let parse ( ? coinbase = false ) ( ? hex = false ) data = match coinbase with } ) ; } ) ) ; ;
let rec serialize_all txs = match txs with ; ;
let rec serialize_all_legacy txs = match txs with ; ;
let parse_all data ntx = in ; ;
let parse_all_legacy data ntx = in ; ;
let is_witness tx = match tx . witness with ; ;
let is_coinbase tx = else ; ;
module Client = Graphql_lib . Client . Make ( struct let preprocess_variables_string = Fn . id let headers = String . Map . empty end ) end
let ingress_uri ~ graphql_target_node = let host = graphql_target_node in let path = " / graphql " in Uri . make ~ scheme " : http " ~ host ~ path ~ port : 3085 ( )
let exec_graphql_request ( ? num_tries = 10 ) 10 ( ? retry_delay_sec = 30 . 0 ) 0 ( ? initial_delay_sec = 30 . 0 ) 0 ~ graphql_target_node query_obj = let open Deferred . Let_syntax in let uri = ingress_uri ~ graphql_target_node in let rec retry n = if n <= 0 then Deferred . Or_err...
module Send_payment = [ % graphql { | $ receiver : PublicKey , ! $ amount : UInt64 , ! $ token : UInt64 , $ fee : UInt64 , ! $ nonce : UInt32 , $ memo : String , $ field : String , $ scalar : String ) String { sendPayment ( sendPaymentinput : { from : $ sender , to : $ r...
module Get_account_data = [ % graphql { | account ( accountpublicKey : $ public_key ) public_key { nonce balance { total liquid locked } } } } ] |
let get_account_data ~ public_key ~ graphql_target_node = let open Deferred . Or_error . Let_syntax in let pk = public_key |> Public_key . compress in let get_acct_data_obj = Get_account_data . make ~ public_key ( : Graphql_lib . Encoders . public_key pk ) pk ( ) in let % bind balance_obj = exe...
let send_signed_transaction ~ sender_priv_key ~ nonce ~ receiver_pub_key ~ amount ~ fee ~ graphql_target_node = let open Deferred . Or_error . Let_syntax in let sender_pub_key = Public_key . of_private_key_exn sender_priv_key |> Public_key . compress in let receiver_pk = receiver_pub_key |> Public_key . c...
type state = { fees_per_byte : int }
type inbox = { cumulated_size : int ; contents : string list }
let get_state ? hooks tx_rollup client = let * json = RPC . Tx_rollup . get_state ? hooks ~ tx_rollup client in let fees_per_byte = JSON . ( json |-> " fees_per_byte " |> as_int ) in return { fees_per_byte }
let get_inbox ? hooks tx_rollup client = let * json = RPC . Tx_rollup . get_inbox ? hooks ~ tx_rollup client in let cumulated_size = JSON . ( json |-> " cumulated_size " |> as_int ) in let contents = JSON . ( json |-> " contents " |> as_list |> List . map as_string ) in return { ...
let parameter_file protocol = Protocol . write_parameter_file ~ base ( : Either . right ( protocol , None ) ) [ ( [ " tx_rollup_enable " ] , Some " true " ) ]
let test_submit_batch ~ protocols = let open Tezt_tezos in Protocol . register_regression_test ~ __FILE__ ~ output_file " : tx_rollup_simple_use_case " ~ title " : Simple use case " ~ tags [ " : tx_rollup " ] ~ protocols @@ fun protocol -> let * parameter_file = parameter_file protocol ...
let test_invalid_rollup_address ~ protocols = let open Tezt_tezos in Protocol . register_test ~ __FILE__ ~ title " : Submit to an invalid rollup address should fail " ~ tags [ " : tx_rollup " ; " cli " ] ~ protocols @@ fun protocol -> let * parameter_file = parameter_file protocol in le...
let test_submit_from_originated_source ~ protocols = let open Tezt_tezos in Protocol . register_test ~ __FILE__ ~ title " : Submit from an originated contract should fail " ~ tags [ " : tx_rollup " ; " cli " ] ~ protocols @@ fun protocol -> let * parameter_file = parameter_file protocol...
let register ~ protocols = test_submit_batch ~ protocols ; test_invalid_rollup_address ~ protocols ; test_submit_from_originated_source ~ protocols
type t = { contents : Tx_rollup_message_repr . hash list ; cumulated_size : int }
let pp fmt { contents ; cumulated_size } = Format . fprintf fmt " tx rollup inbox : % d messages using % d bytes " ( List . length contents ) cumulated_size
let encoding = let open Data_encoding in conv ( fun { contents ; cumulated_size } -> ( contents , cumulated_size ) ) ( fun ( contents , cumulated_size ) -> { contents ; cumulated_size } ) ( obj2 ( req " contents " @@ list Tx_rollup_message_repr . hash_encoding ) ( req "...
type metadata = { cumulated_size : int ; predecessor : Raw_level_repr . t option ; successor : Raw_level_repr . t option ; }
let metadata_encoding = let open Data_encoding in conv ( fun { cumulated_size ; predecessor ; successor } -> ( cumulated_size , predecessor , successor ) ) ( fun ( cumulated_size , predecessor , successor ) -> { cumulated_size ; predecessor ; successor } ) ( obj3 ( req " ...
type error += | Tx_rollup_inbox_does_not_exist of Tx_rollup_repr . t * Raw_level_repr . t | Tx_rollup_inbox_size_would_exceed_limit of Tx_rollup_repr . t | Tx_rollup_message_size_exceeds_limit
let prepare_metadata : Raw_context . t -> Tx_rollup_repr . t -> Tx_rollup_state_repr . t -> Raw_level_repr . t -> ( Raw_context . t * Tx_rollup_state_repr . t * Tx_rollup_inbox_repr . metadata ) tzresult Lwt . t = fun ctxt rollup state level -> Storage . Tx_rollup . Inbox_metadata . f...
let append_message : Raw_context . t -> Tx_rollup_repr . t -> Tx_rollup_state_repr . t -> Tx_rollup_message_repr . t -> ( Raw_context . t * Tx_rollup_state_repr . t ) tzresult Lwt . t = fun ctxt rollup state message -> let level = ( Raw_context . current_level ctxt ) . level in let me...
let get_level : Raw_context . t -> [ ` Current | ` Level of Raw_level_repr . t ] -> Raw_level_repr . t = fun ctxt -> function | ` Current -> ( Raw_context . current_level ctxt ) . level | ` Level lvl -> lvl
let messages_opt : Raw_context . t -> level [ ` : Current | ` Level of Raw_level_repr . t ] -> Tx_rollup_repr . t -> ( Raw_context . t * Tx_rollup_message_repr . hash list option ) tzresult Lwt . t = fun ctxt ~ level tx_rollup -> let level = get_level ctxt level in Storage . Tx_roll...
let messages : Raw_context . t -> level [ ` : Current | ` Level of Raw_level_repr . t ] -> Tx_rollup_repr . t -> ( Raw_context . t * Tx_rollup_message_repr . hash list ) tzresult Lwt . t = fun ctxt ~ level tx_rollup -> messages_opt ctxt ~ level tx_rollup >>=? function | ( ctxt , ...
let size : Raw_context . t -> level [ ` : Current | ` Level of Raw_level_repr . t ] -> Tx_rollup_repr . t -> ( Raw_context . t * int ) tzresult Lwt . t = fun ctxt ~ level tx_rollup -> let level = get_level ctxt level in Storage . Tx_rollup . Inbox_metadata . find ( ctxt , leve...
let find : Raw_context . t -> level [ ` : Current | ` Level of Raw_level_repr . t ] -> Tx_rollup_repr . t -> ( Raw_context . t * Tx_rollup_inbox_repr . t option ) tzresult Lwt . t = fun ctxt ~ level tx_rollup -> let open Tx_rollup_inbox_repr in messages_opt ctxt ~ level tx_rollup >>=...
let get : Raw_context . t -> level [ ` : Current | ` Level of Raw_level_repr . t ] -> Tx_rollup_repr . t -> ( Raw_context . t * Tx_rollup_inbox_repr . t ) tzresult Lwt . t = fun ctxt ~ level tx_rollup -> find ctxt ~ level tx_rollup >>=? function | ( ctxt , Some res ) -> retur...
let get_adjacent_levels : Raw_context . t -> Raw_level_repr . t -> Tx_rollup_repr . t -> ( Raw_context . t * Raw_level_repr . t option * Raw_level_repr . t option ) tzresult Lwt . t = fun ctxt level tx_rollup -> Storage . Tx_rollup . Inbox_metadata . find ( ctxt , level ) tx_rollup...
let ( ) = let open Data_encoding in register_error_kind ` Permanent ~ id " : tx_rollup_inbox_does_not_exist " ~ title " : Missing transaction rollup inbox " ~ description " : The transaction rollup does not have an inbox at this level " ~ pp ( : fun ppf ( addr , level ) -> Format . ...
let address_size = 20 include Blake2B . Make ( Base58 ) ( struct let name = " Tx_rollup_l2_address " let title = " The hash of a BLS public key used to identify a L2 ticket holders " let b58check_prefix = " \ 001 \ 127 \ 181 \ 224 " let size = Some address_size end )
let ( ) = Base58 . check_encoded_prefix b58check_encoding " tru2 " 37
let of_bls_pk : Bls_signature . pk -> t = fun pk -> hash_bytes [ Bls_signature . pk_to_bytes pk ]
let in_memory_size : t -> Cache_memory_helpers . sint = fun _ -> let open Cache_memory_helpers in header_size +! word_size +! string_size_gen address_size
let size _ = address_size
module Indexable = struct include Indexable . Make ( struct type nonrec t = t let encoding = encoding let compare = compare let pp = pp end ) let in_memory_size = Indexable . in_memory_size in_memory_size let size = Indexable . size size end
type deposit = { destination : Tx_rollup_l2_address . Indexable . t ; ticket_hash : Ticket_hash_repr . t ; amount : int64 ; }
let deposit_encoding = let open Data_encoding in conv ( fun { destination ; ticket_hash ; amount } -> ( destination , ticket_hash , amount ) ) ( fun ( destination , ticket_hash , amount ) -> { destination ; ticket_hash ; amount } ) @@ obj3 ( req " destination " Tx_rollu...
type t = Batch of string | Deposit of deposit
let encoding = let open Data_encoding in union ~ tag_size ` : Uint8 [ case ( Tag 0 ) ~ title " : Batch " ( obj1 ( req " batch " string ) ) ( function Batch batch -> Some batch | _ -> None ) ( fun batch -> Batch batch ) ; case ( Tag 1 ) ~ title " : Deposit " ( ob...
let pp fmt = let open Format in function | Batch str -> let subsize = 10 in let ( str , ellipsis ) = if Compare . Int . ( subsize < String . length str ) then let substring = String . sub str 0 subsize in ( substring , " . . . " ) else ( str , " " ) in fprintf fmt " ...
let size = function | Batch batch -> String . length batch | Deposit { destination = d ; ticket_hash = _ ; amount = _ } -> let destination_size = Tx_rollup_l2_address . Indexable . size d in let key_hash_size = 32 in let amount_size = 8 in destination_size + key_hash_size + amount_size
module Message_hash = Blake2B . Make ( Base58 ) ( struct let name = " Tx_rollup_inbox_message_hash " let title = " The hash of a transaction rollup inbox ’ s message " let b58check_prefix = " \ 002 \ 085 " let size = Some hash_size end )
let ( ) = Base58 . check_encoded_prefix Message_hash . b58check_encoding " M " 51
let hash msg = Message_hash . hash_bytes [ Data_encoding . Binary . to_bytes_exn encoding msg ]
type error += Invalid_rollup_notation of string
let ( ) = let open Data_encoding in register_error_kind ` Permanent ~ id " : rollup . invalid_tx_rollup_notation " ~ title " : Invalid tx rollup notation " ~ pp ( : fun ppf x -> Format . fprintf ppf " Invalid tx rollup notation % S " x ) ~ description : " A malformed tx rollup not...
module Hash = struct let rollup_hash = " \ 001 \ 127 \ 181 \ 221 " module H = Blake2B . Make ( Base58 ) ( struct let name = " Rollup_hash " let title = " A rollup ID " let b58check_prefix = rollup_hash let size = Some 20 end ) include H let ( ) = Base58 . check_encoded_prefi...
type tx_rollup = t type nonrec t = t let compare r1 r2 = Hash . compare r1 r2 end )
let to_b58check rollup = Hash . to_b58check rollup
let of_b58check_opt s = match Base58 . decode s with Some ( Hash . Data hash ) -> Some hash | _ -> None
let of_b58check s = match of_b58check_opt s with | Some hash -> ok hash | _ -> error ( Invalid_rollup_notation s )
let pp ppf hash = Hash . pp ppf hash