btcsuite / btcwallet

A secure bitcoin wallet daemon written in Go (golang)
ISC License
1.15k stars 590 forks source link

Non-witness inputs cannot have a witness #867

Closed lenhatquang97 closed 1 year ago

lenhatquang97 commented 1 year ago

Situation

Now, I am successful in commit transactions. I want to create a reveal transaction for embedding some texts. However, I meet this problem for non-witness inputs. I want to what is the main root cause, and how to solve this problem.

Problem

-25: TX rejected: failed to parse input d48ea76bedebcaef97b0dded85af53f941f847ee3611925d71e2df6c0af0ad7c:0 which references output 9a486548987c117fb3cf73959578854b2dc9eb6f3f35507880621a369410372b:0 - non-witness inputs cannot have a witness (input witness [1b7c17fd0f2a4d80e4bde0e5e3d603f2c9a387bd7fe078edf254493f96982ed3f25f65b2642728cb5ca82132c55970ce76f720439184e4de1dc7c97fd079a338 20bbcea8ef034bd4df764f6339248091e454268446256d851aed3c50f0cf8dd74cac00630b48656c6c6f20576f726c6468 c1bbcea8ef034bd4df764f6339248091e454268446256d851aed3c50f0cf8dd74c], input script bytes , prev output script bytes 76a91488fc282bfeebc8361ef36e2372f94922e3fd427088ac)

Source code: available on https://github.com/lenhatquang97/bitcoin_nft_v2. Note on RevealTx

Btcd, btcwallet commands to run

btcwallet --simnet --username=youruser --password=SomeDecentp4ssw0rd

btcd --simnet --rpcuser=youruser --rpcpass=SomeDecentp4ssw0rd --miningaddr=SeZdpbs8WBuPHMZETPWajMeXZt1xzCJNAJ --txindex

Suggested previous solutions

I also have another clue for this problem:

p2sh-segwit

-25: TX rejected: failed to validate input 17b06d636862cb627a0d00eb633fca9ef27271792de321d69b18a4e8deeed8ad:0 which references output 4b0b636e77a570494e41dce1cc12c97a0bfe4de24b2b99c9b9f0ea6694127638:0 - should have exactly two items in witness, instead have 3 (input witness [e0c6f3c0f8b1f083dd635ff1b18d3f483529b7c35bf55ddcd59b28abf95ec9b0a5ddbb6bc0c39bfc9cc7ef73a56ee99a6a2246f3f6bb6731d30b80964abc347e 20bbcea8ef034bd4df764f6339248091e454268446256d851aed3c50f0cf8dd74cac00630b48656c6c6f20576f726c6468 c1bbcea8ef034bd4df764f6339248091e454268446256d851aed3c50f0cf8dd74c], input script bytes , prev output script bytes 0014624e8cf7aedd1942e13fd335f54f85b99c2536c5)
lenhatquang97 commented 1 year ago

Update: I know the main cause is wrong address type: Two addresses when I debug are p2wpkh and p2sh. I have changed my source code to use P2TR address. However, I also meet error in this transaction after revealing transaction.

-25: TX rejected: failed to validate input f03691956d903a9475f2cb9234e809d9e1ec2c12fc0575358553d454100fd503:0 which references output 86566ae50f44eb08da37dacca524529a6a76e4acef9f99c2f8ddadf13c00f2d2:0 -  (input witness [f083c8b39d9355a107596736f224786120d0061b4583fde2d8b7b670cdb9724487e817f5b9fadda55eb5cee0d1b38aba5da79658c2474621362ce19c39b2e99a 20bbcea8ef034bd4df764f6339248091e454268446256d851aed3c50f0cf8dd74cac00630b48656c6c6f20576f726c6468 c1bbcea8ef034bd4df764f6339248091e454268446256d851aed3c50f0cf8dd74c], input script bytes , prev output script bytes 51209452f02a1041e0b3d7e3d863afb87d61e1d3ac661988541e6e88b053b3e23aeb)
guggero commented 1 year ago

Maybe start with the basics? https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc#pay-to-witness-script-hash-p2wsh I would try to get a p2wsh example to work before attempting p2tr, as that is not documented that well (as in a book or easy to understand tutorial AFAIK).

lenhatquang97 commented 1 year ago

Can I book video call with you about this bug? I meet some problems in creating commit transactions in my thesis. My thesis is using btcwallet for creating Ordinals-fork version (only embedding data).

guggero commented 1 year ago

No, sorry, I'm way too busy to do calls. There are lots of resources out there explaining how to do witness script spends, just mainly for p2wsh and not yet for p2tr. So maybe start there.

lenhatquang97 commented 1 year ago

Ok, so I will start from this! Thank you very much