pub enum Opcode {
Show 115 variants
OP_0 = 0,
OP_PUSHDATA1 = 76,
OP_PUSHDATA2 = 77,
OP_PUSHDATA4 = 78,
OP_1NEGATE = 79,
OP_RESERVED = 80,
OP_1 = 81,
OP_2 = 82,
OP_3 = 83,
OP_4 = 84,
OP_5 = 85,
OP_6 = 86,
OP_7 = 87,
OP_8 = 88,
OP_9 = 89,
OP_10 = 90,
OP_11 = 91,
OP_12 = 92,
OP_13 = 93,
OP_14 = 94,
OP_15 = 95,
OP_16 = 96,
OP_NOP = 97,
OP_VER = 98,
OP_IF = 99,
OP_NOTIF = 100,
OP_VERIF = 101,
OP_VERNOTIF = 102,
OP_ELSE = 103,
OP_ENDIF = 104,
OP_VERIFY = 105,
OP_RETURN = 106,
OP_TOALTSTACK = 107,
OP_FROMALTSTACK = 108,
OP_2DROP = 109,
OP_2DUP = 110,
OP_3DUP = 111,
OP_2OVER = 112,
OP_2ROT = 113,
OP_2SWAP = 114,
OP_IFDUP = 115,
OP_DEPTH = 116,
OP_DROP = 117,
OP_DUP = 118,
OP_NIP = 119,
OP_OVER = 120,
OP_PICK = 121,
OP_ROLL = 122,
OP_ROT = 123,
OP_SWAP = 124,
OP_TUCK = 125,
OP_CAT = 126,
OP_SPLIT = 127,
OP_NUM2BIN = 128,
OP_BIN2NUM = 129,
OP_SIZE = 130,
OP_INVERT = 131,
OP_AND = 132,
OP_OR = 133,
OP_XOR = 134,
OP_EQUAL = 135,
OP_EQUALVERIFY = 136,
OP_RESERVED1 = 137,
OP_RESERVED2 = 138,
OP_1ADD = 139,
OP_1SUB = 140,
OP_2MUL = 141,
OP_2DIV = 142,
OP_NEGATE = 143,
OP_ABS = 144,
OP_NOT = 145,
OP_0NOTEQUAL = 146,
OP_ADD = 147,
OP_SUB = 148,
OP_MUL = 149,
OP_DIV = 150,
OP_MOD = 151,
OP_LSHIFT = 152,
OP_RSHIFT = 153,
OP_BOOLAND = 154,
OP_BOOLOR = 155,
OP_NUMEQUAL = 156,
OP_NUMEQUALVERIFY = 157,
OP_NUMNOTEQUAL = 158,
OP_LESSTHAN = 159,
OP_GREATERTHAN = 160,
OP_LESSTHANOREQUAL = 161,
OP_GREATERTHANOREQUAL = 162,
OP_MIN = 163,
OP_MAX = 164,
OP_WITHIN = 165,
OP_RIPEMD160 = 166,
OP_SHA1 = 167,
OP_SHA256 = 168,
OP_HASH160 = 169,
OP_HASH256 = 170,
OP_CODESEPARATOR = 171,
OP_CHECKSIG = 172,
OP_CHECKSIGVERIFY = 173,
OP_CHECKMULTISIG = 174,
OP_CHECKMULTISIGVERIFY = 175,
OP_NOP1 = 176,
OP_CHECKLOCKTIMEVERIFY = 177,
OP_CHECKSEQUENCEVERIFY = 178,
OP_NOP4 = 179,
OP_NOP5 = 180,
OP_NOP6 = 181,
OP_NOP7 = 182,
OP_NOP8 = 183,
OP_NOP9 = 184,
OP_NOP10 = 185,
OP_CHECKDATASIG = 186,
OP_CHECKDATASIGVERIFY = 187,
OP_REVERSEBYTES = 188,
FIRST_UNDEFINED_OP_VALUE = 189,
}Expand description
All opcodes which can be used in a Bitcoin Cash script.
Can be used in #[bitcoin_cash::script] functions.
§Example
use bitcoin_cash::{Opcode::*, Address, ByteArray, Hashed};
struct Params {
address: Address<'static>,
}
#[bitcoin_cash::script(P2pkhInputs)]
fn p2pkh_script(params: &Params, signature: ByteArray, public_key: ByteArray) {
OP_DUP(public_key);
let pkh = OP_HASH160(public_key);
let address = { params.address.hash().as_slice() };
OP_EQUALVERIFY(pkh, address);
OP_CHECKSIG(signature, public_key);
}Variants§
OP_0 = 0
OP_0() -> IntegerPushes the integer 0 onto the stack.
Usage:
let zero = OP_0;
let expected = 0; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(zero, expected);OP_PUSHDATA1 = 76
Pushes the next byte number of bytes. Not to be used in #[bitcoin_cash::script] functions.
OP_PUSHDATA2 = 77
Pushes the next two byte number of bytes. Not to be used in #[bitcoin_cash::script] functions.
OP_PUSHDATA4 = 78
Pushes the next four byte number of bytes. Not to be used in #[bitcoin_cash::script] functions.
OP_1NEGATE = 79
OP_1NEGATE() -> IntegerPushes the integer -1 onto the stack.
Usage:
// push -1
let minus_one = OP_1NEGATE;
let expected = -1; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(minus_one, expected);OP_RESERVED = 80
Reserved opcode. Fails script if in executed branch immediately.
OP_1 = 81
OP_1() -> IntegerPushes the integer 1 onto the stack.
Usage:
// push 1
let one = OP_1;
let expected = 1; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(one, expected);OP_2 = 82
OP_2() -> IntegerPushes the integer 2 onto the stack.
Usage:
// push 2
let two = OP_2;
let expected = 2; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(two, expected);OP_3 = 83
OP_3() -> IntegerPushes the integer 3 onto the stack.
Usage:
// push 3
let three = OP_3;
let expected = 3; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(three, expected);OP_4 = 84
OP_4() -> IntegerPushes the integer 4 onto the stack.
Usage:
// push 4
let four = OP_4;
let expected = 4; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(four, expected);OP_5 = 85
OP_5() -> IntegerPushes the integer 5 onto the stack.
Usage:
// push 5
let five = OP_5;
let expected = 5; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(five, expected);OP_6 = 86
OP_6() -> IntegerPushes the integer 6 onto the stack.
Usage:
// push 6
let six = OP_6;
let expected = 6; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(six, expected);OP_7 = 87
OP_7() -> IntegerPushes the integer 7 onto the stack.
Usage:
// push 7
let seven = OP_7;
let expected = 7; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(seven, expected);OP_8 = 88
OP_8() -> IntegerPushes the integer 8 onto the stack.
Usage:
// push 8
let eight = OP_8;
let expected = 8; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(eight, expected);OP_9 = 89
OP_9() -> IntegerPushes the integer 9 onto the stack.
Usage:
// push 9
let nine = OP_9;
let expected = 9; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(nine, expected);OP_10 = 90
OP_10() -> IntegerPushes the integer 10 onto the stack.
Usage:
// push 10
let ten = OP_10;
let expected = 10; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(ten, expected);OP_11 = 91
OP_11() -> IntegerPushes the integer 11 onto the stack.
Usage:
// push 11
let eleven = OP_11;
let expected = 11; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(eleven, expected);OP_12 = 92
OP_12() -> IntegerPushes the integer 12 onto the stack.
Usage:
// push 12
let twelve = OP_12;
let expected = 12; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(twelve, expected);OP_13 = 93
OP_13() -> IntegerPushes the integer 13 onto the stack.
Usage:
// push 13
let thirteen = OP_13;
let expected = 13; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(thirteen, expected);OP_14 = 94
OP_14() -> IntegerPushes the integer 14 onto the stack.
Usage:
// push 14
let fourteen = OP_14;
let expected = 14; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(fourteen, expected);OP_15 = 95
OP_15() -> IntegerPushes the integer 15 onto the stack.
Usage:
// push 15
let fiveteen = OP_15;
let expected = 15; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(fiveteen, expected);OP_16 = 96
OP_16() -> IntegerPushes the integer 16 onto the stack.
Usage:
// push 16
let sixteen = OP_16;
let expected = 16; // equivalent (and prefered) way to push numbers
OP_EQUALVERIFY(sixteen, expected);OP_NOP = 97
OP_NOP() -> ()Does nothing.
Usage:
// do nothing
OP_NOP();OP_VER = 98
Reserved opcode. Fails script if in executed branch immediately.
OP_IF = 99
OP_IF(condition: bool) -> ()Creates a branch (OP_IF/OP_ELSE/OP_ENDIF construct) that will only execute
if condition is true and will execute the alternative branch otherwise.
Usage:
let condition = true;
// branch on condition
OP_IF(condition); {
let result = 5;
} OP_ELSE; {
let result = 6;
} OP_ENDIF;
let expected = 5;
OP_EQUALVERIFY(result, expected);OP_NOTIF = 100
Opposite of OP_NOTIF. Currently not supported in #[bitcoin_cash::script] functions.
OP_VERIF = 101
Disabled opcode. Fails script immediately even if not in executed branch.
OP_VERNOTIF = 102
Disabled opcode. Fails script immediately even if not in executed branch.
OP_ELSE = 103
OP_ELSE() -> ()Demarcates a branch (OP_IF/OP_ELSE/OP_ENDIF construct) that will only execute
if condition is true and will execute the alternative branch otherwise.
Usage:
let condition = true;
// branch on condition
OP_IF(condition); {
let result = 5;
} OP_ELSE; {
let result = 6;
} OP_ENDIF;
let expected = 5;
OP_EQUALVERIFY(result, expected);OP_ENDIF = 104
OP_ENDIF() -> ()Ends a branch (OP_IF/OP_ELSE/OP_ENDIF construct) that will only execute
if condition is true and will execute the alternative branch otherwise.
Usage:
let condition = true;
// branch on condition
OP_IF(condition); {
let result = 5;
} OP_ELSE; {
let result = 6;
} OP_ENDIF;
let expected = 5;
OP_EQUALVERIFY(result, expected);OP_VERIFY = 105
OP_VERIFY(condition: bool) -> ()Marks transaction as invalid if condition is not true.
Usage:
let condition = true;
// verify condition
OP_VERIFY(condition);OP_RETURN = 106
Fails execution of the script immediately. Used to attach data to transactions.
OP_TOALTSTACK = 107
OP_TOALTSTACK<T>(item: T) -> ()Moves item to the top of the altstack.
Usage:
let item = b"Bitcoin Cash";
// move item to altstack
OP_TOALTSTACK(item);
let expected = b"Bitcoin Cash";
OP_FROMALTSTACK(item); // Note: retains name "item" on altstack
OP_EQUALVERIFY(expected, item);OP_FROMALTSTACK = 108
OP_FROMALTSTACK<T>(altitem: T) -> TMoves the top item of the altstack to the main stack.
Usage:
let item = b"Bitcoin Cash";
OP_TOALTSTACK(item);
let expected = b"Bitcoin Cash";
// move item back to main stack
OP_FROMALTSTACK(item); // Note: retains name "item" on main stack
OP_EQUALVERIFY(expected, item);OP_2DROP = 109
OP_2DROP<T, U>(a: T, b: U) -> ()Drops the two top stack items.
a b ->Usage:
let a = b"A";
let b = b"B";
let c = b"C";
// drop b and c
OP_2DROP(b, c);
let expected = b"A";
OP_EQUALVERIFY(a, expected);OP_2DUP = 110
OP_2DUP<T, U>(a: T, b: U) -> (T, U, T, U)Duplicates the top two stack items.
a b -> a b a bUsage:
let a = b"A";
let b = b"B";
// duplicate a and b
OP_2DUP(a, b); // Note: duplicated items retain name
let expected = b"A";
OP_EQUALVERIFY(b, expected);
let expected = b"B";
OP_EQUALVERIFY(a, expected);
let expected = b"A";
OP_EQUALVERIFY(b, expected);
let expected = b"B";
OP_EQUALVERIFY(a, expected);OP_3DUP = 111
OP_3DUP<T, U, V>(a: T, b: U, c: V) -> (T, U, V, T, U, V)Duplicates the top two three items.
a b c -> a b c a b cUsage:
let a = b"A";
let b = b"B";
let c = b"C";
// duplicate a, b and c
OP_3DUP(a, b, c); // Note: duplicated items retain name
let expected = b"C";
OP_EQUALVERIFY(c, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"C";
OP_EQUALVERIFY(c, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);OP_2OVER = 112
OP_2OVER<T, U, V, W>(a: T, b: U, c: V, d: W) -> (T, U, V, W, T, U)Copies the pair of items two spaces back in the stack to the front.
a b _ _ -> a b _ _ a bUsage:
let a = b"A";
let b = b"B";
let c = b"C";
let d = b"D";
// duplicate a and b
OP_2OVER(a, b, __, __); // Note: duplicated items retain name
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"D";
OP_EQUALVERIFY(d, expected);
let expected = b"C";
OP_EQUALVERIFY(c, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);OP_2ROT = 113
OP_2ROT<T, U, V, W, X, Y>(a: T, b: U, c: V, d: W, e: X, f: Y) -> (V, W, X, Y, T, U)The fifth and sixth items back are moved to the top of the stack.
a b _ _ _ _ -> _ _ _ _ a bUsage:
let a = b"A";
let b = b"B";
let c = b"C";
let d = b"D";
let e = b"E";
let f = b"F";
// move a and b to the top
OP_2ROT(a, b, __, __, __, __); // Note: moved items retain name
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"F";
OP_EQUALVERIFY(f, expected);
let expected = b"E";
OP_EQUALVERIFY(e, expected);
let expected = b"D";
OP_EQUALVERIFY(d, expected);
let expected = b"C";
OP_EQUALVERIFY(c, expected);OP_2SWAP = 114
OP_2SWAP<T, U, V, W>(a: T, b: U, c: V, d: W) -> (V, W, T, U)Swaps the top two pairs of items.
a b c d -> c d a bUsage:
let a = b"A";
let b = b"B";
let c = b"C";
let d = b"D";
// swap a and b with c and d
OP_2SWAP(a, b, c, d); // Note: moved items retain name
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"D";
OP_EQUALVERIFY(d, expected);
let expected = b"C";
OP_EQUALVERIFY(c, expected);OP_IFDUP = 115
If the top stack value is true, duplicate it. Not to be used in #[bitcoin_cash::script] functions.
OP_DEPTH = 116
OP_DEPTH() -> IntegerReturns the number of stack items.
Usage:
let a = b"A";
let b = b"B";
let c = b"C";
// number of items on the stack
let n = OP_DEPTH();
let expected = 3;
OP_EQUALVERIFY(n, expected);OP_DROP = 117
OP_DROP<T>(a: T) -> ()Drops the top stack item.
a ->Usage:
let a = b"A";
let b = b"B";
// drop b
OP_DROP(b);
let expected = b"A";
OP_EQUALVERIFY(a, expected);OP_DUP = 118
OP_DUP<T>(a: T) -> (T, T)Duplicates the top stack item.
a -> a aUsage:
let a = b"A";
// drop b and c
OP_DUP(a); // Note: duplicated item retains name
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);OP_NIP = 119
OP_NIP<T, U>(a: T, b: U) -> TRemoves the second-to-top stack item.
a b -> bUsage:
let a = b"A";
let b = b"B";
// drop a
OP_NIP(a, __);
let expected = b"B";
OP_EQUALVERIFY(b, expected);OP_OVER = 120
OP_OVER<T, U>(a: T, b: U) -> (T, U, T)Copies the second-to-top stack item to the top of the stack.
a b -> a b aUsage:
let a = b"A";
let b = b"B";
// copy a
OP_OVER(a, __); // Note: duplicated item retains name
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);OP_PICK = 121
OP_PICK<T>(n: Integer) -> TThe item n back in the stack is copied to the top.
xₙ ... x₂ x₁ x₀ <n> -> xₙ ... x₂ x₁ x₀ xₙUsage:
let a = b"A";
let b = b"B";
// calculate depth of a
let depth_a = depth_of(a);
// copy a
OP_PICK(depth_a); // Note: duplicated item retains name
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);OP_ROLL = 122
OP_ROLL<T>(n: Integer) -> TThe item n back in the stack is moved to the top.
xₙ ... x₂ x₁ x₀ <n> -> xₙ₋₁ ... x₂ x₁ x₀ xₙUsage:
let a = b"A";
let b = b"B";
// calculate depth of a
let depth_a = depth_of(a);
// move a to the top of the stack
OP_ROLL(depth_a); // Note: moved item retains name
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);OP_ROT = 123
OP_ROT<T, U, V>(a: T, b: U, c: V) -> (U, V, T)The third-to-top item is moved to the top.
a b c -> b c aUsage:
let a = b"A";
let b = b"B";
let c = b"C";
// move a to the top
OP_ROT(a, __, __);
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"C";
OP_EQUALVERIFY(c, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);OP_SWAP = 124
OP_SWAP<T, U>(a: T, b: U) -> (U, T)The top two items on the stack are swapped.
a b -> b aUsage:
let a = b"A";
let b = b"B";
// swap a and b
OP_SWAP(a, b);
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);OP_TUCK = 125
OP_TUCK<T, U>(a: T, b: U) -> (U, T, U)The item at the top of the stack is copied and inserted before the second-to-top item.
a b -> b a bUsage:
let a = b"A";
let b = b"B";
// insert b before a
OP_TUCK(__, b);
let expected = b"B";
OP_EQUALVERIFY(b, expected);
let expected = b"A";
OP_EQUALVERIFY(a, expected);
let expected = b"B";
OP_EQUALVERIFY(b, expected);OP_CAT = 126
OP_CAT(left: ByteArray, right: ByteArray) -> ByteArrayConcatenates two byte sequences.
Usage:
let a = b"Bitcoin";
let b = b"Cash";
// concatenate a and b
let ab = OP_CAT(a, b);
let expected = b"BitcoinCash";
OP_EQUALVERIFY(ab, expected);OP_SPLIT = 127
OP_SPLIT(array: ByteArray, split_index: Integer) -> (ByteArray, ByteArray)Split array at split_index.
Usage:
let array = b"BitcoinCash";
let split_index = 7;
// split array at index 7
let (a, b) = OP_SPLIT(array, split_index);
let expected = b"Cash";
OP_EQUALVERIFY(b, expected);
let expected = b"Bitcoin";
OP_EQUALVERIFY(a, expected);OP_NUM2BIN = 128
OP_NUM2BIN(num: Integer, n_bytes: Integer) -> ByteArrayConvert numinto a byte sequence of size n_bytes, taking account of
the sign bit. The byte sequence produced uses little-endian encoding.
Usage:
let num = 0x1337;
let n_bytes = 2;
// encode num as 2 bytes
let num2le = OP_NUM2BIN(num, n_bytes);
let expected = b"\x37\x13";
OP_EQUALVERIFY(num2le, expected);OP_BIN2NUM = 129
OP_BIN2NUM(array: ByteArray) -> IntegerConvert array into a numeric value, including minimal encoding.
array must encode the value in little-endian encoding.
Usage:
let num_encoded = b"\x37\x13";
// decode num_encoded
let num = OP_BIN2NUM(num_encoded);
let expected = 0x1337;
OP_EQUALVERIFY(num, expected);OP_SIZE = 130
OP_SIZE(array: ByteArray) -> (ByteArray, Integer)Returns the byte length of array, retaining array.
Usage:
let array = b"BitcoinCash";
// calculate size of array
let (__, size) = OP_SIZE(array);
let expected = 11;
OP_EQUALVERIFY(size, expected);
let expected = b"BitcoinCash";
OP_EQUALVERIFY(array, expected);OP_INVERT = 131
Disabled opcode. Fails script immediately even if not in executed branch.
OP_AND = 132
OP_AND(a: ByteArray, b: ByteArray) -> ByteArrayBoolean AND between each bit of a and b.
The two operands must be the same size.
Usage:
let a = b"\x0103";
let b = b"\x0302";
// calculate a & b
let bits = OP_AND(a, b);
let expected = b"\x0102";
OP_EQUALVERIFY(bits, expected);OP_OR = 133
OP_OR(a: ByteArray, b: ByteArray) -> ByteArrayBoolean OR between each bit of a and b.
The two operands must be the same size.
Usage:
let a = b"\x0103";
let b = b"\x0201";
// calculate a | b
let bits = OP_OR(a, b);
let expected = b"\x0203";
OP_EQUALVERIFY(bits, expected);OP_XOR = 134
OP_XOR(a: ByteArray, b: ByteArray) -> ByteArrayBoolean XOR between each bit of a and b.
The two operands must be the same size.
Usage:
let a = b"\x0103";
let b = b"\x0302";
// calculate a ^ b
let bits = OP_XOR(a, b);
let expected = b"\x0201";
OP_EQUALVERIFY(bits, expected);OP_EQUAL = 135
OP_EQUAL<T>(a: T, b: T) -> boolReturns whether a == b.
Usage:
let a = b"BitcoinCash";
let b = b"BitcoinCash";
// check if a == b
let is_equal = OP_EQUAL(a, b);
OP_VERIFY(is_equal);OP_EQUALVERIFY = 136
OP_EQUALVERIFY<T>(a: T, b: T) -> ()Verifies that a == b.
Usage:
let a = b"BitcoinCash";
let b = b"BitcoinCash";
// verify that a == b
OP_EQUALVERIFY(a, b);OP_RESERVED1 = 137
Reserved opcode. Fails script if in executed branch immediately.
OP_RESERVED2 = 138
Reserved opcode. Fails script if in executed branch immediately.
OP_1ADD = 139
OP_1ADD(a: Integer) -> IntegerCalculates a + 1.
Usage:
let a = 7;
// calculate a + 1
let result = OP_1ADD(a);
let expected = 8;
OP_EQUALVERIFY(result, expected);OP_1SUB = 140
OP_1SUB(a: Integer) -> IntegerCalculates a - 1.
Usage:
let a = 7;
// calculate a - 1
let result = OP_1SUB(a);
let expected = 6;
OP_EQUALVERIFY(result, expected);OP_2MUL = 141
Disabled opcode. Fails script immediately even if not in executed branch.
OP_2DIV = 142
Disabled opcode. Fails script immediately even if not in executed branch.
OP_NEGATE = 143
OP_NEGATE(a: Integer) -> IntegerCalculates -a.
Usage:
let a = 7;
// calculate -a
let result = OP_NEGATE(a);
let expected = -7;
OP_EQUALVERIFY(result, expected);OP_ABS = 144
OP_ABS(a: Integer) -> IntegerCalculates abs(a).
Usage:
let a = -7;
// calculate abs(a)
let result = OP_ABS(a);
let expected = 7;
OP_EQUALVERIFY(result, expected);OP_NOT = 145
OP_NOT(a: Integer) -> IntegerCalculates !a.
Usage:
let a = false;
// calculate !a
let result = OP_NOT(a);
OP_VERIFY(result);OP_0NOTEQUAL = 146
OP_0NOTEQUAL(a: Integer) -> boolCalculates a != 0.
Usage:
let a = 7;
// calculate a != 0
let result = OP_0NOTEQUAL(a);
OP_VERIFY(result);OP_ADD = 147
OP_ADD(a: Integer, b: Integer) -> IntegerCalculates a + b.
Usage:
let a = 7;
let b = 3;
// calculate a + b
let result = OP_ADD(a, b);
let expected = 10;
OP_EQUALVERIFY(result, expected);OP_SUB = 148
OP_SUB(a: Integer, b: Integer) -> IntegerCalculates a - b.
Usage:
let a = 7;
let b = 3;
// calculate a - b
let result = OP_SUB(a, b);
let expected = 4;
OP_EQUALVERIFY(result, expected);OP_MUL = 149
Disabled opcode. Fails script immediately even if not in executed branch.
OP_DIV = 150
OP_DIV(a: Integer, b: Integer) -> IntegerCalculates a / b, truncating the fraction part.
Usage:
let a = 7;
let b = 3;
// calculate a / b
let result = OP_DIV(a, b);
let expected = 2;
OP_EQUALVERIFY(result, expected);OP_MOD = 151
OP_MOD(a: Integer, b: Integer) -> IntegerCalculates a % b (a modulo b).
Usage:
let a = 7;
let b = 3;
// calculate a % b
let result = OP_MOD(a, b);
let expected = 1;
OP_EQUALVERIFY(result, expected);OP_LSHIFT = 152
Disabled opcode. Fails script immediately even if not in executed branch.
OP_RSHIFT = 153
Disabled opcode. Fails script immediately even if not in executed branch.
OP_BOOLAND = 154
OP_BOOLAND(a: bool, b: bool) -> boolCalculates a && b, boolean AND (∧).
Usage:
let a = false;
let b = true;
// calculate a && b
let result = OP_BOOLAND(a, b);
let expected = false;
OP_EQUALVERIFY(result, expected);OP_BOOLOR = 155
OP_BOOLOR(a: bool, b: bool) -> boolCalculates a || b, boolean OR (∨).
Usage:
let a = false;
let b = true;
// calculate a || b
let result = OP_BOOLOR(a, b);
OP_VERIFY(result);OP_NUMEQUAL = 156
OP_NUMEQUAL(a: Integer, b: Integer) -> boolCalculates a == b.
Usage:
let a = 7;
let b = 7;
// check if a == b
let is_equal = OP_NUMEQUAL(a, b);
OP_VERIFY(is_equal);OP_NUMEQUALVERIFY = 157
OP_NUMEQUALVERIFY(a: Integer, b: Integer) -> ()Verifies that a == b.
Usage:
let a = 7;
let b = 7;
// verify that a == b
OP_NUMEQUALVERIFY(a, b);OP_NUMNOTEQUAL = 158
OP_NUMNOTEQUAL(a: Integer, b: Integer) -> boolCalculates a != b.
Usage:
let a = 7;
let b = 9;
// check if a == b
let is_not_equal = OP_NUMNOTEQUAL(a, b);
OP_VERIFY(is_not_equal);OP_LESSTHAN = 159
OP_LESSTHAN(a: Integer, b: Integer) -> boolCalculates a < b.
Usage:
let a = 7;
let b = 9;
// check if a < b
let is_less = OP_LESSTHAN(a, b);
OP_VERIFY(is_less);OP_GREATERTHAN = 160
OP_GREATERTHAN(a: Integer, b: Integer) -> boolCalculates a > b.
Usage:
let a = 11;
let b = 9;
// check if a > b
let is_greater = OP_GREATERTHAN(a, b);
OP_VERIFY(is_greater);OP_LESSTHANOREQUAL = 161
OP_LESSTHANOREQUAL(a: Integer, b: Integer) -> boolCalculates a <= b.
Usage:
let a = 7;
let b = 7;
// check if a <= b
let is_at_most = OP_LESSTHANOREQUAL(a, b);
OP_VERIFY(is_at_most);OP_GREATERTHANOREQUAL = 162
OP_GREATERTHANOREQUAL(a: Integer, b: Integer) -> boolCalculates a >= b.
Usage:
let a = 9;
let b = 9;
// check if a >= b
let is_at_least = OP_GREATERTHANOREQUAL(a, b);
OP_VERIFY(is_at_least);OP_MIN = 163
OP_MIN(a: Integer, b: Integer) -> boolCalculates min(a, b), the lesser of a and b.
Usage:
let a = 3;
let b = 9;
// calculate min(a, b)
let result = OP_MIN(a, b);
let expected = 3;
OP_EQUALVERIFY(result, expected);OP_MAX = 164
OP_MAX(a: Integer, b: Integer) -> boolCalculates max(a, b), the greater of a and b.
Usage:
let a = 3;
let b = 9;
// calculate max(a, b)
let result = OP_MAX(a, b);
let expected = 9;
OP_EQUALVERIFY(result, expected);OP_WITHIN = 165
OP_WITHIN(a: Integer, min: Integer, max: Integer) -> boolCalculates a >= min && a <= max.
Usage:
let a = 3;
let min = 1;
let max = 9;
// calculate if a is within min and max
let result = OP_WITHIN(a, min, max);
OP_VERIFY(result);OP_RIPEMD160 = 166
OP_RIPEMD160(array: ByteArray) -> ByteArrayHashes array using RIPEMD-160.
Usage:
let array = b"BitcoinCash";
// calculate ripemd160(array)
let hash = OP_RIPEMD160(array);
let expected = hex!("0d2aa57463e5fac82f97f496ed98525fbec71c4c");
OP_EQUALVERIFY(hash, expected);OP_SHA1 = 167
OP_SHA1(array: ByteArray) -> ByteArrayHashes array using SHA-1.
Usage:
let array = b"BitcoinCash";
// calculates sha1(array)
let hash = OP_SHA1(array);
let expected = hex!("a7a1986ab925f4d8a81fc0da1352c780ad2f5fe1");
OP_EQUALVERIFY(hash, expected);OP_SHA256 = 168
OP_SHA256(array: ByteArray) -> ByteArrayHashes array using SHA-256.
Usage:
let array = b"BitcoinCash";
// calculates sha256(array)
let hash = OP_SHA256(array);
let expected = hex!("78e015aa460c0a5be71fe4618c72898200a45a20f9bd7048398971babc3b372b");
OP_EQUALVERIFY(hash, expected);OP_HASH160 = 169
OP_HASH160(array: ByteArray) -> ByteArrayHashes array using first SHA-256 and then RIPEMD-160.
Usage:
let array = b"BitcoinCash";
// calculates ripemd160(sha256(array))
let hash = OP_HASH160(array);
let expected = hex!("29e99ecb43b5a4c19aa2b05c7d6fc439bca5f023");
OP_EQUALVERIFY(hash, expected);OP_HASH256 = 170
OP_HASH256(array: ByteArray) -> ByteArrayHashes array twice using SHA-256.
Usage:
let array = b"BitcoinCash";
// calculates sha256(sha256(array))
let hash = OP_HASH256(array);
let expected = hex!("575d8ad02159b76cf2beda18c4ccb9bdb9a7ac894506d97e319c9e5c3096ca37");
OP_EQUALVERIFY(hash, expected);OP_CODESEPARATOR = 171
OP_CODESEPARATOR() -> ()Makes OP_CHECK(MULTI)SIG(VERIFY) set scriptCode to everything after
the most recently-executed OP_CODESEPARATOR when computing the sighash.
Usage:
let array = b"BitcoinCash";
// removes "BitcoinCash" from scriptCode
OP_CODESEPARATOR();OP_CHECKSIG = 172
OP_CHECKSIG(public_key: ByteArray, signature: ByteArray) -> boolThe last byte (=sighash type) of signature is removed.
The sighash for this input is calculated based on the sighash type.
The truncated signature used by OP_CHECKSIG must be a valid ECDSA or
Schnorr signature for that hash and public_key. If it is valid, 1 is
returned, if it is empty, 0 is returned, otherwise the operation fails.
Usage:
#[bitcoin_cash::script(P2PKInputs)]
fn p2pk(_: (), signature: ByteArray) {
let public_key = hex!("0201961ef44067e870a9b1684041929caffad57eae6bbc79dd785320d53231f519");
// check if `signature` signs current sighash for `public_key`
let success = OP_CHECKSIG(signature, public_key);
}OP_CHECKSIGVERIFY = 173
OP_CHECKSIGVERIFY(public_key: ByteArray, signature: ByteArray) -> ()The last byte (=sighash type) of signature is removed.
The sighash for this input is calculated based on the sighash type.
Verifies the truncated signature used by OP_CHECKSIGVERIFY is a
valid ECDSA or Schnorr signature for that hash and public_key.
Usage:
#[bitcoin_cash::script(P2PKInputs)]
fn p2pk(_: (), signature: ByteArray) {
let public_key = hex!("0201961ef44067e870a9b1684041929caffad57eae6bbc79dd785320d53231f519");
// verify `signature` signs current sighash for `public_key`
OP_CHECKSIGVERIFY(signature, public_key);
}OP_CHECKMULTISIG = 174
Performs a multisig check. Not to be used in #[bitcoin_cash::script] functions.
OP_CHECKMULTISIGVERIFY = 175
Verifies a multisig check. Not to be used in #[bitcoin_cash::script] functions.
OP_NOP1 = 176
OP_NOP1() -> ()Does nothing.
Usage:
// do nothing
OP_NOP1();OP_CHECKLOCKTIMEVERIFY = 177
OP_CHECKLOCKTIMEVERIFY(locktime: Integer) -> IntegerMarks transaction as invalid if the top stack item is greater than the transaction’s
nLockTime field, otherwise script evaluation continues as though an OP_NOP was
executed. Transaction is also invalid if
- the stack is empty or
- the top stack item is negative or
- the top stack item is greater than or equal to 500000000 while the transaction’s
nLockTimefield is less than 500000000, or vice versa or - the input’s nSequence field is equal to 0xffffffff.
The precise semantics are described in BIP65.
Usage:
let locktime = 400_000;
// verify locktime
OP_CHECKLOCKTIMEVERIFY(locktime);
let expected = 400_000;
OP_EQUALVERIFY(locktime, expected);OP_CHECKSEQUENCEVERIFY = 178
OP_CHECKSEQUENCEVERIFY(sequence: Integer) -> IntegerMarks transaction as invalid if the relative lock time of the input
(enforced by BIP68 with nSequence) is not equal to or longer than
the value of the top stack item. The precise semantics are described
in BIP112.
Usage:
let sequence = 1000;
// verify input age
OP_CHECKSEQUENCEVERIFY(sequence);
let expected = 1000;
OP_EQUALVERIFY(sequence, expected);OP_NOP4 = 179
OP_NOP4() -> ()Does nothing.
Usage:
// do nothing
OP_NOP4();OP_NOP5 = 180
OP_NOP5() -> ()Does nothing.
Usage:
// do nothing
OP_NOP5();OP_NOP6 = 181
OP_NOP6() -> ()Does nothing.
Usage:
// do nothing
OP_NOP6();OP_NOP7 = 182
OP_NOP7() -> ()Does nothing.
Usage:
// do nothing
OP_NOP7();OP_NOP8 = 183
OP_NOP8() -> ()Does nothing.
Usage:
// do nothing
OP_NOP8();OP_NOP9 = 184
OP_NOP9() -> ()Does nothing.
Usage:
// do nothing
OP_NOP9();OP_NOP10 = 185
OP_NOP10() -> ()Does nothing.
Usage:
// do nothing
OP_NOP10();OP_CHECKDATASIG = 186
OP_CHECKDATASIG(signature: ByteArray, message: ByteArray, public_key: ByteArray) -> boolChecks whether signature is a valid ECDSA or Schnorr signature for sha256(message) and public_key.
Usage:
let signature = [
hex!("3045022100f560a6e928ec52e77801a3ea4cbfbe6d89d1fff77a8d2ed00c457af278ae54").as_ref(),
hex!("01022015cc2b1c92b53cef6afd10e5e5fa33eb66b9d13d82d970a4a951b6e7f1903509").as_ref(),
].concat();
let message = b"BitcoinCash";
let public_key = hex!("0350be375c6e807988a5f575c9776e271e19a79f64681bcfe6a1affde9a5444496");
let is_valid_sig = OP_CHECKDATASIG(signature, message, public_key);OP_CHECKDATASIGVERIFY = 187
OP_CHECKDATASIGVERIFY(signature: ByteArray, message: ByteArray, public_key: ByteArray) -> ()Verifies that signature is a valid ECDSA or Schnorr signature for sha256(message) and public_key.
Usage:
let signature = [
hex!("3045022100f560a6e928ec52e77801a3ea4cbfbe6d89d1fff77a8d2ed00c457af278ae54").as_ref(),
hex!("01022015cc2b1c92b53cef6afd10e5e5fa33eb66b9d13d82d970a4a951b6e7f1903509").as_ref(),
].concat();
let message = b"BitcoinCash";
let public_key = hex!("0350be375c6e807988a5f575c9776e271e19a79f64681bcfe6a1affde9a5444496");
OP_CHECKDATASIGVERIFY(signature, message, public_key);OP_REVERSEBYTES = 188
OP_REVERSEBYTES(array: ByteArray) -> ByteArrayReverse array.
Usage:
let array = b"BitcoinCash";
// reverse array
let reversed = OP_REVERSEBYTES(array);
let expected = b"hsaCnioctiB";
OP_EQUALVERIFY(reversed, expected);FIRST_UNDEFINED_OP_VALUE = 189
The first op_code value after all defined opcodes
Implementations§
Source§impl Opcode
impl Opcode
pub fn is_disabled(self) -> bool
pub fn retains_input(self) -> bool
pub fn behavior(self) -> OpcodeBehavior
Trait Implementations§
Source§impl FromPrimitive for Opcode
impl FromPrimitive for Opcode
Source§fn from_i64(n: i64) -> Option<Opcode>
fn from_i64(n: i64) -> Option<Opcode>
i64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u64(n: u64) -> Option<Opcode>
fn from_u64(n: u64) -> Option<Opcode>
u64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
i128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
u16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u32(n: u32) -> Option<Self>
fn from_u32(n: u32) -> Option<Self>
u32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
u128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read more