mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
Merge #17439: refactor: Use proper MAX_SCRIPT_ELEMENT_SIZE constants consistently
cb9d830a00
test: Use proper MAX_SCRIPT_ELEMENT_SIZE (Hennadii Stepanov)402ee706d8
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: ACKcb9d830a00
-- diff looks correct and change appears to be complete instagibbs: utACKcb9d830a00
Tree-SHA512: 5fa033275d6df7e35962c38bfdf09a7b5cd7ef2ccdd5e30a39ba47d0c21ac779a5559c23f5ef5bfd4293be0fc639e836a308bbedf0e34717e1eead983b389bbd
This commit is contained in:
commit
5ff798c39b
2 changed files with 4 additions and 4 deletions
|
@ -815,8 +815,8 @@ std::unique_ptr<DescriptorImpl> ParseScript(Span<const char>& sp, ParseScriptCon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ctx == ParseScriptContext::P2SH) {
|
if (ctx == ParseScriptContext::P2SH) {
|
||||||
if (script_size + 3 > 520) {
|
if (script_size + 3 > MAX_SCRIPT_ELEMENT_SIZE) {
|
||||||
error = strprintf("P2SH script is too large, %d bytes is larger than 520 bytes", script_size + 3);
|
error = strprintf("P2SH script is too large, %d bytes is larger than %d bytes", script_size + 3, MAX_SCRIPT_ELEMENT_SIZE);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1116,7 +1116,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
MAX_PROGRAM_LENGTH = 10000
|
MAX_PROGRAM_LENGTH = 10000
|
||||||
|
|
||||||
# This program is 19 max pushes (9937 bytes), then 64 more opcode-bytes.
|
# This program is 19 max pushes (9937 bytes), then 64 more opcode-bytes.
|
||||||
long_witness_program = CScript([b'a' * 520] * 19 + [OP_DROP] * 63 + [OP_TRUE])
|
long_witness_program = CScript([b'a' * MAX_SCRIPT_ELEMENT_SIZE] * 19 + [OP_DROP] * 63 + [OP_TRUE])
|
||||||
assert len(long_witness_program) == MAX_PROGRAM_LENGTH + 1
|
assert len(long_witness_program) == MAX_PROGRAM_LENGTH + 1
|
||||||
long_witness_hash = sha256(long_witness_program)
|
long_witness_hash = sha256(long_witness_program)
|
||||||
long_script_pubkey = CScript([OP_0, long_witness_hash])
|
long_script_pubkey = CScript([OP_0, long_witness_hash])
|
||||||
|
@ -1140,7 +1140,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
|
test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
|
||||||
|
|
||||||
# Try again with one less byte in the witness program
|
# Try again with one less byte in the witness program
|
||||||
witness_program = CScript([b'a' * 520] * 19 + [OP_DROP] * 62 + [OP_TRUE])
|
witness_program = CScript([b'a' * MAX_SCRIPT_ELEMENT_SIZE] * 19 + [OP_DROP] * 62 + [OP_TRUE])
|
||||||
assert len(witness_program) == MAX_PROGRAM_LENGTH
|
assert len(witness_program) == MAX_PROGRAM_LENGTH
|
||||||
witness_hash = sha256(witness_program)
|
witness_hash = sha256(witness_program)
|
||||||
script_pubkey = CScript([OP_0, witness_hash])
|
script_pubkey = CScript([OP_0, witness_hash])
|
||||||
|
|
Loading…
Add table
Reference in a new issue