mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
* improve: use bullet rangeproof batch verification for txhashset validation (#1321) * update rust-secp256k1-zkp to tag 'grin_integration_22'
This commit is contained in:
parent
a10557c756
commit
54d3fc0af2
3 changed files with 35 additions and 3 deletions
|
@ -989,20 +989,27 @@ impl<'a> Extension<'a> {
|
|||
{
|
||||
let now = Instant::now();
|
||||
|
||||
let mut commits:Vec<Commitment> = vec![];
|
||||
let mut proofs:Vec<RangeProof> = vec![];
|
||||
|
||||
let mut proof_count = 0;
|
||||
let total_rproofs = pmmr::n_leaves(self.output_pmmr.unpruned_size());
|
||||
for n in 1..self.output_pmmr.unpruned_size() + 1 {
|
||||
if pmmr::is_leaf(n) {
|
||||
if let Some(out) = self.output_pmmr.get_data(n) {
|
||||
if let Some(rp) = self.rproof_pmmr.get_data(n) {
|
||||
out.into_output(rp).verify_proof()?;
|
||||
commits.push(out.commit);
|
||||
proofs.push(rp);
|
||||
} else {
|
||||
// TODO - rangeproof not found
|
||||
return Err(ErrorKind::OutputNotFound.into());
|
||||
}
|
||||
proof_count += 1;
|
||||
|
||||
if proof_count % 500 == 0 {
|
||||
if proofs.len() >= 1000 {
|
||||
Output::batch_verify_proofs(&commits, &proofs)?;
|
||||
commits.clear();
|
||||
proofs.clear();
|
||||
debug!(
|
||||
LOGGER,
|
||||
"txhashset: verify_rangeproofs: verified {} rangeproofs", proof_count,
|
||||
|
@ -1014,6 +1021,18 @@ impl<'a> Extension<'a> {
|
|||
status.on_validation(0, 0, proof_count, total_rproofs);
|
||||
}
|
||||
}
|
||||
|
||||
// remaining part which not full of 1000 range proofs
|
||||
if proofs.len() > 0 {
|
||||
Output::batch_verify_proofs(&commits, &proofs)?;
|
||||
commits.clear();
|
||||
proofs.clear();
|
||||
debug!(
|
||||
LOGGER,
|
||||
"txhashset: verify_rangeproofs: verified {} rangeproofs", proof_count,
|
||||
);
|
||||
}
|
||||
|
||||
debug!(
|
||||
LOGGER,
|
||||
"txhashset: verified {} rangeproofs, pmmr size {}, took {}s",
|
||||
|
|
|
@ -993,6 +993,19 @@ impl Output {
|
|||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
/// Batch validates the range proofs using the commitments
|
||||
pub fn batch_verify_proofs(
|
||||
commits: &Vec<Commitment>,
|
||||
proofs: &Vec<RangeProof>,
|
||||
) -> Result<(), secp::Error> {
|
||||
let secp = static_secp_instance();
|
||||
let secp = secp.lock().unwrap();
|
||||
match secp.verify_bullet_proof_multi(commits.clone(), proofs.clone(), None) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An output_identifier can be build from either an input _or_ an output and
|
||||
|
|
|
@ -20,6 +20,6 @@ zip = "0.4"
|
|||
|
||||
[dependencies.secp256k1zkp]
|
||||
git = "https://github.com/mimblewimble/rust-secp256k1-zkp"
|
||||
tag = "grin_integration_21"
|
||||
tag = "grin_integration_22"
|
||||
#path = "../../rust-secp256k1-zkp"
|
||||
features = ["bullet-proof-sizing"]
|
||||
|
|
Loading…
Reference in a new issue