-
Notifications
You must be signed in to change notification settings - Fork 126
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
Inlined metering #182
Comments
Another question in a hypothetical metering scheme where a global is used: |
Definitely, the prototype of the version with
How? By adding additional code in the main function that copies it from the added param? Or by making the
For compilers predictable branches like this one are quite free. You can also add a compiler hint about branching probability, but I wouldn't go so far at first.
Personally, my favorite option would be to add
Second more complicated option is to return error code from |
btw, this is prototyped here ewasm/sentinel-rs#9 |
Also prototyped here https://github.com/poemm/pywebassembly/blob/master/examples/metering.py . This prototype existed for over a year, but it was cleaned up recently to allow for mutable global exports which landed in the WebAssembly spec this past summer. Having multiple implementations allows for differential testing. This prototype can also be modified to test other things. Python has been great for prototying and testing. |
No need to check at every branch if you allow the gas to go negative. You only need to make the comparison often enough to avoid overly large negative gas. So maybe check on function entry and once in every unbounded loop. Hot tight loops could be unrolled a couple of times to amortize the check more. Downside is it will be harder to determine the exact opcode where it went out of gas. Is this information required? |
Wasm-opt will assume |
This idea has been independently suggested by @chfast, @poemm, @jwasinger and me.
Currently the metering injection inserts a call to an imported method (
ethereum::useGas
) at every check, which comes with a large overhead. One potential solution to this is to inline the statements and reduce the amount of external calls being make.If we assume that code is validated (via the "sentinel contract") prior to metering injection, then we can make use of globals. The proposal is the following:
gasLeft
Some questions:
unreachable
for the failure case? Can it be optimised out by engines? Would it be better to insert a call to an imported abort function? (ethereum::abortOutOfGas
for example)The text was updated successfully, but these errors were encountered: