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中类的线程安全问题
java中各种集合(字符串类)的线程安全性!!! 一.概念: 线程安全:就是当多线程访问时,采用了加锁的机制:即当一个线程访问该类的某个数据时,会对这个数据进行保护,其他线程不能对其访问,直到该线程读 ...
- 多线程系列(3)任务Task
虽然使用线程池ThreadPool让我们使用多线程变得容易,但是因为是由系统来分配的,如果想对线程做精细的控制就不太容易了,比如某个线程结束后执行一个回调方法.恰好Task可以实现这样的需求.这篇文章 ...
- Android-远程Service
http://blog.csdn.net/guolin_blog/article/details/9797169 http://www.jianshu.com/p/eeb2bd59853f 将一个普通 ...
- 2.Observer Pattern(观察者模式)
Observer Pattern(观察者模式)定义: 在对象之间定义一对多的依赖,这样一来,当一个对象改变状态,依赖它的对象都会收到通知,并自动更新. 干说定义肯定没有举例理解的透彻.想到Observ ...
- SpingBoot —— RestTemplate的配置
背景:最近工作上搭建了一个中间系统,采用了RestTemplate框架调用第三系统restful接口,调用方采用轮询的方式调用本系统的相关接口,期间多次出现堆内存溢出,系统假死,通用java自带的ja ...
- JavaScript--表单处理(27)
一 表单介绍 // 在HTML中,表单是由<form>元素来表示的,而在JavaScript中,表单对应的则是HTMLFormElement类型; // HTMLFormElement继承 ...
- django-强大的ORM
一.ORM简介 (对象关系映射:object relationship mapping) MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的 ...
- JNDI 与 LDAP
对于众多接口服务.协议.互联网名称,总会遇到感到熟悉,但是时间一长就会忘记,所以还是要自己整理一下,加强记忆,当然最好的方式还是动手实践. JNDI : 全称:JAVA NAMING AND Dire ...
- 5月8日——iOS中的3D Touch效果
需要在manifest.json文件中进行配置 需要执行的js代码为: 最终操作效果为 本篇文章主要采用了HTML5+ 中的 launcher属性 具体可参照 http://www.html5plu ...
- JS中String与Array的一些常用方法
真是恨透了这些类似于substring substr slice 要么长得像,要么就功能相近的方法... 1⃣️string 1.substring(start开始位置的索引,end结束位置索引) 截 ...