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 key hashes in account updates #12380

Merged
merged 78 commits into from
Feb 1, 2023

Conversation

psteckler
Copy link
Member

@psteckler psteckler commented Dec 15, 2022

Add verification key hashes to account updates with a Proof authorization, to know which verification key is meant to verify the accompanying proof.

Closes #12378.
Closes #12392
Closes #12122

@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

Copy link
Member

@deepthiskumar deepthiskumar left a comment

Choose a reason for hiding this comment

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

The vk hash should be included in an account update's hash

Control.Proof Proof.transaction_dummy
Control.Proof
{ proof = Proof.transaction_dummy
; verification_key_hash = Zkapp_account.dummy_vk_hash ()
Copy link
Member

Choose a reason for hiding this comment

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

This should be actual hash, right? (like other account update fields)

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal of replacing the authorization with a dummy is so we can calculate the transaction hash from the data in the archive db, which does not include proofs or signatures. Could we not use a dummy for the vk hash part of the authorization?

In the replayer, we could get the vk for the account from the ledger it maintains, unless the vk is being set in a previous account update in the containing zkApp, and calculate its hash. If it's being set, the replayer could track those changes.

Suppose we want to calculate the transaction hash, just by looking at the zkapp_account_update table, and tables reachable from it, and we don't have the replayer machinery available. I think it makes sense to use the dummy vk hash here.

The vk is not part of the account update that's part of the zkApp being hashed. There may be a vk update, in which case, there's a previous vk being used for the proof.

Copy link
Member

@deepthiskumar deepthiskumar Dec 15, 2022

Choose a reason for hiding this comment

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

Vk hash is part of the account update, right? It is in the authorization field which is part of an account update. We need to include the vk hash in transaction commitment and by that extension I think we should include it in this hash as well
Also, it should be in the archive database as well (I'm thinking of it as an enforced precondition). For the replayer, we don't need to verify the proof but when we apply transactions from the database, the vk hash in the account update needs to match the vk hash in the account (that check will be added to Zkapp_command_logic)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, in the PR, the vk hash is part of the authorization part of the account update.

If instead we place it as a separate field, and not in the authorization, then there's no need for the dummy hash. In that case, it makes sense to add a column to the account update body table.

Copy link
Member

Choose a reason for hiding this comment

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

But it is needed only for proof updates. maybe it it could part of authorization_kind then? In the archive DB a nullable field in zkapp_account_update_body?

Copy link
Member Author

@psteckler psteckler Dec 15, 2022

Choose a reason for hiding this comment

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

Yes, we can move it to the Proof case of Authorization_kind.t (we may need to add it to Control.Tag.t so they still match).

In the db, we can add a new column for the vk hash, which is not NULL only when the kind is Proof, or change the authorization kind column to a string.

Copy link
Member

Choose a reason for hiding this comment

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

New column seems better to me

src/lib/transaction_snark/transaction_snark.ml Outdated Show resolved Hide resolved
src/lib/verifier/common.ml Outdated Show resolved Hide resolved
@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

1 similar comment
@psteckler
Copy link
Member Author

!ci-build-me

@mitschabaude mitschabaude self-assigned this Dec 19, 2022
@nholland94 nholland94 force-pushed the feature/vk-hash-in-acct-updates branch from 9b73ac2 to 2ea13cc Compare January 27, 2023 16:46
@mitschabaude
Copy link
Contributor

The SnarkyJS part is good to go!

@bkase bkase requested a review from a team as a code owner January 30, 2023 21:32
@bkase
Copy link
Member

bkase commented Jan 30, 2023

!ci-build-me

@bkase
Copy link
Member

bkase commented Jan 30, 2023

!ci-build-me

@bkase
Copy link
Member

bkase commented Jan 31, 2023

!ci-build-me

@bkase
Copy link
Member

bkase commented Jan 31, 2023

!ci-build-me

@bkase
Copy link
Member

bkase commented Jan 31, 2023

!ci-build-me

src/lib/mina_base/account_update.ml Outdated Show resolved Hide resolved
end) =
struct
let create_all (cmds : T.t list)
~(find_vk :
Copy link
Member

Choose a reason for hiding this comment

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

Calling find_vk like this one at a time is going to be inefficient, since each invocation will fallback to the db ledger if the vk was not modified in any of the frontier masks. I fixed a number of issues on mainnet this year related to not batching db operations, and code like this could reintroduce similar performance issues if we need to lookup a lot of vks. We should consider fixing this now by just rewriting find_vk to work on batches.

Copy link
Member

Choose a reason for hiding this comment

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

I've decided to implement this in a separate PR. The work for this is already tracked in this prior issue #11705.

src/lib/network_peer/envelope.ml Outdated Show resolved Hide resolved
src/lib/network_pool/transaction_pool.ml Outdated Show resolved Hide resolved
src/lib/network_pool/transaction_pool.ml Outdated Show resolved Hide resolved
src/lib/network_pool/transaction_pool.ml Outdated Show resolved Hide resolved
@mitschabaude
Copy link
Contributor

!ci-build-me

@deepthiskumar deepthiskumar merged commit 783c08a into develop Feb 1, 2023
@deepthiskumar deepthiskumar deleted the feature/vk-hash-in-acct-updates branch February 1, 2023 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants