以太坊系列之十三: evm指令集
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的执行模型.
以太坊系列之十三: evm指令集的更多相关文章
- 以太坊系列之十六: 使用golang与智能合约进行交互
以太坊系列之十六: 使用golang与智能合约进行交互 以太坊系列之十六: 使用golang与智能合约进行交互 此例子的目录结构 token contract 智能合约的golang wrapper ...
- 以太坊系列之十七: 使用web3进行合约部署调用以及监听
以太坊系列之十七: 使用web3进行智能合约的部署调用以及监听事件(Event) 上一篇介绍了使用golang进行智能合约的部署以及调用,但是使用go语言最大的一个问题是没法持续监听事件的发生. 比如 ...
- 以太坊系列之十六:golang进行智能合约开发
以太坊系列之十六: 使用golang与智能合约进行交互 以太坊系列之十六: 使用golang与智能合约进行交互 此例子的目录结构 token contract 智能合约的golang wrapper ...
- 以太坊智能合约虚拟机(EVM)原理与实现
以太坊 EVM原理与实现 以太坊底层通过EVM模块支持合约的执行与调用,调用时根据合约地址获取到代码,生成环境后载入到EVM中运行.通常智能合约的开发流程是用solidlity编写逻辑代码,再通过编译 ...
- 以太坊系列之一: 以太坊RLP用法-以太坊源码学习
RLP (递归长度前缀)提供了一种适用于任意二进制数据数组的编码,RLP已经成为以太坊中对对象进行序列化的主要编码方式.RLP的唯一目标就是解决结构体的编码问题:对原子数据类型(比如,字符串,整数型, ...
- 以太坊系列之十八: 百行go代码构建p2p聊天室
百行go代码构建p2p聊天室 百行go代码构建p2p聊天室 1. 上手使用 2. whisper 原理 3. 源码解读 3.1 参数说明 3.1 连接主节点 3.2 我的标识 3.2 配置我的节点 3 ...
- 以太坊系列之六: p2p模块--以太坊源码学习
p2p模块 p2p模块对外暴露了Server关键结构,帮助上层管理复杂的p2p网路,使其集中于Protocol的实现,只关注于数据的传输. Server使用discover模块,在指定的UDP端口管理 ...
- 以太坊系列之四: 使用atomic来避免lock
使用atomic来避免lock 在程序中为了互斥,难免要用锁,有些时候可以通过使用atomic来避免锁, 从而更高效. 下面给出一个以太坊中的例子,就是MsgPipeRW,从名字Pipe可以看出, 他 ...
- 以太坊系列之三: 以太坊的crypto模块--以太坊源码学习
以太坊的crypto模块 该模块分为两个部分一个是实现sha3,一个是实现secp256k1(这也是比特币中使用的签名算法). 需要说明的是secp256k1有两种实现方式,一种是依赖libsecp2 ...
随机推荐
- Java-Runoob:Java 教程
ylbtech-Java-Runoob:Java 教程 1.返回顶部 1. Java 教程 Java 是由Sun Microsystems公司于1995年5月推出的高级程序设计语言. Java可运行于 ...
- 测试php中的curl是否可使用
<?php $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,"http://www.baidu.com"); curl_seto ...
- 获取access_token错误 40164
没有添加IP白名单
- Android 4 学习(12):Linkify & Broadcast event
参考<Professional Android 4 Development> Linkify Linkfy类可以在Text View中创建超链接.匹配LInkify中正则表达式的文本将被L ...
- Bootstrap日期插件中文实现
Bootstrap的相关JS和CSS直接跳过. <script type="text/javascript" src="static/js/jquery-1.9.1 ...
- VS 配置外部DLL的引用路径【可执行文件的环境路径】
右键项目,属性->配置属性->调试->环境,在这里写入可执行文件运行时的环境路径,格式为:PATH=ABC,如PATH=$(SolutionDir)/env 这样,我们就可以把运行时 ...
- BP算法在minist数据集上的简单实现
BP算法在minist上的简单实现 数据:http://yann.lecun.com/exdb/mnist/ 参考:blog,blog2,blog3,tensorflow 推导:http://www. ...
- centos6下的安装navicat premium
centos6下的安装navicat premium CentOS6下做开发的时候,数据库客户端是一个必须要有的工具,因为经常要和数据库打交道.由于数据库的类型多样,有MySQL.Oracle.Pos ...
- Java基础-JDK、JRE与JVM的区别
JRE与JVM.JDK的区别 从下而上:最上层 JDK -- java development kit (java开发工具包)中间层 JRE -- java runtime enviro ...
- java基础之io流总结四:字符流读写
字符流读写只适用于字符文件. 基本字符流(转换流)读写文件 转换流本身是字符流,但是实例化的时候传进去的是一个字节流,所以叫做转换流 InputStreamReader isr = new Input ...