Difference between revisions of "Pushdata Opcodes"

(Added detail)
Line 1: Line 1:
The pushdata opcodes push the next bytes of data onto the stack. Opcodes 1-75 simply push the next bytes of data onto the stack without a requirement to first specify how many bytes to push.
+
The Pushdata opcodes each use the value of the data item in the script to determine the length of the data item to push onto the stack.
  
=== OP_PUSHDATA1 ===
+
===Opcodes 1-75===
OP_PUSHDATA1 pushes data of length from 76 to 255 bytes onto the stack.
+
Opcodes 1-75 simply push their value of bytes of data onto the stack.
 +
 
 +
Examples:
 +
 
 +
0x08 <8 byte data item> - would leave the 8 byte data item on the stack.
 +
0x20 <32 byte data item> - would leave the 32 byte data item on the stack
 +
 
 +
===OP_PUSHDATA1===
 +
OP_PUSHDATA1 takes the next 1 byte as the number of bytes to push onto the stack. It can be used to push data items of length from 1 to 255 bytes onto the stack, however is typically only used for data items over 75 bytes in size.
 +
 
 +
Examples:
 +
0x4C 0x64 <100 byte data item> - would leave the 100 byte data item on the stack
 +
0x4C 0xFF <255 byte data item> - would leave the 255 byte data item on the stack
  
 
=== OP_PUSHDATA2 ===
 
=== OP_PUSHDATA2 ===
OP_PUSHDATA2 pushes data of length from 256 bytes up to 63,999 bytes onto the stack.
+
OP_PUSHDATA2 takes the next 2 bytes as the number of bytes to push onto the stack. It can be used to push data items of length from 256 to 65,535 bytes onto the stack.
 +
 
 +
Examples:
 +
0x4C 0x0100 <256 byte data item> - would leave the 256 byte data item on the stack
 +
0x4C 0xFFFF <65,535 byte data item> - would leave the 65,535 byte data item on the stack
  
 
=== OP_PUSHDATA4 ===
 
=== OP_PUSHDATA4 ===
OP_PUSHDATA4 pushes data of length from 64 KB up to 4.3 GB onto the stack.
+
OP_PUSHDATA4 takes the next 4 bytes as the number of bytes to push onto the stack. It can be used to push data items of length from 65,536B up to ‭4,294,967,295‬B onto the stack.
  
=== Pushdata opcodes unused ===
+
OP_PUSHDATA4 is the largest Pushdata opcode in BitcoinScript limiting the size of individual data items in script to ‭4,294,967,295‬B. Once data items are on the stack it is possible to use OP_CAT to join them together, creating larger items for purposes such as file hash verifications and more.
Due to the maximum script size being limited to 520 bytes, these opcodes were essentially rendered useless. The [[Genesis upgrade]] increases the maximum script size such that these opcodes can be used properly in script.
 

Revision as of 23:13, 13 January 2020

The Pushdata opcodes each use the value of the data item in the script to determine the length of the data item to push onto the stack.

Opcodes 1-75

Opcodes 1-75 simply push their value of bytes of data onto the stack.

Examples:

0x08 <8 byte data item> - would leave the 8 byte data item on the stack. 0x20 <32 byte data item> - would leave the 32 byte data item on the stack

OP_PUSHDATA1

OP_PUSHDATA1 takes the next 1 byte as the number of bytes to push onto the stack. It can be used to push data items of length from 1 to 255 bytes onto the stack, however is typically only used for data items over 75 bytes in size.

Examples: 0x4C 0x64 <100 byte data item> - would leave the 100 byte data item on the stack 0x4C 0xFF <255 byte data item> - would leave the 255 byte data item on the stack

OP_PUSHDATA2

OP_PUSHDATA2 takes the next 2 bytes as the number of bytes to push onto the stack. It can be used to push data items of length from 256 to 65,535 bytes onto the stack.

Examples: 0x4C 0x0100 <256 byte data item> - would leave the 256 byte data item on the stack 0x4C 0xFFFF <65,535 byte data item> - would leave the 65,535 byte data item on the stack

OP_PUSHDATA4

OP_PUSHDATA4 takes the next 4 bytes as the number of bytes to push onto the stack. It can be used to push data items of length from 65,536B up to ‭4,294,967,295‬B onto the stack.

OP_PUSHDATA4 is the largest Pushdata opcode in BitcoinScript limiting the size of individual data items in script to ‭4,294,967,295‬B. Once data items are on the stack it is possible to use OP_CAT to join them together, creating larger items for purposes such as file hash verifications and more.