Remove FieldExt::{from_bytes, read, to_bytes, write}

- `ff::PrimeField::{from_repr, to_repr}` are direct replacements for
  `FieldExt::{from_bytes, to_bytes}`.
- `FieldExt::{read, write}` were added for reading and writing `halo2`
  proofs, but `halo2::transcript` now handles this internally.
This commit is contained in:
Jack Grigg 2021-09-20 22:09:45 +01:00
parent ad0360bc1c
commit 3a6f71d2f0
4 changed files with 9 additions and 50 deletions

View file

@ -19,6 +19,8 @@ and this project adheres to Rust's notion of
(moved to `SqrtRatio` trait).
- `FieldExt::{RESCUE_ALPHA, RESCUE_INVALPHA}`
- `FieldExt::from_u64` (use `From<u64> for ff::PrimeField` instead).
- `FieldExt::{from_bytes, read, to_bytes, write}`
(use `ff::PrimeField::{from_repr, to_repr}` instead).
## [0.2.1] - 2021-09-17
### Changed

View file

@ -4,20 +4,16 @@
use core::mem::size_of;
use static_assertions::const_assert;
use subtle::{Choice, CtOption};
use subtle::Choice;
#[cfg(not(feature = "std"))]
use subtle::CtOption;
#[cfg(feature = "std")]
use super::Group;
#[cfg(feature = "std")]
use std::{
assert,
boxed::Box,
convert::TryInto,
io::{self, Read, Write},
marker::PhantomData,
vec::Vec,
};
use std::{assert, boxed::Box, convert::TryInto, marker::PhantomData, vec::Vec};
const_assert!(size_of::<usize>() >= 4);
@ -85,29 +81,6 @@ pub trait FieldExt: SqrtRatio + From<bool> + Ord + Group<Scalar = Self> {
/// Obtains a field element congruent to the integer `v`.
fn from_u128(v: u128) -> Self;
/// Converts this field element to its normalized, little endian byte
/// representation.
fn to_bytes(&self) -> [u8; 32];
/// Writes this element in its normalized, little endian form into a buffer.
fn write<W: Write>(&self, writer: &mut W) -> io::Result<()> {
let compressed = self.to_bytes();
writer.write_all(&compressed[..])
}
/// Attempts to obtain a field element from its normalized, little endian
/// byte representation.
fn from_bytes(bytes: &[u8; 32]) -> CtOption<Self>;
/// Reads a normalized, little endian represented field element from a
/// buffer.
fn read<R: Read>(reader: &mut R) -> io::Result<Self> {
let mut compressed = [0u8; 32];
reader.read_exact(&mut compressed[..])?;
Option::from(Self::from_bytes(&compressed))
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid point encoding in proof"))
}
/// Obtains a field element that is congruent to the provided little endian
/// byte representation of an integer.
fn from_bytes_wide(bytes: &[u8; 64]) -> Self;

View file

@ -627,7 +627,7 @@ impl PrimeFieldBits for Fp {
type ReprBits = ReprBits;
fn to_le_bits(&self) -> FieldBits<Self::ReprBits> {
let bytes = self.to_bytes();
let bytes = self.to_repr();
#[cfg(not(target_pointer_width = "64"))]
let limbs = [
@ -741,14 +741,6 @@ impl FieldExt for Fp {
Fp::from_raw([v as u64, (v >> 64) as u64, 0, 0])
}
fn from_bytes(bytes: &[u8; 32]) -> CtOption<Fp> {
<Self as ff::PrimeField>::from_repr(*bytes)
}
fn to_bytes(&self) -> [u8; 32] {
<Self as ff::PrimeField>::to_repr(self)
}
/// Converts a 512-bit little endian integer into
/// a `Fp` by reducing by the modulus.
fn from_bytes_wide(bytes: &[u8; 64]) -> Fp {

View file

@ -627,7 +627,7 @@ impl PrimeFieldBits for Fq {
type ReprBits = ReprBits;
fn to_le_bits(&self) -> FieldBits<Self::ReprBits> {
let bytes = self.to_bytes();
let bytes = self.to_repr();
#[cfg(not(target_pointer_width = "64"))]
let limbs = [
@ -741,14 +741,6 @@ impl FieldExt for Fq {
Fq::from_raw([v as u64, (v >> 64) as u64, 0, 0])
}
fn from_bytes(bytes: &[u8; 32]) -> CtOption<Fq> {
<Self as ff::PrimeField>::from_repr(*bytes)
}
fn to_bytes(&self) -> [u8; 32] {
<Self as ff::PrimeField>::to_repr(self)
}
/// Converts a 512-bit little endian integer into
/// a `Fq` by reducing by the modulus.
fn from_bytes_wide(bytes: &[u8; 64]) -> Fq {