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

[20241217] merge compatible into develop #16436

Merged
merged 11 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/app/zkapps_examples/tokens/zkapps_tokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ module Rules = struct
*)
Boolean.Assert.any [ proof_must_verify; zero_total ] ;
let proof =
exists (Typ.Internal.ref ()) ~request:(fun () ->
exists (Typ.prover_value ()) ~request:(fun () ->
let proof_must_verify =
As_prover.read Boolean.typ proof_must_verify
in
Expand All @@ -494,7 +494,7 @@ module Rules = struct
; (* dummy to avoid pickles bug *)
{ public_input = recursive_input
; proof =
exists (Typ.Internal.ref ()) ~compute:(fun () ->
exists (Typ.prover_value ()) ~compute:(fun () ->
Lazy.force dummy_proof )
; proof_must_verify = Boolean.false_
}
Expand Down Expand Up @@ -567,7 +567,7 @@ module Rules = struct
*)
Boolean.Assert.any [ proof_must_verify; zero_total ] ;
let proof =
exists (Typ.Internal.ref ()) ~request:(fun () ->
exists (Typ.prover_value ()) ~request:(fun () ->
let proof_must_verify =
As_prover.read Boolean.typ proof_must_verify
in
Expand All @@ -581,7 +581,7 @@ module Rules = struct
; (* dummy to avoid pickles bug *)
{ public_input = recursive_input
; proof =
exists (Typ.Internal.ref ()) ~compute:(fun () ->
exists (Typ.prover_value ()) ~compute:(fun () ->
Lazy.force dummy_proof )
; proof_must_verify = Boolean.false_
}
Expand Down
10 changes: 6 additions & 4 deletions src/app/zkapps_examples/zkapps_examples.ml
Original file line number Diff line number Diff line change
Expand Up @@ -454,20 +454,22 @@ let exists_deferred ?request:req ?compute typ =
(* 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
let requested = exists ?request:req ?compute (Typ.prover_value ()) 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 () ) ) ;
Deferred.upon
(As_prover.read (Typ.prover_value ()) 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 ) )
Option.value_exn @@ Deferred.peek
@@ As_prover.read (Typ.prover_value ()) requested ) )

type return_type =
{ account_update : Account_update.Body.t
Expand Down
1 change: 0 additions & 1 deletion src/dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
(package (name heap_usage))
(package (name hex))
(package (name immutable_array))
(package (name inline_test_quiet_logs))
(package (name integers_stubs_js))
(package (name integration_test_local_engine))
(package (name integration_test_lib))
Expand Down
8 changes: 4 additions & 4 deletions src/lib/blockchain_snark/blockchain_snark_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ let%snarkydef_ step ~(logger : Logger.t)
, previous_state_body_hash ) =
let%bind prev_state_ref =
with_label __LOC__ (fun () ->
exists (Typ.Internal.ref ()) ~request:(As_prover.return Prev_state) )
exists (Typ.prover_value ()) ~request:(As_prover.return Prev_state) )
in
let%bind t =
with_label __LOC__ (fun () ->
exists
(Protocol_state.typ ~constraint_constants)
~compute:(As_prover.Ref.get prev_state_ref) )
~compute:(As_prover.read (Typ.prover_value ()) prev_state_ref) )
in
let%map previous_state_hash, body = Protocol_state.hash_checked t in
let previous_blockchain_proof_input =
Expand Down Expand Up @@ -366,10 +366,10 @@ let%snarkydef_ step ~(logger : Logger.t)
with_label __LOC__ (fun () -> Boolean.Assert.any [ is_base_case; success ])
in
let%bind previous_blockchain_proof =
exists (Typ.Internal.ref ()) ~request:(As_prover.return Prev_state_proof)
exists (Typ.prover_value ()) ~request:(As_prover.return Prev_state_proof)
in
let%map txn_snark_proof =
exists (Typ.Internal.ref ()) ~request:(As_prover.return Txn_snark_proof)
exists (Typ.prover_value ()) ~request:(As_prover.return Txn_snark_proof)
in
( { Pickles.Inductive_rule.Previous_proof_statement.public_input =
previous_blockchain_proof_input
Expand Down
9 changes: 5 additions & 4 deletions src/lib/mina_base/account.ml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ type var =
, Timing.var
, Permissions.Checked.t
(* TODO: This is a hack that lets us avoid unhashing zkApp accounts when we don't need to *)
, Field.Var.t * Zkapp_account.t option As_prover.Ref.t )
, Field.Var.t * Zkapp_account.t option Typ.prover_value )
Poly.t

let identifier_of_var ({ public_key; token_id; _ } : var) =
Expand Down Expand Up @@ -461,12 +461,13 @@ let typ' zkapp =

let typ : (var, value) Typ.t =
let zkapp :
( Field.Var.t * Zkapp_account.t option As_prover.Ref.t
( Field.Var.t * Zkapp_account.t option Typ.prover_value
, Zkapp_account.t option )
Typ.t =
let account :
(Zkapp_account.t option As_prover.Ref.t, Zkapp_account.t option) Typ.t =
Typ.Internal.ref ()
(Zkapp_account.t option Typ.prover_value, Zkapp_account.t option) Typ.t
=
Typ.prover_value ()
in
Typ.(Field.typ * account)
|> Typ.transport ~there:(fun x -> (hash_zkapp_account_opt x, x)) ~back:snd
Expand Down
8 changes: 0 additions & 8 deletions src/lib/mina_base/account_update.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1050,10 +1050,6 @@ module Preconditions = struct
type t = V.var
end

module Int_as_prover_ref = struct
type t = int As_prover.Ref.t
end

type t =
{ network : Zkapp_precondition.Protocol_state.Checked.t
; account : Account_precondition.Checked.t
Expand Down Expand Up @@ -1440,10 +1436,6 @@ module Body = struct
type t = V.var
end

module Int_as_prover_ref = struct
type t = int As_prover.Ref.t
end

type t =
{ public_key : Public_key.Compressed.var
; token_id : Token_id.Checked.t
Expand Down
29 changes: 16 additions & 13 deletions src/lib/mina_base/data_as_hash.ml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
open Snark_params
open Tick

type 'a t = Field.Var.t * 'a As_prover.Ref.t
type 'a t = Field.Var.t * 'a Typ.prover_value

let hash (x, _) = x

let ref (_, x) = x
let prover_value (_, x) = x

let typ ~hash =
Typ.transport
Typ.(Field.typ * Internal.ref ())
Typ.(Field.typ * prover_value ())
~there:(fun s -> (hash s, s))
~back:(fun (_, s) -> s)

let optional_typ ~hash ~non_preimage ~dummy_value =
Typ.transport
Typ.(Field.typ * Internal.ref ())
Typ.(Field.typ * prover_value ())
~there:(function
| None -> (non_preimage, dummy_value) | Some s -> (hash s, s) )
~back:(fun (_, s) -> Some s)

let lazy_optional_typ ~hash ~non_preimage ~dummy_value =
Typ.transport
Typ.(Field.typ * Internal.ref ())
Typ.(Field.typ * prover_value ())
~there:(function
| None -> (Lazy.force non_preimage, dummy_value) | Some s -> (hash s, s)
)
Expand All @@ -33,16 +33,19 @@ let to_input (x, _) = Random_oracle_input.Chunked.field x
let if_ b ~then_ ~else_ =
let open Run in
let hash = Field.if_ b ~then_:(fst then_) ~else_:(fst else_) in
let ref =
As_prover.Ref.create
As_prover.(
fun () ->
let ref = if read Boolean.typ b then snd then_ else snd else_ in
As_prover.Ref.get ref)
let prover_value =
exists (Typ.prover_value ())
~compute:
As_prover.(
fun () ->
let prover_value =
if read Boolean.typ b then snd then_ else snd else_
in
read (Typ.prover_value ()) prover_value)
in
(hash, ref)
(hash, prover_value)

let make_unsafe hash ref : 'a t = (hash, ref)
let make_unsafe hash prover_value : 'a t = (hash, prover_value)

module As_record = struct
(* it's OK that hash is a Field.t (not a var), bc this is just annotation for the deriver *)
Expand Down
6 changes: 3 additions & 3 deletions src/lib/mina_base/data_as_hash.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open Snark_params.Tick
(* Use the hash representing x *) ...
let%bind () =
as_prover As_prover.(
let%map x = As_prover.Ref.get (Data_as_hash.ref x) in
let%map x = As_prover.read (Typ.prover_value ()) (Data_as_hash.prover_value x) in
printf "%s\n" (Foo.to_string x)
)
in
Expand All @@ -26,7 +26,7 @@ type 'value t

val hash : _ t -> Field.Var.t

val ref : 'value t -> 'value As_prover.Ref.t
val prover_value : 'value t -> 'value Typ.prover_value

val typ : hash:('value -> Field.t) -> ('value t, 'value) Typ.t

Expand All @@ -46,7 +46,7 @@ val to_input : _ t -> Field.Var.t Random_oracle_input.Chunked.t

val if_ : Boolean.var -> then_:'value t -> else_:'value t -> 'value t

val make_unsafe : Field.Var.t -> 'value As_prover.Ref.t -> 'value t
val make_unsafe : Field.Var.t -> 'value Typ.prover_value -> 'value t

module As_record : sig
type 'a t = { data : 'a; hash : Field.t } [@@deriving annot, fields]
Expand Down
8 changes: 4 additions & 4 deletions src/lib/mina_base/prover_value.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
open Snark_params.Tick.Run

type 'a t = 'a As_prover.Ref.t
type 'a t = 'a Typ.prover_value

let get = As_prover.Ref.get
let get x = As_prover.read (Typ.prover_value ()) x

let create = As_prover.Ref.create
let create compute = exists (Typ.prover_value ()) ~compute

let if_ b ~then_ ~else_ =
create (fun () ->
get (if Impl.As_prover.read Boolean.typ b then then_ else else_) )

let map t ~f = create (fun () -> f (get t))

let typ = Typ.Internal.ref
let typ = Typ.prover_value
4 changes: 2 additions & 2 deletions src/lib/pickles/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ struct
; main =
(fun { public_input = () } ->
let dummy_proof =
As_prover.Ref.create (fun () ->
exists (Typ.prover_value ()) ~compute:(fun () ->
Proof.dummy Nat.N2.n Nat.N2.n Nat.N2.n ~domain_log2:15 )
in
Promise.return
Expand Down Expand Up @@ -1396,7 +1396,7 @@ struct
; main =
(fun { public_input = () } ->
let proof =
exists (Typ.Internal.ref ()) ~request:(fun () -> Proof)
exists (Typ.prover_value ()) ~request:(fun () -> Proof)
in
Promise.return
{ Inductive_rule.previous_proof_statements =
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/inductive_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end
module Previous_proof_statement = struct
type ('prev_var, 'width) t =
{ public_input : 'prev_var
; proof : ('width, 'width) Proof.t Impls.Step.As_prover.Ref.t
; proof : ('width, 'width) Proof.t Impls.Step.Typ.prover_value
; proof_must_verify : B.t
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/inductive_rule.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end
module Previous_proof_statement : sig
type ('prev_var, 'width) t =
{ public_input : 'prev_var
; proof : ('width, 'width) Proof.t Impls.Step.As_prover.Ref.t
; proof : ('width, 'width) Proof.t Impls.Step.Typ.prover_value
; proof_must_verify : B.t
}

Expand Down
Loading