Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pickles async circuits #15084

Merged
merged 47 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1a2c7ed
Update snarky to expose callback-oriented helpers, use in pickles step
mrmr1993 Feb 11, 2024
8918371
WIP Pickles nearly compiling
mrmr1993 Feb 11, 2024
d975e61
Pickles compiles!
mrmr1993 Feb 11, 2024
38a7848
Fixup default `Pickles.compile` to use non-async inductive rules
mrmr1993 Feb 11, 2024
08165df
Add `Pickles.compile_async`
mrmr1993 Feb 11, 2024
95d6757
Fixup compilation errors (nearly)
mrmr1993 Feb 12, 2024
0c59d1f
make test_fix_domains compile
mitschabaude Feb 20, 2024
7463898
adapt tx snark intf
mitschabaude Feb 20, 2024
1d7f4c2
adapt some tests
mitschabaude Feb 20, 2024
5a99295
adapt some methods which already return a Deferred
mitschabaude Feb 20, 2024
8ea7cfd
fixup zkapp examples build
mitschabaude Feb 20, 2024
40c10bb
missing dune file change
mitschabaude Feb 20, 2024
8e75713
progress: fix_domains runs circuits in order
mitschabaude Feb 22, 2024
d3e025b
work towards running circuits for key generation in sequence
mitschabaude Feb 22, 2024
eebd9a8
run stuff in sequence, but for some reason it doesn't work yet
mitschabaude Feb 22, 2024
114a1d9
fix locking
mitschabaude Feb 23, 2024
402b277
simplify: reuse promise for entire domain vector
mitschabaude Feb 23, 2024
021d8d5
add debugging
mitschabaude Feb 23, 2024
fb1836e
reuse cs generated for key header
mitschabaude Feb 23, 2024
04e0e39
simplify, add debugging
mitschabaude Feb 23, 2024
9ff3cda
reuse sys for wrap keygen
mitschabaude Feb 23, 2024
1e366c5
fix blockchain snark - move known_wrap_keys out of circuit
mitschabaude Feb 23, 2024
8dae1de
simplify: encode wrap keys in main promise
mitschabaude Feb 23, 2024
4bb7976
clean up known wrap key
mitschabaude Feb 23, 2024
41fde71
undo unnecessary refactors
mitschabaude Feb 23, 2024
e8880e3
remove debug logs
mitschabaude Feb 23, 2024
2f6d07e
minimal change to make it work
mitschabaude Feb 23, 2024
61f04c5
fix promise map call semantics
mitschabaude Feb 23, 2024
5f22f96
promise: fix compiler warnings
mitschabaude Feb 23, 2024
69803a7
promise: add clarifying comment for where we don't support ocaml calls
mitschabaude Feb 23, 2024
71c2931
cleanup by reusing deferred_of_promise
mitschabaude Feb 23, 2024
6424eb7
make create_trivial_snapp return deferred vk
mitschabaude Feb 26, 2024
e3d9d02
adapt tx snark tests
mitschabaude Feb 26, 2024
daa71cb
start fixing snark profiler lib
mitschabaude Feb 26, 2024
ec91a50
fixup heap usage app
mitschabaude Feb 26, 2024
b13f95a
fixup test_executive
mitschabaude Feb 26, 2024
5650cf8
fix test failures by sequentializing logic
mitschabaude Feb 26, 2024
b5e4ecc
I don't understand why this fixes the transaction snark profiler
mitschabaude Feb 26, 2024
615de78
remove log_step and log_wrap
mitschabaude Feb 26, 2024
c3b285b
Merge branch 'o1js-main' into feature/async-pickles-circuits
mitschabaude Feb 27, 2024
bcbd526
address feedback pt 1
mitschabaude Mar 4, 2024
95c1215
get rid of early digest exception
mitschabaude Mar 4, 2024
d912eeb
address feedback pt 2
mitschabaude Mar 4, 2024
f28432a
Merge branch 'o1js-main' into feature/async-pickles-circuits
mitschabaude Mar 5, 2024
b031a18
bump snarky
mitschabaude Mar 5, 2024
2bc5964
Installing Git LFS at runtime on nixOS container
SanabriaRusso Mar 5, 2024
af4349d
revert later: workaround for binary files diff
mitschabaude Mar 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/zkapp_metrics.sh
mitschabaude marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ echo "Running heap usage app"
echo "Building zkapp limits app"
make zkapp_limits

echo "Running heap usage app"
echo "Running zkapp limits app"
./_build/default/src/app/zkapp_limits/zkapp_limits.exe
3 changes: 2 additions & 1 deletion src/app/cli/src/init/transaction_snark_profiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ let run ~user_command_profiler ~zkapp_profiler num_transactions ~max_num_updates
let print n msg = printf !"[%i] %s\n%!" n msg in
if use_zkapps then (
let ledger, transactions =
create_ledger_and_zkapps ?min_num_updates ~max_num_updates ()
Async.Thread_safe.block_on_async_exn (fun () ->
create_ledger_and_zkapps ?min_num_updates ~max_num_updates () )
in
Parallel.init_master () ;
let verifier =
Expand Down
6 changes: 4 additions & 2 deletions src/app/heap_usage/values.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ let account : Mina_base.Account.t =
let zkapp_command =
let num_updates = 16 in
let _ledger, zkapp_commands =
Snark_profiler_lib.create_ledger_and_zkapps ~min_num_updates:num_updates
~num_proof_updates:num_updates ~max_num_updates:num_updates ()
Async.Thread_safe.block_on_async_exn (fun () ->
Snark_profiler_lib.create_ledger_and_zkapps ~min_num_updates:num_updates
~num_proof_updates:num_updates ~max_num_updates:num_updates () )
in
List.hd_exn zkapp_commands

Expand Down Expand Up @@ -65,6 +66,7 @@ let verification_key =
Transaction_snark.For_tests.create_trivial_snapp
~constraint_constants:Genesis_constants.Constraint_constants.compiled ()
in
let vk = Async.Thread_safe.block_on_async_exn (fun () -> vk) in
With_hash.data vk

let applied = Mina_base.Transaction_status.Applied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ let () =
(Time.Span.to_string_hum (Time.diff after before))

let () =
Lazy.force Blockchain_snark_instance.Proof.verification_key
Async.Thread_safe.block_on_async_exn (fun () ->
Lazy.force Blockchain_snark_instance.Proof.verification_key )
|> Pickles.Verification_key.to_yojson |> Yojson.Safe.to_string
|> Format.print_string
5 changes: 3 additions & 2 deletions src/app/test_executive/hard_fork.ml
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
; authorization_kind = Signature
}
in
Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec
Async.Thread_safe.block_on_async_exn (fun () ->
Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec )
in

