Ethereum: OP_RETURN max bytes clarification

The Ethereum community has been buzzing about the use of OP_RETURN operating system codes for months, and one concept has sparked curiosity: the maximum bytes allowed by these opcodes. Specifically, the question is how it’s possible for a non-spendable transaction to contain up to 80 arbitrary bytes in its data.

To understand this phenomenon, we need to delve into the world of Ethereum’s scripting language and OP_RETURN opcodes. Here’s a breakdown:

What is OP_RETURN?

Ethereum: OP_RETURN max bytes clarification

OP_RETURN is a special type of transaction opcode that Ethereum introduced in 2014 as part of its Beacon Chain innovation (now known as Polkadot). It allows developers to send data, such as images or other files, without storing them on the blockchain.

The OP_RETURN operation code itself

The OP_RETURN operation code has a specific structure:

functionName(data) {

return { op: 0x00, i: index, len: length, payload }

}

Here’s what each parameter represents:

  • FunctionName: The name of the function that will execute this transaction. In the case of OP_RETURN, this is simply a placeholder for any data.
  • data: The actual data to be sent (in this example, it’s an empty array).
  • index and length: These are used by the Ethereum Virtual Machine (EVM) to determine which part of the data should be included in the transaction.
  • payload: This is where we put our 80 arbitrary bytes. The EVM will store these bytes in the blockchain until they are executed.

How ​​it works

Here’s an example:

  • A developer defines a function with an OP_RETURN opcode, like this:

function opReturn(data) {

return { op: 0x00, i: 0, len: 80, payload: data }

}

  • They send the opReturn transaction to a node, which will execute the function and store the return value (in this case, 80 bytes).
  • When the node executes the transaction, it will check the “payload” parameter, which contains 80 bytes of data.

Why up to 80 bytes?

So, why can’t we just send any arbitrary bytes in our OP_RETURN transactions? The answer lies in the way the Ethereum scripting language works. The EVM has a limited amount of memory and storage space for transaction data, determined by the “i” (index) parameter.

The “payload” parameter includes a “len” field that specifies the number of bytes to store on the blockchain. If we try to include more than 80 bytes in our payload, the EVM will simply ignore them.

Conclusion

In summary, Ethereum OP_RETURN opcodes allow us to send arbitrary data without storing it on the blockchain by using a placeholder function name and including an “i” parameter with a limited value (in this case, up to 80 bytes). This allows developers to send large amounts of data in a compact format, making it easier to use and more efficient than traditional storage solutions.

While this concept may seem complicated at first glance, understanding how it works can help you better appreciate the power and flexibility of the Ethereum scripting language.

ethereum have

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *