Skip to content

Commit

Permalink
Code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
darth-cy committed Nov 26, 2024
1 parent e5c2c6c commit 6425c3a
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 38 deletions.
8 changes: 3 additions & 5 deletions spartan_parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn write_bytes(mut f: &File, bytes: &[u8; 32]) -> std::io::Result<()> {
for i in 0..size {
write!(&mut f, "{} ", bytes[i])?;
}
writeln!(&mut f, "")?;
writeln!(&mut f)?;
Ok(())
}

Expand Down Expand Up @@ -285,7 +285,7 @@ impl<S: SpartanExtensionField> IOProofs<S> {
input_indices = input_indices[..live_input.len()].to_vec();

// batch verify all proofs
let _ = PolyEvalProof::verify_plain_batched_points(
PolyEvalProof::verify_plain_batched_points(
&self.proofs,
transcript,
[
Expand Down Expand Up @@ -313,9 +313,7 @@ impl<S: SpartanExtensionField> IOProofs<S> {
live_input,
]
.concat(),
)?;

Ok(())
)
}
}

Expand Down
7 changes: 0 additions & 7 deletions spartan_parallel/src/scalar/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,11 @@ impl Zeroize for Scalar {
impl Neg for Scalar {
type Output = Scalar;

#[inline]
fn neg(self) -> Scalar {
self.0.neg().into()
}
}
impl Default for Scalar {
#[inline]
fn default() -> Self {
Self::zero()
}
Expand All @@ -138,13 +136,11 @@ impl From<Goldilocks> for Scalar {
}
impl Scalar {
/// Returns zero, the additive identity.
#[inline]
pub const fn zero() -> Self {
Self(Goldilocks(0u64))
}

/// Returns one, the multiplicative identity.
#[inline]
pub const fn one() -> Self {
Self(Goldilocks(1u64))
}
Expand All @@ -153,7 +149,6 @@ impl Scalar {
impl<'a, 'b> Add<&'b Scalar> for &'a Scalar {
type Output = Scalar;

#[inline]
fn add(self, rhs: &'b Scalar) -> Scalar {
self.inner().add(rhs.inner()).into()
}
Expand All @@ -162,7 +157,6 @@ impl<'a, 'b> Add<&'b Scalar> for &'a Scalar {
impl<'a, 'b> Sub<&'b Scalar> for &'a Scalar {
type Output = Scalar;

#[inline]
fn sub(self, rhs: &'b Scalar) -> Scalar {
self.inner().sub(rhs.inner()).into()
}
Expand All @@ -171,7 +165,6 @@ impl<'a, 'b> Sub<&'b Scalar> for &'a Scalar {
impl<'a, 'b> Mul<&'b Scalar> for &'a Scalar {
type Output = Scalar;

#[inline]
fn mul(self, rhs: &'b Scalar) -> Scalar {
self.inner().mul(rhs.inner()).into()
}
Expand Down
7 changes: 0 additions & 7 deletions spartan_parallel/src/scalar/fp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,22 @@ impl Zeroize for ScalarExt2 {
impl Neg for ScalarExt2 {
type Output = Self;

#[inline]
fn neg(self) -> Self {
self.0.neg().into()
}
}
impl Default for ScalarExt2 {
#[inline]
fn default() -> Self {
Self::zero()
}
}
impl ScalarExt2 {
/// Returns zero, the additive identity.
#[inline]
pub const fn zero() -> Self {
Self(GoldilocksExt2::ZERO)
}

/// Returns one, the multiplicative identity.
#[inline]
pub const fn one() -> Self {
Self(GoldilocksExt2::ONE)
}
Expand All @@ -145,7 +141,6 @@ impl ScalarExt2 {
impl<'a, 'b> Add<&'b ScalarExt2> for &'a ScalarExt2 {
type Output = ScalarExt2;

#[inline]
fn add(self, rhs: &'b ScalarExt2) -> ScalarExt2 {
self.inner().add(rhs.inner()).into()
}
Expand All @@ -154,7 +149,6 @@ impl<'a, 'b> Add<&'b ScalarExt2> for &'a ScalarExt2 {
impl<'a, 'b> Sub<&'b ScalarExt2> for &'a ScalarExt2 {
type Output = ScalarExt2;

#[inline]
fn sub(self, rhs: &'b ScalarExt2) -> ScalarExt2 {
self.inner().sub(rhs.inner()).into()
}
Expand All @@ -163,7 +157,6 @@ impl<'a, 'b> Sub<&'b ScalarExt2> for &'a ScalarExt2 {
impl<'a, 'b> Mul<&'b ScalarExt2> for &'a ScalarExt2 {
type Output = ScalarExt2;

#[inline]
fn mul(self, rhs: &'b ScalarExt2) -> ScalarExt2 {
let a = self.inner();
let b = rhs.inner();
Expand Down
19 changes: 0 additions & 19 deletions spartan_parallel/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,21 @@ pub trait SpartanExtensionField:
);

/// Return the neg of field element
#[inline]
fn negate(&self) -> Self {
self.inner().neg().into()
}

/// Doubles this field element.
#[inline]
fn double(&self) -> Self {
self.add(*self)
}

/// Squares this element.
#[inline]
fn square(&self) -> Self {
self.mul(*self)
}

/// Negates `self`.
#[inline]
fn neg(&self) -> Self {
self.inner().neg().into()
}
Expand Down Expand Up @@ -186,7 +182,6 @@ macro_rules! impl_add_binop_specify_output {
impl<'b> Add<&'b $rhs> for $lhs {
type Output = $output;

#[inline]
fn add(self, rhs: &'b $rhs) -> $output {
&self + rhs
}
Expand All @@ -195,7 +190,6 @@ macro_rules! impl_add_binop_specify_output {
impl<'a> Add<$rhs> for &'a $lhs {
type Output = $output;

#[inline]
fn add(self, rhs: $rhs) -> $output {
self + &rhs
}
Expand All @@ -204,7 +198,6 @@ macro_rules! impl_add_binop_specify_output {
impl Add<$rhs> for $lhs {
type Output = $output;

#[inline]
fn add(self, rhs: $rhs) -> $output {
&self + &rhs
}
Expand All @@ -219,7 +212,6 @@ macro_rules! impl_sub_binop_specify_output {
impl<'b> Sub<&'b $rhs> for $lhs {
type Output = $output;

#[inline]
fn sub(self, rhs: &'b $rhs) -> $output {
&self - rhs
}
Expand All @@ -228,7 +220,6 @@ macro_rules! impl_sub_binop_specify_output {
impl<'a> Sub<$rhs> for &'a $lhs {
type Output = $output;

#[inline]
fn sub(self, rhs: $rhs) -> $output {
self - &rhs
}
Expand All @@ -237,7 +228,6 @@ macro_rules! impl_sub_binop_specify_output {
impl Sub<$rhs> for $lhs {
type Output = $output;

#[inline]
fn sub(self, rhs: $rhs) -> $output {
&self - &rhs
}
Expand All @@ -261,7 +251,6 @@ macro_rules! impl_binops_multiplicative_mixed {
impl<'b> Mul<&'b $rhs> for $lhs {
type Output = $output;

#[inline]
fn mul(self, rhs: &'b $rhs) -> $output {
&self * rhs
}
Expand All @@ -270,7 +259,6 @@ macro_rules! impl_binops_multiplicative_mixed {
impl<'a> Mul<$rhs> for &'a $lhs {
type Output = $output;

#[inline]
fn mul(self, rhs: $rhs) -> $output {
self * &rhs
}
Expand All @@ -279,7 +267,6 @@ macro_rules! impl_binops_multiplicative_mixed {
impl Mul<$rhs> for $lhs {
type Output = $output;

#[inline]
fn mul(self, rhs: $rhs) -> $output {
&self * &rhs
}
Expand All @@ -294,28 +281,24 @@ macro_rules! impl_binops_additive {
crate::impl_binops_additive_specify_output!($lhs, $rhs, $lhs);

impl SubAssign<$rhs> for $lhs {
#[inline]
fn sub_assign(&mut self, rhs: $rhs) {
*self = &*self - &rhs;
}
}

impl AddAssign<$rhs> for $lhs {
#[inline]
fn add_assign(&mut self, rhs: $rhs) {
*self = &*self + &rhs;
}
}

impl<'b> SubAssign<&'b $rhs> for $lhs {
#[inline]
fn sub_assign(&mut self, rhs: &'b $rhs) {
*self = &*self - rhs;
}
}

impl<'b> AddAssign<&'b $rhs> for $lhs {
#[inline]
fn add_assign(&mut self, rhs: &'b $rhs) {
*self = &*self + rhs;
}
Expand All @@ -330,14 +313,12 @@ macro_rules! impl_binops_multiplicative {
crate::impl_binops_multiplicative_mixed!($lhs, $rhs, $lhs);

impl MulAssign<$rhs> for $lhs {
#[inline]
fn mul_assign(&mut self, rhs: $rhs) {
*self = &*self * &rhs;
}
}

impl<'b> MulAssign<&'b $rhs> for $lhs {
#[inline]
fn mul_assign(&mut self, rhs: &'b $rhs) {
*self = &*self * rhs;
}
Expand Down

0 comments on commit 6425c3a

Please sign in to comment.