Skip to content

Commit 5ff798c

Browse files
author
MarcoFalke
committed
Merge #17439: refactor: Use proper MAX_SCRIPT_ELEMENT_SIZE constants consistently
cb9d830 test: Use proper MAX_SCRIPT_ELEMENT_SIZE (Hennadii Stepanov) 402ee70 refactor: Use proper MAX_SCRIPT_ELEMENT_SIZE const (Hennadii Stepanov) Pull request description: This PR replaces well-known "magic" numbers with proper `MAX_SCRIPT_ELEMENT_SIZE` constants. ACKs for top commit: practicalswift: ACK cb9d830 -- diff looks correct and change appears to be complete instagibbs: utACK bitcoin/bitcoin@cb9d830 Tree-SHA512: 5fa033275d6df7e35962c38bfdf09a7b5cd7ef2ccdd5e30a39ba47d0c21ac779a5559c23f5ef5bfd4293be0fc639e836a308bbedf0e34717e1eead983b389bbd
2 parents b7bc9b8 + cb9d830 commit 5ff798c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/script/descriptor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,8 @@ std::unique_ptr<DescriptorImpl> ParseScript(Span<const char>& sp, ParseScriptCon
815815
}
816816
}
817817
if (ctx == ParseScriptContext::P2SH) {
818-
if (script_size + 3 > 520) {
819-
error = strprintf("P2SH script is too large, %d bytes is larger than 520 bytes", script_size + 3);
818+
if (script_size + 3 > MAX_SCRIPT_ELEMENT_SIZE) {
819+
error = strprintf("P2SH script is too large, %d bytes is larger than %d bytes", script_size + 3, MAX_SCRIPT_ELEMENT_SIZE);
820820
return nullptr;
821821
}
822822
}

test/functional/p2p_segwit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ def test_max_witness_program_length(self):
11161116
MAX_PROGRAM_LENGTH = 10000
11171117

11181118
# This program is 19 max pushes (9937 bytes), then 64 more opcode-bytes.
1119-
long_witness_program = CScript([b'a' * 520] * 19 + [OP_DROP] * 63 + [OP_TRUE])
1119+
long_witness_program = CScript([b'a' * MAX_SCRIPT_ELEMENT_SIZE] * 19 + [OP_DROP] * 63 + [OP_TRUE])
11201120
assert len(long_witness_program) == MAX_PROGRAM_LENGTH + 1
11211121
long_witness_hash = sha256(long_witness_program)
11221122
long_script_pubkey = CScript([OP_0, long_witness_hash])
@@ -1140,7 +1140,7 @@ def test_max_witness_program_length(self):
11401140
test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
11411141

11421142
# Try again with one less byte in the witness program
1143-
witness_program = CScript([b'a' * 520] * 19 + [OP_DROP] * 62 + [OP_TRUE])
1143+
witness_program = CScript([b'a' * MAX_SCRIPT_ELEMENT_SIZE] * 19 + [OP_DROP] * 62 + [OP_TRUE])
11441144
assert len(witness_program) == MAX_PROGRAM_LENGTH
11451145
witness_hash = sha256(witness_program)
11461146
script_pubkey = CScript([OP_0, witness_hash])

0 commit comments

Comments
 (0)