EEVM.Interpreter.Instructions.Arithmetic (eevm v0.1.0)

Copy Markdown View Source

EVM arithmetic opcodes: ADD, MUL, SUB, DIV, SDIV, MOD, SMOD, ADDMOD, MULMOD, EXP, SIGNEXTEND.

Summary

Functions

Executes EXP (0x0A), which charges Gas.Dynamic.exp_dynamic_cost/2 for its exponent on top of the static cost (EIP-160).

Applies an arithmetic opcode to the stack (a list, top first) and returns the new stack.

Functions

execute(arg1, state)

Executes EXP (0x0A), which charges Gas.Dynamic.exp_dynamic_cost/2 for its exponent on top of the static cost (EIP-160).

Returns {:ok, new_state} on success, {:error, reason, state} on failure.

stack_op(int, list)

@spec stack_op(non_neg_integer(), [non_neg_integer()]) :: [non_neg_integer()]

Applies an arithmetic opcode to the stack (a list, top first) and returns the new stack.

ByteMnemonicOperation
0x01ADD(a + b) mod 2^256
0x02MUL(a * b) mod 2^256
0x03SUB(a - b) mod 2^256
0x04DIVa / b (0 if b == 0)
0x05SDIVsigned division (0 if b == 0)
0x06MODa mod b (0 if b == 0)
0x07SMODsigned modulo (0 if b == 0)
0x08ADDMOD(a + b) mod n (0 if n == 0)
0x09MULMOD(a * b) mod n (0 if n == 0)
0x0BSIGNEXTENDsign-extend x from byte width b

The interpreter has already checked that the stack holds the opcode's inputs. EXP is not here: its gas depends on the exponent, so it goes through execute/2.

iex> EEVM.Interpreter.Instructions.Arithmetic.stack_op(0x03, [1, 3, 7])
[115792089237316195423570985008687907853269984665640564039457584007913129639934, 7]