orenyomtov / openordex

OpenOrdex is an open source zero-fee trustless Bitcoin NFT marketplace based on partially signed bitcoin transactions
MIT License
218 stars 95 forks source link

Improvements to signature validation to prevent fake listings #141

Open timechainz opened 11 months ago

timechainz commented 11 months ago

Currently in openordex sell offer PSBT inputs are prematurely finalized which makes it difficult for the buyer to verify the signatures. This makes it easy to create fake listings which are commonplace on decentralized marketplaces.

Example of inscription #0 listed on openordex for 456 sats. https://openordex.org/inscription?number=6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0

PSBT inputs are not intended to be finalized until they no longer need to be validated by third parties. In the sell order workflow, the marketplace should not finalize the seller input prior to broadcasting the offer which would allow easier subsequent validation of the signature. Similarly, the buyer workflow should validate the signature on input 0 and finalize it prior to broadcasting.

Recommended changes to openordex: 1) Do not finalize the input of a sell offer (wallet specific flags need to be sent to prevent finalization, update bitcoin-cli instructions) 2) Do not require that inputs are finalized when validating sell offer psbts. Instead, if it is not finalized, validate the signature and discard if it is invalid. 3) Alert users when viewing sell offers that were prematurely finalized since the signature may be invalid and thus may fail when broadcast to the mempool 4) Update the NIP to clarify that the PSBT inputs should not be finalized

I'm not sure if this project is actively maintained or just a proof of concept, but wanted to post this here in the hope that others working on decentralized marketplaces will take this into consideration.

dannydeezy commented 11 months ago

i think this makes sense, lets be weary not to break existing clients though

but also, why is it difficult to validate these signatures when finalized? is it just due to the lack of support in bitcoinjs-lib?

timechainz commented 11 months ago

Agree completely @dannydeezy. I think the first step would be to simply implement item 2 above. If the input is not finalized, validate the input rather than discarding the offer. This would allow other entities to not finalize inputs but still appear on openordex.

Regarding bitcoinjs-lib, I had to report a couple bugs to get signature validation to work for taproot addresses. The library does not support verification of finalScriptWitness. The tldr is that it is tricky because it requires current network state, scripts must be validated in addition to signatures and should probably be verified by bitcoin-core rather than a client-side lib.

You can read more on the subject here: https://github.com/bitcoinjs/bitcoinjs-lib/issues/1933 https://github.com/bitcoinjs/bitcoinjs-lib/issues/1520

orenyomtov commented 10 months ago

Hey,

I love this idea, and this should probably have been it was implemented from the get go.

Unfortunately, OpenOrdex is no longer actively maintained.

Feel free to use the NIP or this issue/repo as a schelling point of any kind for coordination of ordinal PSBT standards.

Best, Oren

habibitcoin commented 9 months ago

@timechainz were you ever able to find a way to extract the transaction and/or validate the final script witness?

timechainz commented 9 months ago

@timechainz were you ever able to find a way to extract the transaction and/or validate the final script witness?

No, I haven't looked into it much other than the links and what I posted above. I think a better solution is to not prematurely finalize the PSBTs to allow clients to properly validate. I'm currently handling prematurely finalized PSBTs by showing the user a warning that the tx may fail.