Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: calls to revm with database in typescript #3182

Merged
merged 46 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3f6f425
WIP: NAPI bindings for REVM
Wodann Sep 6, 2022
b1f062f
WIP: thread-safe functions calls to JS/TS
Wodann Sep 9, 2022
105a838
WIP: EVM with layered database & debug API
Wodann Sep 11, 2022
426b086
WIP: implement call API and example for non-forking use case
Wodann Sep 12, 2022
4306f7d
Make basic call and basic create work
fvictorio Sep 13, 2022
662fe12
WIP: resolve hacks
Wodann Sep 13, 2022
c6d5472
chore(ci): add rethnet GitHub Actions workflow
Wodann Sep 15, 2022
4c85e10
feat: add Cargo Husky pre-commit hook
Wodann Sep 15, 2022
a50aced
feat: tool for generating Rust bindings for execution API
Wodann Sep 24, 2022
9929a8e
fix: Windows build
Wodann Sep 25, 2022
b974167
misc: add cargo gen-execution-api alias
Wodann Sep 25, 2022
a8362f8
refactor: delete rethnet_state
Wodann Sep 27, 2022
5c3757e
WIP: feat: integrate rethnet with hardhat-core
Wodann Sep 27, 2022
064305f
Merge remote-tracking branch 'upstream/main' into feat/rethnet-nodejs
Wodann Sep 29, 2022
0363dcc
feat: integrate rethnet with hardhat-core
Wodann Sep 30, 2022
368350e
bump: update revm from 2.0.0 to 2.1.0
Wodann Oct 3, 2022
8242b15
Merge remote-tracking branch 'upstream/rethnet/main' into feat/rethne…
Wodann Oct 3, 2022
3291da0
feat: add access list to Rethnet transactions
Wodann Oct 3, 2022
d3c211f
Use yarn workspaces to link rethnet-evm package
fvictorio Oct 4, 2022
4a9343a
refactor: split napi and native rust code
Wodann Oct 5, 2022
3d95ad2
feat: Rethnet with state management in JS
Wodann Oct 6, 2022
a740264
feat: checkpoint and revert API
Wodann Oct 6, 2022
c99c00f
Merge branch 'rethnet/main' into feat/rethnet-nodejs
fvictorio Oct 13, 2022
ef6d98e
fix: line endings on Windows
Wodann Oct 17, 2022
82b71a0
refactor: allow the client to support databases with a subset of Data…
Wodann Oct 13, 2022
389a4ea
fix: several hardhat core test failures
Wodann Oct 19, 2022
931d4e5
Add difficulty to BlockEnv
fvictorio Oct 21, 2022
d1a351a
Use rethnet in stack traces tests
fvictorio Oct 21, 2022
30e1e97
fix: EIP-3607
Wodann Oct 21, 2022
d53a01d
fix: block gas limit
Wodann Oct 21, 2022
de376a8
fix: eslint errors
Wodann Oct 22, 2022
7a2763c
fix: revert yarn.lock to yarn classic
Wodann Oct 24, 2022
d3525f6
refactor: move HardhatDB to hardhat-core
Wodann Oct 24, 2022
4a57398
Fix build
fvictorio Oct 25, 2022
8b3e2c0
Run prettier
fvictorio Oct 25, 2022
e0b6476
Use chai's assert instead of expect
fvictorio Oct 25, 2022
0df64f7
Use node's assert instead of chai
fvictorio Oct 25, 2022
ec1a80c
Run rethnet workflow in all PRs
fvictorio Oct 25, 2022
8b5b354
Add prebuild script that builds rethnet to hardhat-core
fvictorio Oct 25, 2022
a69fa87
Format rethnet-ci.yml
fvictorio Oct 25, 2022
d5b1aeb
Add prebuild script that builds rethnet to all packages
fvictorio Oct 26, 2022
88a68f0
Fix rethnet CI workflow
fvictorio Oct 26, 2022
f209804
Add prebuild script that builds rethnet to hh-solpp
fvictorio Oct 26, 2022
cad797d
doc: add Rust documentation
Wodann Oct 26, 2022
8c475da
fix: avoid mocha freeze at end of tests
Wodann Oct 26, 2022
7087f34
Merge branch 'rethnet/main' into feat/rethnet-nodejs
fvictorio Oct 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;