-
Notifications
You must be signed in to change notification settings - Fork 782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Out of Gas Issues Due to Interpreting "gasUsed" as "gasConsumed" #283
Comments
A potential option which would have prevented the |
Hi @seesemichaelj, thanks for your wonderful and extensive error descriptions, will have a first look into this. |
Think there should be no reason to not also report the Did you come to the same conclusion? |
@holgerd77 no problem! I maintained a repo for a few months and realized great issue descriptions => happy maintainers. And I'm trying to get you to like me before the more controversial PRs start coming in ;) Yes, that is the conclusion I came up with as well! |
Hehe. 😀 |
This issue comes about from generic
revert
errors reported in issue trufflesuite/ganache#412.The first
revert
error was mitigated from trufflesuite/ganache@2421f4a and is not related to this issue.However the second
revert
was due to running out of gas when using the estimated gas for a transaction. Even increasing the gas limit a little to account for minor fluctuations didn't solve the issue. It turns out the transaction was receiving a gas refund, andethereumjs-vm
implements this by subtracting the refund fromgasUsed
(see https://github.com/ethereumjs/ethereumjs-vm/blob/2a63a921f4f3b8aa85ffcc3c05dc9cc3922699a9/lib/runTx.js#L140-L148) which is a little counter-intuitive because the gas is used, and later refunded.ethereumjs-vm
correctly implements the consumption of this gas at first, and then reports less gas was used because of a refund but does not report a refund was used.Therefore, if you estimated a transaction that was eligible for a
SSTORE
refund of15,000
gas, thegasUsed
reported byethereumjs-vm
would be up to15,000
gas more than what was actually consumed before a refund. If the user then tried to run the transaction with the same amount of gas used of the estimate, the EVM could run out of gas in the middle of the transaction, and report anOOG
error (orrevert
in some cases it seems).I can see why we shouldn't change the reported
gasUsed
, because it's the amount of net gas that was removed from the sending account. However,ethereumjs-vm
should at a minimum report thegasRefund
to let callers know that additional gas may be needed to actually execute the transaction. I believe this proposal makes sense, but I'd love to talk alternatives if it's not quite right. I'm going to go ahead open a PR that implements this proposal.The text was updated successfully, but these errors were encountered: