Skip to content

Commit a189ee0

Browse files
authored
Merge pull request #1802 from bitcoinjs/fix/p2sh-empty
Fix: Interpret P2SH redeemscript === OP_FALSE as empty Buffer.
2 parents bb0f57c + cafa6bd commit a189ee0

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/payments/p2sh.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ function p2sh(a, opts) {
5858
});
5959
const _redeem = lazy.value(() => {
6060
const chunks = _chunks();
61+
const lastChunk = chunks[chunks.length - 1];
6162
return {
6263
network,
63-
output: chunks[chunks.length - 1],
64+
output: lastChunk === OPS.OP_FALSE ? Buffer.from([]) : lastChunk,
6465
input: bscript.compile(chunks.slice(0, -1)),
6566
witness: a.witness || [],
6667
};

test/fixtures/p2sh.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,17 @@
289289
}
290290
},
291291
{
292-
"exception": "Input is invalid",
292+
"exception": "Redeem.output too short",
293293
"arguments": {
294294
"input": "OP_0 OP_0"
295295
}
296296
},
297+
{
298+
"exception": "Input is invalid",
299+
"arguments": {
300+
"input": "OP_0 OP_3"
301+
}
302+
},
297303
{
298304
"exception": "Redeem.input mismatch",
299305
"arguments": {

ts_src/payments/p2sh.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ export function p2sh(a: Payment, opts?: PaymentOpts): Payment {
6868
const _redeem = lazy.value(
6969
(): Payment => {
7070
const chunks = _chunks();
71+
const lastChunk = chunks[chunks.length - 1];
7172
return {
7273
network,
73-
output: chunks[chunks.length - 1] as Buffer,
74+
output:
75+
lastChunk === OPS.OP_FALSE ? Buffer.from([]) : (lastChunk as Buffer),
7476
input: bscript.compile(chunks.slice(0, -1)),
7577
witness: a.witness || [],
7678
};

0 commit comments

Comments
 (0)