-
Notifications
You must be signed in to change notification settings - Fork 118
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
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe I'm not reading this right, but should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
andeval
infallible (not return aResult
)? It looks like they can't fail in either implementationnot really a big deal: we can of course always handle the failure in HotShot
There was a problem hiding this comment.
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.