From 23bcb367b230e522b987ba9db5fb9bbcf15a58a3 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 6 Nov 2015 17:16:07 -0500 Subject: [PATCH] blockchain: Fix bogus error message. In the presence of overflow, the actual output sum is still not negative and should not be reported as so. --- blockchain/validate.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/blockchain/validate.go b/blockchain/validate.go index 395ef908..98beba53 100644 --- a/blockchain/validate.go +++ b/blockchain/validate.go @@ -240,13 +240,14 @@ func CheckTransactionSanity(tx *btcutil.Tx) error { return ruleError(ErrBadTxOutValue, str) } - // TODO(davec): No need to check < 0 here as satoshi is - // guaranteed to be positive per the above check. Also need - // to add overflow checks. + // Two's complement int64 overflow guarantees that any overflow + // is detected and reported. This is impossible for Bitcoin, but + // perhaps possible if an alt increases the total money supply. totalSatoshi += satoshi if totalSatoshi < 0 { str := fmt.Sprintf("total value of all transaction "+ - "outputs has negative value of %v", totalSatoshi) + "outputs exceeds max allowed value of %v", + btcutil.MaxSatoshi) return ruleError(ErrBadTxOutValue, str) } if totalSatoshi > btcutil.MaxSatoshi {