mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
ff: Add PrimeField: From<u64> constraint
This commit is contained in:
@@ -278,6 +278,15 @@ impl ::std::fmt::Display for Fs {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Fs {
|
||||
#[inline(always)]
|
||||
fn from(val: u64) -> Fs {
|
||||
let mut raw = [0u64; 4];
|
||||
raw[0] = val;
|
||||
Fs(FsRepr(raw)) * Fs(R2)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Fs> for FsRepr {
|
||||
fn from(e: Fs) -> FsRepr {
|
||||
e.into_repr()
|
||||
@@ -514,7 +523,7 @@ impl Field for Fs {
|
||||
|
||||
#[inline]
|
||||
fn zero() -> Self {
|
||||
Fs(FsRepr::from(0))
|
||||
Fs::from(0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -1683,10 +1692,7 @@ fn test_fs_num_bits() {
|
||||
#[test]
|
||||
fn test_fs_root_of_unity() {
|
||||
assert_eq!(Fs::S, 1);
|
||||
assert_eq!(
|
||||
Fs::multiplicative_generator(),
|
||||
Fs::from_repr(FsRepr::from(6)).unwrap()
|
||||
);
|
||||
assert_eq!(Fs::multiplicative_generator(), Fs::from(6));
|
||||
assert_eq!(
|
||||
Fs::multiplicative_generator().pow_vartime([
|
||||
0x684b872f6b7b965bu64,
|
||||
|
@@ -24,7 +24,7 @@ impl<E: JubjubEngine> ValueCommitment<E> {
|
||||
pub fn cm(&self, params: &E::Params) -> edwards::Point<E, PrimeOrder> {
|
||||
params
|
||||
.generator(FixedGenerators::ValueCommitmentValue)
|
||||
.mul(self.value, params)
|
||||
.mul(E::Fs::from(self.value), params)
|
||||
.add(
|
||||
¶ms
|
||||
.generator(FixedGenerators::ValueCommitmentRandomness)
|
||||
@@ -291,7 +291,7 @@ impl<E: JubjubEngine> Note<E> {
|
||||
let rho = self.cm_full_point(params).add(
|
||||
¶ms
|
||||
.generator(FixedGenerators::NullifierPosition)
|
||||
.mul(position, params),
|
||||
.mul(E::Fs::from(position), params),
|
||||
params,
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user