►
From YouTube: Yaron Wittenstein, Spacemesh – Fixed-Gas Wasm
Description
Speaker: Yaron Wittenstein, a Leader of the SVM (Spacemesh Virtual Machine) project at Spacemesh
Title: Fixed-Gas Wasm
Spacemesh https://spacemesh.io/
Wasm in Web3 workshop https://avive.github.io/wasm_on_the_blockchain_2021/#/
A
Okay,
so
hello,
everyone
do
you
mean
so
today
I
would
like
to
talk
with
you
and
about
a
very
cool.
I
hope
you
will
find
it
cool
a
project.
It's
called
the
fixed
gas
wasn't,
but
before
that,
a
bit
of
introduction,
so
I'm
young,
I'm
working
for
the
project
named
space,
match
space
machine.
A
It
is
a
project
that
tries
to
implement
a
proof
of
space-time
solution
instead
of
the
other
other
popular
alternatives
like
the
proof-of-work
proof
of
stake,
so
space
mesh
is
about
proof
of
space
time
and
also
very
nice
and
unique
feature.
Is
that,
instead
of
having
like
a
chain
of
transactions,
the
the
spaceman
solution
is
about
storing
a
thing.
It's
called
the
mesh,
so
each
like
each
epoch,
that
of
a
space
mesh,
can
have
multiple
miners
one.
Second,
okay,
now
you
can
see
this
is
the
the
logo
of
space
machine.
A
I
am
the
leader
of
the
project
called
svm.
This
is
the
github
of
our
project
called
svm,
and
we
use
wasmer
was
a
was
wise
man
assembly
one
time.
Basically,
it's
sorry.
We
we
used.
There
was
no
project
from
the
the
early
days
of
wasmery,
much
much
before
right
into
the
1.0
milestone,
and
personally
I
really
like
the
the
company
and
it's
very
always
very
fun,
working
with
them
and
and
the
project
like
the
father
of
the
father
project,
which
is
the
full
node
implementation
of
space
mesh,
is
called
the
go
space
mesh.
A
So
this
is
the
link
to
the
repository
the
as
you
can
see
from
this
prefix.
It
seems
implemented
in
golang,
but
svm
is
a
rust
project
because
it
integrates
with
fastener
and
wasmer
is
written
in
west.
So
the
way
it
works
is
basically
with
some
ffi
layout
that
that
makes
it
possible
to
integrate
with
go
space,
machine,
less
vm.
A
A
few
words
about
myself,
so
I
have
started
working
on
svm,
I
think
about
two
years.
Two
years
ago,
basically
svm
has
gone
through
a
couple
of
big
changes
over
time,
because,
as
time
passed,
we
and
like
requirements
have
changed
and
we
have
refined
things.
They
were
writing
things
and
right
now
it
seems
that
the
svm
is
moving
conf
towards
being
stable
and
reaching
some
very
mature
phase.
A
We
are
always
looking
for
great
people
to
join
the
project,
so
please
take
a
look,
also,
I'm
very
fond
of
the
eras
programming
language
and
I
love
the
wazam,
and
I
think
it
raised
a
bright
future
inside
the
crypto
scene,
but
also
outside
of
it.
I
think
that
it
can
become
like,
like
the
de
facto
universal
bytecode,
that
we
always
hope
to
be
left.
So
it
seems
that
has
a
bright
future
in
front
of
it,
and
this
is
a
link
to
my
personal
website
and.
A
Actually,
it
was
very
fresh.
A
few
weeks
days
ago,
I've
launched
a
new
newsletter,
so
I
will
hope
that
you
will
find
it
useful.
So
please
take
a
look,
and
maybe
you
will
consider-
please
consider
subscribing
to
it,
and
you
can
also
reach
me
out
over
twitter
under
this
ash.
Under
this
tag,
it's
called
real
wittenstein.
A
So
if
you
want
to
say
hi
or
just
follow
me
so
please,
okay,
now,
please,
let's
take
a
step
back
and
forget
for
a
second
about
the
reason
that
we
are
aware
and
the
and
the
the
fact
that
we
are
talking
about
blockchains
and
web
assembly
and
crypto
and
all
this
stuff,
and
let's
talk
about
something
much
much
much
more
eye
level,
which
is
life
okay,
so
in
life,
as
you
know,
life
is
a
one.
Big
trade
of
everything
is
a
trade-off
and
software
is
no
exception.
A
Software
also
has
a
lot
of
trade-offs
and
we
need
to
find
the
each
time
the
the
right,
the
right
balance
for
us.
So
I've
prepared
this
triangle
containing
three
metrics.
Three.
A
You
could
call
it
maybe
vectors
that
I
think
that
it's
very
hard
not
to
say
impossible
to
reach
to
fully
reach
entirely
at
the
same
time
simultaneously.
So
in
the
context
of
software,
if
we
want
to
have
a
software
that
is
very,
very
fast,
super
fast
and
very,
very
flexible
in
terms
of
features
set
capabilities
of
the
software
and
also
very
very
easy
to
use
from
user
experience
and
go,
I
would
say
that
it's
pretty
much
not
possible
to
to
to
fully
fulfill
the
three
dimensions
simultaneously.
A
So
if
we
want
to
have,
for
example,
that
software
that
is
super
flexible
contains
almost
every
er
lot
of
very
complicated
features,
and
also
very
very
fast,
it's
fair
to
say
that
the
user
experience
will
probably
suffer
to
some
extent.
Okay.
So
this
is
when
picking
these
two
points
and
let's
take
another
example,
another
view.
A
So
if
we
want
to
have
a
software
with
a
great
user
experience-
and
we
wanted
to
have
a
lot
of
features
and
being
very
flexible,
it's
likely
that
it
will
not
be
the
fastest
software
that
we
could,
that
she
ever
achieved
otherwise.
And
the
last
case
is
that
if
we
want
to
have
a
software
that
is
very,
very
easy
to
use
and
super
fast,
we
will
probably
have
to
introduce
some
restrictions.
Some
constraints,
so
probably
the
feature
that
we
will
be
able
to
implement
will
will
not
be
complete.
A
We
will
probably
have
to
decide
to
keep
some
of
the
features
that
we
would
like
to
aside.
Okay-
and
I
have-
I
would
argue
that
basically
in
our
scene
of
of
crypto,
it's
blockchain
solution.
It's
very,
very
naive
to
think
that
we
would
like
to
be
not
as
fast
as
we
can.
We
know
how
much
it's
important
to
have
a
good
throughput
and
the
number
of
transactions
spell
in
a
block
a
layering
if
we
will
use
the
space
mesh
terms
terminology.
A
So,
instead
of
looking
at
this
triangle,
I
would
argue
that
it's
more
like
viewing
this,
these
two
metrics
okay,
so
we
are
left
with
being
creating
a
software
or
providing
a
solution
that
will
be
very
flexible
in
terms
of
the
features
that
we
can
implement
on
top
of
it
that
we
can
provide-
and
we
want
also
to
have
a
very
good
user
experience
so
in
space
mesh
we
want
the
vision
is
that
every
person,
even
non-tech,
savvy
person,
like
every
person,
can
use
our
platform
without
being
a
programmer
without
knowing
what
is
variable
same
their
rust
just
being
an
ordinary
computer
and
a
user
now
ill.
A
We
stand
in
front
of
a
very,
very
critical
decision.
Okay,
it's
it's
either
we
pick
the
one
or
the
other.
I
mean
we
need
to
to
decide.
What's
it's
more
important
for
us?
Okay,
so
let's
stop
the
pause
for
a
second
and
let's
talk
for
about
the
gas
estimation
problem
and
it
actually
it,
and
it
is
actually
like
a
direct
continuation
of
the
previous
question
being
that
was
asked
during
the
talk.
A
So
it
all
related
to
the
outing
problem,
so
alan
turing
it,
I
think
it
was
1936
allen,
turing
well
now,
1937
doesn't
matter.
Alan
jones
proved
that
we
cannot
take
a
program,
look
statically
or
or
over
the
cod
and
decide
whether
it
will
stop
or
not.
Okay,
and
this
is
something
that
each
computer
science
student
learns
in
the
first
lesson
of
the
computability
course
and
this.
A
Similarly,
similarly
naive
or
not
very
important
proof
is
actually
a
very,
very
dramatic
to
our
old,
because
we
cannot
let
someone
just
send
the
transaction
smart
contract
transaction
detail.
Will
that
will
execute
on
our
platform
without
knowing
in
advance
whether
it
will,
whether
it
will
stop
or
not
right?
So
the
solution
that
we
currently
pretty
much
have
all
over
the
place
is
to
say:
okay,
I
will
do
my
best
best
effort
guests
and
I
will
try
to
do
whatever
I
can
learning
from
the
story.
A
You
know
performing
some
smart
guesses
and
I
will
do
my
best
and
if
the
the
program
will
exceed
this
threshold
number
of
steps,
the
guards
units
that
I
I'm
okay
to
allocate,
then
it
will
forcibly,
we
will
make
it
out,
we
will
enforce
it
to
terminate
and
the
center
of
the
transaction
will
be
like
punished,
because
the
transaction
will
not
reach
its
completion,
but
it
he
still
will
have
to
compensate
for
this
execution
of
transaction.
A
So
the
gas
estimation
is
something
that
we
must
deal
with.
We
cannot
escape
it
due
to
the
healthy
problem,
and
this
is
really
a
good
example
of
what
we've
just
talked
about
about
being
flexible
and
being
easy
to
use.
So
if,
instead
of
calling
it
flexible
and
easy
to
use,
we
would
say:
okay:
do
we
want
to
be
during
complaint?
A
When
I'm
saying
to
incomplete,
I
mean
do
we
want
to
to
support
any
kind
of
logic
that
we
could
possibly
execute,
or
do
we
more
care
about
giving
a
very
good
gas
estimation,
because
if
we
want
to
be
too
incomplete,
if
we
want
to
to
to
have
no
restrictions
basically-
and
we
are
willing
to
to
pay
yeah
for
the
for
not
having
the
greatest
gas
estimation,
then
it's
fine.
A
But
in
our
case,
in
space
mesh.
For
now,
we
have
settled
on
moving
towards
the
other
side
and
we
put
more.
A
A
We
are
aware
that
we
will
not
have
everything
and
we
are
okay.
With
that
I
mean
we
might
just
decide
in
the
future
to
support
another
mode,
that
we
will
support.
Gaza.
Sorry
during
completeness
and
using
some,
not
ideal
user
experience
of
gas
estimation.
But
right
now-
and
this
is
the
focus
of
our
today's
talk-
is
that
we
are
okay
with
adding
constraints.
We
are
okay
with
not
being
fully
to
incomplete,
but
we
also
want
to
to
accomplish
a
better
user
experience
for
the
gas
estimation,
and
this
is
the
topic
today.
A
This
is
what
we
have
named
the
fixed
gas
okay
in
the
fixed
gas.
So
this
is.
This
is
the
back
end
of
the
the
problem
that
we
are
facing
and
now
we
will
dive
dive
in
deep
how
we
went
in
with
solving
it.
A
So
we've
got
the
svm,
which
is
basically
using
wasmer
and
extending
it
without
functionality
and
adhering
to
the
protocol
of
the
space
mesh
a
full
node,
and
this
is
fine,
but
we
need
to
be
able
to
produce
some
web
assembly
and
it's
not
really
rational,
to
expect
people
to
write
webassembly
manually
right.
So
we
need
to
have
some
platform
to
be
able
to
that
will
enable
us
to
write
smart
contracts
in
our
platform
that
will
compile
to
a
web
assembly
and
this
web
assembly.
A
We
want
it
to
be
a
compliant
with
the
fixed
gas
where
then,
what
it
entails.
I
will
expand
not
in
in
not
in
this
slide,
but
it's
important
to
to
stress
this.
This
is
not
just
a
general
web
assembly.
It's
not
only
a
web
assembly
that
needs
to
to
be
to
know
what
to
talk
with
the
svmos.
A
It's
also
web
assembly
that
we'll
have
restrictions
that
will
enable
us
to
give
the
fixed
gas
estimation
effects
guys
yeah,
sorry
template
so
in
in
as
in
space
mesh,
we
don't
use
the
term
smart
contract,
we
use
the
term
the
term
template
template
is
is
a
a
program.
Yeah.
A
Writing
and
the
what's
unique
in
having
a
template
is
that
once
you
deploy
a
template
to
the
to
the
mesh
yeah,
which
is
like
we
don't
have
a
chain
as
a
reminder,
we
call
it
on
the
mesh,
but
you
get
ideas
so
once
we
deploy
the
template,
we
would
like
to
be
able
to
reuse
it.
Why?
Because
we
don't
want
to
to
find
ourselves
deploying
the
same
code
over
and
over
again,
which
will
bloat
the
the
mesh.
A
So
smart
contract
is
basically
named
the
template
and
the
way
to
develop
a
template.
Right
now
is
using
the
svm
sdk,
and
it's
also
it's
like
a
ras
dsl.
It
is
leveraging
the
last
procedural
macros
and
if
you
will
go
to
the
github,
you
can
see
a
couple
of
sdk
dash
some
world
and
the
primary
crate
is
called
sdk.
It
is
the
root
one
that
assembles
everything
into
one
crate
and
this
cold
and
can
also
be
compiled,
of
course,
to
other.
A
So
this
is
how
we
creating
programs
that
can
be
deployed
to
the
to
the
space
mesh
platform.
Now,
let's
talk
about
the
pipeline
of
the
compilation:
okay,
a
very
high
level,
so
we
start
with
creating
a
program
in
rust.
We
are
using
the
rasters
vm,
the
svm
sdk,
which
is
a
rust
card
and
it's
using
the
procedural
macros
and
then
the
compiler
expands
this
rast
code
and
I've
skipped
here
tons
of
stages
that
are
internal
to
the
rust
sequence.
A
There
was
compiler
and
at
some
stage
the
compiler
after
doing
all
its
type
checking
verific
and
reducing
the
syntax
tree
and
and
the
checking
the
bar
that
everything
is
valid,
like
the
bowel
checking,
bowel
rules
and
anything
else
related.
We
get
to
a
point
that
we
have
some
llvm
intermediate
representation
and
luckily
one
of
the
back
ends
of
the
llvm
is
towards
them.
A
Now
again,
we
cannot
allow
ourselves
to
output
any
general
wasm,
because
we
want
to
deal
with
the
halting
problem
and
we
are
okay
with
not
with
being
non
new,
a
non
q
and
complete.
So
what
we
basically
want
us
to
reach
the
fixed
guys
wasn't
and
the
the
way
to
to
to
achieve
it
is
to
say
okay,
indeed,
in
this
stage,
going
from
there
from
the
svm
sdk
to
the
expanded
code.
A
Let's
talk
about
what
we
would
like
such
a
weber,
selling
what
it
means
to
everything
this
guy
was
and
what
are
the
restrictions
that
we
want
to
this
wasn't
web.
A
So,
first
of
all,
we
cannot
have
loops
right,
so
we
cannot
have,
for
example,
writing,
say
according
the
rust
sdk,
it
cannot
contain
any
for
loops
or
while
loops
cannot
have
any
loops.
A
The
second
one
is
also
we
cannot
have
a
function
called
calling
itself
cannot
have
the
questions,
but
we
can
not
also
live
with
having
a
function,
a
calling
another
function
b
and
then
calling
an
another
function
c,
which
we'll
call
again
function
a
which
started
the
call
process,
the
the
course
the
call
chain,
because
it
means
that
we
still
introduced
a
loop
to
the
program.
Okay.
A
The
last
one
says
that
we
cannot
have
any
polymorphism,
because
if
we
cannot
assert
in
compile
time,
what
will
be
the
target
of
the
function
being
called?
It
means
that,
if
a
calls,
if
we
have
some
function,
a
calling
some
b,
that
we
only
know
the
signature
of
it
and
then
b
calling
another
target
having
the
same
signature,
which
might
be
that
b
is
calling
itself,
for
example.
So
we
cannot
afford
having
polymorphism.
A
So
this
is
the
high
level
the
requirements
for
the
fixed
gasoline.
Now,
let's
talk
about
what
it
means
in
practice
to
in
to
have
such
a
fix
to
a
gas
wasn't.
So
if
we
don't
want
to
have
loops
the
way
to
to
translate
it
into
the
wasm
world
is
to
say
we
cannot
afford
having
the
loophole
code.
Okay,
we
just
need
to
make
sure
that
it
will
not
exist.
A
The
second
one
and
the
third
one
basically
translate
that
we
need
to
make
sure
that
function
cannot
call
itself
for
the
the
cycle
that
I've
explained
and
the
way
to
to
check
that.
It's
also,
by
doing
some
validation
like
validating
that
the
loop
op
code
does
not
exist
and
for
polymorphism
also,
we
need
to
make
sure
that
the
call
in
direct
opcode
is
not
there.
A
A
A
recap:
we've
talked
about
life,
we've
talked
about
software.
We
have
decided
that
we
are
okay
with
not
being
fully
tuned
complete.
We
want
to
give
a
better
gas
estimation,
which
means
a
better
user
experience
to
the
end
user,
and
it
means
that
the
the
the
contracts
being
deployed
in
our
terminology
of
space
message.
A
It
is
the
templates
we
want
the
template
being
compiled
to
us
and
to
be
office
to
be
a
conform
to
the
fixed
guys
rules
that
I've
outlined
in
and
now
let's
talk
how
to
make
sure
that
we
can
really
achieve
that.
Okay,
so
in
how
can
we
really
enforce
the
the
the
code
of
the
compiler
to
to
add
you
to
this
loop
to
these
rules?
Okay,
so.
A
First
of
all,
which
is
basically
something
that
I
guess
any
of
us
programmer
in
the
in
the
audience
probably
probably
has
already
thought
about.
We
will
omit
using
this
standard
library
of
rust.
This
is
one
of
the
strengths
of
rust,
because
it's
super
flexible.
So,
even
though
rust
has
a
standard,
trouble
is
shaping
out
of
the
box.
It's
we
can
decide
that
we
don't
use
want
to
use
it.
A
So
it
means
that,
since
we
cannot
use,
for
example,
a
vector
or
of
of
the
standard
library,
or
we
cannot
even
use
surprisingly
the
result,
type
or
the
option
type,
we
need
to
come
with
our
own
similar
solutions
that
will,
and
that
will
eventually
compile
to
the
wasm
that
we
want.
The
third
one
is
also
very
nice.
I
will
expand
on
it
in
think
it
will
be
the
next
slide.
A
It
is
the
customer
locator
so
similarly
to
the
to
the
way
that
each
programming
last
starts
with
standard
library
imported
in
and
we
can
start
decide
to
discard
it
to
omit
it.
The
same
for
the
locator.
There
is
the
default
allocator
of
first
and
request,
and
we
can
swap
it
with
our
own
implementation,
and
this
is
one
of
the
very
cool
things
that
we
are
doing
and
once
we
have
got
this
free,
it
means
we
have
full
control
over
the
allocation.
So
we
have
full
control
over
the
std
because
we
are
not
using
lcd.
A
We
are
using
our
own
crafted
micro
std.
What
we
are
left
with
is
doing
iterations.
We
need
to
do
a
trial
and
error
process.
We
write
some
code,
we
compile
it
to
asm
right,
there
was
wasn't.
Binary
then
is
a
transformed
into
was
some
textual
representation
to
which
is
lispy-like,
which
is
very
very
handy.
A
Then
we
inspect
it
into
some
text,
editor
in
the
ide
and
if
we
stumble
upon
some
piece
of
a
chord
that
still
is
using,
for
example,
a
loop
or
a
the
calling
direct
or
a
quotient,
or
something
like
that,
we
need
to
think
what
we
need
to
rewrite
and
how
to
close
the
gap
until
eventually,
after
the
couple
of
a
lot
of
iterations,
we
will
reach
a
point
that
we
know
that
the
solution
we've
got
is
good
for
us.
A
Okay,
and
it's
not
a
something
that
we
can
can
say.
We
will
sorry
it's
not
something
that
is
easy
to
know
without
doing
this
trial
and
error,
because
it's
a
lot
of
experimental
work.
It
requires
a
lot
of
patience
and
it
means
that
each
time
in
the
future
that
we
will
have
to-
or
we
will
need
to
add
another
feature
of
rust
to
our
templates
implementation-
it
will
be
an
opportunity
to
or
like
there
is
change
that
we
will
have
to
come
up
with
new
solutions,
for
that
will
extend
the
micro
ssd.
A
So
it's
we,
this
microsd
involvement.
Is
it
basically
relies
on
the
what
we
will
need
in
order
to
implement
the
future
templates,
but
even
though
even
right
now,
it
contains
pretty
much
a
lot
of
functionality,
but
it's
likely
that
things
will
change
and
that
new
types
will
be
added.
So
a
few
examples.
So
in
the
micro
std,
we've
got
a
vector
implementation,
which
is
not
a
resizable
one
right
right.
We
cannot
have
any
logic
that
we
don't
know
ahead
of
time.
A
It's
a
maximum
size
and
option
types,
results,
types
and
a
couple
of
others,
and
the
one
of
the
disadvantages
of
this
solution
is
that
the
output,
one
of
them
will
be
much
bigger
because
once
you
are
not
using
loop
and
we
have,
we
are
using
a
lot
of
loop
and
rolling
techniques
in
the
code
which
translate
and
compile
them
to
a
lot
of
repetitive
code
is
that
okay,
the
code
of
the
wasm
will
be
bigger,
but,
as
I've
explained
here,
templates
for
the
rescue,
so
templates
are
a
citizen
in
space
machine
that
is
supposed
to
to
to
be
in
relatively
aware
like
for
each
account
in
the
system
for
which
a
template
in
the
system
there
will
be
tons
of
accounts
spawned
out
of
it.
A
A
But
well,
it's
not
really
an
issue
just
saying
that
this
is
another
example
of
a
trade-off.
So
this
is
a
very
level
overview
of
what
it
means
to
create
to
develop
this
sdk.
A
Each
time
the
program
needs
some
ip
memory,
it
needs
to
like
do
a
knock,
knock
on
the
door
and
ask
the
in
our
case
it's
the
host
of
the,
because
we
are
running
in
wazam
in
sandbox.
It
is
so
it's
like
the
operating
system.
It
is
asking
for
some
amount
of
memory.
A
We
cannot
use,
of
course,
malloc
or
anything
that
is
to
a
that
might
contain
loops
and
some
some
significant
computation
and
the
solution
that
we
end
up
with.
Is
that
saying?
Okay,
we
know
that
we
don't
have
loops.
This
is
the
assumption
that
we
start
with
and
because
we
don't
have
loops,
it's
very
easy
for
us
to
know
ahead
of
time
how
much
memory
will
be
enough
for
us
in
any
case?
A
Okay,
if
you
want
another
different
explanation,
I
think
it
will
be
more
obvious
by
the
end
of
this
talk,
because
I
will
talk
about
gas
estimation
in
depth
later,
but
basically
it
means
that
we
can
reserve
in
one
time
the
the
maximum
amount
of
memory
that
we
will
ever
need.
A
Thanks
to
the
fact
that
we
don't
have
loops-
and
it
leaves
us
with
doing
a
very,
very
simple
allocation
logic,
it
means
that
each
time
that
a
program
is
running
okay,
this
is
the
this
is
the
program
in
orange
and
the
the
purple
is
the
the
webassembly
runtime
the
svm.
So
each
time
the
program
needs
some
amount
of
some
amount
of
memory
it
knocks
on
the
door
of
the
host.
A
Okay
and
the
host
will
use
the
memory
address
of
the
instance,
and
it
will
just
do
an
offset
bump.
It
will
increase
the
offset
from
all
to
new
and
it
will
always
take
the
same
amount
of
time,
because
it's
only
incrementation
of
the
counter,
so
it
means
we
can
say
that
each
allocation
takes
really
the
same
amount
of
time.
Okay,
we
only
need
to
take
into
account
the
fact
that
we,
once
in
the
beginning
in
the
boot
process,
allocate
a
one-time
memory
and
that's
it.
A
We
don't
care
about
how
much
we
want
in
the
each
future
request.
It
will
always
be
priced
the
same
so
and
for
those
of
you
we
who
might
not
know
there,
is
some
trade
in
rust
that
we,
you
can
implement
your
own
customer
locator,
and
then
you
can
call
it
the
global
allocator
and
in
the
end,
in
the
implementation
of
the
alloc
method
of
this
right.
A
It
basically
just
calls
the
host
a
extern
c
limitation
which,
when
compiled
to
azam,
it
is
transformed
into
a
calling,
an
important
function
and
this
and
then
and
in
the
host.
This
counterincrementation
takes
place.
Okay,.
A
A
So
what
we
are
doing
is
we
are
scanning
in
one
time,
scan
linear
scan
of
the
of
the
call
and
we
are
building
while
we
ask,
while
we
are
passing
the
the
code,
a
call
graph,
it
means
that
each
time
that
we
that
we
are
inside
a
function,
let's
call
it
a
function,
a
each
time
inside
function,
a
we
are
saying,
a
call
to
another
function,
function
b
and
remember:
we
assume
we
are
not
using
polymorphism.
A
It
means
that
we
really
know
that
fb,
we
know
exactly
what
is
the
index
of
the
function
in
wasm?
It's
not
that
we
treat
it
as
something
that
we
will
defer
only
to
the
run
time
and
it
might
a
being
theory
a
recursive
call.
We
know
what
dev
b
is
exactly
in
runtime
by
doing
static
analysis.
A
Okay,
so
we
are
building
this
call
graph,
but
each
time
inside
functionality
calling
function
b,
we
draw
an
edge
between
these
two
nodes
and
while
we
are
building
the
call
graph
as
we
go,
if
we
for
some
reason
encounter
one
of
these
op
codes,
which
are
not
allowed,
we
all
the
process
and
terminate
and
say
that.
Okay,
the
validation
fails
and
later
once
we've
got
the
function
called
the
call
graph.
We
need
to
look
for
loops,
but
not
the
loops
of
code
but
loops
the
self
loops,
like
precautions
and
the
call
cycles.
A
A
So
there
was
a
very
nice
and
easy
and
in
denial,
complexity,
algorithm
called
topological
salt,
and
it
means
that
if
there
is
some
order
might
be
more
than
one.
But
if
there
exists
a
model
such
that
a
is
calling
b,
it's
calling
c
we
will
find
it
okay
and
if,
for
some
reason
the
graph
call
graph
contains
a
loop,
we
will
find
it
as
we
go
and
we
will
out
alt
the
process
and
okay.
A
So
this
is
the
validation
of
the
the
the
fixed
voltage
and
now
comes
the
I
think,
the
most
fun
part
and
the
most
interesting
part
is
how
to
do
the
gauze
estimation.
Okay,
so
again,
we've
got
it
was
we
have
compiled
it
for
using
our
sdk.
A
We
have
been
good
people,
so
we
have
deployed
it.
We
have
passed
the
validation
and
we
have
deployed
it
on
the
mesh
okay
again
on
mesh.
It
says,
because
we
have
a
machine
not
a
chain,
and
now
we
are
left
with
pricing
we
again
because
the
the
lecture
started
with
saying
that
we
want
to
emphasize
the
user
experience.
A
We
want
to
give
some
vlog
before
dispatching
the
transaction
that
if
he
will
pay
10
units
of
gas,
if
for
sure,
we'll
be
able
to
pay
for
its
transaction,
there
will
now
be
a
case
that
the
transaction
will
reach
out
of
gaz
without
terminating
the
logic
and
then
which
will,
which
means
that
bob
will
be
said
because
it
just
got
a
penalty
and
and
and
no
turns
no
successful
execution
of
transaction.
A
This
is
the
the
end
game.
Okay,
we,
this
is
the
goal
we
want
to
to
make
bob,
which
is
not
a
tech
savvy
person.
He
has
nothing
to
do
with
crypto.
He
doesn't
know
what,
for
him,
russ
is
like
a
metal.
Okay,
he
doesn't
care
about
cr
about
blockchain.
You
just
want
to
get
to
use
our
application
without
knowing
anything
like
magic,
transparently,
okay,
so
the
way
to
to
be
able
to
address
this
need
of
estimation
goes
like
this.
A
We've
got
a
wasm
and
then
we
are
using
a
technique
that
is
a
commonly
used
inside
the
compilation
compile
as
well.
It's
called
the
control
flow
graph
in
the
control
flow
graph.
Each
node
in
this
graph
is
named
the
basic
block
and
it
is
a
consecutive
series
of
instructions
that
do
not
contain
a
jump.
So
in
webassembly
we
have
a
couple
of
jumps
couple
of
branching
objects.
A
It
means
that
if
we
are
starting
to
scan
the
code
as
long
as
we
are
not
reaching
any
branch,
a
branch
a
instruction,
we
are
good
the
first
time
that
we
reach
one.
We
need
to
close
the
node
and
create
a
new
one
and
and
create
an
edge
between
these
two
okay,
so
the
cfc,
the
control
flow
of
cfg
edges,
represent
the
jumps
and
and
I've
also
added
something
that
I've
named
it
continuations.
A
A
I
mean
it's
not
exactly
one-to-one
mapping,
because
it
might
be
that
there
are
some
pep
that
will
never
be
be
able
to
execute
in
real
life,
but
any
possible
execution
could
be
also
modeled
using
this
cfg
okay,
so
we
are
covered
and
in
web
in
one
them
each
function,
it's
it's
it's
his
own
entity.
So
what
we
are
doing
is
we
build
a
control
flower
for
each
function,
which
wasn't
function
and
we
are
pricing
each
function
in
isolation.
A
A
If
a
is
calling
b,
we
will
first
estimate
function
b
and
then
only
then
we
will
estimate
function
a
and
when
we
will
reach
the
instruction
inside
function,
a
that
says
call
function
b.
We
by
that
point
in
time
we
will
know
already
what
is
the
price
of
the
function
b?
Okay
and
because
we
don't
have
loops
and-
and
we
have
a
dog
direct,
a
cyclic
graph.
It
means
that
there
is
a
a
solution
and
we
can
price
each
function.
A
Okay,
but
before
talking
about
the
all
program,
pricing
not
only
function,
let's
focus
on
a
couple
of
examples.
Each
one
each
example
will
show
you
a
couple
of
lines
of
web
assembly
code
in
textual
textual
representation,
and
then
we
will
see
a
what
this
corresponding
cfg
looks
like
behind
the
scene.
Okay.
So
this
is
the
first
example.
This
is
the
very,
very
simplest
one.
A
A
No,
the
number
zero,
which
is
the
style
for
everything.
So
there
is
no
in-going
edge
to
to
node
number
zero
and
it
will
be
always
an
empty
node.
So
this
is
why
I
have
another
edge
of
type
continuation
which
will
take
us
to
the
second
node
node.
We
in
a
I
will
find
d1
and
it,
and
it
will
contain
these
two
instructions.
A
A
So
this
example
wants
to
to
to
deliver
a
point
in
wazam
we
can
introduce
a
as
many
a
lot
of
scopes
by
using
the
block
keyword.
So
here
we've
got
three
nested
blocks,
but
from
the
point
of
view
of
the
cfg,
we
don't
care.
It's
like
saying:
we've
got
one
block,
okay,
so
this
and
it
would.
This
nesting
has
no
effect
to
of
the
the
way
we
are
building
the
cfg.
A
Okay.
Now
why
it
is
important,
it's
I
think
it's
important.
I
will
give
something.
That
seems
like
a
good
example,
because
we
don't
want
people
to
try
to
manually
create
some
wiseams
with
tons
of
nesting,
which
will
make
our
svm
work
harder,
similar
to
the
jit
bombs
that
people
always
mention.
We
are
talking
about
compiling
the
wasm
in
smart
contracts
platform
and
why
they
are
using
a
single
pass
compiler.
A
So
this
is
very
similar,
so
this
algorithm
of
building
the
cfg
is
actually
also
linear.
We
can
also
do
it
in
a
single
person.
This
is
the
way
it
is
implemented.
If
you
are
curious
about
the
way
it
is
well,
it
works.
There
is
a
crate
called
svmgaz
under
the
projectors
vm.
The
name
under
the
name
of
the
doctor
is
just
simply
gaz
and,
as
you
can
see,
it
is
single
pass
implementation,
algorithm,
okay,
now,
the
third,
the
third
example:
this
one
contains
a
branch
instruction.
This
is
a
an
unconditional
branch.
A
It
means
that,
each
time
that
we
reach
this
instruction,
we
will
always
jump
to
the
right
after
this
scope
so
because
this
is
zero.
So
it
means
that
we
need
to
finish
this
current
block
and
move
right
here.
So
this
line
of
this
line
will
never
get
to
execute.
Never.
Okay.
So
again,
we've
got
your
block.
A
A
These
two
instructions,
and
because
we
are
hitting
here
a
branch
we
close
this
node
and
we
create
a
new,
a
node
and
we
draw
an
edge
of
a
jump
now,
as
you
can
see,
because
as
I've
said
this
one,
this
instruction
is
is
unreachable.
A
It
means
that
in
our
cfg
graph
this
node
will
be
unreachable
and
later
we
will
just
ignore
it
or
prune
it
when
we
will
want
to
go
to
the
next
steps
for
doing
the
actual
final
estimation,
the
computation,
but
while
building
this
while
implementing
this
algorithm,
it's
very
easy
to
to
start
with
this
implementation
and
just
keep
some
reachable
nodes
in
place.
Okay,
so
this
is
how
it
looks
like
it
means
that
once
we
are
here,
we
always
jump
to
this
node,
which
is
the
final
one.
A
Now
this
is
the
same
example
as
number
three,
but
in
this
time
the
conditional
is
the
the
the
branch
is
conditional.
Okay,
it
depends
on
the
value
fetched
and
the
value
of
the
top
of
the
stack
okay
from
what
is
what
we've
got
at
the
top
of
the
stack.
So
it
means
that
we
either
break
from
the
scope
and
again
continue
to
the
one
instruction
after
the
end
of
this
block
this
code,
or
we
continue
to
the
next
instruction.
A
Okay
and,
as
you
can
see,
there
is
only
one
end:
node,
okay,
always
so,
if
the
the
number
zero
always
exists
and
there's
no
incoming
edges,
the
last
one
always
exists
and
there's
no
outgoing
edges.
Okay,.
A
Now,
let's
talk
about
if
statements,
okay,
so
this
is
the
if
statement
without
an
else
block,
it
means
that
we
only
have
if
two
clause,
let's
see
how
it
looks
like,
and
here
I'm
drawing
the
other
types
of
edges
that
exist
primarily
for
a
debugging
and
the
explanations,
because
there
is
no
really
any
difference
between
having
these
two
types
of
areas
from
the
data
structure
perspective.
It's
mainly
for
us,
the
developers
to
reason
and
to
debug
of
things
that
are
happening.
A
So
if
you
will
look
at
the
code,
you
will
see
that
I'm
really
using
this
terminology
inside
the
code,
because
it
much
much
eases
the
way
to
debug
like
given
some
web
assembly.
What
is
the
corresponding
cmg
looks
like
so
under
this
diagram,
we've
got
continuation.
We've
got
this
statement,
then
we
have.
Then
we've
got
the
if
statement.
A
If
it
is
true,
we
are
executing
the
knob
instruction
and
then
we
proceed
after
the
end
of
the
of
the
on
true
block
to
the
next
or
in
this
case
there
is
no
really
else,
so
we
call
it
on
if
false,
because
there
is
no
else,
so
it
seems
like
sorry.
It
seemed
like
this:
if
the
local
gate
is
true,
then
we
are
executing
this
note
and
then
after
we
are
finished
with
the
knob,
we
jump
right
here
and
if
the
local
get
it's
falsely,
then
again
we
jump
again
right
here.
A
So
it's
this
point
is
basically
the
same
as
saying
number
three.
Okay,
so
I
hope
that
intuitively
you
understand
it
seems.
I
hope
that
it
seems
intuitive
until
you
get
the
idea
in
high
level
and
last
last
example
is
again
an
if
statement,
but
this
time
with
an
else
block.
If
the,
if
statement
is
truthy,
we
push
seven
to
the
stack,
otherwise
we
push
eight
and
after
we
are
executing
this
instruction,
we
have
to
jump
right
after
the
if
statement.
A
Similarly,
if
it's
falsy
we
need
to
if
it
to
execute
the
else
block,
we
need
to
execute
the
this
statement
and
then
jump
again
to
this
point.
So
this
point
that
both
execute
eventually-
and
this
is
the
final
node-
is
node
number
zero.
Again,
we
start
from
number
four
sorry.
So
when
we
start
with
zero,
we
exec
we
push
to
the
start,
the
local,
the
variable
local
variable
zero,
and
then
we
ask
if
the
statement
is
true
free.
We
execute
this.
A
A
We
know
that
the
order
measures,
because
we
need
to
be
aware
to
the
topological
sort
order,
so
we
first
start
with
nodes
that
sorry.
So
if
a
calls
b,
we
first
build
the
cfg
for
b
and
only
then
for
a
and
we've
got
only
one
part
to
discuss
about
okay.
So
how
we
take
this
a
control
flow
graph,
and
now
we
can
produce
our
a
number
that
will
stand
for
the
gas
price.
A
A
Once
we've
got
the
cfg
remember:
we've
got
the
start,
node,
which
is
always
number
zero,
and
we've
got
always
the
some
end,
node,
which
its
exact
number
depends
on
the
the
code.
But
we
know
that
we
have
exactly
one
such
end,
node,
that
we
know
that
it
is
that
it
is
there
and
between
the
start
and
end,
we
need
to
find
the
the
path
that
will
give
us
the
maximum
weight.
A
So
each
node
inside
inside
the
cfg
will
get
some
some
weight
some
number
and
after
we
will
twice
the
each
node,
we
will
run
an
algorithm
that
will
find
the
maximal
weighted
path,
and
this
will
be
the
the
number
that
we
will
use
for
our
fixed
gas.
It
means
that,
no
matter
what
our
algorithm
will
want,
no
matter
what
in
what
case,
we
will
know
that
this
max
this
max
a
weighted
path,
which
is
the
fixed
gas,
will
be
for
sure
enough
for
us
now.
A
Let's
signal
the
the
user,
that
this
is
the
vodka,
the
worst
case
and
and
and
and
the
and
the
eventually
implement
something
that
will
like
use
some
gas
metering
and
then
give
him
a
refund
back
in
the
end
right
now,
we
are
not
doing
that
again
talking
about
trade-offs.
A
The
plus
is
that
the
person
can
say:
okay,
I
will
get
a
refund,
but
the
the
only
one,
and
then
you
introduce
gas
metering,
which
also
is
some
some
over
it.
Okay,
no,
it's
only
not
only
about
running
time.
It's
also
about
you
know,
maintenance
of
a
software,
but
we
could
we
could
so
what
we've
got
right
now
is
that
once
we've
got
the
maximum
path,
this
is
the
fixed
guide,
and
this
is
what
each
transaction
will
pay
for.
A
given
function:
okay
and.
A
How
do
you?
How
do
we
price
the
node?
You
know
this
is
the
collection
of
instructions.
If
it's
function,
it's
it's.
It
contains
the
webassembly
op
code.
Oh
a
call
to
the
host
yeah
using
the
input
function,
each
op
code
will
have
a
fixed
price
and
each
import
function
will
also
have
a
fixed
price,
and
this
is
the
reason
why
our
os
functions
of
svm
currently
are
very
basic,
because
we
want
to
be
able
to
give
a
fixed
price
to
each
import
and
it
plays
nicely
even
with
the
allocation.
A
If
you
remember,
the
teacher
location
takes
exactly
the
same
amount
of
work
because
it's
only
an
offset
bump.
So
even
in
that
case,
even
for
location,
we've
managed
to
to
find
a
think,
an
elegant
solution
and,
let's
see
how
it
looks
like
so,
we've
got
here
the
table
that
for
each
op
code,
will
give
us
its
price.
Some
of
the
price
are
not
relevant,
for
example
the
if
and
else
there
they
they
there
will
be.
No.
A
If
opcode
inside
the
node,
the
the
these
are
codes
like
if
and
else
and
the
branching
they
changed.
The
way
the
cfg
looked
like
the
topography,
the
the
way
the
graph
would
look
like,
but
there
will
be
never
any
else
of
cody
or
a4
branch,
okay.
So
this
is
why
there
is
a
not
available
value
here,
and
this
is
a
again
then
example,
number
six
that
we've
seen.
No
sorry
it's
it's
a
bit
different
in
number
six.
We
did.
We
only
had
a
single
statement,
never
mind
it's,
but
it's
very
similar.
A
So
if
the
if
statement
is
true
field,
then
we
execute
it's
a
bit
tiny,
but
it's
the
const
seven
and
the
knob,
and
otherwise
the
const
18
calls
a9,
and
here
we've
got
the
pricing
for
each
up
card.
So
what
we
are
doing
again,
you
see
I'm
taking
each
node
and
I'm
pricing
it.
Okay,
it's
very
easy,
just
looping
over
the
instructions
and
and
grabbing
the
associated
the
upgrade
price.
By
using
this
table,
and
once
we've
got
this
cfg
and
with
each
node
being
priced,
we
need
to
find
the
maximum
path.
A
So
in
this
case
there
are
only
two
plus.
So
it's
very
easy.
It's
very
nice.
One
path
is
to
say
that
we
are
going
this.
The
left,
the
left
path
and
the
other
one
is
to
take
the
right
path
and,
as
you
can
see
here,
we
pay
30,
20,
plus
10,
and
here
it's
20,
plus
20,
so
the
maximum
weighted
path
is
this
one?
Okay,
so
this
is
the
winner
and
40
will
be
the
price
that
we
will
pay
for
this
function
and
always
in
order
to
find
a
the
maximum
weighted
path.
A
It's
it's
also
done
in
linear
time.
It's
very
easy
to
see
why?
Because
we've
got
your
dag,
it's
a
similar
a
bit
to
the
way
we
are
doing
the
topological.
Sorting
again,
you
can
view
the
code
under
the
svm
repo
under
the
svm
guys
crate
under
which
is
the
guys
folder
and
so
okay,
so
we
have
got
for
it
functioning
first
and
sorry,
so,
once
we've
got
for
which
function
its
price,
it
means
that
when
you
execute
a
transaction,
the
transaction
wants
to
call
a
function.
A
We
need
to
take
into
account
a
couple
of
other
variables,
like
the
the
byte
size
of
the
transaction,
the
cost
of
the
of
allocating
the
memory
once
upfront
when
the
instance
of
the
wasm
is
being
booted,
maybe
a
couple
of
other
things,
but
in
the
end
of
the
day,
it's
something
that
we
can
do
very
very
efficiently,
and
not
only
that
we
can
catch
this
logic.
So
I
mean
this
cfg
building
its
pricing,
for
which
function
can
be
cached.
A
There
is
no
need
to
we
compute
it
for
each
transaction,
okay,
because
we
will
always
get
the
same
result.
It
is
in.
It
is
agnostic
to
the
state
of
the
the
node
and
the
other
parts
that
are
and
that
might
change
between
two
transactions
are
the
maybe
the
bytes
of
the
input
or
things
like
that,
but
again
it's
just
taking
another
variable
and
then
adding
it
to
a
counter
to
a
value
that
is
cached.
So
it's
very
easy.
A
Okay,
so
recap:
we
started
to
talk
about
the
trade-offs
and
the
as
we
have
as
I've
explained
in
it's
in
space
mesh
and
in
sm
in
particular,
we've
decided
to
put
the
emphasize
on
the
fixed
guys
we
want
to
to
to
give
the
best
user
experience
to
the
users
that
will
use
our
system.
A
Our
platform
we
target
the
target
audience
is
virtually
every
person
that
has
a
machine,
not
only
very
technical
people,
and
once
we
have
took
took
it
was
once
we
have
taken
this
decision,
the
implied
the
side
effects
of
it
were
that
we
need
to
be
able
to
introduce
constraints.
A
It
means
that
we
will
not
stay
tuned
complete.
It
means
that
it's
okay
for
us
to
to
not
to
support
any
kind
of
program.
It
means
in
very
level
that
we
don't
allow
any
sort
of
loops,
no
direct
or
indirect.
No
local
cycles,
no
equations
enough.
Nothing,
and
it
means
that
there
are
things
that
we
will
not
be
able
to
support
with
this,
but
each
program
that
can
be
transl
modeled
as
a
state
machine
without
groups
could
be
probably.
A
Find
a
solution
in
our
platform
eventually,
and
even
if
it's
not
now
so
probably
in
the
future,
as
we
continue
adding
more
capabilities
and
features
to
the
platform,
and
once
we
have
taken
the
decision-
and
we
said
okay,
this
is
the
one
this
is.
This
is
the
restrictions
that
we
require
from
it.
We
need
to
specify
what
they
are
and
we
have
done
it
and
we've
called
it
the
fixed
guys,
and
then
we
found
a
solution:
how
to
really
make
it
practical
and
not
only
on
the
whiteboard.
A
So
we
have
a
svm
decade
that
we
know
that
emits
called
code.
It
wasn't
that
is
fixed
gas
and
once
we've
got
fixed
as
well
was
them
we
need
to
be
able
to
first
validate
it,
and
if
it
is
valid,
we
need
to
be
able
to
price
each
function,
and
this
will
be
the
value
that
will
be
used
for
the
gauss
sent
inside
the
transaction
and
the
next
steps.
So
this
is
a
buzzword,
we
call
it
the
smash
lung.
It
means
that
we
could
decide
to
create
something
of
our
own
some
programming
language.
A
I
level
one.
It
could
be
take
something
that
exists
like
solidity,
for
example,
but
only
support
a
subset
of
it.
For
example,
we
cannot
support
lots
but
support
a
subset
of
it,
and
there
is
also
a
third
option
that
we
can
even
think
about
some
visualization,
some
application,
some
ui
that
will
serve
a
lot
of
people
in
some
very
cool
use
cases.
Some
applications
and
the
code
of
this
application
behind
the
scene
will
use
after
being
reduced
to
the
svm
sdk.
A
It
will
be
compiled
to
this
sdk
and
rust
and
then
transformed
into
the
fixed
gas
version.
It
means
that
we
can
see
the
svmsd
rust
as
the
informal
ast
of
our
platform,
from
which
we
can
in
fair
we've
got
a
solution
for
the
fixed
algorithm.
So
if
we
can
take
some
ast
and
reduce
it
into
the
svm
sdk
asd,
then
we
are
good
and
yeah
and
that's
it
I
think.
Thank
you.
I
hope
you
enjoyed
it
yeah,
that's
it.