-
Notifications
You must be signed in to change notification settings - Fork 54
fix(levm): fix gas refunds #1410
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
sender, | ||
U256::from(report.gas_refunded) | ||
.checked_mul(self.env.gas_price) | ||
.ok_or(VMError::GasLimitPriceProductOverflow)?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this error name is not the most appropriate but it's ok though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be OutOfGas
or BalanceUnderflow
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overflow would be the result of multiplying the refunded gas by the gas price, so it should not be an issue in the balance sheet itself. Furthermore, since it is added to the balance sheet, it would be an overflow in any case.
Wait, I remembered that, according to the Yellowpaper, the gas refunds have to be capped at 1/5th of the total gas used. let refunded_gas = report.gas_refunded.min(
consumed_gas
.checked_div(5)
.ok_or(VMError::Internal(InternalError::UndefinedState(-1)))?,
); This PR is a good fit for that I believe, but we have to ensure that at least the same amount of tests pass |
One extra thing, today (or at the latest tomorrow) I'll probably change the logic behind gas consumption and the update of the user's balance. So we can merge this and then change that. |
Motivation
The gas refunds had a bug in the sstore calculation. Fixes all the tests from
stShift
folder.Description
Also, this PR sums the refunds to the sender's balance.