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 推的时候忽略文件的操作: ...
随机推荐
- eclipse .properties插件
资源文件 即 .properties 文件是常用于国际化: eclipse默认的 .properties 文件编辑器有几个问题: 编码问题 多种语言同步问题 下面介绍2种eclipse的 .prope ...
- 【Spring】2、BeanFactory 和FactoryBean的区别
转自:http://chenzehe.iteye.com/blog/1481476 1. BeanFactory BeanFactory定义了 IOC 容器的最基本形式,并提供了 IOC 容器应遵守的 ...
- Java虚拟机 - 多态性实现机制
[深入Java虚拟机]之五:多态性实现机制——静态分派与动态分派 方法解析 Class文件的编译过程中不包含传统编译中的连接步骤,一切方法调用在Class文件里面存储的都只是符号引用,而不是方法在实际 ...
- JAVA设计模式详解(一)----------策略模式
策略模式,顾名思义就是设计一个策略算法,然后与对象拆分开来将其单独封装到一系列策略类中,并且它们之间可以相互替换.首先LZ举一个例子为大家引出这一个模式. 例子:某公司的中秋节奖励制度为每个员工发放2 ...
- JavaScript--事件对象(25)
// JavaScript事件的一个重要的方面是它们拥有一些相对一致的特点,可以给开发提供强大的功能; // 最方便和强大的就是事件对象,它们可以帮你处理鼠标事件和键盘敲击方面的情况; // 此外还可 ...
- ThinkPHP_5对数据库的CURL操作
Db::query();Db::execute(); Db::table()->select(); 所有数据,二维数组,结果不存在时返回空数组Db::table->find(); 一条数据 ...
- SSM 后台封装的有值, 到前台打印的时候没有值
原因: 实体类中的getting setting 方法没有配置,导致封装json 数据的时候没有封装进去
- HTML初学小技巧
01.让背景图不滚动IE浏览器支持一个 Body 属性 bgproperties,它可以让背景不滚动:〈Body Background="图片文件" bgproperties=&q ...
- Python——Queue模块以及生产消费者模型
1.了解Queue Queue是python标准库中的线程安全的队列(FIFO)实现,提供了一个适用于多线程编程的先进先出的数据结构,即队列,用来在生产者和消费者线程之间的信息传递 |queue.Qu ...
- 如何把SQL Server中一个表,一个存储过程,一个视图等改为系统表,系统存储过程,系统视图等
使用如下存储过程即可: EXEC sys.sp_MS_marksystemobject '[dbo].[TableNameToSystem]' 其中"[dbo].[TableNameToSy ...