snarkvm_circuit_algorithms/pedersen/
mod.rsmod commit;
mod commit_uncompressed;
mod hash;
mod hash_uncompressed;
#[cfg(all(test, feature = "console"))]
use snarkvm_circuit_types::environment::{assert_count, assert_output_mode, assert_scope};
use crate::{Commit, CommitUncompressed, Hash, HashUncompressed};
use snarkvm_circuit_types::prelude::*;
pub type Pedersen64<E> = Pedersen<E, 64>;
pub type Pedersen128<E> = Pedersen<E, 128>;
pub struct Pedersen<E: Environment, const NUM_BITS: u8> {
base_window: Vec<Group<E>>,
random_base: Vec<Group<E>>,
}
#[cfg(feature = "console")]
impl<E: Environment, const NUM_BITS: u8> Inject for Pedersen<E, NUM_BITS> {
type Primitive = console::Pedersen<E::Network, NUM_BITS>;
fn new(_mode: Mode, pedersen: Self::Primitive) -> Self {
let base_window = Vec::constant(pedersen.base_window().iter().copied().collect());
assert_eq!(base_window.len(), NUM_BITS as usize);
let random_base = Vec::constant(pedersen.random_base_window().iter().copied().collect());
assert_eq!(random_base.len(), E::ScalarField::size_in_bits());
Self { base_window, random_base }
}
}
#[cfg(all(test, feature = "console"))]
mod tests {
use super::*;
use snarkvm_circuit_types::environment::Circuit;
const ITERATIONS: u64 = 10;
const MESSAGE: &str = "PedersenCircuit0";
const NUM_BITS_MULTIPLIER: u8 = 8;
fn check_setup<const NUM_BITS: u8>(num_constants: u64, num_public: u64, num_private: u64, num_constraints: u64) {
for _ in 0..ITERATIONS {
let native = console::Pedersen::<<Circuit as Environment>::Network, NUM_BITS>::setup(MESSAGE);
Circuit::scope("Pedersen::setup", || {
let circuit = Pedersen::<Circuit, NUM_BITS>::constant(native.clone());
assert_scope!(num_constants, num_public, num_private, num_constraints);
native.base_window().iter().zip_eq(circuit.base_window.iter()).for_each(|(expected, candidate)| {
assert_eq!(*expected, candidate.eject_value());
});
native.random_base_window().iter().zip_eq(circuit.random_base.iter()).for_each(
|(expected, candidate)| {
assert_eq!(*expected, candidate.eject_value());
},
);
});
}
}
#[test]
fn test_setup_constant() {
check_setup::<NUM_BITS_MULTIPLIER>(2590, 0, 0, 0);
check_setup::<{ 2 * NUM_BITS_MULTIPLIER }>(2670, 0, 0, 0);
check_setup::<{ 3 * NUM_BITS_MULTIPLIER }>(2750, 0, 0, 0);
check_setup::<{ 4 * NUM_BITS_MULTIPLIER }>(2830, 0, 0, 0);
check_setup::<{ 5 * NUM_BITS_MULTIPLIER }>(2910, 0, 0, 0);
}
}