2

In unbound loops I often use a low gas test to break and allow the function to complete gracefully.

while (msg.gas > 40000) { ...do something...}

In some previous code review, the reviewer mentioned that gas costs (or other dynamics) may change in the protocol at some future time.

Q1. Does anyone have any reference to possible changes?

Q2. Can anyone suggest other graceful exit practices?

1

Thanks to @niksmac for directing me to the [EIP150] (https://github.com/ethereum/EIPs/issues/150) specification (version 2) which will increase the gas costs of IO heavy opcodes for Metropolis beyond version 1, which was enacted to prevent state bloat attacks.

These are significant cost increases which could break contracts attempting to exit gracefully using the gas test described, if the cost of the cleanup code exceeds the constant in the comparison.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.