text
stringlengths
12
786k
let u0 = Sci . cos_1024 Sci . pi_1024 ; ;
let u1 = Sci . exp_1024 Sci . ipi_1024 ; ;
let u2 = Sci . sin_1024 Sci . pi_1024 ; ;
let u0a = Sci . plus_1024 u0 Sci . sci_1 ; ;
let u1a = Sci . plus_1024 u1 Sci . sci_1 ; ;
let u3 = Sci . exp_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let u4 = Sci . log_1024 u3 ; ;
let u5 = Sci . exp_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_128 ] | ; ;
let u6 = Sci . log_1024 u5 ; ;
let u7 = Sci . sin_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let u8 = Sci . direct_sin_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_128 ] | ; ;
let u7a = Sci . sh_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let u7b = Sci . th_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let u7c = Sci . tan_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let u8a = Sci . sh_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_128 ] | ; ;
let u9 = Sci . arcsin_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let u10 = Sci . arcsin_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_128 ] | ; ;
let u9a = Sci . argsh_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let u9b = Sci . direct_argsh_1024 3 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let u10a = Sci . argsh_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_128 ] | ; ;
let u10b = Sci . direct_argsh_1024 3 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_128 ] | ; ;
let c14 = Sci . plus_1024 Sci . half_pi_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let c15 = Sci . cos_1024 c14 ; ;
let c16 = Sci . plus_1024 Sci . half_ipi_1024 [ | Sci . num_1 ; Sci . num_0 ; Sci . num_minus_16 ] | ; ;
let c17 = Sci . ch_1024 c16 ; ;
let u11 = Sci . tan_1024 ( Sci . plus_1024 Sci . half_pi_1024 Sci . sci_i ) ; ;
let u12 = Sci . th_1024 ( Sci . plus_1024 Sci . sci_1 Sci . half_ipi_1024 ) ; ;
let u13 = Sci . plus_1024 u12 ( Sci . mult_1024 Sci . sci_i u11 ) ; ;
let u14 = Sci . exp_1024 ( Sci . mult_1024 ( Sci . sci_of_int 17 ) Sci . ipi_1024 ) ; ;
let u15 = Sci . exp_1024 ( Sci . mult_1024 ( Sci . sci_of_int 99999999 ) Sci . ipi_1024 ) ; ;
let u16 = Sci . log_1024 Sci . sci_minus_1 ; ;
let u17 = Sci . argth_1024 Sci . sci_2 ; ;
let u18 = Sci . th_1024 u17 ; ;
let f29 = Sci . fact 10 29 ; ;
let f170 = Sci . fact 100 170 ; ;
let ( tr , r ) = let a = Sys . time ( ) in let s = Sci . complete_sieve 100 2_000 in let b = Sys . time ( ) in ( b . - a , s ) ; ;
let ( tf , f ) = let a = Sys . time ( ) in let s = Sci . factorial_sieve 100 2_000 in let b = Sys . time ( ) in ( b . - a , s ) ; ;
let ( tp , p ) = let a = Sys . time ( ) in let s = Sci . sieve 50_000 in let b = Sys . time ( ) in ( b . - a , s ) ; ;
let ( tx , x ) = let a = Sys . time ( ) in let s = Sci . factors 444_444_444_444 in let b = Sys . time ( ) in ( b . - a , s ) ; ;
let ( ty , y ) = let a = Sys . time ( ) in let s = Sci . factors 444_444_444 in let b = Sys . time ( ) in ( b . - a , s ) ; ;
let ( tz , z ) = let a = Sys . time ( ) in let s = Sci . factors 2294011 in let b = Sys . time ( ) in ( b . - a , s ) ; ;
let err x = Exn ( Script_cache_test_error x )
let liquidity_baking_contract = Contract . of_b58check " KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5 " |> function | Ok x -> x | _ -> assert false
let make_block block f = Incremental . begin_construction block >>=? fun incr -> f ( Incremental . alpha_ctxt incr ) >>=? fun ( ret , ctxt ) -> let incr = Incremental . set_alpha_ctxt incr ctxt in Incremental . finalize_block incr >>=? fun block -> Block . bake block >>=? fun next_block ->...
let ( @! ) f g = f @@ fun ctxt -> g ctxt >>=? fun ret -> return ( ret , ctxt )
let throw_block_away ( x , _block ) = return x
let equal_scripts ( s1 : Script . t ) ( s2 : Script . t ) = Script_repr . ( force_bytes s1 . code >>? fun code1 -> force_bytes s2 . code >>? fun code2 -> force_bytes s1 . storage >>? fun storage1 -> force_bytes s2 . storage >>? fun storage2 -> ok ( Bytes . equal code1 code2 && By...
let find ctxt addr = Script_cache . find ctxt addr >|= Environment . wrap_tzresult >>=? fun ( ctxt , identifier , result ) -> match result with | None -> assert false | Some ( script , Ex_script ir ) -> return ( ctxt , identifier , script , Ex_script ir )
let value_as_int : type a . a Script_typed_ir . ty -> a -> Script_int_repr . z Script_int_repr . num = fun ty v -> match ty with Int_t -> v | _ -> Stdlib . failwith " value_as_int "
let add_some_contracts k src block baker = ( make_block block @@ fun ctxt -> find ctxt liquidity_baking_contract >>=? fun ( ctxt , id , _ , _ ) -> return ( id , ctxt ) ) >>=? fun ( liquidity_baking_contract_id , block ) -> List . fold_left_es ( fun ( rev_contracts , block ) ...
let assert_cache_size expected_size ctxt = fail_unless ( Script_cache . size ctxt = expected_size ) ( err ( Printf . sprintf " Invalid script cache size , expecting % d , got % d " expected_size ( Script_cache . size ctxt ) ) )
let test_size_of_liquidity_baking_contract ( ) = init ( ) >>=? fun ( block , _ , _ , _ ) -> make_block block @! assert_cache_size liquidity_baking_contract_size >>=? throw_block_away
let test_size_of_int_store_contract ( ) = init ( ) >>=? fun ( block , baker , src , _ ) -> originate_contract " contracts / int - store . tz " " 31 " src block baker >>=? fun ( addr , block ) -> ( make_block block @! fun ctxt -> Script_cache . find ctxt addr >|= Environ...
let test_find_correctly_looks_up ( ) = init ( ) >>=? fun ( block , baker , src , _ ) -> originate_contract " contracts / sapling_contract . tz " " { } " src block baker >>=? fun ( addr , block ) -> ( make_block block @! fun ctxt -> Script_cache . find ctxt addr >|= En...
let test_update_modifies_cached_contract ( ) = init ( ) >>=? fun ( block , baker , src , _ ) -> originate_contract " contracts / int - store . tz " " 36 " src block baker >>=? fun ( addr , block ) -> ( make_block block @! fun ctxt -> find ctxt addr >>=? fun ( ctxt , i...
let test_entries_returns_the_list_in_correct_order ( ) = let ncontracts = 10 in init ( ) >>=? fun ( block , baker , src , _ ) -> add_some_contracts ncontracts src block baker >>=? fun ( contracts , block ) -> let addrs = snd @@ List . split contracts in ( make_block block @! fun c...
let test_contract_rank_is_lru_rank ( ) = let ncontracts = 10 in init ( ) >>=? fun ( block , baker , src , _ ) -> add_some_contracts ncontracts src block baker >>=? fun ( contracts , block ) -> let addrs = snd @@ List . split contracts in ( make_block block @! fun ctxt -> let rec ...
let test_size_adds_entries_sizes ( ) = let ncontracts = 10 in init ( ) >>=? fun ( block , baker , src , _ ) -> add_some_contracts ncontracts src block baker >>=? fun ( _ , block ) -> ( make_block block @! fun ctxt -> let expected_size = liquidity_baking_contract_size + ( ncontra...
let defined_size_limit = Tezos_protocol_alpha_parameters . Default_parameters . constants_mainnet . cache_script_size
let test_size_limit_is_in_constants_repr ( ) = init ( ) >>=? fun ( block , _baker , _src , _ ) -> ( make_block block @! fun ctxt -> fail_unless ( Script_cache . size_limit ctxt = defined_size_limit ) ( err ( Printf . sprintf " Invalid size limit , expecting % d , got % d...
let test_entries_shows_lru ( ) = let ncontracts = 10 in init ( ) >>=? fun ( block , baker , src , _ ) -> add_some_contracts ncontracts src block baker >>=? fun ( contracts , block ) -> let new_size = 2 * defined_size_limit / ncontracts in ( make_block block @@ fun ctxt -> List . ...
let tests = let open Tztest in [ tztest " assumption about size of liquidity baking holds " ` Quick test_size_of_liquidity_baking_contract ; tztest " assumption about size of ' int_store ' contract holds " ` Quick test_size_of_int_store_contract ; tztest " find correctly looks up " ` Quick ...
let normalize_compare c = let open Compare . Int in if c > 0 then 1 else if c < 0 then - 1 else 0
let rec reference_compare_comparable : type a . a comparable_ty -> a -> a -> int = fun ty x y -> match ( ty , x , y ) with | ( Unit_key , ( ) , ( ) ) -> 0 | ( Never_key , _ , _ ) -> . | ( Signature_key , x , y ) -> normalize_compare @@ Script_signature . com...
type ex_comparable_data = | Ex_comparable_data : ' a comparable_ty * ' a -> ex_comparable_data
type ex_comparable_data_2 = | Ex_comparable_data_2 : ' a comparable_ty * ' a * ' a -> ex_comparable_data_2
type ex_comparable_data_3 = | Ex_comparable_data_3 : ' a comparable_ty * ' a * ' a * ' a -> ex_comparable_data_3
module Parameters = struct let atom_size_range : Tezos_benchmark . Base_samplers . range = { min = 0 ; max = 10 } let other_size : Tezos_benchmark . Base_samplers . range = { min = 0 ; max = 100 } let parameters : Michelson_samplers . parameters = { base_parameters = { int_size...
module Crypto_samplers = let size = 1000 let algo = ` Default end )
module Samplers : Michelson_samplers . S = Michelson_samplers . Make ( Parameters ) ( Crypto_samplers )
let ex_comparable_data_sampler : ex_comparable_data Tezos_benchmark . Base_samplers . sampler = fun random_state -> let size = Tezos_benchmark . Base_samplers . sample_in_interval ~ range { : min = 1 ; max = 20 } random_state in let ( Ex_comparable_ty ty ) = Samplers . Random_type . m_c...
let ex_comparable_data_2_sampler : ex_comparable_data_2 Tezos_benchmark . Base_samplers . sampler = fun random_state -> let size = Tezos_benchmark . Base_samplers . sample_in_interval ~ range { : min = 1 ; max = 20 } random_state in let ( Ex_comparable_ty ty ) = Samplers . Random_type . ...
let ex_comparable_data_3_sampler : ex_comparable_data_3 Tezos_benchmark . Base_samplers . sampler = fun random_state -> let size = Tezos_benchmark . Base_samplers . sample_in_interval ~ range { : min = 1 ; max = 20 } random_state in let ( Ex_comparable_ty ty ) = Samplers . Random_type . ...
let comparable_data_generator : ex_comparable_data QCheck . Gen . t = ex_comparable_data_sampler
let comparable_data_2_generator : ex_comparable_data_2 QCheck . Gen . t = ex_comparable_data_2_sampler
let comparable_data_3_generator : ex_comparable_data_3 QCheck . Gen . t = ex_comparable_data_3_sampler
let comparable_data_arbitrary : ex_comparable_data QCheck . arbitrary = QCheck . make comparable_data_generator
let comparable_data_2_arbitrary : ex_comparable_data_2 QCheck . arbitrary = QCheck . make comparable_data_2_generator
let comparable_data_3_arbitrary : ex_comparable_data_3 QCheck . arbitrary = QCheck . make comparable_data_3_generator
let assert_ok = function Ok x -> x | Error _ -> assert false
let assert_return x = assert_ok ( Lwt_main . run x )
let ctxt = assert_return ( Context . init 3 >>=? fun ( b , _cs ) -> Incremental . begin_construction b >>=? fun v -> return ( Incremental . alpha_ctxt v ) )
let unparse_comparable_ty ty = Micheline . strip_locations ( fst ( assert_ok Script_ir_translator . ( unparse_ty ~ loc ( ) : ctxt ( ty_of_comparable_ty ty ) ) ) )
let unparse_comparable_data ty x = Micheline . strip_locations ( fst ( assert_return Script_ir_translator . ( unparse_data ctxt Readable ( ty_of_comparable_ty ty ) x ) ) )
let pack_comparable_data ty x = fst ( assert_return Script_ir_translator . ( pack_data ctxt ( ty_of_comparable_ty ty ) x ) )
let unpack_comparable_data ty bytes = let ty = Script_ir_translator . ty_of_comparable_ty ty in fst ( assert_return ( Script_interpreter_defs . unpack ctxt ~ ty ~ bytes ) )
let pp_comparable_ty fmt ty = Michelson_v1_printer . print_expr fmt ( unparse_comparable_ty ty )
let pp_comparable_data ty fmt x = Michelson_v1_printer . print_expr fmt ( unparse_comparable_data ty x )
let pp ty x y pp_c fmt c = Format . fprintf fmt " Compare ( ty =% a , % a , % a ) = % a " pp_comparable_ty ty ( pp_comparable_data ty ) x ( pp_comparable_data ty ) y pp_c c
let compare_through_pack ty x y = Bytes . compare ( pack_comparable_data ty x ) ( pack_comparable_data ty y ) = 0
let qcheck_compare_comparable ~ expected ty x y = qcheck_eq ~ pp ( : pp ty x y Format . pp_print_int ) expected ( Script_comparable . compare_comparable ty x y )
let qcheck_compare_comparable_eq ~ expected ty x y = qcheck_eq ~ pp ( : pp ty x y Format . pp_print_bool ) expected ( Script_comparable . compare_comparable ty x y = 0 )
let test_compatible_with_reference = QCheck . Test . make ~ name " : compatible_with_reference " comparable_data_2_arbitrary ( fun ( Ex_comparable_data_2 ( ty , x , y ) ) -> qcheck_compare_comparable ~ expected ( : reference_compare_comparable ty x y ) ty x y )
let test_compatible_with_packing = QCheck . Test . make ~ name " : compatible_with_packing " comparable_data_2_arbitrary ( fun ( Ex_comparable_data_2 ( ty , x , y ) ) -> qcheck_compare_comparable_eq ~ expected ( : compare_through_pack ty x y ) ty x y )
let test_reflexivity = QCheck . Test . make ~ name " : reflexivity " comparable_data_arbitrary ( fun ( Ex_comparable_data ( ty , x ) ) -> qcheck_compare_comparable ~ expected : 0 ty x x )
let test_symmetry = QCheck . Test . make ~ name " : symmetry " comparable_data_2_arbitrary ( fun ( Ex_comparable_data_2 ( ty , x , y ) ) -> qcheck_compare_comparable ~ expected ( :- Script_comparable . compare_comparable ty x y ) ty y x )
let test_transitivity = QCheck . Test . make ~ name " : transitivity " comparable_data_3_arbitrary ( fun ( Ex_comparable_data_3 ( ty , x , y , z ) ) -> let cxy = Script_comparable . compare_comparable ty x y in let cyz = Script_comparable . compare_comparable ty y z in match ( cxy , ...
let test_pack_unpack = QCheck . Test . make ~ count : 100_000 ~ name " : pack_unpack " comparable_data_arbitrary ( fun ( Ex_comparable_data ( ty , x ) ) -> let oty = match option_key ( - 1 ) ty with Ok ty -> ty | Error _ -> assert false in qcheck_eq ~ cmp ( : Script_comparable ...
let ( ) = Alcotest . run " Script_comparison " [ ( " compatible_with_reference " , qcheck_wrap [ test_compatible_with_reference ] ) ; ( " compatible_with_packing " , qcheck_wrap [ test_compatible_with_packing ] ) ; ( " reflexivity " , qcheck_wrap [ test_reflexivity...
let err x = Exn ( Script_typed_ir_test_error x )