在无约束回路中,我经常使用低气体测试来破坏,并允许函数优雅地完成。
while (msg.gas > 40000) { ...do something...}在以前的代码评审中,评审人员提到,气体成本(或其他动态)可能会在将来的某个时候改变协议。
Q1。有没有人提到可能发生的变化?
Q2。有人能建议其他优雅的退出措施吗?
发布于 2017-03-25 23:54:03
感谢@niksmac引导我使用EIP150规范(版本2),它将增加IO重操作码的气体成本,超出了版本1,该版本是为防止州膨胀攻击而制定的。
如果清理代码的成本超过了比较中的常量,这些都是显著的成本增加,可能会打破试图使用所描述的气体测试体面退出的合同。
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.https://ethereum.stackexchange.com/questions/13501
复制相似问题