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

Adding benchmark and Weighted Alba #15

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9f833d6
Adding initial version of Alba prehashed
Jun 26, 2024
989c3a8
Caledonia: Separating utils functions from algo
Jul 1, 2024
42ef58d
Caledonia: creating distinct utils lib to support several algo
Jul 1, 2024
1b4b0e5
Caledonia: splitting prehashed algo from lib.rs
Jul 1, 2024
14768ec
Caledonia: Adding bounded algo
Jul 1, 2024
57a74e3
Caledonia/bounded.rs: Fix typo
Jul 1, 2024
3e91c24
Caledonia: Randomizing tests
rrtoledo Jul 1, 2024
65aaec9
Caledonia/ Cargo: Update description, categories and include
rrtoledo Jul 3, 2024
2351e48
Caledonia: Adding gitignore
rrtoledo Jul 3, 2024
46fa1ac
Caledonia/utils: fix division in mod_non_power_of_2
rrtoledo Jul 3, 2024
8580166
Caledonia: Adding benchmarks on prove and verify time
rrtoledo Jul 3, 2024
d13236e
Caledonia/bounded-prehashed: removing in test benchmarks
rrtoledo Jul 3, 2024
fb2f148
Caledonia/bench: updating bounded_bench
rrtoledo Jul 5, 2024
9de3f8a
Caledonia/bench: Adding bounded bench on steps
rrtoledo Jul 5, 2024
f8e78c8
Caledonia/bench: Adding breaking bench on repetitions
rrtoledo Jul 5, 2024
0324d5c
rust ci
curiecrypt Jul 5, 2024
b7fe9b4
remove rust ci top handle it another branch
curiecrypt Jul 5, 2024
c7e2b86
rust ci try (#16)
curiecrypt Jul 5, 2024
bce91f0
Caledonia/utils: fixing format function
rrtoledo Jul 8, 2024
13d7cdf
Caledonia/bounded test: Fixing up test prove
rrtoledo Jul 8, 2024
a1c518e
Caledonia/bounded: Added cases with new bounds
rrtoledo Jul 8, 2024
0e5a301
Caledonia/bounded: Adding case tests
rrtoledo Jul 8, 2024
22a2d91
Caledonia/bounded: Adding cases in test_prove
rrtoledo Jul 8, 2024
42f6c2b
Caledonia/*: Moving back utils in src
rrtoledo Jul 8, 2024
18b6ea5
Caledonia/prehashed-bounded: cleaning up comments
rrtoledo Jul 8, 2024
1b46daa
Caledonia/bounded: update bound check for cases
rrtoledo Jul 10, 2024
7cee1ae
Caledonia/*: Adding global constants and types
rrtoledo Jul 10, 2024
7c2da28
Caledonia/bounded: inverting limit
rrtoledo Jul 10, 2024
9ac4e26
Caledonia: Adding benchmarks on prove and verify time
rrtoledo Jul 3, 2024
e154220
Caledonia/bounded-prehashed: removing in test benchmarks
rrtoledo Jul 3, 2024
9648254
Caledonia/bench: updating bounded_bench
rrtoledo Jul 5, 2024
43805b9
Caledonia/bench: Adding bounded bench on steps
rrtoledo Jul 5, 2024
e593ecb
Caledonia/bench: Adding breaking bench on repetitions
rrtoledo Jul 5, 2024
f03b70a
Caledonia: fixup benches
rrtoledo Jul 10, 2024
8c53bcf
dump
rrtoledo Jul 12, 2024
46d99ca
fixup bump
rrtoledo Jul 12, 2024
c6ab076
Adding old VRF
rrtoledo Aug 23, 2024
752a596
Adding old VRF
rrtoledo Aug 23, 2024
9dd3372
fixup
rrtoledo Aug 23, 2024
58e8b4c
Adding telescope decentralised
rrtoledo Aug 23, 2024
29c0b6d
Adding weighted decentralised
rrtoledo Aug 23, 2024
0204947
Updating lib and utils
rrtoledo Aug 23, 2024
12afe8b
Adding and updating benches
rrtoledo Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Rust CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

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

- name: Uninstall pre-installed tools
run: |
rm -f ~/.cargo/bin/rust-analyzer
rm -f ~/.cargo/bin/rustfmt
rm -f ~/.cargo/bin/cargo-fmt

- name: Update Rust toolchain and components
run: |
rustup update
rustup component add rustfmt
rustup component add clippy

- name: Build
run: cargo build --verbose
working-directory: caledonia

- name: Verify target directory exists
run: |
echo "Checking if target directory exists and is not empty"
ls -la caledonia/target

- name: Run tests
run: cargo test --verbose
working-directory: caledonia

# - name: Run Clippy
# run: cargo clippy -- -D warnings
# working-directory: caledonia

- name: Check format
run: cargo fmt -- --check
working-directory: caledonia

- name: Build and test documentation
run: cargo doc --no-deps --verbose
working-directory: caledonia

- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-

- name: Cache Cargo build
uses: actions/cache@v3
with:
path: caledonia/target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
1 change: 1 addition & 0 deletions caledonia/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
36 changes: 36 additions & 0 deletions caledonia/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "caledonia"
version = "0.1.0"
edition = "2021"
description = "A Rust implementation of Approximate Lower Bound Arguments (ALBAs)."
categories = ["cryptography"]
include = ["**/*.rs", "Cargo.toml", "README.md", ".gitignore"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
vrf_dalek = {path = "./vrf"}
blake2 = "0.10.6"
rand_core = "0.6.4"
rayon = "1.10.0"

[dev-dependencies]
rand = "0.8.5"
rand_chacha = "0.3.1"
criterion = { version = "0.5.1", features = ["html_reports"] }

[[bench]]
name = "bounded_time"
harness = false

[[bench]]
name = "bounded_step"
harness = false

[[bench]]
name = "decentralised_time"
harness = false

[[bench]]
name = "weighted_time"
harness = false
76 changes: 76 additions & 0 deletions caledonia/benches/bounded_repetition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;
use std::time::Duration;

use caledonia::bounded::Proof;

pub mod utils;

fn prepetitions(
c: &mut Criterion<utils::Repetitions>,
lambdas: &[usize],
s_p: &[usize],
n_p: &[usize],
_hash_size: usize,
) {
let mut group = c.benchmark_group("Alba Bounded".to_string());

fn prove_repetitions(l: usize, sp: usize, np: usize, truncate_size: usize, n: u64) -> u64 {
let mut rng = ChaCha20Rng::from_entropy();
let mut total_repetitions = 0;
for _ in 0..n {
// Setup
let (mut dataset, bench_setup) = utils::setup_bounded_wrapper(&mut rng, l, sp, np);
dataset.truncate(truncate_size);
// Bench
black_box({
let (_, r, _) = Proof::bench(&bench_setup, &dataset);
total_repetitions += 1 + r;
});
}
total_repetitions as u64
}

for &l in lambdas {
for &sp in s_p {
for &np in n_p {
// Bench with all of Sp
let high = sp;

// Bench with all of np% of Sp
let low = (high * np).div_ceil(100);

// Bench with (100+np)/2 percent of Sp
let mean = (100 + np).div_ceil(2);
let mid = (high + low).div_ceil(2);

group.bench_function(
utils::bench_id("Proving repetitions", np, l, sp, np),
move |b| b.iter_custom(|n| prove_repetitions(l, sp, np, low, n)),
);
group.bench_function(
utils::bench_id("Proving repetitions", mean, l, sp, np),
move |b| b.iter_custom(|n| prove_repetitions(l, sp, np, mid, n)),
);
group.bench_function(
utils::bench_id("Proving repetitions", 100, l, sp, np),
move |b| b.iter_custom(|n| prove_repetitions(l, sp, np, high, n)),
);
}
}
}
group.finish();
}

fn prove_step_benches(c: &mut Criterion<utils::Repetitions>) {
prepetitions(c, &[50], &[100], &[60, 66, 80], 256);
}

criterion_group!(name = benches;
config = Criterion::default().sample_size(500).nresamples(1000).measurement_time(Duration::from_secs(30)).with_measurement(utils::Repetitions);
targets =
prove_step_benches
);

criterion_main!(benches);
74 changes: 74 additions & 0 deletions caledonia/benches/bounded_step.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;

use caledonia::bounded::Proof;

pub mod utils;

fn psteps(
c: &mut Criterion<utils::Steps>,
lambdas: &[usize],
s_p: &[usize],
n_p: &[usize],
_hash_size: usize,
) {
let mut group = c.benchmark_group("Alba Bounded".to_string());

fn prove_steps(l: usize, sp: usize, np: usize, truncate_size: usize, n: u64) -> u64 {
let mut rng = ChaCha20Rng::from_entropy();
let mut total_steps = 0;
for _ in 0..n {
// Setup
let (mut dataset, bench_setup) = utils::setup_bounded_wrapper(&mut rng, l, sp, np);
dataset.truncate(truncate_size);
// Bench
black_box({
let (steps, _, _) = Proof::bench(&bench_setup, &dataset);
total_steps += steps;
});
}
total_steps as u64
}

for &l in lambdas {
for &sp in s_p {
for &np in n_p {
// Bench with all of Sp
let high = sp;

// Bench with all of np% of Sp
let low = (high * np).div_ceil(100);

// Bench with (100+np)/2 percent of Sp
let mean = (100 + np).div_ceil(2);
let mid = (high + low).div_ceil(2);

group.bench_function(utils::bench_id("Proving steps", np, l, sp, np), move |b| {
b.iter_custom(|n| prove_steps(l, sp, np, low, n))
});
group.bench_function(
utils::bench_id("Proving steps", mean, l, sp, np),
move |b| b.iter_custom(|n| prove_steps(l, sp, np, mid, n)),
);
group.bench_function(utils::bench_id("Proving steps", 100, l, sp, np), move |b| {
b.iter_custom(|n| prove_steps(l, sp, np, high, n))
});
}
}
}
group.finish();
}

fn prove_step_benches(c: &mut Criterion<utils::Steps>) {
// prove(c, &[128], &[1000, 5000], &[60, 66, 80], 256);
psteps(c, &[10], &[1000], &[60, 66, 80], 256);
}

criterion_group!(name = benches;
config = Criterion::default().nresamples(1000).with_measurement(utils::Steps);
targets =
prove_step_benches
);

criterion_main!(benches);
127 changes: 127 additions & 0 deletions caledonia/benches/bounded_time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;
use std::time::{Duration, Instant};

use caledonia::bounded::Proof;

pub mod utils;

fn prove(c: &mut Criterion, lambdas: &[usize], s_p: &[usize], n_p: &[usize], _hash_size: usize) {
let mut group = c.benchmark_group("Alba Bounded".to_string());

fn prove_duration(l: usize, sp: usize, np: usize, truncate_size: usize, n: u64) -> Duration {
let mut rng = ChaCha20Rng::from_entropy();
let mut total_duration = Duration::ZERO;
for _ in 0..n {
// Setup
let (mut dataset, bench_setup) = utils::setup_bounded_wrapper(&mut rng, l, sp, np);
dataset.truncate(truncate_size);
// Bench
let start = Instant::now();
black_box({
Proof::prove(&bench_setup, &dataset);
});
total_duration = total_duration.saturating_add(start.elapsed());
}
total_duration
}

for &l in lambdas {
for &sp in s_p {
for &np in n_p {
// Bench with all of Sp
let high = sp;

// Bench with all of np% of Sp
let low = (high * np).div_ceil(100);

// Bench with (100+np)/2 percent of Sp
let mean = (100 + np).div_ceil(2);
let mid = (high + low).div_ceil(2);

group.bench_function(utils::bench_id("Proving time", np, l, sp, np), move |b| {
b.iter_custom(|n| prove_duration(l, sp, np, low, n))
});
group.bench_function(utils::bench_id("Proving time", mean, l, sp, np), move |b| {
b.iter_custom(|n| prove_duration(l, sp, np, mid, n))
});
group.bench_function(utils::bench_id("Proving time", 100, l, sp, np), move |b| {
b.iter_custom(|n| prove_duration(l, sp, np, high, n))
});
}
}
}
group.finish();
}

fn verify(c: &mut Criterion, lambdas: &[usize], s_p: &[usize], n_p: &[usize], _hash_size: usize) {
let mut group = c.benchmark_group("Alba".to_string());

fn verify_duration(l: usize, sp: usize, np: usize, truncate_size: usize, n: u64) -> Duration {
let mut rng = ChaCha20Rng::from_entropy();
let mut total_duration = Duration::ZERO;
for _ in 0..n {
// Setup
let (mut dataset, bench_setup) = utils::setup_bounded_wrapper(&mut rng, l, sp, np);
dataset.truncate(truncate_size);
// Prove
let proof = Proof::prove(&bench_setup, &dataset);
// Bench
let start = Instant::now();
black_box({
Proof::verify(&bench_setup, proof);
});
total_duration = total_duration.saturating_add(start.elapsed());
}
total_duration
}

for &l in lambdas {
for &sp in s_p {
for &np in n_p {
// Bench with all of Sp
let high = sp;

// Bench with all of np% of Sp
let low = (high * np).div_ceil(100);

// Bench with (100+np)/2 percent of Sp
let mean = (100 + np).div_ceil(2);
let mid = (high + low).div_ceil(2);

group.bench_function(
utils::bench_id("Verification time", np, l, sp, np),
move |b| b.iter_custom(|n| verify_duration(l, sp, np, low, n)),
);
group.bench_function(
utils::bench_id("Verification time", mean, l, sp, np),
move |b| b.iter_custom(|n| verify_duration(l, sp, np, mid, n)),
);
group.bench_function(
utils::bench_id("Verification time", 100, l, sp, np),
move |b| b.iter_custom(|n| verify_duration(l, sp, np, high, n)),
);
}
}
}
group.finish();
}

fn prove_benches(c: &mut Criterion) {
// prove(c, &[128], &[1000, 5000], &[60, 66, 80], 256);
prove(c, &[128], &[1_000_000], &[60, 66, 80], 256);
}

fn verify_benches(c: &mut Criterion) {
verify(c, &[10], &[1000], &[60, 66, 80], 256);
}

criterion_group!(name = benches;
config = Criterion::default().nresamples(1000);
targets =
prove_benches,
verify_benches
);

criterion_main!(benches);
Loading
Loading