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

feat(root): Adding state commitments computation using the bonsai lib #1611

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

antiyro
Copy link
Contributor

@antiyro antiyro commented May 27, 2024

draft pr to implement commtiments

@antiyro antiyro marked this pull request as draft May 27, 2024 09:08
Comment on lines +49 to +50
commitment_tx.expect("Failed to calculate transaction commitment"),
commitment_event.expect("Failed to calculate event commitment"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

panic? Why no error handling?

where
H: HasherT,
{
let starknet_state_prefix = Felt252Wrapper::try_from("STARKNET_STATE_V0".as_bytes()).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make it a constant

Comment on lines +132 to +133
if classes_trie_root == Felt252Wrapper::ZERO {
contracts_trie_root
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment explaining why?
Is this behavior defined in the Starknet specs? If so can you add a link to it?

Comment on lines +148 to +151
/// # Arguments
///
/// * `CommitmentStateDiff` - The commitment state diff inducing unprocessed state changes.
/// * `BonsaiDb` - The database responsible for storing computing the state tries.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong arguments

///
///
/// The updated state root as a `Felt252Wrapper`.
pub fn update_state_root(csd: CommitmentStateDiff, block_number: u64) -> Felt252Wrapper {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't look like it's updating anything. It just computes and returns.
We should probably change the method name

where
H: HasherT,
{
let include_signature = block_number >= 61394;
Copy link
Collaborator

Choose a reason for hiding this comment

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

does not make sense in madara

// Include signatures for Invoke transactions or for all transactions
let signature = invoke_tx.signature();

H::compute_hash_on_elements(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can change the signature of HasherT so that it takes an interator as input.
I will open an issue

&signature.0.iter().map(|x| Felt252Wrapper::from(*x).into()).collect::<Vec<FieldElement>>(),
)
} else {
H::compute_hash_on_elements(&[])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you define this value somewhere as a const?
Rather than computing it again every time.

Even if you have to add it as a const in the HasherT trait

let txs = transactions
.par_iter()
.map(|tx| calculate_transaction_hash_with_signature::<PedersenHasher>(tx, chain_id, block_number))
.collect::<Vec<_>>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to collect as you call into_iter just after

Comment on lines +123 to +124
bonsai_storage.commit(id).expect("Failed to commit to bonsai storage");
let root_hash = bonsai_storage.root_hash(identifier).expect("Failed to get root hash");
Copy link
Collaborator

Choose a reason for hiding this comment

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

panic

Copy link

There hasn't been any activity on this pull request recently, and in order to prioritize active work, it has been marked as stale.
This PR will be closed and locked in 7 days if no further activity occurs.
Thank you for your contributions!

@github-actions github-actions bot added the stale label Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants