TurtleVm is an evaluator for Bitcoin Cash Script (2025 & beyond) implemented in Bitcoin Cash Script (2025). It currently supports all the opcodes except: OP_PUSHDATA_X, OP_TOALTSTACK, OP_FROMALTSTACK, OP_CODESEPARATOR, OP_ACTIVEBYTECODE. It uses the primary stack of the underlying Bitcoin Cash VM and is therefore subject to the same limits on the size of the stack entries. It has a separate control stack with configurable size. TurtleVm is a Proof of Concept and is not fully developed and tested.
The main purpose of TurtleVm is to illustrate this point:
In practice, the difference between code and data in Bitcoin Cash Script is not clear cut.
Today P2SH contracts can accept data (byte strings) as input. They can transform/mutate data using several opcodes. Using the conditional branching opcodes, contracts can let data affect the control flow in the contract. Data affecting the control flow sounds a bit like code. If the data is made to be byte strings of Bitcoin Cash opcodes, then it also resembles code. If the contract can arrange its control flow based on these “byte strings of opcodes” in a similar way as the Bitcoin Cash VM would, so that the effect on the primary stack is the same, then the similarity with code is complete. This is how TurtleVm operates.
Due to lack of loops in BCH2025, TurtleVm’s opcode evaluator must be unrolled. Therefore TurtleVm grows with the length of the opcode sequences it should be able to evaluate. This makes it impractical/impossible to use the full TurtleVm in Mainnet transactions. However, it is possible to create versions of TurtleVm that can evaluate short programs consisting of a very limited subset of opcodes. One such limited version is MiniTurtleVm-101 which is small enough to be relayed in a transaction on Mainnet.
MiniTurtleVm-101 has the following properties:
-
P1: It can evaluate a trace of a maximum of 12 opcodes.
-
P2: It supports these opcodes:
-
OP_DATA_02 (0x02): ( – {two-byte string} )
-
OP_1 (0x51): ( – 1)
-
OP_1ADD (0x8b): ( x1 – {x1 + 1} )
-
OP_MUL (0x95): ( x1 x2 – {x1 * x2} )
-
OP_DEFINE (0x89): ( {bytes} – )
-
OP_INVOKE (0x8a): ( – {result of function evaluation} )
-
As seen above, MiniTurtleVm-101 supports OP_DEFINE/OP_INVOKE (limited versions); opcodes that are not present in the implementation language (Bitcoin Cash Script (2025)).
-
-
P3: The default OP_DEFINE function at VM startup is “OP_0”.
A contract using MiniTurtleVm-101 has been deployed in a P2SH transaction at:
bitcoincash:pzf0mthtyfnm8fmma9ew9n59282azuq4egu6hx6slq
with BCH 0.02 (~1 beer or so) in funds. The contract will release the funds to anyone who can provide a MiniTurtleVm-101 program satisfying the following conditions (or who can utilize any bugs in the contract):
-
C1: The program is a maximum of 9 bytes long.
-
C2: The program leaves the value 5 on the stack when finished (and nothing else).
-
C3: The program does not use the same byte/opcode twice in a row.
-
C4: The program does not use OP_1ADD right after OP_MUL.
The contract redeem script (which contains MiniTurtleVm-101) is:
8259a1697601ff7c768251a27763517f527952798791697b0195876378018b879169686768768251a27763517f527952798791697b0195876378018b879169686768768251a27763517f527952798791697b0195876378018b879169686768768251a27763517f527952798791697b0195876378018b879169686768768251a27763517f527952798791697b0195876378018b879169686768768251a27763517f527952798791697b0195876378018b879169686768768251a27763517f527952798791697b0195876378018b879169686768768251a27763517f527952798791697b0195876378018b879169686768768251a27763517f527952798791697b0195876378018b8791696867686d01006b6b6c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c6375956702453100696868686868686775686c82009c636b5267517f6b517c7e68517f7c51876301007e815167750000686376529c63756c527f6b677601519c6375516776028b009c63758b67760289009c63756c6c757c6b6b6776028a009c63756c6c767b7e7c6b6b67760295009c637595670245310069686868686868677568559d51
The contract takes a single argument which is the MiniTurtleVm-101 program to evaluate.
The above P2SH contract illustrates that today’s contracts can accept “code” as input. They can also perform “code” mutation.
All of the above ties into the risk discussions around “CHIP-2025-05 Functions”. I’m for the Functions CHIP in its current formulation: https://github.com/bitjson/bch-functions (3c40074).
I’ll push the source code as part of the albaDsl project later.