Skip to content

Commit

Permalink
feat: place ethereum tests into the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss committed Jan 3, 2024
1 parent d51703d commit ca04f87
Show file tree
Hide file tree
Showing 60 changed files with 9,729 additions and 10 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ jobs:
run: cargo build --no-default-features --verbose
- name: Build for feature (tracing)
run: cargo build --features tracing --verbose
- name: Run tests
run: cargo test --verbose
jsontests:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Run tests
run: |
cd evm-tests/jsontests
cargo test --release
run: cargo test --all --verbose
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "evm-tests"]
path = evm-tests
url = https://github.com/aurora-is-near/evm-tests.git
[submodule "evm-tests/jsontests/res/ethtests"]
path = evm-tests/jsontests/res/ethtests
url = https://github.com/ethereum/tests
tag = v12.3
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ members = [
"gasometer",
"runtime",
"fuzzer",
"evm-tests/jsontests"
]
1 change: 0 additions & 1 deletion evm-tests
Submodule evm-tests deleted from b35875
22 changes: 22 additions & 0 deletions evm-tests/EIP-152/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "eip-152"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
repository = "https://github.com/openethereum/openethereum"
documentation = "https://docs.rs/eip-152"
readme = "README.md"
description = "eip-512 blake2 F compression function"
keywords = ["eip-152", "eip152", "eip"]
license = "GPL-3.0"
edition = "2018"

[dependencies]
arrayref = "0.3.5"

[dev-dependencies]
criterion = "0.3"
rustc-hex = "2.1.0"

[[bench]]
name = "bench"
harness = false
25 changes: 25 additions & 0 deletions evm-tests/EIP-152/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
This program is copyright 2020 Parity Technologies Limited and its licensors.

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Some portions of the program (“the Software”) are Copyright (c) 2018 Jack O'Connor
and the following relates solely to such portions:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
214 changes: 214 additions & 0 deletions evm-tests/EIP-152/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
// This file is part of Open Ethereum.

// Open Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Open Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Open Ethereum. If not, see <http://www.gnu.org/licenses/>.

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use eip_152::portable;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod avx {
use criterion::{black_box, BenchmarkId, Criterion, Throughput};
use std::mem;
use std::sync::atomic::{AtomicPtr, Ordering};

use eip_152::{avx2, portable};

type FnRaw = *mut ();
type Blake2bF = fn(&mut [u64; 8], [u64; 16], [u64; 2], bool, usize);

static FN: AtomicPtr<()> = AtomicPtr::new(detect as FnRaw);

fn detect(state: &mut [u64; 8], message: [u64; 16], count: [u64; 2], f: bool, rounds: usize) {
let fun = if is_x86_feature_detected!("avx2") {
avx2::compress as FnRaw
} else {
portable::compress as FnRaw
};
FN.store(fun as FnRaw, Ordering::Relaxed);
unsafe { mem::transmute::<FnRaw, Blake2bF>(fun)(state, message, count, f, rounds) }
}

pub fn avx_ifunc_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("avx2_ifunc");

for rounds in [12, 50, 100].iter() {
group.throughput(Throughput::Elements(*rounds as u64));
group.bench_with_input(BenchmarkId::new("rounds", rounds), &rounds, |b, rounds| {
let mut state = [
0x6a09e667f2bdc948_u64,
0xbb67ae8584caa73b_u64,
0x3c6ef372fe94f82b_u64,
0xa54ff53a5f1d36f1_u64,
0x510e527fade682d1_u64,
0x9b05688c2b3e6c1f_u64,
0x1f83d9abfb41bd6b_u64,
0x5be0cd19137e2179_u64,
];

let message = [
0x0000000000636261_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
];
let count = [3, 0];
let f = true;

b.iter(|| unsafe {
let fun = FN.load(Ordering::Relaxed);
mem::transmute::<FnRaw, Blake2bF>(fun)(
black_box(&mut state),
black_box(message),
black_box(count),
black_box(f),
black_box(**rounds as usize),
);
});
});
}

group.finish();
}

pub fn avx_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("avx2");

for rounds in [12, 50, 100].iter() {
group.throughput(Throughput::Elements(*rounds as u64));
group.bench_with_input(BenchmarkId::new("rounds", rounds), &rounds, |b, rounds| {
let mut state = [
0x6a09e667f2bdc948_u64,
0xbb67ae8584caa73b_u64,
0x3c6ef372fe94f82b_u64,
0xa54ff53a5f1d36f1_u64,
0x510e527fade682d1_u64,
0x9b05688c2b3e6c1f_u64,
0x1f83d9abfb41bd6b_u64,
0x5be0cd19137e2179_u64,
];

let message = [
0x0000000000636261_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
];
let count = [3, 0];
let f = true;

b.iter(|| unsafe {
avx2::compress(
black_box(&mut state),
black_box(message),
black_box(count),
black_box(f),
black_box(**rounds as usize),
);
});
});
}

group.finish();
}
}

pub fn portable_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("portable_impl");

for rounds in [12, 50, 100].iter() {
group.throughput(Throughput::Elements(*rounds as u64));
group.bench_with_input(BenchmarkId::new("rounds", rounds), &rounds, |b, rounds| {
let mut state = [
0x6a09e667f2bdc948_u64,
0xbb67ae8584caa73b_u64,
0x3c6ef372fe94f82b_u64,
0xa54ff53a5f1d36f1_u64,
0x510e527fade682d1_u64,
0x9b05688c2b3e6c1f_u64,
0x1f83d9abfb41bd6b_u64,
0x5be0cd19137e2179_u64,
];

let message = [
0x0000000000636261_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
0x0000000000000000_u64,
];
let count = [3, 0];
let f = true;

b.iter(|| {
portable::compress(
black_box(&mut state),
black_box(message),
black_box(count),
black_box(f),
black_box(**rounds as usize),
);
});
});
}

group.finish();
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
criterion_group!(
benches,
avx::avx_benchmark,
avx::avx_ifunc_benchmark,
portable_benchmark
);
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
criterion_group!(benches, portable_benchmark);

criterion_main!(benches);
Loading

0 comments on commit ca04f87

Please sign in to comment.