TeachMeBitcoin

OP_PUSHDATA1 - Pushing Up to 255 Bytes

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

4. OP_PUSHDATA1 — Pushing Up to 255 Bytes

Overview

OP_PUSHDATA1 is a variable-length data push opcode that allows a script to push between 1 and 255 bytes of arbitrary data onto the stack. It occupies opcode byte 0x4c and is the first of three PUSHDATA variants that extend the direct-push range beyond 75 bytes.

Opcode Format

Format: 0x4c <length:1 byte> <data:length bytes>

Example: Push the 3-byte sequence [0xDE, 0xAD, 0xBE]:
0x4c 0x03 0xDE 0xAD 0xBE

Example: Push a 100-byte blob of zeros:
0x4c 0x64 [0x00 * 100]

The 0x4c byte signals the interpreter to read the next byte as an unsigned 8-bit length, then read that many subsequent bytes as the data to push.

Byte Range and Applicability

OP_PUSHDATA1 can encode pushes of 1 to 255 bytes. However, BIP 62 minimal push rules require that this opcode only be used when the data length is between 76 and 255 bytes:

Data length 0:          use OP_0
Data length 1–75:       use direct push (0x01–0x4b prefix)
Data length 76–255:     use OP_PUSHDATA1
Data length 256–65535:  use OP_PUSHDATA2
Data length 65536+:     use OP_PUSHDATA4

Using OP_PUSHDATA1 for data that could fit in a direct push is a BIP 62 violation and results in a non-standard (but technically valid) transaction.

Common Uses

The most common payload pushed via OP_PUSHDATA1 in real Bitcoin transactions is signatures. A standard DER-encoded ECDSA signature is 71–73 bytes including the SIGHASH flag byte — just at the boundary where direct push works (up to 75 bytes). However, Schnorr signatures (used in Taproot) are 64–65 bytes and always fit in the direct-push range. For larger scripts or custom data payloads embedded in scriptSig, OP_PUSHDATA1 becomes necessary.

Typical DER signature push (72 bytes, uses direct push 0x48):
0x48 <72-byte DER signature>

If somehow 76 bytes were needed (hypothetical):
0x4c 0x4c <76-byte data>

Interpreter Execution

// From src/script/interpreter.cpp
case OP_PUSHDATA1: {
    if (pc + 1 > pend)
        return set_error(serror, SCRIPT_ERR_BAD_OPCODE);
    nSize = *pc++;   // read 1-byte length
    break;
}
// After size is determined:
if (pc + nSize > pend)
    return set_error(serror, SCRIPT_ERR_BAD_OPCODE);
valtype vchPushValue(pc, pc + nSize);
pc += nSize;
stack.push_back(vchPushValue);

Stack Effect

Before: [ ... ]
OP_PUSHDATA1 <N> <data[0..N-1]>
After:  [ ... | data[0..N-1] ]

The entire data block is treated as a single atomic stack item regardless of its contents.

Error Conditions

Execution of OP_PUSHDATA1 fails if:

These failures result in an immediate script execution error and the transaction is considered invalid.


☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!