Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
ea33da6 to
6a30cea
Compare
Not sure, reusing a destination would be an unrelated bug? So I am half suggesting to drop the test in a third commit again, or at least clarify in the comment that this isn't supposed to test any real production behavior. lgtm either way. |
6a30cea to
f313faf
Compare
We do have some existing reuses, e.g. in bitcoin/src/rpc/blockchain.cpp Lines 3435 to 3462 in e7aef7e Coin in the loop. Regardless, added a comment clarifying that this tests the fallback directly, since normal UTXO insertion excludes oversized scripts.
|
| { | ||
| // Test the fallback directly, since normal UTXO insertion excludes oversized scripts | ||
| CScript restored{ParseScript("0x01")}; // Incomplete push: appending OP_RETURN would make it pushed data | ||
| (DataStream{} << Using<ScriptCompression>(CScript{CScript() << std::vector(MAX_SCRIPT_SIZE + 1, uint8_t{0})})) >> Using<ScriptCompression>(restored); |
There was a problem hiding this comment.
This has a bit too much happening at once IMO (+ redundant CScript-ctor-call). Would rather have something closer to
| (DataStream{} << Using<ScriptCompression>(CScript{CScript() << std::vector(MAX_SCRIPT_SIZE + 1, uint8_t{0})})) >> Using<ScriptCompression>(restored); | |
| DataStream oversized_compressed{DataStream{} << Using<ScriptCompression>(CScript{} << std::vector(MAX_SCRIPT_SIZE + 1, uint8_t{0}))}; | |
| oversized_compressed >> Using<ScriptCompression>(restored); |
| CScript restored{ParseScript("0x01")}; // Incomplete push: appending OP_RETURN would make it pushed data | ||
| (DataStream{} << Using<ScriptCompression>(CScript{CScript() << std::vector(MAX_SCRIPT_SIZE + 1, uint8_t{0})})) >> Using<ScriptCompression>(restored); |
There was a problem hiding this comment.
nit: Could verify that restored starts out spendable before the compression round-trip makes it unspendable?
| CScript restored{ParseScript("0x01")}; // Incomplete push: appending OP_RETURN would make it pushed data | |
| (DataStream{} << Using<ScriptCompression>(CScript{CScript() << std::vector(MAX_SCRIPT_SIZE + 1, uint8_t{0})})) >> Using<ScriptCompression>(restored); | |
| CScript restored{ParseScript("0x01")}; // Incomplete push: appending OP_RETURN would make it pushed data | |
| BOOST_CHECK(!restored.IsUnspendable()); | |
| (DataStream{} << Using<ScriptCompression>(CScript{CScript() << std::vector(MAX_SCRIPT_SIZE + 1, uint8_t{0})})) >> Using<ScriptCompression>(restored); |
| // Test the fallback directly, since normal UTXO insertion excludes oversized scripts | ||
| CScript restored{ParseScript("0x01")}; // Incomplete push: appending OP_RETURN would make it pushed data | ||
| (DataStream{} << Using<ScriptCompression>(CScript{CScript() << std::vector(MAX_SCRIPT_SIZE + 1, uint8_t{0})})) >> Using<ScriptCompression>(restored); | ||
| BOOST_CHECK(restored.IsUnspendable()); |
There was a problem hiding this comment.
Ralph suggested also pinning down the resulting script (https://git.fish.foo/bitcoin/bitcoin/pulls/36386#issuecomment-608275), which seems fair enough.
Guess it could be done through:
| BOOST_CHECK(restored.IsUnspendable()); | |
| BOOST_CHECK(restored.IsUnspendable()); | |
| const CScript expected{OP_RETURN}; | |
| BOOST_CHECK_EQUAL_COLLECTIONS(restored.begin(), restored.end(), expected.begin(), expected.end()); |
f313faf to
426f29c
Compare
|
tACK 426f29c I decoded 1307 compressed scripts (raw sizes 0 to 39 and from just under One path still depends on the target: an uncompressed P2PK (type 4 or 5) whose x is not on the curve leaves a reused target untouched, so a P2PKH stays a P2PKH. #36280 makes that path throw. Its |
| BOOST_AUTO_TEST_CASE(compress_oversized_script) | ||
| { | ||
| // Test the fallback directly, since normal UTXO insertion excludes oversized scripts | ||
| CScript restored{ParseScript("0x01")}; // Incomplete push: appending OP_RETURN would make it pushed data |
There was a problem hiding this comment.
nit: Could compute at compile time:
--- a/src/test/compress_tests.cpp
+++ b/src/test/compress_tests.cpp
@@ -28,6 +28,8 @@
// amounts 50 .. 21000000
#define NUM_MULTIPLES_50BTC 420000
+using namespace util::hex_literals;
+
BOOST_FIXTURE_TEST_SUITE(compress_tests, BasicTestingSetup)
bool static TestEncode(uint64_t in) {
@@ -172,7 +174,7 @@ BOOST_AUTO_TEST_CASE(compress_p2pk_scripts_not_on_curve)
BOOST_AUTO_TEST_CASE(compress_oversized_script)
{
// Test the fallback directly, since normal UTXO insertion excludes oversized scripts
- CScript restored{ParseScript("0x01")}; // Incomplete push: appending OP_RETURN would make it pushed data
+ auto restored{CScript{} << "01"_hex}; // Incomplete push: appending OP_RETURN would make it pushed data
BOOST_CHECK(!restored.IsUnspendable());
DataStream oversized_compressed{DataStream{} << Using<ScriptCompression>(CScript{} << std::vector(MAX_SCRIPT_SIZE + 1, uint8_t{0}))};
oversized_compressed >> Using<ScriptCompression>(restored);|
review ACK 426f29c 🏉 Show signatureSignature: |
| if (nSize > MAX_SCRIPT_SIZE) { | ||
| // Overly long script, replace with a short invalid one | ||
| script << OP_RETURN; | ||
| script = CScript{OP_RETURN}; |
There was a problem hiding this comment.
426f29c compressor: replace oversized scripts instead of appending:
Would it be possible to clear the script output variable at the beginning of this method? That would ensure the claim (independence of previous value).
sedited
left a comment
There was a problem hiding this comment.
Not sure why this should be changed from the motivation provided here. If I understand this correctly, the only way to encounter an oversized script outside of loadtxoutset is corruption. Why not just throw in that case? Deserializing potentially corrupt entries as unspendable seems confusing to me in the first place.
Even if this happens inside loadtxoutset, such a utxo-file is still only possible after corruption. While reviewing this I thought that this was needed to gracefully upgrade ancient utxo dbs, and looking at the diff of #7933, it seems that was accurate? However, according to |
Record that decompression accepts scripts larger than MAX_SCRIPT_SIZE. Valid UTXO records cannot contain these scripts.
Valid UTXO records exclude oversized scripts because they are unspendable. Reject the corrupt record with a deserialization error instead of replacing it with the `OP_RETURN` fallback.
426f29c to
777ede5
Compare
I really hated that ugly, hacky |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |

Problem: UTXO insertion excludes scripts larger than
MAX_SCRIPT_SIZEas unspendable, so an oversized compressed script indicates corrupt data. Deserialization currently uses anOP_RETURNfallback and skips the oversized payload, hiding the corruption.Fix: Throw
std::ios_base::failureas soon as the decoded script length exceedsMAX_SCRIPT_SIZE.Context: #7933 added the fallback to avoid an out-of-memory failure in the then-current per-transaction chainstate format, when coin database deserialization errors were indistinguishable from missing entries. #34931 now sends coin deserialization failures to the fatal database-error path, and #24236 removed upgrade support for that old format.