0

I know that we parse a transaction in bytes. So there are 2 quesions that I search for the answers of:

1- Can VarInt field -that gives the number of inputs in a transaction- be more than 2 hex digits(2 Hex = 8 bits = 1 byte)? I am asking this to be sure that it is not fixed size. We know that 2^8 = max 256 and I am pretty sure that there can be more than 256 inputs in a tx.

2- If it is not a fixed size field how do we know where number of inputs field ends or prevTx field starts? Transaction

1
  • Does this answer your question? Or this code?
    – MCCCS
    Commented Apr 14, 2020 at 10:29

1 Answer 1

1

A Varint is a Variable Length Integer, and can be up to 9 bytes in total

It is usually only one byte, which can represent numbers 0-252. 253-255 (0xFD-0xFF) are used as markers for the next three lengths.

Marker    Payload
None      1 byte of integer data
0xFD      0xFD followed by two bytes of integer data
0xFE      0xFE followed by four bytes of integer data
0xFF      0xFF followed by eight byes of integer data

Each marker indicates how to interpret the upcoming bytes.

4
  • 1
    So to have a better understanding: At most this field can be: FFFFFFFFFFFFFFFFFF, which represents 1.844674407371E+19 many inputs in the transaction, right? (first byte for representation and others for the input count)
    – Efe
    Commented Apr 14, 2020 at 11:12
  • @EfeCini That's right - you will hit the block's SIGOPS and size limits far before you hit a encoding limit for the number of inputs Commented Apr 14, 2020 at 12:54
  • Similarly PUSHDATA4 as an opcode is impossible to use.
    – Claris
    Commented Apr 14, 2020 at 13:56
  • Except on legacy transactions.
    – Claris
    Commented Apr 14, 2020 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.