Bitcoin Forum
May 09, 2024, 05:21:26 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What do you actually sign in P2PKH?  (Read 85 times)
BoyFromDubai (OP)
Jr. Member
*
Offline Offline

Activity: 33
Merit: 22


View Profile
December 05, 2022, 12:04:07 AM
 #1

There is scriptSig and scriptPubKey. And when you provide scriptPubKey — you provide your public key and some opcodes are added. But when you provide scriptSig — what do you sign? What data you sign when spending your bitcoins: all data for the locked output or all data in new input? Just a little confused about the principle of the algorithm and how it works technically
1715232086
Hero Member
*
Offline Offline

Posts: 1715232086

View Profile Personal Message (Offline)

Ignore
1715232086
Reply with quote  #2

1715232086
Report to moderator
If you want to be a moderator, report many posts with accuracy. You will be noticed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715232086
Hero Member
*
Offline Offline

Posts: 1715232086

View Profile Personal Message (Offline)

Ignore
1715232086
Reply with quote  #2

1715232086
Report to moderator
1715232086
Hero Member
*
Offline Offline

Posts: 1715232086

View Profile Personal Message (Offline)

Ignore
1715232086
Reply with quote  #2

1715232086
Report to moderator
1715232086
Hero Member
*
Offline Offline

Posts: 1715232086

View Profile Personal Message (Offline)

Ignore
1715232086
Reply with quote  #2

1715232086
Report to moderator
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5818


not your keys, not your coins!


View Profile WWW
December 05, 2022, 12:34:28 AM
Last edit: December 05, 2022, 01:01:57 AM by n0nce
Merited by ABCbits (3), pooya87 (2)
 #2

I generally recommend Learnmeabitcoin as a resource for introduction to more technical topics.

In the article I linked to, they explain how scriptPubKey is the locking script.
There are different possible script types, but the most common nowadays is P2PKH. It can be unlocked by providing the original public key and correct signature (this tuple is the scriptSig).

Code:
OP_DUP OP_HASH160 fde0a08625e327ba400644ad62d5c571d2eec3de OP_EQUALVERIFY OP_CHECKSIG

In short: The 'opcodes added' duplicate the public key, perform the hash160. The result lies on the stack. Then, the script pushes the (hardcoded into the transaction) public key hash to the stack and verify that these 2 public key hashes match. Finally, the signature is matched against the public key.

More information about P2PKH here.

As you asked: 'What do you sign?' -- you sign the whole transaction.
More about transactions here.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
December 05, 2022, 04:59:33 AM
Merited by n0nce (1)
 #3

As you asked: 'What do you sign?' -- you sign the whole transaction.
Technically you sign the modified transaction (eg. replacing all signature scripts with empty except the input being signed that is replaced by a modified spending script) and how much of it you sign depends on the SigHashType that is used in the signature (ALL/SINGLE/NONE+ANYONECANPAY).

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
baro77
Member
**
Offline Offline

Activity: 90
Merit: 91


View Profile WWW
December 05, 2022, 07:11:40 AM
 #4

There is scriptSig and scriptPubKey. And when you provide scriptPubKey — you provide your public key and some opcodes are added. But when you provide scriptSig — what do you sign?

I wrote it in 2019 so it's not up-to-date with taproot & co, but maybe it can someway help you, as far as you are starting from the bases:
https://github.com/baro77/btcUnlockingLockingScriptCS

 
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!