diff --git a/CODEOWNERS b/CODEOWNERS index ad52a5e42..f558202f5 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -25,9 +25,6 @@ # Owner of `jf-rescue` crate /rescue/ @philippecamacho -# Owner of `jf-vdf` crate -/vdf/ @mrain - # Owner of `jf-vid` crate /vid/ @ggutoski @akonring diff --git a/Cargo.toml b/Cargo.toml index 0d8a0e24b..06d1c8d11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["aead", "commitment", "crhf", "elgamal", "merkle_tree", "pcs", "plonk", "prf", "relation", "rescue", "signature", "utilities", "vdf", "vid", "vrf"] +members = ["aead", "commitment", "crhf", "elgamal", "merkle_tree", "pcs", "plonk", "prf", "relation", "rescue", "signature", "utilities", "vid", "vrf"] resolver = "2" [workspace.package] @@ -19,7 +19,7 @@ ark-bw6-761 = { version = "0.4.0", default-features = false } ark-ec = { version = "0.4.0", default-features = false } ark-ff = { version = "0.4.0", default-features = false, features = [ "asm" ] } ark-poly = { version = "0.4.0", default-features = false } -ark-serialize = { version = "0.4.0", default-features = false } +ark-serialize = { version = "0.4.0", default-features = false, features = [ "derive" ] } ark-std = { version = "0.4.0", default-features = false } derivative = { version = "2", features = ["use_core"] } digest = { version = "0.10.1", default-features = false, features = [ "alloc" ] } diff --git a/README.md b/README.md index 397f29e68..7852dbe55 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,6 @@ For general discussions on Jellyfish PLONK, please join our [Discord channel](ht - ['jf-aead'](aead): authenticated encryption with associated data (AEAD) implementation. - ['jf-merkle-tree'](merkle_tree): various (vanilla, sparse, namespaced) Merkle tree trait definitions and implementations. - ['jf-pcs'](pcs): polynomial commitment scheme (PCS) trait definitions and univariate/multilinear KZG-PCS implementations. -- ['jf-vdf'](vdf): verifiable delay function (VDF) trait definitions and (non-verifiable) MinRoot implementation. - ['jf-vid'](vid): verifiable information dispersal (VID) trait definition and implementation. ### Plonk diff --git a/scripts/check_no_std.sh b/scripts/check_no_std.sh index 28929f375..7f5e31f83 100755 --- a/scripts/check_no_std.sh +++ b/scripts/check_no_std.sh @@ -9,7 +9,6 @@ cargo-nono check --no-default-features --package jf-merkle-tree --features "gadg cargo-nono check --no-default-features --package jf-pcs --features "test-srs" cargo-nono check --no-default-features --package jf-rescue --features "gadgets" cargo-nono check --no-default-features --package jf-signature --features "bls, schnorr, gadgets" -cargo-nono check --no-default-features --package jf-vdf cargo-nono check --no-default-features --package jf-vid --features "test-srs" cargo-nono check --no-default-features --package jf-aead cargo-nono check --no-default-features --package jf-elgamal --features "gadgets" diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index fe3bf8d9e..ba237f301 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -10,7 +10,6 @@ cargo +nightly test --release -p jf-merkle-tree --features gadgets -- -Zunstable cargo +nightly test --release -p jf-pcs --features test-srs -- -Zunstable-options --report-time cargo +nightly test --release -p jf-rescue --features gadgets -- -Zunstable-options --report-time cargo +nightly test --release -p jf-signature --features "bls, schnorr, gadgets" -- -Zunstable-options --report-time -cargo +nightly test --release -p jf-vdf -- -Zunstable-options --report-time cargo +nightly test --release -p jf-vid --features test-srs -- -Zunstable-options --report-time cargo +nightly test --release -p jf-aead -- -Zunstable-options --report-time cargo +nightly test --release -p jf-elgamal --features gadgets -- -Zunstable-options --report-time diff --git a/vdf/CHAGELOG.md b/vdf/CHAGELOG.md deleted file mode 100644 index bbee589dc..000000000 --- a/vdf/CHAGELOG.md +++ /dev/null @@ -1,8 +0,0 @@ -# CHANGELOG - -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 - -- Initial release. VDF trait definition and (non-verifiable) MinRoot delay function implementation. diff --git a/vdf/Cargo.toml b/vdf/Cargo.toml deleted file mode 100644 index e25840a01..000000000 --- a/vdf/Cargo.toml +++ /dev/null @@ -1,35 +0,0 @@ -[package] -name = "jf-vdf" -version = "0.1.0" -description = "Verifiable delay function." -authors = { workspace = true } -edition = { workspace = true } -license = { workspace = true } -rust-version = { workspace = true } -homepage = { workspace = true } -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-serialize = { workspace = true } -ark-std = { workspace = true } -displaydoc = { workspace = true } - -[dev-dependencies] -criterion = "0.5.1" - -[[bench]] -name = "minroot" -harness = false - -[features] -default = [] -std = [ - "ark-pallas/std", "ark-bls12-381/std", "ark-bn254/std", "ark-std/std", - "ark-ff/std", "ark-ec/std", -] diff --git a/vdf/benches/minroot.rs b/vdf/benches/minroot.rs deleted file mode 100644 index 95748154a..000000000 --- a/vdf/benches/minroot.rs +++ /dev/null @@ -1,50 +0,0 @@ -// 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 . - -#[macro_use] -extern crate criterion; -use ark_bls12_381::Fr as Fr381; -use ark_bn254::Fr as Fr254; -use ark_pallas::Fr as PastaFr; -use ark_std::rand::rngs::StdRng; -use criterion::{Criterion, Throughput}; -use jf_vdf::{ - minroot::{MinRoot, MinRootElement}, - VDF, -}; - -fn minroot_bench(c: &mut Criterion) { - let mut benchmark_group = c.benchmark_group("MinRoot"); - benchmark_group.sample_size(10); - let iterations = 1u64 << 16; - - benchmark_group.throughput(Throughput::Elements(iterations)); - let pp = MinRoot::::setup::(iterations, None).unwrap(); - let input = MinRootElement::::default(); - benchmark_group.bench_function("MinRoot_BN254", |b| { - b.iter(|| MinRoot::::eval(&pp, &input).unwrap()) - }); - - let input = MinRootElement::::default(); - benchmark_group.bench_function("MinRoot_BLS381", |b| { - b.iter(|| MinRoot::::eval(&pp, &input).unwrap()) - }); - - let input = MinRootElement::::default(); - benchmark_group.bench_function("MinRoot_Pallas", |b| { - b.iter(|| MinRoot::::eval(&pp, &input).unwrap()) - }); - - benchmark_group.finish(); -} - -fn bench(c: &mut Criterion) { - minroot_bench(c); -} - -criterion_group!(benches, bench); - -criterion_main!(benches); diff --git a/vdf/src/lib.rs b/vdf/src/lib.rs deleted file mode 100644 index d7f409b57..000000000 --- a/vdf/src/lib.rs +++ /dev/null @@ -1,96 +0,0 @@ -// 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 . - -//! Trait and implementation for a Verifiable Delay Function (VDF) . - -#![cfg_attr(not(feature = "std"), no_std)] -// Temporarily allow warning for nightly compilation with [`displaydoc`]. -#![allow(warnings)] -#![deny(missing_docs)] -#[cfg(test)] -extern crate std; - -#[cfg(any(not(feature = "std"), target_has_atomic = "ptr"))] -#[doc(hidden)] -extern crate alloc; - -use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use ark_std::{ - fmt::Debug, - rand::{CryptoRng, RngCore}, - string::String, -}; -use displaydoc::Display; - -pub mod minroot; - -/// VDF error type -#[derive(Debug, Display, Eq, PartialEq)] -pub struct VDFError(String); - -impl ark_std::error::Error for VDFError {} - -/// Glorified bool type. -type VerificationResult = Result<(), ()>; - -/// A trait for VDF proof, evaluation and verification. -pub trait VDF { - /// Public parameters - type PublicParameter; - - /// VDF proof. - type Proof: Debug - + Clone - + Send - + Sync - + CanonicalSerialize - + CanonicalDeserialize - + PartialEq - + Eq; - - /// VDF input. - type Input: Debug - + Clone - + Send - + Sync - + CanonicalSerialize - + CanonicalDeserialize - + PartialEq - + Eq; - - /// VDF output. - type Output: Debug - + Clone - + Send - + Sync - + CanonicalSerialize - + CanonicalDeserialize - + PartialEq - + Eq; - - /// Generates a public parameter from RNG with given difficulty. - /// Concrete instantiations of VDF shall document properly about the - /// correspondence between the difficulty value and the time required - /// for evaluation/proof generation. - fn setup( - difficulty: u64, - prng: Option<&mut R>, - ) -> Result; - - /// Computes the VDF output and proof. - fn eval( - pp: &Self::PublicParameter, - input: &Self::Input, - ) -> Result<(Self::Output, Self::Proof), VDFError>; - - /// Verifies a VDF output given the proof. - fn verify( - pp: &Self::PublicParameter, - input: &Self::Input, - output: &Self::Output, - proof: &Self::Proof, - ) -> Result; -} diff --git a/vdf/src/minroot.rs b/vdf/src/minroot.rs deleted file mode 100644 index 68aeb8d10..000000000 --- a/vdf/src/minroot.rs +++ /dev/null @@ -1,186 +0,0 @@ -// 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 . -//! Instantiation of the MinRoot Delay function . - -use crate::{VDFError, VDF}; -use ark_ec::AffineRepr; -use ark_ff::PrimeField; -use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; -use ark_std::vec::Vec; -use core::marker::PhantomData; - -/// Glorified bool type -type VerificationResult = Result<(), ()>; - -/// MinRoot compatible field -pub trait MinRootField: PrimeField { - /// The MinRoot iteration is calculating the cubic root (or fifth-root if - /// modulus % 3 == 1) of a field element. E.g. `EXP_COEF` should be (2 * - /// modulus - 1) / 3 if modulus % 3 != 1. - const EXP_COEF: Self::BigInt; -} - -#[derive( - Copy, - Clone, - Debug, - Default, - Eq, - PartialEq, - Ord, - PartialOrd, - CanonicalSerialize, - CanonicalDeserialize, -)] - -/// Public parameter for MinRoot DF, -pub struct MinRootPP { - /// Indicates the number of iterations - pub difficulty: u64, -} - -/// A minroot element consists of a pair of field elements. -#[derive( - Copy, - Clone, - Debug, - Default, - Eq, - PartialEq, - Ord, - PartialOrd, - CanonicalSerialize, - CanonicalDeserialize, -)] -pub struct MinRootElement(F, F); - -impl From for MinRootElement -where - T: AffineRepr, - F: MinRootField, -{ - fn from(value: T) -> Self { - let (x, y) = value.xy().unwrap(); - MinRootElement(*x, *y) - } -} - -/// Dummy struct for MinRoot delay function. -pub struct MinRoot { - _phantom: PhantomData, -} - -impl VDF for MinRoot { - type PublicParameter = MinRootPP; - type Proof = MinRootElement; - type Input = MinRootElement; - type Output = MinRootElement; - - fn setup( - difficulty: u64, - _prng: Option<&mut R>, - ) -> Result { - Ok(MinRootPP { difficulty }) - } - - fn eval( - pp: &Self::PublicParameter, - input: &Self::Input, - ) -> Result<(Self::Output, Self::Proof), VDFError> { - let mut output = *input; - for i in 0..pp.difficulty { - Self::iterate_in_place(&mut output, i)?; - } - Ok((output, output)) - } - - fn verify( - _pp: &Self::PublicParameter, - _input: &Self::Input, - output: &Self::Output, - proof: &Self::Proof, - ) -> Result { - if proof == output { - Ok(Ok(())) - } else { - Ok(Err(())) - } - } -} - -impl MinRoot { - #[inline] - fn iterate_in_place(elem: &mut MinRootElement, round: u64) -> Result<(), VDFError> { - let x = elem.0; - elem.0 = (x + elem.1).pow(F::EXP_COEF); - // assert_eq!(elem.0.pow([5u64]), x + elem.1); - elem.1 = x + F::from(round); - Ok(()) - } -} - -impl MinRootField for ark_bn254::Fr { - // modulus 21888242871839275222246405745257275088548364400416034343698204186575808495617 - // modulus % 3 == 1, modulus % 5 == 2 - // coef = (4 * modulus - 3) / 5 - // coef: 17510594297471420177797124596205820070838691520332827474958563349260646796493 - const EXP_COEF: Self::BigInt = ark_ff::BigInt::<4>([ - 14981214993055009997, - 6006880321387387405, - 10624953561019755799, - 2789598613442376532, - ]); -} - -impl MinRootField for ark_bls12_381::Fr { - // modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513 - // modulus % 3 == 1, modulus % 5 == 3 - // coef = (2 * modulus - 1) / 5 - // coef: 20974350070050476191779096203274386335076221000211055129041463479975432473805 - const EXP_COEF: Self::BigInt = ark_ff::BigInt::<4>([ - 3689348813023923405, - 2413663763415232921, - 16233882818423549954, - 3341406743785779740, - ]); -} - -impl MinRootField for ark_pallas::Fr { - // modulus 28948022309329048855892746252171976963363056481941647379679742748393362948097 - // modulus % 3 == 1, modulus % 5 == 2 - // coef = (4 * modulus - 3) / 5 - // coef: 23158417847463239084714197001737581570690445185553317903743794198714690358477 - const EXP_COEF: Self::BigInt = ark_ff::BigInt::<4>([ - 15465117582000704717, - 5665212537877281354, - 3689348814741910323, - 3689348814741910323, - ]); -} - -#[cfg(test)] -mod test { - use super::{MinRoot, MinRootElement, MinRootField}; - use crate::VDF; - use ark_std::rand::rngs::StdRng; - - #[test] - fn test_minroot() { - test_minroot_helper::(); - test_minroot_helper::(); - test_minroot_helper::(); - } - - fn test_minroot_helper() { - let start = MinRootElement(F::one(), F::one()); - let pp = MinRoot::::setup::(100, None).unwrap(); - let (output, proof) = MinRoot::::eval(&pp, &start).unwrap(); - assert_eq!(output, proof); - assert!(MinRoot::::verify(&pp, &start, &output, &proof) - .unwrap() - .is_ok()); - } -}