From 328d832bd6e3ac33cf4c160c4d78085dafb20adf Mon Sep 17 00:00:00 2001 From: Antioch Peverell <30642645+antiochp@users.noreply.github.com> Date: Wed, 8 Aug 2018 09:47:30 +0100 Subject: [PATCH] cleanup verify_coinbase on block (#1326) --- core/src/core/block.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/core/src/core/block.rs b/core/src/core/block.rs index 18a127d7a..92c04d2a8 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -776,12 +776,9 @@ impl Block { Ok(()) } - /// Validate the coinbase outputs generated by miners. Entails 2 main - /// checks: - /// - /// * That the sum of all coinbase-marked outputs equal the supply. - /// * That the sum of blinding factors for all coinbase-marked outputs match - /// the coinbase-marked kernels. + /// Validate the coinbase outputs generated by miners. + /// Check the sum of coinbase-marked outputs match + /// the sum of coinbase-marked kernels accounting for fees. pub fn verify_coinbase(&self) -> Result<(), Error> { let cb_outs = self.outputs .iter() @@ -793,23 +790,27 @@ impl Block { .filter(|kernel| kernel.features.contains(KernelFeatures::COINBASE_KERNEL)) .collect::>(); - let over_commit; - let out_adjust_sum; - let kerns_sum; { let secp = static_secp_instance(); let secp = secp.lock().unwrap(); - over_commit = secp.commit_value(reward(self.total_fees()))?; - out_adjust_sum = secp.commit_sum( + let over_commit = secp.commit_value(reward(self.total_fees()))?; + + let out_adjust_sum = secp.commit_sum( cb_outs.iter().map(|x| x.commitment()).collect(), vec![over_commit], )?; - kerns_sum = secp.commit_sum(cb_kerns.iter().map(|x| x.excess).collect(), vec![])?; + + let kerns_sum = secp.commit_sum( + cb_kerns.iter().map(|x| x.excess).collect(), + vec![], + )?; + + // Verify the kernel sum equals the output sum accounting for block fees. + if kerns_sum != out_adjust_sum { + return Err(Error::CoinbaseSumMismatch); + } } - if kerns_sum != out_adjust_sum { - return Err(Error::CoinbaseSumMismatch); - } Ok(()) } }