onlydustxyz / imhotep Goto Github PK
View Code? Open in Web Editor NEWCairo EVM bytecode interpreter
License: MIT License
Cairo EVM bytecode interpreter
License: MIT License
Add the ability to parse the opcodes defined in the 20s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
Add the ability to parse the opcodes defined in the 30s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
Add the ability to parse the opcodes defined in the a0s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
Add the ability to parse the opcodes defined in the 80s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
Add the ability to parse the opcodes defined in the 0s
section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
EVM bytecode often starts with conditional jumps based on the function selector given as an input.
Since this is the beginning of the bytecode, we need to be able to execute it to test the rest of the opcodes implementations.
Have an in-memory program counter, passed to functions as an implicit argument. This counter is not incremented yet, this will be done when implementing the execution loop for the stack machine.
We also need to implement the JUMP
opcode that updates the program counter value.
JUMP
opcode, altered and returned thereThis is the first implementation of the EVM memory.
The goal is to be able to mimic a random-access memory, addressed by offset.
Have two internal functions corresponding to MSTORE
and MLOAD
. The store should take as an argument a value to store as well as an offset, the load function should take an offset to load from.
Don't use the stack implementation at this point unless #15 is done.
Add the ability to parse the opcodes defined in the f0s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
In order to code a stack machine, we need, well, a stack!
The way I see it is to have an in-memory object that gets passed as an implicit argument to opcode functions.
The goal is to implement the stack. For this, make it work with a simple opcode function, let's say the 01
addition opcode.
If the function is already present in the code thanks to #1, directly use it, otherwise create it it's no big deal.
I expect the implemented stack to be usable for more opcode functions than the addition, so don't just put 2 numbers in memory returning the sum :)
Do write some protostar unit tests for this, this is the real backbone for the whole project, we cannot afford bugs on this part.
Important: work with 32-bytes slots! And the max stack size is 1024 in the EVM.
Create a dict to map the different opcodes to functions so that they can be called when reading a contract bytecode.
Functions can then be called with from starkware.cairo.common.invoke import invoke
and from starkware.cairo.common.registers import get_label_location
Add some Github action workflows to run the tests and the build for every pull requests.
Add the ability to parse the opcodes defined in the 10s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
pc
points at the instruction currently being processed by the EVM, and is represented as a byte offset in the bytecode.
Have an internal function to read the current opcode at a given pc
value. Keep in mind that some opcodes are expressed on several bytes, because they hold a value alongside with the actual opcode value. PUSH1
is one of these for example.
pc
value and returns the opcode at the given offsetJUMPDEST
JUMPDEST
for example, and two bytes for PUSH1
Add the ability to parse the opcodes defined in the 40s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
This is the first implementation of the EVM storage.
The goal is to be able to store some data in a persistent storage.
Have two internal functions corresponding to SSTORE and SLOAD. The store should take as an argument a key and a value to store, the load function should take a key to load.
Don't use the stack implementation at this point unless #15 is done.
Add the ability to parse the opcodes defined in the 90s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
Add the ability to parse the opcodes defined in the 50s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
We want to be progressive with what the interpreter can execute. Luckily for us, EVM bytecode is split between different opcodes, we can then have a incremental support of these opcodes.
With all the first pieces of the interpreter put together, we will be able to start to execute some EVM bytecode. We need to prepare the first tests we will do: write some simplistic bytecode based on a very reduced set of opcodes. Namely JUMP
, ADD
, MSTORE
for example.
Add the ability to parse the opcodes defined in the 60s & 70s section of the yellow paper, in order to decode the instruction and call the correct function.
https://ethereum.github.io/yellowpaper/paper.pdf
https://ethereum.org/en/developers/docs/evm/opcodes/
Every Imhotep contract will embed an EVM bytecode interpreter. We need to have the bytecode stored somewhere in order to be able to execute it.
A first and naive approach is to store it in the contract itself, as a storage var. We provide the bytecode at construction time, and we store it.
A more advanced approach, out of the scope of this issue, would be to directly embed the EVM bytecode into the Starknet contract assembly, as if it was "hardcoded" on the Cairo code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.