Skip to content

Commit

Permalink
improve: use batch verification for txhashset rangeproof validation (m…
Browse files Browse the repository at this point in the history
…imblewimble#1321) (mimblewimble#1363)

* improve: use bullet rangeproof batch verification for txhashset validation (mimblewimble#1321)

* update rust-secp256k1-zkp to tag 'grin_integration_22'
  • Loading branch information
garyyu authored and yeastplume committed Aug 17, 2018
1 parent a10557c commit 54d3fc0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
23 changes: 21 additions & 2 deletions chain/src/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions core/src/core/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 54d3fc0

Please sign in to comment.