Skip to content

Commit

Permalink
chore(bb): define missing univ-fr operators (#7859)
Browse files Browse the repository at this point in the history
The defined operators could only take a field on the right hand side.

(On the AVM side, this simplifies codegen)
  • Loading branch information
fcarreiro authored Aug 8, 2024
1 parent 4348654 commit 30d226e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include "barretenberg/common/serialize.hpp"
#include "barretenberg/ecc/curves/bn254/fq2.hpp"
#include "barretenberg/numeric/uint256/uint256.hpp"
Expand Down Expand Up @@ -63,6 +64,8 @@ template <typename Fq_, typename Fr_, typename Params> class alignas(64) affine_

constexpr affine_element operator+(const affine_element& other) const noexcept;

constexpr affine_element operator*(const Fr& exponent) const noexcept;

template <typename BaseField = Fq,
typename CompileTimeEnabled = std::enable_if_t<(BaseField::modulus >> 255) == uint256_t(0), void>>
[[nodiscard]] constexpr uint256_t compress() const noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ constexpr affine_element<Fq, Fr, T> affine_element<Fq, Fr, T>::operator+(
return affine_element(element<Fq, Fr, T>(*this) + element<Fq, Fr, T>(other));
}

template <class Fq, class Fr, class T>
constexpr affine_element<Fq, Fr, T> affine_element<Fq, Fr, T>::operator*(const Fr& exponent) const noexcept
{
return bb::group_elements::element(*this) * exponent;
}

template <class Fq, class Fr, class T>
template <typename BaseField, typename CompileTimeEnabled>

Expand Down
14 changes: 0 additions & 14 deletions barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,3 @@ template <class Fq, class Fr, class Params> std::ostream& operator<<(std::ostrea
} // namespace bb::group_elements

#include "./element_impl.hpp"

template <class Fq, class Fr, class Params>
bb::group_elements::affine_element<Fq, Fr, Params> operator*(
const bb::group_elements::affine_element<Fq, Fr, Params>& base, const Fr& exponent) noexcept
{
return bb::group_elements::affine_element<Fq, Fr, Params>(bb::group_elements::element(base) * exponent);
}

template <class Fq, class Fr, class Params>
bb::group_elements::affine_element<Fq, Fr, Params> operator*(const bb::group_elements::element<Fq, Fr, Params>& base,
const Fr& exponent) noexcept
{
return (bb::group_elements::element(base) * exponent);
}
21 changes: 21 additions & 0 deletions barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,27 @@ inline void write(B& it, Univariate<Fr, domain_end, domain_start> const& univari
write(it, univariate.evaluations);
}

template <class Fr, size_t domain_end, size_t domain_start = 0, size_t skip_count = 0>
Univariate<Fr, domain_end, domain_start, skip_count> operator+(
const Fr& ff, const Univariate<Fr, domain_end, domain_start, skip_count>& uv)
{
return uv + ff;
}

template <class Fr, size_t domain_end, size_t domain_start = 0, size_t skip_count = 0>
Univariate<Fr, domain_end, domain_start, skip_count> operator-(
const Fr& ff, const Univariate<Fr, domain_end, domain_start, skip_count>& uv)
{
return uv - ff;
}

template <class Fr, size_t domain_end, size_t domain_start = 0, size_t skip_count = 0>
Univariate<Fr, domain_end, domain_start, skip_count> operator*(
const Fr& ff, const Univariate<Fr, domain_end, domain_start, skip_count>& uv)
{
return uv * ff;
}

template <class Fr, size_t domain_end, size_t domain_start = 0, size_t skip_count = 0> class UnivariateView {
public:
static constexpr size_t LENGTH = domain_end - domain_start;
Expand Down

0 comments on commit 30d226e

Please sign in to comment.