let%bind zkapp_command_update_vk_proof, zkapp_command_update_vk_impossible =
Expand Down
7 changes: 4 additions & 3 deletions src/app/test_executive/peers_reliability_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
}
in
return
@@ Transaction_snark.For_tests.deploy_snapp
~constraint_constants:(Network.constraint_constants network)
parties_spec
@@ Async.Thread_safe.block_on_async_exn (fun () ->
Transaction_snark.For_tests.deploy_snapp
~constraint_constants:(Network.constraint_constants network)
parties_spec )
in
let%bind () =
send_zkapp ~logger
Expand Down
11 changes: 8 additions & 3 deletions src/app/test_executive/verification_key_update.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
constraint_constants )
~choices:(fun ~self:_ -> [ Trivial_rule2.rule ])
in
let vk1 = Pickles.Side_loaded.Verification_key.of_compiled tag1 in
let vk2 = Pickles.Side_loaded.Verification_key.of_compiled tag2 in
let%bind.Async.Deferred vk1 =
Pickles.Side_loaded.Verification_key.of_compiled tag1
in
let%bind.Async.Deferred vk2 =
Pickles.Side_loaded.Verification_key.of_compiled tag2
in
let%bind.Async.Deferred account_update1, _ =
trivial_prover1 ~handler:Trivial_rule1.handler ()
in
Expand Down Expand Up @@ -216,7 +220,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
; authorization_kind = Signature
}
in
Transaction_snark.For_tests.deploy_snapp ~constraint_constants spec
Async.Thread_safe.block_on_async_exn (fun () ->
Transaction_snark.For_tests.deploy_snapp ~constraint_constants spec )
in
let call_forest_to_zkapp ~call_forest ~nonce : Zkapp_command.t =
let memo = Signed_command_memo.empty in
Expand Down
5 changes: 3 additions & 2 deletions src/app/test_executive/zkapps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
}
in
return
@@ Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec
@@ Async.Thread_safe.block_on_async_exn (fun () ->
Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec )
in
let%bind.Deferred zkapp_command_update_permissions, permissions_updated =
(* construct a Zkapp_command.t, similar to zkapp_test_transaction update-permissions *)
Expand Down
20 changes: 12 additions & 8 deletions src/app/test_executive/zkapps_timing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
Token_id.default
in

( Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec
( Async.Thread_safe.block_on_async_exn (fun () ->
Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec )
, timing_account_id
, zkapp_command_spec.snapp_update
, zkapp_keypair )
Expand Down Expand Up @@ -150,8 +151,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
}
in
return
@@ Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec
@@ Async.Thread_safe.block_on_async_exn (fun () ->
Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec )
in
(* Create a timed account that with initial liquid balance being 0, and vesting 1 mina at each slot.
This account would be used to test the edge case of vesting. See `zkapp_command_transfer_from_third_timed_account`
Expand Down Expand Up @@ -200,8 +202,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
(zkapp_keypair.public_key |> Signature_lib.Public_key.compress)
Token_id.default
in
( Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec
( Async.Thread_safe.block_on_async_exn (fun () ->
Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec )
, timing_account_id
, zkapp_keypair )
in
Expand Down Expand Up @@ -242,8 +245,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
; authorization_kind = Signature
}
in
Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec
Async.Thread_safe.block_on_async_exn (fun () ->
Transaction_snark.For_tests.deploy_snapp ~constraint_constants
zkapp_command_spec )
in
let%bind zkapp_command_transfer_from_timed_account =
let open Mina_base in
Expand Down
9 changes: 5 additions & 4 deletions src/app/zkapp_test_transaction/lib/commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ let gen_proof ?(zkapp_account = None) (zkapp_command : Zkapp_command.t) =
(Account.create id Currency.Balance.(of_mina_int_exn 1_000))
|> Or_error.ok_exn
in
let _v =
Option.value_map zkapp_account ~default:() ~f:(fun pk ->
let open Async.Deferred.Let_syntax in
let%bind () =
Option.value_map zkapp_account ~default:(Deferred.return ()) ~f:(fun pk ->
let `VK vk, `Prover _ = Lazy.force vk_and_prover in
let%map vk = vk in
let id = Account_id.create pk Token_id.default in
Ledger.get_or_create_account ledger id
{ (Account.create id Currency.Balance.(of_mina_int_exn 1_000)) with
Expand Down Expand Up @@ -122,7 +124,6 @@ let gen_proof ?(zkapp_account = None) (zkapp_command : Zkapp_command.t) =
, zkapp_command )
]
in
let open Async.Deferred.Let_syntax in
let module T = Transaction_snark.Make (struct
let constraint_constants = constraint_constants

Expand Down Expand Up @@ -368,7 +369,7 @@ let create_zkapp_account ~debug ~sender ~sender_nonce ~fee ~fee_payer
; authorization_kind = Signature
}
in
let zkapp_command =
let%bind zkapp_command =
Transaction_snark.For_tests.deploy_snapp
~permissions:Permissions.user_default ~constraint_constants spec
in
Expand Down
4 changes: 3 additions & 1 deletion src/app/zkapps_examples/test/actions/actions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ let%test_module "Actions test" =

module P = (val p_module)

let vk = Pickles.Side_loaded.Verification_key.of_compiled tag
let vk =
Async.Thread_safe.block_on_async_exn (fun () ->
Pickles.Side_loaded.Verification_key.of_compiled tag )

module Deploy_account_update = struct
let account_update_body : Account_update.Body.t =
Expand Down
4 changes: 3 additions & 1 deletion src/app/zkapps_examples/test/add_events/add_events.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ let%test_module "Add events test" =

module P = (val p_module)

let vk = Pickles.Side_loaded.Verification_key.of_compiled tag
let vk =
Async.Thread_safe.block_on_async_exn (fun () ->
Pickles.Side_loaded.Verification_key.of_compiled tag )

module Deploy_account_update = struct
let account_update_body : Account_update.Body.t =
Expand Down
3 changes: 2 additions & 1 deletion src/app/zkapps_examples/test/big_circuit/big_circuit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ let tag, _cache, _p_module, Pickles.Provers.[ prover ] =
[ Zkapps_big_circuit.rule ~num_constraints pk_compressed ] )

let vk : Side_loaded_verification_key.t =
Pickles.Side_loaded.Verification_key.of_compiled tag
Async.Thread_safe.block_on_async_exn (fun () ->
Pickles.Side_loaded.Verification_key.of_compiled tag )

let vk_hash = Mina_base.Verification_key_wire.digest_vk vk

Expand Down
4 changes: 3 additions & 1 deletion src/app/zkapps_examples/test/calls/calls.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ let%test_module "Composability test" =

module P = (val p_module)

let vk = Pickles.Side_loaded.Verification_key.of_compiled tag
let vk =
Async.Thread_safe.block_on_async_exn (fun () ->
Pickles.Side_loaded.Verification_key.of_compiled tag )

module Deploy_account_update = struct
let account_update_body : Account_update.Body.t =
Expand Down
4 changes: 3 additions & 1 deletion src/app/zkapps_examples/test/empty_update/empty_update.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ let tag, _, p_module, Pickles.Provers.[ prover ] =

module P = (val p_module)

let vk = Pickles.Side_loaded.Verification_key.of_compiled tag
let vk =
Async.Thread_safe.block_on_async_exn (fun () ->
Pickles.Side_loaded.Verification_key.of_compiled tag )

let account_update, () = Async.Thread_safe.block_on_async_exn prover

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ let%test_module "Initialize state test" =

module P = (val p_module)

let vk = Pickles.Side_loaded.Verification_key.of_compiled tag
let vk =
Async.Thread_safe.block_on_async_exn (fun () ->
Pickles.Side_loaded.Verification_key.of_compiled tag )

module Deploy_account_update = struct
let account_update_body : Account_update.Body.t =
Expand Down
4 changes: 3 additions & 1 deletion src/app/zkapps_examples/test/tokens/tokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ let%test_module "Tokens test" =

let owned_token_id = Account_id.derive_token_id ~owner:account_id

let vk = Lazy.force Zkapps_tokens.vk
let vk =
Async.Thread_safe.block_on_async_exn (fun () ->
Lazy.force Zkapps_tokens.vk )

let mint_to_keys = gen_keys ()

Expand Down
4 changes: 4 additions & 0 deletions src/app/zkapps_examples/tokens/zkapps_tokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,12 @@ module P = struct
let verification_key =
Lazy.bind p_module ~f:(fun (module P : Proof_intf) -> P.verification_key)

let verification_key_promise = lazy (failwith "not implemented")

let id = Lazy.bind p_module ~f:(fun (module P : Proof_intf) -> P.id)

let id_promise = lazy (failwith "not implemented")

let verify statements =
let module P : Proof_intf = (val Lazy.force p_module) in
P.verify statements
Expand Down
2 changes: 1 addition & 1 deletion src/app/zkapps_examples/tokens/zkapps_tokens.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ val tag :
Pickles.Tag.t
Lazy.t

val vk : Pickles.Side_loaded.Verification_key.t Lazy.t
val vk : Pickles.Side_loaded.Verification_key.t Async.Deferred.t Lazy.t

module P :
Pickles.Proof_intf
Expand Down
33 changes: 27 additions & 6 deletions src/app/zkapps_examples/zkapps_examples.ml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,27 @@ let dummy_constraints () =
(Kimchi_backend_common.Scalar_challenge.create x)
: Field.t * Field.t )

