Data Insertion Mechanism

Learn about the Data Insertion Mechanism

Kasplex uses a "Commit-Reveal Scheme" to insert arbitrary data onto the Kaspa network. This scheme involves two transactions: a commit transaction, where the user creates a Redeem Script and an "envelope" containing defined operations, and a reveal transaction, where the output from the commit transaction is spent, revealing the "envelope" content on-chain.

Envelope

An "envelope" can be created using several methods. The Data Drop method pushes data onto the stack and drops it off the stack during script execution. In this method, each OP_PUSH opcode will have the same number of OP_DROP opcodes. Another method involves wrapping data push operations in an OP_FALSE OP_IF … OP_ENDIF structure. This is widely used in Bitcoin’s Ordinals protocol.

Since the max bytes pushable to the stack on Kaspa is 520 bytes, it is more practical to use OP_FALSE OP_IF … OP_ENDIF than push a nested JSON string then drop it.

We use the bytes "kasplex" to indicate that this envelope belongs to the Kasplex Protocol. The envelope should be inserted at the end of the redeem script in a P2SH transaction. Which would actually be:

<pubkey>
OP_CHECKSIG     
OP_FALSE
OP_IF
 OP_PUSH "kasplex"
 OP_PUSH 1
 OP_PUSH "text/plain;charset=utf-8"
 OP_PUSH 0
 OP_PUSH "Hello, world!"
OP_ENDIF

OP_PUSH 1 indicates that the next push contains the extra information(The field is currently reserved and can be passed as an empty string.), and OP_PUSH 0 indicates that subsequent data pushes contain the content itself. The max bytes pushable to the stack is 520 bytes.

Commit transaction

In the commit transaction, the user creates a Redeem Script, and then applies the OP_BLAKE2B algorithm to this script. The output script is then:

OP_BLAKE2B <RedeemScriptHash> OP_EQUAL 

Reveal transaction

In the reveal transaction, the user creates an input script (referencing the UTXO above) consisting of the Redeem Script itself (as a single stack element, thus limited to 520 bytes) preceded by a sequence of Script operations that will make the Redeem Script result in only true after execution. The input script is then:

<signature> <RedeemScript>

The complete Commit-Reveal Scheme is like this:

Last updated