Block inputs and ouputs Merkle tree validation.

This commit is contained in:
Ignotus Peverell 2017-01-25 11:44:37 -08:00
parent fc2697e7d8
commit 4a034018cb
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211
2 changed files with 9 additions and 1 deletions

View file

@ -167,7 +167,6 @@ fn validate_header(b: &Block, ctx: &mut BlockContext) -> Result<(), Error> {
/// Fully validate the block content.
fn validate_block(b: &Block, ctx: &mut BlockContext) -> Result<(), Error> {
// TODO check tx merkle tree
let curve = secp::Secp256k1::with_caps(secp::ContextFlag::Commit);
try!(b.verify(&curve).map_err(&Error::InvalidBlockProof));
// TODO check every input exists

View file

@ -350,6 +350,7 @@ impl Block {
pub fn verify(&self, secp: &Secp256k1) -> Result<(), secp::Error> {
// sum all inputs and outs commitments
let io_sum = try!(self.sum_commitments(secp));
// sum all proofs commitments
let proof_commits = map_vec!(self.proofs, |proof| proof.remainder);
let proof_sum = try!(secp.commit_sum(proof_commits, vec![]));
@ -364,6 +365,14 @@ impl Block {
for proof in &self.proofs {
try!(proof.verify(secp));
}
// verify the transaction Merkle root
let tx_merkle = merkle_inputs_outputs(&self.inputs, &self.outputs);
if tx_merkle != self.header.tx_merkle {
// TODO more specific error
return Err(secp::Error::IncorrectCommitSum);
}
Ok(())
}