以太坊系列之十三: 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 ...
随机推荐
- HUSTOJ 昆虫繁殖(递推)
昆虫繁殖 时间限制: 1 Sec 内存限制: 128 MB提交: 25 解决: 16[提交][状态][讨论版][命题人:quanxing] 题目描述 科学家在热带森林中发现了一种特殊的昆虫,这种昆 ...
- ILMerge最佳实践
背景 为了生成的代码更加简捷,复制方便,常常会把多个可执行文件合并成一个. 方案 Project=>Properties=>Build Events=>Edit Post-build ...
- 完整部署OpenStack-memcache配置
一.[root@openstack-server ~]# nova listERROR (CommandError): You must provide a username or user id v ...
- MFC 控件使用汇总
一.动态创建button CButton *button=new CButton; button->Create(_T(,,,),);//最后一个是ID BEGIN_MESSAGE_MAP(CM ...
- blockground
颜色的表示方法 一共有三种:单词.rgb表示法.十六进制表示法 rgb:红色 绿色 蓝色 三原色光学显示器,每个像素都是由三原色的发光原件组成的,靠明亮度不同调成不同的颜色的.用逗号隔开,r.g.b的 ...
- 手把手教你如何优化linux服务器
关闭不需要的服务.列出需要启动的的服务crond.network.sshd.irqbalance.syslog 启用 irqbalance 服务既可以提升性能,又可以降低能耗. syslog 是 li ...
- 把jpg文件读取到内存char* 再转换成CImage
网络上找到大神写的转换方法,不过就记下来,学习学习: 当然转成CImage之后就可以从CImage转换成HBITMAP 了 void DrawPic(CDC *pDC,char *buf,int le ...
- python 模块 optparse
optparse,是一个能够让程式设计人员轻松设计出简单明了.易于使用.符合标准的Unix命令列程式的Python模块.生成使用和帮助信息. 下面是一个简单的示例: import optparse p ...
- windows 共存多个位数不同的jdk时,eclipse的报错对应措施
1. 判断当前jdk的位数 # java -version java version "1.6.0_26" Java(TM) SE Runtime Environment (bui ...
- mysql多个字段拼接
Mysql的查询结果行字段拼接,可以用下面两个函数实现: 1. concat函数 mysql') from test ; +---------------------+ ') | +--------- ...