text
stringlengths
0
601k
let vrf_truncated_output : t = ' \ x15 '
let web_pipe : t = ' \ x16 '
let coinbase_stack_data : t = ' \ x17 '
let coinbase_stack_hash : t = ' \ x18 '
let pending_coinbase_hash_builder : t = ' \ x19 '
let snapp_command : t = ' \ x1A '
let verification_key : t = ' \ x1B '
let token_id_key : t = ' \ x1C '
let ledger_test_hash : t = ' \ x30 '
let private_key : t = ' \ x5A '
let non_zero_curve_point_compressed : t = ' \ xCB '
let signature : t = ' \ x9A '
let parse_generated_hg_version generated_hg_version = generated_hg_version |> String . chop_suffix_if_exists ~ suffix " :\ n " |> String . split ~ on ' :\ n ' |> List . map ~ f ( : fun line -> match String . rsplit2 line ~ on ' : ' with | None -> line | Some ( repo , rev_status ) -> if String . mem rev_status ' _ ' then line else String . concat [ repo ; " _ " ; String . prefix rev_status 12 ; if String . length rev_status mod 2 = 1 then String . suffix rev_status 1 else " " ] ) ; ;
let version_list = parse_generated_hg_version ( generated_hg_version ( ) )
let version = String . concat version_list ~ sep " : "
let hg_version = String . concat version_list ~ sep " :\ n "
let build_info = generated_build_info ( )
module Version = struct type t = { repo : string ; version : string } [ @@ deriving sexp_of ] let parse version = match String . rsplit2 version ~ on ' : _ ' with | None -> error_s [ % message " Could not parse version " version ] | Some ( repo , version ) -> Ok { repo ; version } end
let arg_spec = [ ( " - version " , Arg . Unit ( fun ( ) -> print_endline hg_version ; exit 0 ) , " Print the hg revision of this build and exit " ) ; ( " - build_info " , Arg . Unit ( fun ( ) -> print_endline build_info ; exit 0 ) , " Print build info as sexp and exit " ) ; ]
module Application_specific_fields = struct type t = Sexp . t String . Map . t [ @@ deriving sexp ] end
module Time_with_limited_parsing = struct type t = Time . t * Sexp . t let t_of_sexp sexp = let str = string_of_sexp sexp in try match String . chop_suffix str ~ suffix " : Z " with | None -> failwith " zone must be Z " | Some rest -> match String . lsplit2 rest ~ on ' : ' with | None -> failwith " time must contain one space between date and ofday " | Some ( date , ofday ) -> let date = Date . t_of_sexp ( sexp_of_string date ) in let ofday = Time . Ofday . t_of_sexp ( sexp_of_string ofday ) in Time . of_date_ofday date ofday ~ zone : Time . Zone . utc , sexp with | Sexplib . Conv . Of_sexp_error ( e , _ ) | e -> raise ( Sexplib . Conv . Of_sexp_error ( e , sexp ) ) let sexp_of_t_ref = ref ( fun ( _ , sexp ) -> sexp ) let sexp_of_t time = ! sexp_of_t_ref time end
type t = { username : string option [ @ sexp . option ] ; hostname : string option [ @ sexp . option ] ; kernel : string option [ @ sexp . option ] ; build_time : Time_with_limited_parsing . t option [ @ sexp . option ] ; x_library_inlining : bool ; portable_int63 : bool ; dynlinkable_code : bool ; ocaml_version : string ; executable_path : string ; build_system : string ; allowed_projections : string list option [ @ sexp . option ] ; with_fdo : ( string * Md5 . t option ) option [ @ sexp . option ] ; application_specific_fields : Application_specific_fields . t option [ @ sexp . option ] ;
let build_info_as_sexp = Exn . handle_uncaught_and_exit ( fun ( ) -> Sexp . of_string build_info ) ; ;
let t = Exn . handle_uncaught_and_exit ( fun ( ) -> t_of_sexp build_info_as_sexp )
let { username ; hostname ; kernel ; build_time = build_time_and_sexp ; x_library_inlining ; portable_int63 ; dynlinkable_code ; ocaml_version ; executable_path ; build_system ; allowed_projections ; with_fdo ; application_specific_fields ; } = t ; ;
let build_time = match build_time_and_sexp with | None -> None | Some ( time , _sexp ) -> Some time
let reprint_build_info sexp_of_time = Ref . set_temporarily Time_with_limited_parsing . sexp_of_t_ref ( fun ( time , _ ) -> sexp_of_time time ) ~ f ( : fun ( ) -> Sexp . to_string ( sexp_of_t t ) )
let compiled_for_speed = x_library_inlining && not dynlinkable_code
module For_tests = struct let parse_generated_hg_version = parse_generated_hg_version end
let mouseLeftDown = ref false
let mouseRightDown = ref false
let mouseMiddleDown = ref false
let mouseX = ref 0 . 0
let mouseY = ref 0 . 0
let cameraAngleX = ref 0 . 0
let cameraAngleY = ref 0 . 0
let cameraDistance = ref 0 . 0
let drawMode = ref 0
let maxVertices = ref 0
let maxIndices = ref 0
let ( += ) a b = ( a := ! a . + b ) ; ;
let vertices = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; - 1 . ; - 1 . ; 1 . ; - 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; 1 . ; - 1 . ; - 1 . ; - 1 . ; - 1 . ; - 1 . ; - 1 . ; 1 . ; - 1 . ; - 1 . ; - 1 . ; 1 . ; - 1 . ; - 1 . ; 1 . ; - 1 . ; 1 . ; - 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ; - 1 . ; - 1 . ; - 1 . ; - 1 . ; - 1 . ; 1 . ; - 1 . ; 1 . ; 1 . ; - 1 . ] |
let normals = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ; 0 . ; 0 . ; - 1 . ] |
let colors = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 1 . ; 1 . ; 1 . ; 1 . ; 1 . ; 0 . ; 1 . ; 1 . ; 0 . ; 1 . ; 0 . ; 1 . ; 1 . ; 0 . ; 1 . ; 1 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 0 . ; 0 . ; 0 . ; 0 . ; 0 . ; 1 . ; 1 . ; 0 . ; 1 . ; 1 . ; 0 . ; 0 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 0 . ; 0 . ; 1 . ; 0 . ; 0 . ; 1 . ; 1 . ] |
let indices = Bigarray . Array1 . of_array Bigarray . int16_unsigned Bigarray . c_layout [ | 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ; 14 ; 15 ; 16 ; 17 ; 18 ; 19 ; 20 ; 21 ; 22 ; 23 ] |
let draw1 ( ) = glPushMatrix ( ) ; glTranslate ( - 2 . ) ( 2 . ) ( 0 . ) ; glBegin GL_QUADS ; glNormal3 0 . 0 . 1 . ; glColor3 1 . 1 . 1 . ; glVertex3 1 . 1 . 1 . ; glColor3 1 . 1 . 0 . ; glVertex3 ( - 1 . ) 1 . 1 . ; glColor3 1 . 0 . 0 . ; glVertex3 ( - 1 . ) ( - 1 . ) 1 . ; glColor3 1 . 0 . 1 . ; glVertex3 1 . ( - 1 . ) 1 . ; glNormal3 1 . 0 . 0 . ; glColor3 1 . 1 . 1 . ; glVertex3 1 . 1 . 1 . ; glColor3 1 . 0 . 1 . ; glVertex3 1 . ( - 1 . ) 1 . ; glColor3 0 . 0 . 1 . ; glVertex3 1 . ( - 1 . ) ( - 1 . ) ; glColor3 0 . 1 . 1 . ; glVertex3 1 . 1 . ( - 1 . ) ; glNormal3 0 . 1 . 0 . ; glColor3 1 . 1 . 1 . ; glVertex3 1 . 1 . 1 . ; glColor3 0 . 1 . 1 . ; glVertex3 1 . 1 . ( - 1 . ) ; glColor3 0 . 1 . 0 . ; glVertex3 ( - 1 . ) 1 . ( - 1 . ) ; glColor3 1 . 1 . 0 . ; glVertex3 ( - 1 . ) 1 . 1 . ; glNormal3 ( - 1 . ) 0 . 0 . ; glColor3 1 . 1 . 0 . ; glVertex3 ( - 1 . ) 1 . 1 . ; glColor3 0 . 1 . 0 . ; glVertex3 ( - 1 . ) 1 . ( - 1 . ) ; glColor3 0 . 0 . 0 . ; glVertex3 ( - 1 . ) ( - 1 . ) ( - 1 . ) ; glColor3 1 . 0 . 0 . ; glVertex3 ( - 1 . ) ( - 1 . ) 1 . ; glNormal3 0 . ( - 1 . ) 0 . ; glColor3 0 . 0 . 0 . ; glVertex3 ( - 1 . ) ( - 1 . ) ( - 1 . ) ; glColor3 0 . 0 . 1 . ; glVertex3 1 . ( - 1 . ) ( - 1 . ) ; glColor3 1 . 0 . 1 . ; glVertex3 1 . ( - 1 . ) 1 . ; glColor3 1 . 0 . 0 . ; glVertex3 ( - 1 . ) ( - 1 . ) 1 . ; glNormal3 0 . 0 . ( - 1 . ) ; glColor3 0 . 0 . 1 . ; glVertex3 1 . ( - 1 . ) ( - 1 . ) ; glColor3 0 . 0 . 0 . ; glVertex3 ( - 1 . ) ( - 1 . ) ( - 1 . ) ; glColor3 0 . 1 . 0 . ; glVertex3 ( - 1 . ) 1 . ( - 1 . ) ; glColor3 0 . 1 . 1 . ; glVertex3 1 . 1 . ( - 1 . ) ; glEnd ( ) ; glPopMatrix ( ) ; ; ;
let draw2 ( ) = glEnableClientState GL_NORMAL_ARRAY ; glEnableClientState GL_COLOR_ARRAY ; glEnableClientState GL_VERTEX_ARRAY ; glNormalPointer Norm . GL_FLOAT 0 normals ; glColorPointer 3 Color . GL_FLOAT 0 colors ; glVertexPointer 3 Coord . GL_FLOAT 0 vertices ; glPushMatrix ( ) ; glTranslate 2 . 2 . 0 . ; glDrawArrays GL_QUADS 0 24 ; glPopMatrix ( ) ; glDisableClientState GL_VERTEX_ARRAY ; glDisableClientState GL_COLOR_ARRAY ; glDisableClientState GL_NORMAL_ARRAY ; ; ;
let draw3 ( ) = glEnableClientState GL_NORMAL_ARRAY ; glEnableClientState GL_COLOR_ARRAY ; glEnableClientState GL_VERTEX_ARRAY ; glNormalPointer Norm . GL_FLOAT 0 normals ; glColorPointer 3 Color . GL_FLOAT 0 colors ; glVertexPointer 3 Coord . GL_FLOAT 0 vertices ; glPushMatrix ( ) ; glTranslate ( - 2 . ) ( - 2 . ) ( 0 . ) ; glDrawElements GL_QUADS 24 Elem . GL_UNSIGNED_SHORT indices ; glPopMatrix ( ) ; glDisableClientState GL_VERTEX_ARRAY ; glDisableClientState GL_COLOR_ARRAY ; glDisableClientState GL_NORMAL_ARRAY ; ; ;
let draw4 ( ) = glEnableClientState GL_NORMAL_ARRAY ; glEnableClientState GL_COLOR_ARRAY ; glEnableClientState GL_VERTEX_ARRAY ; glNormalPointer Norm . GL_FLOAT 0 normals ; glColorPointer 3 Color . GL_FLOAT 0 colors ; glVertexPointer 3 Coord . GL_FLOAT 0 vertices ; glPushMatrix ( ) ; glTranslate ( 2 . ) ( - 2 . ) ( 0 . ) ; glDrawRangeElements GL_QUADS 0 11 12 Elem . GL_UNSIGNED_SHORT indices ; glDrawRangeElements GL_QUADS 12 23 12 Elem . GL_UNSIGNED_SHORT ( Bigarray . Array1 . sub indices 12 12 ) ; glPopMatrix ( ) ; glDisableClientState GL_VERTEX_ARRAY ; glDisableClientState GL_COLOR_ARRAY ; glDisableClientState GL_NORMAL_ARRAY ; ; ;
let draw_string str x y ( r , g , b , a ) font = glPushAttrib [ Attrib . GL_LIGHTING_BIT ; Attrib . GL_CURRENT_BIT ] ; glDisable GL_LIGHTING ; glColor4 r g b a ; glRasterPos2 ( float x ) ( float y ) ; let len = String . length str in for i = 0 to pred len do glutBitmapCharacter font str . [ i ] ; done ; glEnable GL_LIGHTING ; glPopAttrib ( ) ; ; ;
let draw_string_3D str ( x , y , z ) ( r , g , b , a ) font = glPushAttrib [ Attrib . GL_LIGHTING_BIT ; Attrib . GL_CURRENT_BIT ] ; glDisable GL_LIGHTING ; glColor4 r g b a ; glRasterPos3 x y z ; let len = String . length str in for i = 0 to pred len do glutBitmapCharacter font str . [ i ] ; done ; glEnable GL_LIGHTING ; glPopAttrib ( ) ; ; ;
let show_info ( ) = glPushMatrix ( ) ; glLoadIdentity ( ) ; glMatrixMode GL_PROJECTION ; glPushMatrix ( ) ; glLoadIdentity ( ) ; gluOrtho2D 0 . 400 . 0 . 300 . ; let color = ( 1 . , 1 . , 1 . , 1 . ) in let str = Printf . sprintf " Max Elements Vertices : % d " ! maxVertices in draw_string str 1 286 color font ; let str = Printf . sprintf " Max Elements Indices : % d " ! maxIndices in draw_string str 1 272 color font ; glPopMatrix ( ) ; glMatrixMode GL_MODELVIEW ; glPopMatrix ( ) ; ; ;
let display ( ) = glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ; GL_STENCIL_BUFFER_BIT ] ; glPushMatrix ( ) ; glTranslate 0 . 0 . ! cameraDistance ; glRotate ! cameraAngleX 1 . 0 . 0 . ; glRotate ! cameraAngleY 0 . 1 . 0 . ; draw1 ( ) ; draw2 ( ) ; draw3 ( ) ; draw4 ( ) ; let color = ( 1 . , 1 . , 1 . , 1 . ) in let pos = ( - 4 . 0 , 3 . 5 , 0 . 0 ) in draw_string_3D " Immediate " pos color font ; let pos = ( 1 . 0 , 0 . 6 , 0 . 0 ) in draw_string_3D " glDrawArrays ( ) " pos color font ; let pos = ( - 4 . 0 , - 0 . 8 , 0 . 0 ) in draw_string_3D " glDrawElements ( ) " pos color font ; let pos = ( 1 . 0 , - 3 . 8 , 0 . 0 ) in draw_string_3D " glDrawRangeElements ( ) " pos color font ; show_info ( ) ; glPopMatrix ( ) ; glutSwapBuffers ( ) ; ; ;
let reshape ~ width : w ~ height : h = glViewport 0 0 w h ; let aspect = ( float w ) . / ( float h ) in glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; ) * gluPerspective ~ fovy : 60 . 0 ~ aspect ~ zNear : 0 . 5 ~ zFar : 80 . 0 ; glMatrixMode GL_MODELVIEW ; ; ;
let rec timer ~ value : millisec = glutTimerFunc ~ msecs : millisec ~ timer ~ value : millisec ; glutPostRedisplay ( ) ; ; ;
let motion ~ x ~ y = if ( ! mouseLeftDown ) then begin cameraAngleY += ( float x . - ! mouseX ) ; cameraAngleX += ( float y . - ! mouseY ) ; mouseX := float x ; mouseY := float y ; end ; if ( ! mouseRightDown ) then begin cameraDistance += ( float y . - ! mouseY ) . * 0 . 2 ; mouseY := float y ; end ; glutPostRedisplay ( ) ; ; ;
let mouse ~ button ~ state ~ x ~ y = mouseX := float x ; mouseY := float y ; match button , state with | GLUT_LEFT_BUTTON , GLUT_DOWN -> mouseLeftDown := true ; | GLUT_LEFT_BUTTON , GLUT_UP -> mouseLeftDown := false ; | GLUT_RIGHT_BUTTON , GLUT_DOWN -> mouseRightDown := true ; | GLUT_RIGHT_BUTTON , GLUT_UP -> mouseRightDown := false ; | GLUT_MIDDLE_BUTTON , GLUT_DOWN -> mouseMiddleDown := true ; | GLUT_MIDDLE_BUTTON , GLUT_UP -> mouseMiddleDown := false ; | _ -> ( ) ; ;
let keyboard ~ key ~ x ~ y = begin match key with | ' \ 027 ' -> exit 0 ; | ' D ' | ' d ' -> drawMode := ( ! drawMode + 1 ) mod 3 ; if ( ! drawMode = 0 ) then begin glPolygonMode GL_FRONT_AND_BACK GL_FILL ; glEnable GL_DEPTH_TEST ; glEnable GL_CULL_FACE ; end else if ( ! drawMode = 1 ) then begin glPolygonMode GL_FRONT_AND_BACK GL_LINE ; glDisable GL_DEPTH_TEST ; glDisable GL_CULL_FACE ; end else begin glPolygonMode GL_FRONT_AND_BACK GL_POINT ; glDisable GL_DEPTH_TEST ; glDisable GL_CULL_FACE ; end ; | _ -> ( ) end ; glutPostRedisplay ( ) ; ; ;
let init_lights ( ) = let lightKa = ( 0 . 2 , 0 . 2 , 0 . 2 , 1 . 0 ) and lightKd = ( 0 . 7 , 0 . 7 , 0 . 7 , 1 . 0 ) and lightKs = ( 1 . 0 , 1 . 0 , 1 . 0 , 1 . 0 ) in glLight ( GL_LIGHT 0 ) ( Light . GL_AMBIENT lightKa ) ; glLight ( GL_LIGHT 0 ) ( Light . GL_DIFFUSE lightKd ) ; glLight ( GL_LIGHT 0 ) ( Light . GL_SPECULAR lightKs ) ; let lightPos = ( 0 . , 0 . , 20 . , 1 . ) in glLight ( GL_LIGHT 0 ) ( Light . GL_POSITION lightPos ) ; glEnable GL_LIGHT0 ; ; ;
let set_camera ~ posX ~ posY ~ posZ ~ targetX ~ targetY ~ targetZ = glMatrixMode GL_MODELVIEW ; glLoadIdentity ( ) ; gluLookAt posX posY posZ targetX targetY targetZ 0 . 1 . 0 . ; ; ;
let initGLUT ( ) = ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_RGB ; GLUT_DOUBLE ; GLUT_DEPTH ; GLUT_STENCIL ] ; glutInitWindowSize 400 300 ; glutInitWindowPosition 100 100 ; let handle = glutCreateWindow Sys . argv . ( 0 ) in glutDisplayFunc ~ display ; glutTimerFunc ~ msecs : 100 ~ timer ~ value : 100 ; glutReshapeFunc ~ reshape ; glutKeyboardFunc ~ keyboard ; glutMouseFunc ~ mouse ; glutMotionFunc ~ motion ; ( handle ) ; ;
let initGL ( ) = glShadeModel GL_SMOOTH ; glPixelStorei GL_UNPACK_ALIGNMENT 4 ; glHint GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST ; glEnable GL_DEPTH_TEST ; glEnable GL_LIGHTING ; glEnable GL_TEXTURE_2D ; glEnable GL_CULL_FACE ; glColorMaterial GL_FRONT_AND_BACK GL_AMBIENT_AND_DIFFUSE ; glEnable GL_COLOR_MATERIAL ; glClearColor 0 . 0 . 0 . 0 . ; glClearStencil 0 ; glClearDepth 1 . 0 ; glDepthFunc GL_LEQUAL ; init_lights ( ) ; set_camera 0 . 0 . 10 . 0 . 0 . 0 . ; ; ;
let ( ) = let _ = initGLUT ( ) in initGL ( ) ; maxVertices := glGetInteger1 Get . GL_MAX_ELEMENTS_VERTICES ; maxIndices := glGetInteger1 Get . GL_MAX_ELEMENTS_INDICES ; glutMainLoop ( ) ; ; ;
module Bigint = struct module R = struct include Field . Bigint let of_data _ = failwith __LOC__ let to_field = Field . of_bigint let of_field = Field . to_bigint end end
let field_size : Bigint . R . t = Field . size
module Verification_key = struct type t = ( Pasta_bindings . Fp . t , Kimchi_bindings . Protocol . SRS . Fp . t , Pasta_bindings . Fq . t Kimchi_types . or_infinity Kimchi_types . poly_comm ) Kimchi_types . VerifierIndex . verifier_index let to_string _ = failwith __LOC__ let of_string _ = failwith __LOC__ let shifts ( t : t ) t = t . shifts end
module R1CS_constraint_system = Plonk_constraint_system . Make ( Field ) Field ( Kimchi_bindings . Protocol . Gates . Vector . Fp ) Fp ( struct let params = Sponge . Params ( . map pasta_p_kimchi ~ f ( : fun x -> Field . of_bigint ( Bigint256 . of_decimal_string x ) x ) ) end ) end
let lagrange : int -> _ Kimchi_types . poly_comm array = Memo . general ~ hashable : Int . hashable ( fun domain_log2 -> Array . map Precomputed . Lagrange_precomputations ( . vesta ( . index_of_domain_log2 domain_log2 ) domain_log2 ) domain_log2 ~ f ( : fun unshifted -> { Kimchi_types . unshifted = Array . map unshifted ~ f ( : fun ( x , y ) y -> Kimchi_types . Finite ( x , y ) y ) y ; shifted = None } ) )
let with_lagrange f ( vk : Verification_key . t ) t = f ( lagrange vk . domain . log_size_of_group ) log_size_of_group vk
let with_lagranges f ( vks : Verification_key . t array ) array = let lgrs = Array . map vks ~ f ( : fun vk -> lagrange vk . domain . log_size_of_group ) log_size_of_group in f lgrs vks
module Keypair = Dlog_plonk_based_keypair . Make ( struct let name = " vesta " module Rounds = Rounds module Urs = Kimchi_bindings . Protocol . SRS . Fp module Index = Kimchi_bindings . Protocol . Index . Fp module Curve = Curve module Poly_comm = Fp_poly_comm module Scalar_field = Field module Verifier_index = Kimchi_bindings . Protocol . VerifierIndex . Fp module Gate_vector = Kimchi_bindings . Protocol . Gates . Vector . Fp module Constraint_system = R1CS_constraint_system end ) end
module Proof = Plonk_dlog_proof . Make ( struct let id = " pasta_vesta " module Scalar_field = Field module Base_field = Fq module Backend = struct type t = ( Pasta_bindings . Fq . t Kimchi_types . or_infinity , Pasta_bindings . Fp . t ) Kimchi_types . prover_proof include Kimchi_bindings . Protocol . Proof . Fp let batch_verify vks ts = Promise . run_in_thread ( fun ( ) -> batch_verify vks ts ) ts let create_aux ~ f : create ( pk : Keypair . t ) t primary auxiliary prev_chals prev_comms = let external_values i = let open Field . Vector in if i = 0 then Field . one else if i - 1 < length primary then get primary ( i - 1 ) 1 else get auxiliary ( i - 1 - length primary ) primary in let computed_witness = R1CS_constraint_system . compute_witness pk . cs external_values in let num_rows = Array . length computed_witness ( . 0 ) 0 in let witness_cols = Array . init Kimchi_backend_common . Constants . columns ~ f ( : fun col -> let witness = Field . Vector . create ( ) in for row = 0 to num_rows - 1 do Field . Vector . emplace_back witness computed_witness ( . col ) col ( . row ) row done ; witness ) in create pk . index witness_cols prev_chals prev_comms let create_async ( pk : Keypair . t ) t primary auxiliary prev_chals prev_comms = create_aux pk primary auxiliary prev_chals prev_comms ~ f ( : fun pk auxiliary_input prev_challenges prev_sgs -> Promise . run_in_thread ( fun ( ) -> create pk auxiliary_input prev_challenges prev_sgs ) ) let create ( pk : Keypair . t ) t primary auxiliary prev_chals prev_comms = create_aux pk primary auxiliary prev_chals prev_comms ~ f : create end module Verifier_index = Kimchi_bindings . Protocol . VerifierIndex . Fp module Index = Keypair module Evaluations_backend = struct type t = Scalar_field . t Kimchi_types . proof_evaluations end module Opening_proof_backend = struct type t = ( Curve . Affine . Backend . t , Scalar_field . t ) t Kimchi_types . opening_proof end module Poly_comm = Fp_poly_comm module Curve = Curve end ) end
module Proving_key = struct type t = Keypair . t include Core_kernel . Binable . Of_binable ( Core_kernel . Unit ) Unit ( struct type nonrec t = t let to_binable _ = ( ) let of_binable ( ) = failwith " TODO " end ) end let is_initialized _ = ` Yes let set_constraint_system _ _ = ( ) let to_string _ = failwith " TODO " let of_string _ = failwith " TODO " end
module Oracles = Plonk_dlog_oracles . Make ( struct module Verifier_index = Verification_key module Field = Field module Proof = Proof module Backend = struct include Kimchi_bindings . Protocol . Oracles . Fp let create = with_lagrange create end end ) end
let relu = Layer . of_fn_ ( fun xs ~ is_training : _ -> Tensor . relu xs )
let relu_ = Layer . of_fn_ ( fun xs ~ is_training : _ -> Tensor . relu_ xs )
type t = | C of int | M
let layers_cfg = function | ` A -> [ C 64 ; M ; C 128 ; M ; C 256 ; C 256 ; M ; C 512 ; C 512 ; M ; C 512 ; C 512 ; M ] | ` B -> [ C 64 ; C 64 ; M ; C 128 ; C 128 ; M ; C 256 ; C 256 ; M ; C 512 ; C 512 ; M ; C 512 ; C 512 ; M ] | ` D -> [ C 64 ; C 64 ; M ; C 128 ; C 128 ; M ; C 256 ; C 256 ; C 256 ; M ; C 512 ; C 512 ; C 512 ; M ; C 512 ; C 512 ; C 512 ; M ] | ` E -> [ C 64 ; C 64 ; M ; C 128 ; C 128 ; M ; C 256 ; C 256 ; C 256 ; C 256 ; M ; C 512 ; C 512 ; C 512 ; C 512 ; M ; C 512 ; C 512 ; C 512 ; C 512 ; M ]
let make_layers vs cfg ~ batch_norm ~ in_place_relu = let relu = if in_place_relu then relu_ else relu in let sub_vs index = Var_store . sub vs ( Int . to_string index ) in let ( _output_dim , _output_idx ) , layers = List . fold_map ( layers_cfg cfg ) ~ init ( : 3 , 0 ) ~ f ( : fun ( input_dim , idx ) v -> match v with | M -> ( ( input_dim , idx + 1 ) , [ Layer . of_fn ( Tensor . max_pool2d ~ ksize ( : 2 , 2 ) ) |> Layer . with_training ] ) | C output_dim -> let conv2d = Layer . conv2d_ ( sub_vs idx ) ~ ksize : 3 ~ stride : 1 ~ padding : 1 ~ input_dim output_dim |> Layer . with_training in if batch_norm then ( let batch_norm = Layer . batch_norm2d ( sub_vs ( idx + 1 ) ) output_dim in ( output_dim , idx + 3 ) , [ conv2d ; batch_norm ; relu ] ) else ( output_dim , idx + 2 ) , [ conv2d ; relu ] ) in List . concat layers
let vgg ~ num_classes vs cfg ~ batch_norm = let cls_vs i = Var_store . ( vs / " classifier " / Int . to_string i ) in let layers = make_layers ( Var_store . sub vs " features " ) cfg ~ batch_norm ~ in_place_relu : true |> Layer . sequential_ in let fc1 = Layer . linear ( cls_vs 0 ) ~ input_dim ( : 512 * 7 * 7 ) 4096 in let fc2 = Layer . linear ( cls_vs 3 ) ~ input_dim : 4096 4096 in let fc3 = Layer . linear ( cls_vs 6 ) ~ input_dim : 4096 num_classes in Layer . of_fn_ ( fun xs ~ is_training -> let batch_size = Tensor . shape xs |> List . hd_exn in Layer . forward_ layers xs ~ is_training |> Tensor . view ~ size [ : batch_size ; - 1 ] |> Layer . forward fc1 |> Tensor . relu |> Tensor . dropout ~ p : 0 . 5 ~ is_training |> Layer . forward fc2 |> Tensor . relu |> Tensor . dropout ~ p : 0 . 5 ~ is_training |> Layer . forward fc3 )
let vgg11 vs ~ num_classes = vgg ~ num_classes vs ` A ~ batch_norm : false
let vgg11_bn vs ~ num_classes = vgg ~ num_classes vs ` A ~ batch_norm : true
let vgg13 vs ~ num_classes = vgg ~ num_classes vs ` B ~ batch_norm : false
let vgg13_bn vs ~ num_classes = vgg ~ num_classes vs ` B ~ batch_norm : true
let vgg16 vs ~ num_classes = vgg ~ num_classes vs ` D ~ batch_norm : false
let vgg16_bn vs ~ num_classes = vgg ~ num_classes vs ` D ~ batch_norm : true
let vgg19 vs ~ num_classes = vgg ~ num_classes vs ` E ~ batch_norm : false
let vgg19_bn vs ~ num_classes = vgg ~ num_classes vs ` E ~ batch_norm : true
let vgg16_layers ( ? max_layer = Int . max_value ) vs ~ batch_norm = let layers = List . take ( make_layers ( Var_store . sub vs " features " ) ` D ~ batch_norm ~ in_place_relu : false ) max_layer in Staged . stage ( fun xs -> List . fold_mapi layers ~ init : xs ~ f ( : fun i xs layer -> let xs = Layer . forward_ layer xs ~ is_training : false in xs , ( i , xs ) ) |> fun ( _ , indexed_layers ) -> Map . of_alist_exn ( module Int ) indexed_layers )
let vgg19 ( ) = let block iter ~ block_idx ~ out_channels x = List . init iter ~ f : Fn . id |> List . fold ~ init : x ~ f ( : fun acc idx -> Fnn . conv2d ( ) acc ~ name ( : Printf . sprintf " conv % d_ % d " block_idx ( idx + 1 ) 1 ) 1 ~ w_init ( ` : normal 0 . 1 ) 1 ~ filter ( : 3 , 3 ) 3 ~ strides ( : 1 , 1 ) 1 ~ padding ` : same ~ out_channels |> Fnn . relu ) relu |> Fnn . max_pool ~ filter ( : 2 , 2 ) 2 ~ strides ( : 2 , 2 ) 2 ~ padding ` : same in let input , input_id = Fnn . input ~ shape ( : D3 ( img_size , img_size , 3 ) 3 ) 3 in let model = Fnn . reshape input ~ shape ( : D3 ( img_size , img_size , 3 ) 3 ) 3 |> block 2 ~ block_idx : 1 ~ out_channels : 64 |> block 2 ~ block_idx : 2 ~ out_channels : 128 |> block 4 ~ block_idx : 3 ~ out_channels : 256 |> block 4 ~ block_idx : 4 ~ out_channels : 512 |> block 4 ~ block_idx : 5 ~ out_channels : 512 |> Fnn . flatten |> Fnn . dense ~ name " : fc6 " ~ w_init ( ` : normal 0 . 1 ) 1 4096 |> Fnn . relu |> Fnn . dense ~ name " : fc7 " ~ w_init ( ` : normal 0 . 1 ) 1 4096 |> Fnn . relu |> Fnn . dense ~ name " : fc8 " ~ w_init ( ` : normal 0 . 1 ) 1 1000 |> Fnn . softmax |> Fnn . Model . create Float in input_id , model
let ( ) = let { Image . tensor ; _ } = Image . load " input . jpg " in let input_id , model = vgg19 ( ) in Fnn . Model . load model ~ filename ( : Caml . Sys . getcwd ( ) ^ " / vgg19 . cpkt ) " ; let results = Fnn . Model . predict model [ input_id , tensor ] in let pr , category = List . init 1000 ~ f ( : fun i -> Tensor . get results [ | 0 ; i ] , | i + 1 ) 1 |> List . reduce_exn ~ f : Caml . max in Stdio . printf " % d : . % 2f %%\ n " category ( 100 . . * pr ) pr
module type Image = sig type t val create : int -> int -> t val size : t -> int val blit_all : t -> t -> unit val copy : t -> t val blank : t -> unit val randomize : t -> unit end
module Image = struct include Mm_image . Image . YUV420 let create w h = create w h let scale = scale ~ proportional : false end
module Make ( Image : Image ) = struct module I = Image type t = Image . t array type buffer = t let make len width height = Array . init len ( fun _ -> Image . create width height ) let single img = [ | img ] | let blit sbuf sofs dbuf dofs len = for i = 0 to len - 1 do Image . blit_all sbuf . ( sofs + i ) dbuf . ( dofs + i ) done let copy vid = Array . map Image . copy vid let length vid = Array . length vid let size vid = let n = ref 0 in for i = 0 to Array . length vid - 1 do n := ! n + Image . size vid . ( i ) done ; ! n let get vid i = vid . ( i ) let set vid i img = vid . ( i ) <- img let iter f vid off len = for i = off to off + len - 1 do f vid . ( i ) done let blank vid off len = iter Image . blank vid off len let randomize vid off len = iter Image . randomize vid off len end
module Canvas = struct module Image = Mm_image . Image . Canvas ( Image ) type image = Image . t type t = Image . t array let make len ( width , height ) : t = Array . init len ( fun _ -> Image . create width height ) let single img = [ | img ] | let single_image img = single ( Image . make img ) let length ( v : t ) = Array . length v let copy ( v : t ) = Array . init ( length v ) ( fun i -> v . ( i ) ) let size ( v : t ) = let n = ref 0 in for i = 0 to Array . length v - 1 do n := ! n + Image . size v . ( i ) done ; ! n let get v i = v . ( i ) let set v i img = v . ( i ) <- img let map_image f v i = v . ( i ) <- f v . ( i ) let render v i = Image . render v . ( i ) let put v i img = v . ( i ) <- Image . make img let blit sbuf sofs dbuf dofs len = for i = 0 to len - 1 do dbuf . ( dofs + i ) <- sbuf . ( sofs + i ) done let map f buf ofs len = for i = ofs to ofs + len - 1 do buf . ( i ) <- f buf . ( i ) done let blank buf ofs len = map ( fun img -> Image . create ( Image . width img ) ( Image . height img ) ) buf ofs len let iter f buf ofs len = for i = ofs to ofs + len - 1 do buf . ( i ) <- Image . iter f buf . ( i ) done end
module FPS = struct type t = float let to_frac f = let n = floor ( ( f . * 100 . ) . + 0 . 5 ) in let n = int_of_float n in if n mod 100 = 0 then ( n / 100 , 1 ) else ( n , 100 ) end
module AVI = struct module Writer = struct let word n = let s = Bytes . create 2 in Bytes . set_int16_le s 0 n ; Bytes . unsafe_to_string s let dword n = let s = Bytes . create 4 in Bytes . set_int32_le s 0 ( Int32 . of_int n ) ; Bytes . unsafe_to_string s module Chunk = struct let create id len = let pad = len mod 2 = 1 in assert ( String . length id = 4 ) ; let s = Bytes . create ( 8 + len + if pad then 1 else 0 ) in Bytes . blit_string id 0 s 0 4 ; Bytes . blit_string ( dword len ) 0 s 4 4 ; if pad then Bytes . set s ( 8 + len ) ( char_of_int 0 ) ; s let make id data = let len = String . length data in let s = create id len in Bytes . blit_string data 0 s 8 len ; Bytes . unsafe_to_string s let audio_s16le buf = let len = Audio . length buf in let channels = Audio . channels buf in let s = create " 01wb " ( len * channels * 2 ) in Audio . S16LE . of_audio buf 0 s 8 len ; Bytes . unsafe_to_string s let video_yuv420 img = let open Mm_image in let width = Image . YUV420 . width img in let height = Image . YUV420 . height img in let y , u , v = Image . YUV420 . data img in let y = Image . Data . to_string y in let u = Image . Data . to_string u in let v = Image . Data . to_string v in let y_stride = Image . YUV420 . y_stride img in let uv_stride = Image . YUV420 . uv_stride img in let s = create " 00db " ( width * height + 2 * ( width / 2 ) * ( height / 2 ) ) in let o = ref 8 in let add_sub data off len = Bytes . blit_string data off s ! o len ; o := ! o + len in let add data = add_sub data 0 ( String . length data ) in if y_stride = width then add y else for j = 0 to height - 1 do add_sub y ( j * y_stride ) width done ; if uv_stride = width / 2 then ( add u ; add v ) else ( for j = 0 to ( height / 2 ) - 1 do add_sub u ( j * uv_stride ) ( width / 2 ) done ; for j = 0 to ( height / 2 ) - 1 do add_sub v ( j * uv_stride ) ( width / 2 ) done ) ; Bytes . unsafe_to_string s let list = make " LIST " end let header ( ? format ` = YUV420 ) ~ width ~ height ~ framerate ? channels ? samplerate ? vendor ( ) = ignore format ; let has_audio = channels <> None in let channels = Option . value ~ default : 0 channels in let samplerate = Option . value ~ default : 0 samplerate in assert ( not has_audio || samplerate > 0 ) ; let dword_max ( ) = word 0xffff ^ word 0xffff in let avi_header = Chunk . make " avih " ( dword ( 1000000 / framerate ) ^ dword 0 ^ dword 0 ^ dword 0x0100 ^ dword_max ( ) ^ dword 0 ^ dword ( 1 + if has_audio then 1 else 0 ) ^ dword 0 ^ dword width ^ dword height ^ dword 0 ^ dword 0 ^ dword 0 ^ dword 0 ) in let video_header = let stream_header = Chunk . make " strh " ( " vids " ^ " I420 " ^ dword 0 ^ word 0 ^ word 0 ^ dword 0 ^ dword 1 ^ dword framerate ^ dword 0 ^ dword_max ( ) ^ dword 0 ^ dword_max ( ) ^ dword 0 ^ word 0 ^ word 0 ^ word width ^ word height ) in let stream_format = Chunk . make " strf " ( dword 40 ^ dword width ^ dword height ^ word 1 ^ word 12 ^ " I420 " ^ dword ( width * height * 6 / 4 ) ^ dword 0 ^ dword 0 ^ dword 0 ^ dword 0 ) in Chunk . list ( " strl " ^ stream_header ^ stream_format ) in let audio_header = if not has_audio then " " else let stream_header = Chunk . make " strh " ( " auds " ^ dword 0 ^ dword 0 ^ word 0 ^ word 0 ^ dword 0 ^ dword 1 ^ dword samplerate ^ dword 0 ^ dword_max ( ) ^ dword 0 ^ dword_max ( ) ^ dword ( 2 * channels ) ^ word 0 ^ word 0 ^ word 0 ^ word 0 ) in let stream_format = Chunk . make " strf " ( word 1 ^ word channels ^ dword samplerate ^ dword ( 2 * channels * samplerate ) ^ word ( 2 * channels ) ^ word 16 ^ word 0 ) in Chunk . list ( " strl " ^ stream_header ^ stream_format ) in let headers = Chunk . list ( " hdrl " ^ avi_header ^ video_header ^ audio_header ) in let info = match vendor with | Some vendor -> let producer = Chunk . make " ISFT " vendor in Chunk . list ( " INFO " ^ producer ) | None -> " " in " RIFF " ^ dword_max ( ) ^ " AVI " ^ headers ^ info ^ " LIST " ^ dword_max ( ) ^ " movi " end end
module IO = struct exception Invalid_file module Reader = struct class type t = object method width : int method height : int method frame_rate : float method read : buffer -> int -> int -> int method close : unit end end module Writer = struct class type t = object method write : buffer -> int -> int -> unit method close : unit end class virtual avi frame_rate w h = let frames_per_chunk = int_of_float ( frame_rate . + 0 . 5 ) in let frame_size = w * h * 3 in object ( self ) inherit IO . helper method virtual private stream_write : string -> int -> int -> int method virtual private stream_seek : int -> unit method virtual private stream_close : unit initializer self # output " RIFF " ; self # output_int 0 ; self # output " AVI " ; self # output " LIST " ; self # output_int 192 ; self # output " hdrl " ; self # output " avih " ; self # output_int 56 ; self # output_int ( int_of_float ( 1000000 . . / frame_rate ) ) ; self # output_int 0 ; self # output_int 0 ; self # output_byte 0 ; self # output_byte 1 ; self # output_byte 0 ; self # output_byte 0 ; self # output_int 0 ; self # output_int 0 ; self # output_int 1 ; self # output_int 0 ; self # output_int w ; self # output_int h ; self # output_int 0 ; self # output_int 0 ; self # output_int 0 ; self # output_int 0 ; self # output " LIST " ; self # output_int 116 ; self # output " strl " ; self # output " strh " ; self # output_int 56 ; self # output " vids " ; self # output " RGB " ; self # output_int 0 ; self # output_int 0 ; self # output_int 0 ; self # output_int 10 ; self # output_int ( int_of_float ( frame_rate . * 10 . ) ) ; self # output_int 0 ; self # output_int 0 ; self # output_int ( frames_per_chunk * frame_size ) ; self # output_int 0 ; self # output_int 0 ; self # output_short 0 ; self # output_short 0 ; self # output_short w ; self # output_short h ; self # output " strf " ; self # output_int 40 ; self # output_int 40 ; self # output_int w ; self # output_int h ; self # output_short 1 ; self # output_short 24 ; self # output_int 0 ; self # output_int frame_size ; self # output_int 0 ; self # output_int 0 ; self # output_int 0 ; self # output_int 0 ; self # output " LIST " ; self # output_int 0 ; self # output " movi " ; self # output " 00dc " ; self # output_int 0 val mutable datalen = 0 val mutable dataframes = 0 method write ( _ : buffer ) ofs len = for _ = ofs to ofs + len - 1 do let s = failwith " TODO : output YUV420 avi " in self # output s ; datalen <- datalen + String . length s done ; dataframes <- dataframes + len method close = Printf . printf " completing . . . ( % d frames ) \ n " %! dataframes ; self # stream_seek 4 ; self # output_int ( datalen + ( 56 * 4 ) ) ; self # stream_seek ( 12 * 4 ) ; self # output_int dataframes ; self # stream_seek ( 35 * 4 ) ; self # output_int dataframes ; self # stream_seek ( 54 * 4 ) ; self # output_int ( datalen + ( 3 * 4 ) ) ; self # stream_seek ( 57 * 4 ) ; self # output_int datalen ; self # stream_close end class to_avi_file fname fr w h = object inherit avi fr w h inherit IO . Unix . rw ~ write : true fname end end end
type t = { duration : int option ; h : int option ; w : int option ; mimetype : string option ; size : int option ; thumbnail_url : string option ; thumbnail_file : Encrypted_file . t option ; thumbnail_info : Thumbnail_info . t option ; }
let encoding = let to_tuple t = ( t . duration , t . h , t . w , t . mimetype , t . size , t . thumbnail_url , t . thumbnail_file , t . thumbnail_info ) in let of_tuple v = let ( duration , h , w , mimetype , size , thumbnail_url , thumbnail_file , thumbnail_info ) = v in { duration ; h ; w ; mimetype ; size ; thumbnail_url ; thumbnail_file ; thumbnail_info ; } in let with_tuple = obj8 ( opt " duration " int ) ( opt " h " int ) ( opt " w " int ) ( opt " mimetype " string ) ( opt " size " int ) ( opt " thumbnail_url " string ) ( opt " thumbnail_file " Encrypted_file . encoding ) ( opt " thumbnail_info " Thumbnail_info . encoding ) in conv to_tuple of_tuple with_tuple