Test that parsing a transaction with superfluous witness data leads to an error
This commit is contained in:
parent
95059df96a
commit
a9f124423f
1 changed files with 5 additions and 13 deletions
|
@ -120,14 +120,12 @@ Transaction.fromBuffer = function (buffer, __noStrict) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasWitnesses) {
|
if (hasWitnesses) {
|
||||||
var isNull = true
|
|
||||||
for (i = 0; i < vinLen; ++i) {
|
for (i = 0; i < vinLen; ++i) {
|
||||||
tx.ins[i].witness = readVector()
|
tx.ins[i].witness = readVector()
|
||||||
isNull = isNull && tx.ins[i].witness.length === 0
|
|
||||||
}
|
|
||||||
if (isNull) {
|
|
||||||
throw new Error('Transaction has superfluous witness data')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// was this pointless?
|
||||||
|
if (!tx._hasWitnesses()) throw new Error('Transaction has superfluous witness data')
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.locktime = readUInt32()
|
tx.locktime = readUInt32()
|
||||||
|
@ -188,7 +186,7 @@ Transaction.prototype.addOutput = function (scriptPubKey, value) {
|
||||||
|
|
||||||
Transaction.prototype._hasWitnesses = function () {
|
Transaction.prototype._hasWitnesses = function () {
|
||||||
return this.ins.some(function (x) {
|
return this.ins.some(function (x) {
|
||||||
return x.witness !== EMPTY_WITNESS
|
return x.witness.length !== 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +410,6 @@ Transaction.prototype.toBuffer = function (buffer, initialOffset) {
|
||||||
writeInt32(this.version)
|
writeInt32(this.version)
|
||||||
|
|
||||||
var hasWitnesses = this._hasWitnesses()
|
var hasWitnesses = this._hasWitnesses()
|
||||||
var serializeWitnesses = hasWitnesses // TODO: remove this, temporary
|
|
||||||
|
|
||||||
if (hasWitnesses) {
|
if (hasWitnesses) {
|
||||||
writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)
|
writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)
|
||||||
|
@ -439,15 +436,10 @@ Transaction.prototype.toBuffer = function (buffer, initialOffset) {
|
||||||
writeVarSlice(txOut.script)
|
writeVarSlice(txOut.script)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (serializeWitnesses) {
|
if (hasWitnesses) {
|
||||||
var isNull = true
|
|
||||||
this.ins.forEach(function (input) {
|
this.ins.forEach(function (input) {
|
||||||
writeVector(input.witness)
|
writeVector(input.witness)
|
||||||
isNull = isNull && input.witness.length === 0
|
|
||||||
})
|
})
|
||||||
if (isNull) {
|
|
||||||
throw new Error('Transaction has superfluous witness data')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writeUInt32(this.locktime)
|
writeUInt32(this.locktime)
|
||||||
|
|
Loading…
Add table
Reference in a new issue