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

Reduce snarkyjs loading time - BERKELEY #13892

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9b7577f
Lightweight Network configuration and documentation (rampup).
shimkiv May 26, 2023
fa6d1e2
Update only genesis timestamp without complete overwrite.
shimkiv May 27, 2023
2a4d8d2
Readme update (issue with proof_level overriding via genesis ledger j…
shimkiv May 27, 2023
7196658
Update lightnet.mlh as per review
shimkiv Jun 2, 2023
4d991f3
Merge branch 'rampup' into lightweight-net-config-rampup
shimkiv Jun 2, 2023
2464cf4
Merge pull request #13341 from MinaProtocol/fix/wasm-build
mrmr1993 Jun 5, 2023
9aeb1b4
Merge branch 'rampup' into lightweight-net-config-rampup
deepthiskumar Jun 7, 2023
4e0b324
Merge pull request #13287 from MinaProtocol/lightweight-net-config-ra…
deepthiskumar Jun 7, 2023
f74bb2e
Merge remote-tracking branch 'origin/berkeley' into rampup
deepthiskumar Jun 16, 2023
cde9efa
updated genesis timestamp
vanarasiantonyswamy Jul 5, 2023
510bdfb
updated the UTC timestamp
vanarasiantonyswamy Jul 5, 2023
0ec65fb
Merge pull request #13522 from MinaProtocol/updateGenesisTimeStamp
deepthiskumar Jul 5, 2023
bfd1009
Empty commit to sign Berkeley 2.0.0rampup3
vanarasiantonyswamy Jul 5, 2023
867b242
fix(account_update.ml): modify verification_key_hash field to use cus…
MartinMinkov Jul 11, 2023
2c192f4
snarkyjs
mitschabaude Jul 14, 2023
f7dd759
Replayer, check snarked ledger hash, berkeley cron job
psteckler Jul 25, 2023
6a370dc
fix batch api version for all jobs
dkijania Jul 25, 2023
4a4caee
Update image, fix db name
psteckler Jul 25, 2023
38d73a6
Merge pull request #13717 from MinaProtocol/dkijania/fix_helm_chart_l…
stevenplatt Jul 25, 2023
2ec57da
Merge branch 'rampup' into feature/berkeley-replayer-cronjob-snarked-…
psteckler Jul 25, 2023
dab2d94
Next slot must not be an orphan
psteckler Jul 27, 2023
8d7b946
update cron image
psteckler Jul 27, 2023
ccf1e2b
Merge pull request #13715 from MinaProtocol/feature/berkeley-replayer…
psteckler Aug 3, 2023
872ef5c
Merge remote-tracking branch 'origin/berkeley' into merge/berk-rampup…
deepthiskumar Aug 13, 2023
8ee87dc
convert poseidon params from strings just once
mitschabaude Aug 16, 2023
3571448
Merge pull request #13859 from MinaProtocol/merge/berk-rampup-08/14
nholland94 Aug 16, 2023
d232a0d
don't compute dummy vk hash at the top level
mitschabaude Aug 16, 2023
78de73e
don't compute dummy tx at the top level
mitschabaude Aug 16, 2023
7d9fa28
evaluate pickles dummy stuff lazily
mitschabaude Aug 16, 2023
43a52a8
expose random oracle state to/from array
mitschabaude Aug 17, 2023
03756db
precompute and bundle prefix hash states
mitschabaude Aug 17, 2023
a0c7565
precompute a few remaining hash prefixes
mitschabaude Aug 17, 2023
bf992e0
create dummy proofs lazily
mitschabaude Aug 17, 2023
8f532f6
lazy zkapp uri hash
mitschabaude Aug 17, 2023
9629f0e
lazy coinbase hash at level 0
mitschabaude Aug 17, 2023
4f0b185
lazy forbidden shifted values
mitschabaude Aug 17, 2023
e7c4080
faster top level poseidon param conversion
mitschabaude Aug 17, 2023
4e43359
faster top level integer to field conversions
mitschabaude Aug 17, 2023
1faddeb
snarky
mitschabaude Aug 17, 2023
4b1a79a
snarkyjs
mitschabaude Aug 17, 2023
3fce81b
snarkyjs
mitschabaude Aug 17, 2023
96860a4
handle missing bindings (for stupid jest)
mitschabaude Aug 17, 2023
8259b20
simplify pickles dummy changes
mitschabaude Aug 18, 2023
b1af865
revert changes that cause vk change
mitschabaude Aug 18, 2023
f473f4a
Merge branch 'snarkyjs/loading-time-fix' into snarkyjs/loading-time
mitschabaude Aug 18, 2023
ec15eaf
clean up
mitschabaude Aug 18, 2023
895f90a
oops
mitschabaude Aug 18, 2023
ffbe4be
Merge branch 'berkeley' into snarkyjs/loading-time-berkeley
mitschabaude Aug 21, 2023
27e87ac
delete prettierignore
mitschabaude Aug 21, 2023
936ea1d
Merge branch 'rampup' into snarkyjs/loading-time
mitschabaude Aug 21, 2023
be7e115
Revert "faster top level integer to field conversions"
mitschabaude Aug 22, 2023
4d5a360
address feedback - don't override ! operator in dummy.ml
mitschabaude Aug 22, 2023
89595ca
address feedback - don't override ! operator in proof.ml
mitschabaude Aug 22, 2023
8a05e0d
snarkyjs
mitschabaude Aug 22, 2023
a85812c
Merge branch 'snarkyjs/loading-time' into snarkyjs/loading-time-berkeley
mitschabaude Aug 22, 2023
15fa26d
Merge branch 'berkeley' into snarkyjs/loading-time-berkeley
mitschabaude Aug 22, 2023
fcd1d8a
fix dune src/lib compilation
mitschabaude Aug 23, 2023
8c05a61
Merge branch 'snarkyjs/loading-time' into snarkyjs/loading-time-berkeley
mitschabaude Aug 23, 2023
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: 0 additions & 2 deletions .prettierignore

This file was deleted.

2 changes: 1 addition & 1 deletion genesis_ledgers/berkeley.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"genesis": {
"genesis_state_timestamp": "2023-04-06T23:30:01Z"
"genesis_state_timestamp": "2023-07-05T19:01:01Z"
},
"ledger": {
"name": "berkeley",
Expand Down
Empty file modified scripts/mina-local-network/mina-local-network.sh
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions src/app/heap_usage/values.ml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ let scan_state_merge_node :
let sok_msg : Mina_base.Sok_message.t =
{ fee = Currency.Fee.zero; prover = sample_pk_compressed }
in
let proof = Mina_base.Proof.transaction_dummy in
let proof = Lazy.force Mina_base.Proof.transaction_dummy in
let statement =
let without_sok =
Quickcheck.random_value ~seed:(`Deterministic "no sok left")
Expand All @@ -260,7 +260,7 @@ let scan_state_merge_node :
{ fee = Currency.Fee.zero; prover = sample_pk_compressed }
in
(* so the left, right proofs differ, don't want sharing *)
let proof = Mina_base.Proof.blockchain_dummy in
let proof = Lazy.force Mina_base.Proof.blockchain_dummy in
let statement =
let without_sok =
Quickcheck.random_value ~seed:(`Deterministic "no sok right")
Expand Down
2 changes: 1 addition & 1 deletion src/app/replayer/replayer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ let zkapp_command_to_transaction ~logger ~pool (cmd : Sql.Zkapp_command.t) :
let (authorization : Control.t) =
match body.authorization_kind with
| Proof _ ->
Proof Proof.transaction_dummy
Proof (Lazy.force Proof.transaction_dummy)
| Signature ->
Signature Signature.dummy
| None_given ->
Expand Down
3 changes: 2 additions & 1 deletion src/app/test_executive/zkapps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
| Proof _ ->
{ other_p with
authorization =
Control.Proof Mina_base.Proof.blockchain_dummy
Control.Proof
(Lazy.force Mina_base.Proof.blockchain_dummy)
}
| _ ->
other_p )
Expand Down
1 change: 1 addition & 0 deletions src/dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
(package (name graphql_wrapper))
(package (name hash_prefixes))
(package (name hash_prefix_states))
(package (name hash_prefix_create))
(package (name heap_usage))
(package (name hex))
(package (name immutable_array))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,9 @@ module Fp_poly_comm = Kimchi_backend_common.Poly_comm.Make (struct
fun unshifted shifted : t -> { shifted; unshifted }
end
end)

(* poseidon params *)

let poseidon_params_fp = Sponge.Params.(map pasta_p_kimchi ~f:Fp.of_string)

let poseidon_params_fq = Sponge.Params.(map pasta_q_kimchi ~f:Fq.of_string)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ open Kimchi_pasta_basic
include
Plonk_constraint_system.Make (Fq) (Kimchi_bindings.Protocol.Gates.Vector.Fq)
(struct
let params =
Sponge.Params.(
map pasta_q_kimchi ~f:(fun x ->
Fq.of_bigint (Bigint256.of_decimal_string x) ))
let params = poseidon_params_fq
end)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ open Kimchi_pasta_basic
include
Plonk_constraint_system.Make (Fp) (Kimchi_bindings.Protocol.Gates.Vector.Fp)
(struct
let params =
Sponge.Params.(
map pasta_p_kimchi ~f:(fun x ->
Fp.of_bigint (Bigint256.of_decimal_string x) ))
let params = poseidon_params_fp
end)
16 changes: 9 additions & 7 deletions src/lib/dummy_values/gen_values/gen_values.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ let str ~loc =
end) in
let open E in
[%str
let blockchain_proof, transaction_proof =
( Core_kernel.Binable.of_string
(module Pickles.Proof.Proofs_verified_2.Stable.Latest)
[%e estring blockchain_proof_string]
, Core_kernel.Binable.of_string
(module Pickles.Proof.Proofs_verified_2.Stable.Latest)
[%e estring transaction_proof_string] )]
let blockchain_proof () =
Core_kernel.Binable.of_string
(module Pickles.Proof.Proofs_verified_2.Stable.Latest)
[%e estring blockchain_proof_string]

