mirror of https://github.com/zcash/halo2.git
Add hash and blinding_factor functions
This commit is contained in:
parent
8cfe0ae67d
commit
54697b22ed
|
@ -412,6 +412,41 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
/// $\mathsf{SinsemillaCommit}$ from [§ 5.4.8.4][concretesinsemillacommit].
|
||||
///
|
||||
/// [concretesinsemillacommit]: https://zips.z.cash/protocol/nu5.pdf#concretesinsemillacommit
|
||||
pub fn hash(
|
||||
&self,
|
||||
layouter: impl Layouter<C::Base>,
|
||||
message: Message<C, SinsemillaChip, K, MAX_WORDS>,
|
||||
) -> Result<
|
||||
(
|
||||
ecc::NonIdentityPoint<C, EccChip>,
|
||||
Vec<SinsemillaChip::RunningSum>,
|
||||
),
|
||||
Error,
|
||||
> {
|
||||
assert_eq!(self.M.sinsemilla_chip, message.chip);
|
||||
self.M.hash_to_point(layouter, message)
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
/// $\mathsf{SinsemillaCommit}$ from [§ 5.4.8.4][concretesinsemillacommit].
|
||||
///
|
||||
/// [concretesinsemillacommit]: https://zips.z.cash/protocol/nu5.pdf#concretesinsemillacommit
|
||||
pub fn blinding_factor(
|
||||
&self,
|
||||
mut layouter: impl Layouter<C::Base>,
|
||||
r: ecc::ScalarFixed<C, EccChip>,
|
||||
) -> Result<
|
||||
ecc::Point<C, EccChip>,
|
||||
Error,
|
||||
> {
|
||||
let (blind, _) = self.R.mul(layouter.namespace(|| "[r] R"), r)?;
|
||||
Ok(blind)
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
/// $\mathsf{SinsemillaCommit}$ from [§ 5.4.8.4][concretesinsemillacommit].
|
||||
///
|
||||
|
@ -429,8 +464,8 @@ where
|
|||
Error,
|
||||
> {
|
||||
assert_eq!(self.M.sinsemilla_chip, message.chip);
|
||||
let (blind, _) = self.R.mul(layouter.namespace(|| "[r] R"), r)?;
|
||||
let (p, zs) = self.M.hash_to_point(layouter.namespace(|| "M"), message)?;
|
||||
let blind = self.blinding_factor(layouter.namespace(|| "[r] R"), r)?;
|
||||
let (p, zs) = self.hash(layouter.namespace(|| "M"), message)?;
|
||||
let commitment = p.add(layouter.namespace(|| "M + [r] R"), &blind)?;
|
||||
Ok((commitment, zs))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue