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

fix(primitives): commit function #487

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 7 additions & 8 deletions primitives/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,18 @@ impl<F: RescueParameter, const INPUT_LEN: usize, const INPUT_LEN_PLUS_ONE: usize
type Input = [F; INPUT_LEN];
type Output = F;
type Randomness = F;

fn commit<T: Borrow<Self::Input>>(
input: T,
r: Option<&Self::Randomness>,
) -> Result<Self::Output, PrimitivesError> {
let mut msg = [F::zero(); INPUT_LEN_PLUS_ONE];
msg[0] = *r.ok_or_else(|| {
PrimitivesError::ParameterError("Expecting a blinding factor".to_string())
})?;
msg[1..INPUT_LEN_PLUS_ONE].copy_from_slice(&input.borrow()[..(INPUT_LEN)]);

Ok(FixedLengthRescueCRHF::<F, INPUT_LEN_PLUS_ONE, 1>::evaluate(&msg)?[0])
}

if let Some(blinding_factor) = r {
msg[0] = *blinding_factor;
} else {
return Err(PrimitivesError::ParameterError("Blinding factor is required".to_string()));
}

fn verify<T: Borrow<Self::Input>>(
input: T,
Expand Down