-
Notifications
You must be signed in to change notification settings - Fork 0
Merge bitcoin/bitcoin#28193: test: add script compression coverage for not-on-curve P2PK outputs #1117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: backport-0.28-batch-740
Are you sure you want to change the base?
Merge bitcoin/bitcoin#28193: test: add script compression coverage for not-on-curve P2PK outputs #1117
Conversation
…-curve P2PK outputs 28287cf test: add script compression coverage for not-on-curve P2PK outputs (Sebastian Falbesoner) Pull request description: This PR adds unit test coverage for the script compression functions `{Compress,Decompress}Script` in the special case of uncompressed P2PK outputs (scriptPubKey: OP_PUSH65 <0x04 ....> OP_CHECKSIG) with [pubkeys that are not fully valid](https://github.com/bitcoin/bitcoin/blob/44b05bf3fef2468783dcebf651654fdd30717e7e/src/pubkey.cpp#L297-L302), i.e. where the encoded point is not on the secp256k1 curve. For those outputs, script compression is not possible, as the y coordinate of the pubkey can't be recovered (see also call-site of `IsToPubKey`): https://github.com/bitcoin/bitcoin/blob/44b05bf3fef2468783dcebf651654fdd30717e7e/src/compressor.cpp#L49-L50 Likewise, for a compressed script of an uncompressed P2PK script (i.e. compression ids 4 and 5) where the x coordinate is not on the curve, decompression fails: https://github.com/bitcoin/bitcoin/blob/44b05bf3fef2468783dcebf651654fdd30717e7e/src/compressor.cpp#L122-L129 Note that the term "compression" is used here in two different meanings (though they are related), which might be a little confusing. The encoding of a pubkey can either be compressed (33-bytes with 0x02/0x03 prefixes) or uncompressed (65-bytes with 0x04 prefix). On the other hand there is also compression for whole output scripts, which is used for storing scriptPubKeys in the UTXO set in a compact way (and also for the `dumptxoutset` result, accordingly). P2PK output scripts with uncompressed pubkeys get compressed by storing only the x-coordinate and the sign as a prefix (0x04 = even, 0x05 = odd). Was diving deeper into the subject while working on bitcoin#27432, where the script decompression of uncompressed P2PK needed special handling (see also bitcoin#24628 (comment)). Trivia: as of now (block 801066), there are 13 uncompressed P2PK outputs in the UTXO set with a pubkey not on the curve (which obviously means they are unspendable). ACKs for top commit: achow101: ACK 28287cf tdb3: ACK for 28287cf. cbergqvist: ACK 28287cf! marcofleon: Nicely done, ACK 28287cf. Built the PR branch, ran the unit and functional tests, everything passed. Tree-SHA512: 777b6c3065654fbfa1ce94926f4cadb91a9ca9dc4dd4af6008ad77bd1da5416f156ad0dfa880d26faab2e168bf9b27e0a068abc9a2be2534d82bee61ee055c65
WalkthroughA new test case was added to the compression tests, specifically targeting the handling of Pay-to-PubKey (P2PK) scripts containing uncompressed public keys that are not fully valid (i.e., points not on the elliptic curve). The test verifies that compression and decompression functions correctly reject such invalid keys. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (3)src/**/*.{cpp,h,cc,cxx,hpp}📄 CodeRabbit Inference Engine (CLAUDE.md)
Files:
src/{test,wallet/test,qt/test}/**/*.{cpp,h,cc,cxx,hpp}📄 CodeRabbit Inference Engine (CLAUDE.md)
Files:
**⚙️ CodeRabbit Configuration File
Files:
🧠 Learnings (6)📓 Common learnings📚 Learning: 2025-07-28T20:34:29.061ZApplied to files:
📚 Learning: 2025-07-28T22:03:12.364ZApplied to files:
📚 Learning: 2025-07-30T14:45:15.700ZApplied to files:
📚 Learning: 2025-07-29T21:29:32.827ZApplied to files:
📚 Learning: 2025-07-28T23:09:09.522ZApplied to files:
🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Backport Verification SuccessfulNo issues found! This backport is complete and faithful to the original Bitcoin change. Original Bitcoin commit: Verification Details:
Reviewer Feedback Analysis:PastaPastaPasta comments reviewed: 0 No reviewer feedback requiring action. Backport Quality Assessment:
This PR adds comprehensive test coverage for script compression functions in the special case of uncompressed P2PK outputs with pubkeys that are not on the secp256k1 curve. The backport is faithful to Bitcoin's original implementation. This PR is ready for merge. ✅ |
Issues Found1. ✅ Missing Dependency Fixed
2. ❌ Bitcoin-Only Feature Dependency
Validation Results
RecommendationThis backport requires manual review to either:
🚫 CI Check: 5 jobs failing (threshold: max 1 allowed) |
Backports bitcoin#28193
Original commit: ef6329f
Backported from Bitcoin Core v0.28
Summary by CodeRabbit