Skip to content

Commit 8d13bd7

Browse files
committed
Rename sha256cat to reduce_merkle_layer
1 parent 230532d commit 8d13bd7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

matt/script_helpers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ def drop(n: int = 1) -> CScript:
3232

3333
# x_0, x_1, ..., x_{n-1} -- sha256(x_0 || x_1), sha256(x_2 || x_3), ...
3434
# if n is odd, the last element is copied unchanged
35-
def sha256cat(n: int) -> CScript:
35+
def reduce_merkle_layer(n: int) -> CScript:
3636
assert n >= 1
3737

3838
if n == 1:
3939
return CScript([])
4040
elif n == 2:
4141
return CScript([OP_CAT, OP_SHA256])
4242
if n % 2 == 1:
43-
return CScript([OP_TOALTSTACK, *sha256cat(n-1), OP_FROMALTSTACK])
43+
return CScript([OP_TOALTSTACK, *reduce_merkle_layer(n-1), OP_FROMALTSTACK])
4444
else:
4545
# compute the last pair, reduce to the case with one less pair
46-
return CScript([OP_CAT, OP_SHA256, OP_TOALTSTACK, *sha256cat(n-2), OP_FROMALTSTACK])
46+
return CScript([OP_CAT, OP_SHA256, OP_TOALTSTACK, *reduce_merkle_layer(n-2), OP_FROMALTSTACK])
4747

4848

4949
# x_0, x_1, ..., x_{n - 1} -- x_0, x_1, ..., x_{n - 1} root
@@ -55,7 +55,7 @@ def merkle_root(n_leaves: int) -> CScript:
5555
ret = []
5656
# compute layer by layer, from the bottom up to the root
5757
while n_leaves > 1:
58-
ret.extend(sha256cat(n_leaves))
58+
ret.extend(reduce_merkle_layer(n_leaves))
5959
n_leaves = (n_leaves + 1) // 2
6060
return CScript(ret)
6161

0 commit comments

Comments
 (0)