Is there an existing issue for this?
- I have searched the existing issues
Current behaviour
I’m attempting to reproduce the transaction specified by AJ Towns that pointed out BitVM bridges with CTV+CSFS for p2sh outputs are vulnerable to theft. You can read more about the topic here.
The TLDR is i’m attempting to sign a p2sh(p2pk)
script.
I’ve attempted to create this transaction via the signrawtransactionwithkey
RPC. I kept receiving an error saying
{ 'error': 'Unable to sign input, invalid stack size (possibly missing key)'}]}
despite explicitly passing in the public key and redeem script in the prevTxs
and keys
rpc argument. You can view this here:
After wandering through the source code, it seems that there is a disconnect between the Solver
and creation of the KeyStore
inside of ParsePrevOuts
.
The KeyStore
attempts to search for the KeyId of the p2sh output script.
The ParsePrevOuts
function only adds the KeyId
of the redeemScript for p2sh outputs.
I’ve modified the code on my feature branch to add both the keyid of the p2sh redeem script and the keyid of the output script to the keystore, and now I at least get a digital signature produced (rather than Unable to sign input, invalid stack size (possibly missing key)
).
From a quick glance through rpc_signrawtransactionwithkey.py
it seems that p2sh(p2wsh())
is tested, but AFAICT legacy p2sh is not tested.
Expected behaviour
rpc_signrawtransactionwithkey
should be able to sign p2pk redeem scripts
Steps to reproduce
Run ./build/test/functional/feature_bitvmctvcsfs_bridge.py
on this commit: https://github.com/Christewart/bitcoin/commit/ae6d4476b730d0909f88405f9a9c08383611a49f
and remove this line of code to see the failure:
Relevant log output
No response
How did you obtain Bitcoin Core
Compiled from source
What version of Bitcoin Core are you using?
https://github.com/Christewart/bitcoin/commit/ae6d4476b730d0909f88405f9a9c08383611a49f
Operating system and version
Mac
Machine specifications
No response