ethereum/EIPs-170 Contract code size limit
| eip | title | author | type | category | status | created |
|---|---|---|---|---|---|---|
|
170
|
Contract code size limit
|
Vitalik Buterin
|
Standards Track
|
Core
|
Final
|
2016-11-04
|
Hard fork
Parameters
FORK_BLKNUM: 2,675,000CHAIN_ID: 1 (main net)
Specification
If block.number >= FORK_BLKNUM, then if contract creation initialization returns data with length of more than 0x6000(2**14 + 2**13) bytes, contract creation fails with an out of gas error.
如果合约的数据大小大于0x6000,那么该合约的创建将会失败
Rationale
Currently, there remains one slight quadratic vulnerability in Ethereum: when a contract is called, even though the call takes a constant amount of gas, the call can trigger O(n) cost in terms of reading the code from disk, preprocessing the code for VM execution, and also adding O(n) data to the Merkle proof for the block's proof-of-validity. At current gas levels, this is acceptable even if suboptimal. At the higher gas levels that could be triggered in the future, possibly very soon due to dynamic gas limit rules, this would become a greater concern—not nearly as serious as recent denial of service attacks, but still inconvenient especially for future light clients verifying proofs of validity or invalidity. The solution is to put a hard cap on the size of an object that can be saved to the blockchain, and do so non-disruptively by setting the cap at a value slightly higher than what is feasible with current gas limits.
目前ethereum仍有一个脆弱点:当一个合约被调用时,即使它使用的是固定的gas值,这个调用仍然会触发O(n)量级的花销在从硬盘中读取代码、对VM执行的代码进行预处理和将O(n)数据添加到Merkle证明中以验证块的有效性上。在目前的gas水平下,这是可以接受的,即使不是最理想的。但是在未来可能被触发的较高的gas水平的情况下,可能很快由于动态气体限制规则而其将成为一个更大的担忧——可能不像最近的拒绝服务攻击那么严重,但仍然不方便,特别是对未来的轻客户端验证有效性或无效的证明。
解决方案是对一个对象的大小设置一个硬盘的上限(在这里既为合约的数据大小不大于0x6000),该上限可以保存到区块链,并通过将上限设置在略高于当前气体限制的可行值的情况下进行非干扰性设置。
References
- EIP-170 issue and discussion: https://github.com/ethereum/EIPs/issues/170
- pyethereum implementation: https://github.com/ethereum/pyethereum/blob/5217294871283d8dc4fb3ca9d8a78c7d416490e8/ethereum/messages.py#L397
该代码实现:
- EIP 170: Contract code size limit - changes the maximum code size that a contract on the blockchain can have. This update prevents an attack scenario where large pieces of account code can be accessed repeatedly at a fixed gas cost. The maximum size has been set to 24576 bytes, which is larger than any currently deployed contract.改变区块链中能够有的最大代码大小.盖更新将防止在设定好的gas开销中,大片账户代码被重复接收的攻击方案,最大的大小设置为字节,这比目前所有被设置的合约都大
def create_contract(ext, msg):
log_msg.debug('CONTRACT CREATION') code = msg.data.extract_all() if ext.tx_origin != msg.sender:
ext.increment_nonce(msg.sender) if ext.post_metropolis_hardfork() and msg.sender == null_address:
msg.to = utils.mk_contract_address(msg.sender, )
# msg.to = sha3(msg.sender + code)[:]
else:
nonce = utils.encode_int(ext.get_nonce(msg.sender) - )
msg.to = utils.mk_contract_address(msg.sender, nonce) b = ext.get_balance(msg.to)
if b > :
ext.set_balance(msg.to, b)
ext.set_nonce(msg.to, )
ext.set_code(msg.to, b'')
# ext.reset_storage(msg.to) msg.is_create = True
# assert not ext.get_code(msg.to)
msg.data = vm.CallData([], , )
snapshot = ext.snapshot()
if len(ext.get_code(msg.to)):
log_msg.debug('CREATING CONTRACT ON TOP OF EXISTING CONTRACT')
# return , , b'' ext.set_nonce(msg.to, if ext.post_spurious_dragon_hardfork() else )//
res, gas, dat = _apply_msg(ext, msg, code) log_msg.debug('CONTRACT CREATION FINISHED', res=res, gas=gas, dat=dat if len(dat) < else ("data<%d>" % len(dat))) if res:
if not len(dat):
# ext.set_code(msg.to, b'')
return , gas, msg.to
gcost = len(dat) * opcodes.GCONTRACTBYTE
if gas >= gcost and (len(dat) <= or not ext.post_anti_dos_hardfork())://合约创建钱判断gas的使用,合约的大小等
gas -= gcost
else://否则创建失败
dat = []
log_msg.debug('CONTRACT CREATION FAILED', have=gas, want=gcost, block_number=ext.block_number)
if ext.post_homestead_hardfork():
ext.revert(snapshot)
return , , b''
ext.set_code(msg.to, bytearray_to_bytestr(dat))
log_msg.debug('SETTING CODE', addr=encode_hex(msg.to), lendat=len(dat))
return , gas, msg.to
else:
ext.revert(snapshot)
return , gas, dat
ethereum/EIPs-170 Contract code size limit的更多相关文章
- *** FATAL ERROR L250: CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED
*** FATAL ERROR L250: CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED 在软件已经执行破解仍然出现,是因为工程是破解前建立的,要先执行 ...
- EVALUation mode running with code size limit:2k keil进行仿真过程中出现的报错
EVALUation mode running with code size limit:2k 如果keil软件未破解,会限制程序的存储大小.第一是你的软件没有破解,不能编译2K以上的程序:这种情况下 ...
- ethereum/EIPs-1271 smart contract
https://github.com/PhABC/EIPs/blob/is-valid-signature/EIPS/eip-1271.md Standard Signature Validation ...
- [转]預防 Android Dex 64k Method Size Limit
转载自:http://ingramchen.io/blog/2014/09/prevention-of-android-dex-64k-method-size-limit.html 08 Septem ...
- ORA-27092: size of file exceeds file size limit of the process
停数据库时遇到下述问题: $ ./addbctl.sh stop You are running addbctl.sh version 120.1 Shutting down database UAT ...
- [Mon Feb 10 15:21:06 2014] [notice] child pid 7101 exit signal File size limit exceeded (25)
今天遇到的问题: LAMP的LOG里报如下错误. 然后IE和FIREFOX里显示连接被重置或是无法访问. 但自己建一个正常的PHP测试探针倒可以. 原来是PHP错误日志太多,无法写入LOG导致. [r ...
- Github 修正上传时“this exceeds GitHub’s file size limit of 100 MB”错误
自己的项目的版本控制用的是Git,代码仓库在github托管.项目里用到了IJKMediaFramework 想把代码push到github上,结果出错了,被拒绝,具体信息是: Total 324 ( ...
- ES部署报错 max file size 和 kibana 报错File size limit exceeded
启动失败一 ERROR: [2] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process ...
- git this exceeds GitHub's file size limit of 100.00 MB
git push origin master过程中,出现如下错误 关键词:this exceeds GitHub's file size limit of 100.00 MB 推的时候忽略文件的操作: ...
随机推荐
- java多线程——线程池源码分析(一)
本文首发于cdream的个人博客,点击获得更好的阅读体验! 欢迎转载,转载请注明出处. 通常应用多线程技术时,我们并不会直接创建一个线程,因为系统启动一个新线程的成本是比较高的,涉及与操作系统的交互, ...
- RxJava1升级到RxJava2的注意事项
1.package更改 rx1包名由原来的rx.xxx更改为io.reactivex.xxx,并且在同一个module之下,rx1和rx2是不兼容的. 2.背压支持 RxJava在1.0只有一个个观察 ...
- Python 进阶必备函数
1. lambda 表达式 匿名函数(英语:anonymous function)是指一类无需定义标识符(函数名)的函数.通俗来说呢,就是它可以让我们的函数,可以不需要函数名. 正常情况下,我们定义一 ...
- RBAC 介绍 (权限)
RBAC是什么? RBAC是基于角色的访问控制(Role-Based Access Control )在RBAC中,权限与角色相关联,用户通过成为适当角色的成员而得到这些角色的权限.这就极大地简化了权 ...
- Bash:字符串操作
参考:http://blog.csdn.net/finewings/article/details/5718133 字符串提取 去掉指定前缀 1. ${varible#pattern} ...
- layui 三级菜单
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- android画板笔锋实现
前言 在安卓绘图中,path是一个很常用的类,使用它可以实现基本的画线功能,但是自己用path画出来的同一条线段大小是不会改变的.如果做书写类型的软件,当然想要实现更好的逼真的书写效果,在实际书写过程 ...
- Android--用JS去控制WebView显示的字体的大小
<script type="text/javascript"> function changeFontSize(size) { var tfs = '120%'; va ...
- [WPF 基础知识系列] —— 绑定中的数据校验Vaildation
前言: 只要是有表单存在,那么就有可能有对数据的校验需求.如:判断是否为整数.判断电子邮件格式等等. WPF采用一种全新的方式 - Binding,来实现前台显示与后台数据进行交互,当然数据校验方式也 ...
- 如何使用 Swift 开发简单的条形码检测器?
[编者按]本文作者为 Matthew Maher,主要手把手地介绍如何用 Swift 构建简单的条形码检测器.文章系 OneAPM 工程师编译整理. 超市收银员对货物进行扫码,机场内录入行李或检查乘客 ...