Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native p2wpkv0 example #10

Open
wants to merge 1 commit into
base: vault
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions bip-0YYY.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,116 @@ Minimize signature checking operations. Optimize <code>sigOpCost</code> counting

==Examples==

=== Native P2WPKV0 ===

unsigned transaction of two inputs and two outputs:
02000000021C8C38932199131BEBF535B25E799F0331A37DA876D9DE473770A6F7D3BE93730300000000FFFFFFFF14A4B9190E852B2CD9D6449D18DA07D8D6D135EE7097A3C49E21EAD536FD8D7A0200000000FDFFFFFF028055C820000000001600141C00381AD450B3D561979AC29230E98F30538D7D00C2EB0B000000001976A914A5340B476548BA4DF9C65068CED1A2FEFF5B607188ACB2030000

02000000
02
1C8C38932199131BEBF535B25E799F0331A37DA876D9DE473770A6F7D3BE9373
03000000
00
FFFFFFFF
14A4B9190E852B2CD9D6449D18DA07D8D6D135EE7097A3C49E21EAD536FD8D7A
02000000
00
FDFFFFFF
02
8055C82000000000
16 00141C00381AD450B3D561979AC29230E98F30538D7D
00C2EB0B00000000
19 76A914A5340B476548BA4DF9C65068CED1A2FEFF5B607188AC
B2030000

first input is P2WPKH:

program : 0 0x14 0x8E3F94B8E7EEF5661AC7AFEC61FE3EF6CCE5398C
value : 4.504
privkey : FC17E76AC1311192D280E417C376E39F34AC3A5D1E031E86FFCF43FF6F5B446C

second input is P2WPV0:

program : 1 0x21 0x02C929B19F8DE22FF56302141BD6DC941779628371225C59214631397A3D3C837C
value : 3.006
privkey : 7A31BE18DA5EC37BE3350B32F3A228880A4DE7C35CCD1E75A69B93AFB66B6E12

The outputs are valued at 5.5 for the first and 2.0 for the second output.
The fee used in the transaction is 0.01, and 0.006 of that sum are paid by the P2WPKV0 (second) input.


sign it with SIGHASH_MSV0_ALL:

hashPrevouts, hashSequence and hashOutputs are computed the same as in bip143:

hashPrevouts:
hash256(1C8C38932199131BEBF535B25E799F0331A37DA876D9DE473770A6F7D3BE93730300000014A4B9190E852B2CD9D6449D18DA07D8D6D135EE7097A3C49E21EAD536FD8D7A02000000)
= 030F0BFF5877CC3D2E66006060BCAC26D25A39A94287C5A6C0CF3EB1885C5818

hashSequence
hash256(FFFFFFFFFDFFFFFF)
0DC0D8B1EE1438145E579B91CB570B7D64C3E8EAB38EA6E6664422B6BFA1C73E
= 0DC0D8B1EE1438145E579B91CB570B7D64C3E8EAB38EA6E6664422B6BFA1C73E

hashOutputs:
hash256(8055C820000000001600141C00381AD450B3D561979AC29230E98F30538D7D00C2EB0B000000001976A914A5340B476548BA4DF9C65068CED1A2FEFF5B607188AC)
= C03598C36101B056AC1D96CCEF2E5682EE4B954C1AB62BC410D0BF9D4F4144F9

sighash midstate:
0200000001000000030F0BFF5877CC3D2E66006060BCAC26D25A39A94287C5A6C0CF3EB1885C58180000000000000000000000000000000000000000000000000000000000000000FFFFFFFF0DC0D8B1EE1438145E579B91CB570B7D64C3E8EAB38EA6E6664422B6BFA1C73EFFFFFFFFC0CAEA1100000000C03598C36101B056AC1D96CCEF2E5682EE4B954C1AB62BC410D0BF9D4F4144F9FFFFFFFFFFFFFFFF0040420F0000000000B2030000232102C929B19F8DE22FF56302141BD6DC941779628371225C59214631397A3D3C837CAC00000000000000000000000001

nVersion : 02000000
nInputIndex : 01000000
hashPrevouts : 030F0BFF5877CC3D2E66006060BCAC26D25A39A94287C5A6C0CF3EB1885C5818
prevoutSingle : 0000000000000000000000000000000000000000000000000000000000000000 FFFFFFFF
hashSequence : 0DC0D8B1EE1438145E579B91CB570B7D64C3E8EAB38EA6E6664422B6BFA1C73E
sequenceSingle : FFFFFFFF
nAmount : C0CAEA1100000000
hashOutputs : C03598C36101B056AC1D96CCEF2E5682EE4B954C1AB62BC410D0BF9D4F4144F9
outputSingleValue : FFFFFFFFFFFFFFFF
outputSingleScript: 00
nFees : 40420F0000000000
nLocktime : B2030000
scriptCode : 23 2102C929B19F8DE22FF56302141BD6DC941779628371225C59214631397A3D3C837CAC
scriptWitCode0 : 00
scriptWitCode1 : 00
scriptWitCode2 : 00
scriptWitCode3 : 00
scriptWitCode4 : 00
nHashType : 00000000
nSigVersion : 00000001

sighash: 698B7103ED99494C11ED40D62F6D274405BFBA302B0C2238B48B561AD4EE2381

signature: 7371FE956E90D990A83633C0B0A2071D642748E4925B95B54B035143324274FE78376E681A56BDFB90B215598CDB55A8BD214F822558DB8E98113288C0A38670

signed transaction:
020000000001021C8C38932199131BEBF535B25E799F0331A37DA876D9DE473770A6F7D3BE93730300000000FFFFFFFF14A4B9190E852B2CD9D6449D18DA07D8D6D135EE7097A3C49E21EAD536FD8D7A0200000000FDFFFFFF028055C820000000001600141C00381AD450B3D561979AC29230E98F30538D7D00C2EB0B000000001976A914A5340B476548BA4DF9C65068CED1A2FEFF5B607188AC02483045022100B8744F898B06788280A7A9BF017092BA39B6AC7A7815C03FC2A430E3AC54950502206D56EB2E05FB3415AF48E5A79F7B68F3560C012CFCF27890E7263A7CA1B0CB670121030CC9F9AB9A5AFDD50F742534CA24C55FC25B5BCC36167A9A6196E92C64D1310A02407371FE956E90D990A83633C0B0A2071D642748E4925B95B54B035143324274FE78376E681A56BDFB90B215598CDB55A8BD214F822558DB8E98113288C0A3867000B2030000

02000000
00
01
02
1C8C38932199131BEBF535B25E799F0331A37DA876D9DE473770A6F7D3BE9373
03000000
00
FFFFFFFF
14A4B9190E852B2CD9D6449D18DA07D8D6D135EE7097A3C49E21EAD536FD8D7A
02000000
00
FDFFFFFF
02
8055C82000000000
16 00141C00381AD450B3D561979AC29230E98F30538D7D
00C2EB0B00000000
19 76A914A5340B476548BA4DF9C65068CED1A2FEFF5B607188AC
02
48 3045022100B8744F898B06788280A7A9BF017092BA39B6AC7A7815C03FC2A430E3AC54950502206D56EB2E05FB3415AF48E5A79F7B68F3560C012CFCF27890E7263A7CA1B0CB6701
21 030CC9F9AB9A5AFDD50F742534CA24C55FC25B5BCC36167A9A6196E92C64D1310A
02
40 7371FE956E90D990A83633C0B0A2071D642748E4925B95B54B035143324274FE78376E681A56BDFB90B215598CDB55A8BD214F822558DB8E98113288C0A38670
00
B2030000

== Backward compatibility ==
As a soft fork, older software will continue to operate without modification. Non-upgraded nodes, however, will consider <code>MSV0</code> and <code>P2WPKV0</code> programs as anyone-can-spend scripts.
Expand Down