Skip to content

Commit

Permalink
Merge branch 'main' into 1030-implement-missing-p2p-message-handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ElFantasma committed Nov 14, 2024
2 parents b931492 + 0e12f1a commit e17afb5
Show file tree
Hide file tree
Showing 92 changed files with 4,512 additions and 2,356 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/hive_and_assertoor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ name: "Hive & Assertoor"
on:
merge_group:
paths-ignore:
- "crates/l2/**"
- 'README.md'
- 'LICENSE'
- "**/README.md"
- "**/docs/**"
pull_request:
branches: ["**"]
paths-ignore:
- "crates/l2/**"
paths-ignore:
- 'README.md'
- 'LICENSE'
- "**/README.md"
Expand Down Expand Up @@ -116,7 +114,7 @@ jobs:

- name: Load image
run: |
docker load --input /tmp/ethereum_rust_image.tar
docker load --input /tmp/ethereum_rust_image.tar
- name: Setup kurtosis testnet and run assertoor tests
uses: ethpandaops/kurtosis-assertoor-github-action@v1
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

cmd/ef_tests/vectors
cmd/ef_tests/ethereum_rust/vectors
cmd/ef_tests/levm/vectors

# Repos checked out by make target
hive/
Expand Down
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ members = [
"crates/storage/trie",
"crates/common/rlp",
"cmd/ethereum_rust",
"cmd/ef_tests",
"cmd/ef_tests/ethereum_rust",
"cmd/ef_tests/levm",
"cmd/ethereum_rust_l2",
"crates/vm/levm",
"crates/vm/levm/bench/revm_comparison",
Expand Down Expand Up @@ -51,7 +52,7 @@ serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
libmdbx = { version = "0.5.0", features = ["orm"] }
bytes = { version = "1.6.0", features = ["serde"] }
tokio = { version = "1.38.0", features = ["full"] }
tokio = { version = "1.41.1", features = ["full"] }
thiserror = "1.0.61"
hex = "0.4.3"
hex-literal = "0.4.1"
Expand All @@ -64,3 +65,8 @@ rand = "0.8.5"
cfg-if = "1.0.0"
reqwest = { version = "0.12.7", features = ["json"] }
snap = "1.1.1"
secp256k1 = { version = "0.29", default-features = false, features = [
"global-context",
"recovery",
"rand",
] }
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ lint: ## 🧹 Linter check

SPECTEST_VERSION := v3.0.0
SPECTEST_ARTIFACT := tests_$(SPECTEST_VERSION).tar.gz
SPECTEST_VECTORS_DIR := cmd/ef_tests/vectors
SPECTEST_VECTORS_DIR := cmd/ef_tests/ethereum_rust/vectors

CRATE ?= *
test: $(SPECTEST_VECTORS_DIR) ## 🧪 Run each crate's tests
cargo test -p '$(CRATE)' --workspace --exclude ethereum_rust-prover -- --skip test_contract_compilation --skip testito
cargo test -p '$(CRATE)' --workspace --exclude ethereum_rust-prover --exclude ethereum_rust-levm --exclude ef_tests-levm -- --skip test_contract_compilation --skip testito

clean: clean-vectors ## 🧹 Remove build artifacts
cargo clean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ef_tests"
name = "ef_tests-ethereum_rust"
version.workspace = true
edition.workspace = true

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use ef_tests::test_runner::{parse_test_file, run_ef_test};
use ef_tests_ethereum_rust::test_runner::{parse_test_file, run_ef_test};

fn parse_and_execute(path: &Path) -> datatest_stable::Result<()> {
let tests = parse_test_file(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use ef_tests::test_runner::{parse_test_file, run_ef_test};
use ef_tests_ethereum_rust::test_runner::{parse_test_file, run_ef_test};

fn parse_and_execute(path: &Path) -> datatest_stable::Result<()> {
let tests = parse_test_file(path);
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions cmd/ef_tests/levm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "ef_tests-levm"
version.workspace = true
edition.workspace = true

[dependencies]
ethereum_rust-blockchain.workspace = true
ethereum_rust-core.workspace = true
ethereum_rust-storage.workspace = true
ethereum_rust-rlp.workspace = true
ethereum_rust-levm = { path = "../../../crates/vm/levm" }
serde.workspace = true
serde_json.workspace = true
bytes.workspace = true
hex.workspace = true
keccak-hash = "0.11.0"
colored = "2.1.0"
spinoff = "0.8.0"

[dev-dependencies]
hex = "0.4.3"

[lib]
path = "./ef_tests.rs"

[[test]]
name = "test"
harness = false
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ef::test::EFTest;
use crate::types::EFTest;
use bytes::Bytes;
use ethereum_rust_core::U256;
use serde::Deserialize;
Expand Down
4 changes: 4 additions & 0 deletions cmd/ef_tests/levm/ef_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod deserialize;
mod report;
pub mod runner;
mod types;
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Note: I use this to do not affect the EF tests logic with this side effects
// The cost to add this would be to return a Result<(), InternalError> in EFTestsReport methods

use colored::Colorize;
use std::fmt;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ef::{report::EFTestsReport, test::EFTest};
use crate::{report::EFTestsReport, types::EFTest};
use ethereum_rust_core::{H256, U256};
use ethereum_rust_levm::{
db::{Cache, Db},
Expand All @@ -13,7 +13,7 @@ use std::{error::Error, sync::Arc};
pub fn run_ef_tests() -> Result<EFTestsReport, Box<dyn Error>> {
let mut report = EFTestsReport::default();
let cargo_manifest_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let ef_general_state_tests_path = cargo_manifest_dir.join("tests/ef/tests/GeneralStateTests");
let ef_general_state_tests_path = cargo_manifest_dir.join("vectors/GeneralStateTests");
let mut spinner = Spinner::new(Dots, report.to_string(), Color::Cyan);
for test_dir in std::fs::read_dir(ef_general_state_tests_path)?.flatten() {
for test in std::fs::read_dir(test_dir.path())?
Expand Down Expand Up @@ -52,7 +52,6 @@ pub fn run_ef_tests() -> Result<EFTestsReport, Box<dyn Error>> {
}

pub fn run_ef_test(test: EFTest, report: &mut EFTestsReport) -> Result<(), Box<dyn Error>> {
dbg!(&test.name);
let mut evm = prepare_vm(&test, report)?;
ensure_pre_state(&evm, &test, report)?;
let execution_result = evm.transact();
Expand Down
6 changes: 6 additions & 0 deletions cmd/ef_tests/levm/tests/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use ef_tests_levm::runner;

fn main() {
let report = runner::run_ef_tests().unwrap();
println!("{report}");
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ef::deserialize::{
use crate::deserialize::{
deserialize_ef_post_value_indexes, deserialize_hex_bytes, deserialize_hex_bytes_vec,
deserialize_u256_optional_safe, deserialize_u256_safe, deserialize_u256_valued_hashmap_safe,
deserialize_u256_vec_safe,
Expand Down
17 changes: 8 additions & 9 deletions cmd/ethereum_rust/ethereum_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber};
mod cli;
mod decode;

const DEFAULT_DATADIR: &str = "ethereum_rust";
#[tokio::main]
async fn main() {
let matches = cli::cli().get_matches();

if let Some(matches) = matches.subcommand_matches("removedb") {
let default_datadir = get_default_datadir();
let data_dir = matches
.get_one::<String>("datadir")
.unwrap_or(&default_datadir);
.map_or(set_datadir(DEFAULT_DATADIR), |datadir| set_datadir(datadir));
let path = Path::new(&data_dir);
if path.exists() {
std::fs::remove_dir_all(path).expect("Failed to remove data directory");
Expand Down Expand Up @@ -110,11 +110,11 @@ async fn main() {
let tcp_socket_addr =
parse_socket_addr(tcp_addr, tcp_port).expect("Failed to parse addr and port");

let default_datadir = get_default_datadir();
let data_dir = matches
.get_one::<String>("datadir")
.unwrap_or(&default_datadir);
let store = Store::new(data_dir, EngineType::Libmdbx).expect("Failed to create Store");
.map_or(set_datadir(DEFAULT_DATADIR), |datadir| set_datadir(datadir));

let store = Store::new(&data_dir, EngineType::Libmdbx).expect("Failed to create Store");

let genesis = read_genesis_file(genesis_file_path);
store
Expand Down Expand Up @@ -204,7 +204,7 @@ async fn main() {
// We do not want to start the networking module if the l2 feature is enabled.
cfg_if::cfg_if! {
if #[cfg(feature = "l2")] {
let l2_proposer = ethereum_rust_l2::start_proposer(store.clone()).into_future();
let l2_proposer = ethereum_rust_l2::start_proposer(store).into_future();
tracker.spawn(l2_proposer);
} else if #[cfg(feature = "dev")] {
use ethereum_rust_dev;
Expand Down Expand Up @@ -283,9 +283,8 @@ fn parse_socket_addr(addr: &str, port: &str) -> io::Result<SocketAddr> {
))
}

fn get_default_datadir() -> String {
let project_dir =
ProjectDirs::from("", "", "ethereum_rust").expect("Couldn't find home directory");
fn set_datadir(datadir: &str) -> String {
let project_dir = ProjectDirs::from("", "", datadir).expect("Couldn't find home directory");
project_dir
.data_local_dir()
.to_str()
Expand Down
2 changes: 1 addition & 1 deletion cmd/ethereum_rust_l2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ colored = "2.1.0"
spinoff = "0.8.0"
itertools = "0.13.0"
strum = "0.26.3"
libsecp256k1 = "0.7.1"
secp256k1.workspace = true
keccak-hash = "0.10.0"

ethereum_rust-l2.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions cmd/ethereum_rust_l2/src/commands/stack.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{config::EthereumRustL2Config, utils::config::confirm};
use clap::Subcommand;
use eyre::ContextCompat;
use libsecp256k1::SecretKey;
use secp256k1::SecretKey;
use std::path::{Path, PathBuf};

pub const CARGO_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
Expand Down Expand Up @@ -188,7 +188,7 @@ fn deploy_l1(
.arg("--rpc-url")
.arg(l1_rpc_url)
.arg("--private-key")
.arg(hex::encode(deployer_private_key.serialize())) // TODO: In the future this must be the proposer's private key.
.arg(hex::encode(deployer_private_key.secret_bytes())) // TODO: In the future this must be the proposer's private key.
.arg("--broadcast")
.arg("--use")
.arg(solc_path)
Expand Down
41 changes: 25 additions & 16 deletions cmd/ethereum_rust_l2/src/commands/test.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::config::EthereumRustL2Config;
use bytes::Bytes;
use clap::Subcommand;
use ethereum_rust_blockchain::constants::TX_GAS_COST;
use ethereum_rust_core::types::{EIP1559Transaction, TxKind};
use ethereum_rust_l2::utils::eth_client::EthClient;
use ethereum_rust_l2::utils::eth_client::{eth_sender::Overrides, EthClient};
use ethereum_types::{Address, H160, H256, U256};
use keccak_hash::keccak;
use libsecp256k1::SecretKey;
use secp256k1::SecretKey;
use std::{
fs::File,
io::{self, BufRead},
Expand Down Expand Up @@ -70,10 +70,10 @@ async fn transfer_from(
cfg: EthereumRustL2Config,
) -> u64 {
let client = EthClient::new(&cfg.network.l2_rpc_url);
let private_key = SecretKey::parse(pk.parse::<H256>().unwrap().as_fixed_bytes()).unwrap();
let private_key = SecretKey::from_slice(pk.parse::<H256>().unwrap().as_bytes()).unwrap();

let mut buffer = [0u8; 64];
let public_key = libsecp256k1::PublicKey::from_secret_key(&private_key).serialize();
let public_key = private_key.public_key(secp256k1::SECP256K1).serialize();
buffer.copy_from_slice(&public_key[1..]);

let address = H160::from(keccak(buffer));
Expand All @@ -86,18 +86,27 @@ async fn transfer_from(
println!("transfer {i} from {pk}");
}

let mut tx = EIP1559Transaction {
to: TxKind::Call(to_address),
chain_id: cfg.network.l2_chain_id,
nonce: i,
gas_limit: TX_GAS_COST,
value,
max_fee_per_gas: 3121115334,
max_priority_fee_per_gas: 3000000000,
..Default::default()
};
let tx = client
.build_eip1559_transaction(
to_address,
Bytes::new(),
Overrides {
chain_id: Some(cfg.network.l2_chain_id),
nonce: Some(i),
value: Some(value),
gas_price: Some(3121115334),
priority_gas_price: Some(3000000000),
gas_limit: Some(TX_GAS_COST),
..Default::default()
},
)
.await
.unwrap();

while let Err(e) = client.send_eip1559_transaction(&mut tx, private_key).await {
while let Err(e) = client
.send_eip1559_transaction(tx.clone(), &private_key)
.await
{
println!("Transaction failed (PK: {pk} - Nonce: {}): {e}", tx.nonce);
retries += 1;
sleep(std::time::Duration::from_secs(2));
Expand Down
Loading

0 comments on commit e17afb5

Please sign in to comment.