let transaction_proof () =
Core_kernel.Binable.of_string
(module Pickles.Proof.Proofs_verified_2.Stable.Latest)
[%e estring transaction_proof_string]]

let main () =
let fmt =
Expand Down
3 changes: 2 additions & 1 deletion src/lib/genesis_ledger_helper/genesis_ledger_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ module Ledger = struct
; List.to_string balances ~f:(fun (i, balance) ->
sprintf "%i %s" i (Currency.Balance.to_string balance) )
; (* Distinguish ledgers when the hash function is different. *)
Snark_params.Tick.Field.to_string Mina_base.Account.empty_digest
Snark_params.Tick.Field.to_string
(Lazy.force Mina_base.Account.empty_digest)
; (* Distinguish ledgers when the account record layout has changed. *)
Bin_prot.Writer.to_string Mina_base.Account.Stable.Latest.bin_writer_t
Mina_base.Account.empty
Expand Down
1 change: 1 addition & 0 deletions src/lib/hash_prefix_states/dune
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
random_oracle
mina_signature_kind
hash_prefixes
hash_prefix_create
pickles
)
(preprocessor_deps ../../config.mlh)
Expand Down
10 changes: 10 additions & 0 deletions src/lib/hash_prefix_states/hash_prefix_create/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(library
(name hash_prefix_create)
(public_name hash_prefix_create)
(libraries hash_prefixes random_oracle)
(instrumentation
(backend bisect_ppx))
(preprocess
(pps ppx_version))
(virtual_modules hash_prefix_create)
(default_implementation hash_prefix_create.native))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val salt : string -> Random_oracle.Digest.t Random_oracle.State.t

val salt_legacy : string -> Random_oracle.Digest.t Random_oracle.Legacy.State.t
9 changes: 9 additions & 0 deletions src/lib/hash_prefix_states/hash_prefix_create/js/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(library
(public_name hash_prefix_create.js)
(name hash_prefix_create_js)
(libraries pickles random_oracle js_of_ocaml base core_kernel)
(instrumentation
(backend bisect_ppx))
(preprocess
(pps ppx_version))
(implements hash_prefix_create))
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
open Core_kernel
module Js = Js_of_ocaml.Js
module Field = Pickles.Impls.Step.Field.Constant

external get_ts_bindings : unit -> Js.Unsafe.any Js.Optdef.t = "getTsBindings"

(* the ?. operator from JS *)
let ( |. ) (value : _ Js.Optdef.t) (key : string) =
Js.(
if phys_equal value undefined then undefined
else Unsafe.get value (string key))

let lookup kind prefix =
get_ts_bindings () |. kind |. prefix |> Js.Optdef.to_option

let of_js x =
Js.to_array x |> Array.map ~f:(Fn.compose Field.of_string Js.to_string)

let salt s =
match lookup "prefixHashes" s with
| Some state ->
of_js state |> Random_oracle.State.of_array
| None ->
Random_oracle.salt s

