以太坊系列之十三: 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的执行模型.

目录
相关文章
|
Java 开发工具 Android开发
【 uniapp 】打包Android的apk(原生APP-云打包),及发布测试
【 uniapp 】打包Android的apk(原生APP-云打包),及发布测试
【 uniapp 】打包Android的apk(原生APP-云打包),及发布测试
|
机器学习/深度学习 PyTorch 算法框架/工具
RGCN的torch简单案例
RGCN 是指 Relational Graph Convolutional Network,是一种基于图卷积神经网络(GCN)的模型。与传统的 GCN 不同的是,RGCN 可以处理具有多种关系(边)类型的图数据,从而更好地模拟现实世界中的实体和它们之间的复杂关系。 RGCN 可以用于多种任务,例如知识图谱推理、社交网络分析、药物发现等。以下是一个以知识图谱推理为例的应用场景: 假设我们有一个知识图谱,其中包含一些实体(如人、物、地点)以及它们之间的关系(如出生于、居住在、工作于)。图谱可以表示为一个二元组 (E, R),其中 E 表示实体的集合,R 表示关系的集合,每个关系 r ∈ R
1916 0
|
供应链 前端开发 JavaScript
《Solidity 简易速速上手小册》第10章:区块链项目实战(2024 最新版)(上)
《Solidity 简易速速上手小册》第10章:区块链项目实战(2024 最新版)
371 0
|
2月前
|
JSON 监控 数据挖掘
借助拼多多 API,拼多多店铺商品类目优化精准指导
在电商竞争激烈的环境下,拼多多店铺通过API优化商品类目,可提升搜索排名与转化率。本文详解如何利用API获取类目数据、分析匹配度并实现自动化优化,助力商家精准定位商品类目,提升流量与销量。
147 0
|
机器学习/深度学习 数据可视化 网络架构
增强深度学习模型的可解释性和泛化能力的方法研究
【8月更文第15天】在深度学习领域,模型的准确率和预测能力是衡量模型好坏的重要指标。然而,随着模型复杂度的增加,它们往往变得越来越难以理解,这限制了模型在某些关键领域的应用,例如医疗诊断、金融风险评估等。本文将探讨如何通过几种方法来增强深度学习模型的可解释性,同时保持或提高模型的泛化能力。
1262 2
|
前端开发 Shell Go
微服务效率工具 goctl 深度解析(上)
微服务效率工具 goctl 深度解析(上)
|
机器学习/深度学习 并行计算 编译器
AVX 指令集简介及其与 SSE 的对比
本文介绍了AVX指令集在高性能计算中的重要性,它是Intel于2011年推出的一种SIMD技术,扩展了SSE指令集,将向量宽度增至256位,支持更多数据类型和浮点精度控制。主要差异包括向量宽度、数据类型扩展、指令集增加和精度控制。文中通过C代码示例展示了如何使用AVX进行向量加法。AVX对科学计算、图像处理和机器学习等领域提供了显著的性能提升。编译时需确保编译器支持AVX标志。
深入理解AMBA总线(十四)AXI Ordering Model、非对齐访问等
深入理解AMBA总线(十四)AXI Ordering Model、非对齐访问等
2284 1
|
前端开发 安全 区块链