Code Monkey home page Code Monkey logo

evm-from-scratch's Introduction

EVM From Scratch

EVM From Scratch

Welcome to EVM From Scratch! It's a 100% practical course that will help you better understand the inner workings of the Ethereum Virtual Machine. During this course, we'll implement EVM in your favorite programming language.

Getting Started

Clone the repo:

git clone https://github.com/w1nt3r-eth/evm-from-scratch

This repository contains evm.json file with more than 100 test cases. Your goal is to create an implementation in any programming language of your choice that passes all tests.

The test cases are organized by complexity: they start with the simplest opcodes and gradually progress to advanced. Each test case has a name, code and expectation. The code is provided as a human-readable instructions list (asm) and machine-readable bytecode encoded in hex (bin). Your implementation should only look at bin, the asm is provided to make unit tests easier to debug.

The repository contains templates for JavaScript, TypeScript, Python, Go and Rust. However, you don't have to use the existing templates, you can build your own test suite based on evm.json.

Credits

All the materials in the repository are made by w1nt3r.eth. The repository is part of the "EVM From Scratch" course (release date TBD).

evm-from-scratch's People

Contributors

arr4n avatar damianmarti avatar iainnash avatar karmacoma-eth avatar olawolu avatar olegakbarov avatar w1nt3r-eth avatar wp-lai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

evm-from-scratch's Issues

possible typo in SMOD (negative) test

The signed decimal value of 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8 is -8 right? why is it expected to convert to -10?

"asm": "PUSH32 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd\nPUSH32 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8\nSMOD",

RFC: Test cases for gas, ether transfers and state changes.

Hey w1nt3r,

First of all, thank you for the open sourcing this repo. The tests (and hints) have been very useful to me while building and testing Tiviem (Typescript EVM). I very recently passed all the test cases in this repo. However, I noticed that there are no test cases for testing gas, ether transfers, and state changes.

I am planning to write some tests to cover the above cases but I wanted to know if you have any plans / specifics about how to implement them.

My evm() function returns a Result object, as of now only success, stack, logs and returndata are tested against the expected values.

type Result = {
  success: boolean,
  stack: bigint[],
  memory: Uint8Array,
  gas: number,
  returndata: Uint8Array,
  logs: Log[],
  state: Map<bigint, AccountState>, // address -> AccountState
}

type AccountState = {
  balance: bigint,
  code?: {
    asm?: string,
    bin: Uint8Array
  },
  storage?: Map<bigint, bigint>,
  nonce: bigint
}

My plan I to compare test gas and state in a similar manner.

I just wanted to put this out there to thank you for open sourcing this repo and wanted some insight into if/how you plan on implementing the remaining tests.

Add the TLOAD and TSTORE opcode after Dencun upgrade

Dencun Hardfork of Ethereum that took place on 13 March, 2024 added 2 new opcodes in the EVM namely TLOAD and TSTORE.

The opcodes respectively load and store words from transient storage.

I'd like to work on adding these opcodes to the repository.

Question: about RETURNDATASIZE test case

image
In this testcase, the main contract called 0x10...c42 with retSize = 0. However the actual return size is 1, and in the expected result, the RETURNDATASIZE get result 1. I'm not sure if this obeys the evm rule.

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.