Skip to main content

Opcode

Enum Opcode 

Source
pub enum Opcode {
Show 36 variants CheckHeightVerify(u64), CheckHeight(u64), CompareHeightVerify, CompareHeight, Nop, PushZero, PushOne, PushHash(Box<HashValue>), PushInt(i64), PushPubKey(Box<CompressedKey<RistrettoPublicKey>>), Drop, Dup, RevRot, GeZero, GtZero, LeZero, LtZero, Add, Sub, Equal, EqualVerify, Or(u8), OrVerify(u8), HashBlake256, HashSha256, HashSha3, CheckSig(Box<Message>), CheckSigVerify(Box<Message>), CheckMultiSig(u8, u8, Vec<CompressedKey<RistrettoPublicKey>>, Box<Message>), CheckMultiSigVerify(u8, u8, Vec<CompressedKey<RistrettoPublicKey>>, Box<Message>), CheckMultiSigVerifyAggregatePubKey(u8, u8, Vec<CompressedKey<RistrettoPublicKey>>, Box<Message>), ToRistrettoPoint, Return, IfThen, Else, EndIf,
}

Variants§

§

CheckHeightVerify(u64)

Compare the current block height to height. Fails with IncompatibleTypes if u64 is not a valid 64-bit unsigned integer. Fails with VerifyFailed if the block height < height.

§

CheckHeight(u64)

Pushes the value of (the current tip height - height) to the stack. In other words, the top of the stack will hold the height difference between height and the current height. If the chain has progressed beyond height, the value is positive; and negative if the chain has yet to reach height. Fails with IncompatibleTypes if u64 is not a valid 64-bit unsigned integer. Fails with StackOverflow if the stack would exceed the max stack height.

§

CompareHeightVerify

Pops the top of the stack as height and compares it to the current block height. Fails with InvalidInput if there is not a valid integer value on top of the stack. Fails with StackUnderflow if the stack is empty. Fails with VerifyFailed if the block height < height.

§

CompareHeight

Pops the top of the stack as height, then pushes the value of (the current height - height) to the stack. In other words, this opcode replaces the top of the stack with the difference between height and the current height. Fails with InvalidInput if there is not a valid integer value on top of the stack. Fails with StackUnderflow if the stack is empty.

§

Nop

No op. Does nothing. Never fails.

§

PushZero

Pushes a zero onto the stack. This is a very common opcode and has the same effect as PushInt(0) but is more compact. Fails with StackOverflow if the stack would exceed the max stack height.

§

PushOne

Pushes a one onto the stack. This is a very common opcode and has the same effect as PushInt(1) but is more compact. Fails with StackOverflow if the stack would exceed the max stack height.

§

PushHash(Box<HashValue>)

Pushes the associated 32-byte value onto the stack. Fails with IncompatibleTypes if HashValue is not a valid 32 byte sequence. Fails with StackOverflow if the stack would exceed the max stack height.

§

PushInt(i64)

Pushes the associated 64-bit signed integer onto the stack Fails with IncompatibleTypes if i64 is not a valid 64-bit integer. Fails with StackOverflow if the stack would exceed the max stack height.

§

PushPubKey(Box<CompressedKey<RistrettoPublicKey>>)

Pushes the associated 32-byte value onto the stack. It will be interpreted as a public key or a commitment. Fails with IncompatibleTypes if RistrettoPublicKey is not a valid 32 byte sequence. Fails with StackOverflow if the stack would exceed the max stack height.

§

Drop

Drops the top stack item. Fails with StackUnderflow if the stack is empty.

§

Dup

Duplicates the top stack item. Fails with StackUnderflow if the stack is empty. Fails with StackOverflow if the stack would exceed the max stack height.

§

RevRot

Reverse rotation. The top stack item moves into 3rd place, e.g. abc => bca. Fails with StackUnderflow if the stack has fewer than three items.

§

GeZero

Pops the top stack element as val. If val is greater than or equal to zero, push a 1 to the stack, otherwise push 0. Fails with StackUnderflow if the stack is empty. Fails with InvalidInput if val is not an integer.

§

GtZero

Pops the top stack element as val. If val is strictly greater than zero, push a 1 to the stack, otherwise push 0. Fails with StackUnderflow if the stack is empty. Fails with InvalidInput if the item is not an integer.

§

LeZero

Pops the top stack element as val. If val is less than or equal to zero, push a 1 to the stack, otherwise push 0. Fails with StackUnderflow if the stack is empty. Fails with InvalidInput if the item is not an integer.

§

LtZero

Pops the top stack element as val. If val is strictly less than zero, push a 1 to the stack, otherwise push 0. Fails with StackUnderflow if the stack is empty. Fails with InvalidInput if the items is not an integer.

§

Add

Pops two items from the stack and pushes their sum to the stack. Fails with StackUnderflow if the stack has fewer than two items. Fails with InvalidInput if the items cannot be added to each other (e.g. an integer and public key).

§

Sub

Pops two items from the stack and pushes the second minus the top to the stack. Fails with StackUnderflow if the stack has fewer than two items. Fails with InvalidInput if the items cannot be subtracted from each other (e.g. an integer and public key).

§

Equal

Pops the top two items from the stack, and pushes 1 to the stack if the inputs are exactly equal, 0 otherwise. A 0 is also pushed if the values cannot be compared (e.g. integer and pubkey). Fails with StackUnderflow if the stack has fewer than two items.

§

EqualVerify

Pops the top two items from the stack, and compares their values. Fails with StackUnderflow if the stack has fewer than two items. Fails with VerifyFailed if the top two stack elements are not equal.

§

Or(u8)

Pops n + 1 items from the stack (with u8 as n). If the last item matches at least one of the first n items, push 1 onto the stack, otherwise push 0 onto the stack. Fails with StackUnderflow if the stack has fewer than n + 1 items. Fails with InvalidInput if u8 is not a valid 8-bit unsigned integer.

§

OrVerify(u8)

Pops n + 1 items from the stack (with u8 as n). If the last item matches at least one of the first n items, continue. Fails with StackUnderflow if the stack has fewer than n + 1 items. Fails with VerifyFailed the last item does not match at least one of the first n items. Fails with InvalidInput if u8 is not a valid 8-bit unsigned integer.

§

HashBlake256

Pops the top element, hash it with the Blake2b hash function and push the result to the stack. Fails with StackUnderflow if the stack is empty. Fails with InvalidInput if the input is not a valid 32 byte hash value.

§

HashSha256

Pops the top element, hash it with the SHA256 hash function and push the result to the stack. Fails with StackUnderflow if the stack is empty. Fails with InvalidInput if the input is not a valid 32 byte hash value.

§

HashSha3

Pops the top element, hash it with the SHA-3 hash function and push the result to the stack. Fails with StackUnderflow if the stack is empty. Fails with InvalidInput if the input is not a valid 32 byte hash value.

§

CheckSig(Box<Message>)

Pops the public key and then the signature from the stack. If signature validation using the 32-byte message and public key succeeds , push 1 to the stack, otherwise push 0. Fails with IncompatibleTypes if Message is not a valid 32-byte sequence. Fails with StackUnderflow if the stack has fewer than 2 items. Fails with InvalidInput if the top stack element is not a PublicKey. Fails with InvalidInput if the second stack element is not a Signature.

§

CheckSigVerify(Box<Message>)

Identical to CheckSig, except that nothing is pushed to the stack if the signature is valid, and the operation fails with VerifyFailed if the signature is invalid.

§

CheckMultiSig(u8, u8, Vec<CompressedKey<RistrettoPublicKey>>, Box<Message>)

Pops exactly m signatures from the stack. The multiple signature validation will not succeed if the m signatures are not unique or if Vec contains a duplicate public key. Each signature is validated using the 32-byte message and a public key that match. If signature validation for m unique signatures succeeds, push 1 to the stack, otherwise push 0. Fails with IncompatibleTypes if either m (the 1st u8) or n (the 2nd u8) is not a valid 8-bit unsigned integer, if Vec contains an invalid public key or if Message is not a valid 32-byte sequence. Fails with ValueExceedsBounds if m == 0 or if n == 0 or if m > n or if n > MAX_MULTISIG_LIMIT (32) or if the number of public keys provided != n. Fails with StackUnderflow if the stack has fewer than m items. Fails with IncompatibleTypes if any of the m signatures from the stack is not a valid signature. Fails with InvalidInput if each of the top m elements is not a Signature.

§

CheckMultiSigVerify(u8, u8, Vec<CompressedKey<RistrettoPublicKey>>, Box<Message>)

Identical to CheckMultiSig, except that nothing is pushed to the stack if the multiple signature validation is either valid or invalid. Fails with VerifyFailed if any signature is invalid.

§

CheckMultiSigVerifyAggregatePubKey(u8, u8, Vec<CompressedKey<RistrettoPublicKey>>, Box<Message>)

Identical to CheckMultiSig, except that the aggregate of the public keys is pushed to the stack if multiple signature validation succeeds. Fails with VerifyFailed if any signature is invalid.

§

ToRistrettoPoint

Pops the top element from the stack (either a scalar or a hash), parses it canonically as a Ristretto secret key if possible, computes the corresponding Ristretto public key, and pushes this value to the stack. Fails with StackUnderflow if the stack is empty. Fails with IncompatibleTypes if the stack item is not either a scalar or a hash. Fails with InvalidInput if the stack item cannot be canonically parsed as a Ristretto secret key.

§

Return

Always fails with Return.

§

IfThen

Pops the top element of the stack into pred. If pred is 1, the instructions between IfThen and Else are executed. If pred is 0, instructions are popped until Else or EndIf is encountered. If Else is encountered, instructions are executed until EndIf is reached. EndIf is a marker opcode and a no-op. Fails with StackUnderflow if the stack is empty. Fails with InvalidInput if pred is anything other than 0 or 1. Fails with the corresponding failure code if any instruction during execution of the clause causes a failure.

§

Else

Marks the beginning of the Else branch.

§

EndIf

Marks the end of the IfThen statement.

Implementations§

Source§

impl Opcode

Source

pub fn get_version(&self) -> OpcodeVersion

Source

pub fn parse(bytes: &[u8]) -> Result<Vec<Opcode>, ScriptError>

Source

pub fn to_bytes<'a>(&self, array: &'a mut Vec<u8>) -> &'a [u8]

Convert an opcode into its binary representation and append it to the array. The function returns the byte slice that matches the opcode as a convenience

Trait Implementations§

Source§

impl Clone for Opcode

Source§

fn clone(&self) -> Opcode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Opcode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Opcode

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Opcode

Source§

fn eq(&self, other: &Opcode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Opcode

Source§

impl StructuralPartialEq for Opcode

Auto Trait Implementations§

§

impl Freeze for Opcode

§

impl RefUnwindSafe for Opcode

§

impl Send for Opcode

§

impl Sync for Opcode

§

impl Unpin for Opcode

§

impl UnwindSafe for Opcode

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.