pub enum Opcode {
Show 81 variants
ADD(usize, usize, usize),
ADDI(usize, usize, u16),
AND(usize, usize, usize),
ANDI(usize, usize, u16),
DIV(usize, usize, usize),
DIVI(usize, usize, u16),
EQ(usize, usize, usize),
EXP(usize, usize, usize),
EXPI(usize, usize, u16),
GT(usize, usize, usize),
LT(usize, usize, usize),
MLOG(usize, usize, usize),
MROO(usize, usize, usize),
MOD(usize, usize, usize),
MODI(usize, usize, u16),
MOVE(usize, usize),
MUL(usize, usize, usize),
MULI(usize, usize, u16),
NOT(usize, usize),
OR(usize, usize, usize),
ORI(usize, usize, u16),
SLL(usize, usize, usize),
SLLI(usize, usize, u16),
SRL(usize, usize, usize),
SRLI(usize, usize, u16),
SUB(usize, usize, usize),
SUBI(usize, usize, u16),
XOR(usize, usize, usize),
XORI(usize, usize, u16),
CIMV(usize, usize, usize),
CTMV(usize, usize),
JI(u32),
JNEI(usize, usize, u16),
RET(usize),
RETD(usize, usize),
CFEI(u32),
CFSI(u32),
LB(usize, usize, u16),
LW(usize, usize, u16),
ALOC(usize),
MCL(usize, usize),
MCLI(usize, u32),
MCP(usize, usize, usize),
MCPI(usize, usize, u16),
MEQ(usize, usize, usize, usize),
SB(usize, usize, u16),
SW(usize, usize, u16),
BAL(usize, usize, usize),
BHSH(usize, usize),
BHEI(usize),
BURN(usize),
CALL(usize, usize, usize, usize),
CCP(usize, usize, usize, usize),
CROO(usize, usize),
CSIZ(usize, usize),
CB(usize),
LDC(usize, usize, usize),
LOG(usize, usize, usize, usize),
LOGD(usize, usize, usize, usize),
MINT(usize),
RVRT(usize),
SLDC(usize, usize, usize),
SRW(usize, usize),
SRWQ(usize, usize),
SWW(usize, usize),
SWWQ(usize, usize),
TR(usize, usize, usize),
TRO(usize, usize, usize, usize),
ECR(usize, usize, usize),
K256(usize, usize, usize),
S256(usize, usize, usize),
XIL(usize, usize),
XIS(usize, usize),
XOL(usize, usize),
XOS(usize, usize),
XWL(usize, usize),
XWS(usize, usize),
NOOP,
FLAG(usize),
GM(usize, u32),
Undefined,
}
Expand description
Instruction representation for the interpreter.
Memory Opcodes
All these opcodes advance the program counter $pc
by 4
after performing
their operation. Every instruction is guaranteed to fit in u32
representation.
Arithmetic/Logic (ALU) Opcodes
All these opcodes advance the program counter $pc
by 4
after performing
their operation.
If the F_UNSAFEMATH
flag is unset, an operation that
would have set $err
to true
is instead a panic.
If the F_WRAPPING
flag is unset, an operation that
would have set $of
to a non-zero value is instead a panic. ## Contract
Opcodes
All these opcodes advance the program counter $pc
by 4
after performing
their operation, except for CALL and
REVERT.
Cryptographic Opcodes
All these opcodes advance the program counter $pc
by 4
after performing
their operation.
Variants
ADD(usize, usize, usize)
Adds two registers.
| Operation | $rA = $rB + $rC;
|
| Syntax | add $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register.
Execution
$of
is assigned the overflow of the operation.
$err
is cleared.
ADDI(usize, usize, u16)
Adds a register and an immediate value.
| Operation | $rA = $rB + imm;
|
| Syntax | addi $rA, $rB, immediate
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA
is a reserved register.
Execution
$of
is assigned the overflow of the operation.
$err
is cleared.
AND(usize, usize, usize)
Bitwise ANDs two registers.
| Operation | $rA = $rB & $rC;
|
| Syntax | and $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register.
Execution
$of
and $err
are cleared.
ANDI(usize, usize, u16)
Bitwise ANDs a register and an immediate value.
| Operation | $rA = $rB & imm;
|
| Syntax | andi $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA
is a reserved register.
Execution
imm
is extended to 64 bits, with the high 52 bits set to 0
.
$of
and $err
are cleared.
DIV(usize, usize, usize)
Divides two registers.
| Operation | $rA = $rB // $rC;
|
| Syntax | div $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register.
Execution
If $rC == 0
, $rA
is cleared and $err
is set to true
.
Otherwise, $err
is cleared.
$of
is cleared.
DIVI(usize, usize, u16)
Divides a register and an immediate value.
| Operation | $rA = $rB // imm;
|
| Syntax | divi $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA
is a reserved register.
Execution
If imm == 0
, $rA
is cleared and $err
is set to true
.
Otherwise, $err
is cleared.
$of
is cleared.
EQ(usize, usize, usize)
Compares two registers for equality.
| Operation | $rA = $rB == $rC;
|
| Syntax | eq $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register,
Execution
$of
and $err
are cleared.
EXP(usize, usize, usize)
Raises one register to the power of another.
| Operation | $rA = $rB ** $rC;
|
| Syntax | exp $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register
Execution
If the result cannot fit in 8 bytes, $of
is set to 1
, otherwise
$of
is cleared.
$err
is cleared.
EXPI(usize, usize, u16)
Raises one register to the power of an immediate value.
| Operation | $rA = $rB ** imm;
|
| Syntax | expi $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA
is a reserved register
Execution
If the result cannot fit in 8 bytes, $of
is set to 1
, otherwise
$of
is cleared.
$err
is cleared.
GT(usize, usize, usize)
Compares two registers for greater-than.
| Operation | $rA = $rB > $rC;
|
| Syntax | gt $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register
Execution
$of
and $err
are cleared.
LT(usize, usize, usize)
Compares two registers for less-than.
| Operation | $rA = $rB < $rC;
|
| Syntax | lt $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register
Execution
$of
and $err
are cleared.
MLOG(usize, usize, usize)
The (integer) logarithm base $rC
of $rB
.
| Operation | $rA = math.floor(math.log($rB, $rC));
|
| Syntax | mlog $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register
Execution
If $rB == 0
, both $rA
and $of
are cleared and $err
is set to
true
.
If $rC <= 1
, both $rA
and $of
are cleared and $err
is set to
true
.
Otherwise, $of
and $err
are cleared.
MROO(usize, usize, usize)
The (integer) $rC
th root of $rB
.
| Operation | $rA = math.floor(math.root($rB, $rC));
|
| Syntax | mroo $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register
Execution
If $rC == 0
, both $rA
and $of
are cleared and $err
is set to
true
.
Otherwise, $of
and $err
are cleared.
MOD(usize, usize, usize)
Modulo remainder of two registers.
| Operation | $rA = $rB % $rC;
|
| Syntax | mod $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register
Execution
If $rC == 0
, both $rA
and $of
are cleared and $err
is set to
true
.
Otherwise, $of
and $err
are cleared.
MODI(usize, usize, u16)
Modulo remainder of a register and an immediate value.
| Operation | $rA = $rB % imm;
|
| Syntax | modi $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA
is a reserved register
Execution
If imm == 0
, both $rA
and $of
are cleared and $err
is set to
true
.
Otherwise, $of
and $err
are cleared.
MOVE(usize, usize)
Copy from one register to another.
| Operation | $rA = $rB;
|
| Syntax | move $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
| Notes | |
Panics
$rA
is a reserved register
Execution
$of
and $err
are cleared.
MUL(usize, usize, usize)
Multiplies two registers.
| Operation | $rA = $rB * $rC;
|
| Syntax | mul $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register
Execution
$of
is assigned the overflow of the operation.
$err
is cleared.
MULI(usize, usize, u16)
Multiplies a register and an immediate value.
| Operation | $rA = $rB * imm;
|
| Syntax | mul $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA
is a reserved register
Execution
$of
is assigned the overflow of the operation.
$err
is cleared.
NOT(usize, usize)
Bitwise NOT a register.
| Operation | $rA = ~$rB;
|
| Syntax | not $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rA
is a reserved register
Execution
$of
and $err
are cleared.
OR(usize, usize, usize)
Bitwise ORs two registers.
| Operation | $rA = $rB \| $rC;
|
| Syntax | or $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register
Execution
$of
and $err
are cleared.
ORI(usize, usize, u16)
Bitwise ORs a register and an immediate value.
| Operation | $rA = $rB \| imm;
|
| Syntax | ori $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA
is a reserved register
Execution
imm
is extended to 64 bits, with the high 52 bits set to 0
.
$of
and $err
are cleared.
SLL(usize, usize, usize)
Left shifts a register by a register.
| Operation | $rA = $rB << $rC;
|
| Syntax | sll $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
| Notes | Zeroes are shifted in. |
Panics
$rA
is a reserved register
Execution
$of
is assigned the overflow of the operation.
$err
is cleared.
SLLI(usize, usize, u16)
Left shifts a register by an immediate value.
| Operation | $rA = $rB << imm;
|
| Syntax | slli $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
| Notes | Zeroes are shifted in. |
Panics
$rA
is a reserved register
Execution
$of
is assigned the overflow of the operation.
$err
is cleared.
SRL(usize, usize, usize)
Right shifts a register by a register.
| Operation | $rA = $rB >> $rC;
|
| Syntax | srl $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
| Notes | Zeroes are shifted in. |
Panics
$rA
is a reserved register
Execution
$of
is assigned the underflow of the operation, as though $of
is the
high byte of a 128-bit register.
$err
is cleared.
SRLI(usize, usize, u16)
Right shifts a register by an immediate value.
| Operation | $rA = $rB >> imm;
|
| Syntax | srli $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
| Notes | Zeroes are shifted in. |
Panics
$rA
is a reserved register
Execution
$of
is assigned the underflow of the operation, as though $of
is the
high byte of a 128-bit register.
$err
is cleared.
SUB(usize, usize, usize)
Subtracts two registers.
| Operation | $rA = $rB - $rC;
|
| Syntax | sub $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
| Notes | $of
is assigned the overflow of the operation. |
Panics
$rA
is a reserved register
Execution
$of
is assigned the underflow of the operation, as though $of
is the
high byte of a 128-bit register.
$err
is cleared.
SUBI(usize, usize, u16)
Subtracts a register and an immediate value.
| Operation | $rA = $rB - imm;
|
| Syntax | subi $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
| Notes | $of
is assigned the overflow of the operation. |
Panics
$rA
is a reserved register
Execution
$of
is assigned the underflow of the operation, as though $of
is the
high byte of a 128-bit register.
$err
is cleared.
XOR(usize, usize, usize)
Bitwise XORs two registers.
| Operation | $rA = $rB ^ $rC;
|
| Syntax | xor $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
| Notes | |
Panics
$rA
is a reserved register
Execution
$of
and $err
are cleared.
XORI(usize, usize, u16)
Bitwise XORs a register and an immediate value.
| Operation | $rA = $rB ^ imm;
|
| Syntax | xori $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
| Notes | |
Panics
$rA
is a reserved register
Execution
$of
and $err
are cleared.
CIMV(usize, usize, usize)
Set $rA
to true
if the $rC <= tx.input[$rB].maturity
.
| Operation | $rA = checkinputmaturityverify($rB, $rC);
|
| Syntax | cimv $rA $rB $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register$rC > tx.input[$rB].maturity
- the input
$rB
is not of typeInputType.Coin
$rB > tx.inputsCount
Execution
Otherwise, advance the program counter $pc
by 4
.
CTMV(usize, usize)
Set $rA
to true
if $rB <= tx.maturity
.
| Operation | $rA = checktransactionmaturityverify($rB);
|
| Syntax | ctmv $rA $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rA
is a reserved register$rB > tx.maturity
Execution
Otherwise, advance the program counter $pc
by 4
.
See also: BIP-65 and Bitcoin’s Time Locks.
JI(u32)
Tuple Fields
0: u32
Jumps to the code instruction offset by imm
.
| Operation | $pc = $is + imm * 4;
|
| Syntax | ji imm
|
| Encoding | 0x00 i i i i
|
Panics
$is + imm * 4 > VM_MAX_RAM - 1
JNEI(usize, usize, u16)
Jump to the code instruction offset by imm
if $rA
is not equal to
$rB
.
| Operation | if $rA != $rB:
$pc = $is + imm * 4;
else:
$pc += 4;
| Syntax | jnei $rA $rB imm
| Encoding | 0x00 rA rB i i
Panics
$is + imm * 4 > VM_MAX_RAM - 1
RET(usize)
Tuple Fields
0: usize
Returns from context with value $rA
.
| Operation | return($rA);
| Syntax | ret $rA
| Encoding | 0x00 rA - - -
If current context is external, cease VM execution and return $rA
.
Returns from contract call, popping the call frame. Before popping:
- Return the unused forwarded gas to the caller:
$cgas = $cgas + $fp->$cgas
(add remaining context gas from previous context to current remaining context gas)
Then pop the call frame and restoring registers except $ggas
and
$cgas
. Afterwards, set the following registers:
$pc = $pc + 4
(advance program counter from where we called)
RETD(usize, usize)
Return from context with data
| Operation | returndata($rA, $rB);
| Syntax | retd $rA, $rB
| Encoding | 0x00 rA rB - -
If current context is external, cease VM execution and return MEM[$rA, $rB]
.
Returns from contract call, popping the call frame. Before popping:
- Return the unused forwarded gas to the caller:
$cgas = $cgas + $fp->$cgas
(add remaining context gas from previous context to current remaining context gas)
Then pop the call frame and restoring registers except $ggas
and
$cgas
. Afterwards, set the following registers:
Set the return value:
-
$ret = $rA
-
$retl = $rB
-
$pc = $pc + 4
(advance program counter from where we called)
CFEI(u32)
Tuple Fields
0: u32
Extend the current call frame’s stack by an immediate value.
| Operation | $sp = $sp + imm
| Syntax | cfei imm
| Encoding | 0x00 i i i i
| Notes | Does not initialize memory.
Panics
$sp + imm
overflows$sp + imm > $hp
CFSI(u32)
Tuple Fields
0: u32
Shrink the current call frame’s stack by an immediate value.
| Operation | $sp = $sp - imm
| Syntax | cfsi imm
| Encoding | 0x00 i i i i
| Notes | Does not clear memory.
Panics
$sp - imm
underflows$sp - imm < $ssp
LB(usize, usize, u16)
A byte is loaded from the specified address offset by imm
.
| Operation | $rA = MEM[$rB + imm, 1];
| Syntax | lb $rA, $rB, imm
| Encoding | 0x00 rA rB i i
Panics
$rA
is a reserved register$rB + imm + 1
overflows$rB + imm + 1 > VM_MAX_RAM
LW(usize, usize, u16)
A word is loaded from the specified address offset by imm
.
| Operation | $rA = MEM[$rB + imm, 8];
| Syntax | lw $rA, $rB, imm
| Encoding | 0x00 rA rB i i
Panics
$rA
is a reserved register$rB + imm + 8
overflows$rB + imm + 8 > VM_MAX_RAM
ALOC(usize)
Tuple Fields
0: usize
Allocate a number of bytes from the heap.
| Operation | $hp = $hp - $rA;
|
| Syntax | aloc $rA
|
| Encoding | 0x00 rA - - -
|
| Notes | Does not initialize memory. |
Panics
$hp - $rA
underflows$hp - $rA < $sp
MCL(usize, usize)
Clear bytes in memory.
| Operation | MEM[$rA, $rB] = 0;
|
| Syntax | mcl $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rA + $rB
overflows$rA + $rB > VM_MAX_RAM
$rB > MEM_MAX_ACCESS_SIZE
- The memory range
MEM[$rA, $rB]
does not pass ownership check
MCLI(usize, u32)
Clear bytes in memory.
| Operation | MEM[$rA, imm] = 0;
|
| Syntax | mcli $rA, imm
|
| Encoding | 0x00 rA i i i
|
Panics
$rA + imm
overflows$rA + imm > VM_MAX_RAM
imm > MEM_MAX_ACCESS_SIZE
- The memory range
MEM[$rA, imm]
does not pass ownership check
MCP(usize, usize, usize)
Copy bytes in memory.
| Operation | MEM[$rA, $rC] = MEM[$rB, $rC];
|
| Syntax | mcp $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA + $rC
overflows$rB + $rC
overflows$rA + $rC > VM_MAX_RAM
$rB + $rC > VM_MAX_RAM
$rC > MEM_MAX_ACCESS_SIZE
- The memory ranges
MEM[$rA, $rC]
andMEM[$rB, $rC]
overlap - The memory range
MEM[$rA, $rC]
does not pass ownership check
MCPI(usize, usize, u16)
Copy bytes in memory.
| Operation | MEM[$rA, imm] = MEM[$rB, imm];
|
| Syntax | mcpi $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA + imm
overflows$rB + imm
overflows$rA + imm > VM_MAX_RAM
$rB + imm > VM_MAX_RAM
imm > MEM_MAX_ACCESS_SIZE
- The memory ranges
MEM[$rA, imm]
andMEM[$rB, imm]
overlap - The memory range
MEM[$rA, imm]
does not pass ownership check
MEQ(usize, usize, usize, usize)
Compare bytes in memory.
| Operation | $rA = MEM[$rB, $rD] == MEM[$rC, $rD];
|
| Syntax | meq $rA, $rB, $rC, $rD
|
| Encoding | 0x00 rA rB rC rD
|
Panics
$rA
is a reserved register$rB + $rD
overflows$rC + $rD
overflows$rB + $rD > VM_MAX_RAM
$rC + $rD > VM_MAX_RAM
$rD > MEM_MAX_ACCESS_SIZE
SB(usize, usize, u16)
The least significant byte of $rB
is stored at the address $rA
offset by imm
.
| Operation | MEM[$rA + imm, 1] = $rB[7, 1];
|
| Syntax | sb $rA, $rB, imm
|
| Encoding | 0x00 rA rB i i
|
Panics
$rA + imm + 1
overflows$rA + imm + 1 > VM_MAX_RAM
- The memory range
MEM[$rA + imm, 1]
does not pass ownership check
SW(usize, usize, u16)
The value of $rB
is stored at the address $rA
offset by imm
.
| Operation | MEM[$rA + imm, 8] = $rB;
| Syntax | sw $rA, $rB, imm
| Encoding | 0x00 rA rB i i
Panics
$rA + imm + 8
overflows$rA + imm + 8 > VM_MAX_RAM
- The memory range
MEM[$rA + imm, 8]
does not pass ownership check
BAL(usize, usize, usize)
Set $rA
to the balance of color at $rB
for contract with ID at
$rC
. Where helper
balance(color: byte[32], contract_id: byte[32]) -> uint64
returns the current balance of color
of contract with ID
contract_id
.
| Operation | $rA = balance(MEM[$rB, 32], MEM[$rC, 32]);
|
| Syntax | bal $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA
is a reserved register$rB + 32
overflows$rB + 32 > VM_MAX_RAM
$rC + 32
overflows$rC + 32 > VM_MAX_RAM
- Contract with ID
MEM[$rC, 32]
is not intx.inputs
BHSH(usize, usize)
Get block header hash.
| Operation | MEM[$rA, 32] = blockhash($rB);
|
| Syntax | bhsh $rA $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rA + 32
overflows$rA + 32 > VM_MAX_RAM
- The memory range
MEM[$rA, 32]
does not pass ownership check
Block header hashes for blocks with height greater than or equal to
current block height are zero (0x00**32
).
BHEI(usize)
Tuple Fields
0: usize
Get Fuel block height.
| Operation | $rA = blockheight();
|
| Syntax | bhei $rA
|
| Encoding | 0x00 rA - - -
|
Panics
$rA
is a reserved register
BURN(usize)
Tuple Fields
0: usize
Burn $rA
coins of the current contract’s color.
| Operation | burn($rA);
|
| Syntax | burn $rA
|
| Encoding | 0x00 rA - - -
|
Panic
- Balance of color
MEM[$fp, 32]
of output with contract IDMEM[$fp, 32]
minus$rA
underflows $fp == 0
(in the script context)
For output with contract ID MEM[$fp, 32]
, decrease balance of color
MEM[$fp, 32]
by $rA
.
This modifies the balanceRoot
field of the appropriate output.
CALL(usize, usize, usize, usize)
Call contract.
| Syntax | call $rA $rB $rC $rD
|
| Encoding | 0x00 rA rB rC rD
|
Panics
$rA + 32
overflows$rC + 32
overflows- Contract with ID
MEM[$rA, 32]
is not intx.inputs
- Reading past
MEM[VM_MAX_RAM - 1]
- Any output range does not pass ownership check
- In an external context, if
$rB > MEM[balanceOfStart(MEM[$rC, 32]), 8]
- In an internal context, if
$rB
is greater than the balance of colorMEM[$rC, 32]
of output with contract IDMEM[$rA, 32]
Register $rA
is a memory address from which the following fields are
set (word-aligned).
$rD
is the amount of gas to forward. If it is set to an amount greater
than the available gas, all available gas is forwarded.
For output with contract ID MEM[$rA, 32]
, increase balance of color
MEM[$rC, 32]
by $rB
. In an external context, decrease
MEM[balanceOfStart(MEM[$rC, 32]), 8]
by $rB
. In an internal context,
decrease color MEM[$rC, 32]
balance of output with contract ID
MEM[$fp, 32]
by $rB
.
A call frame is pushed at $sp
. In addition to
filling in the values of the call frame, the following registers are
set:
$fp = $sp
(on top of the previous call frame is the beginning of this call frame) 1. Set$ssp
and$sp
to the start of the writable stack area of the call frame. 1. Set$pc
and$is
to the starting address of the code. 1.$bal = $rD
(forward coins)$cgas = $rD
or all available gas (forward gas)
This modifies the balanceRoot
field of the appropriate output(s).
CCP(usize, usize, usize, usize)
Copy $rD
bytes of code starting at $rC
for contract with ID equal to
the 32 bytes in memory starting at $rB
into memory starting at $rA
.
| Operation | MEM[$rA, $rD] = code($rB, $rC, $rD);
| Syntax | ccp $rA, $rB, $rC, $rD
| Encoding | 0x00 rA rB rC rD
| Notes | If $rD
is greater than the code size, zero bytes are
filled in.
Panics
$rA + $rD
overflows$rB + 32
overflows$rA + $rD > VM_MAX_RAM
$rB + 32 > VM_MAX_RAM
- The memory range
MEM[$rA, $rD]
does not pass ownership check $rD > MEM_MAX_ACCESS_SIZE
- Contract with ID
MEM[$rB, 32]
is not intx.inputs
CROO(usize, usize)
Set the 32 bytes in memory starting at $rA
to the code root for
contract with ID equal to the 32 bytes in memory starting at $rB
.
| Operation | MEM[$rA, 32] = coderoot(MEM[$rB, 32]);
| Syntax | croo $rA, $rB
| Encoding | 0x00 rA rB - -
Panics
$rA + 32
overflows$rB + 32
overflows$rA + 32 > VM_MAX_RAM
$rB + 32 > VM_MAX_RAM
- The memory range
MEM[$rA, 32]
does not pass ownership check - Contract with ID
MEM[$rB, 32]
is not intx.inputs
Code root compuration is defined here.
CSIZ(usize, usize)
Set $rA
to the size of the code for contract with ID equal to the 32
bytes in memory starting at $rB
.
| Operation | $rA = codesize(MEM[$rB, 32]);
| Syntax | csiz $rA, $rB
| Encoding | 0x00 rA rB - -
Panics
$rA
is a reserved register$rB + 32
overflows$rB + 32 > VM_MAX_RAM
- Contract with ID
MEM[$rB, 32]
is not intx.inputs
CB(usize)
Tuple Fields
0: usize
Get block proposer address.
| Operation | MEM[$rA, 32] = coinbase();
|
| Syntax | cb $rA
|
| Encoding | 0x00 rA - - -
|
Panics
$rA + 32
overflows$rA + 32 > VM_MAX_RAM
- The memory range
MEM[$rA, 32]
does not pass ownership check
LDC(usize, usize, usize)
Copy $rC
bytes of code starting at $rB
for contract with ID equal to
the 32 bytes in memory starting at $rA
into memory starting at $ssp
.
| Operation | MEM[$ssp, $rC] = code($rA, $rB, $rC);
| Syntax | ldc $rA, $rB, $rC
| Encoding | 0x00 rA rB rC -
| Notes | If $rC
is greater than the code size, zero bytes are
filled in.
Panics
$ssp + $rC
overflows$rA + 32
overflows$ssp + $rC > VM_MAX_RAM
$rA + 32 > VM_MAX_RAM
$ssp != $sp
$ssp + $rC > $hp
$rC > CONTRACT_MAX_SIZE
$rC > MEM_MAX_ACCESS_SIZE
- Contract with ID
MEM[$rA, 32]
is not intx.inputs
Increment $hp->codesize
, $ssp
, and $sp
by $rC
padded to word
alignment.
This opcode can be used to concatenate the code of multiple contracts together. It can only be used when the stack area of the call frame is unused (i.e. prior to being used).
LOG(usize, usize, usize, usize)
Log an event. This is a no-op.
| Operation | log($rA, $rB, $rC, $rD);
|
| Syntax | log $rA, $rB, $rC, $rD
|
| Encoding | 0x00 rA rB rC rD
|
LOGD(usize, usize, usize, usize)
Logs the memory range MEM[$rC, $rD]
. This is a no-op.
| Syntax | logd $rA, $rB, $rC, $rD
|
| Encoding | 0x00 rA rB rC rD
|
MINT(usize)
Tuple Fields
0: usize
Mint $rA
coins of the current contract’s color.
| Operation | mint($rA);
|
| Syntax | mint $rA
|
| Encoding | 0x00 rA - - -
|
Panics
- Balance of color
MEM[$fp, 32]
of output with contract IDMEM[$fp, 32]
plus$rA
overflows $fp == 0
(in the script context)
For output with contract ID MEM[$fp, 32]
, increase balance of color
MEM[$fp, 32]
by $rA
.
This modifies the balanceRoot
field of the appropriate output.
RVRT(usize)
Tuple Fields
0: usize
Halt execution, reverting state changes and returning value in $rA
.
| Operation | revert($rA);
| Syntax | rvrt $rA
| Encoding | 0x00 rA - - -
After a revert:
- All OutputContract outputs
will have the same
amount
andstateRoot
as on initialization. 1. All OutputVariable (../protocol/tx_format.md outputs#outputvariable) outputs will haveto
andamount
of zero. - All OutputContractConditional (../protocol/tx_format.md#
outputcontractconditional) outputs will have
contractID
,amount
, andstateRoot
of zero.
SLDC(usize, usize, usize)
Copy $rC
bytes of code starting at $rB
for contract with static
index $rA
into memory starting at $ssp
.
| Operation | MEM[$ssp, $rC] = scode($rA, $rB, $rC);
| Syntax | sloadcode $rA, $rB, $rC
| Encoding | 0x00 rA rB rC -
| Notes | If $rC
is greater than the code size, zero bytes
are filled in. |
Panics
$ssp + $rC
overflows$ssp + $rC > VM_MAX_RAM
$rA >= MAX_STATIC_CONTRACTS
$rA
is greater than or equal tostaticContractsCount
for the contract with IDMEM[$fp, 32]
$ssp != $sp
$ssp + $rC > $hp
$rC > CONTRACT_MAX_SIZE
$rC > MEM_MAX_ACCESS_SIZE
$fp == 0
(in the script context)
Increment $hp->codesize
, $ssp
, and $sp
by $rC
padded to word
alignment.
This opcode can be used to concatenate the code of multiple contracts together. It can only be used when the stack area of the call frame is unused (i.e. prior to being used).
SRW(usize, usize)
A word is read from the current contract’s state.
| Operation | $rA = STATE[MEM[$rB, 32]][0, 8];
|
| Syntax | srw $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
| Notes | Returns zero if the state element does not exist. |
Panics
$rA
is a reserved register$rB + 32
overflows$rB + 32 > VM_MAX_RAM
$fp == 0
(in the script context)
SRWQ(usize, usize)
32 bytes is read from the current contract’s state.
| Operation | MEM[$rA, 32] = STATE[MEM[$rB, 32]];
|
| Syntax | srwx $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
| Notes | Returns zero if the state element does not exist. |
Panics
$rA + 32
overflows$rB + 32
overflows$rA + 32 > VM_MAX_RAM
$rB + 32 > VM_MAX_RAM
- The memory range
MEM[$rA, 32]
does not pass ownership check $fp == 0
(in the script context)
SWW(usize, usize)
A word is written to the current contract’s state.
| Operation | STATE[MEM[$rA, 32]][0, 8] = $rB;
|
| Syntax | sww $rA $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rA + 32
overflows$rA + 32 > VM_MAX_RAM
$fp == 0
(in the script context)
SWWQ(usize, usize)
32 bytes is written to the current contract’s state.
| Operation | STATE[MEM[$rA, 32]] = MEM[$rB, 32];
|
| Syntax | swwx $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rA + 32
overflows$rB + 32
overflows$rA + 32 > VM_MAX_RAM
$rB + 32 > VM_MAX_RAM
$fp == 0
(in the script context)
TR(usize, usize, usize)
Transfer $rB
coins with color at $rC
to contract with ID at $rA
.
| Operation | transfer(MEM[$rA, 32], $rB, MEM[$rC, 32]);
| Syntax | tr $rA, $rB, $rC
| Encoding | 0x00 rA rB rC -
Given helper balanceOfStart(color: byte[32]) -> uint32
which returns
the memory address of color
balance, or 0
if color
has no balance.
Panics
$rA + 32
overflows$rC + 32
overflows$rA + 32 > VM_MAX_RAM
$rC + 32 > VM_MAX_RAM
- Contract with ID
MEM[$rA, 32]
is not intx.inputs
- In an external context, if
$rB > MEM[balanceOf(MEM[$rC, 32]), 8]
- In an internal context, if
$rB
is greater than the balance of colorMEM[$rC, 32]
of output with contract IDMEM[$fp, 32]
$rB == 0
For output with contract ID MEM[$rA, 32]
, increase balance of color
MEM[$rC, 32]
by $rB
. In an external context, decrease
MEM[balanceOfStart(MEM[$rC, 32]), 8]
by $rB
. In an internal context,
decrease color MEM[$rC, 32]
balance of output with contract ID
MEM[$fp, 32]
by $rB
.
This modifies the balanceRoot
field of the appropriate output(s).
TRO(usize, usize, usize, usize)
Transfer $rC
coins with color at $rD
to address at $rA
, with
output $rB
. | Operation | transferout(MEM[$rA, 32], $rB, $rC, MEM[$rD, 32]);
| Syntax | tro $rA, $rB, $rC, $rD
| Encoding | 0x00 rA rB rC rD
Given helper balanceOfStart(color: byte[32]) -> uint32
which returns
the memory address of color
balance, or 0
if color
has no balance.
Panics
$rA + 32
overflows$rD + 32
overflows$rA + 32 > VM_MAX_RAM
$rD + 32 > VM_MAX_RAM
$rB > tx.outputsCount
- In an external context, if
$rC > MEM[balanceOf(MEM[$rD, 32]), 8]
- In an internal context, if
$rC
is greater than the balance of colorMEM[$rD, 32]
of output with contract IDMEM[$fp, 32]
$rC == 0
tx.outputs[$rB].type != OutputType.Variable
tx.outputs[$rB].amount != 0
In an external context, decrease MEM[balanceOfStart(MEM[$rD, 32]), 8]
by $rC
. In an internal context, decrease color MEM[$rD, 32]
balance
of output with contract ID MEM[$fp, 32]
by $rC
. Then set:
tx.outputs[$rB].to = MEM[$rA, 32]
tx.outputs[$rB].amount = $rC
tx.outputs[$rB].color = MEM[$rD, 32]
This modifies the balanceRoot
field of the appropriate output(s).
ECR(usize, usize, usize)
The 64-byte public key (x, y) recovered from 64-byte
signature starting at $rB
on 32-byte message hash starting at $rC
. |
| Operation | MEM[$rA, 64] = ecrecover(MEM[$rB, 64], MEM[$rC, 32]);
| Syntax | ecr $rA, $rB, $rC
| Encoding | 0x00 rA rB rC -
Panics
$rA + 64
overflows$rB + 64
overflows$rC + 32
overflows$rA + 64 > VM_MAX_RAM
$rB + 64 > VM_MAX_RAM
$rC + 32 > VM_MAX_RAM
- The memory range
MEM[$rA, 64]
does not pass ownership check
To get the address, hash the public key with SHA-2-256.
K256(usize, usize, usize)
The keccak-256 hash of $rC
bytes starting at $rB
.
| Operation | MEM[$rA, 32] = keccak256(MEM[$rB, $rC]);
| Syntax | k256 $rA, $rB, $rC
| Encoding | 0x00 rA rB rC -
Panics
$rA + 32
overflows$rB + $rC
overflows$rA + 32 > VM_MAX_RAM
$rB + $rC > VM_MAX_RAM
- The memory range
MEM[$rA, 32]
does not pass ownership check $rC > MEM_MAX_ACCESS_SIZE
S256(usize, usize, usize)
The SHA-2-256 hash of $rC
bytes starting at $rB
.
| Operation | MEM[$rA, 32] = sha256(MEM[$rB, $rC]);
|
| Syntax | s256 $rA, $rB, $rC
|
| Encoding | 0x00 rA rB rC -
|
Panics
$rA + 32
overflows$rB + $rC
overflows$rA + 32 > VM_MAX_RAM
$rB + $rC > VM_MAX_RAM
- The memory range
MEM[$rA, 32]
does not pass ownership check $rC > MEM_MAX_ACCESS_SIZE
XIL(usize, usize)
Set $rA
to the length in bytes of the $rB
th
input.
| Operation | $rA = xil($rB);
|
| Syntax | xil $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rB >= tx.inputsCount
XIS(usize, usize)
Set $rA
to the memory addess of the start of the $rB
th
input.
| Operation | $rA = xis($rB);
|
| Syntax | xis $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rB >= tx.inputsCount
XOL(usize, usize)
Set $rA
to the length in bytes of the $rB
th
output.
| Operation | $rA = xol($rB);
|
| Syntax | xol $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rB >= tx.outputsCount
XOS(usize, usize)
Set $rA
to the memory addess of the start of the $rB
th
output.
| Operation | $rA = xos($rB);
|
| Syntax | xos $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rB >= tx.outputsCount
XWL(usize, usize)
Set $rA
to the length in bytes of the $rB
th
witness.
| Operation | $rA = xwl($rB);
|
| Syntax | xwl $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rB >= tx.witnessesCount
Note that the returned length includes the entire
witness, not just of the witness’s data
field.
XWS(usize, usize)
Set $rA
to the memory addess of the start of the $rB
th
witness.
| Operation | $rA = xws($rB);
|
| Syntax | xws $rA, $rB
|
| Encoding | 0x00 rA rB - -
|
Panics
$rB >= tx.witnessesCount
Note that the returned memory address includes the entire
witness, not just of the witness’s data
field.
NOOP
Performs no operation.
| Operation | |
| Syntax | noop
|
| Encoding | 0x00 - - - -
|
$of
and $err
are cleared.
FLAG(usize)
Tuple Fields
0: usize
Set $flag
to $rA
.
| Operation | $flag = $rA;
|
| Syntax | flag $rA
|
| Encoding | 0x00 rA - - -
|
GM(usize, u32)
Get metadata from memory
| Operation | Selected by imm
|
| Syntax | gm $rA, imm
|
| Encoding | 0x00 rA imm imm imm
|
Undefined
Undefined opcode, potentially from inconsistent serialization
Implementations
Create a new Opcode
given the internal attributes
Create a Opcode
from a slice of bytes
Safety
Reflects the requirements of bytes::from_slice_unchecked
Transform the Opcode
into an optional array of 4 register
identifiers
Create a Opcode
from a slice of bytes
This function will fail if the length of the bytes is smaller than
Opcode::LEN
.
Create a set of Opcode
from an iterator of bytes
If not padded to Self::LEN
, will consume the unaligned bytes but won’t try to parse an
opcode from them.
Trait Implementations
Performs the conversion.
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read
, except that it reads into a slice of buffers. Read more
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
Read all bytes until EOF in this source, placing them into buf
. Read more
Read all bytes until EOF in this source, appending them to buf
. Read more
Read the exact number of bytes required to fill buf
. Read more
read_buf
)Pull some bytes from this source into the specified buffer. Read more
read_buf
)Read the exact number of bytes required to fill buf
. Read more
Creates a “by reference” adaptor for this instance of Read
. Read more
Creates an adapter which will chain this stream with another. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Auto Trait Implementations
impl RefUnwindSafe for Opcode
impl UnwindSafe for Opcode
Blanket Implementations
Mutably borrows from an owned value. Read more