forked from trifle-labs/anybody-problem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_circom.sh
executable file
·101 lines (85 loc) · 2.8 KB
/
generate_circom.sh
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
#!/bin/bash
#!/bin/bash
# Function to generate Circom code with hardcoded sine and cosine values
generate_code() {
# Header for the Circom template
echo "pragma circom 2.1.6;
// NOTE: DO NOT EDIT. THIS CODE WAS GENERATED BY generate_circom.sh
// NOTE: decimals = 2, so the values are multiplied by 100
function returnCosSin(isSin) {
var cos[360];
var sin[360];
"
# Loop to generate sine and cosine values for each degree
for i in {0..359}
do
# Calculating sine and cosine values using bc
a1=$(echo "a(1)" | bc -l)
inside=$(echo "($i*a(1)/45)" | bc -l)
echo "// inside = $inside, a1 = $a1"
cos_value=$(echo "c($inside)*100" | bc -l | awk '{printf "%d\n", $0}')
sin_value=$(echo "s($inside)*100" | bc -l | awk '{printf "%d\n", $0}')
# Printing the hardcoded values in Circom format
echo " cos[$i] = ${cos_value};"
echo " sin[$i] = ${sin_value};"
done
# Footer for the Circom template
echo "
if (isSin == 1) {
return sin;
} else {
return cos;
}
}"
}
# Call the function and save the output to a file
generate_code > circuits/hardcodedSinCos.circom
echo "Circom code generated in hardcodedSinCos.circom"
# # Function to generate Circom code with hardcoded sine and cosine values
# generate_cos_code() {
# # Header for the Circom template
# echo "template HardcodedCos() {
# var decimals = 4;
# signal input in;
# signal output out;
# var cos[360];
# "
# # Loop to generate sine and cosine values for each degree
# for i in {0..359}
# do
# # Calculating sine and cosine values using bc
# cos_value=$(echo "c($i*a(1)/180)*10000" | bc -l | awk '{printf "%d\n", $0}')
# # Printing the hardcoded values in Circom format
# echo " cos[$i] = ${cos_value};"
# done
# # Footer for the Circom template
# echo "
# out <== cos[in];
# }"
# }
# # Function to generate Circom code with hardcoded sine and cosine values
# generate_sin_code() {
# # Header for the Circom template
# echo "template HardcodedSin() {
# var decimals = 4;
# signal input in;
# signal output out;
# var sin[360];
# "
# # Loop to generate sine values for each degree
# for i in {0..359}
# do
# # Calculating sine values using bc
# sin_value=$(echo "s($i*a(1)/180)*10000" | bc -l | awk '{printf "%d\n", $0}')
# # Printing the hardcoded values in Circom format
# echo " cos[$i] = ${sin_value};"
# done
# # Footer for the Circom template
# echo "
# out <== sin[in];
# }"
# }
# # Call the function and save the output to a file
# generate_cos_code > circuits/hardcodedCos.circom
# generate_sin_code > circuits/hardcodedSin.circom
# echo "Circom code generated in hardcodedSin.circom and hardcodedCos.circom"