Skip to content

Commit

Permalink
feat: calls to revm with database in typescript (#3182)
Browse files Browse the repository at this point in the history
Co-authored-by: Franco Victorio <victorio.franco@gmail.com>
  • Loading branch information
Wodann and fvictorio committed Oct 30, 2022
1 parent 7027e82 commit 032640d
Show file tree
Hide file tree
Showing 65 changed files with 7,917 additions and 1,349 deletions.
2 changes: 2 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
gen-execution-api = "run --bin tools -- gen-execution-api"
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.sol linguist-language=Solidity
# prevent github actions to checkout files with crlf line endings
* -text
* text=auto
132 changes: 132 additions & 0 deletions .github/workflows/rethnet-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: rethnet CI

on:
push:
branches:
- $default-branch
- "rethnet/main"
paths:
- "config/**"
- "crates/**"
- "Cargo.toml"
- "rust-toolchain"
pull_request:
branches: ["**"]
paths:
- "config/**"
- "crates/**"
- "Cargo.toml"
- "rust-toolchain"

env:
RUSTFLAGS: -Dwarnings

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Rust (stable)
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true

- uses: Swatinem/rust-cache@v1

- name: Cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --all-targets

test-js:
name: Test Node.js
runs-on: ${{ matrix.os }}
needs: check
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macOS-latest"]
include:
- RUSTFLAGS: "-Dwarnings"
- os: "windows-latest"
RUSTFLAGS: "-Dwarnings -Ctarget-feature=+crt-static"
defaults:
run:
working-directory: crates/rethnet_evm_napi
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v2
with:
node-version: 14
cache: yarn

- name: Install node dependencies
run: yarn --frozen-lockfile

- name: Install Rust (stable)
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
components: rustfmt

- uses: Swatinem/rust-cache@v1

- name: Build
run: yarn build

- name: Test
run: yarn test

test-rs:
name: Test Rust
runs-on: ${{ matrix.os }}
needs: check
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macOS-latest"]
include:
- RUSTFLAGS: "-Dwarnings"
- os: "windows-latest"
RUSTFLAGS: "-Dwarnings -Ctarget-feature=+crt-static"
steps:
- uses: actions/checkout@v3

- name: Install Rust (stable)
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
components: rustfmt

- uses: Swatinem/rust-cache@v1

- name: Doctests
uses: actions-rs/cargo@v1
env:
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
with:
command: test
args: --doc --all-features

- name: Install latest nextest release
uses: taiki-e/install-action@nextest

- name: Test with latest nextest release
uses: actions-rs/cargo@v1
env:
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
CARGO_INCREMENTAL: ${{ matrix.CARGO_INCREMENTAL }}
with:
command: nextest
args: run --all-features
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[workspace]
members = [
"crates/*",
]
resolver = "2"

[profile.dev]
rpath = true

[profile.release]
rpath = true
49 changes: 49 additions & 0 deletions crates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Rethnet

[licence-badge]: https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue
[license]: COPYRIGHT

**Rethnet** is a debugging runtime for the Ethereum Virtual Machine (or EVM). It can be consumed as a Rust or as a Node.js native module.

## Building from Source

Make sure you have the following dependencies installed on your machine:

- [Rust](https://www.rust-lang.org/tools/install)

Rethnet is part of the [Hardhat monorepo](https://github.com/NomicFoundation/hardhat). Clone the source code using ssh:

```bash
git clone git@github.com:NomicFoundation/hardhat.git
```

or https:

```bash
git clone https://github.com/NomicFoundation/hardhat.git
```

Use `cargo` to build a release version:

```bash
cd hardhat
cargo build --release
```

## Building a Node.js native module

Make sure you have the following dependencies installed on your machine:

- [node.js](https://nodejs.org)

Use `npm` (or `yarn`) to build a release version:

```bash
cd crates/rethnet_evm_napi
npm run build
# yarn build
```

## Contributing

Rethnet is still under development by [Nomic Foundation](https://github.com/NomicFoundation/). As such, progress is being merged with the `rethnet/main` branch until its first release.
9 changes: 9 additions & 0 deletions crates/eth_execution_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "eth_execution_api"
version = "1.0.0-beta.1"
edition = "2021"

[dependencies]
derive_builder = { version = "0.11.2", default-features = false }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] }
14 changes: 14 additions & 0 deletions crates/eth_execution_api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
14 changes: 14 additions & 0 deletions crates/rethnet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "rethnet"
version = "0.1.0-dev"
edition = "2021"

[dependencies]
anyhow = "1.0.65"
clap = { version = "3.2.22", default-features = false, features = ["std", "derive"] }
pretty_env_logger = { version = "0.4.0", default-features = false }

[dev-dependencies.cargo-husky]
version = "1.5.0"
default-features = false
features = ["precommit-hook", "run-cargo-test", "run-cargo-fmt", "run-cargo-clippy", "run-for-all"]
46 changes: 46 additions & 0 deletions crates/rethnet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::ffi::OsString;

use clap::{Parser, Subcommand};

#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(subcommand)]
command: Command,
}

#[derive(Subcommand)]
#[allow(clippy::large_enum_variant)]
enum Command {
Start,
}

#[derive(Copy, Debug, Clone, PartialEq, Eq)]
pub enum ExitStatus {
Success,
Error,
}

impl From<bool> for ExitStatus {
fn from(value: bool) -> Self {
if value {
ExitStatus::Success
} else {
ExitStatus::Error
}
}
}

pub fn run_with_args<T, I>(args: I) -> Result<ExitStatus, anyhow::Error>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
let args = Args::parse_from(args);
match args.command {
Command::Start => {
println!("Hello, world!");
Ok(ExitStatus::Success)
}
}
}
13 changes: 13 additions & 0 deletions crates/rethnet/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use rethnet::{run_with_args, ExitStatus};

/// Main entry point for the `rethnet` executable.
fn main() -> anyhow::Result<()> {
pretty_env_logger::try_init()?;

let status = run_with_args(std::env::args_os()).unwrap();
match status {
ExitStatus::Success => (),
ExitStatus::Error => std::process::exit(1),
}
Ok(())
}
14 changes: 14 additions & 0 deletions crates/rethnet_evm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "rethnet_evm"
version = "0.1.0-dev"
edition = "2021"

[dependencies]
anyhow = { version = "1.0.64", default-features = false, features = ["std"] }
bytes = { version = "1.2.1", default-features = false }
hashbrown = { version = "0.12.3", default-features = false, features = ["serde"] }
log = { version = "0.4.17", default-features = false }
primitive-types = { version = "0.11.1", default-features = false, features = ["impl-serde"] }
revm = { git = "https://github.com/bluealloy/revm/", version = "2.1.0", default-features = false, features = ["dev", "k256", "with-serde"] }
sha3 = { version = "0.10.4", default-features = false }
tokio = { version = "1.21.2", default-features = false, features = ["sync"] }
1 change: 1 addition & 0 deletions crates/rethnet_evm/src/db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod layered_db;

0 comments on commit 032640d

Please sign in to comment.