Skip to content

Commit

Permalink
blockchain: Fix bogus error message.
Browse files Browse the repository at this point in the history
In the presence of overflow, the actual output sum is still not
negative and should not be reported as so.
  • Loading branch information
jrick committed Nov 9, 2015
1 parent 756f58b commit 23bcb36
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions blockchain/validate.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 23bcb36

Please sign in to comment.