let exists_deferred ?request:req ?compute typ =
let open Snark_params.Tick.Run in
let open Async_kernel in
(* Set up a full Ivar, in case we are generating the constraint system. *)
let deferred = ref (Ivar.create_full ()) in
(* Request or compute the [Deferred.t] value. *)
let requested = exists ?request:req ?compute (Typ.Internal.ref ()) in
as_prover (fun () ->
(* If we are generating the witness, create a new Ivar.. *)
deferred := Ivar.create () ;
(* ..and fill it when the value we want to read resolves. *)
Deferred.upon (As_prover.Ref.get requested) (fun _ ->
Ivar.fill !deferred () ) ) ;
(* Await the [Deferred.t] if we're generating the witness, otherwise we
immediately bind over the filled Ivar and continue.
*)
Deferred.map (Ivar.read !deferred) ~f:(fun () ->
(* Retrieve the value by peeking in the known-resolved deferred. *)
exists typ ~compute:(fun () ->
Option.value_exn @@ Deferred.peek @@ As_prover.Ref.get requested ) )

type return_type =
{ account_update : Account_update.Body.t
; account_update_digest : Zkapp_command.Digest.Account_update.t
Expand Down Expand Up @@ -590,7 +611,7 @@ let compile :
, Zkapp_statement.t
, return_type Prover_value.t * auxiliary_var
, return_type * auxiliary_value )
H4_6.T(Pickles.Inductive_rule).t = function
H4_6.T(Pickles.Inductive_rule.Deferred).t = function
| [] ->
[]
| { identifier; prevs; main; feature_flags } :: choices ->
Expand All @@ -599,8 +620,8 @@ let compile :
; feature_flags
; main =
(fun { Pickles.Inductive_rule.public_input = () } ->
let vk_hash =
exists Field.typ ~compute:(fun () ->
let%map.Deferred vk_hash =
exists_deferred Field.typ ~compute:(fun () ->
Lazy.force @@ Option.value_exn !vk_hash )
in
let { Pickles.Inductive_rule.previous_proof_statements
Expand All @@ -612,7 +633,7 @@ let compile :
let public_output, account_update_tree =
to_account_update account_update_under_construction
in
{ previous_proof_statements
{ Pickles.Inductive_rule.previous_proof_statements
; public_output
; auxiliary_output = (account_update_tree, auxiliary_output)
} )
Expand All @@ -622,7 +643,7 @@ let compile :
go (choices ~self)
in
let tag, cache_handle, proof, provers =
Pickles.compile () ?self ?cache ?disk_keys ?override_wrap_domain
Pickles.compile_async () ?self ?cache ?disk_keys ?override_wrap_domain
~public_input:(Output Zkapp_statement.typ)
~auxiliary_typ:Typ.(Prover_value.typ () * auxiliary_typ)
~branches ~max_proofs_verified ~name ~constraint_constants ~choices
Expand All @@ -631,7 +652,7 @@ let compile :
vk_hash :=
Some
( lazy
( Zkapp_account.digest_vk
( Deferred.map ~f:Zkapp_account.digest_vk
@@ Pickles.Side_loaded.Verification_key.of_compiled tag ) )
in
let provers =
Expand Down
Loading