Title: Trying to make SIGHASH_SINGLE transaction [unsolved] Post by: pbies on August 05, 2023, 11:54:55 AM I am trying to make a SIGHASH_SINGLE transaction.
I have two inputs, one output. I understand that second input can be not signed (really?). I use Python 3.11.4. I use these libraries: Code: apt install libssl-dev Script I have is: Code: #!/usr/bin/env python3 I am getting error: Code: error code: -25 Both inputs have balance, I am sure of that. I am running script from WSL1 Bash on Windows. What am I missing here? Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: BitMaxz on August 05, 2023, 11:27:04 PM The error bad-txns-inputs-missingorspent it means that you have UTXO missing or you might be trying to spend an already spent uTXO.
Check this part below Code: txid = lx('tx number 1') Did you add the hash of your unspent transaction under tx number 1 and 2? Can you add UTXO hash if ever you forgot to add it. And another thing don't forget to add where you want send it under txout. Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: nc50lc on August 06, 2023, 06:10:54 AM What am I missing here? Seems like you're using the vout as the input's index number, while it's actually the UTXO's output_index.For example: If you want to spend the 3rd output of the transaction (testnet): d7a4d0f41a23af4b07ae75fa003ffa515c687f3da7045baa24d318649a4dbbe9 (https://blockstream.info/testnet/tx/d7a4d0f41a23af4b07ae75fa003ffa515c687f3da7045baa24d318649a4dbbe9); (0.00013000 tBTC) The vout would be '2'. Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: pbies on August 06, 2023, 11:08:05 AM I've already verified that the library used does not work any way. Used one input address and one output, used for that script from examples and it does return the same error.
Yes, I've changed "tx number 1" and second one to proper tx values. Also changed vouts to proper ones (different than here), and still no luck. Txout was included. Vouts are only variables names. They are indexing the outputs from previous transactions (check one and two). I checked few times that they were correct. Yes, I used proper transaction outputs from previous transactions using indexing from 0. Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: BitMaxz on August 06, 2023, 02:45:37 PM Can you share the txid and txid2 here I just want to check if you are correct on giving value on vout for both TXIDs (you can share other txid with the same inputs and outputs if you don't want to share your TXIDs).
And I would like you to try to change this Code: txid = lx('tx number 1') To this Code: txid0 = lx('tx number 1') Let see what will be the result Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: pbies on August 06, 2023, 02:49:22 PM Can you share the txid and txid2 here I just want to check if you are correct on giving value on vout for both TXIDs (you can share other txid with the same inputs and outputs if you don't want to share your TXIDs). ... Code: txid0 = lx('2bb8abb322b5087b21b4bb066a919b03b7ac69ce56840d44d7bf7050942f3d9a') Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: nc50lc on August 07, 2023, 08:20:10 AM And I would like you to try to change this Changing those lines will break the script,and changing the relevant parts of the code to fix it will do nothing but change those variables' names. Code: txid0 = lx('2bb8abb322b5087b21b4bb066a919b03b7ac69ce56840d44d7bf7050942f3d9a') But it still has another unspent transaction output: f860007e0217aeec309060da55fbb3ea614663dfb93a0cfab1c0377be863383c:31 (https://blockstream.info/tx/f860007e0217aeec309060da55fbb3ea614663dfb93a0cfab1c0377be863383c?output:31&expand) (0.00079261 BTC) Use that instead. Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: pbies on August 07, 2023, 11:28:03 AM ... Use that instead. Tried that and failing. I try to send myself part of the balance, but even that does not work. Script for now is: Code: #!/usr/bin/env python3 The error is: Code: error code: -26 I suspect that this python-bitcoinlib is failing. Also, private key shouldn't change here, right? Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: nc50lc on August 07, 2023, 03:37:14 PM Quote from: pbies Also, private key shouldn't change here, right? Yes, same as the spent output that you're trying to spend.However, the new error indicates that it may have been signed with the wrong key or provided with the wrong signature. I suspect that this python-bitcoinlib is failing. I can't comment on that since I haven't checked that library.Title: Re: Trying to make SIGHASH_SINGLE transaction Post by: pbies on August 07, 2023, 07:20:53 PM ... I can't comment on that since I haven't checked that library. Examples in this library were bad. I solved that - just needed to create tx first and set it once again at the end. I am now trying to sign both inputs (in created output transaction) as SIGHASH_SINGLE: 1. Do I need to sign both inputs with SIGHASH_SINGLE? 2. Do I need to give public key as 0x01000...000 or 0x000...00001 or as hash160 of one of these? 3. How should be the second input signed if it is SIGHASH_SINGLE? 4. I know I have to make signature SIGHASH_SINGLE at the last byte. 5. I get now error "mandatory-script-verify-flag-failed (Non-canonical DER signature)" |