mirror of
https://github.com/arnaucube/Nova.git
synced 2026-01-12 00:51:28 +01:00
Simplifications in Nova's RO (#98)
* rename methods for better clarity * rename * Bump version
This commit is contained in:
@@ -13,8 +13,8 @@ pub trait StepCircuit<F: PrimeField>: Send + Sync + Clone {
|
||||
z: AllocatedNum<F>,
|
||||
) -> Result<AllocatedNum<F>, SynthesisError>;
|
||||
|
||||
/// Execute the circuit for a computation step and return output
|
||||
fn compute(&self, z: &F) -> F;
|
||||
/// return the output of the step when provided with with the step's input
|
||||
fn output(&self, z: &F) -> F;
|
||||
}
|
||||
|
||||
/// A trivial step circuit that simply returns the input
|
||||
@@ -35,7 +35,7 @@ where
|
||||
Ok(z)
|
||||
}
|
||||
|
||||
fn compute(&self, z: &F) -> F {
|
||||
fn output(&self, z: &F) -> F {
|
||||
*z
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,10 @@ pub trait Group:
|
||||
|
||||
/// A type that represents a hash function that consumes elements
|
||||
/// from the base field and squeezes out elements of the scalar field
|
||||
type HashFunc: HashFuncTrait<Self::Base, Self::Scalar>;
|
||||
type RO: ROTrait<Self::Base, Self::Scalar>;
|
||||
|
||||
/// An alternate implementation of Self::HashFunc in the circuit model
|
||||
type HashFuncCircuit: HashFuncCircuitTrait<Self::Base>;
|
||||
/// An alternate implementation of Self::RO in the circuit model
|
||||
type ROCircuit: ROCircuitTrait<Self::Base>;
|
||||
|
||||
/// A method to compute a multiexponentation
|
||||
fn vartime_multiscalar_mul(
|
||||
@@ -87,7 +87,7 @@ pub trait AppendToTranscriptTrait {
|
||||
/// A helper trait to absorb different objects in RO
|
||||
pub trait AbsorbInROTrait<G: Group> {
|
||||
/// Absorbs the value in the provided RO
|
||||
fn absorb_in_ro(&self, ro: &mut G::HashFunc);
|
||||
fn absorb_in_ro(&self, ro: &mut G::RO);
|
||||
}
|
||||
|
||||
/// A helper trait to generate challenges using a transcript object
|
||||
@@ -97,9 +97,9 @@ pub trait ChallengeTrait {
|
||||
}
|
||||
|
||||
/// A helper trait that defines the behavior of a hash function that we use as an RO
|
||||
pub trait HashFuncTrait<Base, Scalar> {
|
||||
pub trait ROTrait<Base, Scalar> {
|
||||
/// A type representing constants/parameters associated with the hash function
|
||||
type Constants: HashFuncConstantsTrait<Base> + Clone + Send + Sync;
|
||||
type Constants: ROConstantsTrait<Base> + Clone + Send + Sync;
|
||||
|
||||
/// Initializes the hash function
|
||||
fn new(constants: Self::Constants) -> Self;
|
||||
@@ -107,17 +107,14 @@ pub trait HashFuncTrait<Base, Scalar> {
|
||||
/// Adds a scalar to the internal state
|
||||
fn absorb(&mut self, e: Base);
|
||||
|
||||
/// Returns a random challenge by hashing the internal state
|
||||
fn get_challenge(&self) -> Scalar;
|
||||
|
||||
/// Returns a hash of the internal state
|
||||
fn get_hash(&self) -> Scalar;
|
||||
/// Returns a challenge of `num_bits` by hashing the internal state
|
||||
fn squeeze(&self, num_bits: usize) -> Scalar;
|
||||
}
|
||||
|
||||
/// A helper trait that defines the behavior of a hash function that we use as an RO in the circuit model
|
||||
pub trait HashFuncCircuitTrait<Base: PrimeField> {
|
||||
pub trait ROCircuitTrait<Base: PrimeField> {
|
||||
/// A type representing constants/parameters associated with the hash function
|
||||
type Constants: HashFuncConstantsTrait<Base> + Clone + Send + Sync;
|
||||
type Constants: ROConstantsTrait<Base> + Clone + Send + Sync;
|
||||
|
||||
/// Initializes the hash function
|
||||
fn new(constants: Self::Constants) -> Self;
|
||||
@@ -125,30 +122,25 @@ pub trait HashFuncCircuitTrait<Base: PrimeField> {
|
||||
/// Adds a scalar to the internal state
|
||||
fn absorb(&mut self, e: AllocatedNum<Base>);
|
||||
|
||||
/// Returns a random challenge by hashing the internal state
|
||||
fn get_challenge<CS>(&mut self, cs: CS) -> Result<Vec<AllocatedBit>, SynthesisError>
|
||||
where
|
||||
CS: ConstraintSystem<Base>;
|
||||
|
||||
/// Returns a hash of the internal state
|
||||
fn get_hash<CS>(&mut self, cs: CS) -> Result<Vec<AllocatedBit>, SynthesisError>
|
||||
/// Returns a challenge of `num_bits` by hashing the internal state
|
||||
fn squeeze<CS>(&mut self, cs: CS, num_bits: usize) -> Result<Vec<AllocatedBit>, SynthesisError>
|
||||
where
|
||||
CS: ConstraintSystem<Base>;
|
||||
}
|
||||
|
||||
/// A helper trait that defines the constants associated with a hash function
|
||||
pub trait HashFuncConstantsTrait<Base> {
|
||||
pub trait ROConstantsTrait<Base> {
|
||||
/// produces constants/parameters associated with the hash function
|
||||
fn new() -> Self;
|
||||
}
|
||||
|
||||
/// An alias for constants associated with G::HashFunc
|
||||
pub type HashFuncConstants<G> =
|
||||
<<G as Group>::HashFunc as HashFuncTrait<<G as Group>::Base, <G as Group>::Scalar>>::Constants;
|
||||
/// An alias for constants associated with G::RO
|
||||
pub type ROConstants<G> =
|
||||
<<G as Group>::RO as ROTrait<<G as Group>::Base, <G as Group>::Scalar>>::Constants;
|
||||
|
||||
/// An alias for constants associated with G::HashFuncCircuit
|
||||
pub type HashFuncConstantsCircuit<G> =
|
||||
<<G as Group>::HashFuncCircuit as HashFuncCircuitTrait<<G as Group>::Base>>::Constants;
|
||||
/// An alias for constants associated with G::ROCircuit
|
||||
pub type ROConstantsCircuit<G> =
|
||||
<<G as Group>::ROCircuit as ROCircuitTrait<<G as Group>::Base>>::Constants;
|
||||
|
||||
/// A helper trait for types with a group operation.
|
||||
pub trait GroupOps<Rhs = Self, Output = Self>:
|
||||
|
||||
Reference in New Issue
Block a user