Comments (9)
Have you considered using Miniscript for this policy? There is a crate rust-miniscript that can do these sorts of script constructions for you.
But to answer your specific question, it looks like you have two CHECKSIG
s and one CHECKSIGADD
in your second branch, and I think teh second CHECKSIG
should be a CSA.
from rust-bitcoin.
I think branch is just better at everything. The only exception I can imagine is if you had something smaller than 32 B. Like OP_CSV
. But since all keys are at least 32B long and a transaction without a key can be spent by anyone such thing would be useless.
from rust-bitcoin.
Thanks! I tried that but end up with
RPC error: {\"code\":-26,\"message\":\"non-mandatory-script-verify-flag (OP_IF/NOTIF argument must be minimal in tapscript)\"}"
from rust-bitcoin.
I'm not sure what to make of that. The code you posted does not put any non-minimal data into IF, NOTIF, or the end of the script execution.
from rust-bitcoin.
I think I figured out the problem, using a minimal example
a simple multisig with Alice/Bob
Case 1:
let wallet_script = Builder::new()
.push_opcode(opcodes::OP_TRUE)
.push_opcode(all::OP_IF)
.push_x_only_key(&bob.public_key().into())
.push_opcode(all::OP_CHECKSIGVERIFY)
.push_opcode(opcodes::OP_TRUE)
.push_opcode(all::OP_ELSE)
.push_x_only_key(&alice.public_key().into())
.push_opcode(all::OP_CHECKSIGVERIFY)
.push_opcode(opcodes::OP_TRUE)
.push_opcode(all::OP_ENDIF)
.into_script();
Works when spending like this
let wit = Witness::from_vec(vec![
schnorr_sig_bob.to_vec(),
wallet_script.to_bytes(),
actual_control.serialize(),
]);
If I switch OP_TRUE
to OP_FALSE
then only Alice can sign the transaction
So the goal is to remove the OP_TRUE
/OP_TRUE
from the script and put it inside the spend script. Thats the idea I got from here (https://youtu.be/yU3Sr07Qnxg?feature=shared&t=2589)
But I'm not sure how to push true/false into the spend script so that its picked up by OP_IF
I tried
let wit = Witness::from_vec(vec![
schnorr_sig_bob.to_vec(),
vec![1],
wallet_script.to_bytes(),
actual_control.serialize(),
]);
but run into Invalid Schnorr signature
error
from rust-bitcoin.
If you're providing a different script when signing than actually goes in the transaction, then you'll get an invalid signature.
But I strongly encourage you to look at rust-miniscript which will just do this all for you.
from rust-bitcoin.
@3ierratango I think what you're trying to achieve would be better done using taproot where you simply specify the branches individually and not worry about OP_IF
. You'd also save a bunch of fees.
from rust-bitcoin.
@3ierratango I think what you're trying to achieve would be better done using taproot where you simply specify the branches individually and not worry about OP_IF. You'd also save a bunch of fees.
Great idea, got it working. Whats the downside of using branch vs script. I looked at docs and the idea I get is we use a script when we need to verify some data (like a secret share) but to acheive a multisig solution a script vs branch model makes no difference. Am I correct in this understanding?
from rust-bitcoin.
I looked at docs and the idea I get is we use a script when we need to verify some data (like a secret share)
I'm curious what docs suggest this. It's a pretty obscure usecase. But yes, if you need your script to come with proof-of-publication of some data, that data needs to be directly in the script.
Other than that, as Kix says the "tradeoff" is that a branch is always 32 bytes while a script could sometimes be smaller.
from rust-bitcoin.
Related Issues (20)
- Do We require BIP324 implementation? HOT 1
- bip32: Understand and fix the `m/` problem HOT 4
- TX rejected: failed to validate input - signature not empty on failed checksig HOT 20
- Bug on witness verification (witness flag but empty witnesses) HOT 8
- Should document how to create a custom `Params` HOT 4
- Unpin `kani` once fix is released by them
- Make stuff in `Params` const
- `LockTime::from_height` could use a clarification for the meaning of height HOT 11
- Preparing taproot script spend to be signed HOT 6
- What are the `*_encode_signing_data_to` functions public for? HOT 4
- Schnorr - combine 2 signature HOT 5
- Actually validate taproot spends HOT 4
- `master` still has version set to `0.32.0-rc1` HOT 4
- `Script` should have accessors for hashes embedded in scriptpubkeys
- How to recover address from txn witness data? HOT 7
- ci: Consider shellcheck for bash/shell scripts linting HOT 5
- Support for testnet4 HOT 10
- Implement `ZERO_NORMAL` and `ZERO_HARDENED` constants (and variants for `ONE`) for BIP 32 HOT 1
- Implement constants for `PsbtSighashType` HOT 5
- `derive_xpriv` should not return a `Result` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-bitcoin.