From 84a732e636c28c6ed274b91b8fcd9d2f53bd9ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BC=9F=E6=B0=91?= Date: Fri, 5 Apr 2019 20:53:12 +0800 Subject: [PATCH] fix Transaction.Verify bug --- transaction.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/transaction.go b/transaction.go index 107f0154..79ab07e2 100644 --- a/transaction.go +++ b/transaction.go @@ -145,8 +145,15 @@ func (tx *Transaction) Verify(prevTXs map[string]Transaction) bool { for inID, vin := range tx.Vin { prevTx := prevTXs[hex.EncodeToString(vin.Txid)] + refVoutPubKeyHash := prevTx.Vout[vin.Vout].PubKeyHash + + // check that the spend coin is owned by vin.PubKey + if !bytes.Equal(HashPubKey(vin.PubKey), refVoutPubKeyHash) { + return false + } + txCopy.Vin[inID].Signature = nil - txCopy.Vin[inID].PubKey = prevTx.Vout[vin.Vout].PubKeyHash + txCopy.Vin[inID].PubKey = refVoutPubKeyHash r := big.Int{} s := big.Int{}