Longfellow ZK 0290cb32
Loading...
Searching...
No Matches
compiler_backend.h
1// Copyright 2025 Google LLC.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_
16#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_
17
18#include <stdlib.h>
19
20#include <cstddef>
21
22#include "circuits/compiler/compiler.h"
23
24namespace proofs {
25// backend that compiles a circuit that, when evaluated, computes Elt's
26template <class Field>
27class CompilerBackend {
28 using QuadCircuitF = QuadCircuit<Field>;
29 using Elt = typename Field::Elt;
30
31 public:
32 using V = size_t;
33
34 explicit CompilerBackend(QuadCircuitF* q) : q_(q) {}
35
36 V assert0(const V& a) const { return q_->assert0(a); }
37 V add(const V& a, const V& b) const { return q_->add(a, b); }
38 V sub(const V& a, const V& b) const {
39 auto mb = mul(konst(q_->f_.mone()), b);
40 return add(a, mb);
41 }
42 V mul(const V& a, const V& b) const { return q_->mul(a, b); }
43 V mul(const Elt& a, const V& b) const { return q_->mul(a, b); }
44 V mul(const Elt& a, const V& b, const V& c) const { return q_->mul(a, b, c); }
45 V konst(const Elt& a) const { return q_->konst(a); }
46
47 V ax(const Elt& a, const V& x) const { return q_->mul(a, x); }
48 V axy(const Elt& a, const V& x, const V& y) const { return q_->mul(a, x, y); }
49 V axpy(const V& y, const Elt& a, const V& x) const {
50 return q_->axpy(y, a, x);
51 }
52 V apy(const V& y, const Elt& a) const { return q_->apy(y, a); }
53
54 V input() const { return q_->input(); }
55 void output(size_t n, V wire_id) const { q_->output(n, wire_id); }
56 size_t wire_id(const V& a) const { return q_->wire_id(a); }
57
58 private:
59 QuadCircuitF* q_;
60};
61} // namespace proofs
62
63#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_
Definition compiler.h:50
Definition gf2_128.h:63