|
@ -10,6 +10,7 @@ use core::{ |
|
|
use ff::{PrimeField, PrimeFieldBits};
|
|
|
use ff::{PrimeField, PrimeFieldBits};
|
|
|
use merlin::Transcript;
|
|
|
use merlin::Transcript;
|
|
|
use num_bigint::BigInt;
|
|
|
use num_bigint::BigInt;
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
/// Represents an element of a group
|
|
|
/// Represents an element of a group
|
|
|
/// This is currently tailored for an elliptic curve group
|
|
|
/// This is currently tailored for an elliptic curve group
|
|
@ -25,25 +26,35 @@ pub trait Group: |
|
|
+ ScalarMulOwned<<Self as Group>::Scalar>
|
|
|
+ ScalarMulOwned<<Self as Group>::Scalar>
|
|
|
+ Send
|
|
|
+ Send
|
|
|
+ Sync
|
|
|
+ Sync
|
|
|
|
|
|
+ Serialize
|
|
|
|
|
|
+ for<'de> Deserialize<'de>
|
|
|
{
|
|
|
{
|
|
|
/// A type representing an element of the base field of the group
|
|
|
/// A type representing an element of the base field of the group
|
|
|
type Base: PrimeField + PrimeFieldBits;
|
|
|
|
|
|
|
|
|
type Base: PrimeField + PrimeFieldBits + Serialize + for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// A type representing an element of the scalar field of the group
|
|
|
/// A type representing an element of the scalar field of the group
|
|
|
type Scalar: PrimeField + PrimeFieldBits + ChallengeTrait + Send + Sync;
|
|
|
|
|
|
|
|
|
type Scalar: PrimeField
|
|
|
|
|
|
+ PrimeFieldBits
|
|
|
|
|
|
+ ChallengeTrait
|
|
|
|
|
|
+ Send
|
|
|
|
|
|
+ Sync
|
|
|
|
|
|
+ Serialize
|
|
|
|
|
|
+ for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// A type representing the compressed version of the group element
|
|
|
/// A type representing the compressed version of the group element
|
|
|
type CompressedGroupElement: CompressedGroup<GroupElement = Self>;
|
|
|
|
|
|
|
|
|
type CompressedGroupElement: CompressedGroup<GroupElement = Self>
|
|
|
|
|
|
+ Serialize
|
|
|
|
|
|
+ for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// A type representing preprocessed group element
|
|
|
/// A type representing preprocessed group element
|
|
|
type PreprocessedGroupElement: Clone + Send + Sync;
|
|
|
|
|
|
|
|
|
type PreprocessedGroupElement: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// A type that represents a hash function that consumes elements
|
|
|
/// A type that represents a hash function that consumes elements
|
|
|
/// from the base field and squeezes out elements of the scalar field
|
|
|
/// from the base field and squeezes out elements of the scalar field
|
|
|
type RO: ROTrait<Self::Base, Self::Scalar>;
|
|
|
|
|
|
|
|
|
type RO: ROTrait<Self::Base, Self::Scalar> + Serialize + for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// An alternate implementation of Self::RO in the circuit model
|
|
|
/// An alternate implementation of Self::RO in the circuit model
|
|
|
type ROCircuit: ROCircuitTrait<Self::Base>;
|
|
|
|
|
|
|
|
|
type ROCircuit: ROCircuitTrait<Self::Base> + Serialize + for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// A method to compute a multiexponentation
|
|
|
/// A method to compute a multiexponentation
|
|
|
fn vartime_multiscalar_mul(
|
|
|
fn vartime_multiscalar_mul(
|
|
@ -74,9 +85,11 @@ pub trait Group: |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// Represents a compressed version of a group element
|
|
|
/// Represents a compressed version of a group element
|
|
|
pub trait CompressedGroup: Clone + Copy + Debug + Eq + Sized + Send + Sync + 'static {
|
|
|
|
|
|
|
|
|
pub trait CompressedGroup: |
|
|
|
|
|
Clone + Copy + Debug + Eq + Sized + Send + Sync + Serialize + for<'de> Deserialize<'de> + 'static
|
|
|
|
|
|
{
|
|
|
/// A type that holds the decompressed version of the compressed group element
|
|
|
/// A type that holds the decompressed version of the compressed group element
|
|
|
type GroupElement: Group;
|
|
|
|
|
|
|
|
|
type GroupElement: Group + Serialize + for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// Decompresses the compressed group element
|
|
|
/// Decompresses the compressed group element
|
|
|
fn decompress(&self) -> Option<Self::GroupElement>;
|
|
|
fn decompress(&self) -> Option<Self::GroupElement>;
|
|
@ -106,7 +119,12 @@ pub trait ChallengeTrait { |
|
|
/// A helper trait that defines the behavior of a hash function that we use as an RO
|
|
|
/// A helper trait that defines the behavior of a hash function that we use as an RO
|
|
|
pub trait ROTrait<Base, Scalar> {
|
|
|
pub trait ROTrait<Base, Scalar> {
|
|
|
/// A type representing constants/parameters associated with the hash function
|
|
|
/// A type representing constants/parameters associated with the hash function
|
|
|
type Constants: ROConstantsTrait<Base> + Clone + Send + Sync;
|
|
|
|
|
|
|
|
|
type Constants: ROConstantsTrait<Base>
|
|
|
|
|
|
+ Clone
|
|
|
|
|
|
+ Send
|
|
|
|
|
|
+ Sync
|
|
|
|
|
|
+ Serialize
|
|
|
|
|
|
+ for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// Initializes the hash function
|
|
|
/// Initializes the hash function
|
|
|
fn new(constants: Self::Constants, num_absorbs: usize) -> Self;
|
|
|
fn new(constants: Self::Constants, num_absorbs: usize) -> Self;
|
|
@ -121,7 +139,12 @@ pub trait ROTrait { |
|
|
/// A helper trait that defines the behavior of a hash function that we use as an RO in the circuit model
|
|
|
/// A helper trait that defines the behavior of a hash function that we use as an RO in the circuit model
|
|
|
pub trait ROCircuitTrait<Base: PrimeField> {
|
|
|
pub trait ROCircuitTrait<Base: PrimeField> {
|
|
|
/// A type representing constants/parameters associated with the hash function
|
|
|
/// A type representing constants/parameters associated with the hash function
|
|
|
type Constants: ROConstantsTrait<Base> + Clone + Send + Sync;
|
|
|
|
|
|
|
|
|
type Constants: ROConstantsTrait<Base>
|
|
|
|
|
|
+ Clone
|
|
|
|
|
|
+ Send
|
|
|
|
|
|
+ Sync
|
|
|
|
|
|
+ Serialize
|
|
|
|
|
|
+ for<'de> Deserialize<'de>;
|
|
|
|
|
|
|
|
|
/// Initializes the hash function
|
|
|
/// Initializes the hash function
|
|
|
fn new(constants: Self::Constants, num_absorbs: usize) -> Self;
|
|
|
fn new(constants: Self::Constants, num_absorbs: usize) -> Self;
|
|
|