From 9cd6452f85c85a42b608e006a83d2598fedda35a Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Thu, 8 Aug 2024 19:35:42 +0000 Subject: [PATCH] chore(bb): define missing univ-fr operators --- .../ecc/groups/affine_element.hpp | 3 +++ .../ecc/groups/affine_element_impl.hpp | 6 ++++++ .../src/barretenberg/ecc/groups/element.hpp | 14 ------------- .../barretenberg/polynomials/univariate.hpp | 21 +++++++++++++++++++ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp index 7f3754c7e17..883f8bcb017 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp @@ -1,4 +1,5 @@ #pragma once + #include "barretenberg/common/serialize.hpp" #include "barretenberg/ecc/curves/bn254/fq2.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" @@ -63,6 +64,8 @@ template class alignas(64) affine_ constexpr affine_element operator+(const affine_element& other) const noexcept; + constexpr affine_element operator*(const Fr& exponent) const noexcept; + template > 255) == uint256_t(0), void>> [[nodiscard]] constexpr uint256_t compress() const noexcept; diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp index f58e6f5b7bd..1c1df91b819 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp @@ -68,6 +68,12 @@ constexpr affine_element affine_element::operator+( return affine_element(element(*this) + element(other)); } +template +constexpr affine_element affine_element::operator*(const Fr& exponent) const noexcept +{ + return bb::group_elements::element(*this) * exponent; +} + template template diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp index cb7946beb0f..4203bfdf4dd 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp @@ -153,17 +153,3 @@ template std::ostream& operator<<(std::ostrea } // namespace bb::group_elements #include "./element_impl.hpp" - -template -bb::group_elements::affine_element operator*( - const bb::group_elements::affine_element& base, const Fr& exponent) noexcept -{ - return bb::group_elements::affine_element(bb::group_elements::element(base) * exponent); -} - -template -bb::group_elements::affine_element operator*(const bb::group_elements::element& base, - const Fr& exponent) noexcept -{ - return (bb::group_elements::element(base) * exponent); -} diff --git a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp index 69ebd9765a3..beba262ca5e 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp @@ -524,6 +524,27 @@ inline void write(B& it, Univariate const& univari write(it, univariate.evaluations); } +template +Univariate operator+( + const Fr& ff, const Univariate& uv) +{ + return uv + ff; +} + +template +Univariate operator-( + const Fr& ff, const Univariate& uv) +{ + return uv - ff; +} + +template +Univariate operator*( + const Fr& ff, const Univariate& uv) +{ + return uv * ff; +} + template class UnivariateView { public: static constexpr size_t LENGTH = domain_end - domain_start;