Skip to content

Commit

Permalink
add proofsize check in pow verify (mimblewimble#2805)
Browse files Browse the repository at this point in the history
  • Loading branch information
tromp authored and Hanjiang Yu committed May 6, 2019
1 parent 6b5b9d7 commit a1b320e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/pow/cuckaroo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::pow::common::{CuckooParams, EdgeType};
use crate::pow::error::{Error, ErrorKind};
use crate::pow::siphash::siphash_block;
use crate::pow::{PoWContext, Proof};
use crate::global;

/// Instantiate a new CuckarooContext as a PowContext. Note that this can't
/// be moved in the PoWContext trait as this particular trait needs to be
Expand Down Expand Up @@ -68,6 +69,10 @@ where
}

fn verify(&self, proof: &Proof) -> Result<(), Error> {
if proof.proof_size() != global::proofsize() {
return Err(ErrorKind::Verification(
"wrong cycle length".to_owned(),))?;
}
let nonces = &proof.nonces;
let mut uvs = vec![0u64; 2 * proof.proof_size()];
let mut xor0: u64 = 0;
Expand Down
5 changes: 5 additions & 0 deletions core/src/pow/cuckatoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use croaring::Bitmap;
use crate::pow::common::{CuckooParams, EdgeType, Link};
use crate::pow::error::{Error, ErrorKind};
use crate::pow::{PoWContext, Proof};
use crate::global;
use crate::util;

struct Graph<T>
Expand Down Expand Up @@ -280,6 +281,10 @@ where
/// Verify that given edges are ascending and form a cycle in a header-generated
/// graph
pub fn verify_impl(&self, proof: &Proof) -> Result<(), Error> {
if proof.proof_size() != global::proofsize() {
return Err(ErrorKind::Verification(
"wrong cycle length".to_owned(),))?;
}
let nonces = &proof.nonces;
let mut uvs = vec![0u64; 2 * proof.proof_size()];
let mut xor0: u64 = (self.params.proof_size as u64 / 2) & 1;
Expand Down

0 comments on commit a1b320e

Please sign in to comment.