From 94cd41aa353125cd7dfe6a289369d6469dea33ab Mon Sep 17 00:00:00 2001 From: Cedric Fung Date: Fri, 15 Mar 2019 16:17:06 +0800 Subject: [PATCH] ensure transaction amount and inputs not empty --- common/transaction.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/transaction.go b/common/transaction.go index 36c435e07..7b8fe53ca 100644 --- a/common/transaction.go +++ b/common/transaction.go @@ -88,6 +88,10 @@ func (tx *SignedTransaction) Validate(store DataStore) error { return fmt.Errorf("invalid tx version %d", tx.Version) } + if len(tx.Inputs) < 1 || len(tx.Outputs) < 1 { + return fmt.Errorf("invalid tx inputs or outputs %d %d", len(tx.Inputs), len(tx.Outputs)) + } + if len(tx.Inputs) != len(tx.Signatures) { return fmt.Errorf("invalid tx signature number %d %d", len(tx.Inputs), len(tx.Signatures)) } @@ -206,7 +210,7 @@ func (tx *SignedTransaction) Validate(store DataStore) error { } } - if inputAmount.Cmp(outputAmount) != 0 { + if inputAmount.Sign() <= 0 || inputAmount.Cmp(outputAmount) != 0 { return fmt.Errorf("invalid input output amount %s %s", inputAmount.String(), outputAmount.String()) } return nil