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

Queries serialization improvements #15

Merged
merged 4 commits into from May 5, 2021
Merged

Conversation

irakliyk
Copy link
Collaborator

This PR addresses #6 and also improves queries serialization/deserialization overall. Specifically:

  • Implement deserialization of query bytes directly into field elements
  • Implement flat serialization of query values and Merkle paths (for trace and constraint queries only)

The overall impact of this PR is ~1% reduction in proof sizes, but it also lays groundwork for switching over to new Merkle tree implementation.

@irakliyk irakliyk linked an issue Apr 30, 2021 that may be closed by this pull request
Copy link
Contributor

@kchalkias kchalkias left a comment

Choose a reason for hiding this comment

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

minor comments

assert!(!query_values.is_empty(), "query values cannot be empty");
let elements_per_query = query_values[0].len();
assert!(
elements_per_query != 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer is_empty

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I usually do too - but in this case we need to cache the elements_per_query value - so, I think it's OK to have it like this.

/// TODO: return values as a vector of field elements
pub fn into_batch<H: Hasher>(self, num_leaves: usize) -> (BatchMerkleProof, Vec<Vec<u8>>) {
/// Convert a set of queries into a batch Merkle proof and corresponding query values.
pub fn deserialize<H: Hasher, E: FieldElement>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can any zero value or length cause issues or panic (ie division by zero?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! I've added some assertions here as this code gets called internally from within Winterfell. So, if it is called with wrong parameters, it's ok to panic.

@irakliyk irakliyk merged commit f0fbb53 into main May 5, 2021
@irakliyk irakliyk deleted the queries-deserialization branch May 5, 2021 02:26
@irakliyk irakliyk mentioned this pull request Jun 16, 2021
3 tasks
Jasleen1 pushed a commit to Jasleen1/winterfell that referenced this pull request Sep 8, 2021
Jasleen1 pushed a commit to Jasleen1/winterfell that referenced this pull request Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[common] Improve query deserialization
3 participants