-
Notifications
You must be signed in to change notification settings - Fork 419
Use non_witness_utxo when making SegWit signatures to mitigate the "SegWit bug"
#333
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
|
Concept ACK. I think there might be a simpler approach.
|
This was more or less how I implemented it initially, but there was the issue that signers like hardware wallets would basically ignore the options. I mean, I hope there's no way to ask an HW to sign a transaction while asking it to trust some parts without complaining 😅 So I came to the conclusion that this is more of a Signer-specific thing, we can control it for our signers but not for all of them. Maybe a good compromise is to have a
That's a good point |
I think you misunderstood my suggestion: put the check in pub fn sign(&self, mut psbt: PSBT, sign_options: SignOptions) -> Result<(PSBT, bool), Error> {
// this helps us doing our job later
self.add_input_hd_keypaths(&mut psbt)?;
if !sign_options.trust_witness_utxo {
for input in psbt.input {
if input.non_witness_utxo.is_none() {
return Err(Error::MissingNonWitnessUtxo)
}
}
}
for signer in self
.signers
.signers()
.iter()
.chain(self.change_signers.signers().iter())
{
if signer.sign_whole_tx() {
signer.sign(&mut psbt, None, &self.secp)?;
} else {
for index in 0..psbt.inputs.len() {
signer.sign(&mut psbt, Some(index), &self.secp)?;
}
}
}This means it doesn't matter whether they are hardware wallets at all. |
933b2c6 to
f23de96
Compare
2207755 to
89b5245
Compare
Instead of providing an opt-in option to force the addition of the `non_witness_utxo`, we will now add them by default and provide the option to disable them when they aren't considered necessary.
89b5245 to
17bcd8e
Compare
b1b1694 to
3c7bae9
Compare
Description
Unless explicitly asked not to (by enabling a signer option), we will now by default require the presence of the
non_witness_utxowhen signing SegWit transactions as well, to mitigate the risk of an attacker tricking the wallet into paying more fees than it expects.The
force_non_witness_utxooption which was off by default has been replaced withonly_witness_utxowhich is also disabled by default, but since it's basically the opposite of the one we had previously, it effectively inverts the default behavior from not including thenon_witness_utxoto providing it.Notes to the reviewers
This needed a bit of refactoring in the signing part to introduce some options that can be provided to tweak the behavior of the signer. I don't particularly like having that extra method on our
Signertrait, but I couldn't come up with a better alternative.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features:
CHANGELOG.md