let salt_legacy s =
match lookup "prefixHashesLegacy" s with
| Some state ->
of_js state |> Random_oracle.Legacy.State.of_array
| None ->
Random_oracle.Legacy.salt s
9 changes: 9 additions & 0 deletions src/lib/hash_prefix_states/hash_prefix_create/native/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(library
(public_name hash_prefix_create.native)
(name hash_prefix_create_native)
(libraries random_oracle)
(instrumentation
(backend bisect_ppx))
(preprocess
(pps ppx_version))
(implements hash_prefix_create))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let salt = Random_oracle.salt

let salt_legacy = Random_oracle.Legacy.salt
5 changes: 3 additions & 2 deletions src/lib/hash_prefix_states/hash_prefix_states.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
open Core_kernel
open Hash_prefixes

let salt (s : Hash_prefixes.t) = Random_oracle.salt (s :> string)
let salt (s : Hash_prefixes.t) = Hash_prefix_create.salt (s :> string)

let salt_legacy (s : Hash_prefixes.t) = Random_oracle.Legacy.salt (s :> string)
let salt_legacy (s : Hash_prefixes.t) =
Hash_prefix_create.salt_legacy (s :> string)

let receipt_chain_signed_command = salt_legacy receipt_chain_user_command

Expand Down
2 changes: 1 addition & 1 deletion src/lib/ledger_proof/ledger_proof.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ include Prod
module For_tests = struct
let mk_dummy_proof statement =
create ~statement ~sok_digest:Sok_message.Digest.default
~proof:Proof.transaction_dummy
~proof:(Lazy.force Proof.transaction_dummy)
end
2 changes: 1 addition & 1 deletion src/lib/mina_base/account.ml
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ let empty =
; zkapp = None
}

let empty_digest = digest empty
let empty_digest = lazy (digest empty)

let create account_id balance =
let public_key = Account_id.public_key account_id in
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mina_base/account_update.ml
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,8 @@ module Update = struct
} ) )
; Set_or_keep.typ ~dummy:Permissions.empty Permissions.typ
; Set_or_keep.optional_typ
(Data_as_hash.optional_typ ~hash:Zkapp_account.hash_zkapp_uri
~non_preimage:(Zkapp_account.hash_zkapp_uri_opt None)
(Data_as_hash.lazy_optional_typ ~hash:Zkapp_account.hash_zkapp_uri
~non_preimage:(lazy (Zkapp_account.hash_zkapp_uri_opt None))
~dummy_value:"" )
~to_option:Fn.id ~of_option:Fn.id
; Set_or_keep.typ ~dummy:Account.Token_symbol.default
Expand Down
8 changes: 8 additions & 0 deletions src/lib/mina_base/data_as_hash.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ let optional_typ ~hash ~non_preimage ~dummy_value =
| 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 ())
~there:(function
| None -> (Lazy.force non_preimage, dummy_value) | Some s -> (hash s, s)
)
~back:(fun (_, s) -> Some s)

let to_input (x, _) = Random_oracle_input.Chunked.field x

let if_ b ~then_ ~else_ =
Expand Down
6 changes: 6 additions & 0 deletions src/lib/mina_base/data_as_hash.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ val optional_typ :
-> dummy_value:'value
-> ('value t, 'value option) Typ.t

val lazy_optional_typ :
hash:('value -> Field.t)
-> non_preimage:Field.t lazy_t
-> dummy_value:'value
-> ('value t, 'value option) Typ.t

val to_input : _ t -> Field.Var.t Random_oracle_input.Chunked.t

val if_ : Boolean.var -> then_:'value t -> else_:'value t -> 'value t
Expand Down
1 change: 1 addition & 0 deletions src/lib/mina_base/dune
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
rosetta_coding
random_oracle
hash_prefix_states
hash_prefix_create
dummy_values
currency
mina_numbers
Expand Down
15 changes: 10 additions & 5 deletions src/lib/mina_base/pending_coinbase.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module Make_str (A : Wire_types.Concrete) = struct
(Input.Chunked.append (Coinbase_data.to_input coinbase) (to_input h)) )
|> of_hash

