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

revert!: deprecate VDF crate #683

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
12 changes: 11 additions & 1 deletion vdf/CHAGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.0
# 0.1.1

## Added

- [#683](https://github.com/EspressoSystems/jellyfish/pull/683): add a simple hash chain delay function using Keccak.

## Deprecated

- [#683](https://github.com/EspressoSystems/jellyfish/pull/683): MinRoot delay function is now hidden under a feature flag. Add documentation about its security issue.

# 0.1.0

- Initial release. VDF trait definition and (non-verifiable) MinRoot delay function implementation.
19 changes: 13 additions & 6 deletions vdf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jf-vdf"
version = "0.1.0"
version = "0.1.1"
description = "Verifiable delay function."
authors = { workspace = true }
edition = { workspace = true }
Expand All @@ -11,24 +11,31 @@ documentation = { workspace = true }
repository = { workspace = true }

[dependencies]
ark-bls12-381 = { workspace = true }
ark-bn254 = { workspace = true }
ark-ec = { workspace = true }
ark-ff = { workspace = true }
ark-pallas = "0.4.0"
ark-bls12-381 = { workspace = true, optional = true }
ark-bn254 = { workspace = true, optional = true }
ark-ec = { workspace = true, optional = true }
ark-ff = { workspace = true, optional = true }
ark-pallas = { version = "0.4.0", optional = true }
ark-serialize = { workspace = true }
ark-std = { workspace = true }
displaydoc = { workspace = true }
sha3 = { workspace = true }

[dev-dependencies]
criterion = "0.5.1"

[[bench]]
name = "minroot"
harness = false
required-features = ["minroot"]

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

[features]
default = []
minroot = ["ark-bls12-381", "ark-bn254", "ark-ec", "ark-ff", "ark-pallas"]
std = [
"ark-pallas/std", "ark-bls12-381/std", "ark-bn254/std", "ark-std/std",
"ark-ff/std", "ark-ec/std",
Expand Down
34 changes: 34 additions & 0 deletions vdf/benches/hashchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2022 Espresso Systems (espressosys.com)
// This file is part of the Jellyfish library.

// You should have received a copy of the MIT License
// along with the Jellyfish library. If not, see <https://mit-license.org/>.

#[macro_use]
extern crate criterion;
use ark_std::rand::rngs::StdRng;
use criterion::{Criterion, Throughput};
use jf_vdf::{hashchain::HashChain, VDF};

fn minroot_bench(c: &mut Criterion) {
let mut benchmark_group = c.benchmark_group("HashChain");
benchmark_group.sample_size(10);
let iterations = 1u64 << 22;

benchmark_group.throughput(Throughput::Elements(iterations));
let pp = HashChain::setup::<StdRng>(iterations, None).unwrap();
let input = [0u8; 32];
benchmark_group.bench_function("HashChain_sha3_keccak", |b| {
b.iter(|| HashChain::eval(&pp, &input).unwrap())
});

benchmark_group.finish();
}

fn bench(c: &mut Criterion) {
minroot_bench(c);
}

criterion_group!(benches, bench);

criterion_main!(benches);
88 changes: 88 additions & 0 deletions vdf/src/hashchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) 2022 Espresso Systems (espressosys.com)
// This file is part of the Jellyfish library.

// You should have received a copy of the MIT License
// along with the Jellyfish library. If not, see <https://mit-license.org/>.
//! Instantiation of the hash chain delay function.

use crate::{VDFError, VDF};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::Vec;
use core::marker::PhantomData;
use sha3::Digest;

/// Glorified bool type
type VerificationResult = Result<(), ()>;

#[derive(
Copy,
Clone,
Debug,
Default,
Eq,
PartialEq,
Ord,
PartialOrd,
CanonicalSerialize,
CanonicalDeserialize,
)]
/// Public parameter for MinRoot DF,
pub struct HashChainParam {
/// Indicates the number of iterations
pub difficulty: u64,
}

#[derive(Copy, Debug, Clone)]
/// Dummy struct for MinRoot delay function.
pub struct HashChain;

impl VDF for HashChain {
type PublicParameter = HashChainParam;
type Proof = [u8; 32];
type Input = [u8; 32];
type Output = [u8; 32];

fn setup<R: ark_std::rand::CryptoRng + ark_std::rand::RngCore>(
difficulty: u64,
prng: Option<&mut R>,
) -> Result<Self::PublicParameter, VDFError> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make setup and eval infallible (not return a Result)? It looks like they can't fail in either implementation

not really a big deal: we can of course always handle the failure in HotShot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep it. Error may occur when we are implementing Verifiable DF.

Ok(HashChainParam { difficulty })
}

fn eval(
pp: &Self::PublicParameter,
input: &Self::Input,
) -> Result<(Self::Output, Self::Proof), VDFError> {
let mut output = *input;
for _ in 0..pp.difficulty {
output = sha3::Keccak256::digest(&input).into();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I'm not reading this right, but should this be digest(&output)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stupid me! fixed in ffc603b

}
Ok((output, output))
}

fn verify(
_pp: &Self::PublicParameter,
_input: &Self::Input,
output: &Self::Output,
proof: &Self::Proof,
) -> Result<crate::VerificationResult, VDFError> {
Ok(if output == proof { Ok(()) } else { Err(()) })
}
}

#[cfg(test)]
mod test {
use crate::{hashchain::HashChain, VDF};
use ark_std::rand::rngs::StdRng;

#[test]
fn test_hashchain() {
let start = [0u8; 32];
let pp = HashChain::setup::<StdRng>(100, None).unwrap();
let (output, proof) = HashChain::eval(&pp, &start).unwrap();
assert_eq!(output, proof);
assert!(HashChain::verify(&pp, &start, &output, &proof)
.unwrap()
.is_ok());
}
}
2 changes: 2 additions & 0 deletions vdf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use ark_std::{
};
use displaydoc::Display;

pub mod hashchain;
#[cfg(feature = "minroot")]
pub mod minroot;

/// VDF error type
Expand Down
2 changes: 2 additions & 0 deletions vdf/src/minroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// You should have received a copy of the MIT License
// along with the Jellyfish library. If not, see <https://mit-license.org/>.
//! DEPRECATED! DO NOT USE UNLESS YOU CLEARLY UNDERSTAND THIS <https://ethresear.ch/t/statement-regarding-the-public-report-on-the-analysis-of-minroot/16670>.
//! Instantiation of the MinRoot Delay function <https://eprint.iacr.org/2022/1626.pdf>.

use crate::{VDFError, VDF};
Expand Down Expand Up @@ -68,6 +69,7 @@ where
}
}

#[derive(Copy, Clone, Debug)]
/// Dummy struct for MinRoot delay function.
pub struct MinRoot<F: MinRootField> {
_phantom: PhantomData<F>,
Expand Down
Loading