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 推的时候忽略文件的操作: ...
随机推荐
- 常见hash算法的原理(转)
常见hash算法的原理 散列表,它是基于快速存取的角度设计的,也是一种典型的“空间换时间”的做法.顾名思义,该数据结构可以理解为一个线性表,但是其中的元素不是紧密排列的,而是可能存在空隙. 散列表 ...
- 杭电acm习题分类
专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...
- 山东省第四届acm解题报告(部分)
Rescue The PrincessCrawling in process... Crawling failed Description Several days ago, a beast ca ...
- HDU1260(KB12-H DP)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- 01-MySql的前戏
[转]01-MySql的前戏 MySql的前戏 在学习Mysql之前,我们先来想一下一开始做的登录注册案例,当时我们把用户的信息保存到一个文件中: #用户名 |密码root|123321 alex|1 ...
- 通过ssh实现远程登陆服务器!
通过ssh实现远程登陆前提是服务器已经开启ssh服务,至于怎么开启,可以参看上一篇“Linux服务器开启ssh服务,实现ssh远程登陆!”! 使用ssh登陆时,输入主机(linux的ip地址),账号, ...
- 在Ubuntu 14.04 LTS系统中设置Apache虚拟主机(一IP多访问)
参考资料:http://os.51cto.com/art/201406/441909.htm
- C# Newtonsoft.Json反序列化为dynamic对象之后的使用
通过Newtonsoft.Json将一个json类型的字符串反序列化为dynamic后直接使用报错 源代码: namespace ConsoleApplication1 { class Program ...
- 前端开发笔记(3)css基础(中)
上一篇中我们学习了html的标准文档流,下面我们先来看看如何脱离标准流. 脱离标准流 css中一共有三种方法脱离标准流 浮动 绝对定位 固定定位 浮动 我们要搞清楚什么是浮动,先来看一个标准文档流的例 ...
- html垂直居中
参考于http://www.cnblogs.com/yugege/p/5246652.html <!DOCTYPE html> <html lang="en"&g ...