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: add range proof batch verification to validators #4260

Merged

Conversation

hansieodendaal
Copy link
Contributor

@hansieodendaal hansieodendaal commented Jul 4, 2022

Description

Added batch verification of range proofs where ever more than one range proof needed to be verified.

Motivation and Context

Batch verification range proofs is much faster than running linear proofs

How Has This Been Tested?

Unit tests
Integration tests
System-level tests pending

Added batch verification of range proofs where ever more than one range proof
needed to be verified.
Copy link
Collaborator

@SWvheerden SWvheerden left a comment

Choose a reason for hiding this comment

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

This looks good.
I would just prefer adding docs to the two new functions.
Especially the power_of_two_chunk_sizes one.

}
Ok(())
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a pub function. Does this need to be public?
Either way, this function can benefit from docs. To understand what this function does, you need to read the comment on the function batch_verify_range_proofs and the tests for this function, this is not ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, fixed

@hansieodendaal hansieodendaal force-pushed the ho_batch_verification branch from a8531a3 to 4057498 Compare July 5, 2022 06:30
Comment on lines +488 to +515
pub fn batch_verify_range_proofs(
prover: &RangeProofService,
outputs: &[&TransactionOutput],
) -> Result<(), RangeProofError> {
// We need optimized power of two chunks, for example if we have 15 outputs, then we need chunks of 8, 4, 2, 1.
let power_of_two_vec = power_of_two_chunk_sizes(outputs.len(), 8);
debug!(
target: LOG_TARGET,
"Queueing range proof batch verify output(s): {:?}", &power_of_two_vec
);
let mut index = 0;
for power_of_two in power_of_two_vec {
let mut statements = Vec::with_capacity(power_of_two);
let mut proofs = Vec::with_capacity(power_of_two);
for output in outputs.iter().skip(index).take(power_of_two) {
statements.push(RistrettoAggregatedPublicStatement {
statements: vec![Statement {
commitment: output.commitment.clone(),
minimum_value_promise: 0,
}],
});
proofs.push(output.proof.to_vec().clone());
}
index += power_of_two;
prover.verify_batch(proofs.iter().collect(), statements.iter().collect())?;
}
Ok(())
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function should be in the bulletproofs+ crate. Think about it - Verifying batches of non power-of-two sets is something you'd be writing over and over if its not there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it could move there and be totally transparent.

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 created an issue for it

@@ -70,7 +70,7 @@ mod transaction_input;
mod transaction_input_version;
mod transaction_kernel;
mod transaction_kernel_version;
mod transaction_output;
pub mod transaction_output;
Copy link
Collaborator

Choose a reason for hiding this comment

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

rather use pub use to expose what you want to, otherwise all of these will eventually be pub

@aviator-app aviator-app bot merged commit 02d3121 into tari-project:development Jul 7, 2022
@hansieodendaal hansieodendaal deleted the ho_batch_verification branch July 11, 2022 10:53
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.

5 participants