Closed ghost closed 2 years ago
@joebebel
Instead of using special structs, use arkworks ToConstraintField for public inputs. This does have to use (unfortunately) Boxes or other dynamic dispatch (to get trait objects) but maybe this is better.
I would suggest a builder pattern like the following instead of dynamic dispatch:
/// Public Input Builder
#[derive(derivative::Derivative)]
#[derivative(Default(bound = ""))]
pub struct InputBuilder<F>
where
F: PrimeField,
{
input: Vec<F>,
}
impl<F> InputBuilder<F>
where
F: PrimeField,
{
/// Pushes a new input `item` into `self`, returning `None` if `item` could not be converted
/// into constraint field elements.
pub fn push<T>(self, item: &T) -> Option<Self>
where
T: ToConstraintField<F>,
{
self.extend([item])
}
/// Extends the input buffer by appending all the elements of `iter` converted into constraint
/// field elements, returning `None` if any of the conversions failed.
pub fn extend<'t, T, I>(mut self, iter: I) -> Option<Self>
where
T: 't + ToConstraintField<F>,
I: IntoIterator<Item = &'t T>,
{
for item in iter {
self.input.append(&mut item.to_field_elements()?);
}
Some(self)
}
/// Returns the vector of input elements.
pub fn finish(self) -> Vec<F> {
self.input
}
}
Some extra cleanup that I didn't do in the last PR.
ToConstraintField
for public inputs. This does have to use (unfortunately) Boxes or other dynamic dispatch (to get trait objects) but maybe this is better.PolynomialCommitment<F, DensePolynomial<F>>
instead of theHomomorphicCommitment<F>
trait, which is slightly inconsistent. This makes everything consistent, usingPrimeField
as well.append_commitments
option, since usingappend
for everyimpl CanonicalSerialize
worked well.