-
Notifications
You must be signed in to change notification settings - Fork 878
Add support for pay to anchor outputs #4111
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
Conversation
a4f2d09
to
9c351f2
Compare
Pull Request Test Coverage Report for Build 13561507629Details
💛 - Coveralls |
9c351f2
to
e7c49b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, the code looks good too except for one issue.
bitcoin/src/address/script_pubkey.rs
Outdated
// In SegWit v0, the program must be either 2, 20 or 32 bytes long | ||
debug_assert!( | ||
version != WitnessVersion::V0 || | ||
program.len() == 2 || program.len() == 20 || program.len() == 32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is incorrect. P2A is WitnessVersion::V1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, I think we need a separate assertion for Segwit v1 witness programs ( P2TR, P2A)
Something like this:
// In SegWit v0, the program must be either 20 or 32 bytes long (P2WPKH/P2WSH)
debug_assert!(version != WitnessVersion::V0 || program.len() == 20 || program.len() == 32);
// In SegWit v1, the program must be either 2 bytes (P2A) or 32 bytes (P2TR)
debug_assert!(version != WitnessVersion::V1 || program.len() == 2 || program.len() == 32);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a great catch. I've adapted the PR
e7c49b9
to
34cce11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 34cce11
If you're in the mood you could also check if this can be backported backwards-compatibly. I have an application in mind that could use it.
@@ -105,6 +108,11 @@ impl WitnessProgram { | |||
WitnessProgram::new_p2tr(pubkey) | |||
} | |||
|
|||
/// Constructs a new pay to anchor address | |||
pub fn p2a() -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be possible to make it const
but that might require some modifications to ArrayVec
, so I'm not requiring it. Similarly, we could have a const
on Script
, but that's just extra, so not required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was easier as expected. Apprantly ArrayVec::from_slice
is already const
.
// Verify that the address is considered standard | ||
// and that the output type is P2a | ||
assert!(address.is_spend_standard()); | ||
assert_eq!(address.address_type(), Some(AddressType::P2a)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing address.to_string()
would be nice too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comparision for address.to_string()
ab0eaeb
to
83d7ebb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 83d7ebb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 83d7ebb
Thanks for the contribution! I created a follow up issue to this PR: #4124. I did so intentionally instead of asking for changes so as not to slow down this PR. We appreciate the effort you went to. You are most welcome to attack the follow up but do not feel obliged. Thanks again! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts crossed my mind and I did some more digging. Unfortunately, this is not right.
@@ -25,6 +25,9 @@ pub const MIN_SIZE: usize = 2; | |||
/// The maximum byte size of a segregated witness program. | |||
pub const MAX_SIZE: usize = 40; | |||
|
|||
/// The P2A program which is given by 0x4e73 | |||
pub const P2A_PROGRAM: [u8;2] = [78, 115]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I have now noticed this is public. I don't think it's very helpful and adds noise to docs. I'd prefer to keep it private until there's a use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the P2A_PROGRAM
in another module. I have modified to pub(crate)
bitcoin/src/address/script_pubkey.rs
Outdated
debug_assert!(version != WitnessVersion::V0 || program.len() == 20 || program.len() == 32); | ||
// In SegWit v1, the program must be either 2 bytes (P2A) or 32 bytes (P2TR) | ||
debug_assert!(version != WitnessVersion::V1 || program.len() == 2 || program.len() == 32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just realized this entire check is bogus and should be deleted. For witness versions > 0 receiving is standard to ensure future compatibility but this check (even if in debug) undermines that compatibility. It's also the reason it wasn't here in the first place. (And perhaps a reason to write a comment "other versions intentionally not checked" to avoid this mistake again.) The check only makes sense for v0 because that one makes different lengths unspendable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 83d7ebb; successfully ran local tests
Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
f7ea6e5
83d7ebb
to
f7ea6e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f7ea6e5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f7ea6e5; successfully ran local tests
Manually backport PR rust-bitcoin#4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
Manually backport PR rust-bitcoin#4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. Note the `WitnessProgram::p2a` is conditionally const on Rust `v1.61` because MSRV is only `v1.56.1`. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
Manually backport PR rust-bitcoin#4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. Note the `WitnessProgram::p2a` is conditionally const on Rust `v1.61` because MSRV is only `v1.56.1`. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352
c2481e4 backport: Add support for pay to anchor outputs (Tobin C. Harding) Pull request description: Manually backport PR #4111. Of note, here we put `new_p2a` on `ScriptBuf` instead of on the `script::Builder` because that seems to be where all the other `new_foo` methods are in this release. From the original patch: Add support for the newly created Pay2Anchor output-type. See bitcoin/bitcoin#30352 ACKs for top commit: apoelstra: ACK c2481e4; successfully ran local tests Tree-SHA512: 016919914750adf6f8226acb4e6b36c0dcd8ce230df8cca13f19bcc97709caf07a076be367c76f9519a421fc93fdf73caa078ee65a85a750af7a9d9e6c757e75
Add support for the newly created Pay2Anchor output-type which was introduced in bitcoin 28.0
See bitcoin/bitcoin#30352