let empty = Random_oracle.salt "CoinbaseStack" |> Random_oracle.digest
let empty = Hash_prefix_create.salt "CoinbaseStack" |> Random_oracle.digest

module Checked = struct
type t = var
Expand Down Expand Up @@ -394,7 +394,8 @@ module Make_str (A : Wire_types.Concrete) = struct
|> of_hash

let empty_hash =
Random_oracle.(digest (salt "PendingCoinbaseMerkleTree")) |> of_hash
Hash_prefix_create.salt "PendingCoinbaseMerkleTree"
|> Random_oracle.digest |> of_hash

let of_digest = Fn.compose Fn.id of_hash
end
Expand Down Expand Up @@ -1018,12 +1019,16 @@ module Make_str (A : Wire_types.Concrete) = struct

type t = (Merkle_tree.t, Stack_id.t) Poly.t [@@deriving sexp, to_yojson]

let init_hash = Stack.data_hash Stack.empty

let hash_at_level =
let cached = ref [| init_hash |] in
let cached = ref [||] in
fun i ->
let len = Array.length !cached in
let len =
if len = 0 then (
cached := [| Stack.data_hash Stack.empty |] ;
1 )
else len
in
( if i >= len then
let cur_hash = ref (Array.last !cached) in
cached :=
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mina_base/proof.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

open Core_kernel

let blockchain_dummy = Dummy_values.blockchain_proof
let blockchain_dummy = lazy (Dummy_values.blockchain_proof ())

let transaction_dummy = Dummy_values.transaction_proof
let transaction_dummy = lazy (Dummy_values.transaction_proof ())

[%%versioned
module Stable = struct
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mina_base/proof.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ open Pickles_types

type t = (Nat.N2.n, Nat.N2.n) Pickles.Proof.t [@@deriving sexp, compare, yojson]

val blockchain_dummy : t
val blockchain_dummy : t lazy_t

val transaction_dummy : t
val transaction_dummy : t lazy_t

[%%versioned:
module Stable : sig
Expand Down
3 changes: 2 additions & 1 deletion src/lib/mina_base/receipt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module Chain_hash = struct

let equal = Stable.Latest.equal

let empty = of_hash Random_oracle.(salt "CodaReceiptEmpty" |> digest)
let empty =
of_hash (Hash_prefix_create.salt "CodaReceiptEmpty" |> Random_oracle.digest)

let cons_signed_command_payload (e : Signed_command_elt.t) (t : t) =
let open Random_oracle.Legacy in
Expand Down
9 changes: 5 additions & 4 deletions src/lib/mina_base/zkapp_account.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ end) =
struct
type t = Event.t list [@@deriving compare, sexp]

let empty_hash = Random_oracle.(salt Inputs.salt_phrase |> digest)
let empty_hash =
Hash_prefix_create.salt Inputs.salt_phrase |> Random_oracle.digest

let push_hash acc hash =
Random_oracle.hash ~init:Inputs.hash_prefix [| acc; hash |]
Expand Down Expand Up @@ -126,7 +127,7 @@ module Actions = struct

let empty_state_element =
let salt_phrase = "MinaZkappActionStateEmptyElt" in
Random_oracle.(salt salt_phrase |> digest)
Hash_prefix_create.salt salt_phrase |> Random_oracle.digest

let push_events (acc : Field.t) (events : t) : Field.t =
push_hash acc (hash events)
Expand Down Expand Up @@ -344,8 +345,8 @@ let typ : (Checked.t, t) Typ.t =
let open Poly in
Typ.of_hlistable
[ Zkapp_state.typ Field.typ
; Flagged_option.option_typ
~default:{ With_hash.data = None; hash = dummy_vk_hash () }
; Flagged_option.lazy_option_typ
~default:(lazy { With_hash.data = None; hash = dummy_vk_hash () })
(Data_as_hash.typ ~hash:With_hash.hash)
|> Typ.transport
~there:(Option.map ~f:(With_hash.map ~f:Option.some))
Expand Down
5 changes: 5 additions & 0 deletions src/lib/mina_base/zkapp_basic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ module Flagged_option = struct
let option_typ ~default t =
Typ.transport (typ t) ~there:(of_option ~default) ~back:to_option

let lazy_option_typ ~default t =
Typ.transport (typ t)
~there:(fun t -> of_option t ~default:(Lazy.force default))
~back:to_option

[%%endif]
end

Expand Down
Loading