elements icon indicating copy to clipboard operation
elements copied to clipboard

rpc/wallet: add simulaterawtransaction RPC

Open kallewoof opened this issue 3 years ago • 13 comments

This is an experimental feature for analyzing a given raw transaction, generating a mapping of what the wallet's balances will look like were the transaction to be signed and broadcast.

It uses GetDebit from wallet to determine incoming amounts and the unblinded transaction outputs to determine the outputs.

(Work here is on hold as upstream is progressing.)

Upstream: https://github.com/bitcoin/bitcoin/pull/22751

kallewoof avatar Jul 06 '21 07:07 kallewoof

concept ACK

Have you proposed this for Bitcoin? Curious if you've gotten any feedback there?

apoelstra avatar Jul 08 '21 15:07 apoelstra

This would be of limited use to bitcoin, I think, as it mostly becomes an issue when you are juggling multiple assets. (Maybe I'm too narrow-minded though. If there are actual use cases I would be happy to move upstream.)

kallewoof avatar Jul 09 '21 00:07 kallewoof

Also I don't see how the CI errors are related to this change (e.g. why would feature_taphash_pegins_issuances.py stop working because of a new RPC command that doesn't change anything anywhere?)

kallewoof avatar Jul 09 '21 00:07 kallewoof

Yeah I think they're caused by #1017

apoelstra avatar Jul 09 '21 20:07 apoelstra

@kallewoof how would you feel about rebasing this and changing it to work with PSETs rather than raw transactions?

apoelstra avatar Sep 20 '21 13:09 apoelstra

@apoelstra I'm actually making more progress upstream than I expected. There are two versions, one which is this renamed to simulaterawtransaction in https://github.com/bitcoin/bitcoin/pull/22751 and one where an array of transactions is added to getbalances in https://github.com/bitcoin/bitcoin/pull/22776.

Rewriting this to work with PS?Ts would be a downgrade I believe, as PS?Ts can be turned into raw transactions but raw transactions cannot be turned into PS?Ts.

kallewoof avatar Sep 20 '21 22:09 kallewoof

Rewriting this to work with PS?Ts would be a downgrade I believe, as PS?Ts can be turned into raw transactions but raw transactions cannot be turned into PS?Ts.

You can get a rawtx from a PSBT with finalizepsbt and get a PSBT from a rawtx with converttopsbt. PSBTs have strictly more information.

apoelstra avatar Sep 21 '21 12:09 apoelstra

Ah, I didn't realize that. If you can go both directions it doesn't seem hugely important which one is implemented, though. And since raw transactions are "closer" to what is actually put on chain (e.g. side-stepping bug(s) in PS?T code) raw seems sensible. Is there a specific reason why you prefer the other?

kallewoof avatar Sep 21 '21 23:09 kallewoof

When you go from a PSBT to a raw tranaction then you lose a ton of data: information about the previosu UTXOs needed for signing, BIP32 derivation paths, EC signatures which have not yet been pulled into the actual witness bytes, (in Elements) blinding keys and ECDH keys and explicit data which is hidden in the actual transaction.

The rawtransaction API basically cannot be used for collaborative transaction creation and it is effectively deprecated in favor of PSBT.

apoelstra avatar Sep 21 '21 23:09 apoelstra

The rawtransaction API basically cannot be used for collaborative transaction creation and it is effectively deprecated in favor of PSBT.

I didn't realize this was the sentiment. Perhaps both would be ideal. I haven't done any PSBT stuff yet, but will look into it.

kallewoof avatar Sep 21 '21 23:09 kallewoof

When you go from a PSBT to a raw tranaction then you lose a ton of data: information about the previosu UTXOs needed for signing, BIP32 derivation paths, EC signatures which have not yet been pulled into the actual witness bytes, (in Elements) blinding keys and ECDH keys and explicit data which is hidden in the actual transaction.

The way I envision this to be used is, you get a PSBT thrown at you, you convert it to raw tx, analyze (simulate) it, check that the result is what you expect it to be, then provide a signature for the PSBT in question.

Since you don't throw away that input you don't technically lose any information regardless of whether this is a raw tx command or a psbt command. That said, if people are of the sentiment that we're getting rid of raw tx entirely, then I should rework it for sure.

kallewoof avatar Sep 21 '21 23:09 kallewoof

I doubt we'll ever get rid of the raw transaction API, for backward compatibility and testing purposes. But I expect that users in multi-party transactions (where the ability to analyze transactions is most important) will always use PSET/PSBT rather than rawtxes, so the extraction would be an extra step for them (and the extraction may lose extra data, such as input values, that could be useful for analysis).

apoelstra avatar Sep 22 '21 01:09 apoelstra

I was going to say "there's already an analyzepsbt, maybe the functionality should go there", but then I realized it's non-wallet code. Anyway, thanks for the feedback, I will look into psbt'ifying.

kallewoof avatar Sep 22 '21 04:09 kallewoof