以太坊系列之十三: evm指令集

简介: evm指令集手册Opcodes结果列为"-"表示没有运算结果(不会在栈上产生值),为"*"是特殊情况,其他都表示运算产生唯一值,并放在栈顶.mem[a...b] 表示内存中a到b(不包含b)个字节storage[p] 表示从p开始的32个字节谨记evm虚拟机的word(字)是256位32字...

evm指令集手册

Opcodes

结果列为"-"表示没有运算结果(不会在栈上产生值),为"*"是特殊情况,其他都表示运算产生唯一值,并放在栈顶.

mem[a...b] 表示内存中a到b(不包含b)个字节
storage[p] 表示从p开始的32个字节
谨记evm虚拟机的word(字)是256位32字节

操作码 结果 注释
stop - stop execution, identical to return(0,0)
add(x, y) x + y
sub(x, y) x - y
mul(x, y) x * y
div(x, y) x / y
sdiv(x, y) x / y, for signed numbers in two’s complement
mod(x, y) x % y
smod(x, y) x % y, for signed numbers in two’s complement
exp(x, y) x to the power of y
not(x) ~x, every bit of x is negated
lt(x, y) 1 if x < y, 0 otherwise
gt(x, y) 1 if x > y, 0 otherwise
slt(x, y) 1 if x < y, 0 otherwise, for signed numbers in two’s complement
sgt(x, y) 1 if x > y, 0 otherwise, for signed numbers in two’s complement
eq(x, y) 1 if x == y, 0 otherwise
iszero(x) 1 if x == 0, 0 otherwise
and(x, y) bitwise and of x and y
or(x, y) bitwise or of x and y
xor(x, y) bitwise xor of x and y
byte(n, x) nth byte of x, where the most significant byte is the 0th byte
addmod(x, y, m) (x + y) % m with arbitrary precision arithmetics
mulmod(x, y, m) (x * y) % m with arbitrary precision arithmetics
signextend(i, x) sign extend from (i*8+7)th bit counting from least significant
keccak256(p, n) keccak(mem[p...(p+n)))
sha3(p, n) keccak(mem[p...(p+n)))
jump(label) - jump to label / code position
jumpi(label, cond) - jump to label if cond is nonzero
pc current position in code
pop(x) - remove the element pushed by x
dup1 ... dup16 copy ith stack slot to the top (counting from top)
swap1 ... swap16 * swap topmost and ith stack slot below it
mload(p) mem[p..(p+32))
mstore(p, v) - mem[p..(p+32)) := v
mstore8(p, v) - mem[p] := v & 0xff - only modifies a single byte
sload(p) storage[p]
sstore(p, v) - storage[p] := v
msize size of memory, i.e. largest accessed memory index
gas gas still available to execution
address address of the current contract / execution context
balance(a) wei balance at address a
caller call sender (excluding delegatecall)
callvalue wei sent together with the current call
calldataload(p) call data starting from position p (32 bytes)
calldatasize size of call data in bytes
calldatacopy(t, f, s) - copy s bytes from calldata at position f to mem at position t
codesize size of the code of the current contract / execution context
codecopy(t, f, s) - copy s bytes from code at position f to mem at position t
extcodesize(a) size of the code at address a
extcodecopy(a, t, f, s) - like codecopy(t, f, s) but take code at address a
returndatasize size of the last returndata
returndatacopy(t, f, s) - copy s bytes from returndata at position f to mem at position t
create(v, p, s) create new contract with code mem[p..(p+s)) and send v wei and return the new address
create2(v, n, p, s) create new contract with code mem[p..(p+s)) at address keccak256( . n . keccak256(mem[p..(p+s))) and send v wei and return the new address
call(g, a, v, in, insize, out, outsize) call contract at address a with input mem[in..(in+insize)) providing g gas and v wei and output area mem[out..(out+outsize)) returning 0 on error (eg. out of gas) and 1 on success
callcode(g, a, v, in, insize, out, outsize) identical to call but only use the code from a and stay in the context of the current contract otherwise
delegatecall(g, a, in, insize, out, outsize) identical to callcode but also keep caller and callvalue
staticcall(g, a, in, insize, out, outsize) identical to call(g, a, 0, in, insize, out, outsize) but do not allow state modifications
return(p, s) - end execution, return data mem[p..(p+s))
revert(p, s) - end execution, revert state changes, return data mem[p..(p+s))
selfdestruct(a) - end execution, destroy current contract and send funds to a
invalid - end execution with invalid instruction
log0(p, s) - log without topics and data mem[p..(p+s))
log1(p, s, t1) - log with topic t1 and data mem[p..(p+s))
log2(p, s, t1, t2) - log with topics t1, t2 and data mem[p..(p+s))
log3(p, s, t1, t2, t3) - log with topics t1, t2, t3 and data mem[p..(p+s))
log4(p, s, t1, t2, t3, t4) - log with topics t1, t2, t3, t4 and data mem[p..(p+s))
origin transaction sender
gasprice gas price of the transaction
blockhash(b) hash of block nr b - only for last 256 blocks excluding current
coinbase current mining beneficiary
timestamp timestamp of the current block in seconds since the epoch
number current block number
difficulty difficulty of the current block
gaslimit block gas limit of the current block

其中call,callcode,delegatecall,staticcall非常重要,要搞清楚,才能理解evm的执行模型.

目录
相关文章
|
8月前
|
存储 前端开发 区块链
常见的 EVM 版本以及它们的区别
常见的 EVM 版本以及它们的区别
141 5
|
存储 安全 编译器
EVMPatch:自动修补以太坊智能合约
EVMPATCH的概念验证实现会自动加固智能合约,这些合约容易受到整数上溢/下溢和访问控制错误的影响,但可以轻松扩展以涵盖更多错误类。对14,000个现实合约的评估表明,本文工具成功地阻止了对合约发起的攻击交易,同时保持了合约的预期功能不变。研究者与经验丰富的软件开发人员进行了一项研究,结果表明EVMPATCH是实用的,并且可以将从给定的Solidity智能合约转换为可升级合约的时间减少97.6%,同时还可以确保与原始合约的功能等效。
134 2
|
存储 安全 编译器
MIPS架构深入理解11-向MIPS移植软件之编程语言
MIPS架构深入理解11-向MIPS移植软件之编程语言
|
存储 缓存 Unix
MIPS架构深入理解8-向MIPS移植软件之大小端模式
MIPS架构深入理解8-向MIPS移植软件之大小端模式
|
存储 Java 区块链
6分钟以太坊实战 - 智能合约与Solidity高级语言(一)
1. 简介 合约是存放在以太坊区块链具有特定地址的代码和数据集合。 合约账户之间可以相互传递消息以实现图灵完备运算。 合约以以太坊特定的二进制字节码通过以太坊虚拟机(EVM)运行于区块链上。目前,合约通常是以Solidity(一门长得很像js的语言)高级语言编写,编译后传到区块链上运行。
9624 0
|
Go 区块链
以太坊系列之十六:golang进行智能合约开发
以太坊系列之十六: 使用golang与智能合约进行交互 以太坊系列之十六: 使用golang与智能合约进行交互 此例子的目录结构 token contract 智能合约的golang wrapper 部署合约 1.
2120 0
|
区块链
以太坊学习之开发编译部署调用智能合约
本文根据汪晓明的视频资料整理,ubuntu16.04测试正确。  1.打开geth控制台 ~$ geth --datadir ~/pengfan/eth --dev 在另一个终端输入 ~$ geth --dev console 2>>file_to_log_output 2.
1923 0
|
存储 Linux API
深入以太坊智能合约 ABI
开发 DApp 时要调用在区块链上的以太坊智能合约,就需要智能合约的 ABI。本文希望更多了解 ABI,如为什么需要 ABI?如何解读 Ethereum 的智能合约 ABI?以及如何取得合约的 ABI? 数字猫合约 ABI ABI(Application Binary Interface) 如果理解 API 就很容易了解 ABI。
1671 0