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

Remove Zkapp_command.Wire.t #16556

Draft
wants to merge 29 commits into
base: georgeee/proof-cache-tag
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e3b2773
Merge revert
georgeee Jan 25, 2025
431e906
Remove Mina_wire_types.Mina_transaction.Valid
georgeee Jan 26, 2025
6ff20bb
Remove Zkapp_command.Verifiable.Stable
georgeee Jan 26, 2025
7e1add3
Rename function hash -> transaction_hash
georgeee Jan 27, 2025
9b6fa5e
Remove unused Stable module in Transaction_hash
georgeee Jan 27, 2025
2a66f9b
Remove Transaction.Valid.Stable
georgeee Jan 27, 2025
9479202
Remove User_command.Valid.Stable
georgeee Jan 27, 2025
89c0aa8
Remove Zkapp_command.Valid.Stable
georgeee Jan 27, 2025
8589eda
Polymorphize Zkapp_command in mina_wire_types
georgeee Jan 27, 2025
d78978e
Assign type to Zkapp_command.T
georgeee Jan 27, 2025
21f6853
Polymorphize some funs in Zkapp_command
georgeee Jan 27, 2025
18718f5
Split Transaction_applied.Varying.t
georgeee Jan 31, 2025
4f34b9c
Split Transaction_applied.Zkapp_command_applied.t
georgeee Jan 31, 2025
76ff3eb
Prepare for Transaction.{Stable.Latest.t != t}
georgeee Jan 31, 2025
477484a
Unwind temporary changes to Transaction.t
georgeee Jan 31, 2025
4089de3
Split User_command's stable and regular types
georgeee Jan 31, 2025
ce38611
Remove transaction_witness.mli
georgeee Feb 3, 2025
0d830cf
Small refactoring of transaction_pool.ml (1/3)
georgeee Feb 3, 2025
468a18c
Small refactoring of transaction_pool.ml (2/3)
georgeee Feb 3, 2025
0a2f39b
Small refactoring of transaction_pool.ml (3/3)
georgeee Feb 3, 2025
7befd70
Use Zkapp_command.Stable.Latest in network_pool
georgeee Feb 3, 2025
2080e21
Redefine Filtered_external_transition.t
georgeee Jan 31, 2025
51bf05f
Update Transaction_hash's use of zkapp command
georgeee Feb 2, 2025
e0342e3
Update graphql code to use stable zkapp_command
georgeee Feb 3, 2025
0e1e760
Separate transaction_witness stable/regular types
georgeee Feb 3, 2025
800a1ad
Update 'mina advanced verify-commands'
georgeee Feb 3, 2025
6b7af57
Prepare for switch of zkapp_command types
georgeee Feb 3, 2025
6beea17
Do not store hashes in Zkapp_command.Stable.t
georgeee Feb 2, 2025
0708458
Remove Zkapp_command.Wire
georgeee Feb 2, 2025
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 src/app/archive/lib/processor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ module User_command = struct
in
let memo = ps.memo |> Signed_command_memo.to_base58_check in
let hash =
Transaction_hash.hash_command (Zkapp_command ps)
Transaction_hash.hash_wrapped_zkapp_command ps
|> Transaction_hash.to_base58_check
in
Mina_caqti.select_insert_into_cols ~select:("id", Caqti_type.int)
Expand Down
8 changes: 6 additions & 2 deletions src/app/archive/lib/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ let%test_module "Archive node unit tests" =
@@ fun () ->
Async.Quickcheck.async_test ~sexp_of:[%sexp_of: User_command.t]
user_command_signed_gen ~f:(fun user_command ->
let transaction_hash = Transaction_hash.hash_command user_command in
let transaction_hash =
Transaction_hash.hash_wrapped_command user_command
in
match%map
let open Deferred.Result.Let_syntax in
let%bind user_command_id =
Expand Down Expand Up @@ -164,7 +166,9 @@ let%test_module "Archive node unit tests" =
@@ fun () ->
Async.Quickcheck.async_test ~trials:20 ~sexp_of:[%sexp_of: User_command.t]
user_command_zkapp_gen ~f:(fun user_command ->
let transaction_hash = Transaction_hash.hash_command user_command in
let transaction_hash =
Transaction_hash.hash_wrapped_command user_command
in
match user_command with
| Signed_command _ ->
failwith "zkapp_gen failed"
Expand Down
5 changes: 4 additions & 1 deletion src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,9 @@ let replay_blocks ~itn_features logger =
block
| Error err ->
failwithf "Could not read block: %s" err () )
| Some "sexp" ->
fun line ->
Sexp.of_string_conv_exn line Mina_block.Precomputed.t_of_sexp
| _ ->
failwith "Expected one of 'json', 'sexp' for -format flag"
in
Expand Down Expand Up @@ -1625,7 +1628,7 @@ let internal_commands ~itn_features logger =
in
let spec =
[%of_sexp:
( Transaction_witness.t
( Transaction_witness.Stable.Latest.t
, Ledger_proof.t )
Snark_work_lib.Work.Single.Spec.t] sexp
in
Expand Down
57 changes: 44 additions & 13 deletions src/app/cli/src/init/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,24 @@ let verify_receipt =
~doc:"TOKEN_ID The token ID for the account"
(optional_with_default Token_id.default Cli_lib.Arg_type.token_id)
in
let legacy_json_flag =
flag "--legacy" no_arg
~doc:"Use legacy json format (zkapp command with hashes)"
in
let config_files = Cli_lib.Flag.config_files in
Command.async ~summary:"Verify a receipt of a sent payment"
(Cli_lib.Background_daemon.rpc_init
(Args.zip5 config_files payment_path_flag proof_path_flag address_flag
token_flag )
~f:(fun port (config_files, payment_path, proof_path, pk, token_id) ->
(Args.zip6 config_files payment_path_flag proof_path_flag address_flag
token_flag legacy_json_flag )
~f:(fun
port
( config_files
, payment_path
, proof_path
, pk
, token_id
, use_legacy_json )
->
let%bind compile_config = load_compile_config config_files in
let account_id = Account_id.create pk token_id in
let dispatch_result =
Expand All @@ -350,22 +362,40 @@ let verify_receipt =
read_json payment_path ~flag:"payment-path"
in
let%bind proof_json = read_json proof_path ~flag:"proof-path" in
let of_payment_json =
if use_legacy_json then
Fn.compose
(Result.map ~f:User_command.unwrap)
User_command.of_yojson
else User_command.Stable.Latest.of_yojson
in
let of_proof_json =
let unwrap_proof =
Tuple2.map_snd ~f:(List.map ~f:User_command.unwrap)
in
if use_legacy_json then
Fn.compose
(Result.map ~f:unwrap_proof)
[%of_yojson: Receipt.Chain_hash.t * User_command.t list]
else
[%of_yojson:
Receipt.Chain_hash.t * User_command.Stable.Latest.t list]
in
let to_deferred_or_error result ~error =
Result.map_error result ~f:(fun s ->
Error.of_string (sprintf "%s: %s" error s) )
|> Deferred.return
in
let%bind payment =
User_command.of_yojson payment_json
|> to_deferred_or_error
~error:
(sprintf "Payment file %s has invalid json format"
payment_path )
to_deferred_or_error
~error:
(sprintf "Payment file %s has invalid json format" payment_path)
(of_payment_json payment_json)
and proof =
[%of_yojson: Receipt.Chain_hash.t * User_command.t list] proof_json
|> to_deferred_or_error
~error:
(sprintf "Proof file %s has invalid json format" proof_path)
to_deferred_or_error
~error:
(sprintf "Proof file %s has invalid json format" proof_path)
(of_proof_json proof_json)
in
Daemon_rpcs.Client.dispatch ~compile_config Verify_proof.rpc
(account_id, payment, proof)
Expand Down Expand Up @@ -2205,7 +2235,8 @@ let receipt_chain_hash =
in
let receipt_elt =
let _txn_commitment, full_txn_commitment =
Zkapp_command.get_transaction_commitments zkapp_cmd
Zkapp_command.get_transaction_commitments
(Zkapp_command.generate zkapp_cmd)
in
Receipt.Zkapp_command_elt.Zkapp_command_commitment
full_txn_commitment
Expand Down
7 changes: 5 additions & 2 deletions src/app/cli/src/init/itn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,13 @@ let create_accounts ~(genesis_constants : Genesis_constants.t)
Transaction_snark.For_tests.multiple_transfers ~constraint_constants
multispec )
in
(* TODO do not compute hashes and remoive Zkapp_command.unwrap *)
let zkapps_batches = List.chunks_of zkapps ~length:zkapps_per_block in
Deferred.List.iter zkapps_batches ~f:(fun zkapps_batch ->
Format.printf "Processing batch of %d zkApps@." (List.length zkapps_batch) ;
List.iteri zkapps_batch ~f:(fun i zkapp ->
let txn_hash =
Transaction_hash.hash_command (Zkapp_command zkapp)
Transaction_hash.hash_wrapped_zkapp_command zkapp
|> Transaction_hash.to_base58_check
in
Format.printf " zkApp %d, transaction hash: %s@." i txn_hash ;
Expand Down Expand Up @@ -220,7 +221,9 @@ let create_accounts ~(genesis_constants : Genesis_constants.t)
balance_change_str ) ) ;
let%bind res =
Daemon_rpcs.Client.dispatch ~compile_config
Daemon_rpcs.Send_zkapp_commands.rpc zkapps_batch port
Daemon_rpcs.Send_zkapp_commands.rpc
(List.map ~f:Zkapp_command.unwrap zkapps_batch)
port
in
( match res with
| Ok res_inner -> (
Expand Down
13 changes: 11 additions & 2 deletions src/app/dump_blocks/dump_blocks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ let mk_io : type a. a Encoding.content -> Encoding.t io -> a codec io =
{ io with
encoding =
( match (content, io.encoding) with
| Precomputed, Sexp ->
(module Sexp_precomputed)
| Precomputed, Json ->
(module Json_precomputed)
| Precomputed, Binary ->
(module Binary_precomputed)
| Block, Sexp ->
(module Sexp_block)
| Block, Json ->
failwith "Json encoding for full blocks not supported."
| Block, Binary ->
Expand All @@ -36,8 +40,10 @@ let encoded_block =
| [ encoding; filename ] ->
{ encoding =
( match String.lowercase encoding with
| "sexp" ->
Encoding.Sexp
| "json" ->
Encoding.Json
Json
| "bin" | "binary" ->
Binary
| _ ->
Expand Down Expand Up @@ -92,7 +98,10 @@ let f (type a) ?parent (outputs : a codec io list) make_breadcrumb =
output_block content output ) ;
clean_up_persistent_root ~frontier )

let default_outputs = [ { encoding = Encoding.Json; filename = "-" } ]
let default_outputs =
[ { encoding = Encoding.Sexp; filename = "-" }
; { encoding = Encoding.Json; filename = "-" }
]

let command =
Command.basic
Expand Down
28 changes: 27 additions & 1 deletion src/app/dump_blocks/encoding.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Core

type t = Json | Binary
type t = Sexp | Json | Binary

type 'a content =
| Block : Mina_block.Stable.Latest.t content
Expand Down Expand Up @@ -43,6 +43,19 @@ module type S = sig
val of_string : string -> t
end

module Sexp_block : S with type t = Mina_block.Stable.Latest.t = struct
type t = Mina_block.Stable.Latest.t

let name = "sexp"

let of_breadcrumb = block_of_breadcrumb

let to_string b =
Mina_block.Stable.Latest.sexp_of_t b |> Sexp.to_string |> append_newline

let of_string s = Sexp.of_string s |> Mina_block.Stable.Latest.t_of_sexp
end

module Binary_block : S with type t = Mina_block.Stable.Latest.t = struct
type t = Mina_block.Stable.Latest.t

Expand Down Expand Up @@ -80,6 +93,19 @@ let precomputed_of_breadcrumb ?with_parent_statehash breadcrumb =
~scheduled_time
(Breadcrumb.block_with_hash breadcrumb)

module Sexp_precomputed : S with type t = Mina_block.Precomputed.t = struct
type t = Mina_block.Precomputed.t

let name = "sexp"

let of_breadcrumb = precomputed_of_breadcrumb

let to_string b =
Mina_block.Precomputed.sexp_of_t b |> Sexp.to_string |> append_newline

let of_string s = Sexp.of_string s |> Mina_block.Precomputed.t_of_sexp
end

module Json_precomputed : S with type t = Mina_block.Precomputed.t = struct
type t = Mina_block.Precomputed.t

Expand Down
42 changes: 38 additions & 4 deletions src/app/test_executive/zkapps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,40 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
zkapp_command_insufficient_fee "Insufficient fee" )
in
let%bind () = wait_for t (Wait_condition.blocks_to_be_produced 1) in
let%bind.Deferred () =
(* Wait for the start of the next slot, attempting to submit all commands
within the same slot.
In particular, this has the goal of reducing flakiness around the
'insufficient replace fee' test, which becomes an 'invalid nonce'
failure if the first transaction has already been included.

Note that this *isn't* redundant with the block waiting above, because
the block will be produced part-way through a slot, and will further
take us some time to receive the message about that block production
due to polling.
*)
let next_slot_time =
let genesis_timestamp =
constants.genesis_constants.protocol.genesis_state_timestamp
|> Int64.to_float |> Time.Span.of_ms |> Time.of_span_since_epoch
in
let block_duration_ms =
constants.constraint_constants.block_window_duration_ms
|> Int.to_float
in
let current_slot_span_ms =
Time.(diff (now ()) genesis_timestamp) |> Time.Span.to_ms
in
let target_slot =
block_duration_ms /. current_slot_span_ms |> Float.round_up
in
let target_slot_span_ms =
target_slot *. current_slot_span_ms |> Time.Span.of_ms
in
Time.add genesis_timestamp target_slot_span_ms
in
after Time.(diff (now ()) next_slot_time)
in
(* Won't be accepted until the previous transactions are applied *)
let%bind () =
section_hard "Send a zkApp transaction to update all fields"
Expand All @@ -775,16 +809,16 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
zkapp_command_update_all )
in
let%bind () =
section_hard "Send a zkapp with an invalid proof"
section_hard "Send a zkapp with an insufficient replace fee"
(send_invalid_zkapp ~logger
(Network.Node.get_ingress_uri node)
zkapp_command_invalid_proof "Invalid_proof" )
zkapp_command_insufficient_replace_fee "Insufficient_replace_fee" )
in
let%bind () =
section_hard "Send a zkapp with an insufficient replace fee"
section_hard "Send a zkapp with an invalid proof"
(send_invalid_zkapp ~logger
(Network.Node.get_ingress_uri node)
zkapp_command_insufficient_replace_fee "Insufficient_replace_fee" )
zkapp_command_invalid_proof "Invalid_proof" )
in
let%bind () =
section_hard "Send a zkApp transaction with an invalid nonce"
Expand Down
Loading