首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在低汽油上有优雅退出的最佳做法吗?

在低汽油上有优雅退出的最佳做法吗?
EN

Ethereum用户
提问于 2017-03-25 04:28:09
回答 1查看 183关注 0票数 2

在无约束回路中,我经常使用低气体测试来破坏,并允许函数优雅地完成。

代码语言:javascript
复制
while (msg.gas > 40000) { ...do something...}

在以前的代码评审中,评审人员提到,气体成本(或其他动态)可能会在将来的某个时候改变协议。

Q1。有没有人提到可能发生的变化?

Q2。有人能建议其他优雅的退出措施吗?

EN

回答 1

Ethereum用户

发布于 2017-03-25 23:54:03

感谢@niksmac引导我使用EIP150规范(版本2),它将增加IO重操作码的气体成本,超出了版本1,该版本是为防止州膨胀攻击而制定的。

如果清理代码的成本超过了比较中的常量,这些都是显著的成本增加,可能会打破试图使用所描述的气体测试体面退出的合同。

代码语言:javascript
复制
Specification (version 2)

If block.number >= METROPOLIS_FORK_BLKNUM, then:

Increase the gas cost of EXTCODESIZE to 4000
Increase the base gas cost of EXTCODECOPY to 4000
Increase the gas cost of BALANCE to 400
Increase the gas cost of SLOAD to 200
Increase the gas cost of CALL, CALLDELEGATE, CALLCODE to 4000
Increase the gas cost of SUICIDE to 5000
If SUICIDE hits a newly created account, it triggers an additional gas cost of 25000 (similar to CALLs)
Increase the recommended gas limit target to 5.5 million
Define "all but one 64th" of N as N - floor(N / 64)
If a call asks for more gas than the maximum allowed amount, do not return an OOG error; instead, if a call asks for more gas than all but one 64th of the maximum allowed amount, call with all but one 64th of the maximum allowed amount of gas (this is equivalent to a version of #90 plus #114). CREATE only provides all but one 64th of the parent gas to the child call.
When executing EXTCODESIZE, EXTCODECOPY, CALL, CALLDELEGATE or CALLCODE (but NOT BALANCE), let CODELOADING_GAS be int(400 + len(code) / 6). At the end of the call, refund an additional 4000 - CODELOADING_GAS (if CODELOADING < 0, refund nothing). CREATE only provides 63/64 of the parent gas to the child call.
票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/13501

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档