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

chore(contracts): Calculate public call stack item hash from Noir #1141

Merged
merged 7 commits into from
Jul 25, 2023

Conversation

spalladino
Copy link
Collaborator

Removes a longstanding TODO to calculate the call stack item hash (for enqueued public calls) correctly in Noir, instead of overwriting it in private_execution. This required changing several hash methods in cpp from NCT::compress to NCT::hash, so they match the Pedersen flavor used in Noir (cc @suyash67).

@@ -246,15 +260,42 @@ struct PublicCircuitPublicInputs {
new_commitments: [Field; MAX_NEW_COMMITMENTS_PER_CALL],
new_nullifiers: [Field; crate::abi::MAX_NEW_NULLIFIERS_PER_CALL],
new_l2_to_l1_msgs: [Field; crate::abi::MAX_NEW_L2_TO_L1_MSGS_PER_CALL],
commitment_trees_roots: CommitmentTreesRoots,
commitment_trees_roots: CommitmentTreesRoots, // TODO: This is not present in cpp or ts, do we need to include it?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Maddiaa0 I noted this field was added in Noir but has no counterpart in cpp. Should we add it there as well, so the two structs don't diverge?

@spalladino spalladino force-pushed the palla/pub-call-stack-item-hash-from-noir branch from 1dded6d to 70be9bd Compare July 21, 2023 18:21
@spalladino spalladino marked this pull request as draft July 21, 2023 18:33
@netlify
Copy link

netlify bot commented Jul 24, 2023

Deploy Preview for preeminent-bienenstitch-606ad0 ready!

Name Link
🔨 Latest commit 1fd762f
🔍 Latest deploy log https://app.netlify.com/sites/preeminent-bienenstitch-606ad0/deploys/64c0068ef703b600088a9777
😎 Deploy Preview https://deploy-preview-1141--preeminent-bienenstitch-606ad0.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +177 to +183
/**
* Alias for toBuffer32.
* @returns A 32-byte Buffer containing the padded Ethereum address.
*/
public toBuffer() {
return this.toBuffer32();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Serializing EthAddress to 20 bytes by default was causing issues with serialization to/from cpp (yay). Msgpack autobindings were calling toBuffer on this field for serializing, which returned 20 bytes, but cpp was expecting 32. This resulted in the eth address being left or right aligned in cpp depending on how it got there. This was not uncovered before because eth address deserialization handled both cases, but when we started hashing this field in cpp, the difference started to show.

Please add 4hs to the counter of "time lost due to serialization issues"!

Copy link
Contributor

Choose a reason for hiding this comment

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

💀💀💀

@spalladino spalladino force-pushed the palla/pub-call-stack-item-hash-from-noir branch 3 times, most recently from c7955b3 to cad0757 Compare July 25, 2023 15:13
@spalladino spalladino force-pushed the palla/pub-call-stack-item-hash-from-noir branch from cad0757 to 1fd762f Compare July 25, 2023 17:29
@spalladino spalladino marked this pull request as ready for review July 25, 2023 18:45
Copy link
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

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

Just a minor comment. Great job!

constexpr size_t PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH =
2 + RETURN_VALUES_LENGTH + // + 1 for args_hash + 1 call_context.hash
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL + MAX_PUBLIC_DATA_READS_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL +
MAX_NEW_COMMITMENTS_PER_CALL + MAX_NEW_NULLIFIERS_PER_CALL + MAX_NEW_L2_TO_L1_MSGS_PER_CALL + 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would help readability if you describe why is there the +5.

Copy link
Collaborator Author

@spalladino spalladino Jul 25, 2023

Choose a reason for hiding this comment

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

Agree. I will add it on a subsequent PR, for now I want to merge this one before I keep getting conflicts!

@spalladino spalladino merged commit 4ef25f1 into master Jul 25, 2023
@spalladino spalladino deleted the palla/pub-call-stack-item-hash-from-noir branch July 25, 2023 19:12
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