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

Add FROST traits. #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["plonk", "kzg", "fri"]
members = ["plonk", "kzg", "fri", "frost"]
resolver = "2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 changes: 7 additions & 0 deletions frost/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "frost"
version = "0.1.0"
edition = "2021"

[dependencies]
rand_core = "0.9.0-alpha.2"
3 changes: 3 additions & 0 deletions frost/src/core/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub enum FieldError {

}
2 changes: 2 additions & 0 deletions frost/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod r#trait;
mod error;
59 changes: 59 additions & 0 deletions frost/src/core/trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use core::{
ops::{Add, Mul, Sub}
};
use std::fmt::Debug;
use rand_core::{CryptoRng, RngCore};

use crate::core::error::FieldError;

/// A prime order finite field
pub trait Field: Copy + Clone {
type Scalar: Add<Output = Self::Scalar>
+ Mul<Output = Self::Scalar>
+ Sub<Output = Self::Scalar>
+ Eq + PartialEq + Copy + Clone;

/// The additive identity
fn zero() -> Self::Scalar;

/// The multiplicative identity
fn one() -> Self::Scalar;

/// The inversion
fn invert(number: Self::Scalar) -> Result<Self::Scalar, FieldError>;

/// Random function
fn random<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar;
}

/// A prime-order group
pub trait Group: Copy + Clone + PartialEq {
type Field: Field;

// Element in group
type Element: Add<Output = Self::Element>
+ Mul<<Self::Field as Field>::Scalar, Output = Self::Element>
+ Sub<Output = Self::Element>
+ Eq + PartialEq + Clone + Copy;

/// The cofactor is the order of the entire group (number of points on the curve)
/// divided by the order of the subgroup generated by your basepoint.
///
/// If using a prime order elliptic curve, the cofactor should be 1 in the scalar field.
fn cofactor() -> <Self::Field as Field>::Scalar;

/// Additive identity of the prime order group
fn identity() -> Self::Element;

/// The generator of the prime order group
fn generator() -> Self::Element;

}

pub trait Frost: Copy + Clone + PartialEq + Debug + 'static {
type Group: Group;
type HashFunction;

fn hash_function_1(m: &[u8]) -> <<Self::Group as Group>::Field as Field>::Scalar;
fn hash_function_2(m: &[u8]) -> <Self::Group as Group>::Element;
}
2 changes: 2 additions & 0 deletions frost/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod core;

Loading