Beersy
BRC-21

Push TX

A script can normally only see the coins it is unlocking, not the wider transaction doing the spending. This describes a technique that lets a script inspect that whole transaction and impose conditions on it.

No author creditedchanged 5 Apr 20233 min read
preimagedummy keysigpubkeypushdroplock

Summary

Why
Bitcoin script cannot normally see or enforce conditions on the transaction spending it, so contracts cannot check things like output values or the next script without a way to pull that data into the script itself.
What
BRC-21 defines Push TX, a scripting technique that lets a Bitcoin script inspect and enforce conditions on the transaction that is spending it.
How
A developer pushes the transaction's pre-image onto the stack in the , then the locking script computes a signature over it on-chain with a throwaway key and checks it with OP_CHECKSIG, so any mismatch with the required conditions fails the script.

What this lets you do

  • Check the transaction's own inputs and outputs from inside a locking script
  • Enforce values like input/output amounts and at spend time
  • Restrict which script the funds can be sent to next, enabling stateful contracts
  • Build multi-step contracts that carry rules forward from one transaction to the next

Written by claude-sonnet-5 from the specification text. Where the two differ, the original is correct.

Reference for an AI

Everything an assistant needs to answer questions about BRC-21 accurately, including what it depends on.

The specification

Abstract

Push TX is a technique that enables users to enforce and access transactional states and conditions within Bitcoin script using ECDSA signature messages. It allows for the enforcement of several transaction elements, such as the number of inputs, values, input and output values, and script conditions, as well as the ability to specify the script into which tokens will be spent. The Push TX algorithm works by pushing the transaction pre-image message that generates the signature onto the stack as part of the input's . This message can be pushed as a single contiguous blob, multiple separate elements, or as a partial set, with the remaining elements of the message set via the output's locking script. The signature is then computed on-chain within the script and checked against the public key using OP_CHECKSIG to ensure the current transaction is valid. This standard outlines the motivation and specifications for implementing the Push TX technique within Bitcoin script.

Motivation

The Push TX technique offers several benefits to Bitcoin users and developers. Firstly, it allows for the enforcement of complex transactional states and conditions at the consensus layer, making it easier to create Turing complete machines within the Bitcoin ecosystem. This is achieved by enabling users to specify the script into which tokens will be spent, which can be used to enforce next state conditions. Additionally, it enables users to specify and enforce various transaction elements, such as input and output values, nSequence values, and the condition. This improves the security and efficiency of Bitcoin transactions by ensuring that all transactional conditions are met and enforced at the consensus layer.

Specification

The Push TX algorithm works as follows:

  1. The user or process that is using the pushes the transaction pre-image message that generates the signature onto the stack as part of the unlocking script. This message can be pushed as a single contiguous blob, multiple separate elements, or as a partial set, with the remaining elements of the message set via the output's locking script.

  2. The algorithm pushes the current transaction onto the stack.

  3. The algorithm pushes a dummy private key onto the stack.

  4. Using the transaction and private key pushed in steps 2 and 3, the algorithm generates an ECDSA signature on-chain within the script.

  5. The algorithm pushes the public key derived from the private key onto the stack.

  6. The algorithm uses OP_CHECKSIG to check the signature against the public key, ensuring that the current transaction is valid.

The Push TX algorithm can be used to enforce several elements of the transaction, including but not limited to the number of inputs, nSequence values, input and output values, and script conditions, as well as the ability to specify the script into which tokens will be spent.

Implementations

This has been implemented in the sCrypt ecosystem.

Commentary

Bitcoin script is often misunderstood as being limited to the data provided in the locking and unlocking scripts. However, the Push TX technique allows for the inspection of the entire transaction within a contract itself, including all inputs and outputs. This opens up boundless possibilities for smart contracts on Bitcoin.

The ability to place arbitrary constraints on inputs and outputs within a contract means that a wide range of use cases can be implemented on Bitcoin. For example, contracts that enforce multi-signature transactions or time-based restrictions can be easily created using Push TX. Additionally, the technique enables the creation of more complex contracts that can enforce next state conditions, making it possible to create Turing complete machines within the Bitcoin ecosystem.

The high-level functionality of Push TX is relatively simple: it allows for the inspection and enforcement of transactional states and conditions within Bitcoin script. However, the implications of this functionality are far-reaching, as it enables the creation of a wide range of smart contracts and decentralized applications on the Bitcoin blockchain. This is important for Bitcoin because it expands its use cases and makes it a more versatile platform for developers and businesses looking to leverage blockchain technology.

References

nChain WP-1605
Xiaohui Liu Article

Was this helpful?

Search Beersy

Search standards by number, title, author or topic