Skip to content

Commit 94cd41a

Browse files
committed
ensure transaction amount and inputs not empty
1 parent 1c47831 commit 94cd41a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

common/transaction.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func (tx *SignedTransaction) Validate(store DataStore) error {
8888
return fmt.Errorf("invalid tx version %d", tx.Version)
8989
}
9090

91+
if len(tx.Inputs) < 1 || len(tx.Outputs) < 1 {
92+
return fmt.Errorf("invalid tx inputs or outputs %d %d", len(tx.Inputs), len(tx.Outputs))
93+
}
94+
9195
if len(tx.Inputs) != len(tx.Signatures) {
9296
return fmt.Errorf("invalid tx signature number %d %d", len(tx.Inputs), len(tx.Signatures))
9397
}
@@ -206,7 +210,7 @@ func (tx *SignedTransaction) Validate(store DataStore) error {
206210
}
207211
}
208212

209-
if inputAmount.Cmp(outputAmount) != 0 {
213+
if inputAmount.Sign() <= 0 || inputAmount.Cmp(outputAmount) != 0 {
210214
return fmt.Errorf("invalid input output amount %s %s", inputAmount.String(), outputAmount.String())
211215
}
212216
return nil

0 commit comments

Comments
 (0)