From 021adfc95365d32313e7e05c775ece7fbf5607d8 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 24 Aug 2023 01:19:20 +0000 Subject: [PATCH 01/45] Initial work Lagrange poly def. --- .../polynomials/univariate_lagrange.hpp | 61 +++ .../polynomials/univariate_lagrange.test.cpp | 57 +++ circuits/cpp/barretenberg/spec/protogalaxy.md | 466 ++++++++++++++++++ 3 files changed, 584 insertions(+) create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp create mode 100644 circuits/cpp/barretenberg/spec/protogalaxy.md diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp new file mode 100644 index 00000000000..f996eb8ab9f --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp @@ -0,0 +1,61 @@ +#include "barycentric_data.hpp" + +/** + * @brief A container for a + * + */ +namespace proof_system::honk::sumcheck { +template class LagrangeMultiple { + public: + static constexpr std::array construct_data() + { + std::array result; + std::fill(result.begin(), result.end(), 0); + std::get(result) = 1; + return result; + } + + static constexpr std::array evaluations = construct_data(); + + template Univariate extend() + { + Univariate result; + Fr center = center_idx; + for (size_t idx = 0; idx < domain_size; idx++) { + result.evaluations[idx] = evaluations[idx]; + } + using Barycentric = BarycentricDataCompileTime; + // WORKTODO: inefficient inversions + /* Using the initial formula + L_i(k+1) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{k+1-j}{i-j} + = \frac{\prod_{j\in\{0,\ldots, k\}\setminus\{i\}}k+1-j} + {\prod_{j\in\{0,\ldots, k\}\setminus\{i\}} i-j} + = \frac{(k+1)!}{d_i\cdot (k+1-i) \cdot 1}, + */ + Fr new_value = std::get(Barycentric::lagrange_denominators); + new_value = Fr(1) / new_value; + for (size_t idx = 1; idx < 1 + domain_size; idx++) { + if (idx != domain_size - center_idx) { + new_value *= idx; + } + } + std::get(result.evaluations) = new_value; + + Fr denominator = 1; + Fr counter = 1; + /* Using the recursive formula + L_i(k+s+1) = \frac{(k+s+1)(k+s-i)}{(k+s+1-i)(s+1)} L_i(k+s). + */ + for (size_t point_idx = domain_size + 1; point_idx < num_evals; point_idx++) { + Fr point = point_idx; + new_value *= point; + new_value *= point - (Fr(1) + center); + denominator = counter * (point - center); + new_value /= denominator; + result.evaluations[point_idx] = new_value; + counter += 1; + } + return result; + } +}; +} // namespace proof_system::honk::sumcheck \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp new file mode 100644 index 00000000000..1b2713807b7 --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp @@ -0,0 +1,57 @@ +#include "univariate_lagrange.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/numeric/random/engine.hpp" +#include + +#pragma GCC diagnostic ignored "-Wunused-variable" + +using namespace proof_system::honk::sumcheck; +namespace test_univariate_lagrange { + +template class UnivariateLagrangeTest : public testing::Test { + public: + using FF_ = FF; +}; + +using FieldTypes = testing::Types; +TYPED_TEST_SUITE(UnivariateLagrangeTest, FieldTypes); + +#define ALIASES using FF = TypeParam; +// IMPROVEMENT: Can't make alias for Univariate for some reason. +// Might be convenient to solve boilerplate or repeated type aliasing +// using this or some other means. + +TYPED_TEST(UnivariateLagrangeTest, Constructors) +{ + ALIASES + constexpr size_t domain_size = 8; + constexpr size_t center_idx = 1; + auto lagrange = LagrangeMultiple(); + + const auto compute_lagrange_naive = [&](FF new_point) { + FF result = 1; + FF denominator = 1; + FF center = center_idx; + + for (size_t idx = 0; idx < domain_size; idx++) { + if (idx != center_idx) { + result *= (new_point - FF(idx)); + denominator *= (center - FF(idx)); + } + } + result /= denominator; + return result; + }; + + EXPECT_EQ(lagrange.evaluations[0], compute_lagrange_naive(0)); + EXPECT_EQ(lagrange.evaluations[1], compute_lagrange_naive(1)); + EXPECT_EQ(lagrange.evaluations[7], compute_lagrange_naive(7)); + + auto extended = lagrange.template extend<16>(); + + for (size_t idx = 0; idx < 16; idx++) { + EXPECT_EQ(extended.evaluations[idx], compute_lagrange_naive(idx)); + } +} + +} // namespace test_univariate_lagrange diff --git a/circuits/cpp/barretenberg/spec/protogalaxy.md b/circuits/cpp/barretenberg/spec/protogalaxy.md new file mode 100644 index 00000000000..8bde1360f04 --- /dev/null +++ b/circuits/cpp/barretenberg/spec/protogalaxy.md @@ -0,0 +1,466 @@ +# ProtoGalaxy Implementation Spec + +$$ +\newcommand{\bB}{\mathbb{B}} +\newcommand{\bF}{\mathbb{F}} +\newcommand{\bin}{\text{bin}} +\newcommand{\MAX}{\text{MAX}} +\newcommand{\dMAX}{d_\MAX} +\newcommand{\circuitsize}{n} +\newcommand{\Rel}{\text{Rel}} +\newcommand{\UGH}{\text{UGH}} +\newcommand{\Arith}{\text{Arith}} +\newcommand{\Perm}{\text{Perm}} +\newcommand{\Lookup}{\text{Lookup}} +\newcommand{\GenPerm}{\text{GenPerm}} +\newcommand{\Aux}{\text{Aux}} +\newcommand{\Elliptic}{\text{Elliptic}} +\newcommand{\ECCOpQueue}{\text{ECCOpQueue}} +\newcommand{\perm}{\text{perm}} +\newcommand{\pow}{\text{pow}} +\newcommand{\lookup}{\text{lookup}} +\newcommand{\Trace}{\text{Trace}} +\newcommand{\Polys}{\text{Polys}} +\newcommand{\NumPolys}{N_\Polys} +\newcommand{\ProtoGalaxy}{\text{ProtoGalaxy}} +\newcommand{\Honk}{\text{Honk}} +$$ + +TODO: names for the globals: 48; 26 +TODO: max degree is 5 (right?) and max relation length is one greater than that. +# Background +We will use [ProtoGalaxy](https://eprint.iacr.org/archive/2023/1106/1690490682.pdf) to fold [UltraGoblinHonk](https://github.com/AztecProtocol/aztec-packages/blob/master/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp) claims. The UltraGoblinHonk (UGH) proving system construct proofs for satisfying assignments for circuits built using [UltraCircuitBuilder](https://github.com/AztecProtocol/aztec-packages/blob/master/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp). The circuits built using this builder class encode application logic and witnesses in an execution trace: + +| row | ... | $w_l$ | ... | $q_r$ | ... | +|-------|-----|--------------|-----|---------------|-----| +| $0$ | * | $w_{l, 0}$ | * | $q_{r, 0}$ | * | +| $1$ | * | $w_{l, 1}$ | * | $q_{r, 1}$ | * | +| ... | ... | ... | ... | ... | ... | +| $n-1$ | * | $w_{l, n-1}$ | * | $q_{r, n-1}$ | * | + + +Using the Lagrange basis on the boolean hypercube $\bB^t$ of dimension $t = \log(n)$, this data, along with the data of additional derived witnesses ($Z_\perm$ and $Z_\lookup$) and auxiliary polynomials (Lagrange polynomials e.g.) are stored in a `GoblinUltra::ProverPolynomials` instance $\Polys$, which we can model here as a tuple of $\NumPolys$-many polynomials. The claim of interest to the UGH prover is that the full aggregated UGH relation, a polynomial in variables +$P_1,\ldots, P_{\NumPolys}$ +$$ +\begin{aligned} +\Rel_\UGH(P_1,\ldots, P_{\NumPolys}) = +&\phantom{+ \alpha^{1} \cdot } \Rel_\Arith(P_1,\ldots, P_{\NumPolys}) \\ +&+ \alpha^{1}\cdot\Rel_\Perm(P_1,\ldots, P_{\NumPolys}) \\ +&+ \alpha^{2}\cdot\Rel_\Lookup(P_1,\ldots, P_{\NumPolys}) \\ +&+ \alpha^{3}\cdot\Rel_\GenPerm(P_1,\ldots, P_{\NumPolys}) \\ +&+ \alpha^{4}\cdot\Rel_\Elliptic(P_1,\ldots, P_{\NumPolys}) \\ +&+ \alpha^{5}\cdot\Rel_\Aux(P_1,\ldots, P_{\NumPolys}) \\ +&+ \alpha^{6}\cdot\Rel_\ECCOpQueue(P_1,\ldots, P_{\NumPolys}), \\ +\end{aligned} +$$ +when evaluated on $\Polys$, gives a polynomial that vanishes on $\bB^t$. A prover can argue this claim in $O(\circuitsize)$ time by allowing a verifier to generate a challenge $\beta$ and then using a sumcheck argument for the claim +$$ +\sum_{i=0}^{n-1}\beta^i\Rel_\UGH(\bin(i)) = 0 +$$ +where $\bin(i)$ is the length-$t$ vector of binary digits of $i$. + +For comparison, ProtoGalaxy uses the notation for $\omega$ for the data encoded in $\Polys$ regarded simly as a data of vectors. Roughly speaking, the relation $\Rel_\UGH$ gets the name $f$. More precisely, $f$ is a mapping +$$f: \bF^{\NumPolys}\to \bF^\circuitsize$$ +whose image is defiend by $\circuitsize$ component functions $f_i$. In our earlier notation, $f_i(\omega)$ is defined by +$$f_i(\omega) = \Rel_\UGH(\Polys_1(\bin(i)), \ldots, \Polys_{\NumPolys}(\bin(i))).$$ + +# Mara's sketch work. + + We unroll the protocol presented in the paper. + + ### Relating Paper to Code + * $\omega$ is the Honk polynomials $\Polys$, for UGH there are 48 of them found in the GoblinUltra flavor + * these polynomials are represented in evaluation form over the boolean hypercube $\{0,1\}^t$ where $t = \log n$ and $n$ is the circuit size (note that the code and earlier Honk resources use $d$ instead of $t$). + * Honk polynomials = how we represent a circuit + * $f$ in ProtoGalaxy is the full $\Rel_{UGH}$ itself + * in Honk's sumcheck, each round constructs univariates over two consecutive rows in the table + * the $i$-th row of the execution trace is filled with the evaluation of the Honk polynomials $\Polys$ at $i$, represented as a point of the hypercube + * to represent each univariate we need $\dMAX + 1$ evaluations +* The value $f_i(\omega)$ in ProtoGalaxy is equal to $\Rel_{UGH}(\Trace_i)$, the evaluation of the full relation on the $i$-th row of the execution trace. + +## How folding transforms Aztec's architecture: +### Current Structure +* a Noir contract is a collection of functions, where each function corresponds to a seperate circuit +* assume a Noir contract has a function `foo` which then calls a function `bar` +* if the user calls `foo`, executing that Noir code will produce a proof `P_foo` for `foo` and a proof `P_bar` for `bar`. `P_foo` will be accompanied, among other stuff, by a public input which specifies that `foo` calls `bar` + * we think of this user action as a transaction and the private kernel circuit is responsible for proving it's validity; this entails recursively checking whatever functions `foo` calls +* in the example above, the private kernel will have two iterations to prove this private transaction is valid + * first iteration is `K_foo` (this is a circuit): it will recursively verify `P_foo`, take most of `foo`'s public inputs (remember `foo` is actually a circuit) and transfer them to `K_foo`, add some constraints and finally, generate `P_K_foo` + * so the structure of the `K_foo` circuit is as follows: + * public inputs are (more or less) `foo`'s public inputs as well as "bar comes after foo" + * `P_foo` also corresponds to inputs (not sure if public or private) + * the `K_foo` circuit will have a Honk verifier subcircuit for `P_foo` and some other constraints + * second iteration is `K_bar`: it recursively verifies `P_K_foo`, ensures that as part of `K_foo`s public_inputs we have "`foo` comes after `bar`", afterwards it recursively verifies `P_bar`, creates `K_bar`s public inputs from `K_foo` and `bar` and finally generates `P_K_bar` + * the structure of `K_bar` circuit is: + * public inputs of `K_foo` and `bar` more or less + * `P_bar` passed as input + * the circuit will have: + * subcircuits for verifying `P_bar` and `P_k_bar` with Honk + * constraints for verifying `bar` comes after `foo` + * and some other constraints +If `bar` was to call a function `baz` there would be another kernel iteration `K_baz` with a similar structure to `K_bar` + +### What Changes with folding +So instead of recursively proving these circuits, we fold them. This doesn't change anything in the structure of first kernel iteration but eliminates the need to have a Honk verifier circuit at iteration $i$ for recursively verifying the kernel proof from iteration $i-1$. However, each kernel iteration still Honk verifies the Noir proof of the corresponding function or otherwise we need to fold app kernel circuits as well. + +### Notation: + +* $k$ is the number of instances we fold with our accumulator, the exact value of $k$ we will use is an open question as the paper presents various techniques with trade-offs + +* $\log(n) = t$ + +* Define the vanishing polynomial as $Z(X) = \prod_{a \in \mathbb{H}}(X - a)$ where: + * In our case $\mathbb{H} = {0,\ldots, k}$ + * Its Lagrange base is $L_0(X), \ldots, L_k(X)$ where + $L_i(X) = \prod_{j\in \{0 \ldots k \},\,, j\neq i} \tfrac{(X-j)}{(i-j)}$ + + * these polynomials have degree $k$ + + + +$$\ProtoGalaxy(\Phi = ((\phi, \vec{\beta}, e), (\phi_1,\ldots, \phi_k); (\omega, \omega_1,\ldots, \omega_k)))$$ +(semicolumn separates public and private inputs) + +1. $V \rightarrow P:\delta \in \mathbb{F}$ + * to achieve this noninteractively, we add ($k + 1$) public inputs corresponding to each instance, $e$ and $\vec{\beta}$ to the transcript + * $\vec{\beta}$ has size aprox $\log(n)$ so in total we add to the transcript (i.e. hash) $log(n) + 1$ scalars and $Pub_{tot}$ group elements from all the instances $\phi$ + * $Pub_{tot} = 26k + \sum Pub_{\omega_i}$, where: + - $26$ is the number of selector polynomials whose commitments the verifier has as public inputs in $UGH$ + - $Pub_{\omega_i}$ is the number of public inputs of $\omega_i$ note that this can vary for each instance $\omega_i$ but in practice we will haave to bound $Pub_{tot}$. +2. $P, V$ compute $\vec{\delta} = (\delta, \delta^2, \ldots, \delta^{2^{t -1}})$ , which can be computed with $t-1$ squaring operations. +3. $P$ computes $F(X) = \sum_{i = 0..n-1} pow_i(\vec{\beta} + X\vec{\delta})f_i(\omega)$ where $pow_0(\vec{\beta} + X\vec{\delta}) = 1$ + * $i$ corresponds to the rows in the sumcheck matrix and $\omega$ is the full $\Honk$ relation + * this consists of 48 polynomials defined in flavor, the maximum degree among them being 5 + * unlike what happens in sumcheck, we will evaluate each full Honk relation at $i$ (we need code to do that) bu getting all the $f_i$ is a linear operation + * Computing $pow_i(\vec{\beta} + X\vec{\delta})$ + * naively, the cost of computing this is $O(n \log n)$ but the paper provides a smart way to compute it in $O(n)$ + * binary tree trick (*insert drawing*) + * following the paper notation, my understaing is + * $\vec{\beta} + X\vec{\gamma} = (\beta + X\gamma, \beta^2 + X\gamma^2, \ldots, \beta^{2^{t -1}} + X\gamma^{2^{t -1}})$ let's call this vector $\vec{v} = (v_1,..., v_t)$ + * so $pow_i(\vec{\beta} + X\vec{\gamma}) = pow_i(\vec{v}) = \prod_{j{}} v_j$ where $i = \sum_j 2^j$ + + + +* final $F$ will be a polynomial of degree $t = log(n)$ +4. $P$ sends $F_1, \ldots,F_{t}$ to $V$ +5. $V$ sends random challenge $\alpha \in \mathbb{F}$ + * In the noninteractive setting, this means adding another $logn$ scalars to the transcript +6. $P, V$ compute $F(\alpha) = e + \sum_{i = 0..t-1}F_i \alpha^i$, this is $\log n$ scalar operations +7. $P, V$ compute $\beta^*_i = \beta_i +\alpha \cdot \delta^{2^{i-1}}$ these are the elements of $\vec{\beta}^*$ and require another $\log n$ multiplication and additions of scalars +8. P computes $G(X) = \sum_{i = 0..n-1} pow_i(\vec{\beta^{*}})f_i(L_0(X)\omega + \sum_{j \in [k]} L_j(X)\omega_j)$ whose maximum degree is $dk$ + * where $d$ is the maximum degree of a relation, in our case 5 (`MAX_RELATION_LENGTH` - 1) + * the problem with the $pow_i(\vec{\beta^*})$ polynomial is that it's not preserving the nice structure presented on page 7 and we will probably have to use the binary tree trick here as well + * we can compute f_i($L_0(X)\omega + \sum_{j \in [k]} L_j(X)\omega_j$) by partially reusing the sumcheck code for computing univariates + * the current sumcheck code, for $k \in \{0, 1\}$ computes $L_0(X)f_i(\omega) + L_1(X)f_{i+1}(\omega)$ which is obtained by computing $d+1$ evaluations + * in our case we will need $dk + 1$ evaluation points for computing the polynomial and then apply $f_i$ for each row +9. P computes polynomial $K$ and sends its coefficients +$G(X) = F(\alpha)L_0(X) + Z(X)K(X)$ + * if $G(X)$ has degree $dk$, so will $Z(X)K(X)$ (because $F(\alpha)L_0(X)$ has degree $k$) + and given $Z(X)$ has degree $k+1$,$K(X)$ will have degree k(d-1)-1 + * We need to compute $K$ without FFTs (because we might want to work with Grumpkin and also we don't want to use FFTs in UGH) + * Option 1: schoolbook polynomial division (moonmath, page 32)[https://github.com/LeastAuthority/moonmath-manual] + * Option 2: Zac's idea: + * recall the degree of $K$ is $k(d-1)-1$ and thus we need $k(d-1)$ evaluations to represent it + * we can evaluate $G$, $Z$, $L_0$ at $k(d-1)$ points and compute the division in evaluation form to obtain $K$ + * note, all this points must be $\not\in \mathbb{H}$ where $\mathbb{H}$ is the vanishing set of $Z$ + * then we can convert $K$ to coefficient form and send the coefficients to the verifier +11. V sends $\gamma$ + * in the noninteractive setting we add $K$'s coefficients (scalars) to the transcript +12. $P, V$ compute $e^* = F(\alpha)L_0(\gamma) + Z(\gamma)K(\gamma)$ which is (d-1)k scalar operations +11. At the end of the pr + * $V: \phi^* = L_0(\gamma)\phi + \sum_{i \in [k]} L_i(\gamma)\phi_i$ + * as the public inputs are group elements, we require $Pub_{tot}$ ecc scalar multiplication which are going to be offset to the ECC VM + * P: $\omega^* = L_0(\gamma)\omega + \sum_{i \in [k]} L_i(\gamma)\omega_i$ + +ProtoGalaxy requires 3 rather than $2k\log n$ ($\log n$ for sumcheck and $\log n$ zeromorph + gemini) values from the random oracle. + + +--- +## Scratch work on computation of $G(Y)$ + + +We have reserved $X$ for the names of the inputs to the prover polynomials, the variables on the boolean hypercube, e.g., $w_l = w_l(X_1, \ldots, X_d)$. So let's use $Y$ for the perturbation and combiner variables in PG. This agrees with the notation of Protostar. Let's use $P$ for the inputs to the relations. + +How do we interpret the definition of $G(Y)$? In the paper we write +$$G(Y) += \sum_{i=0}^{n-1}\pow_i(\beta^*)f_i\left(\sum_{j=0}^{k}L_j(Y)\omega_j\right) += \sum_{i=0}^{n-1}\pow_i(\beta^*)\Rel_\UGH\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{i}\right) +$$ + +To rewrite this in our terms, the instances $\omega_0,\omega_1, \ldots, \omega_k$ correspond to `honk::flavor::Ultra::ProverPolynomials` instances $\Polys^{(0)}, \Polys^{(1)}, \ldots, \Polys^{(k)}$ and the polynomial $G$ becomes +$$G(Y) += \sum_{i=0}^{n-1}\pow_i(\beta^*)\Rel_\UGH\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{i}\right) +$$ + +Let's focus on the sub-term $\Rel_\Arith\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{i}\right).$ Using the indexing of `honk::flavor::Ultra`, we have + +$$\Rel_\UGH(P_1,\ldots, P_{\NumPolys}) = P_{5}P_{25}P_{26} + P_{1}P_{25} + P_{2}P_{26} + P_{3}P_{27} + P_{0}.$$ +To be clear, if $\Polys$ is an instance of `honk::flavor::Ultra::ProverPolynomials`, then + +$$\Rel_\UGH(\Polys) := \Rel_\UGH(\Polys_1,\ldots, \Polys_{\NumPolys}) = q_{m}w_lw_r + q_{l}w_{l} + q_{r}w_{r} + q_{o}w_{o} + q_{c}.$$ + +Similarly, with the superscript $(j)$ used in the natural way, +$$\begin{aligned} +\Rel_\Arith\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}\right) +&:= \Rel_\Arith\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{1}, + \ldots, \sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{\NumPolys}\right) \\ +&= \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{m}\right) + \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{l}\right) + \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{r}\right) \\ +&\hphantom{...}+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{l}\right) + \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{l}\right)\\ +&\hphantom{...}+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{r}\right) + \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{r}\right)\\ +&\hphantom{...}+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{o}\right) + \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{o}\right)\\ +&\hphantom{...}+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{c}\right) +\end{aligned} +$$ +which is a polynomial of degree $3\circuitsize$ (in general, $G$ has degree $\dMAX\circuitsize$ where $\dMAX=5$ is one less than the maximum `RELATION_LENGTH` over the relations in `honk::flavor::Ultra::Relations`). + +### Efficient extension of Lagrange polynomials + +Note: this is all done at compilation time, so it's less important to be efficient, but I write down the ideas nonetheless. We will need to compute products of Lagrange polynomials of degree $\dMAX$. Each Lagrange polynomial has degree $k$, hence is determined by $k+1$ evaluations , hence a product of $\dMAX$ such polynomials will be represented by $k\dMAX+1$ values. To precompute all extensions of $L_0,\ldots, L_k$, we would have to store $k\cdot (\dMAX-1)\cdot(k+1)$ field elements. With values $\dMAX = 5$ and $k+1=128$, this is $127 * 5 * 4 * 128 * 32 = 10\_403\_840$ bytes of data. So probably we can just do this, but it will be important to be efficient at compilation time. + +#### The formulas +Recall that the barycentric evaluation of polynomials represented by their values works as follows (cf [Vitalik's post](https://hackmd.io/@vbuterin/barycentric_evaluation)). I $P(X)$ is a polynomial represented by its evaluations $(y_1,\ldots, y_N)$ at points $(x_1, \ldots, x_N)$ , then $P(X) = \sum_i y_iL_i(X)$ where $L_i(X)$ is the Lagrange basis polynomial centered at $x_i$. By definition, +$$ +L_i(X) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{X-x_j}{x_i-x_j}. +$$ +Hence, defining $M(X) = \prod_{j\in\{1,\ldots, N\}}(X-x_j)$ and $d_i = \prod_{j\in\{1,\ldots, N\}\setminus\{i\}}x_i-x_j$, we have +$$P(X) += \sum_i y_iL_i(X) += \sum_i y_i\prod_{j\in\{1,\ldots, N\}\setminus\{i\}}\frac{X-x_j}{x_i-x_j} += M(X)\sum_i \frac{y_i}{d_i(X-x_i)}. +$$ +This means that, naively, one barycentric evaluation costs: $N$ subtractions and $N-1$ multiplications (to compute the value of $M$), $N$ multiplications (to divide $y_i/d_i$, assuming $d_i$ is inverted at compilation time), $N$ subtractions (to compute the $X-x_i$ values), $3N$ multiplications (amortized cost to batch invert the $X-x_i$ values), $N$ multiplications (to compute the summands), $N-1$ additions, and a final multiplication. The leading term here is $6N$ multiplications to get a single value. Hence, to extend to an additional set $x'_1, \ldots, x'_N$ of $N$ points costs about $6N^2$ operations. + +However, with special structure we can do much better. We consider the case where $P(X)$ is _itself_ a Lagrange polynomial $L_i$, $N = k+1$ for some $k$, and $x_i = i-1$, so the domain of interest is, $\{0, 1, \ldots, k\}$ and we extend to $\{0, 1, \ldots, 2k+1\}$ (so $x'_i = i+k$). In that case note that +$$ +L_i(k+1) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{k+1-j}{i-j} += \frac{\prod_{j\in\{0,\ldots, k\}\setminus\{i\}}k+1-j} + {\prod_{j\in\{0,\ldots, k\}\setminus\{i\}} i-j} += \frac{(k+1)!}{d_i\cdot (k+1-i) \cdot 1}, +$$ +$$ +L_i(k+2) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{k+2-j}{i-j} += \frac{(k+2)!}{d_i\cdot (k+2-i) \cdot 1!} += \frac{(k+2)(k+1-i)}{(k+2-i)\cdot 2} L_i(k+1), +$$ +and in general, +$$ +L_i(k+s+1) = \frac{(k+s+1)(k+s-i)}{(k+s+1-i)(s+1)} L_i(k+s). +$$ +Hence we can compute the extension to an additional $N$ values more efficiently. + +Moreover, note that the same recursive formula holds when $L_i$ is replaced by $cL_i$ for some constant $c$. This means enables the approach using 'successive extensions' we have taken elsewhere in the relations (or at least we used to? Maybe that optimization went away?). +### Comparison of cost models + +With this new responsibility for execution of the relations comes a different cost model. Namely, before, it would have been efficient to compute part of the arithmetic relation as in +$$ +q_m w_l w_r + q_{l} w_{l} = w_l\cdot (q_m w_r + q_l) \qquad 2\times,\, 1+ \text{ on values} +$$ +Reusing the code path for the combiner polynomial combination, would likely look like this. We would want to compute +$$ +\left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{l}\right) +\cdot \left(\left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{m}\right) +\left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{r}\right) ++ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{l}\right)\right). +$$ +Each $L_j$ is naturally represented by $k+1$ values, meaning the resulting expression would be represented by $3(k+1)$ values. Extending each $L_j$ requires $2\cdot 2(k+1)$ multiplications and $2(k+1)$ divisions (could batch invert, equivalent to about $3\cdot (2k+1) $ muls). Then each prover polynomial value would scale a Lagrange polynomial's value ($4 \cdot (2(k+1)+1)$ muls). Then we would assble the relation: $2\cdot 2(k+1)$ muls and $2(k+1)$ additions. So altogether we have: about $22k$ muls + +Alternatively: compute the above as +$$ +\sum_{j_1, j_2, j_3 = 0}^{k}\Big(L_{j_1}(Y)L_{j_2}(Y)L_{j_3}(Y)\Big) + q^{(j)}_{m}w^{(j)}_{l}w^{(j)}_{r} ++ \sum_{j_1, j_2 = 0}^{k} \Big(L_{j_1}(Y)L_{j_2}(Y)\Big) + q^{(j)}_{l}w^{(j)}_{l} +$$ + +### Comparison of cost models take 2 + +Setting: we focus on the highest-degree ($=d$) monomial term in the PG combiner polynomial in the case where we are folding $k$ relations. Our target values we expect are $k=127$, $d=5$. + +For each $\ell=1,\ldots, d$ there are $k+1$ polynomials $P_\ell^{(0)},\ldots,\, P_\ell^{(k)}$ described by $n$ evaluations over $\bB^d$. Denote by $P_{\ell, i}^{j} = P_{\ell}^{j}(\bin(i))$. We will be interested in computing the terms +$$ +\prod_{\ell=1}^d L_{j_\ell}(Y)P_{\ell, i}^{(j_\ell)} +$$ +for all $i=0,\ldots, n-1$, for every typle $(j_1, \ldots, j_d)\in \{0,\ldots, k\}^d$. Here each $L_j$ is the Lagrange polynomial on $\{0,\ldots, k\}$ centered at $j$, and extended over the set $\{0,\ldots, kd\}$ (i.e., it is regarded as the vector of its $kd+1$ values over that set). For now we ignore a small optmization of using the sparseness of the $L_j$ in the first $k+1$ terms in this representation. + +#### Naive way +This is the way that would let us reuse our existing relations code: +$$ +\prod_{\ell=1}^d \left(L_{j_\ell}(Y)P_{\ell, i}^{(j_\ell)}\right) +$$ +- Each inner term: $kd+1$ muls, so computing all of them is $d\cdot (kd+1)$ +- Multiplying the inner terms: $(d-1)(kd+1)$ muls +- Doing this for all $i$: multiply both of these preceding counts by $n$ +- Do this for every index $j_*$: multiply both runnin counts by $(k+1)^d$. + +Altogether the cost to compute these $n(k+1)^d$ terms is +$$ +(d(kd+1)+((d-1)(kd+1)))\cdot n\cdot (k+1)^d = n(2d-1)(k+1)^{d+1} +$$ + +If we could tolerate $(kd+1)\times$ as much memory usage, we could hold on to the inner terms $L_{j_\ell}(Y)P_{\ell, i}^{(j_\ell)}$. Using the target values, this factor is $636$. If each circuit had size $2^17$, our storage for the polynomials $P_\ell^{(j)}$ witness is $2^{17}*636*32 = 636*2^{22}$ $636*4 = 2544$ MiB. We dream of getting the circuit size down to $2^{15}$, which brings the storage for a polynomail down to 636 MiB. And this is just for one polynomial. + +Alternatively, if we were to reduce $k+1$ to $32$, then then the $636$ factor becomes 156, and so we see a 75% reduction in the above numbers. + +#### Isolating monomial terms +This way would require us isolating homogeneous components of the relations. We group terms as in +$$ +\left(\prod_{\ell=1}^d L_{j_\ell}\right)\left(\prod_{\ell=1}^d P_{\ell, i}^{(j_\ell)}\right) +$$ +- Taking the product of the Lagrange polynomials: $(d-1)(kd+1)$ muls. +- Multiplying the polynomial values $d-1$ muls +- Multiplying against the Lagrange term: $kd+1$ muls +- Doing the previous two steps for all $i$: multiply the counts by $n$ +- Do this for every index $j_*$: multiply both of the preceding counts by $(k+1)^d$. + +Altogether the cost to compute these $n(k+1)^d$ terms is +$$ +\begin{align*} +((d-1)(kd+1) + ((d-1) + (kd+1)) n) (k+1)^d \\ += nd(k+1)^{d+1} + (d-1)(kd+1)(k+1)^d +\end{align*} +$$ + +Asymptotically in $n$, this is a $\frac{d}{2d-1} = \frac{5}{9}$ reduction in costs. The total cost of storing all of the Lagrange polynomial products is $(kd+1)(k+1)^d$ field elements, which for our target values is $636\cdot 2^{7*5}$ bytes, or $636 \cdot 2^{5} = 20352$ GiB of information. If we were to reduce $k$ to $32$, then we would see $156\cdot 2^{5*5}$ bytes, or $156 \cdot 2^{5} = 4992$ MiB of information. + +--- + +## Plan for interfaces + +```c++ +// for simplicity I ommitted header/source file separation and shared_ptr mentions +template class FoldingComposer { + using CircuitBuilder = typename Flavor::CircuitBuilder; + // The ProvingKey and VerificationKey in the FoldingFlavor will also have beta and e (which will be update to Beta* and e* in construct_folding_proof and verify_folding_proof) + // what if beta = randomizer_term + // and e = relaxation_term (or are we happy with beta and e?) + using ProvingKey = typename Flavor::ProvingKey; + using VerificationKey = typename Flavor::VerificationKey; + + // Produced by the FoldingProver and FoldingVerifier, respectively, in the previous folding stage. + // If this is the first folding stage, we take k+1 CircuitBuilders and we initialise + // acc_proving_key and acc_verification_key from the first CircuitBuilder. + ProvingKey acc_proving_key; + VerificationKey acc_verification_key; + + // Should these be encapsulated in an array of FoldingInstance structs? + // Meh, these are given as parameters to different structs so maybe it makes sense to stay separate + CircuitBuilder[] circuit_builders; + ProvingKey[] inst_proving_keys[]; + VerificationKey[] inst_verification_keys; + + FoldingComposer(); + // We will use this to create a FoldingComposer after we have folded at least once + FoldingComposer(ProvingKey pk, VerificationKey vk); + + ... + + FoldingProver create_prover (CircuitBuilder[] builders) { + // if this is the first time we fold i.e acc_proving_key is null, need to initialise the acc_proving_key with the first Circuit_Builder + // is this extra if clause ok to have? + + // Finalise the k Circuit Builders - this is needed to be able to + // build the polynomials. Also, in brute force recursion, we would finalise each + // CircuitBuilder in part. The only issue is that the prover needs more memory available at once. + // TODO: based on memory estimates of FoldingProver decide if this is acceptable + + // compute the k proving keys and the k witnesses + // the witnesses are also stored in their corresponding proving key + + FoldingProver prover(acc_proving_key, inst_proving_keys); + return prover; + } + + FoldingVerifier create_verifier(CircuitBuilder[] builders) { + // if this is the first time we fold i.e. acc_verifier_key is null, need to initialise the acc_verification_key with the first Circuit_Builder + // is this extra if clause ok to have? + + // Compute the k verification keys + + FoldingVerifier verifier(acc_verification_key, inst_verification_keys); + } + + template struct FoldingProof { + using ProvingKey = typename Flavor::ProvingKey; + using FF = typename Flavor::FF; + + // ONLY non-constant coefficients of F + std::vector pow_perturbation_coeffs; + // Coefficients of K + std::vector combiner_quotient_coeffs; + + } + + template class FoldingProver { + using ProvingKey = typename Flavor::ProvingKey; + // The FoldingProof goes to the FoldingVerifier and the ProvingKey will be used to construct the next + // FoldingComposer + std::pair construct_folding_proof() { + } + + } + + template class FoldingVerifier { + using VerificationKey = typename Flavor::VerificationKey; + + VerificationKey verify_folding_proof(FoldingProof proof){ + } + } +} + +// It would be nice to have only a DeciderFlavor and instantiate the UltraConmposer with +// that but the CircuitBuilder is very ingrained in the UltraComposer and we only have a +// ProvingKey and VerificationKey at this stage +template class DeciderComposer { + // A DeciderFlavor will not have a CircuitBuilder! but only the ProvingKey and VerificationKey obtained from the FoldingProver and FoldingVerifier + using ProvingKey = typename Flavor::ProvingKey; + using VerificationKey = typename Flavor::VerificationKey; + // The PCS appears in the Decider because we run a full Honk proof + using PCS = typename Flavor::PCS; + using CommitmentKey = typename Flavor::CommitmentKey; + using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; + + // We should probably have no empty constructor for the DeciderComposer + DeciderComposer(ProvingKey pk, VerificationKey vk); + + // Is a DeciderProver and DeciderVerifier overkill? + // Potentially yes because we could instantiate an UltraProver and UltraVerifier with a DeciderFlavor + bool decide() { + compute_commitment_key(...) + UltraProver_ prover(proving_key, verification_key); + auto proof = prover.construct_proof(); + UltraVerifier_ verifier(verification_key); + return verifier.verify_proof(proof); + } +} +``` +### How does this change the way things are done in the circuits library + +Currently in the circuits library, after `stdlib::recursion::verify_proof` has been called once (`verify_proof` is responsible for recursive verification), an `AggregationObject` is constructed, whose `aggregate` method incrementally continues to verify proofs, wtih folding this could change to something like below + +```c++ + // the AggregationObject needs to only gather k CircuitBuilders somehow + auto circuit_builders = ... + // iteration #1 of folding + FoldingComposer composer = FoldingComposer(); + auto prover = composer.create_folding_prover(circuit_builders); + // this is not correct C++ syntax, use std::pair or std::tuple + auto (folding_proof, acc_proving_key) = prover.construct_folding_proof(); + auto verifier = composer.create_folding_verifier(circuit_builders); + auto acc_verifying_key = verifier.verify_folding_proof(folding_proof); + + // in practice the FoldingVerifier will be a RecursiveVerifier + + // Option 1: we want to fold again + FoldingComposer composer = FoldingComposer(acc_proving_key, acc_verifying_key); + // same thing again + + // Option 2: we want to decide + DeciderComposer composer = DeciderComposer(acc_proving_key, acc_verifying_key); + auto result = composer.decide() + +``` \ No newline at end of file From 868227b38221c5e0fe088e3238ac7007a51443dc Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 24 Aug 2023 17:04:44 +0000 Subject: [PATCH 02/45] Refactor to all compile time. --- .../polynomials/univariate_lagrange.hpp | 42 +++++++++---------- .../polynomials/univariate_lagrange.test.cpp | 11 ++--- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp index f996eb8ab9f..3ec4935ec5a 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp @@ -5,33 +5,23 @@ * */ namespace proof_system::honk::sumcheck { -template class LagrangeMultiple { +template class LagrangeMultiple { public: - static constexpr std::array construct_data() + static constexpr std::array construct_data() { - std::array result; + std::array result; std::fill(result.begin(), result.end(), 0); std::get(result) = 1; - return result; - } - - static constexpr std::array evaluations = construct_data(); - template Univariate extend() - { - Univariate result; - Fr center = center_idx; - for (size_t idx = 0; idx < domain_size; idx++) { - result.evaluations[idx] = evaluations[idx]; - } - using Barycentric = BarycentricDataCompileTime; - // WORKTODO: inefficient inversions - /* Using the initial formula + /* Compute first value outside of domain, i.e., at the point == domain_size (here, k+1): L_i(k+1) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{k+1-j}{i-j} = \frac{\prod_{j\in\{0,\ldots, k\}\setminus\{i\}}k+1-j} {\prod_{j\in\{0,\ldots, k\}\setminus\{i\}} i-j} = \frac{(k+1)!}{d_i\cdot (k+1-i) \cdot 1}, */ + // WORKTODO: inefficient inversions + using Barycentric = BarycentricDataCompileTime; + Fr center = center_idx; Fr new_value = std::get(Barycentric::lagrange_denominators); new_value = Fr(1) / new_value; for (size_t idx = 1; idx < 1 + domain_size; idx++) { @@ -39,23 +29,33 @@ template class LagrangeMultipl new_value *= idx; } } - std::get(result.evaluations) = new_value; + std::get(result) = new_value; - Fr denominator = 1; - Fr counter = 1; /* Using the recursive formula L_i(k+s+1) = \frac{(k+s+1)(k+s-i)}{(k+s+1-i)(s+1)} L_i(k+s). */ + Fr denominator = 1; + Fr counter = 1; for (size_t point_idx = domain_size + 1; point_idx < num_evals; point_idx++) { Fr point = point_idx; new_value *= point; new_value *= point - (Fr(1) + center); denominator = counter * (point - center); new_value /= denominator; - result.evaluations[point_idx] = new_value; + result[point_idx] = new_value; counter += 1; } return result; } + + // WORKTODO: faster with std::valarray? + static constexpr std::array evaluations = construct_data(); + + // WORKTODO: model for successive extension + Univariate operator*=(Fr scalar){ + auto result = Univariate(evaluations); + result *= scalar; + return result; + } }; } // namespace proof_system::honk::sumcheck \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp index 1b2713807b7..da41db6174f 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp @@ -25,8 +25,9 @@ TYPED_TEST(UnivariateLagrangeTest, Constructors) { ALIASES constexpr size_t domain_size = 8; + constexpr size_t num_evals = 16; constexpr size_t center_idx = 1; - auto lagrange = LagrangeMultiple(); + auto lagrange = LagrangeMultiple(); const auto compute_lagrange_naive = [&](FF new_point) { FF result = 1; @@ -43,14 +44,8 @@ TYPED_TEST(UnivariateLagrangeTest, Constructors) return result; }; - EXPECT_EQ(lagrange.evaluations[0], compute_lagrange_naive(0)); - EXPECT_EQ(lagrange.evaluations[1], compute_lagrange_naive(1)); - EXPECT_EQ(lagrange.evaluations[7], compute_lagrange_naive(7)); - - auto extended = lagrange.template extend<16>(); - for (size_t idx = 0; idx < 16; idx++) { - EXPECT_EQ(extended.evaluations[idx], compute_lagrange_naive(idx)); + EXPECT_EQ(lagrange.evaluations[idx], compute_lagrange_naive(idx)); } } From 06a796b37ae064bb6c25476590a46c0097dd08f9 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 24 Aug 2023 17:21:54 +0000 Subject: [PATCH 03/45] Refactor to subclass. --- .../honk/sumcheck/polynomials/univariate.hpp | 1 + .../sumcheck/polynomials/univariate_lagrange.hpp | 16 ++++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp index 948382b8453..c58242674d2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp @@ -14,6 +14,7 @@ template class Univariate { public: static constexpr size_t LENGTH = _length; + // WORKTODO: try out std::valarray? std::array evaluations; Univariate() = default; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp index 3ec4935ec5a..d6487efe046 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp @@ -1,13 +1,16 @@ #include "barycentric_data.hpp" +#include "univariate.hpp" /** * @brief A container for a * */ namespace proof_system::honk::sumcheck { -template class LagrangeMultiple { +template +class LagrangeMultiple : public Univariate { public: - static constexpr std::array construct_data() + // WORKTODO: model for successive extensions, including with scalar multiples + static constexpr std::array construct_evaluations() { std::array result; std::fill(result.begin(), result.end(), 0); @@ -48,14 +51,7 @@ template cla return result; } - // WORKTODO: faster with std::valarray? - static constexpr std::array evaluations = construct_data(); + consteval LagrangeMultiple() { this->evaluations = construct_evaluations(); }; - // WORKTODO: model for successive extension - Univariate operator*=(Fr scalar){ - auto result = Univariate(evaluations); - result *= scalar; - return result; - } }; } // namespace proof_system::honk::sumcheck \ No newline at end of file From 9e44ce55f5fd7b7d8d6302fa4f10d62a2d3cb22d Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 28 Aug 2023 01:24:16 +0000 Subject: [PATCH 04/45] Light renaming and add comments. --- .../relations/arithmetic_relation.hpp | 41 +++++++++++-------- .../sumcheck/relations/auxiliary_relation.hpp | 2 +- .../relations/ecc_op_queue_relation.hpp | 2 +- .../sumcheck/relations/elliptic_relation.hpp | 2 +- .../relations/gen_perm_sort_relation.hpp | 2 +- .../sumcheck/relations/lookup_relation.hpp | 2 +- .../relations/permutation_relation.hpp | 20 ++++----- .../sumcheck/relations/relation_types.hpp | 11 +++-- .../relations/ultra_arithmetic_relation.hpp | 2 +- 9 files changed, 46 insertions(+), 38 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp index e9de26471ca..1e82e1be25f 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp @@ -8,6 +8,7 @@ namespace proof_system::honk::sumcheck { +// WORKTODO: ... this is not a base class. template class ArithmeticRelationBase { public: // 1 + polynomial degree of this relation @@ -19,41 +20,45 @@ template class ArithmeticRelationBase { /** * @brief Expression for the StandardArithmetic gate. - * @details The relation is defined as C(extended_edges(X)...) = + * @details The relation is defined as * (q_m * w_r * w_l) + (q_l * w_l) + (q_r * w_r) + (q_o * w_o) + q_c * - * @param evals transformed to `evals + C(extended_edges(X)...)*scaling_factor` - * @param extended_edges an std::array containing the fully extended Univariate edges. - * @param parameters contains beta, gamma, and public_input_delta, .... - * @param scaling_factor optional term to scale the evaluation before adding to evals. + * @param accumulator the term being calculated by a sequence of calls to this function + * @param new_term the term to be accumulated + * @param parameters inputs not varying between successive executions of this function + * @param scaling_factor term to scale the new accumulator contribution by before incorporating it + * @todo WORKTODO: Why isn't scaling_factor in the parameters? It varies between executions? */ template - void static add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& accumulator, - const auto& extended_edges, - const RelationParameters&, - const FF& scaling_factor) + void static accumulate(typename AccumulatorTypes::Accumulators& accumulators, + const auto& new_term, + [[maybe_unused]]const RelationParameters& parameters, + const FF& scaling_factor) { // OPTIMIZATION?: Karatsuba in general, at least for some degrees? // See https://hackmd.io/xGLuj6biSsCjzQnYN-pEiA?both using View = typename std::tuple_element<0, typename AccumulatorTypes::AccumulatorViews>::type; - auto w_l = View(extended_edges.w_l); - auto w_r = View(extended_edges.w_r); - auto w_o = View(extended_edges.w_o); - auto q_m = View(extended_edges.q_m); - auto q_l = View(extended_edges.q_l); - auto q_r = View(extended_edges.q_r); - auto q_o = View(extended_edges.q_o); - auto q_c = View(extended_edges.q_c); + auto w_l = View(new_term.w_l); + auto w_r = View(new_term.w_r); + auto w_o = View(new_term.w_o); + auto q_m = View(new_term.q_m); + auto q_l = View(new_term.q_l); + auto q_r = View(new_term.q_r); + auto q_o = View(new_term.q_o); + auto q_c = View(new_term.q_c); auto tmp = w_l * (q_m * w_r + q_l); tmp += q_r * w_r; tmp += q_o * w_o; tmp += q_c; tmp *= scaling_factor; - std::get<0>(accumulator) += tmp; + std::get<0>(accumulators) += tmp; }; }; +// WORKTODO: the field type should be supplied through the base class? +// ...moreover, should just be hidden in the relation parameters? +// WORKTODO: make these decisions then propagate to other relations template using ArithmeticRelation = RelationWrapper; } // namespace proof_system::honk::sumcheck diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp index 7d3123592ba..408e5add32d 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp @@ -58,7 +58,7 @@ template class AuxiliaryRelationBase { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& accumulators, + inline static void accumulate(typename AccumulatorTypes::Accumulators& accumulators, const auto& extended_edges, const RelationParameters& relation_parameters, const FF& scaling_factor) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp index 20ce470587f..44f70c52e4b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp @@ -44,7 +44,7 @@ template class EccOpQueueRelationBase { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - void static add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& accumulators, + void static accumulate(typename AccumulatorTypes::Accumulators& accumulators, const auto& extended_edges, const RelationParameters&, const FF& scaling_factor) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp index d63fd5ac4ff..b9734fb6db1 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp @@ -29,7 +29,7 @@ template class EllipticRelationBase { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - static void add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& accumulators, + static void accumulate(typename AccumulatorTypes::Accumulators& accumulators, const auto& extended_edges, const RelationParameters&, const FF& scaling_factor){ diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp index 248822e00d9..ce16b2064f2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp @@ -36,7 +36,7 @@ template class GenPermSortRelationBase { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - void static add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& accumulators, + void static accumulate(typename AccumulatorTypes::Accumulators& accumulators, const auto& extended_edges, const RelationParameters&, const FF& scaling_factor) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp index 56ff50447fd..fa5af543e26 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp @@ -161,7 +161,7 @@ template class LookupRelationBase { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& accumulators, + inline static void accumulate(typename AccumulatorTypes::Accumulators& accumulators, const auto& extended_edges, const RelationParameters& relation_parameters, const FF& scaling_factor) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp index c3deb11fcf1..2120f3588e7 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp @@ -74,10 +74,10 @@ template class PermutationRelationBase { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& accumulator, - const auto& input, - const RelationParameters& relation_parameters, - const FF& scaling_factor) + inline static void accumulate(typename AccumulatorTypes::Accumulators& accumulators, + const auto& input, + const RelationParameters& relation_parameters, + const FF& scaling_factor) { const auto& public_input_delta = relation_parameters.public_input_delta; @@ -89,7 +89,7 @@ template class PermutationRelationBase { auto lagrange_last = View(input.lagrange_last); // Contribution (1) - std::get<0>(accumulator) += + std::get<0>(accumulators) += (((z_perm + lagrange_first) * compute_grand_product_numerator(input, relation_parameters, 0)) - ((z_perm_shift + lagrange_last * public_input_delta) * @@ -102,7 +102,7 @@ template class PermutationRelationBase { auto lagrange_last = View(input.lagrange_last); // Contribution (2) - std::get<1>(accumulator) += (lagrange_last * z_perm_shift) * scaling_factor; + std::get<1>(accumulators) += (lagrange_last * z_perm_shift) * scaling_factor; } }; }; @@ -176,10 +176,10 @@ template class UltraPermutationRelationBase { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& accumulators, - const auto& extended_edges, - const RelationParameters& relation_parameters, - const FF& scaling_factor) + inline static void accumulate(typename AccumulatorTypes::Accumulators& accumulators, + const auto& extended_edges, + const RelationParameters& relation_parameters, + const FF& scaling_factor) { const auto& public_input_delta = relation_parameters.public_input_delta; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp index e66cc8f9800..44ab8620dd3 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp @@ -67,10 +67,12 @@ inline typename std::tuple_element<0, typename AccumulatorTypes::AccumulatorView * @tparam FF * @tparam RelationBase Base class that implements the arithmetic for a given relation (or set of sub-relations) */ +// WORKTODO: RelationWrapper is not a Relation(Base), so there shouldn't be inheritance here. template typename RelationBase> class RelationWrapper : public RelationBase { private: + // WORKTODO: does these templates being defined inside of here mean we can't reuse their instantiations? template struct UnivariateAccumulatorTypes { - using Accumulators = std::tuple...>; + using Accumulators = std::tuple...>; // Values extracted from relation. using AccumulatorViews = std::tuple...>; }; template struct ValueAccumulatorTypes { @@ -81,18 +83,19 @@ template typename RelationBase> class Relation public: using Relation = RelationBase; using UnivariateAccumTypes = typename Relation::template AccumulatorTypesBase; + // WORKTODO: the lengths do nothing in the case of values? using ValueAccumTypes = typename Relation::template AccumulatorTypesBase; using RelationUnivariates = typename UnivariateAccumTypes::Accumulators; using RelationValues = typename ValueAccumTypes::Accumulators; static constexpr size_t RELATION_LENGTH = Relation::RELATION_LENGTH; - inline void add_edge_contribution(auto& accumulator, + inline void add_edge_contribution(RelationUnivariates& accumulator, const auto& input, const RelationParameters& relation_parameters, const FF& scaling_factor) const { - Relation::template add_edge_contribution_impl( + Relation::template accumulate( accumulator, input, relation_parameters, scaling_factor); } @@ -101,7 +104,7 @@ template typename RelationBase> class Relation const RelationParameters& relation_parameters, const FF& scaling_factor = 1) const { - Relation::template add_edge_contribution_impl( + Relation::template accumulate( accumulator, input, relation_parameters, scaling_factor); } diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp index 6127a39e19c..e64ad40ddc4 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp @@ -70,7 +70,7 @@ template class UltraArithmeticRelationBase { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - void static add_edge_contribution_impl(typename AccumulatorTypes::Accumulators& evals, + void static accumulate(typename AccumulatorTypes::Accumulators& evals, const auto& extended_edges, const RelationParameters&, const FF& scaling_factor){ From e027cb4d55383bd1943c2fcf2277c0cb2cb6fcc5 Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 30 Aug 2023 16:16:57 +0000 Subject: [PATCH 05/45] Cleanup --- .../polynomials/univariate_lagrange.hpp | 57 --- .../polynomials/univariate_lagrange.test.cpp | 52 -- .../relations/arithmetic_relation.hpp | 2 +- .../sumcheck/relations/relation_types.hpp | 3 +- circuits/cpp/barretenberg/spec/protogalaxy.md | 466 ------------------ 5 files changed, 3 insertions(+), 577 deletions(-) delete mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp delete mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp delete mode 100644 circuits/cpp/barretenberg/spec/protogalaxy.md diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp deleted file mode 100644 index d6487efe046..00000000000 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "barycentric_data.hpp" -#include "univariate.hpp" - -/** - * @brief A container for a - * - */ -namespace proof_system::honk::sumcheck { -template -class LagrangeMultiple : public Univariate { - public: - // WORKTODO: model for successive extensions, including with scalar multiples - static constexpr std::array construct_evaluations() - { - std::array result; - std::fill(result.begin(), result.end(), 0); - std::get(result) = 1; - - /* Compute first value outside of domain, i.e., at the point == domain_size (here, k+1): - L_i(k+1) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{k+1-j}{i-j} - = \frac{\prod_{j\in\{0,\ldots, k\}\setminus\{i\}}k+1-j} - {\prod_{j\in\{0,\ldots, k\}\setminus\{i\}} i-j} - = \frac{(k+1)!}{d_i\cdot (k+1-i) \cdot 1}, - */ - // WORKTODO: inefficient inversions - using Barycentric = BarycentricDataCompileTime; - Fr center = center_idx; - Fr new_value = std::get(Barycentric::lagrange_denominators); - new_value = Fr(1) / new_value; - for (size_t idx = 1; idx < 1 + domain_size; idx++) { - if (idx != domain_size - center_idx) { - new_value *= idx; - } - } - std::get(result) = new_value; - - /* Using the recursive formula - L_i(k+s+1) = \frac{(k+s+1)(k+s-i)}{(k+s+1-i)(s+1)} L_i(k+s). - */ - Fr denominator = 1; - Fr counter = 1; - for (size_t point_idx = domain_size + 1; point_idx < num_evals; point_idx++) { - Fr point = point_idx; - new_value *= point; - new_value *= point - (Fr(1) + center); - denominator = counter * (point - center); - new_value /= denominator; - result[point_idx] = new_value; - counter += 1; - } - return result; - } - - consteval LagrangeMultiple() { this->evaluations = construct_evaluations(); }; - -}; -} // namespace proof_system::honk::sumcheck \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp deleted file mode 100644 index da41db6174f..00000000000 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate_lagrange.test.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "univariate_lagrange.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/numeric/random/engine.hpp" -#include - -#pragma GCC diagnostic ignored "-Wunused-variable" - -using namespace proof_system::honk::sumcheck; -namespace test_univariate_lagrange { - -template class UnivariateLagrangeTest : public testing::Test { - public: - using FF_ = FF; -}; - -using FieldTypes = testing::Types; -TYPED_TEST_SUITE(UnivariateLagrangeTest, FieldTypes); - -#define ALIASES using FF = TypeParam; -// IMPROVEMENT: Can't make alias for Univariate for some reason. -// Might be convenient to solve boilerplate or repeated type aliasing -// using this or some other means. - -TYPED_TEST(UnivariateLagrangeTest, Constructors) -{ - ALIASES - constexpr size_t domain_size = 8; - constexpr size_t num_evals = 16; - constexpr size_t center_idx = 1; - auto lagrange = LagrangeMultiple(); - - const auto compute_lagrange_naive = [&](FF new_point) { - FF result = 1; - FF denominator = 1; - FF center = center_idx; - - for (size_t idx = 0; idx < domain_size; idx++) { - if (idx != center_idx) { - result *= (new_point - FF(idx)); - denominator *= (center - FF(idx)); - } - } - result /= denominator; - return result; - }; - - for (size_t idx = 0; idx < 16; idx++) { - EXPECT_EQ(lagrange.evaluations[idx], compute_lagrange_naive(idx)); - } -} - -} // namespace test_univariate_lagrange diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp index 1e82e1be25f..3588ee317c7 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp @@ -8,7 +8,7 @@ namespace proof_system::honk::sumcheck { -// WORKTODO: ... this is not a base class. +// WORKTODO: ... this is a base in a weird way. Wish I could simplify the structure here. template class ArithmeticRelationBase { public: // 1 + polynomial degree of this relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp index 44ab8620dd3..6831c2ea732 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp @@ -72,7 +72,8 @@ template typename RelationBase> class Relation private: // WORKTODO: does these templates being defined inside of here mean we can't reuse their instantiations? template struct UnivariateAccumulatorTypes { - using Accumulators = std::tuple...>; // Values extracted from relation. + // These Values are extracted from RelationBase. + using Accumulators = std::tuple...>; using AccumulatorViews = std::tuple...>; }; template struct ValueAccumulatorTypes { diff --git a/circuits/cpp/barretenberg/spec/protogalaxy.md b/circuits/cpp/barretenberg/spec/protogalaxy.md deleted file mode 100644 index 8bde1360f04..00000000000 --- a/circuits/cpp/barretenberg/spec/protogalaxy.md +++ /dev/null @@ -1,466 +0,0 @@ -# ProtoGalaxy Implementation Spec - -$$ -\newcommand{\bB}{\mathbb{B}} -\newcommand{\bF}{\mathbb{F}} -\newcommand{\bin}{\text{bin}} -\newcommand{\MAX}{\text{MAX}} -\newcommand{\dMAX}{d_\MAX} -\newcommand{\circuitsize}{n} -\newcommand{\Rel}{\text{Rel}} -\newcommand{\UGH}{\text{UGH}} -\newcommand{\Arith}{\text{Arith}} -\newcommand{\Perm}{\text{Perm}} -\newcommand{\Lookup}{\text{Lookup}} -\newcommand{\GenPerm}{\text{GenPerm}} -\newcommand{\Aux}{\text{Aux}} -\newcommand{\Elliptic}{\text{Elliptic}} -\newcommand{\ECCOpQueue}{\text{ECCOpQueue}} -\newcommand{\perm}{\text{perm}} -\newcommand{\pow}{\text{pow}} -\newcommand{\lookup}{\text{lookup}} -\newcommand{\Trace}{\text{Trace}} -\newcommand{\Polys}{\text{Polys}} -\newcommand{\NumPolys}{N_\Polys} -\newcommand{\ProtoGalaxy}{\text{ProtoGalaxy}} -\newcommand{\Honk}{\text{Honk}} -$$ - -TODO: names for the globals: 48; 26 -TODO: max degree is 5 (right?) and max relation length is one greater than that. -# Background -We will use [ProtoGalaxy](https://eprint.iacr.org/archive/2023/1106/1690490682.pdf) to fold [UltraGoblinHonk](https://github.com/AztecProtocol/aztec-packages/blob/master/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp) claims. The UltraGoblinHonk (UGH) proving system construct proofs for satisfying assignments for circuits built using [UltraCircuitBuilder](https://github.com/AztecProtocol/aztec-packages/blob/master/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp). The circuits built using this builder class encode application logic and witnesses in an execution trace: - -| row | ... | $w_l$ | ... | $q_r$ | ... | -|-------|-----|--------------|-----|---------------|-----| -| $0$ | * | $w_{l, 0}$ | * | $q_{r, 0}$ | * | -| $1$ | * | $w_{l, 1}$ | * | $q_{r, 1}$ | * | -| ... | ... | ... | ... | ... | ... | -| $n-1$ | * | $w_{l, n-1}$ | * | $q_{r, n-1}$ | * | - - -Using the Lagrange basis on the boolean hypercube $\bB^t$ of dimension $t = \log(n)$, this data, along with the data of additional derived witnesses ($Z_\perm$ and $Z_\lookup$) and auxiliary polynomials (Lagrange polynomials e.g.) are stored in a `GoblinUltra::ProverPolynomials` instance $\Polys$, which we can model here as a tuple of $\NumPolys$-many polynomials. The claim of interest to the UGH prover is that the full aggregated UGH relation, a polynomial in variables -$P_1,\ldots, P_{\NumPolys}$ -$$ -\begin{aligned} -\Rel_\UGH(P_1,\ldots, P_{\NumPolys}) = -&\phantom{+ \alpha^{1} \cdot } \Rel_\Arith(P_1,\ldots, P_{\NumPolys}) \\ -&+ \alpha^{1}\cdot\Rel_\Perm(P_1,\ldots, P_{\NumPolys}) \\ -&+ \alpha^{2}\cdot\Rel_\Lookup(P_1,\ldots, P_{\NumPolys}) \\ -&+ \alpha^{3}\cdot\Rel_\GenPerm(P_1,\ldots, P_{\NumPolys}) \\ -&+ \alpha^{4}\cdot\Rel_\Elliptic(P_1,\ldots, P_{\NumPolys}) \\ -&+ \alpha^{5}\cdot\Rel_\Aux(P_1,\ldots, P_{\NumPolys}) \\ -&+ \alpha^{6}\cdot\Rel_\ECCOpQueue(P_1,\ldots, P_{\NumPolys}), \\ -\end{aligned} -$$ -when evaluated on $\Polys$, gives a polynomial that vanishes on $\bB^t$. A prover can argue this claim in $O(\circuitsize)$ time by allowing a verifier to generate a challenge $\beta$ and then using a sumcheck argument for the claim -$$ -\sum_{i=0}^{n-1}\beta^i\Rel_\UGH(\bin(i)) = 0 -$$ -where $\bin(i)$ is the length-$t$ vector of binary digits of $i$. - -For comparison, ProtoGalaxy uses the notation for $\omega$ for the data encoded in $\Polys$ regarded simly as a data of vectors. Roughly speaking, the relation $\Rel_\UGH$ gets the name $f$. More precisely, $f$ is a mapping -$$f: \bF^{\NumPolys}\to \bF^\circuitsize$$ -whose image is defiend by $\circuitsize$ component functions $f_i$. In our earlier notation, $f_i(\omega)$ is defined by -$$f_i(\omega) = \Rel_\UGH(\Polys_1(\bin(i)), \ldots, \Polys_{\NumPolys}(\bin(i))).$$ - -# Mara's sketch work. - - We unroll the protocol presented in the paper. - - ### Relating Paper to Code - * $\omega$ is the Honk polynomials $\Polys$, for UGH there are 48 of them found in the GoblinUltra flavor - * these polynomials are represented in evaluation form over the boolean hypercube $\{0,1\}^t$ where $t = \log n$ and $n$ is the circuit size (note that the code and earlier Honk resources use $d$ instead of $t$). - * Honk polynomials = how we represent a circuit - * $f$ in ProtoGalaxy is the full $\Rel_{UGH}$ itself - * in Honk's sumcheck, each round constructs univariates over two consecutive rows in the table - * the $i$-th row of the execution trace is filled with the evaluation of the Honk polynomials $\Polys$ at $i$, represented as a point of the hypercube - * to represent each univariate we need $\dMAX + 1$ evaluations -* The value $f_i(\omega)$ in ProtoGalaxy is equal to $\Rel_{UGH}(\Trace_i)$, the evaluation of the full relation on the $i$-th row of the execution trace. - -## How folding transforms Aztec's architecture: -### Current Structure -* a Noir contract is a collection of functions, where each function corresponds to a seperate circuit -* assume a Noir contract has a function `foo` which then calls a function `bar` -* if the user calls `foo`, executing that Noir code will produce a proof `P_foo` for `foo` and a proof `P_bar` for `bar`. `P_foo` will be accompanied, among other stuff, by a public input which specifies that `foo` calls `bar` - * we think of this user action as a transaction and the private kernel circuit is responsible for proving it's validity; this entails recursively checking whatever functions `foo` calls -* in the example above, the private kernel will have two iterations to prove this private transaction is valid - * first iteration is `K_foo` (this is a circuit): it will recursively verify `P_foo`, take most of `foo`'s public inputs (remember `foo` is actually a circuit) and transfer them to `K_foo`, add some constraints and finally, generate `P_K_foo` - * so the structure of the `K_foo` circuit is as follows: - * public inputs are (more or less) `foo`'s public inputs as well as "bar comes after foo" - * `P_foo` also corresponds to inputs (not sure if public or private) - * the `K_foo` circuit will have a Honk verifier subcircuit for `P_foo` and some other constraints - * second iteration is `K_bar`: it recursively verifies `P_K_foo`, ensures that as part of `K_foo`s public_inputs we have "`foo` comes after `bar`", afterwards it recursively verifies `P_bar`, creates `K_bar`s public inputs from `K_foo` and `bar` and finally generates `P_K_bar` - * the structure of `K_bar` circuit is: - * public inputs of `K_foo` and `bar` more or less - * `P_bar` passed as input - * the circuit will have: - * subcircuits for verifying `P_bar` and `P_k_bar` with Honk - * constraints for verifying `bar` comes after `foo` - * and some other constraints -If `bar` was to call a function `baz` there would be another kernel iteration `K_baz` with a similar structure to `K_bar` - -### What Changes with folding -So instead of recursively proving these circuits, we fold them. This doesn't change anything in the structure of first kernel iteration but eliminates the need to have a Honk verifier circuit at iteration $i$ for recursively verifying the kernel proof from iteration $i-1$. However, each kernel iteration still Honk verifies the Noir proof of the corresponding function or otherwise we need to fold app kernel circuits as well. - -### Notation: - -* $k$ is the number of instances we fold with our accumulator, the exact value of $k$ we will use is an open question as the paper presents various techniques with trade-offs - -* $\log(n) = t$ - -* Define the vanishing polynomial as $Z(X) = \prod_{a \in \mathbb{H}}(X - a)$ where: - * In our case $\mathbb{H} = {0,\ldots, k}$ - * Its Lagrange base is $L_0(X), \ldots, L_k(X)$ where - $L_i(X) = \prod_{j\in \{0 \ldots k \},\,, j\neq i} \tfrac{(X-j)}{(i-j)}$ - - * these polynomials have degree $k$ - - - -$$\ProtoGalaxy(\Phi = ((\phi, \vec{\beta}, e), (\phi_1,\ldots, \phi_k); (\omega, \omega_1,\ldots, \omega_k)))$$ -(semicolumn separates public and private inputs) - -1. $V \rightarrow P:\delta \in \mathbb{F}$ - * to achieve this noninteractively, we add ($k + 1$) public inputs corresponding to each instance, $e$ and $\vec{\beta}$ to the transcript - * $\vec{\beta}$ has size aprox $\log(n)$ so in total we add to the transcript (i.e. hash) $log(n) + 1$ scalars and $Pub_{tot}$ group elements from all the instances $\phi$ - * $Pub_{tot} = 26k + \sum Pub_{\omega_i}$, where: - - $26$ is the number of selector polynomials whose commitments the verifier has as public inputs in $UGH$ - - $Pub_{\omega_i}$ is the number of public inputs of $\omega_i$ note that this can vary for each instance $\omega_i$ but in practice we will haave to bound $Pub_{tot}$. -2. $P, V$ compute $\vec{\delta} = (\delta, \delta^2, \ldots, \delta^{2^{t -1}})$ , which can be computed with $t-1$ squaring operations. -3. $P$ computes $F(X) = \sum_{i = 0..n-1} pow_i(\vec{\beta} + X\vec{\delta})f_i(\omega)$ where $pow_0(\vec{\beta} + X\vec{\delta}) = 1$ - * $i$ corresponds to the rows in the sumcheck matrix and $\omega$ is the full $\Honk$ relation - * this consists of 48 polynomials defined in flavor, the maximum degree among them being 5 - * unlike what happens in sumcheck, we will evaluate each full Honk relation at $i$ (we need code to do that) bu getting all the $f_i$ is a linear operation - * Computing $pow_i(\vec{\beta} + X\vec{\delta})$ - * naively, the cost of computing this is $O(n \log n)$ but the paper provides a smart way to compute it in $O(n)$ - * binary tree trick (*insert drawing*) - * following the paper notation, my understaing is - * $\vec{\beta} + X\vec{\gamma} = (\beta + X\gamma, \beta^2 + X\gamma^2, \ldots, \beta^{2^{t -1}} + X\gamma^{2^{t -1}})$ let's call this vector $\vec{v} = (v_1,..., v_t)$ - * so $pow_i(\vec{\beta} + X\vec{\gamma}) = pow_i(\vec{v}) = \prod_{j{}} v_j$ where $i = \sum_j 2^j$ - - - -* final $F$ will be a polynomial of degree $t = log(n)$ -4. $P$ sends $F_1, \ldots,F_{t}$ to $V$ -5. $V$ sends random challenge $\alpha \in \mathbb{F}$ - * In the noninteractive setting, this means adding another $logn$ scalars to the transcript -6. $P, V$ compute $F(\alpha) = e + \sum_{i = 0..t-1}F_i \alpha^i$, this is $\log n$ scalar operations -7. $P, V$ compute $\beta^*_i = \beta_i +\alpha \cdot \delta^{2^{i-1}}$ these are the elements of $\vec{\beta}^*$ and require another $\log n$ multiplication and additions of scalars -8. P computes $G(X) = \sum_{i = 0..n-1} pow_i(\vec{\beta^{*}})f_i(L_0(X)\omega + \sum_{j \in [k]} L_j(X)\omega_j)$ whose maximum degree is $dk$ - * where $d$ is the maximum degree of a relation, in our case 5 (`MAX_RELATION_LENGTH` - 1) - * the problem with the $pow_i(\vec{\beta^*})$ polynomial is that it's not preserving the nice structure presented on page 7 and we will probably have to use the binary tree trick here as well - * we can compute f_i($L_0(X)\omega + \sum_{j \in [k]} L_j(X)\omega_j$) by partially reusing the sumcheck code for computing univariates - * the current sumcheck code, for $k \in \{0, 1\}$ computes $L_0(X)f_i(\omega) + L_1(X)f_{i+1}(\omega)$ which is obtained by computing $d+1$ evaluations - * in our case we will need $dk + 1$ evaluation points for computing the polynomial and then apply $f_i$ for each row -9. P computes polynomial $K$ and sends its coefficients -$G(X) = F(\alpha)L_0(X) + Z(X)K(X)$ - * if $G(X)$ has degree $dk$, so will $Z(X)K(X)$ (because $F(\alpha)L_0(X)$ has degree $k$) - and given $Z(X)$ has degree $k+1$,$K(X)$ will have degree k(d-1)-1 - * We need to compute $K$ without FFTs (because we might want to work with Grumpkin and also we don't want to use FFTs in UGH) - * Option 1: schoolbook polynomial division (moonmath, page 32)[https://github.com/LeastAuthority/moonmath-manual] - * Option 2: Zac's idea: - * recall the degree of $K$ is $k(d-1)-1$ and thus we need $k(d-1)$ evaluations to represent it - * we can evaluate $G$, $Z$, $L_0$ at $k(d-1)$ points and compute the division in evaluation form to obtain $K$ - * note, all this points must be $\not\in \mathbb{H}$ where $\mathbb{H}$ is the vanishing set of $Z$ - * then we can convert $K$ to coefficient form and send the coefficients to the verifier -11. V sends $\gamma$ - * in the noninteractive setting we add $K$'s coefficients (scalars) to the transcript -12. $P, V$ compute $e^* = F(\alpha)L_0(\gamma) + Z(\gamma)K(\gamma)$ which is (d-1)k scalar operations -11. At the end of the pr - * $V: \phi^* = L_0(\gamma)\phi + \sum_{i \in [k]} L_i(\gamma)\phi_i$ - * as the public inputs are group elements, we require $Pub_{tot}$ ecc scalar multiplication which are going to be offset to the ECC VM - * P: $\omega^* = L_0(\gamma)\omega + \sum_{i \in [k]} L_i(\gamma)\omega_i$ - -ProtoGalaxy requires 3 rather than $2k\log n$ ($\log n$ for sumcheck and $\log n$ zeromorph + gemini) values from the random oracle. - - ---- -## Scratch work on computation of $G(Y)$ - - -We have reserved $X$ for the names of the inputs to the prover polynomials, the variables on the boolean hypercube, e.g., $w_l = w_l(X_1, \ldots, X_d)$. So let's use $Y$ for the perturbation and combiner variables in PG. This agrees with the notation of Protostar. Let's use $P$ for the inputs to the relations. - -How do we interpret the definition of $G(Y)$? In the paper we write -$$G(Y) -= \sum_{i=0}^{n-1}\pow_i(\beta^*)f_i\left(\sum_{j=0}^{k}L_j(Y)\omega_j\right) -= \sum_{i=0}^{n-1}\pow_i(\beta^*)\Rel_\UGH\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{i}\right) -$$ - -To rewrite this in our terms, the instances $\omega_0,\omega_1, \ldots, \omega_k$ correspond to `honk::flavor::Ultra::ProverPolynomials` instances $\Polys^{(0)}, \Polys^{(1)}, \ldots, \Polys^{(k)}$ and the polynomial $G$ becomes -$$G(Y) -= \sum_{i=0}^{n-1}\pow_i(\beta^*)\Rel_\UGH\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{i}\right) -$$ - -Let's focus on the sub-term $\Rel_\Arith\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{i}\right).$ Using the indexing of `honk::flavor::Ultra`, we have - -$$\Rel_\UGH(P_1,\ldots, P_{\NumPolys}) = P_{5}P_{25}P_{26} + P_{1}P_{25} + P_{2}P_{26} + P_{3}P_{27} + P_{0}.$$ -To be clear, if $\Polys$ is an instance of `honk::flavor::Ultra::ProverPolynomials`, then - -$$\Rel_\UGH(\Polys) := \Rel_\UGH(\Polys_1,\ldots, \Polys_{\NumPolys}) = q_{m}w_lw_r + q_{l}w_{l} + q_{r}w_{r} + q_{o}w_{o} + q_{c}.$$ - -Similarly, with the superscript $(j)$ used in the natural way, -$$\begin{aligned} -\Rel_\Arith\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}\right) -&:= \Rel_\Arith\left(\sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{1}, - \ldots, \sum_{j=0}^{k}L_j(Y)\Polys^{(j)}_{\NumPolys}\right) \\ -&= \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{m}\right) - \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{l}\right) - \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{r}\right) \\ -&\hphantom{...}+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{l}\right) - \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{l}\right)\\ -&\hphantom{...}+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{r}\right) - \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{r}\right)\\ -&\hphantom{...}+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{o}\right) - \left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{o}\right)\\ -&\hphantom{...}+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{c}\right) -\end{aligned} -$$ -which is a polynomial of degree $3\circuitsize$ (in general, $G$ has degree $\dMAX\circuitsize$ where $\dMAX=5$ is one less than the maximum `RELATION_LENGTH` over the relations in `honk::flavor::Ultra::Relations`). - -### Efficient extension of Lagrange polynomials - -Note: this is all done at compilation time, so it's less important to be efficient, but I write down the ideas nonetheless. We will need to compute products of Lagrange polynomials of degree $\dMAX$. Each Lagrange polynomial has degree $k$, hence is determined by $k+1$ evaluations , hence a product of $\dMAX$ such polynomials will be represented by $k\dMAX+1$ values. To precompute all extensions of $L_0,\ldots, L_k$, we would have to store $k\cdot (\dMAX-1)\cdot(k+1)$ field elements. With values $\dMAX = 5$ and $k+1=128$, this is $127 * 5 * 4 * 128 * 32 = 10\_403\_840$ bytes of data. So probably we can just do this, but it will be important to be efficient at compilation time. - -#### The formulas -Recall that the barycentric evaluation of polynomials represented by their values works as follows (cf [Vitalik's post](https://hackmd.io/@vbuterin/barycentric_evaluation)). I $P(X)$ is a polynomial represented by its evaluations $(y_1,\ldots, y_N)$ at points $(x_1, \ldots, x_N)$ , then $P(X) = \sum_i y_iL_i(X)$ where $L_i(X)$ is the Lagrange basis polynomial centered at $x_i$. By definition, -$$ -L_i(X) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{X-x_j}{x_i-x_j}. -$$ -Hence, defining $M(X) = \prod_{j\in\{1,\ldots, N\}}(X-x_j)$ and $d_i = \prod_{j\in\{1,\ldots, N\}\setminus\{i\}}x_i-x_j$, we have -$$P(X) -= \sum_i y_iL_i(X) -= \sum_i y_i\prod_{j\in\{1,\ldots, N\}\setminus\{i\}}\frac{X-x_j}{x_i-x_j} -= M(X)\sum_i \frac{y_i}{d_i(X-x_i)}. -$$ -This means that, naively, one barycentric evaluation costs: $N$ subtractions and $N-1$ multiplications (to compute the value of $M$), $N$ multiplications (to divide $y_i/d_i$, assuming $d_i$ is inverted at compilation time), $N$ subtractions (to compute the $X-x_i$ values), $3N$ multiplications (amortized cost to batch invert the $X-x_i$ values), $N$ multiplications (to compute the summands), $N-1$ additions, and a final multiplication. The leading term here is $6N$ multiplications to get a single value. Hence, to extend to an additional set $x'_1, \ldots, x'_N$ of $N$ points costs about $6N^2$ operations. - -However, with special structure we can do much better. We consider the case where $P(X)$ is _itself_ a Lagrange polynomial $L_i$, $N = k+1$ for some $k$, and $x_i = i-1$, so the domain of interest is, $\{0, 1, \ldots, k\}$ and we extend to $\{0, 1, \ldots, 2k+1\}$ (so $x'_i = i+k$). In that case note that -$$ -L_i(k+1) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{k+1-j}{i-j} -= \frac{\prod_{j\in\{0,\ldots, k\}\setminus\{i\}}k+1-j} - {\prod_{j\in\{0,\ldots, k\}\setminus\{i\}} i-j} -= \frac{(k+1)!}{d_i\cdot (k+1-i) \cdot 1}, -$$ -$$ -L_i(k+2) = \prod_{j\in\{0,\ldots, k\}\setminus\{i\}}\frac{k+2-j}{i-j} -= \frac{(k+2)!}{d_i\cdot (k+2-i) \cdot 1!} -= \frac{(k+2)(k+1-i)}{(k+2-i)\cdot 2} L_i(k+1), -$$ -and in general, -$$ -L_i(k+s+1) = \frac{(k+s+1)(k+s-i)}{(k+s+1-i)(s+1)} L_i(k+s). -$$ -Hence we can compute the extension to an additional $N$ values more efficiently. - -Moreover, note that the same recursive formula holds when $L_i$ is replaced by $cL_i$ for some constant $c$. This means enables the approach using 'successive extensions' we have taken elsewhere in the relations (or at least we used to? Maybe that optimization went away?). -### Comparison of cost models - -With this new responsibility for execution of the relations comes a different cost model. Namely, before, it would have been efficient to compute part of the arithmetic relation as in -$$ -q_m w_l w_r + q_{l} w_{l} = w_l\cdot (q_m w_r + q_l) \qquad 2\times,\, 1+ \text{ on values} -$$ -Reusing the code path for the combiner polynomial combination, would likely look like this. We would want to compute -$$ -\left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{l}\right) -\cdot \left(\left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{m}\right) -\left(\sum_{j=0}^{k}L_j(Y)w^{(j)}_{r}\right) -+ \left(\sum_{j=0}^{k}L_j(Y)q^{(j)}_{l}\right)\right). -$$ -Each $L_j$ is naturally represented by $k+1$ values, meaning the resulting expression would be represented by $3(k+1)$ values. Extending each $L_j$ requires $2\cdot 2(k+1)$ multiplications and $2(k+1)$ divisions (could batch invert, equivalent to about $3\cdot (2k+1) $ muls). Then each prover polynomial value would scale a Lagrange polynomial's value ($4 \cdot (2(k+1)+1)$ muls). Then we would assble the relation: $2\cdot 2(k+1)$ muls and $2(k+1)$ additions. So altogether we have: about $22k$ muls - -Alternatively: compute the above as -$$ -\sum_{j_1, j_2, j_3 = 0}^{k}\Big(L_{j_1}(Y)L_{j_2}(Y)L_{j_3}(Y)\Big) - q^{(j)}_{m}w^{(j)}_{l}w^{(j)}_{r} -+ \sum_{j_1, j_2 = 0}^{k} \Big(L_{j_1}(Y)L_{j_2}(Y)\Big) - q^{(j)}_{l}w^{(j)}_{l} -$$ - -### Comparison of cost models take 2 - -Setting: we focus on the highest-degree ($=d$) monomial term in the PG combiner polynomial in the case where we are folding $k$ relations. Our target values we expect are $k=127$, $d=5$. - -For each $\ell=1,\ldots, d$ there are $k+1$ polynomials $P_\ell^{(0)},\ldots,\, P_\ell^{(k)}$ described by $n$ evaluations over $\bB^d$. Denote by $P_{\ell, i}^{j} = P_{\ell}^{j}(\bin(i))$. We will be interested in computing the terms -$$ -\prod_{\ell=1}^d L_{j_\ell}(Y)P_{\ell, i}^{(j_\ell)} -$$ -for all $i=0,\ldots, n-1$, for every typle $(j_1, \ldots, j_d)\in \{0,\ldots, k\}^d$. Here each $L_j$ is the Lagrange polynomial on $\{0,\ldots, k\}$ centered at $j$, and extended over the set $\{0,\ldots, kd\}$ (i.e., it is regarded as the vector of its $kd+1$ values over that set). For now we ignore a small optmization of using the sparseness of the $L_j$ in the first $k+1$ terms in this representation. - -#### Naive way -This is the way that would let us reuse our existing relations code: -$$ -\prod_{\ell=1}^d \left(L_{j_\ell}(Y)P_{\ell, i}^{(j_\ell)}\right) -$$ -- Each inner term: $kd+1$ muls, so computing all of them is $d\cdot (kd+1)$ -- Multiplying the inner terms: $(d-1)(kd+1)$ muls -- Doing this for all $i$: multiply both of these preceding counts by $n$ -- Do this for every index $j_*$: multiply both runnin counts by $(k+1)^d$. - -Altogether the cost to compute these $n(k+1)^d$ terms is -$$ -(d(kd+1)+((d-1)(kd+1)))\cdot n\cdot (k+1)^d = n(2d-1)(k+1)^{d+1} -$$ - -If we could tolerate $(kd+1)\times$ as much memory usage, we could hold on to the inner terms $L_{j_\ell}(Y)P_{\ell, i}^{(j_\ell)}$. Using the target values, this factor is $636$. If each circuit had size $2^17$, our storage for the polynomials $P_\ell^{(j)}$ witness is $2^{17}*636*32 = 636*2^{22}$ $636*4 = 2544$ MiB. We dream of getting the circuit size down to $2^{15}$, which brings the storage for a polynomail down to 636 MiB. And this is just for one polynomial. - -Alternatively, if we were to reduce $k+1$ to $32$, then then the $636$ factor becomes 156, and so we see a 75% reduction in the above numbers. - -#### Isolating monomial terms -This way would require us isolating homogeneous components of the relations. We group terms as in -$$ -\left(\prod_{\ell=1}^d L_{j_\ell}\right)\left(\prod_{\ell=1}^d P_{\ell, i}^{(j_\ell)}\right) -$$ -- Taking the product of the Lagrange polynomials: $(d-1)(kd+1)$ muls. -- Multiplying the polynomial values $d-1$ muls -- Multiplying against the Lagrange term: $kd+1$ muls -- Doing the previous two steps for all $i$: multiply the counts by $n$ -- Do this for every index $j_*$: multiply both of the preceding counts by $(k+1)^d$. - -Altogether the cost to compute these $n(k+1)^d$ terms is -$$ -\begin{align*} -((d-1)(kd+1) + ((d-1) + (kd+1)) n) (k+1)^d \\ -= nd(k+1)^{d+1} + (d-1)(kd+1)(k+1)^d -\end{align*} -$$ - -Asymptotically in $n$, this is a $\frac{d}{2d-1} = \frac{5}{9}$ reduction in costs. The total cost of storing all of the Lagrange polynomial products is $(kd+1)(k+1)^d$ field elements, which for our target values is $636\cdot 2^{7*5}$ bytes, or $636 \cdot 2^{5} = 20352$ GiB of information. If we were to reduce $k$ to $32$, then we would see $156\cdot 2^{5*5}$ bytes, or $156 \cdot 2^{5} = 4992$ MiB of information. - ---- - -## Plan for interfaces - -```c++ -// for simplicity I ommitted header/source file separation and shared_ptr mentions -template class FoldingComposer { - using CircuitBuilder = typename Flavor::CircuitBuilder; - // The ProvingKey and VerificationKey in the FoldingFlavor will also have beta and e (which will be update to Beta* and e* in construct_folding_proof and verify_folding_proof) - // what if beta = randomizer_term - // and e = relaxation_term (or are we happy with beta and e?) - using ProvingKey = typename Flavor::ProvingKey; - using VerificationKey = typename Flavor::VerificationKey; - - // Produced by the FoldingProver and FoldingVerifier, respectively, in the previous folding stage. - // If this is the first folding stage, we take k+1 CircuitBuilders and we initialise - // acc_proving_key and acc_verification_key from the first CircuitBuilder. - ProvingKey acc_proving_key; - VerificationKey acc_verification_key; - - // Should these be encapsulated in an array of FoldingInstance structs? - // Meh, these are given as parameters to different structs so maybe it makes sense to stay separate - CircuitBuilder[] circuit_builders; - ProvingKey[] inst_proving_keys[]; - VerificationKey[] inst_verification_keys; - - FoldingComposer(); - // We will use this to create a FoldingComposer after we have folded at least once - FoldingComposer(ProvingKey pk, VerificationKey vk); - - ... - - FoldingProver create_prover (CircuitBuilder[] builders) { - // if this is the first time we fold i.e acc_proving_key is null, need to initialise the acc_proving_key with the first Circuit_Builder - // is this extra if clause ok to have? - - // Finalise the k Circuit Builders - this is needed to be able to - // build the polynomials. Also, in brute force recursion, we would finalise each - // CircuitBuilder in part. The only issue is that the prover needs more memory available at once. - // TODO: based on memory estimates of FoldingProver decide if this is acceptable - - // compute the k proving keys and the k witnesses - // the witnesses are also stored in their corresponding proving key - - FoldingProver prover(acc_proving_key, inst_proving_keys); - return prover; - } - - FoldingVerifier create_verifier(CircuitBuilder[] builders) { - // if this is the first time we fold i.e. acc_verifier_key is null, need to initialise the acc_verification_key with the first Circuit_Builder - // is this extra if clause ok to have? - - // Compute the k verification keys - - FoldingVerifier verifier(acc_verification_key, inst_verification_keys); - } - - template struct FoldingProof { - using ProvingKey = typename Flavor::ProvingKey; - using FF = typename Flavor::FF; - - // ONLY non-constant coefficients of F - std::vector pow_perturbation_coeffs; - // Coefficients of K - std::vector combiner_quotient_coeffs; - - } - - template class FoldingProver { - using ProvingKey = typename Flavor::ProvingKey; - // The FoldingProof goes to the FoldingVerifier and the ProvingKey will be used to construct the next - // FoldingComposer - std::pair construct_folding_proof() { - } - - } - - template class FoldingVerifier { - using VerificationKey = typename Flavor::VerificationKey; - - VerificationKey verify_folding_proof(FoldingProof proof){ - } - } -} - -// It would be nice to have only a DeciderFlavor and instantiate the UltraConmposer with -// that but the CircuitBuilder is very ingrained in the UltraComposer and we only have a -// ProvingKey and VerificationKey at this stage -template class DeciderComposer { - // A DeciderFlavor will not have a CircuitBuilder! but only the ProvingKey and VerificationKey obtained from the FoldingProver and FoldingVerifier - using ProvingKey = typename Flavor::ProvingKey; - using VerificationKey = typename Flavor::VerificationKey; - // The PCS appears in the Decider because we run a full Honk proof - using PCS = typename Flavor::PCS; - using CommitmentKey = typename Flavor::CommitmentKey; - using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; - - // We should probably have no empty constructor for the DeciderComposer - DeciderComposer(ProvingKey pk, VerificationKey vk); - - // Is a DeciderProver and DeciderVerifier overkill? - // Potentially yes because we could instantiate an UltraProver and UltraVerifier with a DeciderFlavor - bool decide() { - compute_commitment_key(...) - UltraProver_ prover(proving_key, verification_key); - auto proof = prover.construct_proof(); - UltraVerifier_ verifier(verification_key); - return verifier.verify_proof(proof); - } -} -``` -### How does this change the way things are done in the circuits library - -Currently in the circuits library, after `stdlib::recursion::verify_proof` has been called once (`verify_proof` is responsible for recursive verification), an `AggregationObject` is constructed, whose `aggregate` method incrementally continues to verify proofs, wtih folding this could change to something like below - -```c++ - // the AggregationObject needs to only gather k CircuitBuilders somehow - auto circuit_builders = ... - // iteration #1 of folding - FoldingComposer composer = FoldingComposer(); - auto prover = composer.create_folding_prover(circuit_builders); - // this is not correct C++ syntax, use std::pair or std::tuple - auto (folding_proof, acc_proving_key) = prover.construct_folding_proof(); - auto verifier = composer.create_folding_verifier(circuit_builders); - auto acc_verifying_key = verifier.verify_folding_proof(folding_proof); - - // in practice the FoldingVerifier will be a RecursiveVerifier - - // Option 1: we want to fold again - FoldingComposer composer = FoldingComposer(acc_proving_key, acc_verifying_key); - // same thing again - - // Option 2: we want to decide - DeciderComposer composer = DeciderComposer(acc_proving_key, acc_verifying_key); - auto result = composer.decide() - -``` \ No newline at end of file From cfad8adccfaa68d33ad567ff0209d4948bcbde39 Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 30 Aug 2023 17:48:08 +0000 Subject: [PATCH 06/45] Efficient 2_to_N with benchmarks. --- .../cpp/barretenberg/cpp/CMakePresets.json | 2 +- .../src/barretenberg/benchmark/CMakeLists.txt | 3 +- .../benchmark/relations_bench/CMakeLists.txt | 18 +++++++ .../relations_bench/barycentric.bench.cpp | 26 +++++++++ .../compare_branch_vs_baseline.sh | 54 +++++++++++++++++++ .../benchmark/relations_bench/main.bench.cpp | 3 ++ .../benchmark/relations_bench/utilities.hpp | 9 ++++ .../sumcheck/polynomials/barycentric_data.hpp | 36 ++++++++----- .../honk/sumcheck/polynomials/univariate.hpp | 10 ++++ .../sumcheck/polynomials/univariate.test.cpp | 10 ---- 10 files changed, 146 insertions(+), 25 deletions(-) create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp create mode 100755 circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/compare_branch_vs_baseline.sh create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/main.bench.cpp create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/utilities.hpp diff --git a/circuits/cpp/barretenberg/cpp/CMakePresets.json b/circuits/cpp/barretenberg/cpp/CMakePresets.json index 310dd897b19..db4457d1dfa 100644 --- a/circuits/cpp/barretenberg/cpp/CMakePresets.json +++ b/circuits/cpp/barretenberg/cpp/CMakePresets.json @@ -75,7 +75,7 @@ "name": "bench", "displayName": "Build benchmarks", "description": "Build default preset but with a special benchmark directory", - "inherits": "default", + "inherits": "clang15", "binaryDir": "build-bench" }, { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt index 6387aa089ef..16f375379bb 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(decrypt_bench) add_subdirectory(pippenger_bench) add_subdirectory(plonk_bench) -add_subdirectory(honk_bench) \ No newline at end of file +add_subdirectory(honk_bench) +add_subdirectory(relations_bench) \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt new file mode 100644 index 00000000000..5414d4f73b9 --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt @@ -0,0 +1,18 @@ +# Each source represents a separate benchmark suite +set(BENCHMARK_SOURCES +barycentric.bench.cpp +) + +# Required libraries for benchmark suites +set(LINKED_LIBRARIES + honk + benchmark::benchmark +) + +# Add executable and custom target for each suite, e.g. standard_honk_bench +foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) + get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension + add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE} utilities.hpp) + target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) + add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +endforeach() \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp new file mode 100644 index 00000000000..cc113a5b29b --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp @@ -0,0 +1,26 @@ +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" +#include + +using namespace benchmark; + +namespace { +auto& engine = numeric::random::get_debug_engine(); +} + +using FF = barretenberg::fr; + +namespace proof_system::honk::sumcheck::relations_bench { + +void extend_2_to_6(State& state) noexcept +{ + auto f = Univariate::get_random(); + BarycentricData barycentric_2_to_6; + for (auto _ : state) + { + DoNotOptimize(barycentric_2_to_6.extend(f)); + } +} +BENCHMARK(extend_2_to_6); + +} // namespace proof_system::honk::sumcheck::relations_bench \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/compare_branch_vs_baseline.sh b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/compare_branch_vs_baseline.sh new file mode 100755 index 00000000000..612514c4149 --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/compare_branch_vs_baseline.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# This script is used to compare the honk benchmarks between baseline (default: master) and +# the branch from which the script is run. Simply check out the branch of interest, ensure +# it is up to date with local master, and run the script. + +# Specify the benchmark suite and the "baseline" branch against which to compare +BENCH_TARGET="ultra_honk_bench" +BASELINE_BRANCH="master" + +echo -e "\nComparing $BENCH_TARGET between $BASELINE_BRANCH and current branch:" +# Set some directories +BASE_DIR="$HOME/barretenberg/cpp" +BUILD_DIR="$BASE_DIR/build-bench" # matches build dir specified in bench preset +BENCH_RESULTS_DIR="$BASE_DIR/tmp_bench_results" +BENCH_TOOLS_DIR="$BUILD_DIR/_deps/benchmark-src/tools" + +# Install requirements (numpy + scipy) for comparison script if necessary. +# Note: By default, installation will occur in $HOME/.local/bin. +pip3 install --user -r $BUILD_DIR/_deps/benchmark-src/requirements.txt + +# Create temporary directory for benchmark results (json) +cd $BASE_DIR +mkdir $BENCH_RESULTS_DIR + +# Build and run bench in current branch +echo -e "\nConfiguring and building $BENCH_TARGET in current feature branch..\n" +rm -rf $BUILD_DIR +cmake --preset bench > /dev/null && cmake --build --preset bench --target $BENCH_TARGET +cd build-bench +BRANCH_RESULTS="$BENCH_RESULTS_DIR/results_branch.json" +echo -e "\nRunning $BENCH_TARGET in feature branch.." +bin/$BENCH_TARGET --benchmark_format=json > $BRANCH_RESULTS + +# Checkout baseline branch, run benchmarks, save results in json format +echo -e "\nConfiguring and building $BENCH_TARGET in $BASELINE_BRANCH branch..\n" +git checkout master > /dev/null +cd $BASE_DIR +rm -rf $BUILD_DIR +cmake --preset bench > /dev/null && cmake --build --preset bench --target $BENCH_TARGET +cd build-bench +BASELINE_RESULTS="$BENCH_RESULTS_DIR/results_baseline.json" +echo -e "\nRunning $BENCH_TARGET in master.." +bin/$BENCH_TARGET --benchmark_format=json > $BASELINE_RESULTS + +# Call compare.py on the results (json) to get high level statistics. +# See docs at https://github.com/google/benchmark/blob/main/docs/tools.md for more details. +$BENCH_TOOLS_DIR/compare.py benchmarks $BASELINE_RESULTS $BRANCH_RESULTS + +# Return to branch from which the script was called +git checkout - + +# Delete the temporary results directory and its contents +rm -r $BENCH_RESULTS_DIR diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/main.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/main.bench.cpp new file mode 100644 index 00000000000..71fefa04722 --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/main.bench.cpp @@ -0,0 +1,3 @@ +#include + +BENCHMARK_MAIN(); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/utilities.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/utilities.hpp new file mode 100644 index 00000000000..bcb0d6ab94e --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/utilities.hpp @@ -0,0 +1,9 @@ +#include + +using namespace benchmark; + +namespace bench_utils { + + + +} // namespace bench_utils \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp index 319ba0f287a..2439260e5d7 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp @@ -20,9 +20,12 @@ namespace proof_system::honk::sumcheck { /** - * NOTE: We should definitely consider question of optimal choice of domain, but if decide on {0,1,...,t-1} then we can + + * @todo: We should definitely consider question of optimal choice of domain, but if decide on {0,1,...,t-1} then we can * simplify the implementation a bit. - * NOTE: if we use this approach in the recursive setting, will use Plookup? + * @todo: If we use this approach in the recursive setting, should we use Plookup. WORKTODO + */ +/** */ template class BarycentricDataCompileTime { public: @@ -146,23 +149,30 @@ template class BarycentricDataC { // ASSERT(u>t); Univariate result; - for (size_t k = 0; k != domain_size; ++k) { result.value_at(k) = f.value_at(k); } - for (size_t k = domain_size; k != num_evals; ++k) { - result.value_at(k) = 0; - // compute each term v_j / (d_j*(x-x_j)) of the sum - for (size_t j = 0; j != domain_size; ++j) { - Fr term = f.value_at(j); - term *= precomputed_denominator_inverses[domain_size * k + j]; - result.value_at(k) += term; + if constexpr (domain_size == 2) { + Fr delta = f.value_at(1) - f.value_at(0); + for (size_t idx = 1; idx < num_evals - 1; idx++) { + result.value_at(idx + 1) = result.value_at(idx) + delta; } - // scale the sum by the the value of of B(x) - result.value_at(k) *= full_numerator_values[k]; + return result; + } else { + for (size_t k = domain_size; k != num_evals; ++k) { + result.value_at(k) = 0; + // compute each term v_j / (d_j*(x-x_j)) of the sum + for (size_t j = 0; j != domain_size; ++j) { + Fr term = f.value_at(j); + term *= precomputed_denominator_inverses[domain_size * k + j]; + result.value_at(k) += term; + } + // scale the sum by the the value of of B(x) + result.value_at(k) *= full_numerator_values[k]; + } + return result; } - return result; } /** diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp index c58242674d2..c6fdf5df583 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp @@ -10,6 +10,7 @@ namespace proof_system::honk::sumcheck { template class UnivariateView; +// IMPROVEMENT(Cody) this is not used anywhere? Move to memeber function of U/snivariate? template class Univariate { public: static constexpr size_t LENGTH = _length; @@ -60,6 +61,15 @@ template class Univariate { return result; } + static Univariate get_random() + { + auto output = Univariate(); + for (size_t i = 0; i != _length; ++i) { + output.value_at(i) = Fr::random_element(); + } + return output; + }; + // Operations between Univariate and other Univariate bool operator==(const Univariate& other) const = default; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp index 91417fec90e..1952cdb6d5d 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp @@ -11,16 +11,6 @@ namespace test_univariate { template class UnivariateTest : public testing::Test { public: template using UnivariateView = UnivariateView; - - // IMPROVEMENT(Cody) this is not used anywhere? Move to memeber function of U/snivariate? - template Univariate random_univariate() - { - auto output = Univariate(); - for (size_t i = 0; i != length; ++i) { - output.value_at(i) = FF::random_element(); - } - return output; - }; }; using FieldTypes = testing::Types; From f7071201241b9c8cc7b01f5523ad57bc7cf53f55 Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 30 Aug 2023 19:37:22 +0000 Subject: [PATCH 07/45] consts, std, etc. --- .../relations_bench/barycentric.bench.cpp | 4 ++-- .../sumcheck/polynomials/barycentric_data.hpp | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp index cc113a5b29b..cc1c1b04dcd 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp @@ -14,11 +14,11 @@ namespace proof_system::honk::sumcheck::relations_bench { void extend_2_to_6(State& state) noexcept { - auto f = Univariate::get_random(); + auto univariate = Univariate::get_random(); BarycentricData barycentric_2_to_6; for (auto _ : state) { - DoNotOptimize(barycentric_2_to_6.extend(f)); + DoNotOptimize(barycentric_2_to_6.extend(univariate)); } } BENCHMARK(extend_2_to_6); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp index 2439260e5d7..31e84a6ecc6 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp @@ -129,7 +129,7 @@ template class BarycentricDataC static constexpr auto full_numerator_values = construct_full_numerator_values(big_domain); /** - * @brief Given A univariate f represented by {f(0), ..., f(t-1)}, compute {f(t), ..., f(u-1)} + * @brief Given a univariate f represented by {f(0), ..., f(t-1)}, compute {f(t), ..., f(u-1)} * and return the Univariate represented by {f(0), ..., f(u-1)}. * * @details Write v_i = f(x_i) on a the domain {x_0, ..., x_{t-1}}. To efficiently compute the needed values of f, @@ -139,19 +139,16 @@ template class BarycentricDataC * - B(x) = Π_{i=0}^{t-1} (x-x_i) * - d_i = Π_{j ∈ {0, ..., t-1}, j≠i} (x_i-x_j) for i ∈ {0, ..., t-1} * - * NOTE: just taking x_i = i for now and possibly forever. Hence can significantly optimize: - * extending an Edge f = v0(1-X) + v1X to a new value involves just one addition and a subtraction: - * setting Δ = v1-v0, the values of f(X) are - * f(0)=v0, f(1)= v0 + Δ, v2 = f(1) + Δ, v3 = f(2) + Δ... + * When the domain size is two, extending f = v0(1-X) + v1X to a new value involves just one addition and a + * subtraction: setting Δ = v1-v0, the values of f(X) are f(0)=v0, f(1)= v0 + Δ, v2 = f(1) + Δ, v3 = f(2) + Δ... * */ - Univariate extend(Univariate f) + Univariate extend(const Univariate& f) { - // ASSERT(u>t); + static_assert(num_evals >= domain_size); // WORKTODO > triggered Univariate result; - for (size_t k = 0; k != domain_size; ++k) { - result.value_at(k) = f.value_at(k); - } + + std::copy(f.evaluations.begin(), f.evaluations.end(), result.evaluations.begin()); if constexpr (domain_size == 2) { Fr delta = f.value_at(1) - f.value_at(0); @@ -181,7 +178,7 @@ template class BarycentricDataC * @param f * @return Fr */ - Fr evaluate(Univariate& f, const Fr& u) + Fr evaluate(const Univariate& f, const Fr& u) { Fr full_numerator_value = 1; From 2f2def3906029d6e39dbdc5bdb3b9285968c0459 Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 30 Aug 2023 20:40:00 +0000 Subject: [PATCH 08/45] Add relaiton benchmarks. --- .../benchmark/relations_bench/CMakeLists.txt | 1 + .../relations_bench/relations.bench.cpp | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt index 5414d4f73b9..c40aecbd33f 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt @@ -1,6 +1,7 @@ # Each source represents a separate benchmark suite set(BENCHMARK_SOURCES barycentric.bench.cpp +relations.bench.cpp ) # Required libraries for benchmark suites diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp new file mode 100644 index 00000000000..9ec880fc70f --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -0,0 +1,101 @@ +#include "barretenberg/honk/flavor/goblin_ultra.hpp" +#include "barretenberg/honk/flavor/standard.hpp" +#include "barretenberg/honk/flavor/ultra.hpp" +#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include + +namespace { +auto& engine = numeric::random::get_debug_engine(); +} + +namespace proof_system::honk::sumcheck::relations_bench { + +using FF = barretenberg::fr; + +template void execute_relation(benchmark::State& state) +{ + // Generate beta and gamma + auto beta = FF::random_element(); + auto gamma = FF::random_element(); + auto public_input_delta = FF::random_element(); + + sumcheck::RelationParameters params{ + .beta = beta, + .gamma = gamma, + .public_input_delta = public_input_delta, + }; + + using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; + using RelationValues = typename Relation::RelationValues; + + // Extract an array containing all the polynomial evaluations at a given row i + ClaimedEvaluations new_value; + // Define the appropriate RelationValues type for this relation and initialize to zero + RelationValues accumulator; + // Evaluate each constraint in the relation and check that each is satisfied + + Relation relation; + for (auto _ : state) { + relation.add_full_relation_value_contribution(accumulator, new_value, params); + } +} + +void arithmetic_relation(benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(arithmetic_relation); + +// WORKTODO +// void auxiliary_relation(benchmark::State& state) noexcept +// { +// execute_relation>(state); +// } +// BENCHMARK(auxiliary_relation); + +void elliptic_relation(benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(elliptic_relation); + + +void ecc_op_queue_relation(benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(ecc_op_queue_relation); + +void gen_perm_sort_relation(benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(gen_perm_sort_relation); + +void lookup_relation(benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(lookup_relation); + +void permutation_relation(benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(permutation_relation); + +void ultra_arithmetic_relation(benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(ultra_arithmetic_relation); + + +} // namespace proof_system::honk::sumcheck::relations_bench From 0ee5f81a1911cdbb0205145cdb2ee93c193207d0 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 02:27:46 +0000 Subject: [PATCH 09/45] Clean up includes. --- .../sumcheck/relations/arithmetic_relation.hpp | 4 ---- .../sumcheck/relations/auxiliary_relation.hpp | 4 ---- .../sumcheck/relations/ecc_op_queue_relation.hpp | 4 ---- .../honk/sumcheck/relations/elliptic_relation.hpp | 4 ---- .../sumcheck/relations/gen_perm_sort_relation.hpp | 4 ---- .../honk/sumcheck/relations/lookup_relation.hpp | 2 -- .../sumcheck/relations/permutation_relation.hpp | 2 -- .../relations/relation_consistency.test.cpp | 15 ++++++--------- .../relations/relation_correctness.test.cpp | 1 - .../sumcheck/relations/relation_parameters.hpp | 1 - .../honk/sumcheck/relations/relation_types.hpp | 3 --- .../relations/ultra_arithmetic_relation.hpp | 4 ---- .../relations/ultra_relation_consistency.test.cpp | 8 +++----- 13 files changed, 9 insertions(+), 47 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp index 3588ee317c7..f4d61242871 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp @@ -1,8 +1,4 @@ #pragma once -#include -#include - -#include "../polynomials/univariate.hpp" #include "relation_parameters.hpp" #include "relation_types.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp index 408e5add32d..55572d2d347 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp @@ -1,8 +1,4 @@ #pragma once -#include -#include - -#include "../polynomials/univariate.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "relation_parameters.hpp" #include "relation_types.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp index 44f70c52e4b..2f2967ea5a4 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp @@ -1,8 +1,4 @@ #pragma once -#include -#include - -#include "../polynomials/univariate.hpp" #include "relation_parameters.hpp" #include "relation_types.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp index b9734fb6db1..582197b1ff3 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp @@ -1,8 +1,4 @@ #pragma once -#include -#include - -#include "../polynomials/univariate.hpp" #include "relation_parameters.hpp" #include "relation_types.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp index ce16b2064f2..d041ce869f4 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp @@ -1,8 +1,4 @@ #pragma once -#include -#include - -#include "../polynomials/univariate.hpp" #include "relation_parameters.hpp" #include "relation_types.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp index fa5af543e26..38cef5fcab0 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp @@ -1,6 +1,4 @@ #pragma once -#include "../polynomials/univariate.hpp" -#include "barretenberg/polynomials/polynomial.hpp" #include "relation_parameters.hpp" #include "relation_types.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp index 2120f3588e7..45c66965b9f 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp @@ -1,6 +1,4 @@ #pragma once -#include "../polynomials/univariate.hpp" -#include "barretenberg/polynomials/polynomial.hpp" #include "relation_parameters.hpp" #include "relation_types.hpp" // TODO(luke): change name of this file to permutation_grand_product_relation(s).hpp and move 'init' relation into it. diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp index 038212c28f5..a2a9f47b75d 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp @@ -1,17 +1,14 @@ -#include "../polynomials/barycentric_data.hpp" -#include "../polynomials/univariate.hpp" -#include "arithmetic_relation.hpp" #include "barretenberg/honk/flavor/standard.hpp" +#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" +#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" #include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" -#include "permutation_relation.hpp" -#include "relation_parameters.hpp" - -#include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/numeric/random/engine.hpp" - -#include #include + using namespace proof_system::honk::sumcheck; /** * The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is equivalent to diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp index f88bb12de1e..2ff1e3d917d 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp @@ -1,5 +1,4 @@ #include - #include "barretenberg/honk/composer/standard_composer.hpp" #include "barretenberg/honk/composer/ultra_composer.hpp" #include "barretenberg/honk/proof_system/grand_product_library.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp index a575a999a76..c9e72761338 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp @@ -1,6 +1,5 @@ #pragma once -#include namespace proof_system::honk::sumcheck { /** diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp index 6831c2ea732..ec9ee4744c5 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp @@ -1,7 +1,4 @@ #pragma once -#include -#include - #include "../polynomials/univariate.hpp" #include "relation_parameters.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp index e64ad40ddc4..fc351fb562e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp @@ -1,8 +1,4 @@ #pragma once -#include -#include - -#include "../polynomials/univariate.hpp" #include "relation_parameters.hpp" #include "relation_types.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp index ee36a28f0a2..3943f88729e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp @@ -1,6 +1,7 @@ #include "../polynomials/barycentric_data.hpp" #include "../polynomials/univariate.hpp" #include "arithmetic_relation.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/honk/flavor/ultra.hpp" #include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" #include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" @@ -8,14 +9,11 @@ #include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/numeric/random/engine.hpp" #include "permutation_relation.hpp" #include "relation_parameters.hpp" - -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/numeric/random/engine.hpp" - -#include #include + // TODO(luke): This testing infrastructure was duplicated between here and relation_consistency.test.cpp with the // orignal Flavor PR. Find a way to recombine these test suites or at least share this functionality. using namespace proof_system::honk::sumcheck; From e28045ce03f40e673f8ea5ce5bda3ea1d4b98823 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 02:33:33 +0000 Subject: [PATCH 10/45] Remove more includes --- .../honk/sumcheck/polynomials/multivariates.test.cpp | 4 +--- .../cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp | 7 ------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp index 82c26a54353..182c82d1853 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp @@ -1,8 +1,6 @@ -#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" #include "barretenberg/honk/sumcheck/sumcheck.hpp" - -#include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/numeric/random/engine.hpp" #include diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 7d21b09d001..c0084c3e7ba 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -8,13 +8,6 @@ #include "barretenberg/honk/utils/grand_product_delta.hpp" #include "polynomials/univariate.hpp" #include "sumcheck_round.hpp" -#include -#include -#include -#include -#include -#include -#include namespace proof_system::honk::sumcheck { From 6fc8b268d859008b9c17b40dc50a5806ec4cc233 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 02:36:06 +0000 Subject: [PATCH 11/45] Rename test suite. --- .../sumcheck/polynomials/multivariates.test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp index 182c82d1853..5e9103ec3c7 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp @@ -8,11 +8,11 @@ using namespace proof_system::honk::sumcheck; namespace test_sumcheck_polynomials { -template class MultivariatesTests : public testing::Test {}; +template class FoldingTests : public testing::Test {}; using Flavors = testing::Types; -TYPED_TEST_SUITE(MultivariatesTests, Flavors); +TYPED_TEST_SUITE(FoldingTests, Flavors); /* * We represent a bivariate f0 as f0(X0, X1). The indexing starts from 0 to match with the round number in sumcheck. @@ -40,7 +40,7 @@ TYPED_TEST_SUITE(MultivariatesTests, Flavors); * f0(u0,u1) = (v00 * (1-u0) + v10 * u0) * (1-u1) * + (v01 * (1-u0) + v11 * u0) * u1. */ -TYPED_TEST(MultivariatesTests, FoldTwoRoundsSpecial) +TYPED_TEST(FoldingTests, FoldTwoRoundsSpecial) { using Flavor = TypeParam; using FF = typename Flavor::FF; @@ -78,7 +78,7 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsSpecial) EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } -TYPED_TEST(MultivariatesTests, FoldTwoRoundsGeneric) +TYPED_TEST(FoldingTests, FoldTwoRoundsGeneric) { using Flavor = TypeParam; using FF = typename Flavor::FF; @@ -135,7 +135,7 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsGeneric) * f0(u0, u1, u2) = [(v000 * (1-u0) + v100 * u0) * (1-u1) + (v010 * (1-u0) + v110 * u0) * u1] * (1-u2) * + [(v001 * (1-u0) + v101 * u0) * (1-u1) + (v011 * (1-u0) + v111 * u0) * u1] * u2. */ -TYPED_TEST(MultivariatesTests, FoldThreeRoundsSpecial) +TYPED_TEST(FoldingTests, FoldThreeRoundsSpecial) { using Flavor = TypeParam; using FF = typename Flavor::FF; @@ -186,7 +186,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsSpecial) EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } -TYPED_TEST(MultivariatesTests, FoldThreeRoundsGeneric) +TYPED_TEST(FoldingTests, FoldThreeRoundsGeneric) { using Flavor = TypeParam; using FF = typename Flavor::FF; @@ -237,7 +237,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGeneric) EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } -TYPED_TEST(MultivariatesTests, FoldThreeRoundsGenericMultiplePolys) +TYPED_TEST(FoldingTests, FoldThreeRoundsGenericMultiplePolys) { using Flavor = TypeParam; using FF = typename Flavor::FF; From 668855603cb4163ef343cdef885828aecf1924e1 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 02:38:21 +0000 Subject: [PATCH 12/45] Rename tests--even better. --- .../sumcheck/polynomials/multivariates.test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp index 5e9103ec3c7..6894bf92c32 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp @@ -8,11 +8,11 @@ using namespace proof_system::honk::sumcheck; namespace test_sumcheck_polynomials { -template class FoldingTests : public testing::Test {}; +template class PartialEvaluationTests : public testing::Test {}; using Flavors = testing::Types; -TYPED_TEST_SUITE(FoldingTests, Flavors); +TYPED_TEST_SUITE(PartialEvaluationTests, Flavors); /* * We represent a bivariate f0 as f0(X0, X1). The indexing starts from 0 to match with the round number in sumcheck. @@ -40,7 +40,7 @@ TYPED_TEST_SUITE(FoldingTests, Flavors); * f0(u0,u1) = (v00 * (1-u0) + v10 * u0) * (1-u1) * + (v01 * (1-u0) + v11 * u0) * u1. */ -TYPED_TEST(FoldingTests, FoldTwoRoundsSpecial) +TYPED_TEST(PartialEvaluationTests, TwoRoundsSpecial) { using Flavor = TypeParam; using FF = typename Flavor::FF; @@ -78,7 +78,7 @@ TYPED_TEST(FoldingTests, FoldTwoRoundsSpecial) EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } -TYPED_TEST(FoldingTests, FoldTwoRoundsGeneric) +TYPED_TEST(PartialEvaluationTests, TwoRoundsGeneric) { using Flavor = TypeParam; using FF = typename Flavor::FF; @@ -135,7 +135,7 @@ TYPED_TEST(FoldingTests, FoldTwoRoundsGeneric) * f0(u0, u1, u2) = [(v000 * (1-u0) + v100 * u0) * (1-u1) + (v010 * (1-u0) + v110 * u0) * u1] * (1-u2) * + [(v001 * (1-u0) + v101 * u0) * (1-u1) + (v011 * (1-u0) + v111 * u0) * u1] * u2. */ -TYPED_TEST(FoldingTests, FoldThreeRoundsSpecial) +TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) { using Flavor = TypeParam; using FF = typename Flavor::FF; @@ -186,7 +186,7 @@ TYPED_TEST(FoldingTests, FoldThreeRoundsSpecial) EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } -TYPED_TEST(FoldingTests, FoldThreeRoundsGeneric) +TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) { using Flavor = TypeParam; using FF = typename Flavor::FF; @@ -237,7 +237,7 @@ TYPED_TEST(FoldingTests, FoldThreeRoundsGeneric) EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } -TYPED_TEST(FoldingTests, FoldThreeRoundsGenericMultiplePolys) +TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) { using Flavor = TypeParam; using FF = typename Flavor::FF; From 0b545dfeffa04c369b23d0ac54efa016758fc1a2 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 02:38:59 +0000 Subject: [PATCH 13/45] Move multivariates.test.cpp --- .../multivariates.test.cpp => partial_evaluation.test.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/{polynomials/multivariates.test.cpp => partial_evaluation.test.cpp} (100%) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp From ce06bee492b72c4f54169f12988a7bc262f77049 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 02:43:28 +0000 Subject: [PATCH 14/45] Clean up includes. --- .../barretenberg/honk/sumcheck/partial_evaluation.test.cpp | 3 --- .../honk/sumcheck/polynomials/univariate.test.cpp | 5 ++--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp index 6894bf92c32..b84b30c72e8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp @@ -1,8 +1,5 @@ #include "barretenberg/honk/flavor/standard.hpp" -#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" #include "barretenberg/honk/sumcheck/sumcheck.hpp" -#include "barretenberg/honk/transcript/transcript.hpp" -#include "barretenberg/numeric/random/engine.hpp" #include using namespace proof_system::honk::sumcheck; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp index 1952cdb6d5d..14083b2f09e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp @@ -1,8 +1,7 @@ -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barycentric_data.hpp" #include "univariate.hpp" - +#include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/numeric/random/engine.hpp" +#include "barycentric_data.hpp" #include using namespace proof_system::honk::sumcheck; From b148b499a1d4b9e89cd6f0409e66373db5730208 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 02:48:08 +0000 Subject: [PATCH 15/45] ...clean up includes. --- .../barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp | 2 -- .../honk/sumcheck/polynomials/barycentric_data.test.cpp | 2 -- .../src/barretenberg/honk/sumcheck/polynomials/univariate.hpp | 2 -- .../barretenberg/honk/sumcheck/polynomials/univariate.test.cpp | 2 -- 4 files changed, 8 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp index 31e84a6ecc6..80463295ec3 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp @@ -1,7 +1,5 @@ #pragma once #include "univariate.hpp" -#include -#include // TODO(#674): We need the functionality of BarycentricData for both field (native) and field_t (stdlib). The former is // is compatible with constexpr operations, and the former is not. The functions for computing the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.test.cpp index 91d67db9c4f..abe02b08a00 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.test.cpp @@ -1,7 +1,5 @@ #include "barycentric_data.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" - -#include "barretenberg/numeric/random/engine.hpp" #include using namespace proof_system::honk::sumcheck; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp index c6fdf5df583..7279a86e265 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp @@ -2,8 +2,6 @@ #include "barretenberg/common/assert.hpp" #include "barretenberg/common/serialize.hpp" #include -#include -#include #include namespace proof_system::honk::sumcheck { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp index 14083b2f09e..dcda91db938 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp @@ -1,6 +1,4 @@ -#include "univariate.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/numeric/random/engine.hpp" #include "barycentric_data.hpp" #include From 9daf7d71747cdf9068a7f05f239f2027b0c47294 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 03:05:03 +0000 Subject: [PATCH 16/45] Move up: univariate, barycentric, pow. --- .../benchmark/relations_bench/barycentric.bench.cpp | 2 +- .../cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp | 5 +++-- .../cpp/src/barretenberg/honk/flavor/standard.hpp | 5 +++-- .../cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp | 5 +++-- .../barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp | 5 +++-- .../cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp | 5 +++-- .../cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp | 5 +++-- .../cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp | 3 ++- .../honk/sumcheck/relations/relation_consistency.test.cpp | 5 +++-- .../barretenberg/honk/sumcheck/relations/relation_types.hpp | 2 +- .../sumcheck/relations/ultra_relation_consistency.test.cpp | 4 ++-- .../cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp | 2 +- .../cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp | 6 +++--- .../src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp | 2 +- .../src/barretenberg/honk/transcript/transcript.test.cpp | 3 ++- .../barycentric_data.hpp => polynomials/barycentric.hpp} | 0 .../barycentric.test.cpp} | 2 +- .../barretenberg/{honk/sumcheck => }/polynomials/pow.hpp | 0 .../{honk/sumcheck => }/polynomials/pow.test.cpp | 4 ++-- .../{honk/sumcheck => }/polynomials/univariate.hpp | 0 .../{honk/sumcheck => }/polynomials/univariate.test.cpp | 2 +- .../cpp/src/barretenberg/proof_system/flavor/flavor.hpp | 4 ++-- .../stdlib/recursion/honk/transcript/transcript.hpp | 3 ++- .../stdlib/recursion/honk/transcript/transcript.test.cpp | 3 ++- .../cpp/src/barretenberg/stdlib/utility/utility.hpp | 3 ++- .../cpp/src/barretenberg/transcript/transcript.test.cpp | 2 +- 26 files changed, 47 insertions(+), 35 deletions(-) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck/polynomials/barycentric_data.hpp => polynomials/barycentric.hpp} (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck/polynomials/barycentric_data.test.cpp => polynomials/barycentric.test.cpp} (99%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => }/polynomials/pow.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => }/polynomials/pow.test.cpp (80%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => }/polynomials/univariate.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => }/polynomials/univariate.test.cpp (99%) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp index cc1c1b04dcd..894958829b6 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp @@ -1,5 +1,5 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" +#include "barretenberg/polynomials/barycentric.hpp" #include using namespace benchmark; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 2b56c16e6cc..03fd3b1c3b6 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -1,8 +1,6 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" #include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" #include "barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp" #include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" @@ -11,11 +9,14 @@ #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" +#include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" +// WORKTODO ugh #include #include #include diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp index 91324a69ea1..6936817ace6 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp @@ -1,8 +1,9 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp index 90adf4d5387..e7169ce2f10 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp @@ -1,8 +1,9 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/ipa/ipa.hpp" -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index d5c348f2df6..961ec9d7eb0 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -1,8 +1,9 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" #include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp index 173ee9de622..fb89959fa31 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp @@ -2,8 +2,9 @@ #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/ipa/ipa.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" #include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp index 3162b860482..29579d128cc 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp @@ -2,8 +2,9 @@ #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" #include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp index b2f673b7cab..7818514fb33 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp @@ -4,7 +4,8 @@ #include "barretenberg/honk/pcs/claim.hpp" #include "barretenberg/honk/proof_system/grand_product_library.hpp" #include "barretenberg/honk/proof_system/prover_library.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" // will go away +#include "barretenberg/polynomials/univariate.hpp" + // will go away #include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/sumcheck/sumcheck.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp index a2a9f47b75d..39a0dcc87cc 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp @@ -1,6 +1,7 @@ #include "barretenberg/honk/flavor/standard.hpp" -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp index ec9ee4744c5..88a0be6e5aa 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../polynomials/univariate.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "relation_parameters.hpp" namespace proof_system::honk::sumcheck { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp index 3943f88729e..e7aee5046cd 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp @@ -1,5 +1,5 @@ -#include "../polynomials/barycentric_data.hpp" -#include "../polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "arithmetic_relation.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/honk/flavor/ultra.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index c0084c3e7ba..6fffa96dbbb 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -6,7 +6,7 @@ #include "barretenberg/honk/sumcheck/sumcheck_output.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/honk/utils/grand_product_delta.hpp" -#include "polynomials/univariate.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "sumcheck_round.hpp" namespace proof_system::honk::sumcheck { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 4dc27e075f8..48f8e90a58a 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -2,9 +2,9 @@ #include "barretenberg/common/log.hpp" #include "barretenberg/common/thread.hpp" #include "barretenberg/honk/flavor/ultra.hpp" -#include "polynomials/barycentric_data.hpp" -#include "polynomials/pow.hpp" -#include "polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/pow.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "relations/relation_parameters.hpp" #include #include diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp index fa6b176e0be..bd398e42040 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp @@ -1,7 +1,7 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/numeric/random/engine.hpp" -#include "polynomials/univariate.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "sumcheck_round.hpp" #include diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp index 3821d5d6505..627469af283 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp @@ -2,7 +2,8 @@ #include "barretenberg/honk/composer/standard_composer.hpp" #include "barretenberg/honk/composer/ultra_composer.hpp" #include "barretenberg/honk/flavor/standard.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" #include "transcript.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp similarity index 99% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.test.cpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp index abe02b08a00..986579f5e2c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/barycentric_data.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp @@ -1,4 +1,4 @@ -#include "barycentric_data.hpp" +#include "barycentric.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/pow.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/pow.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/pow.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp similarity index 80% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/pow.test.cpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp index b67816d3632..b3c88dff07e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/pow.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp @@ -1,5 +1,4 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/utils/power_polynomial.hpp" #include "pow.hpp" #include @@ -20,7 +19,8 @@ TEST(SumcheckPow, FullPowConsistency) pow_univariate.partially_evaluate(u_i); } - FF expected_eval = proof_system::honk::power_polynomial::evaluate(zeta, variables); + FF expected_eval; // WORKTODO + // FF expected_eval = proof_system::honk::power_polynomial::evaluate(zeta, variables); EXPECT_EQ(pow_univariate.partial_evaluation_constant, expected_eval); } } // namespace proof_system::honk::sumcheck::pow_test diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp similarity index 99% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp index dcda91db938..a0a63d41f74 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/polynomials/univariate.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp @@ -1,5 +1,5 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barycentric_data.hpp" +#include "barycentric.hpp" #include using namespace proof_system::honk::sumcheck; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 45d019a417b..2f6e44d1d46 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -64,8 +64,8 @@ */ #pragma once -#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/proof_system/types/circuit_type.hpp" #include "barretenberg/honk/pcs/commitment_key.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.hpp index c26809d4353..cfdd0e2bcfd 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.hpp @@ -3,7 +3,8 @@ #include "barretenberg/ecc/curves/bn254/fq.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp index f32032e499b..bb83ba510e8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp @@ -4,7 +4,8 @@ #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/flavor/ultra.hpp" #include "barretenberg/honk/flavor/ultra_recursive.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/stdlib/recursion/honk/transcript/transcript.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/utility/utility.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/utility/utility.hpp index 0031ef3231a..d6927b4ad8e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/utility/utility.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/utility/utility.hpp @@ -3,7 +3,8 @@ #include "barretenberg/ecc/curves/bn254/fq.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/univariate.hpp" + #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp index 0603a7e2207..a2422874876 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp @@ -1,4 +1,4 @@ -#include "../honk/sumcheck/polynomials/univariate.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "transcript_wrappers.hpp" #include #include From 8ef4655c2d77b5f8793f22c1202c236bd8a04aab Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 04:07:02 +0000 Subject: [PATCH 17/45] Move univariate, pow, barycentric to bb namespace. --- .../relations_bench/barycentric.bench.cpp | 3 ++ .../barretenberg/honk/flavor/goblin_ultra.hpp | 15 +------- .../src/barretenberg/honk/flavor/standard.hpp | 10 +---- .../honk/flavor/standard_grumpkin.hpp | 2 +- .../src/barretenberg/honk/flavor/ultra.hpp | 2 +- .../honk/flavor/ultra_grumpkin.hpp | 2 +- .../relations/relation_consistency.test.cpp | 7 ++-- .../sumcheck/relations/relation_types.hpp | 4 +- .../ultra_relation_consistency.test.cpp | 5 +++ .../barretenberg/honk/sumcheck/sumcheck.hpp | 16 ++++---- .../honk/sumcheck/sumcheck_round.hpp | 38 ++++++++++--------- .../honk/sumcheck/sumcheck_round.test.cpp | 3 ++ .../honk/transcript/transcript.test.cpp | 6 +-- .../barretenberg/polynomials/barycentric.hpp | 4 +- .../polynomials/barycentric.test.cpp | 5 +-- .../barretenberg/polynomials/polynomial.hpp | 4 +- .../cpp/src/barretenberg/polynomials/pow.hpp | 4 +- .../src/barretenberg/polynomials/pow.test.cpp | 6 +-- .../barretenberg/polynomials/univariate.hpp | 4 +- .../polynomials/univariate.test.cpp | 5 +-- .../honk/transcript/transcript.test.cpp | 7 ++-- .../barretenberg/stdlib/utility/utility.hpp | 4 +- .../transcript/transcript.test.cpp | 2 +- 23 files changed, 74 insertions(+), 84 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp index 894958829b6..f6a439df496 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp @@ -9,6 +9,9 @@ auto& engine = numeric::random::get_debug_engine(); } using FF = barretenberg::fr; +using barretenberg::Univariate; +using barretenberg::BarycentricData; + namespace proof_system::honk::sumcheck::relations_bench { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 03fd3b1c3b6..b80d9472136 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -1,5 +1,4 @@ #pragma once -#include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" #include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" #include "barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp" @@ -9,20 +8,10 @@ #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" -#include "barretenberg/srs/factories/crs_factory.hpp" -// WORKTODO ugh -#include -#include -#include -#include -#include -#include + namespace proof_system::honk::flavor { @@ -340,7 +329,7 @@ class GoblinUltra { */ template using ExtendedEdges = - AllEntities, sumcheck::Univariate>; + AllEntities, barretenberg::Univariate>; /** * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp index 6936817ace6..8b42850560b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp @@ -12,12 +12,6 @@ #include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" -#include -#include -#include -#include -#include -#include namespace proof_system::honk::flavor { @@ -235,8 +229,8 @@ class Standard { * @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH? */ template - using ExtendedEdges = - AllEntities, sumcheck::Univariate>; + using ExtendedEdges = AllEntities, + barretenberg::Univariate>; /** * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp index e7169ce2f10..6081744dfe2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp @@ -227,7 +227,7 @@ class StandardGrumpkin { */ template using ExtendedEdges = - AllEntities, sumcheck::Univariate>; + AllEntities, barretenberg::Univariate>; /** * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 961ec9d7eb0..85bef385369 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -304,7 +304,7 @@ class Ultra { */ template using ExtendedEdges = - AllEntities, sumcheck::Univariate>; + AllEntities, barretenberg::Univariate>; /** * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp index fb89959fa31..e39563307c5 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp @@ -304,7 +304,7 @@ class UltraGrumpkin { */ template using ExtendedEdges = - AllEntities, sumcheck::Univariate>; + AllEntities, barretenberg::Univariate>; /** * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp index 39a0dcc87cc..9185a359e97 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp @@ -1,16 +1,17 @@ #include "barretenberg/honk/flavor/standard.hpp" -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/univariate.hpp" - #include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" #include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/numeric/random/engine.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include using namespace proof_system::honk::sumcheck; +using barretenberg::Univariate; +using barretenberg::BarycentricData; /** * The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is equivalent to * a simpler unoptimized version implemented in the tests themselves. This is useful 1) as documentation since the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp index 88a0be6e5aa..fd4b81699c0 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp @@ -70,8 +70,8 @@ template typename RelationBase> class Relation // WORKTODO: does these templates being defined inside of here mean we can't reuse their instantiations? template struct UnivariateAccumulatorTypes { // These Values are extracted from RelationBase. - using Accumulators = std::tuple...>; - using AccumulatorViews = std::tuple...>; + using Accumulators = std::tuple...>; + using AccumulatorViews = std::tuple...>; }; template struct ValueAccumulatorTypes { using Accumulators = std::array; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp index e7aee5046cd..5655f451334 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp @@ -14,6 +14,9 @@ #include "relation_parameters.hpp" #include +using barretenberg::BarycentricData; +using barretenberg::Univariate; + // TODO(luke): This testing infrastructure was duplicated between here and relation_consistency.test.cpp with the // orignal Flavor PR. Find a way to recombine these test suites or at least share this functionality. using namespace proof_system::honk::sumcheck; @@ -29,6 +32,8 @@ using namespace proof_system::honk::sumcheck; */ static const size_t INPUT_UNIVARIATE_LENGTH = 2; +using barretenberg::Univariate; + namespace proof_system::honk_relation_tests { class UltraRelationConsistency : public testing::Test { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 6fffa96dbbb..80ffc8c04e8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -70,12 +70,12 @@ template class SumcheckProver { * * @details */ - SumcheckOutput prove( - auto full_polynomials, const RelationParameters& relation_parameters) // pass by value, not by reference + SumcheckOutput prove(auto full_polynomials, + const RelationParameters& relation_parameters) // pass by value, not by reference { auto [alpha, zeta] = transcript.get_challenges("Sumcheck:alpha", "Sumcheck:zeta"); - PowUnivariate pow_univariate(zeta); + barretenberg::PowUnivariate pow_univariate(zeta); std::vector multivariate_challenge; multivariate_challenge.reserve(multivariate_d); @@ -169,8 +169,8 @@ template class SumcheckVerifier { * target sum. * * @details If verification fails, returns std::nullopt, otherwise returns SumcheckOutput - * @param relation_parameters - * @param transcript + * @param relation_parameters + * @param transcript */ std::optional> verify(const RelationParameters& relation_parameters, auto& transcript) { @@ -178,7 +178,7 @@ template class SumcheckVerifier { auto [alpha, zeta] = transcript.get_challenges("Sumcheck:alpha", "Sumcheck:zeta"); - PowUnivariate pow_univariate(zeta); + barretenberg::PowUnivariate pow_univariate(zeta); // All but final round. // target_total_sum is initialized to zero then mutated in place. @@ -192,8 +192,8 @@ template class SumcheckVerifier { for (size_t round_idx = 0; round_idx < multivariate_d; round_idx++) { // Obtain the round univariate from the transcript std::string round_univariate_label = "Sumcheck:univariate_" + std::to_string(round_idx); - auto round_univariate = transcript.template receive_from_prover>( - round_univariate_label); + auto round_univariate = transcript.template receive_from_prover< + barretenberg::Univariate>(round_univariate_label); bool checked = round.check_sum(round_univariate); verified = verified && checked; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 48f8e90a58a..7a4a16e819d 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -75,7 +75,9 @@ template class SumcheckProverRound { RelationUnivariates univariate_accumulators; // TODO(#224)(Cody): this should go away - BarycentricData barycentric_2_to_max = BarycentricData(); + // WORKTODO long + barretenberg::BarycentricData barycentric_2_to_max = + barretenberg::BarycentricData(); // Prover constructor SumcheckProverRound(size_t initial_round_size) @@ -91,13 +93,13 @@ template class SumcheckProverRound { * * @tparam T : In practice, this is a Univariate. */ - Univariate batch_over_relations(FF challenge, - const PowUnivariate& pow_univariate) + barretenberg::Univariate batch_over_relations( + FF challenge, const barretenberg::PowUnivariate& pow_univariate) { FF running_challenge = 1; scale_univariates(univariate_accumulators, challenge, running_challenge); - auto result = Univariate(0); + auto result = barretenberg::Univariate(0); extend_and_batch_univariates(univariate_accumulators, pow_univariate, result); // Reset all univariate accumulators to 0 before beginning accumulation in the next round @@ -116,7 +118,7 @@ template class SumcheckProverRound { { size_t univariate_idx = 0; // TODO(#391) zip for (auto& poly : multivariates) { - auto edge = Univariate({ poly[edge_idx], poly[edge_idx + 1] }); + auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); extended_edges[univariate_idx] = barycentric_2_to_max.extend(edge); ++univariate_idx; } @@ -127,9 +129,9 @@ template class SumcheckProverRound { * values. Most likely this will end up being S_l(0), ... , S_l(t-1) where t is around 12. At the end, reset all * univariate accumulators to be zero. */ - Univariate compute_univariate(auto& polynomials, + barretenberg::Univariate compute_univariate(auto& polynomials, const RelationParameters& relation_parameters, - const PowUnivariate& pow_univariate, + const barretenberg::PowUnivariate& pow_univariate, const FF alpha) { // Precompute the vector of required powers of zeta @@ -241,20 +243,21 @@ template class SumcheckProverRound { */ template static void extend_and_batch_univariates(auto& tuple, - const PowUnivariate& pow_univariate, - Univariate& result) + const barretenberg::PowUnivariate& pow_univariate, + barretenberg::Univariate& result) { // Random poly R(X) = (1-X) + X.zeta_pow - auto random_poly_edge = Univariate({ 1, pow_univariate.zeta_pow }); - BarycentricData pow_zeta_univariate_extender = BarycentricData(); - Univariate extended_random_polynomial_edge = + auto random_poly_edge = barretenberg::Univariate({ 1, pow_univariate.zeta_pow }); + barretenberg::BarycentricData pow_zeta_univariate_extender = + barretenberg::BarycentricData(); + barretenberg::Univariate extended_random_polynomial_edge = pow_zeta_univariate_extender.extend(random_poly_edge); auto extend_and_sum = [&](Element& element) { using Relation = typename std::tuple_element::type; // TODO(#224)(Cody): this barycentric stuff should be more built-in? - BarycentricData barycentric_utils; + barretenberg::BarycentricData barycentric_utils; auto extended = barycentric_utils.extend(element); const bool is_subrelation_linearly_independent = @@ -401,7 +404,7 @@ template class SumcheckVerifierRound { */ FF compute_full_honk_relation_purported_value(ClaimedEvaluations purported_evaluations, const RelationParameters& relation_parameters, - const PowUnivariate& pow_univariate, + const barretenberg::PowUnivariate& pow_univariate, const FF alpha) { accumulate_relation_evaluations<>( @@ -418,7 +421,7 @@ template class SumcheckVerifierRound { * * @param univariate T^{l}(X), the round univariate that is equal to S^{l}(X)/( (1−X) + X⋅ζ^{ 2^l } ) */ - bool check_sum(Univariate& univariate) + bool check_sum(barretenberg::Univariate& univariate) { // S^{l}(0) = ( (1−0) + 0⋅ζ^{ 2^l } ) ⋅ T^{l}(0) = T^{l}(0) // S^{l}(1) = ( (1−1) + 1⋅ζ^{ 2^l } ) ⋅ T^{l}(1) = ζ^{ 2^l } ⋅ T^{l}(1) @@ -445,11 +448,12 @@ template class SumcheckVerifierRound { * @param round_challenge u_l * @return FF sigma_{l+1} = S^l(u_l) */ - FF compute_next_target_sum(Univariate& univariate, FF& round_challenge) + FF compute_next_target_sum(barretenberg::Univariate& univariate, FF& round_challenge) { // IMPROVEMENT(Cody): Use barycentric static method, maybe implement evaluation as member // function on Univariate. - auto barycentric = BarycentricData(); + auto barycentric = + barretenberg::BarycentricData(); // Evaluate T^{l}(u_{l}) target_total_sum = barycentric.evaluate(univariate, round_challenge); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp index bd398e42040..183ec09bbb5 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp @@ -18,6 +18,9 @@ using namespace proof_system::honk; using namespace proof_system::honk::sumcheck; +using barretenberg::Univariate; +using barretenberg::PowUnivariate; +using barretenberg::BarycentricData; using Flavor = flavor::Standard; using FF = typename Flavor::FF; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp index 627469af283..89b26fa53fd 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp @@ -3,14 +3,10 @@ #include "barretenberg/honk/composer/ultra_composer.hpp" #include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/polynomials/univariate.hpp" - #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" #include "transcript.hpp" -#include -#include #include -#include using namespace proof_system::honk; @@ -189,7 +185,7 @@ TYPED_TEST(TranscriptTests, ProverAndVerifierBasic) constexpr size_t LENGTH = 8; using Fr = barretenberg::fr; - using Univariate = proof_system::honk::sumcheck::Univariate; + using Univariate = barretenberg::Univariate; using Commitment = barretenberg::g1::affine_element; std::array evaluations; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp index 80463295ec3..b84bccd1214 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp @@ -15,7 +15,7 @@ 3) There should be more thorough testing of this class in isolation. */ -namespace proof_system::honk::sumcheck { +namespace barretenberg { /** @@ -411,4 +411,4 @@ using BarycentricData = std::conditional_t, BarycentricDataCompileTime, BarycentricDataRunTime>; -} // namespace proof_system::honk::sumcheck +} // namespace barretenberg diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp index 986579f5e2c..2dcda2c229d 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp @@ -2,8 +2,7 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" #include -using namespace proof_system::honk::sumcheck; -namespace test_sumcheck_polynomials { +namespace barretenberg::test_barycentric { template class BarycentricDataTests : public testing::Test {}; @@ -95,4 +94,4 @@ TYPED_TEST(BarycentricDataTests, BarycentricData5to6) EXPECT_EQ(ext1, expected); } -} // namespace test_sumcheck_polynomials +} // namespace barretenberg::test_barycentric diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index a12f79be787..7b9be45c8e8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -4,10 +4,8 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "evaluation_domain.hpp" #include "polynomial_arithmetic.hpp" -#include -#include #include -#include + namespace barretenberg { template class Polynomial { public: diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp index dd84d7cebc8..9039266cac0 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp @@ -1,6 +1,6 @@ #pragma once -namespace proof_system::honk::sumcheck { +namespace barretenberg { /** * @brief Succinct representation of the `pow` polynomial that can be partially evaluated variable-by-variable. @@ -128,4 +128,4 @@ template struct PowUnivariate { partial_evaluation_constant *= current_univariate_eval; } }; -} // namespace proof_system::honk::sumcheck \ No newline at end of file +} // namespace barretenberg \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp index b3c88dff07e..772126924bb 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp @@ -1,8 +1,8 @@ -#include "barretenberg/ecc/curves/bn254/fr.hpp" #include "pow.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" #include -namespace proof_system::honk::sumcheck::pow_test { +namespace barretenberg::test_pow { using FF = barretenberg::fr; @@ -23,4 +23,4 @@ TEST(SumcheckPow, FullPowConsistency) // FF expected_eval = proof_system::honk::power_polynomial::evaluate(zeta, variables); EXPECT_EQ(pow_univariate.partial_evaluation_constant, expected_eval); } -} // namespace proof_system::honk::sumcheck::pow_test +} // namespace barretenberg::test_pow diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp index 7279a86e265..fffb79155c2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp @@ -4,7 +4,7 @@ #include #include -namespace proof_system::honk::sumcheck { +namespace barretenberg { template class UnivariateView; @@ -365,4 +365,4 @@ template std::array array_to_array return array_to_array_aux(elements, std::make_index_sequence()); }; -} // namespace proof_system::honk::sumcheck +} // namespace barretenberg diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp index a0a63d41f74..41a35337142 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp @@ -2,8 +2,7 @@ #include "barycentric.hpp" #include -using namespace proof_system::honk::sumcheck; -namespace test_univariate { +namespace barretenberg::test_univariate { template class UnivariateTest : public testing::Test { public: @@ -160,4 +159,4 @@ TYPED_TEST(UnivariateTest, Serialization) } } -} // namespace test_univariate +} // namespace barretenberg::test_univariate diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp index bb83ba510e8..9611368117c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp @@ -4,9 +4,8 @@ #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/flavor/ultra.hpp" #include "barretenberg/honk/flavor/ultra_recursive.hpp" -#include "barretenberg/polynomials/univariate.hpp" - #include "barretenberg/honk/transcript/transcript.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/stdlib/recursion/honk/transcript/transcript.hpp" namespace proof_system::plonk::stdlib::recursion::honk { @@ -28,7 +27,7 @@ template auto generate_mock_proof_data(auto prover { using FF = typename Flavor::FF; using Commitment = typename Flavor::Commitment; - using Univariate = typename proof_system::honk::sumcheck::Univariate; + using Univariate = typename barretenberg::Univariate; // Create some mock data to be added to the transcript in several mock rounds uint32_t data = 25; @@ -70,7 +69,7 @@ template void perform_mock_verifier_transcript_ope { using FF = typename Flavor::FF; using Commitment = typename Flavor::Commitment; - using Univariate = typename proof_system::honk::sumcheck::Univariate; + using Univariate = typename barretenberg::Univariate; // round 0 transcript.template receive_from_prover("data"); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/utility/utility.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/utility/utility.hpp index d6927b4ad8e..e17926fa47d 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/utility/utility.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/utility/utility.hpp @@ -29,8 +29,8 @@ template class StdlibTypesUtility { using element_ct = element; using FF = barretenberg::fr; using Commitment = barretenberg::g1::affine_element; - template using Univariate = proof_system::honk::sumcheck::Univariate; - template using Univariate_ct = proof_system::honk::sumcheck::Univariate; + template using Univariate = barretenberg::Univariate; + template using Univariate_ct = barretenberg::Univariate; public: /** diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp index a2422874876..6489f90d014 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp @@ -136,7 +136,7 @@ TEST(transcript, univariate_serialization) constexpr size_t LENGTH = 8; using Fr = barretenberg::fr; - using Univariate = proof_system::honk::sumcheck::Univariate; + using Univariate = barretenberg::Univariate; using Transcript = transcript::StandardTranscript; std::vector g1_vector(64); From 4e6be56814a5b0810dcf2489c8e70a830c4f683a Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 04:11:42 +0000 Subject: [PATCH 18/45] Link only polynomaials. --- .../src/barretenberg/benchmark/relations_bench/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt index c40aecbd33f..0d2b36e0538 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt @@ -6,7 +6,7 @@ relations.bench.cpp # Required libraries for benchmark suites set(LINKED_LIBRARIES - honk + polynomials benchmark::benchmark ) From 25c444028c1e47a944e5289bfd5aed2b39b1c35f Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 14:03:42 +0000 Subject: [PATCH 19/45] Prune includes --- .../cpp/src/barretenberg/honk/flavor/ultra.hpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 85bef385369..057c6958ba7 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -15,13 +15,6 @@ #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" -#include "barretenberg/srs/factories/crs_factory.hpp" -#include -#include -#include -#include -#include -#include namespace proof_system::honk::flavor { From 3a9307feed9f2530f5fc126c05bb32553d7869d9 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 19:28:46 +0000 Subject: [PATCH 20/45] Refactor to be indep of flavor, hence Honk. --- .../src/barretenberg/honk/flavor/standard.hpp | 5 +- .../relations/relation_consistency.test.cpp | 374 ++++++------------ .../relations/relation_parameters.hpp | 10 + .../sumcheck/relations/relation_types.hpp | 8 +- 4 files changed, 129 insertions(+), 268 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp index 8b42850560b..f356afdfa02 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp @@ -1,14 +1,13 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/univariate.hpp" - #include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" +#include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp index 9185a359e97..2d5f28f8a2f 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp @@ -1,293 +1,145 @@ -#include "barretenberg/honk/flavor/standard.hpp" -#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" -#include "barretenberg/numeric/random/engine.hpp" -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/univariate.hpp" -#include - -using namespace proof_system::honk::sumcheck; -using barretenberg::Univariate; -using barretenberg::BarycentricData; /** - * The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is equivalent to - * a simpler unoptimized version implemented in the tests themselves. This is useful 1) as documentation since the - * simple implementations here should make the underlying arithmetic easier to see, and 2) as a check that optimizations - * introduced into the Relations have not changed the result. + * @file relation_consistency.test.cpp + * @brief Show that relation arithmetic has a simple form. + * @details The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is + * equivalent to a simpler unoptimized version implemented in the tests themselves. This is useful 1) as documentation + * since the simple implementations here should make the underlying arithmetic easier to see, and 2) as a check that + * optimizations introduced into the Relations have not changed the result. * * For this purpose, we simply feed (the same) random inputs into each of the two implementations and confirm that * the outputs match. This does not confirm the correctness of the identity arithmetic (the identities will not be * satisfied in general by random inputs) only that the two implementations are equivalent. + * */ -static const size_t INPUT_UNIVARIATE_LENGTH = 2; +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include -namespace proof_system::honk_relation_tests { +using namespace proof_system::honk::sumcheck; -class StandardRelationConsistency : public testing::Test { - public: - using Flavor = honk::flavor::Standard; - using FF = typename Flavor::FF; - using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; - // TODO(#390): Move MAX_RELATION_LENGTH into Flavor and simplify this. +namespace proof_system::honk_relation_tests { - template using ExtendedEdges = typename Flavor::template ExtendedEdges; +using FF = barretenberg::fr; +struct InputElements { + static constexpr size_t NUM_ELEMENTS = 18; + std::array _data; - // TODO(#225)(Adrian): Accept FULL_RELATION_LENGTH as a template parameter for this function only, so that the - // test can decide to which degree the polynomials must be extended. Possible accept an existing list of - // "edges" and extend them to the degree. - template - static void compute_mock_extended_edges( - ExtendedEdges& extended_edges, - std::array, NUM_POLYNOMIALS>& input_edges) + static InputElements get_random() { - BarycentricData barycentric_2_to_max = - BarycentricData(); - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - extended_edges[i] = barycentric_2_to_max.extend(input_edges[i]); - } + InputElements result; + std::generate(result._data.begin(), result._data.end(), [] { return FF::random_element(); }); + return result; } - /** - * @brief Returns randomly sampled parameters to feed to the relations. - * - * @return RelationParameters - */ - RelationParameters compute_mock_relation_parameters() + static InputElements get_special() { - return { .eta = FF::random_element(), - .beta = FF::random_element(), - .gamma = FF::random_element(), - .public_input_delta = FF::random_element(), - .lookup_grand_product_delta = FF::random_element() }; + InputElements result; + FF idx = 0; + std::generate(result._data.begin(), result._data.end(), [&] { + idx += FF(1); + return idx; + }); + return result; } - /** - * @brief Given an array of Univariates, create a new array containing only the i-th evaluations - * of all the univariates. - * - * @note Not really optimized, mainly used for testing that the relations evaluate to the same value when - * evaluated as Univariates, Expressions, or index-by-index - * @todo(Adrian) Maybe this is more helpful as part of a `check_logic` function. - * - * @tparam NUM_UNIVARIATES number of univariates in the input array (deduced from `univariates`) - * @tparam univariate_length number of evaluations (deduced from `univariates`) - * @param univariates array of Univariates - * @param i index of the evaluations we want to take from each univariate - * @return std::array such that result[j] = univariates[j].value_at(i) - */ - template - static ClaimedEvaluations transposed_univariate_array_at(ExtendedEdges univariates, size_t i) - { - ASSERT(i < univariate_length); - std::array result; - size_t result_idx = 0; // TODO(#391) zip - for (auto& univariate : univariates) { - result[result_idx] = univariate.value_at(i); - ++result_idx; - } - return result; - }; + FF& q_c = std::get<0>(_data); + FF& q_l = std::get<1>(_data); + FF& q_r = std::get<2>(_data); + FF& q_o = std::get<3>(_data); + FF& q_m = std::get<4>(_data); + FF& sigma_1 = std::get<5>(_data); + FF& sigma_2 = std::get<6>(_data); + FF& sigma_3 = std::get<7>(_data); + FF& id_1 = std::get<8>(_data); + FF& id_2 = std::get<9>(_data); + FF& id_3 = std::get<10>(_data); + FF& lagrange_first = std::get<11>(_data); + FF& lagrange_last = std::get<12>(_data); + FF& w_l = std::get<13>(_data); + FF& w_r = std::get<14>(_data); + FF& w_o = std::get<15>(_data); + FF& z_perm = std::get<16>(_data); + FF& z_perm_shift = std::get<17>(_data); +}; - /** - * @brief Compute the evaluation of a `relation` in different ways, comparing it to the provided `expected_evals` - * - * @details Check both `add_full_relation_value_contribution` and `add_edge_contribution` by comparing the result to - * the `expected_evals` computed by the caller. - * Ensures that the relations compute the same result as the expression given in the tests. - * - * @param expected_evals Relation evaluation computed by the caller. - * @param relation being tested - * @param extended_edges - * @param relation_parameters - */ - template - static void validate_evaluations(const auto& expected_full_length_univariates, /* array of Univariates*/ - const auto relation, - const ExtendedEdges& extended_edges, - const RelationParameters& relation_parameters) +class StandardRelationConsistency : public testing::Test { + public: + template + static void validate_relation_execution(const auto& expected_values, const InputElements& input_elements, const auto& parameters) { - // First check that the verifier's computation on individual evaluations is correct. - // Note: since add_full_relation_value_contribution computes the identities at a single evaluation of the - // multivariates, we need only pass in one evaluation point from the extended edges. Which one we choose is - // arbitrary so we choose the 0th. - - // Extract the RelationValues type for the given relation - using RelationValues = typename decltype(relation)::RelationValues; - RelationValues relation_evals; - RelationValues expected_relation_evals; - - ASSERT_EQ(expected_relation_evals.size(), expected_full_length_univariates.size()); - // Initialize expected_evals to 0th coefficient of expected full length univariates - for (size_t idx = 0; idx < relation_evals.size(); ++idx) { - relation_evals[idx] = FF(0); // initialize to 0 - expected_relation_evals[idx] = expected_full_length_univariates[idx].value_at(0); - } - - // Extract 0th evaluation from extended edges - ClaimedEvaluations edge_evaluations = transposed_univariate_array_at(extended_edges, 0); - - // Evaluate the relation using the verifier functionality - relation.add_full_relation_value_contribution(relation_evals, edge_evaluations, relation_parameters); - - EXPECT_EQ(relation_evals, expected_relation_evals); - - // Next, check that the prover's computation on Univariates is correct - - using RelationUnivariates = typename decltype(relation)::RelationUnivariates; - RelationUnivariates relation_univariates; - zero_univariates<>(relation_univariates); - - constexpr std::size_t num_univariates = std::tuple_size::value; - - // Compute the relatiion univariates via the sumcheck prover functionality, then extend - // them to full length for easy comparison with the expected result. - relation.add_edge_contribution(relation_univariates, extended_edges, relation_parameters, 1); - - auto full_length_univariates = std::array, num_univariates>(); - extend_tuple_of_arrays(relation_univariates, full_length_univariates); - - EXPECT_EQ(full_length_univariates, expected_full_length_univariates); + typename Relation::RelationValues accumulator; + std::fill(accumulator.begin(), accumulator.end(), FF(0)); + Relation::add_full_relation_value_contribution(accumulator, input_elements, parameters); + EXPECT_EQ(accumulator, expected_values); }; - - template static void zero_univariates(std::tuple& tuple) - { - auto& element = std::get(tuple); - std::fill(element.evaluations.begin(), element.evaluations.end(), FF(0)); - - if constexpr (idx + 1 < sizeof...(Ts)) { - zero_univariates(tuple); - } - } - - template - static void extend_tuple_of_arrays(std::tuple& tuple, auto& result_univariates) - { - auto& element = std::get(tuple); - using Element = std::remove_reference_t; - BarycentricData barycentric_utils; - result_univariates[idx] = barycentric_utils.extend(element); - - if constexpr (idx + 1 < sizeof...(Ts)) { - extend_tuple_of_arrays(tuple, result_univariates); - } - } }; TEST_F(StandardRelationConsistency, ArithmeticRelation) { - using Flavor = honk::flavor::Standard; - using FF = typename Flavor::FF; - static constexpr size_t FULL_RELATION_LENGTH = 5; - using ExtendedEdges = typename Flavor::template ExtendedEdges; - static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; - - const auto relation_parameters = compute_mock_relation_parameters(); - auto run_test = [&relation_parameters](bool is_random_input) { - std::array, NUM_POLYNOMIALS> input_polynomials; - ExtendedEdges extended_edges; - if (!is_random_input) { - // evaluation form, i.e. input_univariate(0) = 1, input_univariate(1) = 2,.. The polynomial is x+1. - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = Univariate({ 1, 2 }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - } else { - // input_univariates are random polynomials of degree one - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = - Univariate({ FF::random_element(), FF::random_element() }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - }; - auto relation = ArithmeticRelation(); - // Manually compute the expected edge contribution - const auto& w_l = extended_edges.w_l; - const auto& w_r = extended_edges.w_r; - const auto& w_o = extended_edges.w_o; - const auto& q_m = extended_edges.q_m; - const auto& q_l = extended_edges.q_l; - const auto& q_r = extended_edges.q_r; - const auto& q_o = extended_edges.q_o; - const auto& q_c = extended_edges.q_c; - - // Compute expected full length Univariates using straight forward expressions. - // Note: expect { { 5, 22, 57, 116, 205} } for input polynomial {1, 2} - constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; - auto expected_full_length_univariates = std::array, NUM_SUBRELATIONS>(); - - expected_full_length_univariates[0] = (q_m * w_r * w_l) + (q_r * w_r) + (q_l * w_l) + (q_o * w_o) + (q_c); - validate_evaluations(expected_full_length_univariates, relation, extended_edges, relation_parameters); + auto run_test = [](bool random_inputs) { + using Relation = ArithmeticRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_l = input_elements.w_l; + const auto& w_r = input_elements.w_r; + const auto& w_o = input_elements.w_o; + const auto& q_m = input_elements.q_m; + const auto& q_l = input_elements.q_l; + const auto& q_r = input_elements.q_r; + const auto& q_o = input_elements.q_o; + const auto& q_c = input_elements.q_c; + + RelationValues expected_values; + expected_values[0] = (q_m * w_r * w_l) + (q_r * w_r) + (q_l * w_l) + (q_o * w_o) + (q_c); + + const auto parameters = RelationParameters::get_random(); + + validate_relation_execution(expected_values, input_elements, parameters); }; - run_test(/* is_random_input=*/true); - run_test(/* is_random_input=*/false); + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); }; TEST_F(StandardRelationConsistency, PermutationRelation) { - using Flavor = honk::flavor::Standard; - using FF = typename Flavor::FF; - static constexpr size_t FULL_RELATION_LENGTH = 5; - using ExtendedEdges = typename Flavor::template ExtendedEdges; - static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; - - const auto relation_parameters = compute_mock_relation_parameters(); - auto run_test = [&relation_parameters](bool is_random_input) { - ExtendedEdges extended_edges; - std::array, NUM_POLYNOMIALS> input_polynomials; - if (!is_random_input) { - // evaluation form, i.e. input_univariate(0) = 1, input_univariate(1) = 2,.. The polynomial is x+1. - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = Univariate({ 1, 2 }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - } else { - // input_univariates are random polynomials of degree one - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = - Univariate({ FF::random_element(), FF::random_element() }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - }; - auto relation = PermutationRelation(); - - const auto& beta = relation_parameters.beta; - const auto& gamma = relation_parameters.gamma; - const auto& public_input_delta = relation_parameters.public_input_delta; - - // Manually compute the expected edge contribution - const auto& w_1 = extended_edges.w_l; - const auto& w_2 = extended_edges.w_r; - const auto& w_3 = extended_edges.w_o; - const auto& sigma_1 = extended_edges.sigma_1; - const auto& sigma_2 = extended_edges.sigma_2; - const auto& sigma_3 = extended_edges.sigma_3; - const auto& id_1 = extended_edges.id_1; - const auto& id_2 = extended_edges.id_2; - const auto& id_3 = extended_edges.id_3; - const auto& z_perm = extended_edges.z_perm; - const auto& z_perm_shift = extended_edges.z_perm_shift; - const auto& lagrange_first = extended_edges.lagrange_first; - const auto& lagrange_last = extended_edges.lagrange_last; - - // Compute expected full length Univariates using straight forward expressions - constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; - auto expected_full_length_univariates = std::array, NUM_SUBRELATIONS>(); - - expected_full_length_univariates[0] = (z_perm + lagrange_first) * (w_1 + id_1 * beta + gamma) * - (w_2 + id_2 * beta + gamma) * (w_3 + id_3 * beta + gamma) - - (z_perm_shift + lagrange_last * public_input_delta) * - (w_1 + sigma_1 * beta + gamma) * (w_2 + sigma_2 * beta + gamma) * - (w_3 + sigma_3 * beta + gamma); - - expected_full_length_univariates[1] = z_perm_shift * lagrange_last; - - validate_evaluations(expected_full_length_univariates, relation, extended_edges, relation_parameters); + auto run_test = [](bool random_inputs) { + using Relation = PermutationRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_1 = input_elements.w_l; + const auto& w_2 = input_elements.w_r; + const auto& w_3 = input_elements.w_o; + const auto& sigma_1 = input_elements.sigma_1; + const auto& sigma_2 = input_elements.sigma_2; + const auto& sigma_3 = input_elements.sigma_3; + const auto& id_1 = input_elements.id_1; + const auto& id_2 = input_elements.id_2; + const auto& id_3 = input_elements.id_3; + const auto& z_perm = input_elements.z_perm; + const auto& z_perm_shift = input_elements.z_perm_shift; + const auto& lagrange_first = input_elements.lagrange_first; + const auto& lagrange_last = input_elements.lagrange_last; + + RelationValues expected_values; + const auto parameters = RelationParameters::get_random(); + const auto& beta = parameters.beta; + const auto& gamma = parameters.gamma; + const auto& public_input_delta = parameters.public_input_delta; + + expected_values[0] = (z_perm + lagrange_first) * (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * + (w_3 + id_3 * beta + gamma) - + (z_perm_shift + lagrange_last * public_input_delta) * (w_1 + sigma_1 * beta + gamma) * + (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma); + + expected_values[1] = z_perm_shift * lagrange_last; + + validate_relation_execution(expected_values, input_elements, parameters); }; - run_test(/* is_random_input=*/true); - run_test(/* is_random_input=*/false); + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); }; } // namespace proof_system::honk_relation_tests diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp index c9e72761338..6fec7e4614b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp @@ -13,5 +13,15 @@ template struct RelationParameters { FF gamma = FF(0); // Permutation + Lookup FF public_input_delta = FF(0); // Permutation FF lookup_grand_product_delta = FF(0); // Lookup + + static RelationParameters get_random(){ + RelationParameters result; + result.eta = FF::random_element(); + result.beta = FF::random_element(); + result.gamma = FF::random_element(); + result.public_input_delta = FF::random_element(); + result.lookup_grand_product_delta = FF::random_element(); + return result; + } }; } // namespace proof_system::honk::sumcheck diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp index fd4b81699c0..b9c8dbb4d18 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp @@ -88,19 +88,19 @@ template typename RelationBase> class Relation using RelationValues = typename ValueAccumTypes::Accumulators; static constexpr size_t RELATION_LENGTH = Relation::RELATION_LENGTH; - inline void add_edge_contribution(RelationUnivariates& accumulator, + static inline void add_edge_contribution(RelationUnivariates& accumulator, const auto& input, const RelationParameters& relation_parameters, - const FF& scaling_factor) const + const FF& scaling_factor) { Relation::template accumulate( accumulator, input, relation_parameters, scaling_factor); } - void add_full_relation_value_contribution(RelationValues& accumulator, + static void add_full_relation_value_contribution(RelationValues& accumulator, auto& input, const RelationParameters& relation_parameters, - const FF& scaling_factor = 1) const + const FF& scaling_factor = 1) { Relation::template accumulate( accumulator, input, relation_parameters, scaling_factor); From 72cad4cfd61bad8095bb510df3b074e98ed5294c Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 19:31:37 +0000 Subject: [PATCH 21/45] Rename file --- ...onsistency.test.cpp => standard_relation_consistency.test.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/{relation_consistency.test.cpp => standard_relation_consistency.test.cpp} (100%) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp From defab37051ed9592f6ec4e5b1413259ff8e4cb2c Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 19:32:03 +0000 Subject: [PATCH 22/45] Update comment --- .../relations/relation_consistency.test.cpp | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp new file mode 100644 index 00000000000..bc460c60638 --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp @@ -0,0 +1,145 @@ +/** + * @file standard_relation_consistency.test.cpp + * @brief Show that relation arithmetic has a simple form. + * @details The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is + * equivalent to a simpler unoptimized version implemented in the tests themselves. This is useful 1) as documentation + * since the simple implementations here should make the underlying arithmetic easier to see, and 2) as a check that + * optimizations introduced into the Relations have not changed the result. + * + * For this purpose, we simply feed (the same) random inputs into each of the two implementations and confirm that + * the outputs match. This does not confirm the correctness of the identity arithmetic (the identities will not be + * satisfied in general by random inputs) only that the two implementations are equivalent. + * + */ +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" +#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include + +using namespace proof_system::honk::sumcheck; + +namespace proof_system::honk_relation_tests { + +using FF = barretenberg::fr; +struct InputElements { + static constexpr size_t NUM_ELEMENTS = 18; + std::array _data; + + static InputElements get_random() + { + InputElements result; + std::generate(result._data.begin(), result._data.end(), [] { return FF::random_element(); }); + return result; + } + + static InputElements get_special() + { + InputElements result; + FF idx = 0; + std::generate(result._data.begin(), result._data.end(), [&] { + idx += FF(1); + return idx; + }); + return result; + } + + FF& q_c = std::get<0>(_data); + FF& q_l = std::get<1>(_data); + FF& q_r = std::get<2>(_data); + FF& q_o = std::get<3>(_data); + FF& q_m = std::get<4>(_data); + FF& sigma_1 = std::get<5>(_data); + FF& sigma_2 = std::get<6>(_data); + FF& sigma_3 = std::get<7>(_data); + FF& id_1 = std::get<8>(_data); + FF& id_2 = std::get<9>(_data); + FF& id_3 = std::get<10>(_data); + FF& lagrange_first = std::get<11>(_data); + FF& lagrange_last = std::get<12>(_data); + FF& w_l = std::get<13>(_data); + FF& w_r = std::get<14>(_data); + FF& w_o = std::get<15>(_data); + FF& z_perm = std::get<16>(_data); + FF& z_perm_shift = std::get<17>(_data); +}; + +class StandardRelationConsistency : public testing::Test { + public: + template + static void validate_relation_execution(const auto& expected_values, const InputElements& input_elements, const auto& parameters) + { + typename Relation::RelationValues accumulator; + std::fill(accumulator.begin(), accumulator.end(), FF(0)); + Relation::add_full_relation_value_contribution(accumulator, input_elements, parameters); + EXPECT_EQ(accumulator, expected_values); + }; +}; + +TEST_F(StandardRelationConsistency, ArithmeticRelation) +{ + auto run_test = [](bool random_inputs) { + using Relation = ArithmeticRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_l = input_elements.w_l; + const auto& w_r = input_elements.w_r; + const auto& w_o = input_elements.w_o; + const auto& q_m = input_elements.q_m; + const auto& q_l = input_elements.q_l; + const auto& q_r = input_elements.q_r; + const auto& q_o = input_elements.q_o; + const auto& q_c = input_elements.q_c; + + RelationValues expected_values; + expected_values[0] = (q_m * w_r * w_l) + (q_r * w_r) + (q_l * w_l) + (q_o * w_o) + (q_c); + + const auto parameters = RelationParameters::get_random(); + + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); +}; + +TEST_F(StandardRelationConsistency, PermutationRelation) +{ + auto run_test = [](bool random_inputs) { + using Relation = PermutationRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_1 = input_elements.w_l; + const auto& w_2 = input_elements.w_r; + const auto& w_3 = input_elements.w_o; + const auto& sigma_1 = input_elements.sigma_1; + const auto& sigma_2 = input_elements.sigma_2; + const auto& sigma_3 = input_elements.sigma_3; + const auto& id_1 = input_elements.id_1; + const auto& id_2 = input_elements.id_2; + const auto& id_3 = input_elements.id_3; + const auto& z_perm = input_elements.z_perm; + const auto& z_perm_shift = input_elements.z_perm_shift; + const auto& lagrange_first = input_elements.lagrange_first; + const auto& lagrange_last = input_elements.lagrange_last; + + RelationValues expected_values; + const auto parameters = RelationParameters::get_random(); + const auto& beta = parameters.beta; + const auto& gamma = parameters.gamma; + const auto& public_input_delta = parameters.public_input_delta; + + expected_values[0] = (z_perm + lagrange_first) * (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * + (w_3 + id_3 * beta + gamma) - + (z_perm_shift + lagrange_last * public_input_delta) * (w_1 + sigma_1 * beta + gamma) * + (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma); + + expected_values[1] = z_perm_shift * lagrange_last; + + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); +}; + +} // namespace proof_system::honk_relation_tests From 7a803aaac56d84e5881b40dd40841cfbbf37198a Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 20:47:19 +0000 Subject: [PATCH 23/45] Refactor ultra relation consistency tests. --- .../relations/relation_consistency.test.cpp | 145 --- .../standard_relation_consistency.test.cpp | 15 +- .../ultra_relation_consistency.test.cpp | 1136 ++++++++--------- 3 files changed, 516 insertions(+), 780 deletions(-) delete mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp deleted file mode 100644 index bc460c60638..00000000000 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_consistency.test.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/** - * @file standard_relation_consistency.test.cpp - * @brief Show that relation arithmetic has a simple form. - * @details The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is - * equivalent to a simpler unoptimized version implemented in the tests themselves. This is useful 1) as documentation - * since the simple implementations here should make the underlying arithmetic easier to see, and 2) as a check that - * optimizations introduced into the Relations have not changed the result. - * - * For this purpose, we simply feed (the same) random inputs into each of the two implementations and confirm that - * the outputs match. This does not confirm the correctness of the identity arithmetic (the identities will not be - * satisfied in general by random inputs) only that the two implementations are equivalent. - * - */ -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include - -using namespace proof_system::honk::sumcheck; - -namespace proof_system::honk_relation_tests { - -using FF = barretenberg::fr; -struct InputElements { - static constexpr size_t NUM_ELEMENTS = 18; - std::array _data; - - static InputElements get_random() - { - InputElements result; - std::generate(result._data.begin(), result._data.end(), [] { return FF::random_element(); }); - return result; - } - - static InputElements get_special() - { - InputElements result; - FF idx = 0; - std::generate(result._data.begin(), result._data.end(), [&] { - idx += FF(1); - return idx; - }); - return result; - } - - FF& q_c = std::get<0>(_data); - FF& q_l = std::get<1>(_data); - FF& q_r = std::get<2>(_data); - FF& q_o = std::get<3>(_data); - FF& q_m = std::get<4>(_data); - FF& sigma_1 = std::get<5>(_data); - FF& sigma_2 = std::get<6>(_data); - FF& sigma_3 = std::get<7>(_data); - FF& id_1 = std::get<8>(_data); - FF& id_2 = std::get<9>(_data); - FF& id_3 = std::get<10>(_data); - FF& lagrange_first = std::get<11>(_data); - FF& lagrange_last = std::get<12>(_data); - FF& w_l = std::get<13>(_data); - FF& w_r = std::get<14>(_data); - FF& w_o = std::get<15>(_data); - FF& z_perm = std::get<16>(_data); - FF& z_perm_shift = std::get<17>(_data); -}; - -class StandardRelationConsistency : public testing::Test { - public: - template - static void validate_relation_execution(const auto& expected_values, const InputElements& input_elements, const auto& parameters) - { - typename Relation::RelationValues accumulator; - std::fill(accumulator.begin(), accumulator.end(), FF(0)); - Relation::add_full_relation_value_contribution(accumulator, input_elements, parameters); - EXPECT_EQ(accumulator, expected_values); - }; -}; - -TEST_F(StandardRelationConsistency, ArithmeticRelation) -{ - auto run_test = [](bool random_inputs) { - using Relation = ArithmeticRelation; - using RelationValues = typename Relation::RelationValues; - - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); - const auto& w_l = input_elements.w_l; - const auto& w_r = input_elements.w_r; - const auto& w_o = input_elements.w_o; - const auto& q_m = input_elements.q_m; - const auto& q_l = input_elements.q_l; - const auto& q_r = input_elements.q_r; - const auto& q_o = input_elements.q_o; - const auto& q_c = input_elements.q_c; - - RelationValues expected_values; - expected_values[0] = (q_m * w_r * w_l) + (q_r * w_r) + (q_l * w_l) + (q_o * w_o) + (q_c); - - const auto parameters = RelationParameters::get_random(); - - validate_relation_execution(expected_values, input_elements, parameters); - }; - run_test(/*random_inputs=*/false); - run_test(/*random_inputs=*/true); -}; - -TEST_F(StandardRelationConsistency, PermutationRelation) -{ - auto run_test = [](bool random_inputs) { - using Relation = PermutationRelation; - using RelationValues = typename Relation::RelationValues; - - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); - const auto& w_1 = input_elements.w_l; - const auto& w_2 = input_elements.w_r; - const auto& w_3 = input_elements.w_o; - const auto& sigma_1 = input_elements.sigma_1; - const auto& sigma_2 = input_elements.sigma_2; - const auto& sigma_3 = input_elements.sigma_3; - const auto& id_1 = input_elements.id_1; - const auto& id_2 = input_elements.id_2; - const auto& id_3 = input_elements.id_3; - const auto& z_perm = input_elements.z_perm; - const auto& z_perm_shift = input_elements.z_perm_shift; - const auto& lagrange_first = input_elements.lagrange_first; - const auto& lagrange_last = input_elements.lagrange_last; - - RelationValues expected_values; - const auto parameters = RelationParameters::get_random(); - const auto& beta = parameters.beta; - const auto& gamma = parameters.gamma; - const auto& public_input_delta = parameters.public_input_delta; - - expected_values[0] = (z_perm + lagrange_first) * (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * - (w_3 + id_3 * beta + gamma) - - (z_perm_shift + lagrange_last * public_input_delta) * (w_1 + sigma_1 * beta + gamma) * - (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma); - - expected_values[1] = z_perm_shift * lagrange_last; - - validate_relation_execution(expected_values, input_elements, parameters); - }; - run_test(/*random_inputs=*/false); - run_test(/*random_inputs=*/true); -}; - -} // namespace proof_system::honk_relation_tests diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp index 2d5f28f8a2f..93d67d2182c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp @@ -1,5 +1,5 @@ /** - * @file relation_consistency.test.cpp + * @file standard_relation_consistency.test.cpp * @brief Show that relation arithmetic has a simple form. * @details The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is * equivalent to a simpler unoptimized version implemented in the tests themselves. This is useful 1) as documentation @@ -16,9 +16,8 @@ #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include -using namespace proof_system::honk::sumcheck; -namespace proof_system::honk_relation_tests { +namespace proof_system::standard_relation_consistency_tests { using FF = barretenberg::fr; struct InputElements { @@ -66,7 +65,9 @@ struct InputElements { class StandardRelationConsistency : public testing::Test { public: template - static void validate_relation_execution(const auto& expected_values, const InputElements& input_elements, const auto& parameters) + static void validate_relation_execution(const auto& expected_values, + const InputElements& input_elements, + const auto& parameters) { typename Relation::RelationValues accumulator; std::fill(accumulator.begin(), accumulator.end(), FF(0)); @@ -77,7 +78,7 @@ class StandardRelationConsistency : public testing::Test { TEST_F(StandardRelationConsistency, ArithmeticRelation) { - auto run_test = [](bool random_inputs) { + const auto run_test = [](bool random_inputs) { using Relation = ArithmeticRelation; using RelationValues = typename Relation::RelationValues; @@ -104,7 +105,7 @@ TEST_F(StandardRelationConsistency, ArithmeticRelation) TEST_F(StandardRelationConsistency, PermutationRelation) { - auto run_test = [](bool random_inputs) { + const auto run_test = [](bool random_inputs) { using Relation = PermutationRelation; using RelationValues = typename Relation::RelationValues; @@ -142,4 +143,4 @@ TEST_F(StandardRelationConsistency, PermutationRelation) run_test(/*random_inputs=*/true); }; -} // namespace proof_system::honk_relation_tests +} // namespace proof_system::standard_relation_consistency_tests diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp index 5655f451334..2af4be9653e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp @@ -1,684 +1,564 @@ -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/univariate.hpp" -#include "arithmetic_relation.hpp" +/** + * @file ultra_relation_consistency.test.cpp + * @brief Show that relation arithmetic has a simple form. + * @details The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is + * equivalent to a simpler unoptimized version implemented in the tests themselves. This is useful 1) as documentation + * since the simple implementations here should make the underlying arithmetic easier to see, and 2) as a check that + * optimizations introduced into the Relations have not changed the result. + * + * For this purpose, we simply feed (the same) random inputs into each of the two implementations and confirm that + * the outputs match. This does not confirm the correctness of the identity arithmetic (the identities will not be + * satisfied in general by random inputs) only that the two implementations are equivalent. + * + */ #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/flavor/ultra.hpp" #include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" #include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" #include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" #include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" -#include "barretenberg/numeric/random/engine.hpp" -#include "permutation_relation.hpp" -#include "relation_parameters.hpp" #include -using barretenberg::BarycentricData; -using barretenberg::Univariate; - -// TODO(luke): This testing infrastructure was duplicated between here and relation_consistency.test.cpp with the -// orignal Flavor PR. Find a way to recombine these test suites or at least share this functionality. -using namespace proof_system::honk::sumcheck; -/** - * The purpose of this test suite is to show that the identity arithmetic implemented in the Relations is equivalent to - * a simpler unoptimized version implemented in the tests themselves. This is useful 1) as documentation since the - * simple implementations here should make the underlying arithmetic easier to see, and 2) as a check that optimizations - * introduced into the Relations have not changed the result. - * - * For this purpose, we simply feed (the same) random inputs into each of the two implementations and confirm that - * the outputs match. This does not confirm the correctness of the identity arithmetic (the identities will not be - * satisfied in general by random inputs) only that the two implementations are equivalent. - */ -static const size_t INPUT_UNIVARIATE_LENGTH = 2; +using namespace proof_system::honk::sumcheck; // WORKTODO -using barretenberg::Univariate; +namespace proof_system::ultra_relation_consistency_tests { -namespace proof_system::honk_relation_tests { +using FF = barretenberg::fr; +struct InputElements { + static constexpr size_t NUM_ELEMENTS = 43; + std::array _data; -class UltraRelationConsistency : public testing::Test { - public: - using Flavor = honk::flavor::Ultra; - using FF = typename Flavor::FF; - using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; - - // TODO(#390): Move MAX_RELATION_LENGTH into Flavor and simplify this. - template using ExtendedEdges = typename Flavor::template ExtendedEdges; - - // TODO(#225)(Adrian): Accept FULL_RELATION_LENGTH as a template parameter for this function only, so that the test - // can decide to which degree the polynomials must be extended. Possible accept an existing list of "edges" and - // extend them to the degree. - template - static void compute_mock_extended_edges( - ExtendedEdges& extended_edges, - std::array, NUM_POLYNOMIALS>& input_edges) + static InputElements get_random() { - BarycentricData barycentric_2_to_max = - BarycentricData(); - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - extended_edges[i] = barycentric_2_to_max.extend(input_edges[i]); - } + InputElements result; + std::generate(result._data.begin(), result._data.end(), [] { return FF::random_element(); }); + return result; } - /** - * @brief Returns randomly sampled parameters to feed to the relations. - * - * @return RelationParameters - */ - RelationParameters compute_mock_relation_parameters() + static InputElements get_special() { - return { .eta = FF::random_element(), - .beta = FF::random_element(), - .gamma = FF::random_element(), - .public_input_delta = FF::random_element(), - .lookup_grand_product_delta = FF::random_element() }; + InputElements result; + FF idx = 0; + std::generate(result._data.begin(), result._data.end(), [&] { + idx += FF(1); + return idx; + }); + return result; } - /** - * @brief Given an array of Univariates, create a new array containing only the i-th evaluations - * of all the univariates. - * - * @note Not really optimized, mainly used for testing that the relations evaluate to the same value when - * evaluated as Univariates, Expressions, or index-by-index - * @todo(Adrian) Maybe this is more helpful as part of a `check_logic` function. - * - * @tparam NUM_UNIVARIATES number of univariates in the input array (deduced from `univariates`) - * @tparam univariate_length number of evaluations (deduced from `univariates`) - * @param univariates array of Univariates - * @param i index of the evaluations we want to take from each univariate - * @return std::array such that result[j] = univariates[j].value_at(i) - */ - template - static ClaimedEvaluations transposed_univariate_array_at(ExtendedEdges univariates, size_t i) - { - ASSERT(i < univariate_length); - std::array result; - size_t result_idx = 0; // TODO(#391) zip - for (auto& univariate : univariates) { - result[result_idx] = univariate.value_at(i); - ++result_idx; - } - return result; - }; + FF& q_c = std::get<0>(_data); + FF& q_l = std::get<1>(_data); + FF& q_r = std::get<2>(_data); + FF& q_o = std::get<3>(_data); + FF& q_4 = std::get<4>(_data); + FF& q_m = std::get<5>(_data); + FF& q_arith = std::get<6>(_data); + FF& q_sort = std::get<7>(_data); + FF& q_elliptic = std::get<8>(_data); + FF& q_aux = std::get<9>(_data); + FF& q_lookup = std::get<10>(_data); + FF& sigma_1 = std::get<11>(_data); + FF& sigma_2 = std::get<12>(_data); + FF& sigma_3 = std::get<13>(_data); + FF& sigma_4 = std::get<14>(_data); + FF& id_1 = std::get<15>(_data); + FF& id_2 = std::get<16>(_data); + FF& id_3 = std::get<17>(_data); + FF& id_4 = std::get<18>(_data); + FF& table_1 = std::get<19>(_data); + FF& table_2 = std::get<20>(_data); + FF& table_3 = std::get<21>(_data); + FF& table_4 = std::get<22>(_data); + FF& lagrange_first = std::get<23>(_data); + FF& lagrange_last = std::get<24>(_data); + FF& w_l = std::get<25>(_data); + FF& w_r = std::get<26>(_data); + FF& w_o = std::get<27>(_data); + FF& w_4 = std::get<28>(_data); + FF& sorted_accum = std::get<29>(_data); + FF& z_perm = std::get<30>(_data); + FF& z_lookup = std::get<31>(_data); + FF& table_1_shift = std::get<32>(_data); + FF& table_2_shift = std::get<33>(_data); + FF& table_3_shift = std::get<34>(_data); + FF& table_4_shift = std::get<35>(_data); + FF& w_l_shift = std::get<36>(_data); + FF& w_r_shift = std::get<37>(_data); + FF& w_o_shift = std::get<38>(_data); + FF& w_4_shift = std::get<39>(_data); + FF& sorted_accum_shift = std::get<40>(_data); + FF& z_perm_shift = std::get<41>(_data); + FF& z_lookup_shift = std::get<42>(_data); +}; - /** - * @brief Compute the evaluation of a `relation` in different ways, comparing it to the provided `expected_evals` - * - * @details Check both `add_full_relation_value_contribution` and `add_edge_contribution` by comparing the result to - * the `expected_evals` computed by the caller. - * Ensures that the relations compute the same result as the expression given in the tests. - * - * @param expected_evals Relation evaluation computed by the caller. - * @param relation being tested - * @param extended_edges - * @param relation_parameters - */ - template - static void validate_evaluations(const auto& expected_full_length_univariates, /* array of Univariates*/ - const auto relation, - const ExtendedEdges& extended_edges, - const RelationParameters& relation_parameters) +class UltraRelationConsistency : public testing::Test { + public: + template + static void validate_relation_execution(const auto& expected_values, + const InputElements& input_elements, + const auto& parameters) { - // First check that the verifier's computation on individual evaluations is correct. - // Note: since add_full_relation_value_contribution computes the identities at a single evaluation of the - // multivariates, we need only pass in one evaluation point from the extended edges. Which one we choose is - // arbitrary so we choose the 0th. - - // Extract the RelationValues type for the given relation - using RelationValues = typename decltype(relation)::RelationValues; - RelationValues relation_evals; - RelationValues expected_relation_evals; - - ASSERT_EQ(expected_relation_evals.size(), expected_full_length_univariates.size()); - // Initialize expected_evals to 0th coefficient of expected full length univariates - for (size_t idx = 0; idx < relation_evals.size(); ++idx) { - relation_evals[idx] = FF(0); // initialize to 0 - expected_relation_evals[idx] = expected_full_length_univariates[idx].value_at(0); - } - - // Extract 0th evaluation from extended edges - ClaimedEvaluations edge_evaluations = transposed_univariate_array_at(extended_edges, 0); - - // Evaluate the relation using the verifier functionality - relation.add_full_relation_value_contribution(relation_evals, edge_evaluations, relation_parameters); - - EXPECT_EQ(relation_evals, expected_relation_evals); - - // Next, check that the prover's computation on Univariates is correct - - using RelationUnivariates = typename decltype(relation)::RelationUnivariates; - RelationUnivariates relation_univariates; - zero_univariates<>(relation_univariates); - - constexpr std::size_t num_univariates = std::tuple_size::value; - - // Compute the relatiion univariates via the sumcheck prover functionality, then extend - // them to full length for easy comparison with the expected result. - relation.add_edge_contribution(relation_univariates, extended_edges, relation_parameters, 1); - - auto full_length_univariates = std::array, num_univariates>(); - extend_tuple_of_arrays(relation_univariates, full_length_univariates); - - EXPECT_EQ(full_length_univariates, expected_full_length_univariates); + typename Relation::RelationValues accumulator; + std::fill(accumulator.begin(), accumulator.end(), FF(0)); + Relation::add_full_relation_value_contribution(accumulator, input_elements, parameters); + EXPECT_EQ(accumulator, expected_values); }; - - template static void zero_univariates(std::tuple& tuple) - { - auto& element = std::get(tuple); - std::fill(element.evaluations.begin(), element.evaluations.end(), FF(0)); - - if constexpr (idx + 1 < sizeof...(Ts)) { - zero_univariates(tuple); - } - } - - template - static void extend_tuple_of_arrays(std::tuple& tuple, auto& result_univariates) - { - auto& element = std::get(tuple); - using Element = std::remove_reference_t; - BarycentricData barycentric_utils; - result_univariates[idx] = barycentric_utils.extend(element); - - if constexpr (idx + 1 < sizeof...(Ts)) { - extend_tuple_of_arrays(tuple, result_univariates); - } - } }; TEST_F(UltraRelationConsistency, UltraArithmeticRelation) { - using Flavor = honk::flavor::Ultra; - using FF = typename Flavor::FF; - static constexpr size_t FULL_RELATION_LENGTH = 6; - using ExtendedEdges = typename Flavor::template ExtendedEdges; - static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; - - const auto relation_parameters = compute_mock_relation_parameters(); - ExtendedEdges extended_edges; - std::array, NUM_POLYNOMIALS> input_polynomials; - - // input_univariates are random polynomials of degree one - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = Univariate({ FF::random_element(), FF::random_element() }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - - auto relation = UltraArithmeticRelation(); - - // Extract the extended edges for manual computation of relation contribution - const auto& w_1 = extended_edges.w_l; - const auto& w_1_shift = extended_edges.w_l_shift; - const auto& w_2 = extended_edges.w_r; - const auto& w_3 = extended_edges.w_o; - const auto& w_4 = extended_edges.w_4; - const auto& w_4_shift = extended_edges.w_4_shift; - const auto& q_m = extended_edges.q_m; - const auto& q_l = extended_edges.q_l; - const auto& q_r = extended_edges.q_r; - const auto& q_o = extended_edges.q_o; - const auto& q_4 = extended_edges.q_4; - const auto& q_c = extended_edges.q_c; - const auto& q_arith = extended_edges.q_arith; - - static const FF neg_half = FF(-2).invert(); - - constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; - auto expected_full_length_univariates = std::array, NUM_SUBRELATIONS>(); - - // Contribution 1 - auto contribution_1 = (q_arith - 3) * (q_m * w_2 * w_1) * neg_half; - contribution_1 += (q_l * w_1) + (q_r * w_2) + (q_o * w_3) + (q_4 * w_4) + q_c; - contribution_1 += (q_arith - 1) * w_4_shift; - contribution_1 *= q_arith; - expected_full_length_univariates[0] = contribution_1; - - // Contribution 2 - auto contribution_2 = (w_1 + w_4 - w_1_shift + q_m); - contribution_2 *= (q_arith - 2) * (q_arith - 1) * q_arith; - expected_full_length_univariates[1] = contribution_2; - - validate_evaluations(expected_full_length_univariates, relation, extended_edges, relation_parameters); + const auto run_test = [](bool random_inputs) { + using Relation = UltraArithmeticRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_1 = input_elements.w_l; + const auto& w_1_shift = input_elements.w_l_shift; + const auto& w_2 = input_elements.w_r; + const auto& w_3 = input_elements.w_o; + const auto& w_4 = input_elements.w_4; + const auto& w_4_shift = input_elements.w_4_shift; + const auto& q_m = input_elements.q_m; + const auto& q_l = input_elements.q_l; + const auto& q_r = input_elements.q_r; + const auto& q_o = input_elements.q_o; + const auto& q_4 = input_elements.q_4; + const auto& q_c = input_elements.q_c; + const auto& q_arith = input_elements.q_arith; + + RelationValues expected_values; + static const FF neg_half = FF(-2).invert(); + + // Contribution 1 + auto contribution_1 = (q_arith - 3) * (q_m * w_2 * w_1) * neg_half; + contribution_1 += (q_l * w_1) + (q_r * w_2) + (q_o * w_3) + (q_4 * w_4) + q_c; + contribution_1 += (q_arith - 1) * w_4_shift; + contribution_1 *= q_arith; + expected_values[0] = contribution_1; + + // Contribution 2 + auto contribution_2 = (w_1 + w_4 - w_1_shift + q_m); + contribution_2 *= (q_arith - 2) * (q_arith - 1) * q_arith; + expected_values[1] = contribution_2; + + const auto parameters = RelationParameters::get_random(); + + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); }; TEST_F(UltraRelationConsistency, UltraPermutationRelation) { - using Flavor = honk::flavor::Ultra; - using FF = typename Flavor::FF; - using Flavor = honk::flavor::Ultra; - static constexpr size_t FULL_RELATION_LENGTH = 6; - using ExtendedEdges = typename Flavor::template ExtendedEdges; - static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; - auto relation_parameters = compute_mock_relation_parameters(); - ExtendedEdges extended_edges; - std::array, NUM_POLYNOMIALS> input_polynomials; - - // input_univariates are random polynomials of degree one - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = Univariate({ FF::random_element(), FF::random_element() }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - - auto relation = UltraPermutationRelation(); - - const auto& beta = relation_parameters.beta; - const auto& gamma = relation_parameters.gamma; - const auto& public_input_delta = relation_parameters.public_input_delta; - - // Extract the extended edges for manual computation of relation contribution - const auto& w_1 = extended_edges.w_l; - const auto& w_2 = extended_edges.w_r; - const auto& w_3 = extended_edges.w_o; - const auto& w_4 = extended_edges.w_4; - const auto& sigma_1 = extended_edges.sigma_1; - const auto& sigma_2 = extended_edges.sigma_2; - const auto& sigma_3 = extended_edges.sigma_3; - const auto& sigma_4 = extended_edges.sigma_4; - const auto& id_1 = extended_edges.id_1; - const auto& id_2 = extended_edges.id_2; - const auto& id_3 = extended_edges.id_3; - const auto& id_4 = extended_edges.id_4; - const auto& z_perm = extended_edges.z_perm; - const auto& z_perm_shift = extended_edges.z_perm_shift; - const auto& lagrange_first = extended_edges.lagrange_first; - const auto& lagrange_last = extended_edges.lagrange_last; - - constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; - auto expected_full_length_univariates = std::array, NUM_SUBRELATIONS>(); - - // Compute the expected result using a simple to read version of the relation expression - - // Contribution 1 - auto contribution_1 = (z_perm + lagrange_first) * (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * - (w_3 + id_3 * beta + gamma) * (w_4 + id_4 * beta + gamma) - - (z_perm_shift + lagrange_last * public_input_delta) * (w_1 + sigma_1 * beta + gamma) * - (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma) * - (w_4 + sigma_4 * beta + gamma); - expected_full_length_univariates[0] = contribution_1; - - // Contribution 2 - auto contribution_2 = z_perm_shift * lagrange_last; - expected_full_length_univariates[1] = contribution_2; - - validate_evaluations(expected_full_length_univariates, relation, extended_edges, relation_parameters); + const auto run_test = [](bool random_inputs) { + using Relation = UltraPermutationRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_1 = input_elements.w_l; + const auto& w_2 = input_elements.w_r; + const auto& w_3 = input_elements.w_o; + const auto& w_4 = input_elements.w_4; + const auto& sigma_1 = input_elements.sigma_1; + const auto& sigma_2 = input_elements.sigma_2; + const auto& sigma_3 = input_elements.sigma_3; + const auto& sigma_4 = input_elements.sigma_4; + const auto& id_1 = input_elements.id_1; + const auto& id_2 = input_elements.id_2; + const auto& id_3 = input_elements.id_3; + const auto& id_4 = input_elements.id_4; + const auto& z_perm = input_elements.z_perm; + const auto& z_perm_shift = input_elements.z_perm_shift; + const auto& lagrange_first = input_elements.lagrange_first; + const auto& lagrange_last = input_elements.lagrange_last; + + RelationValues expected_values; + + const auto parameters = RelationParameters::get_random(); + const auto& beta = parameters.beta; + const auto& gamma = parameters.gamma; + const auto& public_input_delta = parameters.public_input_delta; + + // Contribution 1 + auto contribution_1 = (z_perm + lagrange_first) * (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * + (w_3 + id_3 * beta + gamma) * (w_4 + id_4 * beta + gamma) - + (z_perm_shift + lagrange_last * public_input_delta) * (w_1 + sigma_1 * beta + gamma) * + (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma) * + (w_4 + sigma_4 * beta + gamma); + expected_values[0] = contribution_1; + + // Contribution 2 + auto contribution_2 = z_perm_shift * lagrange_last; + expected_values[1] = contribution_2; + + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); }; TEST_F(UltraRelationConsistency, LookupRelation) { - using Flavor = honk::flavor::Ultra; - using FF = typename Flavor::FF; - using Flavor = honk::flavor::Ultra; - static constexpr size_t FULL_RELATION_LENGTH = 6; - using ExtendedEdges = typename Flavor::ExtendedEdges; - static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; - auto relation_parameters = compute_mock_relation_parameters(); - ExtendedEdges extended_edges; - std::array, NUM_POLYNOMIALS> input_polynomials; - - // input_univariates are random polynomials of degree one - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = Univariate({ FF::random_element(), FF::random_element() }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - - auto relation = LookupRelation(); - - const auto eta = relation_parameters.eta; - const auto beta = relation_parameters.beta; - const auto gamma = relation_parameters.gamma; - auto grand_product_delta = relation_parameters.lookup_grand_product_delta; - - // Extract the extended edges for manual computation of relation contribution - auto one_plus_beta = FF::one() + beta; - auto gamma_by_one_plus_beta = gamma * one_plus_beta; - auto eta_sqr = eta * eta; - auto eta_cube = eta_sqr * eta; - - const auto& w_1 = extended_edges.w_l; - const auto& w_2 = extended_edges.w_r; - const auto& w_3 = extended_edges.w_o; - - const auto& w_1_shift = extended_edges.w_l_shift; - const auto& w_2_shift = extended_edges.w_r_shift; - const auto& w_3_shift = extended_edges.w_o_shift; - - const auto& table_1 = extended_edges.table_1; - const auto& table_2 = extended_edges.table_2; - const auto& table_3 = extended_edges.table_3; - const auto& table_4 = extended_edges.table_4; - - const auto& table_1_shift = extended_edges.table_1_shift; - const auto& table_2_shift = extended_edges.table_2_shift; - const auto& table_3_shift = extended_edges.table_3_shift; - const auto& table_4_shift = extended_edges.table_4_shift; - - const auto& s_accum = extended_edges.sorted_accum; - const auto& s_accum_shift = extended_edges.sorted_accum_shift; - const auto& z_lookup = extended_edges.z_lookup; - const auto& z_lookup_shift = extended_edges.z_lookup_shift; - - const auto& table_index = extended_edges.q_o; - const auto& column_1_step_size = extended_edges.q_r; - const auto& column_2_step_size = extended_edges.q_m; - const auto& column_3_step_size = extended_edges.q_c; - const auto& q_lookup = extended_edges.q_lookup; - - const auto& lagrange_first = extended_edges.lagrange_first; - const auto& lagrange_last = extended_edges.lagrange_last; - - auto wire_accum = (w_1 + column_1_step_size * w_1_shift) + (w_2 + column_2_step_size * w_2_shift) * eta + - (w_3 + column_3_step_size * w_3_shift) * eta_sqr + table_index * eta_cube; - - auto table_accum = table_1 + table_2 * eta + table_3 * eta_sqr + table_4 * eta_cube; - auto table_accum_shift = table_1_shift + table_2_shift * eta + table_3_shift * eta_sqr + table_4_shift * eta_cube; - - constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; - auto expected_full_length_univariates = std::array, NUM_SUBRELATIONS>(); - - // Compute the expected result using a simple to read version of the relation expression - - // Contribution 1 - auto contribution_1 = (z_lookup + lagrange_first) * (q_lookup * wire_accum + gamma) * - (table_accum + table_accum_shift * beta + gamma_by_one_plus_beta) * one_plus_beta; - contribution_1 -= (z_lookup_shift + lagrange_last * grand_product_delta) * - (s_accum + s_accum_shift * beta + gamma_by_one_plus_beta); - expected_full_length_univariates[0] = contribution_1; - - // Contribution 2 - auto contribution_2 = z_lookup_shift * lagrange_last; - expected_full_length_univariates[1] = contribution_2; - - validate_evaluations(expected_full_length_univariates, relation, extended_edges, relation_parameters); + const auto run_test = [](bool random_inputs) { + using Relation = LookupRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_1 = input_elements.w_l; + const auto& w_2 = input_elements.w_r; + const auto& w_3 = input_elements.w_o; + + const auto& w_1_shift = input_elements.w_l_shift; + const auto& w_2_shift = input_elements.w_r_shift; + const auto& w_3_shift = input_elements.w_o_shift; + + const auto& table_1 = input_elements.table_1; + const auto& table_2 = input_elements.table_2; + const auto& table_3 = input_elements.table_3; + const auto& table_4 = input_elements.table_4; + + const auto& table_1_shift = input_elements.table_1_shift; + const auto& table_2_shift = input_elements.table_2_shift; + const auto& table_3_shift = input_elements.table_3_shift; + const auto& table_4_shift = input_elements.table_4_shift; + + const auto& s_accum = input_elements.sorted_accum; + const auto& s_accum_shift = input_elements.sorted_accum_shift; + const auto& z_lookup = input_elements.z_lookup; + const auto& z_lookup_shift = input_elements.z_lookup_shift; + + const auto& table_index = input_elements.q_o; + const auto& column_1_step_size = input_elements.q_r; + const auto& column_2_step_size = input_elements.q_m; + const auto& column_3_step_size = input_elements.q_c; + const auto& q_lookup = input_elements.q_lookup; + + const auto& lagrange_first = input_elements.lagrange_first; + const auto& lagrange_last = input_elements.lagrange_last; + + RelationValues expected_values; + + const auto parameters = RelationParameters::get_random(); + + const auto eta = parameters.eta; + const auto beta = parameters.beta; + const auto gamma = parameters.gamma; + auto grand_product_delta = parameters.lookup_grand_product_delta; + + // Extract the extended edges for manual computation of relation contribution + auto one_plus_beta = FF::one() + beta; + auto gamma_by_one_plus_beta = gamma * one_plus_beta; + auto eta_sqr = eta * eta; + auto eta_cube = eta_sqr * eta; + + auto wire_accum = (w_1 + column_1_step_size * w_1_shift) + (w_2 + column_2_step_size * w_2_shift) * eta + + (w_3 + column_3_step_size * w_3_shift) * eta_sqr + table_index * eta_cube; + + auto table_accum = table_1 + table_2 * eta + table_3 * eta_sqr + table_4 * eta_cube; + auto table_accum_shift = + table_1_shift + table_2_shift * eta + table_3_shift * eta_sqr + table_4_shift * eta_cube; + + // Contribution 1 + auto contribution_1 = (z_lookup + lagrange_first) * (q_lookup * wire_accum + gamma) * + (table_accum + table_accum_shift * beta + gamma_by_one_plus_beta) * one_plus_beta; + contribution_1 -= (z_lookup_shift + lagrange_last * grand_product_delta) * + (s_accum + s_accum_shift * beta + gamma_by_one_plus_beta); + expected_values[0] = contribution_1; + + // Contribution 2 + auto contribution_2 = z_lookup_shift * lagrange_last; + expected_values[1] = contribution_2; + + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); }; TEST_F(UltraRelationConsistency, GenPermSortRelation) { - using Flavor = honk::flavor::Ultra; - using FF = typename Flavor::FF; - using Flavor = honk::flavor::Ultra; - static constexpr size_t FULL_RELATION_LENGTH = 6; - using ExtendedEdges = typename Flavor::ExtendedEdges; - static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; - auto relation_parameters = compute_mock_relation_parameters(); - ExtendedEdges extended_edges; - std::array, NUM_POLYNOMIALS> input_polynomials; - - // input_univariates are random polynomials of degree one - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = Univariate({ FF::random_element(), FF::random_element() }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - - auto relation = GenPermSortRelation(); - - // Extract the extended edges for manual computation of relation contribution - const auto& w_1 = extended_edges.w_l; - const auto& w_2 = extended_edges.w_r; - const auto& w_3 = extended_edges.w_o; - const auto& w_4 = extended_edges.w_4; - const auto& w_1_shift = extended_edges.w_l_shift; - const auto& q_sort = extended_edges.q_sort; - - // Compute wire differences - auto delta_1 = w_2 - w_1; - auto delta_2 = w_3 - w_2; - auto delta_3 = w_4 - w_3; - auto delta_4 = w_1_shift - w_4; - - constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; - auto expected_full_length_univariates = std::array, NUM_SUBRELATIONS>(); - - // Compute the expected result using a simple to read version of the relation expression - auto contribution_1 = delta_1 * (delta_1 - 1) * (delta_1 - 2) * (delta_1 - 3); - auto contribution_2 = delta_2 * (delta_2 - 1) * (delta_2 - 2) * (delta_2 - 3); - auto contribution_3 = delta_3 * (delta_3 - 1) * (delta_3 - 2) * (delta_3 - 3); - auto contribution_4 = delta_4 * (delta_4 - 1) * (delta_4 - 2) * (delta_4 - 3); - - expected_full_length_univariates[0] = contribution_1 * q_sort; - expected_full_length_univariates[1] = contribution_2 * q_sort; - expected_full_length_univariates[2] = contribution_3 * q_sort; - expected_full_length_univariates[3] = contribution_4 * q_sort; - - validate_evaluations(expected_full_length_univariates, relation, extended_edges, relation_parameters); + const auto run_test = [](bool random_inputs) { + using Relation = GenPermSortRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_1 = input_elements.w_l; + const auto& w_2 = input_elements.w_r; + const auto& w_3 = input_elements.w_o; + const auto& w_4 = input_elements.w_4; + const auto& w_1_shift = input_elements.w_l_shift; + const auto& q_sort = input_elements.q_sort; + + auto delta_1 = w_2 - w_1; + auto delta_2 = w_3 - w_2; + auto delta_3 = w_4 - w_3; + auto delta_4 = w_1_shift - w_4; + + auto contribution_1 = delta_1 * (delta_1 - 1) * (delta_1 - 2) * (delta_1 - 3); + auto contribution_2 = delta_2 * (delta_2 - 1) * (delta_2 - 2) * (delta_2 - 3); + auto contribution_3 = delta_3 * (delta_3 - 1) * (delta_3 - 2) * (delta_3 - 3); + auto contribution_4 = delta_4 * (delta_4 - 1) * (delta_4 - 2) * (delta_4 - 3); + + RelationValues expected_values; + + expected_values[0] = contribution_1 * q_sort; + expected_values[1] = contribution_2 * q_sort; + expected_values[2] = contribution_3 * q_sort; + expected_values[3] = contribution_4 * q_sort; + + const auto parameters = RelationParameters::get_random(); + + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); }; TEST_F(UltraRelationConsistency, EllipticRelation) { - using Flavor = honk::flavor::Ultra; - using FF = typename Flavor::FF; - using Flavor = honk::flavor::Ultra; - static constexpr size_t FULL_RELATION_LENGTH = 6; - using ExtendedEdges = typename Flavor::ExtendedEdges; - static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; - auto relation_parameters = compute_mock_relation_parameters(); - ExtendedEdges extended_edges; - std::array, NUM_POLYNOMIALS> input_polynomials; - - // input_univariates are random polynomials of degree one - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = Univariate({ FF::random_element(), FF::random_element() }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); + const auto run_test = [](bool random_inputs) { + using Relation = EllipticRelation; + using RelationValues = typename Relation::RelationValues; - auto relation = EllipticRelation(); + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& x_1 = input_elements.w_r; + const auto& y_1 = input_elements.w_o; - // Extract the extended edges for manual computation of relation contribution - const auto& x_1 = extended_edges.w_r; - const auto& y_1 = extended_edges.w_o; + const auto& x_2 = input_elements.w_l_shift; + const auto& y_2 = input_elements.w_4_shift; + const auto& x_3 = input_elements.w_r_shift; + const auto& y_3 = input_elements.w_o_shift; - const auto& x_2 = extended_edges.w_l_shift; - const auto& y_2 = extended_edges.w_4_shift; - const auto& x_3 = extended_edges.w_r_shift; - const auto& y_3 = extended_edges.w_o_shift; + const auto& q_sign = input_elements.q_l; + const auto& q_beta = input_elements.q_o; + const auto& q_beta_sqr = input_elements.q_4; + const auto& q_elliptic = input_elements.q_elliptic; - const auto& q_sign = extended_edges.q_l; - const auto& q_beta = extended_edges.q_o; - const auto& q_beta_sqr = extended_edges.q_4; - const auto& q_elliptic = extended_edges.q_elliptic; + RelationValues expected_values; + // Compute x/y coordinate identities - constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; - auto expected_full_length_univariates = std::array, NUM_SUBRELATIONS>(); + // Contribution 1 + auto x_identity = q_sign * (y_1 * y_2 * 2); + x_identity += q_beta * (x_1 * x_2 * x_3 * 2 + x_1 * x_1 * x_2) * FF(-1); + x_identity += q_beta_sqr * (x_2 * x_2 * x_3 - x_1 * x_2 * x_2); + x_identity += (x_1 * x_1 * x_3 - y_2 * y_2 - y_1 * y_1 + x_2 * x_2 * x_2 + x_1 * x_1 * x_1); - // Compute x/y coordinate identities + // Contribution 2 + auto y_identity = q_sign * (y_2 * x_3 - y_2 * x_1); + y_identity += q_beta * (x_2 * y_3 + y_1 * x_2); + y_identity += (x_1 * y_1 - x_1 * y_3 - y_1 * x_3 - x_1 * y_1); - // Contribution 1 - auto x_identity = q_sign * (y_1 * y_2 * 2); - x_identity += q_beta * (x_1 * x_2 * x_3 * 2 + x_1 * x_1 * x_2) * FF(-1); - x_identity += q_beta_sqr * (x_2 * x_2 * x_3 - x_1 * x_2 * x_2); - x_identity += (x_1 * x_1 * x_3 - y_2 * y_2 - y_1 * y_1 + x_2 * x_2 * x_2 + x_1 * x_1 * x_1); + expected_values[0] = x_identity * q_elliptic; + expected_values[1] = y_identity * q_elliptic; - // Contribution 2 - auto y_identity = q_sign * (y_2 * x_3 - y_2 * x_1); - y_identity += q_beta * (x_2 * y_3 + y_1 * x_2); - y_identity += (x_1 * y_1 - x_1 * y_3 - y_1 * x_3 - x_1 * y_1); + const auto parameters = RelationParameters::get_random(); - expected_full_length_univariates[0] = x_identity * q_elliptic; - expected_full_length_univariates[1] = y_identity * q_elliptic; - - validate_evaluations(expected_full_length_univariates, relation, extended_edges, relation_parameters); + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); }; TEST_F(UltraRelationConsistency, AuxiliaryRelation) { - using Flavor = honk::flavor::Ultra; - using FF = typename Flavor::FF; - using Flavor = honk::flavor::Ultra; - static constexpr size_t FULL_RELATION_LENGTH = 6; - using ExtendedEdges = typename Flavor::ExtendedEdges; - static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; - auto relation_parameters = compute_mock_relation_parameters(); - ExtendedEdges extended_edges; - std::array, NUM_POLYNOMIALS> input_polynomials; - - // input_univariates are random polynomials of degree one - for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { - input_polynomials[i] = Univariate({ FF::random_element(), FF::random_element() }); - } - compute_mock_extended_edges(extended_edges, input_polynomials); - - auto relation = AuxiliaryRelation(); - - const auto& eta = relation_parameters.eta; - - // Extract the extended edges for manual computation of relation contribution - const auto& w_1 = extended_edges.w_l; - const auto& w_2 = extended_edges.w_r; - const auto& w_3 = extended_edges.w_o; - const auto& w_4 = extended_edges.w_4; - const auto& w_1_shift = extended_edges.w_l_shift; - const auto& w_2_shift = extended_edges.w_r_shift; - const auto& w_3_shift = extended_edges.w_o_shift; - const auto& w_4_shift = extended_edges.w_4_shift; - - const auto& q_1 = extended_edges.q_l; - const auto& q_2 = extended_edges.q_r; - const auto& q_3 = extended_edges.q_o; - const auto& q_4 = extended_edges.q_4; - const auto& q_m = extended_edges.q_m; - const auto& q_c = extended_edges.q_c; - const auto& q_arith = extended_edges.q_arith; - const auto& q_aux = extended_edges.q_aux; - - constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; - auto expected_full_length_univariates = std::array, NUM_SUBRELATIONS>(); - - constexpr FF LIMB_SIZE(uint256_t(1) << 68); - constexpr FF SUBLIMB_SHIFT(uint256_t(1) << 14); - constexpr FF SUBLIMB_SHIFT_2(SUBLIMB_SHIFT * SUBLIMB_SHIFT); - constexpr FF SUBLIMB_SHIFT_3(SUBLIMB_SHIFT_2 * SUBLIMB_SHIFT); - constexpr FF SUBLIMB_SHIFT_4(SUBLIMB_SHIFT_3 * SUBLIMB_SHIFT); - - /** - * Non native field arithmetic gate 2 - * - * _ _ - * / _ _ _ 14 \ - * q_2 . q_4 | (w_1 . w_2) + (w_1 . w_2) + (w_1 . w_4 + w_2 . w_3 - w_3) . 2 - w_3 - w_4 | - * \_ _/ - * - **/ - auto limb_subproduct = w_1 * w_2_shift + w_1_shift * w_2; - auto non_native_field_gate_2 = (w_1 * w_4 + w_2 * w_3 - w_3_shift); - non_native_field_gate_2 *= LIMB_SIZE; - non_native_field_gate_2 -= w_4_shift; - non_native_field_gate_2 += limb_subproduct; - - limb_subproduct *= LIMB_SIZE; - limb_subproduct += (w_1_shift * w_2_shift); - auto non_native_field_gate_1 = limb_subproduct; - non_native_field_gate_1 -= (w_3 + w_4); - - auto non_native_field_gate_3 = limb_subproduct; - non_native_field_gate_3 += w_4; - non_native_field_gate_3 -= (w_3_shift + w_4_shift); - - auto non_native_field_identity = q_2 * q_3 * non_native_field_gate_1; - non_native_field_identity += q_2 * q_4 * non_native_field_gate_2; - non_native_field_identity += q_2 * q_m * non_native_field_gate_3; - - auto limb_accumulator_1 = w_1 + w_2 * SUBLIMB_SHIFT + w_3 * SUBLIMB_SHIFT_2 + w_1_shift * SUBLIMB_SHIFT_3 + - w_2_shift * SUBLIMB_SHIFT_4 - w_4; - - auto limb_accumulator_2 = w_3 + w_4 * SUBLIMB_SHIFT + w_1_shift * SUBLIMB_SHIFT_2 + w_2_shift * SUBLIMB_SHIFT_3 + - w_3_shift * SUBLIMB_SHIFT_4 - w_4_shift; - - auto limb_accumulator_identity = q_3 * q_4 * limb_accumulator_1; - limb_accumulator_identity += q_3 * q_m * limb_accumulator_2; - - /** - * MEMORY - **/ - - /** - * Memory Record Check - */ - auto memory_record_check = w_3; - memory_record_check *= eta; - memory_record_check += w_2; - memory_record_check *= eta; - memory_record_check += w_1; - memory_record_check *= eta; - memory_record_check += q_c; - auto partial_record_check = memory_record_check; // used in RAM consistency check - memory_record_check = memory_record_check - w_4; - - /** - * ROM Consistency Check - */ - auto index_delta = w_1_shift - w_1; - auto record_delta = w_4_shift - w_4; - - auto index_is_monotonically_increasing = index_delta * index_delta - index_delta; - - // auto adjacent_values_match_if_adjacent_indices_match = (FF(1) - index_delta) * record_delta; - auto adjacent_values_match_if_adjacent_indices_match = (index_delta * FF(-1) + FF(1)) * record_delta; - - expected_full_length_univariates[1] = adjacent_values_match_if_adjacent_indices_match * (q_1 * q_2); - expected_full_length_univariates[2] = index_is_monotonically_increasing * (q_1 * q_2); - auto ROM_consistency_check_identity = memory_record_check * (q_1 * q_2); - - /** - * RAM Consistency Check - */ - auto access_type = (w_4 - partial_record_check); // will be 0 or 1 for honest Prover - auto access_check = access_type * access_type - access_type; // check value is 0 or 1 - - auto next_gate_access_type = w_3_shift; - next_gate_access_type *= eta; - next_gate_access_type += w_2_shift; - next_gate_access_type *= eta; - next_gate_access_type += w_1_shift; - next_gate_access_type *= eta; - next_gate_access_type = w_4_shift - next_gate_access_type; - - auto value_delta = w_3_shift - w_3; - auto adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation = - (index_delta * FF(-1) + FF(1)) * value_delta * (next_gate_access_type * FF(-1) + FF(1)); - - // We can't apply the RAM consistency check identity on the final entry in the sorted list (the wires in the - // next gate would make the identity fail). - // We need to validate that its 'access type' bool is correct. Can't do - // with an arithmetic gate because of the `eta` factors. We need to check that the *next* gate's access type is - // correct, to cover this edge case - auto next_gate_access_type_is_boolean = next_gate_access_type * next_gate_access_type - next_gate_access_type; - - // Putting it all together... - expected_full_length_univariates[3] = - adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation * (q_arith); - expected_full_length_univariates[4] = index_is_monotonically_increasing * (q_arith); - expected_full_length_univariates[5] = next_gate_access_type_is_boolean * (q_arith); - auto RAM_consistency_check_identity = access_check * (q_arith); - - /** - * RAM/ROM access check gate - */ - memory_record_check *= (q_1 * q_m); - - /** - * RAM Timestamp Consistency Check - */ - auto timestamp_delta = w_2_shift - w_2; - auto RAM_timestamp_check_identity = (index_delta * FF(-1) + FF(1)) * timestamp_delta - w_3; - RAM_timestamp_check_identity *= (q_1 * q_4); - - /** - * The complete RAM/ROM memory identity - */ - auto memory_identity = ROM_consistency_check_identity; - memory_identity += RAM_timestamp_check_identity; - memory_identity += memory_record_check; - memory_identity += RAM_consistency_check_identity; - - expected_full_length_univariates[0] = memory_identity + non_native_field_identity + limb_accumulator_identity; - - expected_full_length_univariates[0] *= q_aux; - expected_full_length_univariates[1] *= q_aux; - expected_full_length_univariates[2] *= q_aux; - expected_full_length_univariates[3] *= q_aux; - expected_full_length_univariates[4] *= q_aux; - expected_full_length_univariates[5] *= q_aux; - - validate_evaluations(expected_full_length_univariates, relation, extended_edges, relation_parameters); + const auto run_test = [](bool random_inputs) { + using Relation = AuxiliaryRelation; + using RelationValues = typename Relation::RelationValues; + + const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const auto& w_1 = input_elements.w_l; + const auto& w_2 = input_elements.w_r; + const auto& w_3 = input_elements.w_o; + const auto& w_4 = input_elements.w_4; + const auto& w_1_shift = input_elements.w_l_shift; + const auto& w_2_shift = input_elements.w_r_shift; + const auto& w_3_shift = input_elements.w_o_shift; + const auto& w_4_shift = input_elements.w_4_shift; + + const auto& q_1 = input_elements.q_l; + const auto& q_2 = input_elements.q_r; + const auto& q_3 = input_elements.q_o; + const auto& q_4 = input_elements.q_4; + const auto& q_m = input_elements.q_m; + const auto& q_c = input_elements.q_c; + const auto& q_arith = input_elements.q_arith; + const auto& q_aux = input_elements.q_aux; + + constexpr FF LIMB_SIZE(uint256_t(1) << 68); + constexpr FF SUBLIMB_SHIFT(uint256_t(1) << 14); + constexpr FF SUBLIMB_SHIFT_2(SUBLIMB_SHIFT * SUBLIMB_SHIFT); + constexpr FF SUBLIMB_SHIFT_3(SUBLIMB_SHIFT_2 * SUBLIMB_SHIFT); + constexpr FF SUBLIMB_SHIFT_4(SUBLIMB_SHIFT_3 * SUBLIMB_SHIFT); + + const auto parameters = RelationParameters::get_random(); + const auto& eta = parameters.eta; + + RelationValues expected_values; + /** + * Non native field arithmetic gate 2 + * + * _ _ + * / _ _ _ 14 \ + * q_2 . q_4 | (w_1 . w_2) + (w_1 . w_2) + (w_1 . w_4 + w_2 . w_3 - w_3) . 2 - w_3 - w_4 | + * \_ _/ + * + **/ + auto limb_subproduct = w_1 * w_2_shift + w_1_shift * w_2; + auto non_native_field_gate_2 = (w_1 * w_4 + w_2 * w_3 - w_3_shift); + non_native_field_gate_2 *= LIMB_SIZE; + non_native_field_gate_2 -= w_4_shift; + non_native_field_gate_2 += limb_subproduct; + + limb_subproduct *= LIMB_SIZE; + limb_subproduct += (w_1_shift * w_2_shift); + auto non_native_field_gate_1 = limb_subproduct; + non_native_field_gate_1 -= (w_3 + w_4); + + auto non_native_field_gate_3 = limb_subproduct; + non_native_field_gate_3 += w_4; + non_native_field_gate_3 -= (w_3_shift + w_4_shift); + + auto non_native_field_identity = q_2 * q_3 * non_native_field_gate_1; + non_native_field_identity += q_2 * q_4 * non_native_field_gate_2; + non_native_field_identity += q_2 * q_m * non_native_field_gate_3; + + auto limb_accumulator_1 = w_1 + w_2 * SUBLIMB_SHIFT + w_3 * SUBLIMB_SHIFT_2 + w_1_shift * SUBLIMB_SHIFT_3 + + w_2_shift * SUBLIMB_SHIFT_4 - w_4; + + auto limb_accumulator_2 = w_3 + w_4 * SUBLIMB_SHIFT + w_1_shift * SUBLIMB_SHIFT_2 + + w_2_shift * SUBLIMB_SHIFT_3 + w_3_shift * SUBLIMB_SHIFT_4 - w_4_shift; + + auto limb_accumulator_identity = q_3 * q_4 * limb_accumulator_1; + limb_accumulator_identity += q_3 * q_m * limb_accumulator_2; + + /** + * MEMORY + **/ + + /** + * Memory Record Check + */ + auto memory_record_check = w_3; + memory_record_check *= eta; + memory_record_check += w_2; + memory_record_check *= eta; + memory_record_check += w_1; + memory_record_check *= eta; + memory_record_check += q_c; + auto partial_record_check = memory_record_check; // used in RAM consistency check + memory_record_check = memory_record_check - w_4; + + /** + * ROM Consistency Check + */ + auto index_delta = w_1_shift - w_1; + auto record_delta = w_4_shift - w_4; + + auto index_is_monotonically_increasing = index_delta * index_delta - index_delta; + + // auto adjacent_values_match_if_adjacent_indices_match = (FF(1) - index_delta) * record_delta; + auto adjacent_values_match_if_adjacent_indices_match = (index_delta * FF(-1) + FF(1)) * record_delta; + + expected_values[1] = adjacent_values_match_if_adjacent_indices_match * (q_1 * q_2); + expected_values[2] = index_is_monotonically_increasing * (q_1 * q_2); + auto ROM_consistency_check_identity = memory_record_check * (q_1 * q_2); + + /** + * RAM Consistency Check + */ + auto access_type = (w_4 - partial_record_check); // will be 0 or 1 for honest Prover + auto access_check = access_type * access_type - access_type; // check value is 0 or 1 + + auto next_gate_access_type = w_3_shift; + next_gate_access_type *= eta; + next_gate_access_type += w_2_shift; + next_gate_access_type *= eta; + next_gate_access_type += w_1_shift; + next_gate_access_type *= eta; + next_gate_access_type = w_4_shift - next_gate_access_type; + + auto value_delta = w_3_shift - w_3; + auto adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation = + (index_delta * FF(-1) + FF(1)) * value_delta * (next_gate_access_type * FF(-1) + FF(1)); + + // We can't apply the RAM consistency check identity on the final entry in the sorted list (the wires in the + // next gate would make the identity fail). We need to validate that its 'access type' bool is correct. Can't do + // with an arithmetic gate because of the `eta` factors. We need to check that the *next* gate's access type is + // correct, to cover this edge case + auto next_gate_access_type_is_boolean = next_gate_access_type * next_gate_access_type - next_gate_access_type; + + // Putting it all together... + expected_values[3] = + adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation * (q_arith); + expected_values[4] = index_is_monotonically_increasing * (q_arith); + expected_values[5] = next_gate_access_type_is_boolean * (q_arith); + auto RAM_consistency_check_identity = access_check * (q_arith); + + /** + * RAM/ROM access check gate + */ + memory_record_check *= (q_1 * q_m); + + /** + * RAM Timestamp Consistency Check + */ + auto timestamp_delta = w_2_shift - w_2; + auto RAM_timestamp_check_identity = (index_delta * FF(-1) + FF(1)) * timestamp_delta - w_3; + RAM_timestamp_check_identity *= (q_1 * q_4); + + /** + * The complete RAM/ROM memory identity + */ + auto memory_identity = ROM_consistency_check_identity; + memory_identity += RAM_timestamp_check_identity; + memory_identity += memory_record_check; + memory_identity += RAM_consistency_check_identity; + + expected_values[0] = memory_identity + non_native_field_identity + limb_accumulator_identity; + expected_values[0] *= q_aux; + expected_values[1] *= q_aux; + expected_values[2] *= q_aux; + expected_values[3] *= q_aux; + expected_values[4] *= q_aux; + expected_values[5] *= q_aux; + + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); }; -} // namespace proof_system::honk_relation_tests +} // namespace proof_system::ultra_relation_consistency_tests + +// TEST_F(UltraRelationConsistency, AuxiliaryRelation) +// { +// using Flavor = honk::flavor::Ultra; +// using FF = typename Flavor::FF; +// using Flavor = honk::flavor::Ultra; +// static constexpr size_t FULL_RELATION_LENGTH = 6; +// using ExtendedEdges = typename Flavor::ExtendedEdges; +// static const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; +// auto relation_parameters = compute_mock_relation_parameters(); +// ExtendedEdges input_elements; +// std::array, NUM_POLYNOMIALS> input_polynomials; + +// // input_univariates are random polynomials of degree one +// for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) { +// input_polynomials[i] = Univariate({ FF::random_element(), FF::random_element() +// }); +// } +// compute_mock_extended_edges(input_elements, input_polynomials); + +// auto relation = AuxiliaryRelation(); + +// // Extract the extended edges for manual computation of relation contribution + +// constexpr std::size_t NUM_SUBRELATIONS = std::tuple_size_v; +// auto expected_values = std::array, NUM_SUBRELATIONS>(); + +// validate_evaluations(expected_values, relation, input_elements, relation_parameters); +// }; + +// } // namespace proof_system::honk_relation_tests From 69ab87830780951d59e99b27538e8385e6c82e61 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 31 Aug 2023 21:16:02 +0000 Subject: [PATCH 24/45] Change relations namespace. --- .../relations_bench/barycentric.bench.cpp | 4 +- .../relations_bench/relations.bench.cpp | 40 +++++++++---------- .../barretenberg/honk/flavor/goblin_ultra.hpp | 22 +++++----- .../src/barretenberg/honk/flavor/standard.hpp | 4 +- .../honk/flavor/standard_grumpkin.hpp | 4 +- .../src/barretenberg/honk/flavor/ultra.hpp | 19 ++++----- .../honk/flavor/ultra_grumpkin.hpp | 19 ++++----- .../honk/flavor/ultra_recursive.hpp | 12 +++--- .../proof_system/grand_product_library.hpp | 4 +- .../barretenberg/honk/proof_system/prover.cpp | 2 +- .../barretenberg/honk/proof_system/prover.hpp | 2 +- .../honk/proof_system/prover_library.test.cpp | 12 +++--- .../honk/proof_system/ultra_prover.hpp | 2 +- .../honk/proof_system/ultra_verifier.cpp | 2 +- .../honk/proof_system/verifier.cpp | 2 +- .../relations/arithmetic_relation.hpp | 2 +- .../sumcheck/relations/auxiliary_relation.hpp | 2 +- .../relations/ecc_op_queue_relation.hpp | 2 +- .../sumcheck/relations/elliptic_relation.hpp | 2 +- .../relations/gen_perm_sort_relation.hpp | 2 +- .../sumcheck/relations/lookup_relation.hpp | 2 +- .../relations/permutation_relation.hpp | 2 +- .../relations/relation_correctness.test.cpp | 37 ++++++++--------- .../relations/relation_parameters.hpp | 2 +- .../sumcheck/relations/relation_types.hpp | 2 +- .../standard_relation_consistency.test.cpp | 2 + .../relations/ultra_arithmetic_relation.hpp | 2 +- .../ultra_relation_consistency.test.cpp | 2 +- .../barretenberg/honk/sumcheck/sumcheck.hpp | 4 +- .../honk/sumcheck/sumcheck.test.cpp | 8 ++-- .../honk/sumcheck/sumcheck_round.hpp | 8 ++-- .../honk/sumcheck/sumcheck_round.test.cpp | 2 + .../verifier/ultra_recursive_verifier.cpp | 2 +- 33 files changed, 121 insertions(+), 114 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp index f6a439df496..94bc5f38782 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp @@ -13,7 +13,7 @@ using barretenberg::Univariate; using barretenberg::BarycentricData; -namespace proof_system::honk::sumcheck::relations_bench { +namespace proof_system::relation::benchmark { void extend_2_to_6(State& state) noexcept { @@ -26,4 +26,4 @@ void extend_2_to_6(State& state) noexcept } BENCHMARK(extend_2_to_6); -} // namespace proof_system::honk::sumcheck::relations_bench \ No newline at end of file +} // namespace proof_system::relation::benchmark \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index 9ec880fc70f..61bd820b86a 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -15,18 +15,18 @@ namespace { auto& engine = numeric::random::get_debug_engine(); } -namespace proof_system::honk::sumcheck::relations_bench { +namespace proof_system::relation::benchmark { using FF = barretenberg::fr; -template void execute_relation(benchmark::State& state) +template void execute_relation(::benchmark::State& state) { // Generate beta and gamma auto beta = FF::random_element(); auto gamma = FF::random_element(); auto public_input_delta = FF::random_element(); - sumcheck::RelationParameters params{ + RelationParameters params{ .beta = beta, .gamma = gamma, .public_input_delta = public_input_delta, @@ -47,55 +47,55 @@ template void execute_relation(benchmark::S } } -void arithmetic_relation(benchmark::State& state) noexcept +void arithmetic_relation(::benchmark::State& state) noexcept { - execute_relation>(state); + execute_relation>(state); } BENCHMARK(arithmetic_relation); // WORKTODO -// void auxiliary_relation(benchmark::State& state) noexcept +// void auxiliary_relation(::benchmark::State& state) noexcept // { -// execute_relation>(state); +// execute_relation>(state); // } // BENCHMARK(auxiliary_relation); -void elliptic_relation(benchmark::State& state) noexcept +void elliptic_relation(::benchmark::State& state) noexcept { - execute_relation>(state); + execute_relation>(state); } BENCHMARK(elliptic_relation); -void ecc_op_queue_relation(benchmark::State& state) noexcept +void ecc_op_queue_relation(::benchmark::State& state) noexcept { - execute_relation>(state); + execute_relation>(state); } BENCHMARK(ecc_op_queue_relation); -void gen_perm_sort_relation(benchmark::State& state) noexcept +void gen_perm_sort_relation(::benchmark::State& state) noexcept { - execute_relation>(state); + execute_relation>(state); } BENCHMARK(gen_perm_sort_relation); -void lookup_relation(benchmark::State& state) noexcept +void lookup_relation(::benchmark::State& state) noexcept { - execute_relation>(state); + execute_relation>(state); } BENCHMARK(lookup_relation); -void permutation_relation(benchmark::State& state) noexcept +void permutation_relation(::benchmark::State& state) noexcept { - execute_relation>(state); + execute_relation>(state); } BENCHMARK(permutation_relation); -void ultra_arithmetic_relation(benchmark::State& state) noexcept +void ultra_arithmetic_relation(::benchmark::State& state) noexcept { - execute_relation>(state); + execute_relation>(state); } BENCHMARK(ultra_arithmetic_relation); -} // namespace proof_system::honk::sumcheck::relations_bench +} // namespace proof_system::honk::relations_bench diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index b80d9472136..837e8f22601 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -12,7 +12,6 @@ #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" - namespace proof_system::honk::flavor { class GoblinUltra { @@ -40,16 +39,17 @@ class GoblinUltra { // The total number of witness entities not including shifts. static constexpr size_t NUM_WITNESS_ENTITIES = 15; // 11 (UH) + 4 op wires - using GrandProductRelations = std::tuple, sumcheck::LookupRelation>; + using GrandProductRelations = + std::tuple, proof_system::relation::LookupRelation>; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - sumcheck::UltraPermutationRelation, - sumcheck::LookupRelation, - sumcheck::GenPermSortRelation, - sumcheck::EllipticRelation, - sumcheck::AuxiliaryRelation, - sumcheck::EccOpQueueRelation>; + using Relations = std::tuple, + proof_system::relation::UltraPermutationRelation, + proof_system::relation::LookupRelation, + proof_system::relation::GenPermSortRelation, + proof_system::relation::EllipticRelation, + proof_system::relation::AuxiliaryRelation, + proof_system::relation::EccOpQueueRelation>; static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); @@ -328,8 +328,8 @@ class GoblinUltra { * @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH? */ template - using ExtendedEdges = - AllEntities, barretenberg::Univariate>; + using ExtendedEdges = AllEntities, + barretenberg::Univariate>; /** * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp index f356afdfa02..ec4a9547fa9 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp @@ -46,9 +46,9 @@ class Standard { // The total number of witness entities not including shifts. static constexpr size_t NUM_WITNESS_ENTITIES = 4; - using GrandProductRelations = std::tuple>; + using GrandProductRelations = std::tuple>; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, sumcheck::PermutationRelation>; + using Relations = std::tuple, proof_system::relation::PermutationRelation>; static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp index b2395b77600..0db236f2e71 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp @@ -46,9 +46,9 @@ class StandardGrumpkin { static constexpr size_t NUM_WITNESS_ENTITIES = 4; // define the tuple of Relations that require grand products - using GrandProductRelations = std::tuple>; + using GrandProductRelations = std::tuple>; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, sumcheck::PermutationRelation>; + using Relations = std::tuple, proof_system::relation::PermutationRelation>; static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 057c6958ba7..1f445c4fa44 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -43,14 +43,15 @@ class Ultra { // The total number of witness entities not including shifts. static constexpr size_t NUM_WITNESS_ENTITIES = 11; - using GrandProductRelations = std::tuple, sumcheck::LookupRelation>; + using GrandProductRelations = + std::tuple, proof_system::relation::LookupRelation>; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - sumcheck::UltraPermutationRelation, - sumcheck::LookupRelation, - sumcheck::GenPermSortRelation, - sumcheck::EllipticRelation, - sumcheck::AuxiliaryRelation>; + using Relations = std::tuple, + proof_system::relation::UltraPermutationRelation, + proof_system::relation::LookupRelation, + proof_system::relation::GenPermSortRelation, + proof_system::relation::EllipticRelation, + proof_system::relation::AuxiliaryRelation>; static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); @@ -296,8 +297,8 @@ class Ultra { * @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH? */ template - using ExtendedEdges = - AllEntities, barretenberg::Univariate>; + using ExtendedEdges = AllEntities, + barretenberg::Univariate>; /** * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp index e39563307c5..e61fe8698f9 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp @@ -52,14 +52,15 @@ class UltraGrumpkin { // The total number of witness entities not including shifts. static constexpr size_t NUM_WITNESS_ENTITIES = 11; - using GrandProductRelations = std::tuple, sumcheck::LookupRelation>; + using GrandProductRelations = + std::tuple, proof_system::relation::LookupRelation>; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - sumcheck::UltraPermutationRelation, - sumcheck::LookupRelation, - sumcheck::GenPermSortRelation, - sumcheck::EllipticRelation, - sumcheck::AuxiliaryRelation>; + using Relations = std::tuple, + proof_system::relation::UltraPermutationRelation, + proof_system::relation::LookupRelation, + proof_system::relation::GenPermSortRelation, + proof_system::relation::EllipticRelation, + proof_system::relation::AuxiliaryRelation>; static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); @@ -303,8 +304,8 @@ class UltraGrumpkin { * @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH? */ template - using ExtendedEdges = - AllEntities, barretenberg::Univariate>; + using ExtendedEdges = AllEntities, + barretenberg::Univariate>; /** * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp index 29579d128cc..9d73c5443d9 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp @@ -63,12 +63,12 @@ class UltraRecursive { static constexpr size_t NUM_WITNESS_ENTITIES = 11; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - sumcheck::UltraPermutationRelation, - sumcheck::LookupRelation, - sumcheck::GenPermSortRelation, - sumcheck::EllipticRelation, - sumcheck::AuxiliaryRelation>; + using Relations = std::tuple, + proof_system::relation::UltraPermutationRelation, + proof_system::relation::LookupRelation, + proof_system::relation::GenPermSortRelation, + proof_system::relation::EllipticRelation, + proof_system::relation::AuxiliaryRelation>; static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp index f8bdbb00584..5408f01a553 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp @@ -47,7 +47,7 @@ namespace proof_system::honk::grand_product_library { template void compute_grand_product(const size_t circuit_size, auto& full_polynomials, - sumcheck::RelationParameters& relation_parameters) + proof_system::relation::RelationParameters& relation_parameters) { using FF = typename Flavor::FF; using Polynomial = typename Flavor::Polynomial; @@ -140,7 +140,7 @@ void compute_grand_product(const size_t circuit_size, template void compute_grand_products(std::shared_ptr& key, typename Flavor::ProverPolynomials& full_polynomials, - sumcheck::RelationParameters& relation_parameters) + proof_system::relation::RelationParameters& relation_parameters) { using GrandProductRelations = typename Flavor::GrandProductRelations; using FF = typename Flavor::FF; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp index a4a6b38e1de..7639aca8a73 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp @@ -107,7 +107,7 @@ template void StandardProver_::execute_grand_pro auto public_input_delta = compute_public_input_delta(public_inputs, beta, gamma, key->circuit_size); - relation_parameters = sumcheck::RelationParameters{ + relation_parameters = proof_system::relation::RelationParameters{ .beta = beta, .gamma = gamma, .public_input_delta = public_input_delta, diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp index ac97786e4ff..e8ee296e2f3 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp @@ -51,7 +51,7 @@ template class StandardProver_ { std::vector public_inputs; - sumcheck::RelationParameters relation_parameters; + proof_system::relation::RelationParameters relation_parameters; std::shared_ptr key; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover_library.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover_library.test.cpp index fd064571cda..e978eb66369 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover_library.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover_library.test.cpp @@ -1,11 +1,11 @@ +#include "prover_library.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/honk/flavor/ultra.hpp" #include "barretenberg/honk/proof_system/grand_product_library.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "prover.hpp" -#include "prover_library.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include @@ -88,7 +88,7 @@ template class ProverLibraryTests : public testing::Test { auto beta = FF::random_element(); auto gamma = FF::random_element(); - sumcheck::RelationParameters params{ + proof_system::relation::RelationParameters params{ .eta = 0, .beta = beta, .gamma = gamma, @@ -125,12 +125,12 @@ template class ProverLibraryTests : public testing::Test { using LHS = typename std::tuple_element::type; if constexpr (Flavor::NUM_WIRES == 4) { - using RHS = typename sumcheck::UltraPermutationRelation; + using RHS = typename proof_system::relation::UltraPermutationRelation; static_assert(std::same_as); grand_product_library::compute_grand_product( proving_key->circuit_size, prover_polynomials, params); } else { - using RHS = sumcheck::PermutationRelation; + using RHS = proof_system::relation::PermutationRelation; static_assert(std::same_as); grand_product_library::compute_grand_product( proving_key->circuit_size, prover_polynomials, params); @@ -262,7 +262,7 @@ template class ProverLibraryTests : public testing::Test { auto gamma = FF::random_element(); auto eta = FF::random_element(); - sumcheck::RelationParameters params{ + proof_system::relation::RelationParameters params{ .eta = eta, .beta = beta, .gamma = gamma, @@ -298,7 +298,7 @@ template class ProverLibraryTests : public testing::Test { // Method 1: Compute z_lookup using the prover library method constexpr size_t LOOKUP_RELATION_INDEX = 1; using LHS = typename std::tuple_element::type; - using RHS = sumcheck::LookupRelation; + using RHS = proof_system::relation::LookupRelation; static_assert(std::same_as); grand_product_library::compute_grand_product( proving_key->circuit_size, prover_polynomials, params); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp index 4c711743921..f2691328ad7 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp @@ -47,7 +47,7 @@ template class UltraProver_ { std::vector public_inputs; size_t pub_inputs_offset; // offset of the PI relative to 0th index in the wire polynomials - sumcheck::RelationParameters relation_parameters; + proof_system::relation::RelationParameters relation_parameters; std::shared_ptr key; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp index 565df400d8f..4b115770d8b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp @@ -44,7 +44,7 @@ template bool UltraVerifier_::verify_proof(const plonk using VerifierCommitments = typename Flavor::VerifierCommitments; using CommitmentLabels = typename Flavor::CommitmentLabels; - RelationParameters relation_parameters; + proof_system::relation::RelationParameters relation_parameters; transcript = VerifierTranscript{ proof.proof_data }; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp index 146d73ab686..d7bf13d914a 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp @@ -97,7 +97,7 @@ template bool StandardVerifier_::verify_proof(const pl const FF public_input_delta = compute_public_input_delta(public_inputs, beta, gamma, circuit_size); - sumcheck::RelationParameters relation_parameters{ + proof_system::relation::RelationParameters relation_parameters{ .beta = beta, .gamma = gamma, .public_input_delta = public_input_delta, diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp index f4d61242871..6e374b0eb34 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp @@ -2,7 +2,7 @@ #include "relation_parameters.hpp" #include "relation_types.hpp" -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { // WORKTODO: ... this is a base in a weird way. Wish I could simplify the structure here. template class ArithmeticRelationBase { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp index 55572d2d347..6e82f2dc6d0 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp @@ -3,7 +3,7 @@ #include "relation_parameters.hpp" #include "relation_types.hpp" -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { template class AuxiliaryRelationBase { public: diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp index 2f2967ea5a4..91cc5e8b7d5 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp @@ -2,7 +2,7 @@ #include "relation_parameters.hpp" #include "relation_types.hpp" -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { template class EccOpQueueRelationBase { public: diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp index 582197b1ff3..4323d2b7a51 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp @@ -2,7 +2,7 @@ #include "relation_parameters.hpp" #include "relation_types.hpp" -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { template class EllipticRelationBase { public: diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp index d041ce869f4..1a07fa75f9b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp @@ -2,7 +2,7 @@ #include "relation_parameters.hpp" #include "relation_types.hpp" -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { template class GenPermSortRelationBase { public: diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp index 38cef5fcab0..38ba009fd3e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp @@ -2,7 +2,7 @@ #include "relation_parameters.hpp" #include "relation_types.hpp" -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { /** * @brief LookupRelationBase defines the algebra for the lookup polynomial: diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp index 45c66965b9f..a8eed00d754 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp @@ -3,7 +3,7 @@ #include "relation_types.hpp" // TODO(luke): change name of this file to permutation_grand_product_relation(s).hpp and move 'init' relation into it. -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { template class PermutationRelationBase { public: diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp index 2ff1e3d917d..eee10c118f8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp @@ -1,4 +1,3 @@ -#include #include "barretenberg/honk/composer/standard_composer.hpp" #include "barretenberg/honk/composer/ultra_composer.hpp" #include "barretenberg/honk/proof_system/grand_product_library.hpp" @@ -12,6 +11,7 @@ #include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" #include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" #include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include using namespace proof_system::honk; @@ -238,7 +238,7 @@ TEST_F(RelationCorrectnessTests, StandardRelationCorrectness) auto public_input_delta = honk::compute_public_input_delta(public_inputs, beta, gamma, prover.key->circuit_size); - sumcheck::RelationParameters params{ + proof_system::relation::RelationParameters params{ .beta = beta, .gamma = gamma, .public_input_delta = public_input_delta, @@ -271,7 +271,8 @@ TEST_F(RelationCorrectnessTests, StandardRelationCorrectness) grand_product_library::compute_grand_products(prover.key, prover_polynomials, params); // Construct the round for applying sumcheck relations and results for storing computed results - auto relations = std::tuple(honk::sumcheck::ArithmeticRelation(), honk::sumcheck::PermutationRelation()); + auto relations = + std::tuple(proof_system::relation::ArithmeticRelation(), proof_system::relation::PermutationRelation()); // Check that each relation is satisfied across each row of the prover polynomials check_relation(std::get<0>(relations), circuit_size, prover_polynomials, params); @@ -324,7 +325,7 @@ TEST_F(RelationCorrectnessTests, UltraRelationCorrectness) auto lookup_grand_product_delta = honk::compute_lookup_grand_product_delta(beta, gamma, prover.key->circuit_size); - sumcheck::RelationParameters params{ + proof_system::relation::RelationParameters params{ .eta = eta, .beta = beta, .gamma = gamma, @@ -391,12 +392,12 @@ TEST_F(RelationCorrectnessTests, UltraRelationCorrectness) ensure_non_zero(prover.key->q_aux); // Construct the round for applying sumcheck relations and results for storing computed results - auto relations = std::tuple(honk::sumcheck::UltraArithmeticRelation(), - honk::sumcheck::UltraPermutationRelation(), - honk::sumcheck::LookupRelation(), - honk::sumcheck::GenPermSortRelation(), - honk::sumcheck::EllipticRelation(), - honk::sumcheck::AuxiliaryRelation()); + auto relations = std::tuple(proof_system::relation::UltraArithmeticRelation(), + proof_system::relation::UltraPermutationRelation(), + proof_system::relation::LookupRelation(), + proof_system::relation::GenPermSortRelation(), + proof_system::relation::EllipticRelation(), + proof_system::relation::AuxiliaryRelation()); // Check that each relation is satisfied across each row of the prover polynomials check_relation(std::get<0>(relations), circuit_size, prover_polynomials, params); @@ -448,7 +449,7 @@ TEST_F(RelationCorrectnessTests, GoblinUltraRelationCorrectness) auto lookup_grand_product_delta = honk::compute_lookup_grand_product_delta(beta, gamma, prover.key->circuit_size); - sumcheck::RelationParameters params{ + proof_system::relation::RelationParameters params{ .eta = eta, .beta = beta, .gamma = gamma, @@ -521,13 +522,13 @@ TEST_F(RelationCorrectnessTests, GoblinUltraRelationCorrectness) ensure_non_zero(prover.key->q_aux); // Construct the round for applying sumcheck relations and results for storing computed results - auto relations = std::tuple(honk::sumcheck::UltraArithmeticRelation(), - honk::sumcheck::UltraPermutationRelation(), - honk::sumcheck::LookupRelation(), - honk::sumcheck::GenPermSortRelation(), - honk::sumcheck::EllipticRelation(), - honk::sumcheck::AuxiliaryRelation(), - honk::sumcheck::EccOpQueueRelation()); + auto relations = std::tuple(proof_system::relation::UltraArithmeticRelation(), + proof_system::relation::UltraPermutationRelation(), + proof_system::relation::LookupRelation(), + proof_system::relation::GenPermSortRelation(), + proof_system::relation::EllipticRelation(), + proof_system::relation::AuxiliaryRelation(), + proof_system::relation::EccOpQueueRelation()); // Check that each relation is satisfied across each row of the prover polynomials check_relation(std::get<0>(relations), circuit_size, prover_polynomials, params); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp index 6fec7e4614b..10a2932f476 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp @@ -1,6 +1,6 @@ #pragma once -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { /** * @brief Container for parameters used by the grand product (permutation, lookup) Honk relations diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp index b9c8dbb4d18..0c75fb03c04 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp @@ -2,7 +2,7 @@ #include "barretenberg/polynomials/univariate.hpp" #include "relation_parameters.hpp" -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { template concept HasSubrelationLinearlyIndependentMember = requires(T) { T::Relation::SUBRELATION_LINEARLY_INDEPENDENT; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp index 93d67d2182c..d19e8bd6df9 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp @@ -17,6 +17,8 @@ #include +using namespace proof_system::relation; + namespace proof_system::standard_relation_consistency_tests { using FF = barretenberg::fr; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp index fc351fb562e..907085caa04 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp @@ -2,7 +2,7 @@ #include "relation_parameters.hpp" #include "relation_types.hpp" -namespace proof_system::honk::sumcheck { +namespace proof_system::relation { template class UltraArithmeticRelationBase { public: diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp index 2af4be9653e..33bb0ffca06 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp @@ -20,7 +20,7 @@ #include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" #include -using namespace proof_system::honk::sumcheck; // WORKTODO +using namespace proof_system::relation; namespace proof_system::ultra_relation_consistency_tests { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 80ffc8c04e8..fd28b05522c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -71,7 +71,7 @@ template class SumcheckProver { * @details */ SumcheckOutput prove(auto full_polynomials, - const RelationParameters& relation_parameters) // pass by value, not by reference + const proof_system::relation::RelationParameters& relation_parameters) // pass by value, not by reference { auto [alpha, zeta] = transcript.get_challenges("Sumcheck:alpha", "Sumcheck:zeta"); @@ -172,7 +172,7 @@ template class SumcheckVerifier { * @param relation_parameters * @param transcript */ - std::optional> verify(const RelationParameters& relation_parameters, auto& transcript) + std::optional> verify(const proof_system::relation::RelationParameters& relation_parameters, auto& transcript) { bool verified(true); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp index 59035ec889d..312d90dda15 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp @@ -315,7 +315,7 @@ TEST_F(SumcheckTests, ProverAndVerifier) lagrange_first, lagrange_last); // Set aribitrary random relation parameters - sumcheck::RelationParameters relation_parameters{ + proof_system::relation::RelationParameters relation_parameters{ .beta = FF::random_element(), .gamma = FF::random_element(), .public_input_delta = FF::one(), @@ -389,7 +389,7 @@ TEST_F(SumcheckTests, ProverAndVerifierLonger) lagrange_last); // Set aribitrary random relation parameters - sumcheck::RelationParameters relation_parameters{ + proof_system::relation::RelationParameters relation_parameters{ .beta = FF::random_element(), .gamma = FF::random_element(), .public_input_delta = FF::one(), @@ -453,7 +453,7 @@ TEST_F(SumcheckTests, RealCircuitStandard) auto public_input_delta = honk::compute_public_input_delta(public_inputs, beta, gamma, prover.key->circuit_size); - sumcheck::RelationParameters relation_parameters{ + proof_system::relation::RelationParameters relation_parameters{ .beta = beta, .gamma = gamma, .public_input_delta = public_input_delta, @@ -635,7 +635,7 @@ TEST_F(SumcheckTests, RealCircuitUltra) auto lookup_grand_product_delta = honk::compute_lookup_grand_product_delta(beta, gamma, prover.key->circuit_size); - sumcheck::RelationParameters relation_parameters{ + proof_system::relation::RelationParameters relation_parameters{ .eta = eta, .beta = beta, .gamma = gamma, diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 7a4a16e819d..f85add3945c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -130,7 +130,7 @@ template class SumcheckProverRound { * univariate accumulators to be zero. */ barretenberg::Univariate compute_univariate(auto& polynomials, - const RelationParameters& relation_parameters, + const proof_system::relation::RelationParameters& relation_parameters, const barretenberg::PowUnivariate& pow_univariate, const FF alpha) { @@ -213,7 +213,7 @@ template class SumcheckProverRound { template void accumulate_relation_univariates(RelationUnivariates& univariate_accumulators, const auto& extended_edges, - const RelationParameters& relation_parameters, + const proof_system::relation::RelationParameters& relation_parameters, const FF& scaling_factor) { std::get(relations).add_edge_contribution( @@ -403,7 +403,7 @@ template class SumcheckVerifierRound { * checked against the final value of the target total sum, defined as sigma_d. */ FF compute_full_honk_relation_purported_value(ClaimedEvaluations purported_evaluations, - const RelationParameters& relation_parameters, + const proof_system::relation::RelationParameters& relation_parameters, const barretenberg::PowUnivariate& pow_univariate, const FF alpha) { @@ -473,7 +473,7 @@ template class SumcheckVerifierRound { template // TODO(#224)(Cody): Input should be an array? void accumulate_relation_evaluations(ClaimedEvaluations purported_evaluations, - const RelationParameters& relation_parameters, + const proof_system::relation::RelationParameters& relation_parameters, const FF& partial_evaluation_constant) { std::get(relations).add_full_relation_value_contribution( diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp index 183ec09bbb5..13d8e8b0148 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.test.cpp @@ -18,6 +18,8 @@ using namespace proof_system::honk; using namespace proof_system::honk::sumcheck; +using namespace proof_system::relation; + using barretenberg::Univariate; using barretenberg::PowUnivariate; using barretenberg::BarycentricData; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.cpp index df9e8a199f0..3d5f3410521 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.cpp @@ -47,7 +47,7 @@ std::array UltraRecursiveVerifier_::ve using PCS = typename Flavor::PCS; // note: This can only be KZG using VerifierCommitments = typename Flavor::VerifierCommitments; using CommitmentLabels = typename Flavor::CommitmentLabels; - using RelationParams = ::proof_system::honk::sumcheck::RelationParameters; + using RelationParams = ::proof_system::relation::RelationParameters; RelationParams relation_parameters; From b4d11c2bd49c95316db85f7dabdc8bbb368aafd1 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 1 Sep 2023 04:13:23 +0000 Subject: [PATCH 25/45] Move relations to proof_system. --- .../relations_bench/relations.bench.cpp | 16 +++++----- .../honk/composer/standard_composer.hpp | 6 ++-- .../honk/composer/standard_composer.test.cpp | 4 +-- .../honk/composer/ultra_composer.test.cpp | 4 +-- .../barretenberg/honk/flavor/goblin_ultra.hpp | 14 ++++----- .../src/barretenberg/honk/flavor/standard.hpp | 4 +-- .../honk/flavor/standard_grumpkin.hpp | 4 +-- .../src/barretenberg/honk/flavor/ultra.hpp | 12 ++++---- .../honk/flavor/ultra_grumpkin.hpp | 12 ++++---- .../honk/flavor/ultra_recursive.hpp | 12 ++++---- .../proof_system/grand_product_library.hpp | 1 + .../honk/proof_system/ultra_prover.cpp | 4 +-- .../honk/proof_system/ultra_prover.hpp | 2 +- .../relation_correctness.test.cpp | 18 +++++------ .../barretenberg/honk/sumcheck/sumcheck.hpp | 2 +- .../honk/sumcheck/sumcheck.test.cpp | 30 +++++-------------- .../honk/sumcheck/sumcheck_round.hpp | 8 +---- .../relations/arithmetic_relation.hpp | 0 .../relations/auxiliary_relation.hpp | 0 .../relations/ecc_op_queue_relation.hpp | 0 .../relations/elliptic_relation.hpp | 0 .../relations/gen_perm_sort_relation.hpp | 0 .../relations/lookup_relation.hpp | 0 .../relations/permutation_relation.hpp | 0 .../relations/relation_parameters.hpp | 0 .../relations/relation_types.hpp | 0 .../standard_relation_consistency.test.cpp | 4 +-- .../relations/ultra_arithmetic_relation.hpp | 0 .../ultra_relation_consistency.test.cpp | 12 ++++---- 29 files changed, 75 insertions(+), 94 deletions(-) rename circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/{relations => }/relation_correctness.test.cpp (97%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/arithmetic_relation.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/auxiliary_relation.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/ecc_op_queue_relation.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/elliptic_relation.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/gen_perm_sort_relation.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/lookup_relation.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/permutation_relation.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/relation_parameters.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/relation_types.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/standard_relation_consistency.test.cpp (97%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/ultra_arithmetic_relation.hpp (100%) rename circuits/cpp/barretenberg/cpp/src/barretenberg/{honk/sumcheck => proof_system}/relations/ultra_relation_consistency.test.cpp (98%) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index 61bd820b86a..9a1eb10cba9 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -1,14 +1,14 @@ #include "barretenberg/honk/flavor/goblin_ultra.hpp" #include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/honk/flavor/ultra.hpp" -#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" +#include "barretenberg/proof_system/relations/ecc_op_queue_relation.hpp" +#include "barretenberg/proof_system/relations/elliptic_relation.hpp" +#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include namespace { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.hpp index 9d94311686b..2117058d747 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.hpp @@ -25,7 +25,7 @@ template class StandardComposer_ { std::shared_ptr verification_key; // The crs_factory holds the path to the srs and exposes methods to extract the srs elements - std::shared_ptr> crs_factory_; + std::shared_ptr> crs_factory_; // The commitment key is passed to the prover but also used herein to compute the verfication key commitments std::shared_ptr commitment_key; @@ -47,11 +47,11 @@ template class StandardComposer_ { } } - StandardComposer_(std::shared_ptr> crs_factory) + StandardComposer_(std::shared_ptr> crs_factory) : crs_factory_(std::move(crs_factory)) {} - StandardComposer_(std::unique_ptr>&& crs_factory) + StandardComposer_(std::unique_ptr>&& crs_factory) : crs_factory_(std::move(crs_factory)) {} StandardComposer_(std::shared_ptr p_key, std::shared_ptr v_key) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.test.cpp index 21872ce863f..56568cbbf11 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.test.cpp @@ -5,8 +5,8 @@ #include "barretenberg/honk/composer/standard_composer.hpp" #include "barretenberg/honk/proof_system/prover.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/honk/sumcheck/sumcheck_round.hpp" #include "barretenberg/honk/utils/grand_product_delta.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.test.cpp index 9cc1b3b088f..777242c05f2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.test.cpp @@ -8,8 +8,8 @@ #include "barretenberg/honk/composer/ultra_composer.hpp" #include "barretenberg/honk/proof_system/prover.hpp" #include "barretenberg/honk/proof_system/ultra_prover.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/honk/sumcheck/sumcheck_round.hpp" #include "barretenberg/honk/utils/grand_product_delta.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 837e8f22601..8435fb03e38 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -1,12 +1,12 @@ #pragma once #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" +#include "barretenberg/proof_system/relations/ecc_op_queue_relation.hpp" +#include "barretenberg/proof_system/relations/elliptic_relation.hpp" +#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp index ec4a9547fa9..f39712937bb 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp @@ -1,8 +1,8 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp index 0db236f2e71..203c931d3e1 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp @@ -4,8 +4,8 @@ #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/univariate.hpp" -#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 1f445c4fa44..7e8ef042131 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -4,12 +4,12 @@ #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/univariate.hpp" -#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" +#include "barretenberg/proof_system/relations/elliptic_relation.hpp" +#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp index e61fe8698f9..9368c9c22aa 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp @@ -5,12 +5,12 @@ #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/univariate.hpp" -#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" +#include "barretenberg/proof_system/relations/elliptic_relation.hpp" +#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp index 9d73c5443d9..4cd9afbdc0c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp @@ -5,12 +5,12 @@ #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/univariate.hpp" -#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" +#include "barretenberg/proof_system/relations/elliptic_relation.hpp" +#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp index 5408f01a553..9554f11c904 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp @@ -2,6 +2,7 @@ #include "barretenberg/honk/sumcheck/sumcheck.hpp" #include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp" #include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/common/constexpr_utils.hpp" #include namespace proof_system::honk::grand_product_library { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp index 7818514fb33..0138c2bd1d6 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp @@ -6,8 +6,8 @@ #include "barretenberg/honk/proof_system/prover_library.hpp" #include "barretenberg/polynomials/univariate.hpp" // will go away -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" #include "barretenberg/honk/sumcheck/sumcheck.hpp" #include "barretenberg/honk/utils/power_polynomial.hpp" #include "barretenberg/polynomials/polynomial.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp index f2691328ad7..d0365775053 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp @@ -5,7 +5,7 @@ #include "barretenberg/honk/pcs/gemini/gemini.hpp" #include "barretenberg/honk/pcs/shplonk/shplonk.hpp" #include "barretenberg/honk/proof_system/work_queue.hpp" -#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/honk/sumcheck/sumcheck_output.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp similarity index 97% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp index eee10c118f8..4fb22b18337 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_correctness.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp @@ -2,15 +2,15 @@ #include "barretenberg/honk/composer/ultra_composer.hpp" #include "barretenberg/honk/proof_system/grand_product_library.hpp" #include "barretenberg/honk/proof_system/prover_library.hpp" -#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" +#include "barretenberg/proof_system/relations/ecc_op_queue_relation.hpp" +#include "barretenberg/proof_system/relations/elliptic_relation.hpp" +#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" +#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include using namespace proof_system::honk; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index fd28b05522c..a98c7d4137d 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -2,7 +2,7 @@ #include "barretenberg/common/serialize.hpp" #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/honk/proof_system/prover.hpp" -#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/honk/sumcheck/sumcheck_output.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/honk/utils/grand_product_delta.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp index 312d90dda15..7109a5ddf00 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp @@ -1,31 +1,17 @@ +#include "sumcheck.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/honk/composer/standard_composer.hpp" #include "barretenberg/honk/composer/ultra_composer.hpp" -#include "barretenberg/honk/flavor/standard.hpp" #include "barretenberg/honk/proof_system/grand_product_library.hpp" -#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/honk/transcript/transcript.hpp" -#include "barretenberg/numeric/random/engine.hpp" -#include "barretenberg/transcript/manifest.hpp" -#include "barretenberg/transcript/transcript_wrappers.hpp" -#include "relations/arithmetic_relation.hpp" -#include "relations/permutation_relation.hpp" -#include "sumcheck.hpp" -#include -#include -#include -#include - +#include "barretenberg/proof_system/relations/arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" +#include "barretenberg/proof_system/relations/elliptic_relation.hpp" +#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include -#include -#include -#include -#include -#include using namespace proof_system::honk; using namespace proof_system::honk::sumcheck; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index f85add3945c..7f3f12ffd7c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -1,15 +1,9 @@ #pragma once #include "barretenberg/common/log.hpp" #include "barretenberg/common/thread.hpp" -#include "barretenberg/honk/flavor/ultra.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/pow.hpp" -#include "barretenberg/polynomials/univariate.hpp" -#include "relations/relation_parameters.hpp" -#include -#include -#include -#include +#include "barretenberg/proof_system/relations/relation_parameters.hpp" namespace proof_system::honk::sumcheck { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/elliptic_relation.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/lookup_relation.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/permutation_relation.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_parameters.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/relation_types.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/standard_relation_consistency.test.cpp similarity index 97% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/standard_relation_consistency.test.cpp index d19e8bd6df9..6430da73029 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/standard_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/standard_relation_consistency.test.cpp @@ -12,8 +12,8 @@ * */ #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" #include diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp similarity index 98% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp index 33bb0ffca06..62f5f9e1ca6 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/relations/ultra_relation_consistency.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp @@ -12,12 +12,12 @@ * */ #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" -#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" +#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" +#include "barretenberg/proof_system/relations/elliptic_relation.hpp" +#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/lookup_relation.hpp" +#include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include using namespace proof_system::relation; From 9929cbced7c9d9b30cf7aeb96f7961aebfaf34f7 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 1 Sep 2023 16:30:43 +0000 Subject: [PATCH 26/45] Fix test. --- .../cpp/src/barretenberg/polynomials/pow.test.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp index 772126924bb..9c5a725d159 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp @@ -11,16 +11,21 @@ TEST(SumcheckPow, FullPowConsistency) constexpr size_t d = 5; FF zeta = FF::random_element(); - PowUnivariate pow_univariate(zeta); + PowUnivariate pow_univariate(zeta); std::array variables{}; for (auto& u_i : variables) { u_i = FF::random_element(); pow_univariate.partially_evaluate(u_i); } - - FF expected_eval; // WORKTODO - // FF expected_eval = proof_system::honk::power_polynomial::evaluate(zeta, variables); + + FF zeta_power = zeta; + FF expected_eval = 1; + for (auto& u_i : variables) { + expected_eval *= FF(1) - u_i + u_i * zeta_power; + zeta_power *= zeta_power; + } + EXPECT_EQ(pow_univariate.partial_evaluation_constant, expected_eval); } } // namespace barretenberg::test_pow From 77bf2adffbfc785627ec16317be2a73243675632 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 1 Sep 2023 17:23:05 +0000 Subject: [PATCH 27/45] Resolve some WORKTODO. --- .../benchmark/relations_bench/relations.bench.cpp | 11 +++++------ .../src/barretenberg/honk/sumcheck/sumcheck_round.hpp | 4 +--- .../cpp/src/barretenberg/polynomials/barycentric.hpp | 10 +++------- .../cpp/src/barretenberg/polynomials/univariate.hpp | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index 9a1eb10cba9..6d522b9b084 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -53,12 +53,11 @@ void arithmetic_relation(::benchmark::State& state) noexcept } BENCHMARK(arithmetic_relation); -// WORKTODO -// void auxiliary_relation(::benchmark::State& state) noexcept -// { -// execute_relation>(state); -// } -// BENCHMARK(auxiliary_relation); +void auxiliary_relation(::benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(auxiliary_relation); void elliptic_relation(::benchmark::State& state) noexcept { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 7f3f12ffd7c..8af080bfbf8 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -69,9 +69,7 @@ template class SumcheckProverRound { RelationUnivariates univariate_accumulators; // TODO(#224)(Cody): this should go away - // WORKTODO long - barretenberg::BarycentricData barycentric_2_to_max = - barretenberg::BarycentricData(); + barretenberg::BarycentricData barycentric_2_to_max; // Prover constructor SumcheckProverRound(size_t initial_round_size) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp index b84bccd1214..40bf9c4e349 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp @@ -18,13 +18,9 @@ namespace barretenberg { /** - - * @todo: We should definitely consider question of optimal choice of domain, but if decide on {0,1,...,t-1} then we can - * simplify the implementation a bit. - * @todo: If we use this approach in the recursive setting, should we use Plookup. WORKTODO - */ -/** + * @todo: TODO(https://github.com/AztecProtocol/barretenberg/issues/713) Optimize with lookup tables? */ + template class BarycentricDataCompileTime { public: static constexpr size_t big_domain_size = std::max(domain_size, num_evals); @@ -143,7 +139,7 @@ template class BarycentricDataC */ Univariate extend(const Univariate& f) { - static_assert(num_evals >= domain_size); // WORKTODO > triggered + static_assert(num_evals >= domain_size); Univariate result; std::copy(f.evaluations.begin(), f.evaluations.end(), result.evaluations.begin()); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp index fffb79155c2..034e83af580 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp @@ -13,7 +13,7 @@ template class Univariate { public: static constexpr size_t LENGTH = _length; - // WORKTODO: try out std::valarray? + // TODO(https://github.com/AztecProtocol/barretenberg/issues/714) Try out std::valarray? std::array evaluations; Univariate() = default; From 784e2c54b8a497ebc2046199e0b266e94d8eb0e2 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 1 Sep 2023 17:56:37 +0000 Subject: [PATCH 28/45] Formatting --- .../relations/arithmetic_relation.hpp | 4 +- .../relations/auxiliary_relation.hpp | 8 ++-- .../relations/ecc_op_queue_relation.hpp | 8 ++-- .../relations/elliptic_relation.hpp | 8 ++-- .../relations/gen_perm_sort_relation.hpp | 8 ++-- .../relations/lookup_relation.hpp | 8 ++-- .../relations/permutation_relation.hpp | 2 +- .../relations/relation_parameters.hpp | 5 ++- .../proof_system/relations/relation_types.hpp | 42 +++++++++---------- .../relations/ultra_arithmetic_relation.hpp | 8 ++-- 10 files changed, 49 insertions(+), 52 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp index 6e374b0eb34..590b436f195 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp @@ -28,7 +28,7 @@ template class ArithmeticRelationBase { template void static accumulate(typename AccumulatorTypes::Accumulators& accumulators, const auto& new_term, - [[maybe_unused]]const RelationParameters& parameters, + [[maybe_unused]] const RelationParameters& parameters, const FF& scaling_factor) { // OPTIMIZATION?: Karatsuba in general, at least for some degrees? @@ -57,4 +57,4 @@ template class ArithmeticRelationBase { // ...moreover, should just be hidden in the relation parameters? // WORKTODO: make these decisions then propagate to other relations template using ArithmeticRelation = RelationWrapper; -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp index 6e82f2dc6d0..43c149ffc3c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -55,9 +55,9 @@ template class AuxiliaryRelationBase { */ template inline static void accumulate(typename AccumulatorTypes::Accumulators& accumulators, - const auto& extended_edges, - const RelationParameters& relation_parameters, - const FF& scaling_factor) + const auto& extended_edges, + const RelationParameters& relation_parameters, + const FF& scaling_factor) { // OPTIMIZATION?: Karatsuba in general, at least for some degrees? // See https://hackmd.io/xGLuj6biSsCjzQnYN-pEiA?both @@ -292,4 +292,4 @@ template class AuxiliaryRelationBase { }; template using AuxiliaryRelation = RelationWrapper; -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp index 91cc5e8b7d5..564ce5c2179 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp @@ -41,9 +41,9 @@ template class EccOpQueueRelationBase { */ template void static accumulate(typename AccumulatorTypes::Accumulators& accumulators, - const auto& extended_edges, - const RelationParameters&, - const FF& scaling_factor) + const auto& extended_edges, + const RelationParameters&, + const FF& scaling_factor) { // OPTIMIZATION?: Karatsuba in general, at least for some degrees? // See https://hackmd.io/xGLuj6biSsCjzQnYN-pEiA?both @@ -109,4 +109,4 @@ template class EccOpQueueRelationBase { template using EccOpQueueRelation = RelationWrapper; -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp index 4323d2b7a51..c771ecbe58c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp @@ -26,9 +26,9 @@ template class EllipticRelationBase { */ template static void accumulate(typename AccumulatorTypes::Accumulators& accumulators, - const auto& extended_edges, - const RelationParameters&, - const FF& scaling_factor){ + const auto& extended_edges, + const RelationParameters&, + const FF& scaling_factor){ // OPTIMIZATION?: Karatsuba in general, at least for some degrees? // See https://hackmd.io/xGLuj6biSsCjzQnYN-pEiA?both // TODO(luke): Formatter doesnt properly handle explicit scoping below so turning off. Whats up? @@ -98,4 +98,4 @@ template class EllipticRelationBase { template using EllipticRelation = RelationWrapper; // clang-format on -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp index 1a07fa75f9b..5a3493e98c3 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp @@ -33,9 +33,9 @@ template class GenPermSortRelationBase { */ template void static accumulate(typename AccumulatorTypes::Accumulators& accumulators, - const auto& extended_edges, - const RelationParameters&, - const FF& scaling_factor) + const auto& extended_edges, + const RelationParameters&, + const FF& scaling_factor) { // OPTIMIZATION?: Karatsuba in general, at least for some degrees? // See https://hackmd.io/xGLuj6biSsCjzQnYN-pEiA?both @@ -98,4 +98,4 @@ template class GenPermSortRelationBase { template using GenPermSortRelation = RelationWrapper; -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index 38ba009fd3e..e13bd3e3c90 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -160,9 +160,9 @@ template class LookupRelationBase { */ template inline static void accumulate(typename AccumulatorTypes::Accumulators& accumulators, - const auto& extended_edges, - const RelationParameters& relation_parameters, - const FF& scaling_factor) + const auto& extended_edges, + const RelationParameters& relation_parameters, + const FF& scaling_factor) { const auto& grand_product_delta = relation_parameters.lookup_grand_product_delta; @@ -197,4 +197,4 @@ template class LookupRelationBase { template using LookupRelation = RelationWrapper; -} // namespace proof_system::honk::sumcheck \ No newline at end of file +} // namespace proof_system::relation \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index a8eed00d754..56fcfd8b956 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -211,4 +211,4 @@ template class UltraPermutationRelationBase { template using PermutationRelation = RelationWrapper; template using UltraPermutationRelation = RelationWrapper; -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp index 10a2932f476..7053b843eb5 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp @@ -14,7 +14,8 @@ template struct RelationParameters { FF public_input_delta = FF(0); // Permutation FF lookup_grand_product_delta = FF(0); // Lookup - static RelationParameters get_random(){ + static RelationParameters get_random() + { RelationParameters result; result.eta = FF::random_element(); result.beta = FF::random_element(); @@ -24,4 +25,4 @@ template struct RelationParameters { return result; } }; -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp index 0c75fb03c04..068098da9f4 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -3,10 +3,8 @@ #include "relation_parameters.hpp" namespace proof_system::relation { -template concept HasSubrelationLinearlyIndependentMember = requires(T) -{ - T::Relation::SUBRELATION_LINEARLY_INDEPENDENT; -}; +template +concept HasSubrelationLinearlyIndependentMember = requires(T) { T::Relation::SUBRELATION_LINEARLY_INDEPENDENT; }; /** * @brief The templates defined herein facilitate sharing the relation arithmetic between the prover and the verifier. * @@ -33,9 +31,9 @@ template concept HasSubrelationLinearlyIndependentMember = requires * @return requires */ template -requires std::is_same, T>::value inline - typename std::tuple_element<0, typename AccumulatorTypes::AccumulatorViews>::type - get_view(const T& input, const size_t index) + requires std::is_same, T>::value +inline typename std::tuple_element<0, typename AccumulatorTypes::AccumulatorViews>::type get_view(const T& input, + const size_t index) { return input[index]; } @@ -70,7 +68,7 @@ template typename RelationBase> class Relation // WORKTODO: does these templates being defined inside of here mean we can't reuse their instantiations? template struct UnivariateAccumulatorTypes { // These Values are extracted from RelationBase. - using Accumulators = std::tuple...>; + using Accumulators = std::tuple...>; using AccumulatorViews = std::tuple...>; }; template struct ValueAccumulatorTypes { @@ -89,21 +87,19 @@ template typename RelationBase> class Relation static constexpr size_t RELATION_LENGTH = Relation::RELATION_LENGTH; static inline void add_edge_contribution(RelationUnivariates& accumulator, - const auto& input, - const RelationParameters& relation_parameters, - const FF& scaling_factor) + const auto& input, + const RelationParameters& relation_parameters, + const FF& scaling_factor) { - Relation::template accumulate( - accumulator, input, relation_parameters, scaling_factor); + Relation::template accumulate(accumulator, input, relation_parameters, scaling_factor); } static void add_full_relation_value_contribution(RelationValues& accumulator, - auto& input, - const RelationParameters& relation_parameters, - const FF& scaling_factor = 1) + auto& input, + const RelationParameters& relation_parameters, + const FF& scaling_factor = 1) { - Relation::template accumulate( - accumulator, input, relation_parameters, scaling_factor); + Relation::template accumulate(accumulator, input, relation_parameters, scaling_factor); } /** @@ -113,8 +109,8 @@ template typename RelationBase> class Relation * @tparam size_t */ template - static constexpr bool is_subrelation_linearly_independent() requires( - !HasSubrelationLinearlyIndependentMember) + static constexpr bool is_subrelation_linearly_independent() + requires(!HasSubrelationLinearlyIndependentMember) { return true; } @@ -125,11 +121,11 @@ template typename RelationBase> class Relation * @tparam size_t */ template - static constexpr bool is_subrelation_linearly_independent() requires( - HasSubrelationLinearlyIndependentMember) + static constexpr bool is_subrelation_linearly_independent() + requires(HasSubrelationLinearlyIndependentMember) { return std::get(Relation::SUBRELATION_LINEARLY_INDEPENDENT); } }; -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp index 907085caa04..4a7227a46ce 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp @@ -67,9 +67,9 @@ template class UltraArithmeticRelationBase { */ template void static accumulate(typename AccumulatorTypes::Accumulators& evals, - const auto& extended_edges, - const RelationParameters&, - const FF& scaling_factor){ + const auto& extended_edges, + const RelationParameters&, + const FF& scaling_factor){ // OPTIMIZATION?: Karatsuba in general, at least for some degrees? // See https://hackmd.io/xGLuj6biSsCjzQnYN-pEiA?both // clang-format off @@ -121,4 +121,4 @@ template using UltraArithmeticRelation = RelationWrapper; // clang-format on -} // namespace proof_system::honk::sumcheck +} // namespace proof_system::relation From 65da5975a9c45f5ce7c6fdc40a0145ac2e1e37c2 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 1 Sep 2023 18:33:25 +0000 Subject: [PATCH 29/45] Clarify relation inheritance. --- .../relations/arithmetic_relation.hpp | 6 ++-- .../relations/auxiliary_relation.hpp | 6 ++-- .../relations/ecc_op_queue_relation.hpp | 5 ++-- .../relations/elliptic_relation.hpp | 6 ++-- .../relations/gen_perm_sort_relation.hpp | 6 ++-- .../relations/lookup_relation.hpp | 8 +++-- .../relations/permutation_relation.hpp | 13 +++++--- .../proof_system/relations/relation_types.hpp | 27 ++++++++--------- .../relations/ultra_arithmetic_relation.hpp | 6 ++-- .../ultra_relation_consistency.test.cpp | 30 ------------------- 10 files changed, 50 insertions(+), 63 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp index 590b436f195..5f8603b29da 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/arithmetic_relation.hpp @@ -5,8 +5,10 @@ namespace proof_system::relation { // WORKTODO: ... this is a base in a weird way. Wish I could simplify the structure here. -template class ArithmeticRelationBase { +template class ArithmeticRelationImpl { public: + using FF = FF_; + // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 4; @@ -56,5 +58,5 @@ template class ArithmeticRelationBase { // WORKTODO: the field type should be supplied through the base class? // ...moreover, should just be hidden in the relation parameters? // WORKTODO: make these decisions then propagate to other relations -template using ArithmeticRelation = RelationWrapper; +template using ArithmeticRelation = Relation>; } // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp index 43c149ffc3c..1e6f3c6518c 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -5,8 +5,10 @@ namespace proof_system::relation { -template class AuxiliaryRelationBase { +template class AuxiliaryRelationImpl { public: + using FF = FF_; + // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 6; @@ -291,5 +293,5 @@ template class AuxiliaryRelationBase { }; }; -template using AuxiliaryRelation = RelationWrapper; +template using AuxiliaryRelation = Relation>; } // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp index 564ce5c2179..7050481b105 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp @@ -4,8 +4,9 @@ namespace proof_system::relation { -template class EccOpQueueRelationBase { +template class EccOpQueueRelationImpl { public: + using FF = FF_; // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 3; // degree(q * (w - w_op_queue)) = 2 @@ -107,6 +108,6 @@ template class EccOpQueueRelationBase { }; }; -template using EccOpQueueRelation = RelationWrapper; +template using EccOpQueueRelation = Relation>; } // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp index c771ecbe58c..1b35bf72e7f 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp @@ -4,8 +4,10 @@ namespace proof_system::relation { -template class EllipticRelationBase { +template class EllipticRelationImpl { public: + using FF = FF_; + // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 6; // degree(q_elliptic * q_beta * x^3) = 5 @@ -96,6 +98,6 @@ template class EllipticRelationBase { }; template -using EllipticRelation = RelationWrapper; +using EllipticRelation = Relation>; // clang-format on } // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp index 5a3493e98c3..61e6d21ad69 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp @@ -4,8 +4,10 @@ namespace proof_system::relation { -template class GenPermSortRelationBase { +template class GenPermSortRelationImpl { public: + using FF = FF_; + // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 6; // degree(q_sort * D(D - 1)(D - 2)(D - 3)) = 5 @@ -96,6 +98,6 @@ template class GenPermSortRelationBase { }; }; -template using GenPermSortRelation = RelationWrapper; +template using GenPermSortRelation = Relation>; } // namespace proof_system::relation diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index e13bd3e3c90..14abfe9c9f7 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -5,7 +5,7 @@ namespace proof_system::relation { /** - * @brief LookupRelationBase defines the algebra for the lookup polynomial: + * @brief LookupRelationImpl defines the algebra for the lookup polynomial: * * ∏ (1 + β) ⋅ (q_lookup*f_k + γ) ⋅ (t_k + βt_{k+1} + γ(1 + β)) * Z_lookup(g^j) = -------------------------------------------------------------------------- @@ -19,8 +19,10 @@ namespace proof_system::relation { * * @tparam FF parametrises the prime field class being used */ -template class LookupRelationBase { +template class LookupRelationImpl { public: + using FF = FF_; + // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 6; // deg(z_lookup * column_selector * wire * q_lookup * table) = 5 @@ -195,6 +197,6 @@ template class LookupRelationBase { }; }; -template using LookupRelation = RelationWrapper; +template using LookupRelation = Relation>; } // namespace proof_system::relation \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index 56fcfd8b956..94d8c5928db 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -5,13 +5,16 @@ namespace proof_system::relation { -template class PermutationRelationBase { +template class PermutationRelationImpl { public: + using FF = FF_; + // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 5; static constexpr size_t LEN_1 = 5; // grand product construction sub-relation static constexpr size_t LEN_2 = 3; // left-shiftable polynomial sub-relation + static constexpr std::tuple SUBRELATION_LENGTHS = {LEN_1, LEN_2}; template