Handle bad input in sighash single.
The bitcoinj test suite actually uses it (the only thing i've seen that does). Specifically it uses it with a bad input which returns a hash of 1.
This commit is contained in:
parent
22c29c4316
commit
927d846f06
1 changed files with 12 additions and 1 deletions
13
script.go
13
script.go
|
@ -653,7 +653,18 @@ func (s *Script) calcScriptHash(script []parsedOpcode, hashType byte) []byte {
|
|||
}
|
||||
}
|
||||
case SigHashSingle:
|
||||
// resize output array to up to and including current output
|
||||
if txidx >= len(txCopy.TxOut) {
|
||||
// This was created by a buggy implementation.
|
||||
// In this case we do the same as bitcoind and bitcoinj
|
||||
// and return 1 (as a uint256 little endian) as an
|
||||
// error. Unfortunately this was not checked anywhere
|
||||
// and thus is treated as the actual
|
||||
// hash.
|
||||
hash := make([]byte, 32)
|
||||
hash[0] = 0x01
|
||||
return hash
|
||||
}
|
||||
// Resize output array to up to and including requested index.
|
||||
txCopy.TxOut = txCopy.TxOut[:txidx+1]
|
||||
// all but current output get zeroed out
|
||||
for i := 0; i < txidx; i++ {
|
||||
|
|
Loading…
Reference in a new issue