Enum Operation

Source
#[repr(u8)]
pub enum Operation {
Show 93 variants Noop = 0, Assert(Felt), FmpAdd = 6, FmpUpdate = 47, SDepth = 62, Caller = 9, Clk = 63, Emit(u32), Join = 87, Split = 84, Loop = 85, Call = 108, Dyn = 88, Dyncall = 92, SysCall = 104, Span = 86, End = 112, Repeat = 116, Respan = 120, Halt = 124, Add = 34, Neg = 2, Mul = 35, Inv = 3, Incr = 4, And = 36, Or = 37, Not = 5, Eq = 33, Eqz = 1, Expacc = 15, Ext2Mul = 25, U32split = 72, U32add = 64, U32assert2(Felt), U32add3 = 76, U32sub = 66, U32mul = 68, U32madd = 78, U32div = 70, U32and = 38, U32xor = 39, Pad = 48, Drop = 41, Dup0 = 49, Dup1 = 50, Dup2 = 51, Dup3 = 52, Dup4 = 53, Dup5 = 54, Dup6 = 55, Dup7 = 56, Dup9 = 57, Dup11 = 58, Dup13 = 59, Dup15 = 60, Swap = 8, SwapW = 24, SwapW2 = 28, SwapW3 = 29, SwapDW = 30, MovUp2 = 10, MovUp3 = 12, MovUp4 = 16, MovUp5 = 18, MovUp6 = 20, MovUp7 = 22, MovUp8 = 26, MovDn2 = 11, MovDn3 = 13, MovDn4 = 17, MovDn5 = 19, MovDn6 = 21, MovDn7 = 23, MovDn8 = 27, CSwap = 42, CSwapW = 43, Push(Felt), AdvPop = 61, AdvPopW = 14, MLoadW = 44, MStoreW = 46, MLoad = 7, MStore = 45, MStream = 83, Pipe = 82, HPerm = 80, MpVerify(Felt), MrUpdate = 96, FriE2F4 = 40, HornerBase = 100, HornerExt = 89, ArithmeticCircuitEval = 93,
}
Expand description

A set of native VM operations which take exactly one cycle to execute.

Variants§

§

Noop = 0

Advances cycle counter, but does not change the state of user stack.

§

Assert(Felt)

Pops the stack; if the popped value is not 1, execution fails.

The internal value specifies an error code associated with the error in case when the execution fails.

§

FmpAdd = 6

Pops an element off the stack, adds the current value of the fmp register to it, and pushes the result back onto the stack.

§

FmpUpdate = 47

Pops an element off the stack and adds it to the current value of fmp register.

§

SDepth = 62

Pushes the current depth of the stack onto the stack.

§

Caller = 9

Overwrites the top four stack items with the hash of a function which initiated the current SYSCALL. Thus, this operation can be executed only inside a SYSCALL code block.

§

Clk = 63

Pushes the current value of the clock cycle onto the stack. This operation can be used to measure the number of cycles it has taken to execute the program up to the current instruction.

§

Emit(u32)

Emits an event id (u32 value) to the host.

We interpret the event id as follows:

  • 16 most significant bits identify the event source,
  • 16 least significant bits identify the actual event.

Similar to Noop, this operation does not change the state of user stack. The immediate value affects the program MAST root computation.

§

Join = 87

Marks the beginning of a join block.

§

Split = 84

Marks the beginning of a split block.

§

Loop = 85

Marks the beginning of a loop block.

§

Call = 108

Marks the beginning of a function call.

§

Dyn = 88

Marks the beginning of a dynamic code block, where the target is specified by the stack.

§

Dyncall = 92

Marks the beginning of a dynamic function call, where the target is specified by the stack.

§

SysCall = 104

Marks the beginning of a kernel call.

§

Span = 86

Marks the beginning of a span code block.

§

End = 112

Marks the end of a program block.

§

Repeat = 116

Indicates that body of an executing loop should be executed again.

§

Respan = 120

Starts processing a new operation batch.

§

Halt = 124

Indicates the end of the program. This is used primarily to pad the execution trace to the required length. Once HALT operation is executed, no other operations can be executed by the VM (HALT operation itself excepted).

§

Add = 34

Pops two elements off the stack, adds them, and pushes the result back onto the stack.

§

Neg = 2

Pops an element off the stack, negates it, and pushes the result back onto the stack.

§

Mul = 35

Pops two elements off the stack, multiplies them, and pushes the result back onto the stack.

§

Inv = 3

Pops an element off the stack, computes its multiplicative inverse, and pushes the result back onto the stack.

§

Incr = 4

Pops an element off the stack, adds 1 to it, and pushes the result back onto the stack.

§

And = 36

Pops two elements off the stack, multiplies them, and pushes the result back onto the stack.

If either of the elements is greater than 1, execution fails. This operation is equivalent to boolean AND.

§

Or = 37

Pops two elements off the stack and subtracts their product from their sum.

If either of the elements is greater than 1, execution fails. This operation is equivalent to boolean OR.

§

Not = 5

Pops an element off the stack and subtracts it from 1.

If the element is greater than one, the execution fails. This operation is equivalent to boolean NOT.

§

Eq = 33

Pops two elements off the stack and compares them. If the elements are equal, pushes 1 onto the stack, otherwise pushes 0 onto the stack.

§

Eqz = 1

Pops an element off the stack and compares it to 0. If the element is 0, pushes 1 onto the stack, otherwise pushes 0 onto the stack.

§

Expacc = 15

Computes a single turn of exponent accumulation for the given inputs. This operation can be be used to compute a single turn of power of a field element.

The top 4 elements of the stack are expected to be arranged as follows (form the top):

  • least significant bit of the exponent in the previous trace if there’s an expacc call, otherwise ZERO
  • exponent of base number a for this turn
  • accumulated power of base number a so far
  • number which needs to be shifted to the right

At the end of the operation, exponent is replaced with its square, current value of power of base number a on exponent is incorporated into the accumulator and the number is shifted to the right by one bit.

§

Ext2Mul = 25

Computes the product of two elements in the extension field of degree 2 and pushes the result back onto the stack as the third and fourth elements. Pushes 0 onto the stack as the first and second elements.

§

U32split = 72

Pops an element off the stack, splits it into upper and lower 32-bit values, and pushes these values back onto the stack.

§

U32add = 64

Pops two elements off the stack, adds them, and splits the result into upper and lower 32-bit values. Then pushes these values back onto the stack.

If either of these elements is greater than or equal to 2^32, the result of this operation is undefined.

§

U32assert2(Felt)

Pops two elements off the stack and checks if each of them represents a 32-bit value. If both of them are, they are pushed back onto the stack, otherwise an error is returned.

The internal value specifies an error code associated with the error in case when the assertion fails.

§

U32add3 = 76

Pops three elements off the stack, adds them together, and splits the result into upper and lower 32-bit values. Then pushes the result back onto the stack.

§

U32sub = 66

Pops two elements off the stack and subtracts the first element from the second. Then, the result, together with a flag indicating whether subtraction underflowed is pushed onto the stack.

If their of the values is greater than or equal to 2^32, the result of this operation is undefined.

§

U32mul = 68

Pops two elements off the stack, multiplies them, and splits the result into upper and lower 32-bit values. Then pushes these values back onto the stack.

If their of the values is greater than or equal to 2^32, the result of this operation is undefined.

§

U32madd = 78

Pops two elements off the stack and multiplies them. Then pops the third element off the stack, and adds it to the result. Finally, splits the result into upper and lower 32-bit values, and pushes them onto the stack.

If any of the three values is greater than or equal to 2^32, the result of this operation is undefined.

§

U32div = 70

Pops two elements off the stack and divides the second element by the first. Then pushes the integer result of the division, together with the remainder, onto the stack.

If their of the values is greater than or equal to 2^32, the result of this operation is undefined.

§

U32and = 38

Pops two elements off the stack, computes their binary AND, and pushes the result back onto the stack.

If either of the elements is greater than or equal to 2^32, execution fails.

§

U32xor = 39

Pops two elements off the stack, computes their binary XOR, and pushes the result back onto the stack.

If either of the elements is greater than or equal to 2^32, execution fails.

§

Pad = 48

Pushes 0 onto the stack.

§

Drop = 41

Removes to element from the stack.

§

Dup0 = 49

Pushes a copy of stack element 0 onto the stack.

§

Dup1 = 50

Pushes a copy of stack element 1 onto the stack.

§

Dup2 = 51

Pushes a copy of stack element 2 onto the stack.

§

Dup3 = 52

Pushes a copy of stack element 3 onto the stack.

§

Dup4 = 53

Pushes a copy of stack element 4 onto the stack.

§

Dup5 = 54

Pushes a copy of stack element 5 onto the stack.

§

Dup6 = 55

Pushes a copy of stack element 6 onto the stack.

§

Dup7 = 56

Pushes a copy of stack element 7 onto the stack.

§

Dup9 = 57

Pushes a copy of stack element 9 onto the stack.

§

Dup11 = 58

Pushes a copy of stack element 11 onto the stack.

§

Dup13 = 59

Pushes a copy of stack element 13 onto the stack.

§

Dup15 = 60

Pushes a copy of stack element 15 onto the stack.

§

Swap = 8

Swaps stack elements 0 and 1.

§

SwapW = 24

Swaps stack elements 0, 1, 2, and 3 with elements 4, 5, 6, and 7.

§

SwapW2 = 28

Swaps stack elements 0, 1, 2, and 3 with elements 8, 9, 10, and 11.

§

SwapW3 = 29

Swaps stack elements 0, 1, 2, and 3, with elements 12, 13, 14, and 15.

§

SwapDW = 30

Swaps the top two words pair wise.

Input: [D, C, B, A, …] Output: [B, A, D, C, …]

§

MovUp2 = 10

Moves stack element 2 to the top of the stack.

§

MovUp3 = 12

Moves stack element 3 to the top of the stack.

§

MovUp4 = 16

Moves stack element 4 to the top of the stack.

§

MovUp5 = 18

Moves stack element 5 to the top of the stack.

§

MovUp6 = 20

Moves stack element 6 to the top of the stack.

§

MovUp7 = 22

Moves stack element 7 to the top of the stack.

§

MovUp8 = 26

Moves stack element 8 to the top of the stack.

§

MovDn2 = 11

Moves the top stack element to position 2 on the stack.

§

MovDn3 = 13

Moves the top stack element to position 3 on the stack.

§

MovDn4 = 17

Moves the top stack element to position 4 on the stack.

§

MovDn5 = 19

Moves the top stack element to position 5 on the stack.

§

MovDn6 = 21

Moves the top stack element to position 6 on the stack.

§

MovDn7 = 23

Moves the top stack element to position 7 on the stack.

§

MovDn8 = 27

Moves the top stack element to position 8 on the stack.

§

CSwap = 42

Pops an element off the stack, and if the element is 1, swaps the top two remaining elements on the stack. If the popped element is 0, the stack remains unchanged.

If the popped element is neither 0 nor 1, execution fails.

§

CSwapW = 43

Pops an element off the stack, and if the element is 1, swaps the remaining elements 0, 1, 2, and 3 with elements 4, 5, 6, and 7. If the popped element is 0, the stack remains unchanged.

If the popped element is neither 0 nor 1, execution fails.

§

Push(Felt)

Pushes the immediate value onto the stack.

§

AdvPop = 61

Removes the next element from the advice stack and pushes it onto the operand stack.

§

AdvPopW = 14

Removes a word (4 elements) from the advice stack and overwrites the top four operand stack elements with it.

§

MLoadW = 44

Pops an element off the stack, interprets it as a memory address, and replaces the remaining 4 elements at the top of the stack with values located at the specified address.

§

MStoreW = 46

Pops an element off the stack, interprets it as a memory address, and writes the remaining 4 elements at the top of the stack into memory at the specified address.

§

MLoad = 7

Pops an element off the stack, interprets it as a memory address, and pushes the first element of the word located at the specified address to the stack.

§

MStore = 45

Pops an element off the stack, interprets it as a memory address, and writes the remaining element at the top of the stack into the first element of the word located at the specified memory address. The remaining 3 elements of the word are not affected.

§

MStream = 83

Loads two words from memory, and replaces the top 8 elements of the stack with them, element-wise, in stack order.

The operation works as follows:

  • The memory address of the first word is retrieved from 13th stack element (position 12).
  • Two consecutive words, starting at this address, are loaded from memory.
  • The top 8 elements of the stack are overwritten with these words (element-wise, in stack order).
  • Memory address (in position 12) is incremented by 2.
  • All other stack elements remain the same.
§

Pipe = 82

Pops two words from the advice stack, writes them to memory, and replaces the top 8 elements of the stack with them, element-wise, in stack order.

The operation works as follows:

  • Two words are popped from the advice stack.
  • The destination memory address for the first word is retrieved from the 13th stack element (position 12).
  • The two words are written to memory consecutively, starting at this address.
  • The top 8 elements of the stack are overwritten with these words (element-wise, in stack order).
  • Memory address (in position 12) is incremented by 2.
  • All other stack elements remain the same.
§

HPerm = 80

Performs a Rescue Prime Optimized permutation on the top 3 words of the operand stack, where the top 2 words are the rate (words C and B), the deepest word is the capacity (word A), and the digest output is the middle word E.

Stack transition: [C, B, A, …] -> [F, E, D, …]

§

MpVerify(Felt)

Verifies that a Merkle path from the specified node resolves to the specified root. This operation can be used to prove that the prover knows a path in the specified Merkle tree which starts with the specified node.

The stack is expected to be arranged as follows (from the top):

  • value of the node, 4 elements.
  • depth of the path, 1 element.
  • index of the node, 1 element.
  • root of the tree, 4 elements.

The Merkle path itself is expected to be provided by the prover non-deterministically (via merkle sets). If the prover is not able to provide the required path, the operation fails. The state of the stack does not change.

The internal value specifies an error code associated with the error in case when the assertion fails.

§

MrUpdate = 96

Computes a new root of a Merkle tree where a node at the specified position is updated to the specified value.

The stack is expected to be arranged as follows (from the top):

  • old value of the node, 4 element
  • depth of the node, 1 element
  • index of the node, 1 element
  • current root of the tree, 4 elements
  • new value of the node, 4 element

The Merkle path for the node is expected to be provided by the prover non-deterministically via the advice provider. At the end of the operation, the old node value is replaced with the new root value, that is computed based on the provided path. Everything else on the stack remains the same.

The tree will always be copied into a new instance, meaning the advice provider will keep track of both the old and new Merkle trees.

§

FriE2F4 = 40

Performs FRI (Fast Reed-Solomon Interactive Oracle Proofs) layer folding by a factor of 4 for FRI protocol executed in a degree 2 extension of the base field.

This operation:

  • Folds 4 query values (v0, v1), (v2, v3), (v4, v5), (v6, v7) into a single value (ne0, ne1)
  • Computes new value of the domain generator power: poe’ = poe^4
  • Increments layer pointer (cptr) by 2
  • Checks that the previous folding was done correctly
  • Shifts the stack to move an item from the overflow table to stack position 15

Stack transition: Input: [v7, v6, v5, v4, v3, v2, v1, v0, f_pos, d_seg, poe, pe1, pe0, a1, a0, cptr, …] Output: [t1, t0, s1, s0, df3, df2, df1, df0, poe^2, f_tau, cptr+2, poe^4, f_pos, ne1, ne0, eptr, …] where eptr is moved from the stack overflow table and is the address of the final FRI layer.

§

HornerBase = 100

Performs 8 steps of the Horner evaluation method on a polynomial with coefficients over the base field, i.e., it computes

acc’ = (((acc_tmp * alpha + c3) * alpha + c2) * alpha + c1) * alpha + c0

where

acc_tmp := (((acc * alpha + c7) * alpha + c6) * alpha + c5) * alpha + c4

In other words, the intsruction computes the evaluation at alpha of the polynomial

P(X) := c7 * X^7 + c6 * X^6 + … + c1 * X + c0

§

HornerExt = 89

Performs 4 steps of the Horner evaluation method on a polynomial with coefficients over the extension field, i.e., it computes

acc’ = (((acc * alpha + c3) * alpha + c2) * alpha + c1) * alpha + c0

In other words, the intsruction computes the evaluation at alpha of the polynomial

P(X) := c3 * X^3 + c2 * X^2 + c1 * X + c0

§

ArithmeticCircuitEval = 93

Evaluates an arithmetic circuit given a pointer to its description in memory, the number of arithmetic gates, and the sum of the input and constant gates.

Implementations§

Source§

impl Operation

Source

pub const OP_BITS: usize = 7usize

Source

pub fn op_code(&self) -> u8

Returns the opcode of this operation.

Source

pub fn imm_value(&self) -> Option<Felt>

Returns an immediate value carried by this operation.

Source

pub fn populates_decoder_hasher_registers(&self) -> bool

Returns true if this operation writes any data to the decoder hasher registers.

In other words, if so, then the user op helper registers are not available.

Trait Implementations§

Source§

impl Clone for Operation

Source§

fn clone(&self) -> Operation

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 Operation

Source§

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

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

impl Deserializable for Operation

Source§

fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
Source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
Source§

impl Display for Operation

Source§

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

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

impl PartialEq for Operation

Source§

fn eq(&self, other: &Operation) -> 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 PrettyPrint for Operation

Source§

fn render(&self) -> Document

The core of the PrettyPrint functionality. Read more
Source§

fn to_pretty_string(&self) -> String

Produce a String containing the results of pretty-printing this object. Read more
Source§

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

Pretty-print this object to the given core::fmt::Formatter. Read more
Source§

impl Serializable for Operation

Source§

fn write_into<W: ByteWriter>(&self, target: &mut W)

Serializes self into bytes and writes these bytes into the target.
Source§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
Source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
Source§

impl Copy for Operation

Source§

impl Eq for Operation

Source§

impl StructuralPartialEq for Operation

Auto Trait Implementations§

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> 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V