Skip to content

Commit 032640d

Browse files
Wodannfvictorio
andauthored
feat: calls to revm with database in typescript (#3182)
Co-authored-by: Franco Victorio <[email protected]>
1 parent 7027e82 commit 032640d

File tree

65 files changed

+7917
-1349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+7917
-1349
lines changed

.cargo/config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[alias]
2+
gen-execution-api = "run --bin tools -- gen-execution-api"

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
*.sol linguist-language=Solidity
22
# prevent github actions to checkout files with crlf line endings
3-
* -text
3+
* text=auto

.github/workflows/rethnet-ci.yml

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: rethnet CI
2+
3+
on:
4+
push:
5+
branches:
6+
- $default-branch
7+
- "rethnet/main"
8+
paths:
9+
- "config/**"
10+
- "crates/**"
11+
- "Cargo.toml"
12+
- "rust-toolchain"
13+
pull_request:
14+
branches: ["**"]
15+
paths:
16+
- "config/**"
17+
- "crates/**"
18+
- "Cargo.toml"
19+
- "rust-toolchain"
20+
21+
env:
22+
RUSTFLAGS: -Dwarnings
23+
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.ref }}
26+
cancel-in-progress: true
27+
28+
jobs:
29+
check:
30+
name: Check
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v3
34+
35+
- name: Install Rust (stable)
36+
uses: actions-rs/toolchain@v1
37+
with:
38+
profile: minimal
39+
override: true
40+
41+
- uses: Swatinem/rust-cache@v1
42+
43+
- name: Cargo check
44+
uses: actions-rs/cargo@v1
45+
with:
46+
command: check
47+
args: --all-targets
48+
49+
test-js:
50+
name: Test Node.js
51+
runs-on: ${{ matrix.os }}
52+
needs: check
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
os: ["ubuntu-latest", "windows-latest", "macOS-latest"]
57+
include:
58+
- RUSTFLAGS: "-Dwarnings"
59+
- os: "windows-latest"
60+
RUSTFLAGS: "-Dwarnings -Ctarget-feature=+crt-static"
61+
defaults:
62+
run:
63+
working-directory: crates/rethnet_evm_napi
64+
steps:
65+
- uses: actions/checkout@v3
66+
67+
- uses: actions/setup-node@v2
68+
with:
69+
node-version: 14
70+
cache: yarn
71+
72+
- name: Install node dependencies
73+
run: yarn --frozen-lockfile
74+
75+
- name: Install Rust (stable)
76+
uses: actions-rs/toolchain@v1
77+
with:
78+
profile: minimal
79+
override: true
80+
components: rustfmt
81+
82+
- uses: Swatinem/rust-cache@v1
83+
84+
- name: Build
85+
run: yarn build
86+
87+
- name: Test
88+
run: yarn test
89+
90+
test-rs:
91+
name: Test Rust
92+
runs-on: ${{ matrix.os }}
93+
needs: check
94+
strategy:
95+
fail-fast: false
96+
matrix:
97+
os: ["ubuntu-latest", "windows-latest", "macOS-latest"]
98+
include:
99+
- RUSTFLAGS: "-Dwarnings"
100+
- os: "windows-latest"
101+
RUSTFLAGS: "-Dwarnings -Ctarget-feature=+crt-static"
102+
steps:
103+
- uses: actions/checkout@v3
104+
105+
- name: Install Rust (stable)
106+
uses: actions-rs/toolchain@v1
107+
with:
108+
profile: minimal
109+
override: true
110+
components: rustfmt
111+
112+
- uses: Swatinem/rust-cache@v1
113+
114+
- name: Doctests
115+
uses: actions-rs/cargo@v1
116+
env:
117+
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
118+
with:
119+
command: test
120+
args: --doc --all-features
121+
122+
- name: Install latest nextest release
123+
uses: taiki-e/install-action@nextest
124+
125+
- name: Test with latest nextest release
126+
uses: actions-rs/cargo@v1
127+
env:
128+
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
129+
CARGO_INCREMENTAL: ${{ matrix.CARGO_INCREMENTAL }}
130+
with:
131+
command: nextest
132+
args: run --all-features

Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[workspace]
2+
members = [
3+
"crates/*",
4+
]
5+
resolver = "2"
6+
7+
[profile.dev]
8+
rpath = true
9+
10+
[profile.release]
11+
rpath = true

