diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index 684b1293c..19f882f9d 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -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 diff --git a/core/src/core/block.rs b/core/src/core/block.rs index 97c210544..afdea2289 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -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(()) }