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 " ( option Raw_level_repr . encoding ) ) ( req " successor " ( option Raw_level_repr . encoding ) ) ) |
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 >>=? fun ( ctxt , metadata ) -> match metadata with | Some metadata -> return ( ctxt , state , metadata ) | None -> let predecessor = Tx_rollup_state_repr . last_inbox_level state in let new_state = Tx_rollup_state_repr . append_inbox state level in ( match predecessor with | None -> return ctxt | Some predecessor_level -> Storage . Tx_rollup . Inbox_metadata . get ( ctxt , predecessor_level ) rollup >>=? fun ( ctxt , predecessor_metadata ) -> Storage . Tx_rollup . Inbox_metadata . add ( ctxt , predecessor_level ) rollup { predecessor_metadata with successor = Some level } >|=? fun ( ctxt , _ , _ ) -> ctxt ) >>=? fun ctxt -> let new_metadata : Tx_rollup_inbox_repr . metadata = { cumulated_size = 0 ; predecessor ; successor = None } in return ( ctxt , new_state , new_metadata ) |
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 . size message in prepare_metadata ctxt rollup state level >>=? fun ( ctxt , new_state , new_metadata ) -> let new_metadata = { new_metadata with cumulated_size = message_size + new_metadata . cumulated_size ; } in Storage . Tx_rollup . Inbox_metadata . add ( ctxt , level ) rollup new_metadata >>=? fun ( ctxt , _ , _ ) -> let new_size = new_metadata . cumulated_size in let inbox_limit = Constants_storage . tx_rollup_hard_size_limit_per_inbox ctxt in fail_unless Compare . Int . ( new_size < inbox_limit ) ( Tx_rollup_inbox_size_would_exceed_limit rollup ) >>=? fun ( ) -> Storage . Tx_rollup . Inbox_rev_contents . find ( ctxt , level ) rollup >>=? fun ( ctxt , mcontents ) -> Storage . Tx_rollup . Inbox_rev_contents . add ( ctxt , level ) rollup ( Tx_rollup_message_repr . hash message :: Option . value ~ default [ ] : mcontents ) >>=? fun ( ctxt , _ , _ ) -> return ( ctxt , new_state ) |
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 , level ) tx_rollup >>=? function | ( ctxt , Some rev_contents ) -> return ( ctxt , Some ( List . rev rev_contents ) ) | ( ctxt , None ) -> Tx_rollup_state_storage . assert_exist ctxt tx_rollup >>=? fun ctxt -> return ( ctxt , None ) |
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 , messages ) | ( _ , None ) -> fail ( Tx_rollup_inbox_does_not_exist ( tx_rollup , get_level ctxt level ) ) |
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 { cumulated_size ; _ } ) -> return ( ctxt , cumulated_size ) | ( ctxt , None ) -> Tx_rollup_state_storage . assert_exist ctxt tx_rollup >>=? fun _ctxt -> fail ( Tx_rollup_inbox_does_not_exist ( tx_rollup , level ) ) |
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 ) -> size ctxt ~ level tx_rollup >>=? fun ( ctxt , cumulated_size ) -> return ( ctxt , Some { cumulated_size ; contents } ) | ( ctxt , None ) -> return ( ctxt , None ) |
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_rollup_inbox_does_not_exist ( tx_rollup , get_level ctxt level ) ) |
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 { predecessor ; successor ; _ } ) -> return ( ctxt , predecessor , successor ) | ( _ , None ) -> fail @@ Tx_rollup_inbox_does_not_exist ( tx_rollup , level ) |
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 does not have an inbox at level % a " Tx_rollup_repr . pp addr Raw_level_repr . pp level ) ( obj2 ( req " tx_rollup_address " Tx_rollup_repr . encoding ) ( req " raw_level " Raw_level_repr . encoding ) ) ( function | Tx_rollup_inbox_does_not_exist ( rollup , level ) -> Some ( rollup , level ) | _ -> None ) ( fun ( rollup , level ) -> Tx_rollup_inbox_does_not_exist ( rollup , level ) ) ; register_error_kind ` Permanent ~ id " : tx_rollup_inbox_size_would_exceed_limit " ~ title " : Transaction rollup inbox β s size would exceed the limit " ~ description " : Transaction rollup inbox β s size would exceed the limit " ~ pp ( : fun ppf addr -> Format . fprintf ppf " Adding the submitted message would make the inbox of % a exceed the \ authorized limit at this level " Tx_rollup_repr . pp addr ) ( obj1 ( req " tx_rollup_address " Tx_rollup_repr . encoding ) ) ( function | Tx_rollup_inbox_size_would_exceed_limit rollup -> Some rollup | _ -> None ) ( fun rollup -> Tx_rollup_inbox_size_would_exceed_limit rollup ) ; register_error_kind ` Permanent ~ id " : tx_rollup_message_size_exceeds_limit " ~ title " : A message submtitted to a transaction rollup inbox exceeds limit " ~ description : " A message submtitted to a transaction rollup inbox exceeds limit " empty ( function Tx_rollup_message_size_exceeds_limit -> Some ( ) | _ -> None ) ( fun ( ) -> Tx_rollup_message_size_exceeds_limit ) |
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 " ticket_hash " Ticket_hash_repr . encoding ) ( req " amount " int64 ) |
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 Deposit deposit -> Some deposit | _ -> None ) ( fun deposit -> Deposit deposit ) ; ] |
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 str |> Hex . show ) ellipsis | Deposit { destination ; ticket_hash ; amount } -> fprintf fmt " [ @< hov 2 > Deposit :@ destination =% a , @ ticket_hash =% a , @ amount :% Ld ] " @ Tx_rollup_l2_address . Indexable . pp destination Ticket_hash_repr . pp ticket_hash amount |
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 script . " ( obj1 ( req " notation " string ) ) ( function Invalid_rollup_notation loc -> Some loc | _ -> None ) ( fun loc -> Invalid_rollup_notation loc ) |
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_encoding . Make_hex ( H ) end |
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 | Error _ -> Json . cannot_destruct " Invalid tx rollup notation . " ) string ) |
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_opt encoding ) | _ -> None let rpc_arg = rpc_arg let encoding = encoding let compare = compare end |
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 transaction rollup " ~ query : RPC_query . empty ~ output : Tx_rollup_inbox . encoding RPC_path . ( custom_root /: Tx_rollup . rpc_arg / " inbox " ) end |
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 " ( option Raw_level_repr . encoding ) ) ( req " fees_per_byte " Tez_repr . encoding ) ( req " inbox_ema " int31 ) ) |
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_ema_multiplier ) + ( inbox_ema * ( 10000 - inbox_ema_multiplier ) ) ) / 10000 in let percentage = inbox_ema * 100 / hard_limit in let computation = let open Compare . Int in if threshold_decrease < percentage && percentage <= threshold_increase then ok fees_per_byte else Tez_repr . ( fees_per_byte *? variation_factor >>? fun x -> x /? 100L ) >>? fun variation -> let variation = if Tez_repr . ( variation = zero ) then Tez_repr . one_mutez else variation in if threshold_increase < percentage then Tez_repr . ( fees_per_byte +? variation ) else if percentage < threshold_decrease && Tez_repr . ( zero < fees_per_byte ) then Tez_repr . ( fees_per_byte -? variation ) else ok fees_per_byte in match computation with | Ok fees_per_byte -> { state with fees_per_byte ; inbox_ema } | Error _ -> { state with fees_per_byte = Tez_repr . max_mutez ; inbox_ema } |
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 end |
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_rollup Tx_rollup_state_repr . initial_state >|=? fst |
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 already used for an existing transaction \ rollup . This should not happen , and indicates there is a bug in the \ protocol . If you can , please report this bug \ ( https :// gitlab . com / tezos / tezos /-/ issues . ) " Tx_rollup_repr . pp addr ) ( obj1 ( req " rollup_address " Tx_rollup_repr . encoding ) ) ( function Tx_rollup_already_exists rollup -> Some rollup | _ -> None ) ( fun rollup -> Tx_rollup_already_exists rollup ) ; register_error_kind ` Temporary ~ id " : tx_rollup_does_not_exist " ~ title " : Transaction rollup does not exist " ~ description " : An invalid transaction rollup address was submitted " ~ pp ( : fun ppf addr -> Format . fprintf ppf " Invalid transaction rollup address % a " Tx_rollup_repr . pp addr ) ( obj1 ( req " rollup_address " Tx_rollup_repr . encoding ) ) ( function Tx_rollup_does_not_exist rollup -> Some rollup | _ -> None ) ( fun rollup -> Tx_rollup_does_not_exist rollup ) |
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_rollup >>=? fun ( ctxt , state ) -> Tx_rollup_inbox_storage . get ~ level ( ` : Level level ) ctxt tx_rollup >>=? fun ( ctxt , inbox ) -> let hard_limit = Constants_storage . tx_rollup_hard_size_limit_per_inbox ctxt in let state = Tx_rollup_state_repr . update_fees_per_byte state ~ final_size : inbox . cumulated_size ~ hard_limit in Storage . Tx_rollup . State . add ctxt tx_rollup state >|=? fun ( ctxt , _ , _ ) -> ctxt ) |
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 " 89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA " ) ) ; Script . OP_EQUALVERIFY ; Script . OP_CHECKSIG ] , 25 ) ; ( [ Script . OP_DUP ; Script . OP_HASH160 ; Script . OP_DATA ( 20 , Hex . to_string ( ` Hex " 89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA " ) ) ; Script . OP_EQUALVERIFY ; Script . OP_CHECKSIG ] , 25 ) ; { pubkeyhash = 0x00 ; scripthash = 0x05 ; hrp = " bc " } ( [ Script . OP_DUP ; Script . OP_HASH160 ; Script . OP_DATA ( 20 , Hex . to_string ( ` Hex " 89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA " ) ) ; Script . OP_EQUALVERIFY ; Script . OP_CHECKSIG ] , 25 ) " 1DYwPTpZuLjY2qApmJdHaSAuWRvEF5skCN " ; ( ` Hex " 0100000000010115e180dc28a2327e687facc33f10f2a20da717e5548406f7ae8b4c811072f8560100000000ffffffff0100b4f505000000001976a9141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b92888ac02483045022100df7b7e5cda14ddf91290e02ea10786e03eb11ee36ec02dd862fe9a326bbcb7fd02203f5b4496b667e6e281cc654a2da9e4f08660c620a1051337fa8965f727eb19190121038262a6c6cec93c2d3ecd6c6072efea86d02ff8e3328bbd0242b20af3425990ac00000000 " ) " miCsSagJ7RQDCMcBUaKFKEryaLnxbhGAPt " ( 85 , 110 ) 113 ( " d869f854e1f8788bcff294cc83b280942a8c728de71eb709a2c29d10bfe21b7c " , " 976015741ba2fc60804dd63167326b1a1f7e94af2b66f4a0fd95b38c18ee729b " ) ; ( ` Hex " 0100000000010115e180dc28a2327e687facc33f10f2a20da717e5548406f7ae8b4c811072f8560200000000ffffffff0188b3f505000000001976a9141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b92888ac02483045022100f9d3fe35f5ec8ceb07d3db95adcedac446f3b19a8f3174e7e8f904b1594d5b43022074d995d89a278bd874d45d0aea835d3936140397392698b7b5bbcdef8d08f2fd012321038262a6c6cec93c2d3ecd6c6072efea86d02ff8e3328bbd0242b20af3425990acac00000000 " ) " miCsSagJ7RQDCMcBUaKFKEryaLnxbhGAPt " ( 85 , 112 ) 113 ( " 78457666f82c28aa37b74b506745a7c7684dc7842a52a457b09f09446721e11c " , " 12b1b3fe5e29f136bed2996d39e935442b619feb0a12d30ca832d29246689aa9 " ) ; ( ` Hex " 0100000000010115e180dc28a2327e687facc33f10f2a20da717e5548406f7ae8b4c811072f85603000000171600141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b928ffffffff019caef505000000001976a9141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b92888ac02483045022100f764287d3e99b1474da9bec7f7ed236d6c81e793b20c4b5aa1f3051b9a7daa63022016a198031d5554dbb855bdbe8534776a4be6958bd8d530dc001c32b828f6f0ab0121038262a6c6cec93c2d3ecd6c6072efea86d02ff8e3328bbd0242b20af3425990ac00000000 " ) " miCsSagJ7RQDCMcBUaKFKEryaLnxbhGAPt " ( 108 , 110 ) 136 ( " 8139979112e894a14f8370438a471d23984061ff83a9eba0bc7a34433327ec21 " , " 6bf4e4dfb860cf0906f49c836700b130ac78cc391c72a0911c94cdec4dcb10ec " ) ; ( ` Hex " 0100000000010115e180dc28a2327e687facc33f10f2a20da717e5548406f7ae8b4c811072f856040000002322002001d5d92effa6ffba3efa379f9830d0f75618b13393827152d26e4309000e88b1ffffffff0188b3f505000000001976a9141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b92888ac02473044022038421164c6468c63dc7bf724aa9d48d8e5abe3935564d38182addf733ad4cd81022076362326b22dd7bfaf211d5b17220723659e4fe3359740ced5762d0e497b7dcc012321038262a6c6cec93c2d3ecd6c6072efea86d02ff8e3328bbd0242b20af3425990acac00000000 " ) " miCsSagJ7RQDCMcBUaKFKEryaLnxbhGAPt " ( 120 , 111 ) 148 ( " 954f43dbb30ad8024981c07d1f5eb6c9fd461e2cf1760dd1283f052af746fc88 " , " a5947589e2762107ff650958ba0e3a3cf341f53281d15593530bf9762c4edab1 " ) ; ( ` Hex " 0200000000010140d43a99926d43eb0e619bf0b3d83b4a31f60c176beecfb9d35bf45e54d0f7420100000017160014a4b4ca48de0b3fffc15404a1acdc8dbaae226955ffffffff0100e1f5050000000017a9144a1154d50b03292b3024370901711946cb7cccc387024830450221008604ef8f6d8afa892dee0f31259b6ce02dd70c545cfcfed8148179971876c54a022076d771d6e91bed212783c9b06e0de600fab2d518fad6f15a2b191d7fbd262a3e0121039d25ab79f41f75ceaf882411fd41fa670a4c672c23ffaf0e361a969cde0692e800000000 " ) " 38Segwituno6sUoEkh57ycM6K7ej5gvJhM " ( 106 , 110 ) 134 ( " c586389e5e4b3acb9d6c8be1c19ae8ab2795397633176f5a6442a261bbdefc3a " , " b759d39a8596b70b3a46700b83e1edb247e17ba58df305421864fe7a9ac142ea " ) ~ prefix ( : Params . of_network BTC ) . prefixes ; ] ; ; |
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 -> Snarky . Typ_monads . Store . bind ( x___2 . Snarky . Types . Typ . store b2 ) ~ f ( : fun b2 -> Snarky . Typ_monads . Store . return { a2 ; b2 } ) ) ) ; Snarky . Types . Typ . read = ( fun { a2 ; b2 } -> Snarky . Typ_monads . Read . bind ( x___3 . Snarky . Types . Typ . read a2 ) ~ f ( : fun a2 -> Snarky . Typ_monads . Read . bind ( x___2 . Snarky . Types . Typ . read b2 ) ~ f ( : fun b2 -> Snarky . Typ_monads . Read . return { a2 ; b2 } ) ) ) ; Snarky . Types . Typ . alloc = Snarky . Typ_monads . Alloc . bind x___3 . Snarky . Types . Typ . alloc ~ f ( : fun a2 -> Snarky . Typ_monads . Alloc . bind x___2 . Snarky . Types . Typ . alloc ~ f ( : fun b2 -> Snarky . Typ_monads . Alloc . return { a2 ; b2 } ) ) ; Snarky . Types . Typ . check = ( fun { a2 ; b2 } -> Snarky . Checked . bind ( x___3 . Snarky . Types . Typ . check a2 ) ~ f ( : fun ( ) -> Snarky . Checked . bind ( x___2 . Snarky . Types . Typ . check b2 ) ~ f ( : fun ( ) -> Snarky . Checked . return ( ) ) ) ) } end |
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 allocate this type . " ) ) ; Snarky . Types . Typ . check = ( fun _ -> Snarky . Checked . return ( ) ) } true |
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 } -> { contents = TExpAlt ( List . map unlink elems ) } | { contents = TId ( id , _ ) } -> { contents = TId ( id , None ) } | { contents = TInt ( n , _ ) } -> { contents = TInt ( n , None ) } | { contents = TUnbound ( name , level , _ ) } -> { contents = TUnbound ( name , level , None ) } |
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 " |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.