crates/README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Rethnet
2+
3+
[licence-badge]: https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue
4+
[license]: COPYRIGHT
5+
6+
**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.
7+
8+
## Building from Source
9+
10+
Make sure you have the following dependencies installed on your machine:
11+
12+
- [Rust](https://www.rust-lang.org/tools/install)
13+
14+
Rethnet is part of the [Hardhat monorepo](https://github.com/NomicFoundation/hardhat). Clone the source code using ssh:
15+
16+
```bash
17+
git clone [email protected]:NomicFoundation/hardhat.git
18+
```
19+
20+
or https:
21+
22+
```bash
23+
git clone https://github.com/NomicFoundation/hardhat.git
24+
```
25+
26+
Use `cargo` to build a release version:
27+
28+
```bash
29+
cd hardhat
30+
cargo build --release
31+
```
32+
33+
## Building a Node.js native module
34+
35+
Make sure you have the following dependencies installed on your machine:
36+
37+
- [node.js](https://nodejs.org)
38+
39+
Use `npm` (or `yarn`) to build a release version:
40+
41+
```bash
42+
cd crates/rethnet_evm_napi
43+
npm run build
44+
# yarn build
45+
```
46+
47+
## Contributing
48+
49+
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.

crates/eth_execution_api/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "eth_execution_api"
3+
version = "1.0.0-beta.1"
4+
edition = "2021"
5+
6+
[dependencies]
7+
derive_builder = { version = "0.11.2", default-features = false }
8+
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
9+
serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] }

crates/eth_execution_api/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

crates/rethnet/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "rethnet"
3+
version = "0.1.0-dev"
4+
edition = "2021"
5+
6+
[dependencies]
7+
anyhow = "1.0.65"
8+
clap = { version = "3.2.22", default-features = false, features = ["std", "derive"] }
9+
pretty_env_logger = { version = "0.4.0", default-features = false }
10+
11+
[dev-dependencies.cargo-husky]
12+
version = "1.5.0"
13+
default-features = false
14+
features = ["precommit-hook", "run-cargo-test", "run-cargo-fmt", "run-cargo-clippy", "run-for-all"]

crates/rethnet/src/lib.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use std::ffi::OsString;
2+
3+
use clap::{Parser, Subcommand};
4+
5+
#[derive(Parser)]
6+
#[clap(author, version, about, long_about = None)]
7+
struct Args {
8+
#[clap(subcommand)]
9+
command: Command,
10+
}
11+
12+
#[derive(Subcommand)]
13+
#[allow(clippy::large_enum_variant)]
14+
enum Command {
15+
Start,
16+
}
17+
18+
#[derive(Copy, Debug, Clone, PartialEq, Eq)]
19+
pub enum ExitStatus {
20+
Success,
21+
Error,
22+
}
23+
24+
impl From<bool> for ExitStatus {
25+
fn from(value: bool) -> Self {
26+
if value {
27+
ExitStatus::Success
28+
} else {
29+
ExitStatus::Error
30+
}
31+
}
32+
}
33+
34+
pub fn run_with_args<T, I>(args: I) -> Result<ExitStatus, anyhow::Error>
35+
where
36+
I: IntoIterator<Item = T>,
37+
T: Into<OsString> + Clone,
38+
{
39+
let args = Args::parse_from(args);
40+
match args.command {
41+
Command::Start => {
42+
println!("Hello, world!");
43+
Ok(ExitStatus::Success)
44+
}
45+
}
46+
}

crates/rethnet/src/main.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use rethnet::{run_with_args, ExitStatus};
2+
3+
/// Main entry point for the `rethnet` executable.
4+
fn main() -> anyhow::Result<()> {
5+
pretty_env_logger::try_init()?;
6+
7+
let status = run_with_args(std::env::args_os()).unwrap();
8+
match status {
9+
ExitStatus::Success => (),
10+
ExitStatus::Error => std::process::exit(1),
11+
}
12+
Ok(())
13+
}

crates/rethnet_evm/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "rethnet_evm"
3+
version = "0.1.0-dev"
4+
edition = "2021"
5+
6+
[dependencies]
7+
anyhow = { version = "1.0.64", default-features = false, features = ["std"] }
8+
bytes = { version = "1.2.1", default-features = false }
9+
hashbrown = { version = "0.12.3", default-features = false, features = ["serde"] }
10+
log = { version = "0.4.17", default-features = false }
11+
primitive-types = { version = "0.11.1", default-features = false, features = ["impl-serde"] }
12+
revm = { git = "https://github.com/bluealloy/revm/", version = "2.1.0", default-features = false, features = ["dev", "k256", "with-serde"] }
13+
sha3 = { version = "0.10.4", default-features = false }
14+
tokio = { version = "1.21.2", default-features = false, features = ["sync"] }

crates/rethnet_evm/src/db.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod layered_db;

0 commit comments

Comments
 (0)