Skip to content
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

Unify gas depletion handling #2013

Open
kulikthebird opened this issue Oct 22, 2024 · 0 comments
Open

Unify gas depletion handling #2013

kulikthebird opened this issue Oct 22, 2024 · 0 comments

Comments

@kulikthebird
Copy link

We have two types of gas:

  • WasmD Gas - the unit that is used in WasmD,
  • WasmVM Gas - currently 1 Cosmos Gas = 140_000 WasmVM Gas

The test case TestLimitRecursiveQueryGas runs the following scenario:

  • Translate WasmD Gas to WasmVM Gas and set the limit for the Query call,
  • Run WasmVM to perform and finish a recursive Query call, return the amount of WasmVM gas used,
  • Translate the returned WasmVM Gas back to WasmD Gas and subtract it from the gas limit assigned for the whole operation,
  • Check in WasmD if there is no gas left - panic in such case.

When we updated WasmVM to v2.2 the gas fee calculations in WasmVM has changed. We encountered the following scenario:

  • Translate WasmD Gas to WasmVM Gas and set the limit for the Query call,
  • Run WasmVM to perform and finish a recursive Query call, return the amount of WasmVM Gas used. This step returned VmError::GasDepletion error.

In the second case if we artificially increase the gas limit set for the Query operation of 1 WasmD Gas or 116_370 WasmVM Gas, the test behave the same way as in the first case i.e. the WasmVM finishes the operation and WasmD panics when theres 0 gas left.

WasmD panics when it has 0 WasmD Gas left, regardless of the fact that there was enough gas to run the whole procedure for WasmVM. In the first case WasmVM finished and returned 23_630 WasmVM Gas. After translation WasmD is left with 23_630 WasmVM Gas / 140_000 = 0.214285714 WasmD Gas. This is rounded down to 0, that's why we get panic from WasmD and not the error from WasmVM.

It seems to me that getting VmError::GasDepletion should be the only valid way to raise the RanOutOfGas panic in WasmD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant