ff: Add PrimeField: From<u64> constraint

This commit is contained in:
Jack Grigg
2020-03-27 23:19:58 +13:00
parent b6457a905b
commit fd79de5408
11 changed files with 50 additions and 37 deletions

View File

@@ -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,

View File

@@ -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(
&params
.generator(FixedGenerators::ValueCommitmentRandomness)
@@ -291,7 +291,7 @@ impl<E: JubjubEngine> Note<E> {
let rho = self.cm_full_point(params).add(
&params
.generator(FixedGenerators::NullifierPosition)
.mul(position, params),
.mul(E::Fs::from(position), params),
params,
);