Skip to content

Commit 7fdcfd4

Browse files
committed
fix: add check for controlBlock length
1 parent 12baabb commit 7fdcfd4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/payments/bip341.js

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ exports.LEAF_VERSION_TAPSCRIPT = 0xc0;
1010
exports.MAX_TAPTREE_DEPTH = 128;
1111
const isHashBranch = ht => 'left' in ht && 'right' in ht;
1212
function rootHashFromPath(controlBlock, leafHash) {
13+
if (controlBlock.length < 33)
14+
throw new TypeError(
15+
`The control-block length is too small. Got ${
16+
controlBlock.length
17+
}, expected min 33.`,
18+
);
1319
const m = (controlBlock.length - 33) / 32;
1420
let kj = leafHash;
1521
for (let j = 0; j < m; j++) {

ts_src/payments/bip341.ts

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export function rootHashFromPath(
3838
controlBlock: Buffer,
3939
leafHash: Buffer,
4040
): Buffer {
41+
if (controlBlock.length < 33)
42+
throw new TypeError(
43+
`The control-block length is too small. Got ${
44+
controlBlock.length
45+
}, expected min 33.`,
46+
);
4147
const m = (controlBlock.length - 33) / 32;
4248

4349
let kj = leafHash;

0 commit comments

Comments
 (0)