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

Uses vks from earlier account updates if present #12248

Merged
merged 2 commits into from
Nov 21, 2022

Conversation

bkase
Copy link
Member

@bkase bkase commented Nov 19, 2022

Fixes #12122

Still needs a test

@bkase bkase requested a review from a team as a code owner November 19, 2022 01:35
Copy link
Member Author

@bkase bkase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any guidance on the right way to add a test for this? Would love someone to point me to a place where we're constructing sample zkapp transactions in tests so I can use that as a starting point and make a specific case for this vk-update-mid-txn.

let account_id = Account_update.account_id p in
let vks_overrided' =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's 100% safe to always record the newly set verification key unconditionally (regardless of authorization), but would love someone to double check if I'm thinking through this properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it isn't safe, then the transaction will get rejected at that point, and we'll never end up using that vk 👍

* If an account_update replaces the verification_key (or deletes it),
* subsequent account_updates use the replaced key instead of looking in the
* ledger for the key (ie set by a previous transaction).
*)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this here because it took me a bit to really think through all the edge cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works if there are multiple vk updates, and the most-recently-set vk is used for each update?

Copy link
Member

@mrmr1993 mrmr1993 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but a few nits.
Love the comments!

(* we haven't set anything; lookup the vk in the ledger *)
find_vk account_id
in
Option.map prioritized_vk ~f:(fun vk ->
Copy link
Member

@mrmr1993 mrmr1993 Nov 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let%map prioritised_vk =

let vks_overrided' =
match Account_update.verification_key p with
| Zkapp_basic.Set_or_keep.Set None ->
Account_id.Map.change vks_overrided account_id ~f:(fun _ ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Account_id.Map.set would be clearer here

let account_id = Account_update.account_id p in
let vks_overrided' =
match Account_update.verification_key p with
| Zkapp_basic.Set_or_keep.Set None ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the match branch below can be combined

Some (Some vk) )
| Zkapp_basic.Set_or_keep.Keep ->
vks_overrided
in
if Control.(Tag.equal Tag.Proof (Control.tag p.authorization)) then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think you need the 2nd Control in this expression

@@ -1538,6 +1538,10 @@ include T
let account_id (t : t) : Account_id.t =
Account_id.create t.body.public_key t.body.token_id

let verification_key (t : t) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function name suggests it's pulling out the vk, but it's converting it to an option.

maybe verification_key_update_to_option ...

* early due to an error *)
Some
Account_id.Map.empty ) ~f:(fun acc p ->
let%bind vks_overrided = acc in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overridden :-)

@bkase
Copy link
Member Author

bkase commented Nov 20, 2022

!ci-build-me

@bkase
Copy link
Member Author

bkase commented Nov 21, 2022

I'm landing as is and following up with an integration test in a separate PR

@bkase bkase merged commit 1b449ab into develop Nov 21, 2022
@bkase bkase deleted the use-vks-from-earlier-updates branch November 21, 2022 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use VK from zkApp transaction to verify proofs in it
3 participants