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

Verification refcounted key hash table in transaction pool #12398

Merged
merged 30 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
277ad0a
Scaffold for verification_key table
bkase Dec 17, 2022
ec9ff1f
Adds libiconv dep
bkase Dec 14, 2022
f175230
Adds other changes from patch
bkase Dec 14, 2022
47fb7eb
Runs nixfmt on code
bkase Dec 14, 2022
4797c8d
Scaffold for verification_key table
bkase Dec 17, 2022
8392da4
Rebases and fixes up errors on top of vk in account updates
bkase Dec 19, 2022
c28cbdf
Merge remote-tracking branch 'origin/verification-key-hash-table' int…
bkase Dec 19, 2022
827d49a
Reformats changes
bkase Dec 19, 2022
a24a51b
Merge remote-tracking branch 'origin/feature/vk-hash-in-acct-updates'…
bkase Dec 21, 2022
8c4a2d7
Makes requested changes
bkase Dec 21, 2022
1b0f589
Double check vk_hash in find_vk_via_ledger
bkase Jan 4, 2023
9208ff6
Makes to_valid also use find_vk
bkase Jan 4, 2023
4226ce8
Moves extract_vks to relevant locations
bkase Jan 4, 2023
25bdc37
Lifts vk lookup fallback logic from pool to reusable
bkase Jan 4, 2023
0991145
Reassigns vk-hashes before verifiabling them
bkase Jan 6, 2023
6504944
WIP on fix
bkase Jan 11, 2023
4d1aab1
Check vk hashes in apply
psteckler Jan 11, 2023
a1ca141
fix tests
psteckler Jan 12, 2023
70a59c6
uncomment test
psteckler Jan 12, 2023
81288a1
Removes dead logic in staged ledger, closer to correct logic in pools
bkase Jan 12, 2023
1876c6d
Restore Proof auth in create tokens test
psteckler Jan 12, 2023
f59c1b0
Also replaces setting vks
bkase Jan 12, 2023
18a4275
use Local_state.add_check
psteckler Jan 12, 2023
1a4ca27
Merge branch 'verification-key-hash-table' into feature/check-vk-hash…
psteckler Jan 12, 2023
ddafda9
Merge pull request #12498 from MinaProtocol/feature/check-vk-hashes-i…
psteckler Jan 12, 2023
06e3100
Merge remote-tracking branch 'origin/verification-key-hash-table' int…
bkase Jan 13, 2023
83efa90
Requested changes
bkase Jan 18, 2023
9164cda
Removed test that is no longer valid
bkase Jan 18, 2023
164b104
Revert "Removed test that is no longer valid"
bkase Jan 19, 2023
3a245de
Temporarily comments out staged ledger test
bkase Jan 19, 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
7 changes: 5 additions & 2 deletions src/app/cli/src/init/transaction_snark_profiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,11 @@ let profile_zkapps ~verifier ledger zkapp_commands =
let v_start_time = Time.now () in
let%bind res =
Verifier.verify_commands verifier
[ User_command.to_verifiable ~ledger ~get:Mina_ledger.Ledger.get
~location_of_account:Mina_ledger.Ledger.location_of_account
[ User_command.to_verifiable
~find_vk:
(Zkapp_command.Verifiable.find_vk_via_ledger ~ledger
~get:Mina_ledger.Ledger.get
~location_of_account:Mina_ledger.Ledger.location_of_account )
(Zkapp_command zkapp_command)
|> Or_error.ok_exn
]
Expand Down
1 change: 1 addition & 0 deletions src/lib/mina_base/mina_base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ module Transaction_status = Transaction_status
module Transaction_union_payload = Transaction_union_payload
module Transaction_union_tag = Transaction_union_tag
module User_command = User_command
module Verification_key_wire = Verification_key_wire
module With_stack_hash = With_stack_hash
module With_status = With_status
11 changes: 10 additions & 1 deletion src/lib/mina_base/transaction_status.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Failure = struct
| Account_proved_state_precondition_unsatisfied
| Account_is_new_precondition_unsatisfied
| Protocol_state_precondition_unsatisfied
| Unexpected_verification_key_hash
| Incorrect_nonce
| Invalid_fee_excess
| Cancelled
Expand Down Expand Up @@ -127,7 +128,8 @@ module Failure = struct
List.init 8 ~f:var.constructor @ acc )
~account_proved_state_precondition_unsatisfied:add
~account_is_new_precondition_unsatisfied:add
~protocol_state_precondition_unsatisfied:add ~incorrect_nonce:add
~protocol_state_precondition_unsatisfied:add
~unexpected_verification_key_hash:add ~incorrect_nonce:add
~invalid_fee_excess:add ~cancelled:add

let gen = Quickcheck.Generator.of_list all
Expand Down Expand Up @@ -211,6 +213,8 @@ module Failure = struct
"Account_is_new_precondition_unsatisfied"
| Protocol_state_precondition_unsatisfied ->
"Protocol_state_precondition_unsatisfied"
| Unexpected_verification_key_hash ->
"Unexpected_verification_key_hash"
| Incorrect_nonce ->
"Incorrect_nonce"
| Invalid_fee_excess ->
Expand Down Expand Up @@ -295,6 +299,8 @@ module Failure = struct
Ok Account_is_new_precondition_unsatisfied
| "Protocol_state_precondition_unsatisfied" ->
Ok Protocol_state_precondition_unsatisfied
| "Unexpected_verification_key_hash" ->
Ok Unexpected_verification_key_hash
| "Incorrect_nonce" ->
Ok Incorrect_nonce
| "Invalid_fee_excess" ->
Expand Down Expand Up @@ -436,6 +442,9 @@ module Failure = struct
"The account update's account is-new state precondition was unsatisfied"
| Protocol_state_precondition_unsatisfied ->
"The account update's protocol state precondition unsatisfied"
| Unexpected_verification_key_hash ->
"The account update's verification key hash does not match the \
verification key in the ledger account"
| Incorrect_nonce ->
"Incorrect nonce"
| Invalid_fee_excess ->
Expand Down
69 changes: 62 additions & 7 deletions src/lib/mina_base/user_command.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,61 @@ module Verifiable = struct
Account_update.Fee_payer.account_id p.fee_payer
end

let to_verifiable (t : t) ~ledger ~get ~location_of_account :
Verifiable.t Or_error.t =
let to_verifiable (t : t) ~find_vk : Verifiable.t Or_error.t =
match t with
| Signed_command c ->
Ok (Signed_command c)
| Zkapp_command cmd ->
Zkapp_command.Verifiable.create ~ledger ~get ~location_of_account cmd
Zkapp_command.Verifiable.create ~find_vk cmd
|> Or_error.map ~f:(fun cmd -> Zkapp_command cmd)

module Make_to_all_verifiable (Strategy : sig
val create_all :
Zkapp_command.t list
-> find_vk:
( Zkapp_basic.F.t
-> Account_id.t
-> (Verification_key_wire.t, Error.t) Result.t )
-> Zkapp_command.Verifiable.t list Or_error.t
end) =
struct
let to_all_verifiable (ts : t list) ~find_vk : Verifiable.t list Or_error.t =
let open Or_error.Let_syntax in
(* First we tag everything with its index *)
let its = List.mapi ts ~f:(fun i x -> (i, x)) in
(* then we partition out the zkapp commands *)
let izk_cmds, is_cmds =
List.partition_map its ~f:(fun (i, cmd) ->
match cmd with
| Zkapp_command c ->
First (i, c)
| Signed_command c ->
Second (i, c) )
in
(* then unzip the indices *)
let ixs, zk_cmds = List.unzip izk_cmds in
(* then we verify the zkapp commands *)
let%map vzk_cmds = Strategy.create_all ~find_vk zk_cmds in
(* rezip indices *)
let ivzk_cmds = List.zip_exn ixs vzk_cmds in
(* Put them back in with a sort by index (un-partition) *)
let ivs =
List.map is_cmds ~f:(fun (i, cmd) -> (i, Signed_command cmd))
@ List.map ivzk_cmds ~f:(fun (i, cmd) -> (i, Zkapp_command cmd))
|> List.sort ~compare:(fun (i, _) (j, _) -> i - j)
in
(* Drop the indices *)
List.unzip ivs |> snd
end

module Any = struct
include Make_to_all_verifiable (Zkapp_command.Verifiable.Any)
end

module Last = struct
include Make_to_all_verifiable (Zkapp_command.Verifiable.Last)
end

let of_verifiable (t : Verifiable.t) : t =
match t with
| Signed_command x ->
Expand Down Expand Up @@ -212,6 +258,12 @@ let applicable_at_nonce (t : t) =

let expected_target_nonce t = Account.Nonce.succ (applicable_at_nonce t)

let extract_vks : t -> Verification_key_wire.t List.t = function
| Signed_command _ ->
[]
| Zkapp_command cmd ->
Zkapp_command.extract_vks cmd

(** The target nonce is what the nonce of the fee payer will be after a user command is successfully applied. *)
let target_nonce_on_success (t : t) =
match t with
Expand Down Expand Up @@ -239,6 +291,8 @@ let valid_until (t : t) =
Mina_numbers.Global_slot.max_value )

module Valid = struct
type t_ = t

[%%versioned
module Stable = struct
module V2 = struct
Expand All @@ -255,7 +309,7 @@ module Valid = struct
module Gen = Gen_make (Signed_command.With_valid_signature)
end

let check ~ledger ~get ~location_of_account (t : t) : Valid.t Or_error.t =
let check_verifiable (t : Verifiable.t) : Valid.t Or_error.t =
match t with
| Signed_command x -> (
match Signed_command.check x with
Expand All @@ -264,9 +318,10 @@ let check ~ledger ~get ~location_of_account (t : t) : Valid.t Or_error.t =
| None ->
Or_error.error_string "Invalid signature" )
| Zkapp_command p ->
Or_error.map
(Zkapp_command.Valid.to_valid ~ledger ~get ~location_of_account p)
~f:(fun p -> Zkapp_command p)
Ok (Zkapp_command (Zkapp_command.Valid.of_verifiable p))

let check ~find_vk (t : t) : Valid.t Or_error.t =
to_verifiable ~find_vk t |> Or_error.bind ~f:check_verifiable

let forget_check (t : Valid.t) : t =
match t with
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 @@ -393,6 +393,11 @@ module F = Snark_params.Tick.Field

[%%endif]

module F_map = struct
include Hashable.Make (F)
include Comparable.Make (F)
end

let invalid_public_key : Public_key.Compressed.t =
{ x = F.zero; is_odd = false }

Expand Down
Loading