Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bb): define missing univ-fr operators #7859

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading