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

Add proofsize check in pow verification #2805

Merged
merged 1 commit into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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