Bitcoin Script and Arkade Script
A contract’s output is a Taproot output: either a virtual output, or an ordinary Bitcoin output that never goes offchain. Its script tree holds two kinds of spending path. A consensus-enforceable path uses only Bitcoin Script. The operator checks it, and Bitcoin can enforce every condition on it alone if need be. The CSV exit path is one of these, and it needs no signature from the operator. An emulator-enforced path holds a spending condition in Arkade Script, which Bitcoin never runs, not even after you unroll a virtual output. Bitcoin checks only the path’s signatures. The operator’s cosigner that emulates Arkade Script signs with the emulator key, and on a virtual output the operator’s cosigner that enables offchain spending signs too. The script tweaks the emulator key, which binds the key to this one script (Key tweak). The operator signs only if the script passes. You write contracts in Arkade Language, and the compiler makes both kinds of path.How an emulator-enforced spend is checked
- The wallet adds an Emulator Packet to the Arkade transaction. The packet holds the Arkade Script and the witness of each input that spends through an emulator-enforced path.
- The wallet sends the transaction to the
/v1/txendpoint atemulatorUrl. - The operator’s cosigner that emulates Arkade Script runs each script in the packet against the transaction, and signs only if each script succeeds.
- On a virtual output, the operator’s cosigner that enables offchain spending adds its signatures. The operator returns the finalized transaction.
Opcodes
Arkade Script keeps the opcode values of Bitcoin Script and uses unused values for new opcodes. The opcode table of the engine isopcode.go. The README describes the new opcodes.
Same as Bitcoin Script
The numeric opcodes take BigNums, not 4-byte numbers.
Stack
OP_PUT is new.
Splice
Bitcoin Script disablesOP_CAT, OP_SUBSTR, OP_LEFT, and OP_RIGHT, but they work in Arkade Script, and OP_REVERSEBYTES is new.
Bitwise logic
Bitcoin Script disables these opcodes, but they work in Arkade Script.Arithmetic
A BigNum is a minimally encoded integer of up to 520 bytes. Bitcoin Script numbers have at most 4 bytes. Bitcoin Script disables the first seven opcodes below, but they work in Arkade Script. Disabled in Bitcoin Script
New
Cryptography
OP_CHECKSIG, OP_CHECKSIGVERIFY, and OP_CHECKSIGADD keep their names but check a different digest (Signature checks). OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY fail, as in tapscript. Use OP_CHECKSIGADD. These opcodes are new:
Elliptic curves
All opcodes in this group are new.curve_id selects the curve. Coordinates are BigNums.
Locktime and time
OP_CHECKLOCKTIMEVERIFY and OP_CHECKSEQUENCEVERIFY work as in Bitcoin Script. The SDK builds emulator-enforced spends with nLockTime 0 and the final sequence 0xffffffff, so a script that runs either opcode fails on those spends. Use OP_CHECKTIME for time conditions. These opcodes are new:
OP_CHECKTIME reads the operator’s enclave clock, not Bitcoin block time. The first script below fails before a time threshold, and the second passes once the virtual output is within the given number of seconds of its expiry.
Transaction introspection
All opcodes in this group are new. Inputs
Outputs
Transaction
Packets and operator-request inputs
All opcodes in this group are new.OP_INSPECTPACKET and OP_INSPECTINPUTPACKET read ARK extension packets, for example the asset packet.
Continuation
OP_TUNNEL is new. It expresses native delegation: someone other than the owner renews a virtual output in each batch settlement.
Assets
All opcodes in this group are new. An Asset ID has two stack items:asset_txid, the ID of the issuance transaction, and asset_gidx, the group index of the issuance.
k is the position of a group in the asset packet of the transaction. OP_FINDASSETGROUPBYASSETID converts an Asset ID to k. The source transaction ID of an operator-request input is not an Asset ID.
Each opcode in this group fails the script if the transaction has no asset packet. Only the group that issues an asset carries its control asset, so OP_INSPECTASSETGROUPCTRL finds none on a later mint, burn, or transfer.
Reserved
OP_NOP1 and OP_NOP5–OP_NOP10 do nothing. OP_RESERVED, OP_VER, OP_VERIF, OP_VERNOTIF, OP_RESERVED1, OP_RESERVED2, and each unassigned value fail the script.
Advanced
Key tweak
An emulator-enforced path uses the emulator key. The hash of the Arkade Script of the path tweaks the key:P_even is the emulator key with even y. The tweak binds the key to one script. A different script gives a different key, so nobody can substitute another script when the operator signs. The SDK function computeArkadeScriptPublicKey calculates P_tweaked. OP_INSPECTINPUTARKADESCRIPTHASH pushes h.
Signature checks
OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKSIGADD, and OP_SIGHASH use a digest that differs from the BIP342 digest in two ways. The final BIP-340 tag is ArkadeTapSighash, not TapSighash, so a signature for one digest fails for the other.
The digest also ignores the witness of each Emulator Packet entry: the witness length is 0 in sha_outputs. A party can sign a script before anyone supplies witness arguments, and the arguments can change between spend attempts. The signatures that the operator adds to the transaction use the standard BIP342 digest.
The TypeScript SDK does not calculate the Arkade digest. To check a signature over your own message, use OP_CHECKSIGFROMSTACK. The complete function of the escrow vault does this.
Emulator Packet
An Emulator Packet carries the script and the witness of each emulator-enforced input. It is a TLV record of type0x01 in an ARK extension. An ARK extension is an OP_RETURN output that starts with the bytes ARK (0x41524b). The README gives the format and the limits.
OP_INSPECTPACKET and OP_INSPECTINPUTPACKET read the packet bytes. A script that uses them depends on the exact byte format. A format change is a protocol change.
Compute limits
The emulator limits how many times each heavy opcode can run in one input. Other opcodes have no limit. Across a whole request, each opcode can run at most 4 times its limit for one input, however many inputs the request spends. The operator can change the limits withEMULATOR_COMPUTE_LIMITS.
Endpoints
The/v1/info endpoint returns signerPubkey.
The SDK exports each pinned key, such as
BITCOIN_EMULATOR_PUBKEY for mainnet. Signet and other networks have no pin: pass the emulator key as emulatorPubkey to Arkade.connect.
Check the pinned key
The SDK builds emulator-enforced paths with the key that it pins for the network, and it never uses the key that the emulator reports. If this code printsfalse, the emulator key differs from the pinned key. The cause is a key rotation, a compromised key, or a man-in-the-middle at the network boundary. Halt emulator-enforced spends and verify the cause before you upgrade @arkade-os/sdk. During a key rotation, the operator also signs with deprecated emulator keys. It can set EMULATOR_DEPRECATED_KEYS_VALID_UNTIL to end that period.
emulator-key.ts