Created
January 29, 2020 21:30
-
-
Save tyler-smith/05f9beee9317cc81ca0eb3bab36b3bc5 to your computer and use it in GitHub Desktop.
Updated Snarky example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core | |
open Snarky | |
module Impl = Snark.Run.Make (Backends.Bn128.Default) (Unit) | |
open Impl | |
let check_product (l : Field.t list) (total : Field.t) () = | |
let open Field in | |
let checked_total = List.fold ~init:one l ~f:( * ) in | |
Assert.equal checked_total total | |
let my_list = List.map ~f:Field.Constant.of_int [1; 2; 3; 4; 5] | |
let total = Field.Constant.of_int 120 | |
let public_input () = Data_spec.[Typ.list ~length:(List.length my_list) Field.typ; Field.typ] | |
let keypair = generate_keypair ~exposing:(public_input ()) check_product | |
let proof = prove (Keypair.pk keypair) (public_input ()) check_product () my_list total | |
let is_valid = verify proof (Keypair.vk keypair) (public_input ()) my_list total | |
let () = printf "Verified program? %b\n" is_valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment