Author

Topic: What are the variable types of "sizes" inside signatures? (Read 210 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
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.
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
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.
staff
Activity: 3458
Merit: 6793
Just writing some code
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.
full member
Activity: 161
Merit: 168
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
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)
Jump to: