text
stringlengths
0
601k
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 " cumulated_size " int31 ) )
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 " cumulated_size " int31 ) ( req " predecessor " (...
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 . find ( ctxt , level ) rollup >>=? fu...
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 message_size = Tx_rollup_message_repr...
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_rollup . Inbox_rev_contents . find ( ctxt...
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 , Some messages ) -> return ( ctxt , messa...
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 , level ) tx_rollup >>=? function | ( ctxt , Some...
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 >>=? function | ( ctxt , Some contents ...
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 ) -> return ( ctxt , res ) | ( _ , None ) -> fail ( Tx...
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 >>=? function | ( ctxt , Some { prede...
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 . fprintf ppf " Transaction rollup % a ...
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_rollup_l2_address . Indexable . encoding ) ( req " tick...
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 " ( obj1 ( req " deposit " deposit_encoding ) ) ( function Depos...
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 " [ @< hov 2 > Batch :@ % s % s ] " @ ( Hex . of_string...
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 notation was given to an RPC or in a scrip...
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_prefix b58check_encoding " tru1 " 37 include Path_...
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
let encoding = let open Data_encoding in def " tx_rollup_id " ~ title " : A tx rollup handle " ~ description : " A tx rollup notation as given to an RPC or inside scripts , is a base58 \ tx rollup hash " @@ splitted ~ binary : Hash . encoding ~ json : ( conv to_b58check ( fun s -> match of_b58check s with | Ok s -> s |...
let originated_tx_rollup nonce = let data = Data_encoding . Binary . to_bytes_exn Origination_nonce . encoding nonce in Hash . hash_bytes [ data ]
let rpc_arg = let construct = to_b58check in let destruct hash = Result . map_error ( fun _ -> " Cannot parse tx rollup id " ) ( of_b58check hash ) in RPC_arg . make ~ descr " : A tx rollup identifier encoded in b58check . " ~ name " : tx_rollup_id " ~ construct ~ destruct ( )
module Index = struct type t = tx_rollup let path_length = 1 let to_path c l = let raw_key = Data_encoding . Binary . to_bytes_exn encoding c in let ( ` Hex key ) = Hex . of_bytes raw_key in key :: l let of_path = function | [ key ] -> Option . bind ( Hex . to_bytes ( ` Hex key ) ) ( Data_encoding . Binary . of_bytes_o...
let custom_root = ( RPC_path . ( open_root / " context " / " tx_rollup " ) : RPC_context . t RPC_path . context )
module S = struct let state = RPC_service . get_service ~ description " : Access the state of a rollup . " ~ query : RPC_query . empty ~ output : Tx_rollup_state . encoding RPC_path . ( custom_root /: Tx_rollup . rpc_arg / " state " ) let inbox = RPC_service . get_service ~ description " : Get the inbox of a transactio...
let register ( ) = let open Services_registration in opt_register1 ~ chunked : false S . state ( fun ctxt tx_rollup ( ) ( ) -> Tx_rollup_state . find ctxt tx_rollup >|=? snd ) ; opt_register1 ~ chunked : false S . inbox ( fun ctxt tx_rollup ( ) ( ) -> Tx_rollup_inbox . find ctxt tx_rollup ~ level ` : Current >|=? snd )
let state ctxt block tx_rollup = RPC_context . make_call1 S . state ctxt block tx_rollup ( ) ( )
let inbox ctxt block tx_rollup = RPC_context . make_call1 S . inbox ctxt block tx_rollup ( ) ( )
type t = { fees_per_byte : Tez_repr . t ; inbox_ema : int ; last_inbox_level : Raw_level_repr . t option ; }
let initial_state = { fees_per_byte = Tez_repr . zero ; inbox_ema = 0 ; last_inbox_level = None }
let encoding : t Data_encoding . t = let open Data_encoding in conv ( fun { last_inbox_level ; fees_per_byte ; inbox_ema } -> ( last_inbox_level , fees_per_byte , inbox_ema ) ) ( fun ( last_inbox_level , fees_per_byte , inbox_ema ) -> { last_inbox_level ; fees_per_byte ; inbox_ema } ) ( obj3 ( req " last_inbox_level " ...
let pp fmt { fees_per_byte ; last_inbox_level ; inbox_ema } = Format . fprintf fmt " Tx_rollup : fees_per_byte = % a ; inbox_ema % d ; last_inbox_level = % a " Tez_repr . pp fees_per_byte inbox_ema ( Format . pp_print_option Raw_level_repr . pp ) last_inbox_level
let update_fees_per_byte : t -> final_size : int -> hard_limit : int -> t = fun ( { fees_per_byte ; inbox_ema ; _ } as state ) ~ final_size ~ hard_limit -> let threshold_increase = 90 in let threshold_decrease = 80 in let variation_factor = 5L in let inbox_ema_multiplier = 165 in let inbox_ema = ( ( final_size * inbox_...
let fees { fees_per_byte ; _ } size = Tez_repr . ( fees_per_byte *? Int64 . of_int size )
let last_inbox_level { last_inbox_level ; _ } = last_inbox_level
let append_inbox t level = { t with last_inbox_level = Some level }
module Internal_for_tests = struct let make : fees_per_byte : Tez_repr . t -> inbox_ema : int -> last_inbox_level : Raw_level_repr . t option -> t = fun ~ fees_per_byte ~ inbox_ema ~ last_inbox_level -> { fees_per_byte ; inbox_ema ; last_inbox_level } let get_inbox_ema : t -> int = fun { inbox_ema ; _ } -> inbox_ema en...
type error += | Tx_rollup_already_exists of Tx_rollup_repr . t | Tx_rollup_does_not_exist of Tx_rollup_repr . t
let init : Raw_context . t -> Tx_rollup_repr . t -> Raw_context . t tzresult Lwt . t = fun ctxt tx_rollup -> Storage . Tx_rollup . State . mem ctxt tx_rollup >>=? fun ( ctxt , already_exists ) -> fail_when already_exists ( Tx_rollup_already_exists tx_rollup ) >>=? fun ( ) -> Storage . Tx_rollup . State . init ctxt tx_r...
let find : Raw_context . t -> Tx_rollup_repr . t -> ( Raw_context . t * Tx_rollup_state_repr . t option ) tzresult Lwt . t = Storage . Tx_rollup . State . find
let get : Raw_context . t -> Tx_rollup_repr . t -> ( Raw_context . t * Tx_rollup_state_repr . t ) tzresult Lwt . t = fun ctxt tx_rollup -> find ctxt tx_rollup >>=? fun ( ctxt , state ) -> match state with | Some state -> return ( ctxt , state ) | None -> fail ( Tx_rollup_does_not_exist tx_rollup )
let assert_exist : Raw_context . t -> Tx_rollup_repr . t -> Raw_context . t tzresult Lwt . t = fun ctxt tx_rollup -> Storage . Tx_rollup . State . mem ctxt tx_rollup >>=? fun ( ctxt , tx_rollup_exists ) -> fail_unless tx_rollup_exists ( Tx_rollup_does_not_exist tx_rollup ) >>=? fun ( ) -> return ctxt
let update : Raw_context . t -> Tx_rollup_repr . t -> Tx_rollup_state_repr . t -> Raw_context . t tzresult Lwt . t = fun ctxt tx_rollup t -> Storage . Tx_rollup . State . update ctxt tx_rollup t >>=? fun ( ctxt , _ ) -> return ctxt
let ( ) = let open Data_encoding in register_error_kind ` Permanent ~ id " : tx_rollup_already_exists " ~ title " : Transaction rollup was already created " ~ description : " The protocol tried to originate the same transaction rollup twice " ~ pp ( : fun ppf addr -> Format . fprintf ppf " Transaction rollup % a is alr...
let fresh_tx_rollup_from_current_nonce ctxt = Raw_context . increment_origination_nonce ctxt >|? fun ( ctxt , nonce ) -> ( ctxt , Tx_rollup_repr . originated_tx_rollup nonce )
let originate ctxt = fresh_tx_rollup_from_current_nonce ctxt >>?= fun ( ctxt , tx_rollup ) -> Tx_rollup_state_storage . init ctxt tx_rollup >|=? fun ctxt -> ( ctxt , tx_rollup )
let update_tx_rollups_at_block_finalization : Raw_context . t -> Raw_context . t tzresult Lwt . t = fun ctxt -> let level = ( Raw_context . current_level ctxt ) . level in Storage . Tx_rollup . fold ctxt level ~ init ( : ok ctxt ) ~ f ( : fun tx_rollup ctxt -> ctxt >>?= fun ctxt -> Tx_rollup_state_storage . get ctxt tx...
let script_parse_test sc scdec octx = ; ;
let script_serialize_test sc scdec octx = ; ;
let script_verify_is_spendable_test sc octx = ; ;
let script_verify_spendable_by_test prefix sc adr octx = ; ;
let tx_parse_test raw octx = ; ;
let tx_parse_and_check_hash raw hash octx = ; ;
let tx_parse_segwit_test raw dest sizes vsize hashes ? prefix ( : prefix ( = Params . of_network XTN ) . prefixes ) octx = ; ;
let tlist = [ ( [ Script . OP_DUP ; Script . OP_HASH160 ; Script . OP_DATA ( 20 , Hex . to_string ( ` Hex " 89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA " ) ) ; Script . OP_EQUALVERIFY ; Script . OP_CHECKSIG ] , 25 ) ; ( [ Script . OP_DUP ; Script . OP_HASH160 ; Script . OP_DATA ( 20 , Hex . to_string ( ` Hex " 89ABCDEFABB...
type ' a ty = Ty of repr
let obj ( Ty ty ) = ty
let repr ty = Ty ( ty )
let print ( Ty ty ) = Format . asprintf " % a " %! Pprintast . core_type ty
let domains = function | Ty { Parsetree . ptyp_desc = Parsetree . Ptyp_arrow ( _ , arg , ret ) ; _ } -> ( Ty arg , Ty ret ) | _ -> invalid_arg " Ty . domains "
let curry ( Ty arg ) ( Ty ret ) = Ty { Parsetree . ptyp_desc = Parsetree . Ptyp_arrow ( Asttypes . Nolabel , arg , ret ) ; ptyp_loc = Location . none ; ptyp_loc_stack = [ ] ; ptyp_attributes = [ ] }
let pair2 ( Ty t1 ) ( Ty t2 ) = Ty { Parsetree . ptyp_desc = Parsetree . Ptyp_tuple [ t1 ; t2 ] ; ptyp_loc = Location . none ; ptyp_loc_stack = [ ] ; ptyp_attributes = [ ] }
let pair3 ( Ty t1 ) ( Ty t2 ) ( Ty t3 ) = Ty { Parsetree . ptyp_desc = Parsetree . Ptyp_tuple [ t1 ; t2 ; t3 ] ; ptyp_loc = Location . none ; ptyp_loc_stack = [ ] ; ptyp_attributes = [ ] }
let pair4 ( Ty t1 ) ( Ty t2 ) ( Ty t3 ) ( Ty t4 ) = Ty { Parsetree . ptyp_desc = Parsetree . Ptyp_tuple [ t1 ; t2 ; t3 ; t4 ] ; ptyp_loc = Location . none ; ptyp_loc_stack = [ ] ; ptyp_attributes = [ ] }
let lst ( Ty ty ) = Ty { Parsetree . ptyp_desc = Parsetree . Ptyp_constr ( { Asttypes . txt = Longident . Lident " list " ; loc = Location . none } , [ ty ] ) ; ptyp_loc = Location . none ; ptyp_loc_stack = [ ] ; ptyp_attributes = [ ] }
module Impl = Snarky . Snark . Make ( Snarky . Backends . Mnt4 . Default )
type nonrec t = { a : bool ; b : field_var }
type nonrec ' a u = { a1 : ' a ; b1 : bool } type nonrec ( ' a , ' b ) v_var = { a2 : ' a ; b2 : ' b } and ( ' a , ' b ) v = { a2 : ' a ; b2 : ' b } let v_typ x___3 x___2 = { Snarky . Types . Typ . store = ( fun { a2 ; b2 } -> Snarky . Typ_monads . Store . bind ( x___3 . Snarky . Types . Typ . store a2 ) ~ f ( : fun a2...
let x __implicit3__ __implicit1__ x = let typ x___6 = v_typ x___6 x___6 in Snarky . exists ( typ __implicit3__ ) ~ compute : ( let open As_prover in fun ( ) -> { a2 = ( let typ x___4 = x___4 in As_prover . read ( typ __implicit1__ ) x ) ; b2 = ( let typ x___5 = x___5 in As_prover . read ( typ __implicit1__ ) x ) } )
let y ( ) = x Typ . boolean { Snarky . Types . Typ . store = ( fun x -> Snarky . Typ_monads . Store . return x ) ; Snarky . Types . Typ . read = ( fun x -> Snarky . Typ_monads . Read . return x ) ; Snarky . Types . Typ . alloc = ( let open Snarky . Typ_monads . Alloc in map alloc ~ f ( : fun _ -> failwith " cannot allo...
type id = string list [ @@ deriving show , eq , ord ]
type vtype = | TUnbound of string * int option * Loc . t option | TId of id * Loc . t option | TComposed of id * t list * Loc . t option | TArrow of t * t * Loc . t option | TLink of t | TExpAlt of t list | TInt of int * Loc . t option
let rec unlink t = match t with | { contents = TLink e } -> unlink e | { contents = TComposed ( id , elems , _ ) } -> { contents = TComposed ( id , List . map unlink elems , None ) } | { contents = TArrow ( t1 , t2 , _ ) } -> { contents = TArrow ( unlink t1 , unlink t2 , None ) } | { contents = TExpAlt elems } -> { con...
let compare a b = compare ( unlink a ) ( unlink b )
let gensym_counter = ref 0
let gensym : unit -> string = fun ( ) -> let n = ! gensym_counter in let ( ) = incr gensym_counter in " ' " ^ string_of_int n
let current_level_val = ref 1
let current_level ( ) = ! current_level_val
let rec makeArrowType ( last : t ) ( types : t list ) : t = match types with | [ ] -> last | h :: t -> ref ( TArrow ( h , makeArrowType last t , None ) )
let rec stripArrow ( typ : t ) : t list * t = match typ with | { contents = TArrow ( t1 , t2 , _ ) } -> let args , last = stripArrow t2 in t1 :: args , last | _ -> [ ] , typ
let newvar : unit -> t = fun ( ) -> ref ( TUnbound ( gensym ( ) , Some ( current_level ( ) ) , None ) )
let base ( t : t ) : id = match ! t with | TId ( id , _ ) -> id | TComposed ( id , _ , _ ) -> id | _ -> failwith " Typ . base : this type does not have a base type "