From 2ec3e144f69af5d3836d5d2b545b36105f6d69f9 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 29 May 2025 13:04:59 +0200 Subject: [PATCH] Update to `PrimeField::from_repr()` changes --- Cargo.lock | 6 ++---- Cargo.toml | 1 + elliptic-curve/src/dev.rs | 8 ++++---- elliptic-curve/src/point/non_identity.rs | 2 +- elliptic-curve/src/scalar/nonzero.rs | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17f247391..edbabcf3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,8 +228,7 @@ dependencies = [ [[package]] name = "ff" version = "0.14.0-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d42dd26f5790eda47c1a2158ea4120e32c35ddc9a7743c98a292accc01b54ef3" +source = "git+https://github.com/zkcrypto/ff.git?rev=8e139e2fb25ab61a5d362394af0a34b10c03d59b#8e139e2fb25ab61a5d362394af0a34b10c03d59b" dependencies = [ "bitvec", "ff_derive", @@ -240,8 +239,7 @@ dependencies = [ [[package]] name = "ff_derive" version = "0.14.0-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9266df7c7c72e5a865a447aca13bf480d7310eaa4f84de117c33e361d4da8888" +source = "git+https://github.com/zkcrypto/ff.git?rev=8e139e2fb25ab61a5d362394af0a34b10c03d59b#8e139e2fb25ab61a5d362394af0a34b10c03d59b" dependencies = [ "addchain", "num-bigint", diff --git a/Cargo.toml b/Cargo.toml index 51544176c..0caa832e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,5 @@ members = [ [patch.crates-io] digest = { path = "digest" } +ff = { git = "https://github.com/zkcrypto/ff.git", rev = "8e139e2fb25ab61a5d362394af0a34b10c03d59b" } signature = { path = "signature" } diff --git a/elliptic-curve/src/dev.rs b/elliptic-curve/src/dev.rs index 98d4c8e1d..bbd34940b 100644 --- a/elliptic-curve/src/dev.rs +++ b/elliptic-curve/src/dev.rs @@ -104,7 +104,7 @@ impl Field for Scalar { loop { rng.try_fill_bytes(&mut bytes)?; - if let Some(scalar) = Self::from_repr(bytes).into() { + if let Some(scalar) = Self::from_repr(&bytes).into() { return Ok(scalar); } } @@ -149,8 +149,8 @@ impl PrimeField for Scalar { const ROOT_OF_UNITY_INV: Self = Self::ZERO; // BOGUS! const DELTA: Self = Self::ZERO; // BOGUS! - fn from_repr(bytes: FieldBytes) -> CtOption { - ScalarPrimitive::from_bytes(&bytes).map(Self) + fn from_repr(bytes: &FieldBytes) -> CtOption { + ScalarPrimitive::from_bytes(bytes).map(Self) } fn to_repr(&self) -> FieldBytes { @@ -898,7 +898,7 @@ mod tests { #[test] fn round_trip() { let bytes = hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721"); - let scalar = Scalar::from_repr(bytes.into()).unwrap(); + let scalar = Scalar::from_repr(&bytes.into()).unwrap(); assert_eq!(&bytes, scalar.to_repr().as_slice()); } } diff --git a/elliptic-curve/src/point/non_identity.rs b/elliptic-curve/src/point/non_identity.rs index 91217827b..07d8828df 100644 --- a/elliptic-curve/src/point/non_identity.rs +++ b/elliptic-curve/src/point/non_identity.rs @@ -293,7 +293,7 @@ mod tests { #[test] fn mul_by_generator() { let scalar = NonZeroScalar::from_repr( - hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721").into(), + &hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721").into(), ) .unwrap(); let point = NonIdentity::::mul_by_generator(&scalar); diff --git a/elliptic-curve/src/scalar/nonzero.rs b/elliptic-curve/src/scalar/nonzero.rs index a0cd28abc..c3c8e1644 100644 --- a/elliptic-curve/src/scalar/nonzero.rs +++ b/elliptic-curve/src/scalar/nonzero.rs @@ -77,7 +77,7 @@ where } /// Decode a [`NonZeroScalar`] from a big endian-serialized field element. - pub fn from_repr(repr: FieldBytes) -> CtOption { + pub fn from_repr(repr: &FieldBytes) -> CtOption { Scalar::::from_repr(repr).and_then(Self::new) } @@ -419,7 +419,7 @@ where let mut bytes = FieldBytes::::default(); if base16ct::mixed::decode(hex, &mut bytes)?.len() == bytes.len() { - Self::from_repr(bytes).into_option().ok_or(Error) + Self::from_repr(&bytes).into_option().ok_or(Error) } else { Err(Error) } @@ -465,7 +465,7 @@ mod tests { #[test] fn round_trip() { let bytes = hex!("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721"); - let scalar = NonZeroScalar::from_repr(bytes.into()).unwrap(); + let scalar = NonZeroScalar::from_repr(&bytes.into()).unwrap(); assert_eq!(&bytes, scalar.to_repr().as_slice()); }