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

Profile risc0 and use AccountTrie in server #115

Merged
merged 9 commits into from
Jun 7, 2024

Conversation

Avi-D-coder
Copy link
Contributor

@Avi-D-coder Avi-D-coder commented Jun 5, 2024

Merge #94 before this PR.

Changes

We now use the same code in the circuit and server.
We now precheck transactions before attempting to include them in a batch.
We now rely on the security of sha(public_key) instead of also checking the public key matches the one used to create an account. This made the circuit a bit more efficient (see 3526834).

Profiling

Our circuit is already pretty optimized unfortunately.

60% of cycles are spent calculating the merkle root, 30% on deserializing the data into risc0.
Maybe we can use the older risc0 custom sterilization instead of serde.
I can align the data a bit better, maybe I can optimize calc_subtree_hash a bit, but not much.

Flat	Flat%	Sum%	Cum	Cum%	Name	Inlined?
2229336	24.11%	24.11%	2229336	24.11%	sha2::sha256::compress256	
1405433	15.20%	39.30%	1405433	15.20%	memcpy	
803798	8.69%	48.00%	2954603	31.95%	<kairos_trie::stored::merkle::Snapshot<V> as kairos_trie::stored::Store<V>>::calc_subtree_hash	
788440	8.53%	56.52%	5509723	59.58%	kairos_trie::transaction::Transaction<S,V>::calc_root_hash_node	
149716	1.62%	58.14%	149716	1.62%	memset	
133000	1.44%	59.58%	443959	4.80%	kairos_trie::transaction::nodes::Leaf<V>::hash_leaf	
0	0.00%	59.58%	5509723	59.58%	main	
0	0.00%	59.58%	5509723	59.58%	__start

Copy link
Contributor

@jonas089 jonas089 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@marijanp marijanp left a comment

Choose a reason for hiding this comment

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

After completing the review I assume that the SECURITY ASSUMPTION comments are intended, so lgtm

Comment on lines +187 to +190
// SECURITY ASUMPTION: see Account docs
// if withdrawer_account.public_key != *withdrawer {
// return Err(("hash collision detected on withdrawer account").into());
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this at a later stage?

@@ -35,6 +35,7 @@ mod error {
use super::*;
use core::fmt::{Debug, Display};

#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to be used in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hopefully not, but maybe.
no_std Error should be in 1.80 I think.

Comment on lines +117 to +120
// SECURITY ASUMPTION: see Account docs
// if sender_account.public_key != *sender {
// return Err(("hash collision detected on sender account").into());
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just left that anywhere I made the assumption.

@Avi-D-coder Avi-D-coder merged commit 00e2437 into main Jun 7, 2024
4 checks passed
@Avi-D-coder Avi-D-coder deleted the profile-risc0-and-account-trie branch June 7, 2024 13:18
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.

3 participants