Template Class arithmetic_operations#

Class Documentation#

template<class params>
class arithmetic_operations#

The arithmetic operations class. Contains the arithmetic operations 0s: Arithmetic Operations:

  • ADD

  • MUL

  • SUB

  • DIV

  • SDIV

  • MOD

  • SMOD

  • ADDMOD

  • MULMOD

  • EXP

  • SIGNEXTEND

Public Types

typedef arith_env_t<params> arith_t#

The arithmetical environment used by the arbitrary length integer library.

typedef arith_t::bn_t bn_t#

The arbitrary length integer type.

typedef arith_t::bn_wide_t bn_wide_t#

The arbitrary length integer type with double the size of the EVM word type.

typedef stack_t<params> stack_t#

The stackk class.

Public Static Functions

static inline __host__ __device__ __forceinline__ void operation_ADD (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The ADD operation implementation. Takes two values from the stack, adds them and pushes the result back to the stack.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[out] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_MUL (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The MUL operation implementation. Takes two values from the stack, multiplies them and pushes the result back to the stack.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[out] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_SUB (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The SUB operation implementation. Takes two values from the stack, subtracts the second value from the first value and pushes the result back to the stack.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[out] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_DIV (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The DIV operation implementation. Takes two values from the stack, divides the first value by the second value and pushes the result back to the stack. It consider the division by zero as zero. Both values are considered unsigned.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[out] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_SDIV (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The SDIV operation implementation. Takes two values from the stack, divides the first value by the second value and pushes the result back to the stack. It consider the division by zero as zero. The special case -2^254 / -1 = -2^254 is considered. Both values are considered signed.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[out] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_MOD (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The MOD operation implementation. Takes two values from the stack, calculates the remainder of the division of the first value by the second value and pushes the result back to the stack. It consider the remainder of division by zero as zero. Both values are considered unsigned.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[out] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_SMOD (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The SMOD operation implementation. Takes two values from the stack, calculates the remainder of the division of the first value by the second value and pushes the result back to the stack. It consider the remainder of division by zero as zero. Both values are considered signed.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[out] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_ADDMOD (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The ADDMOD operation implementation. Takes three values from the stack, adds the first two values, calculates the remainder of the division of the result by the third value and pushes the remainder back to the stack. It consider the remainder of division by zero or one as zero. All values are considered unsigned.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[inout] The error code.

  • pc[inout] The program counter.

static inline __host__ __device__ __forceinline__ void operation_MULMOD (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The MULMOD operation implementation. Takes three values from the stack, multiplies the first two values, calculates the remainder of the division of the result by the third value and pushes the remainder back to the stack. It consider the remainder of division by zero or one as zero. All values are considered unsigned. The first two values goes though a modulo by the third value before multiplication.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[in] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[inout] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_EXP (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The EXP operation implementation. Takes two values from the stack, calculates the first value to the power of the second value and pushes the result back to the stack. It consider the power of zero as one, even if the base is zero. The dynamic gas cost is calculated based on the minimumu number of bytes to store the exponent value.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[inout] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[inout] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.

static inline __host__ __device__ __forceinline__ void operation_SIGNEXTEND (arith_t &arith, bn_t &gas_limit, bn_t &gas_used, uint32_t &error_code, uint32_t &pc, stack_t &stack)

The SIGNEXTEND operation implementation. Takes two values from the stack. It consider the second value to have the size of the number of bytes given by the first value (b) + 1. The operation sign extends the second value to the full size of the aithmetic environment and pushes the result back to the stack. In case the first value is out of range ((b+1) > BYTES) the operation pushes the second value back to the stack. If the second value has more bytes than the value (b+1), the operation consider only the least significant (b+1) bytes of the second value.

Parameters
  • arith[in] The arithmetical environment.

  • gas_limit[inout] The gas limit.

  • gas_used[inout] The gas used.

  • error_code[inout] The error code.

  • pc[inout] The program counter.

  • stack[inout] The stack.