forked from jancarlsson/snarkfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSL_identity.hpp
120 lines (90 loc) · 2.64 KB
/
DSL_identity.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef _SNARKFRONT_DSL_IDENTITY_HPP_
#define _SNARKFRONT_DSL_IDENTITY_HPP_
#include <array>
#include <cstdint>
#include <BigInt.hpp> // snarklib
#include "DSL_base.hpp"
namespace snarkfront {
////////////////////////////////////////////////////////////////////////////////
// identity elements
//
// Boolean
bool zero(const bool& dummy);
bool one(const bool& dummy);
template <typename FR>
c_bool<FR> zero(const bool_x<FR>& dummy) {
return c_bool<FR>(false);
}
template <typename FR>
c_bool<FR> one(const bool_x<FR>& dummy) {
return c_bool<FR>(true);
}
template <typename FR, std::size_t N>
std::array<c_bool<FR>, N> zero(const std::array<bool_x<FR>, N>& dummy) {
std::array<c_bool<FR>, N> a;
for (std::size_t i = 0; i < N; ++i)
a[i] = zero(dummy[i]);
return a;
}
// big integer
template <mp_size_t N>
snarklib::BigInt<N> zero(const snarklib::BigInt<N>& dummy) {
return snarklib::BigInt<N>::zero();
}
template <mp_size_t N>
snarklib::BigInt<N> one(const snarklib::BigInt<N>& dummy) {
return snarklib::BigInt<N>::one();
}
template <typename FR>
c_bigint<FR> zero(const bigint_x<FR>& dummy) {
return c_bigint<FR>(bigint_x<FR>::ValueType::zero());
}
template <typename FR>
c_bigint<FR> one(const bigint_x<FR>& dummy) {
return c_bigint<FR>(bigint_x<FR>::ValueType::one());
}
template <typename FR, std::size_t N>
std::array<c_bigint<FR>, N> zero(const std::array<bigint_x<FR>, N>& dummy) {
std::array<c_bigint<FR>, N> a;
for (std::size_t i = 0; i < N; ++i)
a[i] = zero(dummy[i]);
return a;
}
// 32-bit word
std::uint32_t zero(const std::uint32_t& dummy);
std::uint32_t one(const std::uint32_t& dummy);
template <typename FR>
c_uint32<FR> zero(const uint32_x<FR>& dummy) {
return c_uint32<FR>(0);
}
template <typename FR>
c_uint32<FR> one(const uint32_x<FR>& dummy) {
return c_uint32<FR>(1);
}
template <typename FR, std::size_t N>
std::array<c_uint32<FR>, N> zero(const std::array<uint32_x<FR>, N>& dummy) {
std::array<c_uint32<FR>, N> a;
for (std::size_t i = 0; i < N; ++i)
a[i] = zero(dummy[i]);
return a;
}
// 64-bit word
std::uint64_t zero(const std::uint64_t& dummy);
std::uint64_t one(const std::uint64_t& dummy);
template <typename FR>
c_uint64<FR> zero(const uint64_x<FR>& dummy) {
return c_uint64<FR>(0);
}
template <typename FR>
c_uint64<FR> one(const uint64_x<FR>& dummy) {
return c_uint64<FR>(1);
}
template <typename FR, std::size_t N>
std::array<c_uint64<FR>, N> zero(const std::array<uint64_x<FR>, N>& dummy) {
std::array<c_uint64<FR>, N> a;
for (std::size_t i = 0; i < N; ++i)
a[i] = zero(dummy[i]);
return a;
}
} // namespace snarkfront
#endif