Bitcoin Forum
December 14, 2024, 02:54:54 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Taproot implementation questions  (Read 184 times)
piotr_n (OP)
Legendary
*
Offline Offline

Activity: 2058
Merit: 1416


aka tonikt


View Profile WWW
May 18, 2021, 01:27:49 PM
Merited by Welsh (4), hugeblack (4), ABCbits (2), HeRetiK (1), TheBeardedBaby (1), NotATether (1)
 #1

I'm starting this new topic because I'm trying to implement the taproot functionality in my code.
I hope people can help me to understand some of the taproot technicalities.

So my first question:

How does the new verify_script function use the spend_scripts of the inputs that it is spending?

When I will verify a specific input of a transaction, will I need to have amounts and spend scripts for all the inputs, or will it be enough to have just the one at a time?

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3570
Merit: 6927


Just writing some code


View Profile WWW
May 18, 2021, 05:31:49 PM
Merited by piotr_n (10), hugeblack (4), ABCbits (2)
 #2

The new Sighash algorithm includes all of the values and output scripts of the UTXOs being spent in the transaction.

piotr_n (OP)
Legendary
*
Offline Offline

Activity: 2058
Merit: 1416


aka tonikt


View Profile WWW
May 18, 2021, 05:35:11 PM
 #3

Thank you.

May I ask, out of curiosity, what purpose does it serve?
It kind of makes the taproot implementation quite much harder to make.

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3570
Merit: 6927


Just writing some code


View Profile WWW
May 18, 2021, 05:53:04 PM
Merited by Welsh (10), piotr_n (10), hugeblack (4), ABCbits (3), DdmrDdmr (3)
 #4

May I ask, out of curiosity, what purpose does it serve?
It kind of makes the taproot implementation quite much harder to make.
Requiring all UTXO amounts is there to allow for offline signers to be guaranteed that the amount they are sending is correct. There have been some theorized situations where an offline signer could be tricked into sending more or less Bitcoin to fees than they expect to, which could result either in the loss of funds, or in the transaction not confirming in a timely manner.

Trezor described a potential attack that involve the uncertainty of the amounts in other inputs. This attack could result in the loss of funds by causing an increasing the transaction fee.

So this change to the sighash algorithm resolves such attacks. If the offline signer is lied to about the amount of other inputs, it will produce an invalid signature and so the transaction becomes invalid. Thus it doesn't matter if it is lied to, no funds can be lost.

For requiring all the output scripts, this is again for offline signers, particularly in coinjoins. In this scenario, the offline signer needs to be able to prove that all of the other inputs in the transaction do not belong to it. Otherwise it could lose funds. By requiring all of the scriptPubKeys for the other inputs, the offline signer can be safe to sign even if it is being lied to. Like with the amounts, if it is lied to, it will make an invalid signature and so the transaction is invalid. There is some more information about this on the bitcoin-dev mailing list.

piotr_n (OP)
Legendary
*
Offline Offline

Activity: 2058
Merit: 1416


aka tonikt


View Profile WWW
May 18, 2021, 06:00:59 PM
 #5

Thank you, it helps me a lot.

Call me stupid, but I'm not quite enlightened by the way the BIP docs are explaining themselves. Smiley

So: try to collect the outputs being spent first and verify the scripts later - I'm on it.. thanks!

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
piotr_n (OP)
Legendary
*
Offline Offline

Activity: 2058
Merit: 1416


aka tonikt


View Profile WWW
May 19, 2021, 10:38:47 AM
 #6

Are there any test vectors, but only for the new sighash algorithm?


Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3570
Merit: 6927


Just writing some code


View Profile WWW
May 19, 2021, 04:35:51 PM
Merited by piotr_n (1)
 #7

Are there any test vectors, but only for the new sighash algorithm?
I don't think so.

NotATether
Legendary
*
Offline Offline

Activity: 1820
Merit: 7476


Top Crypto Casino


View Profile WWW
June 07, 2021, 05:09:12 PM
 #8

Are there any test vectors, but only for the new sighash algorithm?
I don't think so.

It just occurred to me that you can reuse the test vectors of BIP341 https://raw.githubusercontent.com/bitcoin-core/qa-assets/main/unit_test_data/script_assets_test.json and to make the unit test, instead of using VerifyScript you could instead construct a CScript out of the script bytes and construct a uint256 hash like this:

Code:
            exec_script = CScript(script_bytes.begin(), script_bytes.end());
            uint256 hash_exec_script;

And then memcmp() the script hash to its expected value.

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!