GithubHelp home page GithubHelp logo

Comments (6)

ehildenb avatar ehildenb commented on June 2, 2024 1

https://github.com/WebAssembly/spec/blob/master/document/core/exec/instructions.rst

Looking at SELECT as a template.

So right now we have:

useGas

Subtracts an amount to the gas counter

Parameters

  • amount i64 the amount to subtract to the gas counter

Returns

nothing

But we might think to have (I'm taking liberty with making my own notation for the system contract math notation at the end):

useGas

  1. Assert: due to validation, that the top element of the stack is a value of type i64.
  2. Pop the value i64.const g from the top of the stack.
  3. Load the value i64.const G from EEI.gasAvailable.
  4. If g <= G, then:
    i. Set EEI.gasAvailable to G - g.
  5. Else:
    ii. Set EEI.trapReason to out of gas and Trap.
~\\[-1ex]
\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
EEI; (\I32.\CONST g) (useGas) &\stepto& EEI'
\end{array}
\\ \qquad
(\iff EEI.gasAvailable = G \\
 \wedge G >= g \\
 \wedge EEI' = EEI \with gasAvailable = G - g \\
 )
\end{array}

\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
EEI; (\I32.\CONST g) (useGas) &\stepto& EEI'; trap
\end{array}
\\ \qquad
(\iff EEI.gasAvailable = G \\
 \wedge G < g \\
 \wedge EEI' = EEI \with trapReason = "out of gas" \\
 )
\end{array}

This would give us a nice way to formalize/disambiguate issues like: #72

from design.

axic avatar axic commented on June 2, 2024

Can you give a short example of what format you'd like it to have? (There are so many versions of the "WAMS spec", I'm not entirely sure which one do you mean.)

from design.

axic avatar axic commented on June 2, 2024
  1. Assert: due to validation, that the top element of the stack is a value of type i64.
  2. Pop the value i64.const g from the top of the stack.

I am not sure we actually have access to the stack.

External functions don’t receive access to the stack of the caller, just arguments, which were popped already off the stack.

from design.

ehildenb avatar ehildenb commented on June 2, 2024

Would the following make more sense?
Note that I've switched (i32.const g) (useGas) to call EEI.useGas i64.const g to reflect that this is a function call.

call EEI.useGas i64.const g

  1. Load the value i64.const G from EEI.gasAvailable.
  2. If g <= G, then:
    i. Set EEI.gasAvailable to G - g.
  3. Else:
    ii. Set EEI.trapReason to out of gas and Trap.
~\\[-1ex]
\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
EEI; (call EEI.useGas i64.const g) &\stepto& EEI'
\end{array}
\\ \qquad
(\iff EEI.gasAvailable = G \\
 \wedge G >= g \\
 \wedge EEI' = EEI \with gasAvailable = G - g \\
 )
\end{array}

\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
EEI; (call EEI.useGas i64.const g) &\stepto& EEI'; trap
\end{array}
\\ \qquad
(\iff EEI.gasAvailable = G \\
 \wedge G < g \\
 \wedge EEI' = EEI \with trapReason = "out of gas" \\
 )
\end{array}

from design.

lrettig avatar lrettig commented on June 2, 2024

From the perspective of a lowly implementer, this would help a lot and would probably preempt a lot of the dumb questions I've asked e.g. https://gitter.im/ewasm/internal?at=5aac31dbc3c5f8b90d7e5e15.

from design.

ehildenb avatar ehildenb commented on June 2, 2024

https://docs.google.com/document/d/1z_u-hmQ6kF50rXbBEmT_tLOnyBGaBplpoOIe0FPEZ3s/edit?usp=sharing

from design.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.