text stringlengths 0 601k |
|---|
module Make_runners ( Backend : Backend_extended . S ) ( Checked : Checked_intf . Extended with type field = Backend . Field . t ) ( As_prover : As_prover_intf . Extended with module Types := Checked . Types with type field := Backend . Field . t ) ( Runner : Runner . S with module Types := Checked . Types with type fi... |
module Make_basic ( Backend : Backend_extended . S ) ( Checked : Checked_intf . Extended with type field = Backend . Field . t ) ( As_prover : As_prover_intf . Extended with module Types := Checked . Types with type field := Backend . Field . t ) ( Runner : Runner . S with module Types := Checked . Types with type fiel... |
module Make ( Backend : Backend_intf . S ) = struct module Backend_extended = Backend_extended . Make ( Backend ) module Runner0 = Runner . Make ( Backend_extended ) module As_prover0 = As_prover . Make_extended ( struct type field = Backend_extended . Field . t end ) ( Checked ) ( As_prover . Make ( Checked ) ( As_pro... |
module Run = struct let functor_counter = ref 0 let active_counters = ref [ ] let is_active_functor_id num = match ! active_counters with | [ ] -> true | active :: _ -> Int . equal active num let active_functor_id ( ) = List . hd_exn ! active_counters let error_on_counter = ref None let throw_on_id id = error_on_counte... |
type ' field m = ( module Snark_intf . Run with type field = ' field ) |
let make ( type field ) ( module Backend : Backend_intf . S with type Field . t = field ) : field m = ( module Run . Make ( Backend ) ) |
let located_label_expr expr = let loc = expr . pexp_loc in [ % expr Stdlib . ( ^ ) [ % e expr ] ( Stdlib . ( ^ ) " : " Stdlib . __LOC__ ) ] |
let located_label_string ~ loc str = [ % expr Stdlib . ( ^ ) [ % e Exp . constant ~ loc ( Const . string ( str ^ " : " ) ) ] Stdlib . __LOC__ ] |
let with_label ~ local ~ loc exprs = let with_label_expr = if local then [ % expr with_label ] else [ % expr Snarky_backendless . Checked . with_label ] in Exp . apply ~ loc with_label_expr exprs |
let with_label_one ~ local ~ loc ~ path : _ expr = with_label ~ local ~ loc [ ( Nolabel , located_label_expr expr ) ] |
let rec snarkydef_inject ~ local ~ loc ~ name expr = match expr . pexp_desc with | Pexp_fun ( lbl , default , pat , body ) -> { expr with pexp_desc = Pexp_fun ( lbl , default , pat , snarkydef_inject ~ local ~ loc ~ name body ) } | Pexp_newtype ( typname , body ) -> { expr with pexp_desc = Pexp_newtype ( typname , snar... |
let snarkydef ~ local ~ loc ~ path : _ name expr = [ % stri let [ % p Pat . var ~ loc ( Located . mk ~ loc name ) ] = [ % e snarkydef_inject ~ local ~ loc ~ name expr ] ] |
let with_label_ext ~ local name = Extension . declare name Extension . Context . expression Ast_pattern . ( single_expr_payload __ ) ( with_label_one ~ local ) |
let snarkydef_ext ~ local name = Extension . declare name Extension . Context . structure_item Ast_pattern . ( pstr ( pstr_value nonrecursive ( value_binding ~ pat ( : ppat_var __ ) ~ expr : __ ^:: nil ) ^:: nil ) ) ( snarkydef ~ local ) |
let main ( ) = Driver . register_transformation name ~ rules : [ Context_free . Rule . extension ( with_label_ext ~ local : false " with_label " ) ; Context_free . Rule . extension ( with_label_ext ~ local : true " with_label_ " ) ; Context_free . Rule . extension ( snarkydef_ext ~ local : false " snarkydef " ) ; Conte... |
module Make ( Inputs : Intf . Test . Inputs_intf ) Inputs_intf = struct open Inputs open Engine open Dsl open Test_common . Make ( Inputs ) Inputs type network = Network . t type node = Network . Node . t type dsl = Dsl . t let initial_fee_payer_balance = Currency . Balance . of_formatted_string " 8000000 " let zkapp_t... |
module type S = sig module Impl : Snarky_backendless . Snark_intf . S open Impl val block_size_in_bits : int val digest_length_in_bits : int val blake2s : ? personalization : string -> Boolean . var array -> Boolean . var array Checked . t end |
module Make ( Impl : Snarky_backendless . Snark_intf . S ) S : S with module Impl := Impl = struct open Impl open Let_syntax module UInt32 = Uint32 . Make ( Impl ) Impl let r1 = 16 let r2 = 12 let r3 = 8 let r4 = 7 let ( := ) ( v , i ) i t = let % map x = t in v ( . i ) i <- x let mixing_g v a b c d x y = let ( := ) i ... |
module Field_intf = struct module type Basic = sig type t val ( * ) : t -> t -> t val ( + ) : t -> t -> t val ( - ) : t -> t -> t val inv_exn : t -> t val negate : t -> t val square : t -> t end module type Constant = sig include Basic end module type Checked = sig type field type bool include Basic val if_ : bool -> t... |
module type Constant_intf = sig type field type t val random : unit -> t val to_affine_exn : t -> field * field val of_affine : field * field -> t val ( + ) : t -> t -> t val negate : t -> t end |
module type Inputs_intf = sig module Impl : Snarky_backendless . Snark_intf . Run module F : sig include Field_intf . Checked with type bool := Impl . Boolean . var and type field := Impl . field module Constant : Field_intf . Constant val assert_square : t -> t -> unit val assert_r1cs : t -> t -> t -> unit val typ : (... |
module Make_checked ( Inputs : Inputs_intf ) = struct open Inputs open Impl type t = F . t * F . t let double ( ( ax , ay ) : t ) : t = let open F in let x_squared = square ax in let lambda = exists typ ~ compute : As_prover . ( fun ( ) -> let x_squared = read typ x_squared in let ay = read typ ay in let open F . Const... |
module type Native_base_field_inputs = sig module Impl : Snarky_backendless . Snark_intf . Run include Inputs_intf with module Impl := Impl and type F . t = Impl . Field . t and type F . Constant . t = Impl . field end |
module For_native_base_field ( Inputs : Native_base_field_inputs ) = struct open Core_kernel open Inputs open Impl include Make_checked ( Inputs ) module Window_table = struct open Tuple_lib type t = Constant . t Quadruple . t array let window_size = 2 let windows = ( Params . group_size_in_bits + window_size - 1 ) / w... |
module type Params_intf = sig type field val a : field val b : field end |
module type Scalar_intf = sig type ( _ , _ ) _ typ type ( _ , _ ) _ checked type boolean_var type var type t [ @@ deriving equal , sexp ] sexp val typ : ( var , t ) t typ val length_in_bits : int val test_bit : t -> int -> bool module Checked : sig val equal : var -> var -> ( boolean_var , _ ) _ checked module Assert :... |
module type Shifted_intf = sig type _ checked type boolean_var type curve_var type t val zero : t val add : t -> curve_var -> t checked val unshift_nonzero : t -> curve_var checked val if_ : boolean_var -> then_ : t -> else_ : t -> t checked module Assert : sig val equal : t -> t -> unit checked end end |
module type Weierstrass_checked_intf = sig module Impl : Snarky_backendless . Snark_intf . S open Impl type unchecked type t val typ : ( t , unchecked ) unchecked Typ . t module Shifted : sig module type S = Shifted_intf with type ' a checked := ' a Checked . t and type curve_var := t and type boolean_var := Boolean . ... |
module Make_weierstrass_checked ( F : Snarky_field_extensions . Intf . S ) S ( Scalar : sig type t val of_int : int -> t end ) end ( Curve : sig type t val random : unit -> t val to_affine_exn : t -> F . Unchecked . t * F . Unchecked . t val of_affine : F . Unchecked . t * F . Unchecked . t -> t val double : t -> t val... |
module Challenge = Limb_vector . Challenge . Make ( Impl ) Impl |
module Sc = Pickles . Scalar_challenge . Make ( Impl ) Impl ( Pickles . Step_main_inputs . Inner_curve ) Inner_curve ( Challenge ) Challenge ( Pickles . Endo . Step_inner_curve ) Step_inner_curve |
let console_log_string s = Js_of_ocaml . Firebug . console ## log ( Js . string s ) s |
let console_log s = Js_of_ocaml . Firebug . console ## log s |
let raise_error s = let s = Js . string s in Js . raise_js_error ( new % js Js . error_constr s ) s |
let raise_errorf fmt = Core_kernel . ksprintf raise_error fmt object method value : Impl . Field . t Js . prop method toString : Js . js_string Js . t Js . meth method toJSON : < . . > Js . t Js . meth method toFields : field_class Js . t Js . js_array Js . t Js . meth end object method value : Impl . Boolean . var Js ... |
module As_field = struct type t let of_field ( x : Impl . Field . t ) t : t = Obj . magic x let of_field_obj ( x : field_class Js . t ) t : t = Obj . magic x let value ( value : t ) t : Impl . Field . t = match Js . to_string ( Js . typeof ( Obj . magic value ) value ) value with | " number " -> let value = Js . float_... |
let bool_constant ( b : Impl . Boolean . var ) var = match ( b :> Impl . Field . t ) t with | Constant b -> Some Impl . Field . Constant ( . equal one b ) b | _ -> None |
module As_bool = struct type t let of_boolean ( x : Impl . Boolean . var ) var : t = Obj . magic x let of_bool_obj ( x : bool_class Js . t ) t : t = Obj . magic x let of_js_bool ( b : bool Js . t ) t : t = Obj . magic b let value ( value : t ) t : Impl . Boolean . var = match Js . to_string ( Js . typeof ( Obj . magic ... |
let bool_class : < . . > Js . t = let f = Js . Unsafe . eval_string { js | ( function ( functionasBoolValue ) functionasBoolValue { return function ( functionx ) functionx { this . value = asBoolValue ( asBoolValuex ) asBoolValuex ; return this ; } } ) | js } js in Js . Unsafe ( . fun_call f [ | inject ( Js . wrap_call... |
let bool_constr : ( As_bool . t -> bool_class Js . t ) t Js . constr = Obj . magic bool_class |
let singleton_array ( type a ) a ( x : a ) a : a Js . js_array Js . t = let arr = new % js Js . array_empty in arr ## push x |> ignore ; arr |
let handle_constants f f_constant ( x : Field . t ) t = match x with Constant x -> f_constant x | _ -> f x |
let handle_constants2 f f_constant ( x : Field . t ) t ( y : Field . t ) t = match ( x , y ) y with Constant x , Constant y -> f_constant x y | _ -> f x y |
let array_get_exn xs i = Js . Optdef . get ( Js . array_get xs i ) i ( fun ( ) -> raise_error ( sprintf " array_get_exn : index =% d , length =% d " i xs . ## length ) length ) |
let array_check_length xs n = if xs . ## length <> n then raise_error ( sprintf " Expected array of length % d " n ) n |
let method_ class_ ( name : string ) string ( f : _ Js . t -> _ ) _ = let prototype = Js . Unsafe . get class_ ( Js . string " prototype ) " in Js . Unsafe . set prototype ( Js . string name ) name ( Js . wrap_meth_callback f ) f |
let optdef_arg_method ( type a ) a class_ ( name : string ) string ( f : _ Js . t -> a Js . Optdef . t -> _ ) _ = let prototype = Js . Unsafe . get class_ ( Js . string " prototype ) " in let meth = let wrapper = Js . Unsafe . eval_string { js | ( function ( functionf ) functionf { return function ( functionxOptdef ) f... |
let to_js_field x : field_class Js . t = new % js field_constr ( As_field . of_field x ) x |
let of_js_field ( x : field_class Js . t ) t : Field . t = x . ## value |
let to_js_field_unchecked x : field_class Js . t = x |> Field . constant |> to_js_field |
let ( ) = let method_ name ( f : field_class Js . t -> _ ) _ = method_ field_class name f in let to_string ( x : Field . t ) t = ( match x with | Constant x -> x | x -> As_prover . read_var x ) |> Field . Constant . to_string |> Js . string in let mk = to_js_field in let add_op1 name ( f : Field . t -> Field . t ) t = ... |
let ( ) = let handle_constants2 f f_constant ( x : Boolean . var ) var ( y : Boolean . var ) var = match ( ( x :> Field . t ) t , ( y :> Field . t ) t ) t with | Constant x , Constant y -> f_constant x y | _ -> f x y in let equal = handle_constants2 Boolean . equal ( fun x y -> Boolean . var_of_value ( Field . Constant... |
type coords = < x : As_field . t Js . prop ; y : As_field . t Js . prop > Js . t |
let group_class : < . . > Js . t = let f = Js . Unsafe . eval_string { js | ( function ( functiontoFieldObj ) functiontoFieldObj { return function ( function ) function { var err = ' Group constructor expects either 2 arguments ( x , y ) y or a single argument object { x , y } ' ; if ( arguments . length == 1 ) 1 { var... |
module As_group = struct type t class type group_class = object method x : field_class Js . t Js . prop method y : field_class Js . t Js . prop method add : group_class Js . t -> group_class Js . t Js . meth method add_ : t -> group_class Js . t Js . meth method sub_ : t -> group_class Js . t Js . meth method neg : gro... |
let to_js_group ( x : Impl . Field . t ) t ( y : Impl . Field . t ) t : group_class Js . t = new % js group_constr ( As_field . of_field_obj ( to_js_field x ) x ) x ( As_field . of_field_obj ( to_js_field y ) y ) y |
let scalar_shift = Pickles_types . Shifted_value . Type1 . Shift . create ( module Other_backend . Field ) Field |
let to_constant_scalar ( bs : Boolean . var array ) array : Other_backend . Field . t Js . Optdef . t = with_return ( fun { return } -> let bs = Array . map bs ~ f ( : fun b -> match ( b :> Field . t ) t with | Constant b -> Impl . Field . Constant ( . equal one b ) b | _ -> return Js . Optdef . empty ) in Js . Optdef ... |
let scalar_class : < . . > Js . t = let f = Js . Unsafe . eval_string { js | ( function ( functiontoConstantFieldElt ) functiontoConstantFieldElt { return function ( functionbits , constantValue ) constantValue { this . value = bits ; if ( constantValue !== undefined ) undefined { this . constantValue = constantValue ;... |
let scalar_constr : ( Boolean . var array -> scalar_class Js . t ) t Js . constr = Obj . magic scalar_class |
let scalar_constr_const : ( Boolean . var array -> Other_backend . Field . t -> scalar_class Js . t ) t Js . constr = Obj . magic scalar_class |
let scalar_to_bits x = let ( Shifted_value x ) x = Pickles_types . Shifted_value . Type1 . of_field ~ shift : scalar_shift ( module Other_backend . Field ) Field x in Array . of_list_map ( Other_backend . Field . to_bits x ) x ~ f : Boolean . var_of_value |
let to_js_scalar x = new % js scalar_constr_const ( scalar_to_bits x ) x x |
let ( ) = let num_bits = Field . size_in_bits in let method_ name ( f : scalar_class Js . t -> _ ) _ = method_ scalar_class name f in let static_method name f = Js . Unsafe . set scalar_class ( Js . string name ) name ( Js . wrap_callback f ) f in let ( ! ) name x = Js . Optdef . get x ( fun ( ) -> raise_error ( sprint... |
let ( ) = let mk ( x , y ) y : group_class Js . t = new % js group_constr ( As_field . of_field x ) x ( As_field . of_field y ) y in let method_ name ( f : group_class Js . t -> _ ) _ = method_ group_class name f in let static name x = Js . Unsafe . set group_class ( Js . string name ) name x in let static_method name ... |
let array_iter t1 ~ f = for i = 0 to t1 . ## length - 1 do f ( array_get_exn t1 i ) i done |
let array_iter2 t1 t2 ~ f = for i = 0 to t1 . ## length - 1 do f ( array_get_exn t1 i ) i ( array_get_exn t2 i ) i done |
let array_map t1 ~ f = let res = new % js Js . array_empty in array_iter t1 ~ f ( : fun x1 -> res ## push ( f x1 ) x1 |> ignore ) ignore ; res |
let array_map2 t1 t2 ~ f = let res = new % js Js . array_empty in array_iter2 t1 t2 ~ f ( : fun x1 x2 -> res ## push ( f x1 x2 ) x2 |> ignore ) ignore ; res |
module Poseidon_sponge_checked = Sponge . Make_sponge ( Pickles . Step_main_inputs . Sponge . Permutation ) Permutation |
module Poseidon_sponge = Sponge . Make_sponge ( Sponge . Poseidon ( Pickles . Tick_field_sponge . Inputs ) Inputs ) Inputs |
let sponge_params_checked = Sponge . Params ( . map pasta_p_kimchi ~ f ( : Fn . compose Field . constant Field . Constant . of_string ) of_string ) of_string |
let sponge_params = Sponge . Params ( . map pasta_p_kimchi ~ f : Field . Constant . of_string ) of_string |
type sponge = | Checked of Poseidon_sponge_checked . t | Unchecked of Poseidon_sponge . t |
let to_unchecked ( x : Field . t ) t = match x with Constant y -> y | y -> Impl . As_prover . read_var y |
let poseidon = object % js method hash ( xs : field_class Js . t Js . js_array Js . t ) t : field_class Js . t = let input = Array . map ( Js . to_array xs ) xs ~ f : of_js_field in let digest = try Random_oracle . Checked . hash input with _ -> Random_oracle . hash ( Array . map ~ f : to_unchecked input ) input |> Fie... |
let keypair_class : < . . > Js . t = Js . Unsafe . eval_string { js ( | function ( functionv ) functionv { this . value = v ; return this } ) | js } js |
let keypair_constr : ( Keypair . t -> keypair_class Js . t ) t Js . constr = Obj . magic keypair_class |
let verification_key_class : < . . > Js . t = Js . Unsafe . eval_string { js ( | function ( functionv ) functionv { this . value = v ; return this } ) | js } js |
let verification_key_constr : ( Verification_key . t -> verification_key_class Js . t ) t Js . constr = Obj . magic verification_key_class |
let proof_class : < . . > Js . t = Js . Unsafe . eval_string { js ( | function ( functionv ) functionv { this . value = v ; return this } ) | js } js |
let proof_constr : ( Backend . Proof . t -> proof_class Js . t ) t Js . constr = Obj . magic proof_class |
module Circuit = struct let check_lengths s t1 t2 = if t1 . ## length <> t2 . ## length then raise_error ( sprintf " % s : Got mismatched lengths , % d != % d " s t1 . ## length t2 . ## length ) else ( ) let wrap name ~ pre_args ~ post_args ~ explicit ~ implicit = let total_implicit = pre_args + post_args in let total_... |
let ( ) = let method_ name ( f : keypair_class Js . t -> _ ) _ = method_ keypair_class name f in method_ " verificationKey " ( fun ( this : keypair_class Js . t ) t : verification_key_class Js . t -> new % js verification_key_constr ( Keypair . vk this . ## value ) value ) |
let ( ) = let method_ name ( f : verification_key_class Js . t -> _ ) _ = method_ verification_key_class name f in proof_class . ## ofString := Js . wrap_callback ( fun ( s : Js . js_string Js . t ) t : proof_class Js . t -> new % js proof_constr ( Js . to_string s |> Binable . of_string ( module Backend . Proof ) Proo... |
let ( ) = let method_ name ( f : proof_class Js . t -> _ ) _ = method_ proof_class name f in method_ " toString " ( fun this : Js . js_string Js . t -> Binable . to_string ( module Backend . Proof ) Proof this . ## value |> Js . string ) ; proof_class . ## ofString := Js . wrap_callback ( fun ( s : Js . js_string Js . ... |
type ' a zkapp_statement = { transaction : ' a ; at_party : ' a } |
let zkapp_statement_to_fields { transaction ; at_party } = [ | transaction ; at_party ] | |
type zkapp_statement_js = < transaction : field_class Js . t Js . readonly_prop ; atParty : field_class Js . t Js . readonly_prop > Js . t |
module Zkapp_statement = struct type t = Field . t zkapp_statement let to_field_elements = zkapp_statement_to_fields let to_constant ( { transaction ; at_party } : t ) t = { transaction = to_unchecked transaction ; at_party = to_unchecked at_party } let to_js ( { transaction ; at_party } : t ) t = object % js val trans... |
let zkapp_statement_typ = let to_hlist { transaction ; at_party } = H_list [ . transaction ; at_party ] in let of_hlist ( [ transaction ; at_party ] : ( unit , _ ) _ H_list . t ) t = { transaction ; at_party } in Typ . of_hlistable [ Field . typ ; Field . typ ] ~ var_to_hlist : to_hlist ~ var_of_hlist : of_hlist ~ valu... |
let dummy_constraints = let module Inner_curve = Kimchi_pasta . Pasta . Pallas in let module Step_main_inputs = Pickles . Step_main_inputs in let inner_curve_typ : ( Field . t * Field . t , Inner_curve . t ) t Typ . t = Typ . transport Step_main_inputs . Inner_curve . typ ~ there : Inner_curve . to_affine_exn ~ back : ... |
type ( ' a_var , ' a_value , ' a_weird ) ' a_weird pickles_rule = { identifier : string ; prevs : ' a_weird list ; main : ' a_var list -> ' a_var -> Boolean . var list ; main_value : ' a_value list -> ' a_value -> bool list } |
type pickles_rule_js = Js . js_string Js . t * ( zkapp_statement_js -> unit ) unit |
let create_pickles_rule ( ( identifier , main ) main : pickles_rule_js ) pickles_rule_js = { identifier = Js . to_string identifier ; prevs = [ ] ; main = ( fun _ statement -> dummy_constraints ( ) ; main ( Zkapp_statement . to_js statement ) statement ; [ ] ) ; main_value = ( fun _ _ -> [ ] ) } |
let dummy_rule self = { identifier = " dummy " ; prevs = [ self ; self ] ; main_value = ( fun _ _ -> [ true ; true ] ) ; main = ( fun _ _ -> dummy_constraints ( ) ; let x = Impl . exists Field . typ ~ compute ( : fun ( ) -> Field . Constant . zero ) zero in Field ( . Assert . equal x ( x + one ) one ) one ; Boolean [ .... |
let other_verification_key_constr : ( Other_impl . Verification_key . t -> verification_key_class Js . t ) t Js . constr = Obj . magic verification_key_class |
type proof = ( Pickles_types . Nat . N2 . n , Pickles_types . Nat . N2 . n ) n Pickles . Proof . t |
module Statement_with_proof = Pickles_types . Hlist . H3 . T ( Pickles . Statement_with_proof ) Statement_with_proof |
let nat_modules_list : ( module Pickles_types . Nat . Intf ) Intf list = let open Pickles_types . Nat in [ ( module N0 ) N0 ; ( module N1 ) N1 ; ( module N2 ) N2 ; ( module N3 ) N3 ; ( module N4 ) N4 ; ( module N5 ) N5 ; ( module N6 ) N6 ; ( module N7 ) N7 ; ( module N8 ) N8 ; ( module N9 ) N9 ; ( module N10 ) N10 ; ( ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.