-
Notifications
You must be signed in to change notification settings - Fork 28
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
fix(levm): sstore refund logic #1559
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.
Nice!
I noticed that in execution specs they do this at the beginning of the opcode:
if evm.gas_left <= GAS_CALL_STIPEND:
raise OutOfGasError
I think it is for avoiding accessing to the storage slot if we don't have enough gas, it feels like an optimization. Do you think we can add it here?
We are doing that in the cost function: pub fn sstore(
storage_slot: &StorageSlot,
new_value: U256,
storage_slot_was_cold: bool,
current_call_frame: &CallFrame,
) -> Result<u64, VMError> {
// EIP-2200
let gas_left = current_call_frame
.gas_limit
.checked_sub(current_call_frame.gas_used)
.ok_or(OutOfGasError::ConsumedGasOverflow)?;
if gas_left <= SSTORE_STIPEND {
return Err(VMError::OutOfGas(OutOfGasError::MaxGasLimitExceeded));
}
... I can move it to the opcode function and if this case happens, we avoid doing extra calculations. Done fce0d53 |
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.
n1
Motivation
There was a discrepancies in gas usage and refunds. The issue was related to an improper management of gas refunds in
sstore
.Description
There was an error when calculating the gas refund. Adjust the conditional logic to subtract refunds when reverting storage changes and adding refunds appropriately. Also, reordered refund and cost logic.