Bitcoin Forum
May 04, 2024, 09:39:57 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What are the variable types of "sizes" inside signatures?  (Read 184 times)
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
March 29, 2019, 09:59:22 AM
Merited by ABCbits (1), bones261 (1)
 #1

Here are two transactions I've made as a reference (TestNet):
P2SH: 7c1819fe9b52a199c9a422b1df3edef43005c3d4eea367d7830bbc060a6aac44
P2WSH: 3e7aaf12e77e5d68b2bc26fb5cfe3ee3108356860056da923a2e735ba4759d58

The first one obviously has a scriptSig and the second one has an empty scriptSig + witness. The following two parts are the corresponding data respectively.
CompactInt refers to this so 1000 would be fde803
OP_PushData refers to values that are interpreted as an OP code and indicate raw data to be pushed on top of the stack. so 1000 would be 4de803
DerInt refers to length in DER TLV encoding and 1000 would be 8203e8

fd4606
CompactInt showing length = 1606
00
OP_0
48
??
30
DER sequence tag(0x30)
45
DerInt length = 69
02 21 00{..32 byte r..} 02 20 {..32 byte s..} 01
rest of the DER encoding...
{..14 similar signatures removed..}

4d0102
OP_PushData = PushData2 | 513 byte
5f
OP_15
21
PushData = 33 byte
02 083f75b6cf2aea023d86a6f757345508a2f7a1de23c1d015b6bc228e995cf2b7
Pubkey
{..14 similar pubkeys removed..}
5f
OP_15
ae
OP_CheckMultiSig



11 (count = 17)
CompactInt showing count= 17
00
OP_0
48
??
30 45 02 21 ....
Same signatures and variable types as above

fd0102
CompactInt showing length = 513
5f 21 02 4c231e0db.... 5f ae
Same script and variable types as above


I think I have gotten everything right, but I can not figure out what the two 0x48 values are. Although it doesn't make a difference because of the size of the value, for the sake of "correctness" I would love to know whether they are both CompactInt or if the one in witness is CompactInt and the one in ScriptSig is an OP_PushData (with value = 72)

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
1714815597
Hero Member
*
Offline Offline

Posts: 1714815597

View Profile Personal Message (Offline)

Ignore
1714815597
Reply with quote  #2

1714815597
Report to moderator
1714815597
Hero Member
*
Offline Offline

Posts: 1714815597

View Profile Personal Message (Offline)

Ignore
1714815597
Reply with quote  #2

1714815597
Report to moderator
1714815597
Hero Member
*
Offline Offline

Posts: 1714815597

View Profile Personal Message (Offline)

Ignore
1714815597
Reply with quote  #2

1714815597
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714815597
Hero Member
*
Offline Offline

Posts: 1714815597

View Profile Personal Message (Offline)

Ignore
1714815597
Reply with quote  #2

1714815597
Report to moderator
1714815597
Hero Member
*
Offline Offline

Posts: 1714815597

View Profile Personal Message (Offline)

Ignore
1714815597
Reply with quote  #2

1714815597
Report to moderator
MixMAx123
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
March 29, 2019, 10:53:28 AM
 #2

0x48 = Length Sig

https://en.bitcoin.it/w/images/en/e/e1/TxBinaryMap.png
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6578


Just writing some code


View Profile WWW
March 29, 2019, 02:41:32 PM
Last edit: March 29, 2019, 05:35:34 PM by achow101
 #3

Both of those are OP_PUSHDATAs with size 72.
The first is an OP_PUSHDATA with size 72. The second is a compact size uint. Compact size uints and pushdata opcodes happen to overlap for small values

In any script, if a length is specified in order to push data, it's an OP_PUSHDATA, not a compact size int.

Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
March 29, 2019, 03:17:51 PM
 #4

Both of those are OP_PUSHDATAs with size 72.

In any script, if a length is specified in order to push data, it's an OP_PUSHDATA, not a compact size int.

Thanks but now this no longer makes sense: https://bitcoincore.org/en/segwit_wallet_dev/#transaction-serialization
"Each witness field starts with a compactSize integer to indicate the number of stack items for the corresponding txin"

Additionally there is fd0102 value indicating the size of the public key script in the SegWit transaction which is in fact a CompactInt not an OP_PushData which should have been 4d0102 indicating length of 513 bytes (which is available in the legacy transaction as an OP_PushData). Note that these transactions were created by Electrum and are already in (TestNet) blocks.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6578


Just writing some code


View Profile WWW
March 29, 2019, 05:31:44 PM
Merited by ABCbits (1)
 #5

Thanks but now this no longer makes sense: https://bitcoincore.org/en/segwit_wallet_dev/#transaction-serialization
"Each witness field starts with a compactSize integer to indicate the number of stack items for the corresponding txin"

Additionally there is fd0102 value indicating the size of the public key script in the SegWit transaction which is in fact a CompactInt not an OP_PushData which should have been 4d0102 indicating length of 513 bytes (which is available in the legacy transaction as an OP_PushData). Note that these transactions were created by Electrum and are already in (TestNet) blocks.
The witness data in a transaction (not to be confused with the scriptSig or scriptPubKeys) is not a script. It is a stack of bytes (can also be viewed as an array of an array of byte values). This is not a script, so it uses compact size uints, not opcodes.

Compact size uints and pushdata opcodes happen to overlap for small values.

I've edited my above post as it was wrong. I misread your question.

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!