it was today I'm going to talk about
virtual machines woz I'm short for web
assembly but I'm not going to just talk
about web assembly and just give a
little overview of virtual machines all
together I think virtual machines are
pretty cool okay so forth um like really
the virtual machine is pretty core to
all of it so like what do we want from a
virtual machine architect right we want
to we want really good performance we
wanted to be close to the metal we don't
want a lot of abstraction between what I
virtual machine is doing what the real
hardware is doing yet we also want it to
be portable we wanted to run on many
devices so we still need a layer between
like x86 and made of assembly and our
virtual machine we also would like it to
be standardized right we don't we don't
need to recreate the real another really
nice thing would be to have like tool
chain compatibility it would be nice to
use llvm to the compile stuff to run on
Virtual Machine and lastly would be good
to have a clean and fairly simple
instruction set or is a
so yeah sorry x86 so to back up a little
bit a traditional or normal hardware we
have the execution environment a CPU
house like an execution environment has
been any parts but execution environment
and then it has a core where the ISA the
instructions actual opcodes get executed
it and the ISA is usually pretty simple
I mean it doesn't there's no instruction
for example to load something from the
hard drive the way that is handled is
you have physical addresses and they
write to memory and then your CPU just
reads from memory reads in right from
memory and that's the memory sections
are allocated you know a boot time for
the physical devices so we sort of have
an analogy to this novel arm so
traditional traditional CPUs they keep
it isolated the instruction set is
modular it doesn't necessarily it isn't
making the assumption about the
environment that is operating in right
it doesn't make assumption about what
kind of devices you have plugged into
your computer right no op codes for a
maps or whatnot so this is what this is
what etherium is current is a it looks
like so this would be the intrinsic set
we have memory operations system
operations so things that give us
information about the state of the
virtual machine
flow control and we have plenty of
integer operations and then going back
to the analogy of the traditional CPU
these opcodes would be like external
devices so I want to draw electro three
and gas call and precompiled now those
are some interesting and i'll talk to
talk to him about later but so like
block hash and code size and all these
things these are properties of an
external environment that need to go
into the virtual machine but through a
modular interface I'm necessarily having
the opcode form so the rationale putting
the call lock code in with the external
external operations that might not
necessarily be clear but our co-op code
is not is not like syscall like if you
ever done unix programming or something
you have a special just call to interact
with the OS our call our call is a
little bit different we can think of
etherium so gap has saying what it is
like the theorems like a singleton
virtual machine which is really nice but
the I think of it sort of like a
singleton hypervisor and each single
contract is its own vm or like its own
vm in the sense that it has its own
storage space it has its own its own
isolated environment that it works in so
going back calls like calls aren't
syscalls in traditional sense when
you're doing operating system Paul's
armel are like a vm talking to another
vm
um so I think it can be external okay uh
gasps so gas is a property of the
virtual machine and if you had pure
hardware that analog to gas would just
be you know clock cycles um so that
would be nice oh so but really found out
something really interesting actually
not all CPUs have clock cycles I anyways
there's actually it's not too relevant
here but there's actually some some CPUs
that are totally asynchronous so you
can't you can't seem that all hardware
has clock cycles and then lastly a
precompiled contracts they're a
necessary hack that we had to do right
because for performance um but if you
had a very performant virtual machine
and you didn't have to rewrite you no
chalk 3 and AH sha-256 and ec recovered
you could just compile it and run it on
the Virtual Machine you wouldn't need
the this pre-compiled contract so the
end result here is we have a stronger vm
we can also have a more consistent
interface so what would alternative you
know possible virtual machine look
architecture you look like so if you
want to look at hardware a really nice
one today is risk 5 so there's multiple
risk stands for reduced struction set so
um there's multiple variations of risk
and risk 5s I think one of the newest
ones that has a lot of momentum so yeah
so is a
it has open source open source it's open
source is a so the specification soca
music all the people developing it also
include an open source implementation
plement ations in it so the hardware is
the rocket Corps the implements is a so
it's just like little teen court and
then the whole CPU is there's one
implementation low risk so there's
multiple implementation stupid ones
called low risk and it uses the rocket
court so yeah so the good thing about
this is like it's really close to the
metal right is metal and it's
standardized that's great how's
toolchain pit batch ability you can
compile any C or C++ program and you can
matter fact just run linux on it it has
a very clean design and but the bad
thing is i mean if you wanted to
actually burn one of these things to
chip it's very expensive so you probably
wouldn't it published emulate it
development with it is fairly tricky it
wasn't necessarily designed it was
designed for hardware people wasn't
designed for software people if you're
not burning it to chip you're emulating
it you gotta have to modify it some and
wasn't really designed for that in mind
environmental info information so like
loading external devices like the
blockchain stuff there's no there's no
strict way or set path to do that it's
assuming you're loading stuff into
memory and then reading addresses from
memory or reading information from
memory and that's really unnecessary
because in etherium we're not plugging
in pulling out devices all the time so
there's really no point to have that
part
picture and lastly it's not necessarily
portable as once again notes yeah
designed for hardware so another
alternative might be web assembly the
basic idea behind web assembly is its
assembly for the web basically
JavaScript wasn't fast enough for
certain applications so people realize
that ok we need a little bit lower level
low level abstract than something really
high javascript so they came up with web
assembly actually first the history was
first they came up with a SI MJS from
Mozilla and which was a subset of
JavaScript that made it really easy for
interpreters to see sections of code in
tournament age it and then it was really
performant I was kind of ugly another
alternative from google was portable
bean apple which allows you to run
compile wildest in e c++ code and run it
in a safe virtual machine so that's the
sort of the predecessor to those with
sir the predecessor to web sembly and
the current version of web assembly is a
new is a that is designed to be pretty
ultra really fairly low-level portable
and fast and also safe for web browsers
strong it is a result of the
collaboration between Google Mozilla
Apple and Microsoft which Chris you know
we have doing all the major browsers and
replace it snap a line sometimes yes
another interesting thing about it is
even though it is fairly low-level it
does have some higher-level abstracts to
it so the instructions are specified
specify some AST abstract tree semantics
so for example functions modules
and has variables instead of registers
but it they're really interchangeable so
it's a registry-based we say variables
and it has it's really easy to represent
a national expressions which is commerce
so yeah okay three minutes of that so
you have some AST semantics which we're
going to skip the ISA in the instruction
set so structure set is pretty I mean
okay so what if people didn't sign an
instruction says for like a pretty long
time right now and they really haven't
changed for the past 50 years so no big
surprise in this director said right
it's a 8-bit bites two's complement in a
juror little ending is comes in two
variants 32 byte 64 byte bit variant so
why would web assembly possibly good for
using on a blockchain well it's built to
be performance it's built age it on
built to be jit it so at the right so
like it would came from JavaScript which
is like really hard and dynamic digit is
it's basically like a compliment to
something that is really dynamic but
really not so dynamic easy to it opcode
compression is built in compressions
like arm pretty pretty important on the
web when you're sending rights across
the wire so that's even more important
in a box chain it's portable you can
should be easy to run on many different
architects it already has llvm back end
meaning you can compile anything you
want to that lvm can compile to it and
target it this specification has a
pretty clear specification and they're
working on a formal specification when
okay
home and it's built to be run in a
hostile environment so what we do need
to change to modify web assembly to work
on a long hanging with him like
environment it needs to be fully just
deterministic so web similarity does a
pretty good job of isolating
non-deterministic behavior um so that
would be pretty easy to you all you have
to do is disable threads and a few
operations that uses approximations that
might be hardware-based you have to add
access to environmental information so
like getting the block half and getting
a different environmental information
from block chain and you'd have to add
me drink that's a pretty big one um so
yeah this is the environmental
information you'd have to add as i said
earlier web simply has the idea of
modules which makes it really nice to
add all this environment information in
since you could implement it as a module
good implemented in a module then that
would have different functions to query
the box chain state and that would that
model would hook into the action late of
code so there's a clean path of how to
embed this instruction set into external
environments so also know the big thing
is you need backwards compatibility and
it turns out trans piling evm code
Moslems pretty straightforward i like to
do in two different stages and is this
not complete project but what you do is
you would first translate it wazzle
in you would translate it to awesome
plus metering some metering code that
would run on a normal awesome machine
but if you modified was them so that you
had the metering built-in natively you
wouldn't do the final step so that's why
it's nice to have it compiled like that
and here's some images of how
transpiring looks but my time is up so
all right but thank you