-
Notifications
You must be signed in to change notification settings - Fork 44
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
Question: Finalizing a fully signed PSBT #469
Comments
Moving this to the Rust bdk repo for better visibility. |
You said you are using a dummy descriptor unrelated to the given inputs of the PSBT, but your PSBT is missing a "final script sig" or "final script witness" (decode with https://bip174.org/). In the BDK code if both of these are missing for an input it tries to create them from your descriptor, but since you aren't using a matching descriptor this is likely why the finalize fails. See the finalize logic check here: https://github.com/bitcoindevkit/bdk/blob/2a8c8c2bb6041a800c596c90139af9b086179e90/src/wallet/mod.rs#L1229 |
How are you finalizing the PSBT with Sparrow? did you use a wallet that has a valid descriptor for the PSBT? |
Sparrow can finalize it without any wallet. And the bitcointx library can too: from bitcointx.core.psbt import (
PartiallySignedTransaction as TXPartiallySignedTransaction,
)
psbt_data = "cHNidP8BAIkBAAAAATuuOwH+YN3lM9CHZuaxhXU+P/xWQQUpwldxTxng2/NWAAAAAAD9////AhAnAAAAAAAAIgAgbnxIFWJ84RPQEHQJIBWYVALEGgr6e99xVLT2DDykpha+kQ0AAAAAACIAIH+2seEetNM9J6mtfXwz2EwP7E1gqjpvr0HHI97D3b5IcwAAAAABAP2HAQEAAAAAAQHSc/5077HT+IqRaNwhhb9WuzlFYINsZk1BxhahFNsqlQAAAAAA/f///wKYuQ0AAAAAACIAIKteOph2G5lDpTD98oWJkrif3i6FX/eHTr2kmU4KN1w1oIYBAAAAAAAiACBYU+aHAWVhSe4DMfwzQhq9NzO6smI694/A7MoURBK4nAQARzBEAiBFFZVQQjC5SlDRCAuC5AkoQgMXyrG54gp71Ro2W6g0fgIgTbg94g7liL0T7DwEeWqOiJfurgpuTv1Q+7bAzFlV/yQBRzBEAiB76jOyWL28VWQzn32ITyy4JlRYAASEaPB9C7mANDLtzAIgCjyov+Y9xRQicB2+v0iDA09RcC7hQHzLxXA9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X9QY+zC5br755VTKeAPRz05JV0MAAAgAEAAIAAAACAAgAAgAAAAAAHAAAAIgIDHSnh2CYwJ5xK2W0KK3A+ddEd6ju4zLbrS6dad7iGRJkcJZfkKTAAAIABAACAAAAAgAIAAIAAAAAABwAAACICA3eBBjx8GKzvNoyDo89SlQGapVMV4cvzxm2uSYZggi1YHCbr+SowAACAAQAAgAAAAIACAACAAAAAAAcAAAAAAQFpUiECpfNLzexJfZ5G++SEVaypCms5w4g/8ExmROHke623xxEhAzc7rxaDI9x7Lvd7U3faPs9e34DNsrDE/V2mRVYn0WLvIQNkHWK1/HMUBxz9Cbs7elmC528iAQWIW104ND9B6ZI1+lOuIgICpfNLzexJfZ5G++SEVaypCms5w4g/8ExmROHke623xxEcJuv5KjAAAIABAACAAAAAgAIAAIABAAAABAAAACICAzc7rxaDI9x7Lvd7U3faPs9e34DNsrDE/V2mRVYn0WLvHPTklXQwAACAAQAAgAAAAIACAACAAQAAAAQAAAAiAgNkHWK1/HMUBxz9Cbs7elmC528iAQWIW104ND9B6ZI1+hwll+QpMAAAgAEAAIAAAACAAgAAgAEAAAAEAAAAAA=="
# Decode the PSBT from base64 to a PSBT object.
psbt = TXPartiallySignedTransaction.from_base64(psbt_data)
print(f"is_final={psbt.is_final()}")
psbt.extract_transaction()
print(f"is_final={psbt.is_final()}")
print(psbt.extract_transaction().serialize().hex()) gives
also bitcoincore
My impression is this type of finalization step, doesn't really fit into bdk.wallet, but into bdk.PartiallySignedTransaction similar to bitcointx. |
Can you give me that bitcointx finalized version (or the sparrow one) in base64 encoding so I can plug it on the bip174.org page? I want to see what they do with the final script fields. |
sure, here is the finalized one:
|
It looks like in BDK we are doing more than bip174 specifies for finalizing. We assume any un-finalized PSBT inputs are from our wallet. For those inputs we use rust-miniscript's What's your use case for using a BDK based wallet to finalize PSBT inputs un-associated with it's wallet descriptor? One possibility is we add a |
|
BDK can possibly expose a method, probably from rust-miniscript, that just handles the finalizer role for a signed psbt. That said, I would expect a method called |
Good point @ValuedMammal. We already export all of the But @andreasgriffin is using the python bindings which only exports a limited set of bdk wallet apis. @thunderbiscuit I think we should move this one back to the |
Sounds good. |
I do think our signing flow could be smarter - it would be worth keeping an issue open to think about. |
This is the signing flow that Andreas is looking for: #[test]
fn test_finalize_psbt() {
let psbt = Psbt::from_str("cHNidP8BAIkBAAAAATuuOwH+YN3lM9CHZuaxhXU+P/xWQQUpwldxTxng2/NWAAAAAAD9////AhAnAAAAAAAAIgAgbnxIFWJ84RPQEHQJIBWYVALEGgr6e99xVLT2DDykpha+kQ0AAAAAACIAIH+2seEetNM9J6mtfXwz2EwP7E1gqjpvr0HHI97D3b5IcwAAAAABAP2HAQEAAAAAAQHSc/5077HT+IqRaNwhhb9WuzlFYINsZk1BxhahFNsqlQAAAAAA/f///wKYuQ0AAAAAACIAIKteOph2G5lDpTD98oWJkrif3i6FX/eHTr2kmU4KN1w1oIYBAAAAAAAiACBYU+aHAWVhSe4DMfwzQhq9NzO6smI694/A7MoURBK4nAQARzBEAiBFFZVQQjC5SlDRCAuC5AkoQgMXyrG54gp71Ro2W6g0fgIgTbg94g7liL0T7DwEeWqOiJfurgpuTv1Q+7bAzFlV/yQBRzBEAiB76jOyWL28VWQzn32ITyy4JlRYAASEaPB9C7mANDLtzAIgCjyov+Y9xRQicB2+v0iDA09RcC7hQHzLxXA9klITMXkBaVIhApBlhYUDvuGXybpbsvXzcXHMb+NikjYe3kqp8xvXMoeJIQPPm4n6VeT9fEoPYLoiy9a3O0mxnSA3wNRunj9xLxmoXSED6TWmEfTbB6zewl0TlxSPr3xmEqifQu5Ou9xoOocqvQlTrnMAAAABASuYuQ0AAAAAACIAIKteOph2G5lDpTD98oWJkrif3i6FX/eHTr2kmU4KN1w1IgICov3eEPPwwA+7S2NpB1FCBk3wZDu+EXBOrtIJi8IgI1lHMEQCIFuO9cKoLEM1v3juKeV+D9yotGzHONOlHdmXaA4qsa7PAiBNN4i+JleuHBXl3NFV8rQIgwCmTJkx4yykF5qnkvtJvAEiA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I1+lOuIgICpfNLzexJfZ5G++SEVaypCms5w4g/8ExmROHke623xxEcJuv5KjAAAIABAACAAAAAgAIAAIABAAAABAAAACICAzc7rxaDI9x7Lvd7U3faPs9e34DNsrDE/V2mRVYn0WLvHPTklXQwAACAAQAAgAAAAIACAACAAQAAAAQAAAAiAgNkHWK1/HMUBxz9Cbs7elmC528iAQWIW104ND9B6ZI1+hwll+QpMAAAgAEAAIAAAACAAgAAgAEAAAAEAAAAAA==").unwrap();
use miniscript::psbt::PsbtExt;
let secp = Secp256k1::default();
let finalize_result = psbt.finalize(&secp);
assert!(finalize_result.is_ok())
} |
I have the following fully signed (regtest) PSBT
and create a dummy_wallet (unrelated to the PSBT inputs):
dummy_wallet.sign(psbt, None)
returnsFalse
It fails to finalize the transaction. Comparison: Sparrow can finalize the PSBT to a fully signed tx.
Am I doing something wrong, or why does bdk need the source wallet to finalize the PSBT?
The text was updated successfully, but these errors were encountered: