diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index d836a7e4..ccbeae4a 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -698,7 +698,22 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, value, type } } - const size = 156 + prev.getVarSize(); + // Calculate the size of the transaction including the Flo Data + let fOmitTxComment = !!(type & hashType.OMIT_TX_COMMENT); + let floDataSize = 0 + if (!fOmitTxComment){ + let bufferLength = Buffer.from(this.strFloData).length; + + if (this.strFloData.length > 0){ + floDataSize += encoding.sizeVarint(bufferLength); + floDataSize += bufferLength + } else { + floDataSize += encoding.sizeVarint(0); + } + } + + const size = 156 + prev.getVarSize() + floDataSize; + const bw = StaticWriter.pool(size); bw.writeU32(this.version); @@ -712,14 +727,14 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, value, type bw.writeBytes(outputs); bw.writeU32(this.locktime); - var fOmitTxComment = !!(type & hashType.OMIT_TX_COMMENT); - + // Add the FloData to the transaction if (this.version >= 2 && !fOmitTxComment) { bw.writeVarBytes(Buffer.from(this.strFloData)); } + // Remove the OMIT_TX_COMMENT flag if included type &= ~hashType.OMIT_TX_COMMENT; - + bw.writeU32(type); return digest.hash256(bw.render()); diff --git a/lib/script/script.js b/lib/script/script.js index 2f71e3f0..f96eeccf 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -1175,14 +1175,19 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers try { hash = tx.signatureHash(index, subscript, value, type, version); res = checksig(hash, sig, key); - } catch (e) {} + } catch (e) { + // Having issues with signatures? Log this error then! + } if (!res){ type ^= Script.hashType.OMIT_TX_COMMENT; try { hash = tx.signatureHash(index, subscript, value, type, version); res = checksig(hash, sig, key); - } catch (e) {} + } catch (e) { + // Having issues with signatures? Log this error then! + throw new ScriptError('CHECKSIGVERIFY_ERROR', e) + } } }