From 8cb73037b8e1095edfb7bf37d42b1bcba459df50 Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 23 May 2022 10:48:59 +0200 Subject: [PATCH 01/25] [snarkyjs] do not export balance change type --- src/lib/snarky_js_bindings/snarky_js_types.ml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lib/snarky_js_bindings/snarky_js_types.ml b/src/lib/snarky_js_bindings/snarky_js_types.ml index c9516994832..e6a2fd16450 100644 --- a/src/lib/snarky_js_bindings/snarky_js_types.ml +++ b/src/lib/snarky_js_bindings/snarky_js_types.ml @@ -4,9 +4,6 @@ let () = let layout = Fields_derivers_zkapps.js_layout in let js_layout = `Assoc - [ ("Parties", layout Parties.deriver) - ; ("BalanceChange", layout Fields_derivers_zkapps.Derivers.balance_change) - ; ("Party", layout Party.deriver) - ] + [ ("Parties", layout Parties.deriver); ("Party", layout Party.deriver) ] in print_endline (js_layout |> Yojson.Safe.pretty_to_string) From 93323ef9f0615a9a07ff3d07ca7f660db2776f58 Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 23 May 2022 11:01:11 +0200 Subject: [PATCH 02/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index 812b31dbda4..a5439c595fe 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit 812b31dbda4effa7b7138331910545f938bce008 +Subproject commit a5439c595fe025b0b52595c788508a897f255236 From 71bf1ae633ba7a37ecb647d9404b99fbd9213d34 Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 23 May 2022 15:06:24 +0200 Subject: [PATCH 03/25] [snarkyjs] fix Field(large number) --- .../lib/snarky_js_bindings_lib.ml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml index 105f7c591b0..b50795d6d43 100644 --- a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml +++ b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml @@ -54,11 +54,18 @@ module As_field = struct let value (value : t) : Impl.Field.t = match Js.to_string (Js.typeof (Obj.magic value)) with | "number" -> - let value = Js.float_of_number (Obj.magic value) in - if Float.is_integer value then - let value = Float.to_int value in - if value >= 0 then Impl.Field.of_int value - else Impl.Field.negate (Impl.Field.of_int (-value)) + let number : Js.number Js.t = Obj.magic value in + let float = Js.float_of_number number in + if Float.is_integer float then + if float >= 0. then + Impl.Field.( + constant @@ Constant.of_string @@ Js.to_string @@ number##toString) + else + let number : Js.number Js.t = Obj.magic (-.float) in + Impl.Field.negate + Impl.Field.( + constant @@ Constant.of_string @@ Js.to_string + @@ number##toString) else raise_error "Cannot convert a float to a field element" | "boolean" -> let value = Js.to_bool (Obj.magic value) in From d952a58f5217d25eb5a40c5758dcfebd8ecff29d Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 23 May 2022 15:08:12 +0200 Subject: [PATCH 04/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index a5439c595fe..37a22b7bff6 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit a5439c595fe025b0b52595c788508a897f255236 +Subproject commit 37a22b7bff6c1a4057e39e45b1aebed691353cb6 From eb1f1786e5d2d88632f9a0f2ceb7230626d9f2e3 Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 23 May 2022 20:40:08 +0200 Subject: [PATCH 05/25] [snarkyjs] switch to max_proofs_verified:N0 --- .../lib/snarky_js_bindings_lib.ml | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml index 105f7c591b0..7d7da009956 100644 --- a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml +++ b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml @@ -1642,26 +1642,11 @@ let create_pickles_rule ((identifier, main) : pickles_rule_js) = ; main_value = (fun _ _ -> []) } -let dummy_rule self = - { identifier = "dummy" - ; prevs = [ self; self ] - ; main_value = (fun _ _ -> [ true; true ]) - ; main = - (fun _ _ -> - dummy_constraints () ; - (* unsatisfiable *) - let x = - Impl.exists Field.typ ~compute:(fun () -> Field.Constant.zero) - in - Field.(Assert.equal x (x + one)) ; - Boolean.[ true_; true_ ] ) - } - let other_verification_key_constr : (Other_impl.Verification_key.t -> verification_key_class Js.t) Js.constr = Obj.magic verification_key_class -type proof = (Pickles_types.Nat.N2.n, Pickles_types.Nat.N2.n) Pickles.Proof.t +type proof = (Pickles_types.Nat.N0.n, Pickles_types.Nat.N0.n) Pickles.Proof.t module Statement_with_proof = Pickles_types.Hlist.H3.T (Pickles.Statement_with_proof) @@ -1696,10 +1681,8 @@ let nat_module (i : int) : (module Pickles_types.Nat.Intf) = let pickles_compile (choices : pickles_rule_js Js.js_array Js.t) = let choices = choices |> Js.to_array |> Array.to_list in - let branches = List.length choices + 1 in - let choices ~self = - List.map choices ~f:create_pickles_rule @ [ dummy_rule self ] - in + let branches = List.length choices in + let choices ~self:_ = List.map choices ~f:create_pickles_rule in let (module Branches) = nat_module branches in (* TODO get rid of Obj.magic for choices *) let tag, _cache, p, provers = @@ -1708,7 +1691,7 @@ let pickles_compile (choices : pickles_rule_js Js.js_array Js.t) = (module Zkapp_statement.Constant) ~typ:zkapp_statement_typ ~branches:(module Branches) - ~max_proofs_verified:(module Pickles_types.Nat.N2) + ~max_proofs_verified:(module Pickles_types.Nat.N0) (* ^ TODO make max_branching configurable -- needs refactor in party types *) ~name:"smart-contract" ~constraint_constants: From 4304cc51ccadcdf0dec28f1e13dcb034cc06a879 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 24 May 2022 20:46:06 +0200 Subject: [PATCH 06/25] [snarkyjs] Field(bigint), Field('-1'), Field.fromX --- .../lib/snarky_js_bindings_lib.ml | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml index b50795d6d43..bff5b1b86eb 100644 --- a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml +++ b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml @@ -51,37 +51,56 @@ module As_field = struct let of_field_obj (x : field_class Js.t) : t = Obj.magic x + let of_number_exn (value : t) : Impl.Field.t = + let number : Js.number Js.t = Obj.magic value in + let float = Js.float_of_number number in + if Float.is_integer float then + if float >= 0. then + Impl.Field.( + constant @@ Constant.of_string @@ Js.to_string @@ number##toString) + else + let number : Js.number Js.t = Obj.magic (-.float) in + Impl.Field.negate + Impl.Field.( + constant @@ Constant.of_string @@ Js.to_string @@ number##toString) + else raise_error "Cannot convert a float to a field element" + + let of_boolean (value : t) : Impl.Field.t = + let value = Js.to_bool (Obj.magic value) in + if value then Impl.Field.one else Impl.Field.zero + + let of_string_exn (value : t) : Impl.Field.t = + let value : Js.js_string Js.t = Obj.magic value in + let s = Js.to_string value in + try + Impl.Field.constant + ( if + String.length s >= 2 + && Char.equal s.[0] '0' + && Char.equal (Char.lowercase_ascii s.[1]) 'x' + then Kimchi_pasta.Pasta.Fp.(of_bigint (Bigint.of_hex_string s)) + else if String.length s >= 1 && Char.equal s.[0] '-' then + String.sub s 1 (String.length s - 1) + |> Impl.Field.Constant.of_string |> Impl.Field.Constant.negate + else Impl.Field.Constant.of_string s ) + with Failure e -> raise_error e + + let of_bigint_exn (value : t) : Impl.Field.t = + let bigint : < toString : Js.js_string Js.t Js.meth > Js.t = + Obj.magic value + in + bigint##toString |> Obj.magic |> of_string_exn + let value (value : t) : Impl.Field.t = match Js.to_string (Js.typeof (Obj.magic value)) with | "number" -> - let number : Js.number Js.t = Obj.magic value in - let float = Js.float_of_number number in - if Float.is_integer float then - if float >= 0. then - Impl.Field.( - constant @@ Constant.of_string @@ Js.to_string @@ number##toString) - else - let number : Js.number Js.t = Obj.magic (-.float) in - Impl.Field.negate - Impl.Field.( - constant @@ Constant.of_string @@ Js.to_string - @@ number##toString) - else raise_error "Cannot convert a float to a field element" + of_number_exn value | "boolean" -> - let value = Js.to_bool (Obj.magic value) in - if value then Impl.Field.one else Impl.Field.zero - | "string" -> ( - let value : Js.js_string Js.t = Obj.magic value in - let s = Js.to_string value in - try - Impl.Field.constant - ( if - String.length s >= 2 - && Char.equal s.[0] '0' - && Char.equal (Char.lowercase_ascii s.[1]) 'x' - then Kimchi_pasta.Pasta.Fp.(of_bigint (Bigint.of_hex_string s)) - else Impl.Field.Constant.of_string s ) - with Failure e -> raise_error e ) + of_boolean value + | "string" -> + of_string_exn value + | "bigint" -> + of_bigint_exn value | "object" -> let is_array = Js.to_bool (Js.Unsafe.global ##. Array##isArray value) in if is_array then @@ -501,7 +520,11 @@ let () = else Field.Constant.of_string s ) ) with Failure _ -> Js.Opt.empty ) | _ -> - Js.Opt.empty ) + Js.Opt.empty ) ; + let from f x = new%js field_constr (As_field.of_field (f x)) in + static_method "fromNumber" (from As_field.of_number_exn) ; + static_method "fromString" (from As_field.of_string_exn) ; + static_method "fromBigInt" (from As_field.of_bigint_exn) let () = let handle_constants2 f f_constant (x : Boolean.var) (y : Boolean.var) = From 40259f65ebf364e1fe0763b18f89317d05b373b2 Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 25 May 2022 09:00:30 +0200 Subject: [PATCH 07/25] [snarkyjs] Field.toBigint, minusOne, ORDER --- .../snarky_js_bindings/lib/snarky_js_bindings_lib.ml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml index bff5b1b86eb..1b84ed617aa 100644 --- a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml +++ b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml @@ -254,6 +254,11 @@ let optdef_arg_method (type a) class_ (name : string) in Js.Unsafe.set prototype (Js.string name) meth +let to_js_bigint = + let bigint_constr = Js.Unsafe.eval_string {js|BigInt|js} in + fun (s : Js.js_string Js.t) -> + Js.Unsafe.fun_call bigint_constr [| Js.Unsafe.inject s |] + let to_js_field x : field_class Js.t = new%js field_constr (As_field.of_field x) let of_js_field (x : field_class Js.t) : Field.t = x##.value @@ -304,6 +309,7 @@ let () = method_ "sizeInFields" (fun _this : int -> 1) ; method_ "toFields" (fun this : field_class Js.t Js.js_array Js.t -> singleton_array this ) ; + method_ "toBigInt" (fun this -> to_string this##.value |> to_js_bigint) ; ((* TODO: Make this work with arbitrary bit length *) let bit_length = Field.size_in_bits - 2 in let cmp_method (name, f) = @@ -384,6 +390,10 @@ let () = in field_class##.one := mk Field.one ; field_class##.zero := mk Field.zero ; + field_class##.minusOne := mk @@ Field.negate Field.one ; + Js.Unsafe.set field_class (Js.string "ORDER") + ( to_js_bigint @@ Js.string @@ Pasta_bindings.BigInt256.to_string + @@ Pasta_bindings.Fp.size () ) ; field_class##.random := Js.wrap_callback (fun () : field_class Js.t -> mk (Field.constant (Field.Constant.random ())) ) ; From 19644b723d83d74ba061c3f37ade7ea78b14936e Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 25 May 2022 10:00:21 +0200 Subject: [PATCH 08/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index 37a22b7bff6..f41d28875d1 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit 37a22b7bff6c1a4057e39e45b1aebed691353cb6 +Subproject commit f41d28875d1756ac29bab0367dbd8bba433fcb97 From 418157ea10b0f73d8ea26248043579a494bd8133 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 26 May 2022 09:53:17 +0200 Subject: [PATCH 09/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index f41d28875d1..d34744d3e21 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit f41d28875d1756ac29bab0367dbd8bba433fcb97 +Subproject commit d34744d3e21b7476551dd5d248d2fbf0d5fdbaff From a379027f70185bc6306db60f9912434115ec2f94 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 26 May 2022 11:54:26 +0200 Subject: [PATCH 10/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index d34744d3e21..f59c5f5bce2 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit d34744d3e21b7476551dd5d248d2fbf0d5fdbaff +Subproject commit f59c5f5bce28b5a6179697efd4da3ea01c4cf41b From 460c3948fe288d2f33579b51af76c620f21a19d8 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 26 May 2022 14:29:07 +0200 Subject: [PATCH 11/25] [snarkyjs] convert pickles proof to tx proof type --- .../snarky_js_bindings/lib/snarky_js_bindings_lib.ml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml index 7d7da009956..df24c5ce368 100644 --- a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml +++ b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml @@ -1714,15 +1714,19 @@ let pickles_compile (choices : pickles_rule_js Js.js_array Js.t) = (* TODO: get rid of Obj.magic, this should be an empty "H3.T" *) let prevs = Obj.magic [] in let statement = Zkapp_statement.(statement_js |> of_js |> to_constant) in - prover ?handler:None prevs statement |> Promise_js_helpers.to_js + let proof_promise = prover ?handler:None prevs statement in + proof_promise + |> Promise.map ~f:Pickles.Side_loaded.Proof.of_proof + |> Promise_js_helpers.to_js in prove in let rec to_js_provers : type a b c. (a, b, c, Zkapp_statement.Constant.t, proof Promise.t) Pickles.Provers.t - -> (zkapp_statement_js -> proof Promise_js_helpers.js_promise) list = - function + -> ( zkapp_statement_js + -> Pickles.Side_loaded.Proof.t Promise_js_helpers.js_promise ) + list = function | [] -> [] | p :: ps -> From d935d0f932655e7aa3440bed96f2ed995803265c Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 26 May 2022 18:19:05 +0200 Subject: [PATCH 12/25] [snarkyjs] enable verification of tx proofs in JS --- .../lib/snarky_js_bindings_lib.ml | 24 ++++++++++++++++++- .../test_module/simple-zkapp-mock-apply.js | 11 +++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml index df24c5ce368..6ac81091ecd 100644 --- a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml +++ b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml @@ -1570,7 +1570,7 @@ module Zkapp_statement = struct val atParty = to_js_field at_party end - let of_js (statement : zkapp_statement_js) = + let of_js (statement : zkapp_statement_js) : t = { transaction = of_js_field statement##.transaction ; at_party = of_js_field statement##.atParty } @@ -1585,6 +1585,11 @@ module Zkapp_statement = struct { transaction = Field.constant transaction ; at_party = Field.constant at_party } + + let of_js (statement : zkapp_statement_js) : t = + { transaction = of_js_field statement##.transaction |> to_unchecked + ; at_party = of_js_field statement##.atParty |> to_unchecked + } end end @@ -2187,6 +2192,21 @@ module Ledger = struct | Proof _ | None_given -> () ) + let verify_party_proof (statement : zkapp_statement_js) + (proof : Js.js_string Js.t) (vk : Js.js_string Js.t) = + let statement = Zkapp_statement.Constant.of_js statement in + let proof = + Result.ok_or_failwith + (Pickles.Side_loaded.Proof.of_base64 (Js.to_string proof)) + in + let vk = + Pickles.Side_loaded.Verification_key.of_base58_check_exn (Js.to_string vk) + in + Pickles.Side_loaded.verify_promise + [ (vk, statement, proof) ] + ~value_to_field_elements:Zkapp_statement.Constant.to_field_elements + |> Promise.map ~f:Js.bool |> Promise_js_helpers.to_js + let public_key_to_string (pk : public_key) : Js.js_string Js.t = pk |> public_key |> Signature_lib.Public_key.Compressed.to_base58_check |> Js.string @@ -2325,6 +2345,8 @@ module Ledger = struct static_method "signFieldElement" sign_field_element ; static_method "signFeePayer" sign_fee_payer ; static_method "signOtherParty" sign_other_party ; + static_method "verifyPartyProof" verify_party_proof ; + static_method "publicKeyToString" public_key_to_string ; static_method "publicKeyOfString" public_key_of_string ; static_method "privateKeyToString" private_key_to_string ; diff --git a/src/lib/snarky_js_bindings/test_module/simple-zkapp-mock-apply.js b/src/lib/snarky_js_bindings/test_module/simple-zkapp-mock-apply.js index 8a062bca5f6..b32c0452157 100644 --- a/src/lib/snarky_js_bindings/test_module/simple-zkapp-mock-apply.js +++ b/src/lib/snarky_js_bindings/test_module/simple-zkapp-mock-apply.js @@ -11,6 +11,7 @@ import { Mina, signFeePayer, Permissions, + Ledger, } from "snarkyjs"; import { tic, toc } from "./tictoc.js"; @@ -90,6 +91,16 @@ partiesJsonInitialize = signFeePayer(partiesJsonInitialize, senderKey, { }); toc(); +// verify the proof +tic("verify transaction proof"); +let parties = JSON.parse(partiesJsonInitialize); +let proof = parties.otherParties[0].authorization.proof; +let statement = Ledger.transactionStatement(partiesJsonInitialize, 0); +let ok = await Ledger.verifyPartyProof(statement, proof, verificationKey.data); +toc(); +console.log("did proof verify?", ok); +if (!ok) console.log("proof didn't verify"); + tic("apply initialize transaction"); Local.applyJsonTransaction(partiesJsonInitialize); toc(); From 07d8e9fb3d49a058371de79afd8e65efadbd975e Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 26 May 2022 20:24:19 +0200 Subject: [PATCH 13/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index 812b31dbda4..d1d982ae583 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit 812b31dbda4effa7b7138331910545f938bce008 +Subproject commit d1d982ae5839be96d0d0d6ac378ff2a8b33e9bf5 From 8e6eba736b1eeb9d13e65c1708272c6fbe6936e8 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 26 May 2022 20:27:36 +0200 Subject: [PATCH 14/25] also verify intg test proof in JS --- .../snarky_js_bindings/test_module/simple-zkapp.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/test_module/simple-zkapp.js b/src/lib/snarky_js_bindings/test_module/simple-zkapp.js index 88bd4363cd1..3147d5df3de 100644 --- a/src/lib/snarky_js_bindings/test_module/simple-zkapp.js +++ b/src/lib/snarky_js_bindings/test_module/simple-zkapp.js @@ -11,6 +11,7 @@ import { shutdown, addCachedAccount, Mina, + Ledger, } from "snarkyjs"; await isReady; @@ -91,7 +92,7 @@ if (command === "update") { publicKey: zkappAddress, zkapp: { appState: [initialState, 0, 0, 0, 0, 0, 0, 0] }, }); - await SimpleZkapp.compile(zkappAddress); + let { verificationKey } = await SimpleZkapp.compile(zkappAddress); let transaction = await Mina.transaction(() => { new SimpleZkapp(zkappAddress).update(Field(2)); }); @@ -110,6 +111,16 @@ if (command === "update") { { parties, feePayer }, feePayerKeyBase58 ); + parties = JSON.parse(data.parties); + let proof = parties.otherParties[0].authorization.proof; + let statement = Ledger.transactionStatement(data.parties, 0); + let ok = await Ledger.verifyPartyProof( + statement, + proof, + verificationKey.data + ); + if (!ok) throw Error("verification failed"); + console.log(data.parties); } From abb4bdf995321b0579978dcc2f2bf554be72168e Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 26 May 2022 20:55:08 +0200 Subject: [PATCH 15/25] revert later: add debugging in verifier.common --- src/lib/verifier/common.ml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib/verifier/common.ml b/src/lib/verifier/common.ml index 8e2ea3689e3..07f62968474 100644 --- a/src/lib/verifier/common.ml +++ b/src/lib/verifier/common.ml @@ -98,6 +98,22 @@ let check : ; at_party = (at_party :> Snark_params.Tick.Field.t) } in + let logger = Logger.create () in + [%log warn] + "Verifier.Common.check\n\ + Transaction statement: $statement\n\ + Proof: $proof\n\ + Verification key: $vk" + ~metadata: + [ ("statement", Zkapp_statement.to_yojson stmt) + ; ( "proof" + , `String (Pickles.Side_loaded.Proof.to_base64 pi) + ) + ; ( "vk" + , `String + (Pickles.Side_loaded.Verification_key + .to_base58_check vk ) ) + ] ; Some (vk, stmt, pi) ) ) in let v : User_command.Valid.t = From c6f22efbfaf0a0c06175c05fb2876fa132798633 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 27 May 2022 22:02:04 +0200 Subject: [PATCH 16/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index f70f8a216d6..6aa176f450c 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit f70f8a216d610037c7c450e8232a4cbdd2e90d1e +Subproject commit 6aa176f450ced9cd710aa8831753d67594620d2d From 3b8fec1bc74d44de0abde4250eecc024f0b5d342 Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 1 Jun 2022 08:41:47 +0200 Subject: [PATCH 17/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index 6aa176f450c..2e2c4e6a2ff 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit 6aa176f450ced9cd710aa8831753d67594620d2d +Subproject commit 2e2c4e6a2ff9b39a1ed32a611429dfe922b056e1 From 017807b8b73d059596ffc7ba51e64bb7e202033c Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 3 Jun 2022 09:58:18 +0200 Subject: [PATCH 18/25] [snarkyjs] add methods to Bool --- src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml index 334790563a1..684ea20c826 100644 --- a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml +++ b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml @@ -557,6 +557,8 @@ let () = method_ name (fun this (y : As_bool.t) : bool_class Js.t -> mk (f this##.value (As_bool.value y)) ) in + Js.Unsafe.set bool_class (Js.string "true") (mk Boolean.true_) ; + Js.Unsafe.set bool_class (Js.string "false") (mk Boolean.false_) ; method_ "toField" (fun this : field_class Js.t -> new%js field_constr (As_field.of_field (this##.value :> Field.t)) ) ; add_op1 "not" Boolean.not ; @@ -564,6 +566,9 @@ let () = add_op2 "or" Boolean.( ||| ) ; method_ "assertEquals" (fun this (y : As_bool.t) : unit -> Boolean.Assert.( = ) this##.value (As_bool.value y) ) ; + method_ "assertTrue" (fun this : unit -> Boolean.Assert.is_true this##.value) ; + method_ "assertFalse" (fun this : unit -> + Boolean.Assert.( = ) this##.value Boolean.false_ ) ; add_op2 "equals" equal ; method_ "toBoolean" (fun this : bool Js.t -> match (this##.value :> Field.t) with From c3f0511107e6ddc64b7498028ea78c3d7ce3921c Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 3 Jun 2022 12:05:45 +0200 Subject: [PATCH 19/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index 2e2c4e6a2ff..dab7ed9aa93 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit 2e2c4e6a2ff9b39a1ed32a611429dfe922b056e1 +Subproject commit dab7ed9aa93fe95fb88f1b184195de252046704c From 065d068f90cc11e63eb4097b8d4f3facdad5128d Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 3 Jun 2022 16:41:56 +0200 Subject: [PATCH 20/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index dab7ed9aa93..ad8dd5f4821 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit dab7ed9aa93fe95fb88f1b184195de252046704c +Subproject commit ad8dd5f4821bf8a38055d0fda3cae56faff793b7 From c25a42767a21181fc600a7b8bbcbabc8317dde90 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 3 Jun 2022 18:38:04 +0200 Subject: [PATCH 21/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index d1d982ae583..08c35173fa5 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit d1d982ae5839be96d0d0d6ac378ff2a8b33e9bf5 +Subproject commit 08c35173fa5e8fae885ea17c5e798f484f63bc10 From b7b41c56afcc368469a7c7e9efa673a326c5ecb0 Mon Sep 17 00:00:00 2001 From: Gregor Date: Sun, 5 Jun 2022 09:03:00 +0200 Subject: [PATCH 22/25] Revert "revert later: add debugging in verifier.common" This reverts commit abb4bdf995321b0579978dcc2f2bf554be72168e. --- src/lib/verifier/common.ml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/lib/verifier/common.ml b/src/lib/verifier/common.ml index 07f62968474..8e2ea3689e3 100644 --- a/src/lib/verifier/common.ml +++ b/src/lib/verifier/common.ml @@ -98,22 +98,6 @@ let check : ; at_party = (at_party :> Snark_params.Tick.Field.t) } in - let logger = Logger.create () in - [%log warn] - "Verifier.Common.check\n\ - Transaction statement: $statement\n\ - Proof: $proof\n\ - Verification key: $vk" - ~metadata: - [ ("statement", Zkapp_statement.to_yojson stmt) - ; ( "proof" - , `String (Pickles.Side_loaded.Proof.to_base64 pi) - ) - ; ( "vk" - , `String - (Pickles.Side_loaded.Verification_key - .to_base58_check vk ) ) - ] ; Some (vk, stmt, pi) ) ) in let v : User_command.Valid.t = From d5481868f397a156e185d2024433ab4162c663e3 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 7 Jun 2022 14:27:36 +0200 Subject: [PATCH 23/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index 08c35173fa5..19d3142102d 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit 08c35173fa5e8fae885ea17c5e798f484f63bc10 +Subproject commit 19d3142102df22d8f2776d5aa3dca401f9052180 From 502c31fad433bdf73b030ca5fcb9278a95b3e67b Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 7 Jun 2022 14:32:39 +0200 Subject: [PATCH 24/25] bump snarkyjs --- src/lib/snarky_js_bindings/snarkyjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/snarky_js_bindings/snarkyjs b/src/lib/snarky_js_bindings/snarkyjs index 19d3142102d..902462c594d 160000 --- a/src/lib/snarky_js_bindings/snarkyjs +++ b/src/lib/snarky_js_bindings/snarkyjs @@ -1 +1 @@ -Subproject commit 19d3142102df22d8f2776d5aa3dca401f9052180 +Subproject commit 902462c594df23423e938299036f987afd5dfebd From 8bf6160a963b1f8c73409ff3e419dcd3adcafb34 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 7 Jun 2022 17:04:12 +0200 Subject: [PATCH 25/25] adress PR feedback --- src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml | 3 +-- .../snarky_js_bindings/test_module/simple-zkapp-mock-apply.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml index f70d1650e72..4608189cec2 100644 --- a/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml +++ b/src/lib/snarky_js_bindings/lib/snarky_js_bindings_lib.ml @@ -1764,8 +1764,7 @@ let pickles_compile (choices : pickles_rule_js Js.js_array Js.t) = (* TODO: get rid of Obj.magic, this should be an empty "H3.T" *) let prevs = Obj.magic [] in let statement = Zkapp_statement.(statement_js |> of_js |> to_constant) in - let proof_promise = prover ?handler:None prevs statement in - proof_promise + prover ?handler:None prevs statement |> Promise.map ~f:Pickles.Side_loaded.Proof.of_proof |> Promise_js_helpers.to_js in diff --git a/src/lib/snarky_js_bindings/test_module/simple-zkapp-mock-apply.js b/src/lib/snarky_js_bindings/test_module/simple-zkapp-mock-apply.js index b32c0452157..845a8ab19ee 100644 --- a/src/lib/snarky_js_bindings/test_module/simple-zkapp-mock-apply.js +++ b/src/lib/snarky_js_bindings/test_module/simple-zkapp-mock-apply.js @@ -99,7 +99,7 @@ let statement = Ledger.transactionStatement(partiesJsonInitialize, 0); let ok = await Ledger.verifyPartyProof(statement, proof, verificationKey.data); toc(); console.log("did proof verify?", ok); -if (!ok) console.log("proof didn't verify"); +if (!ok) throw Error("proof didn't verify"); tic("apply initialize transaction"); Local.applyJsonTransaction(partiesJsonInitialize);