cap9 icon indicating copy to clipboard operation
cap9 copied to clipboard

Handle gas allocation robustly

Open JakeOShannessy opened this issue 6 years ago • 3 comments

As part of a syscall (or any call) we usually pass the value of the GAS call, which is equivalent to allowing the called contract to use as much of the remaining gas as it needs. When performing a CALL in EVM this was quite easy, as the GAS call was the last instruction executed before performing the call. When comping to WASM this isn't quite as simple, as we can't guarantee that it is the final instruction called.

Currently, there are a few instances of GAS - SomeValue to allow some leftover gas to complete other instructions. This is not a robust way to do this and we should find alternatives.

JakeOShannessy avatar Jun 14 '19 04:06 JakeOShannessy

I have a solution for this. We can use the same mechanism as cap9_syscall_low and introduce cap9_maxgas_call_code and the like. In the same way we can control the exact instructions deployed and make sure that exactly all the remaining gas is used.

JakeOShannessy avatar Jun 21 '19 02:06 JakeOShannessy

I have a solution for this. We can use the same mechanism as cap9_syscall_low and introduce cap9_maxgas_call_code and the like. In the same way we can control the exact instructions deployed and make sure that exactly all the remaining gas is used.

Would this still be feasible for validation?

Latrasis avatar Jun 21 '19 05:06 Latrasis

In that particular case it's only for the kernel, so we don't have to run it through the validation code.

For procedures we have defined syscalls in such a way that handles this already, we just have to make sure the values are correct, which I failed to do in #178 it seems.

JakeOShannessy avatar Jun 21 '19 06:06 JakeOShannessy