Skip to content

Commit e62c1cd

Browse files
committed
Fixes and tests passed
1 parent ec0e7f4 commit e62c1cd

19 files changed

+925
-283
lines changed

c/calcwit.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,29 @@ void Circom_CalcWit::freeBigInts(PBigInt bi, int n) {
122122
}
123123

124124
void Circom_CalcWit::getSignal(int cIdx, int sIdx, PBigInt value) {
125+
#ifdef SANITY_CHECK
126+
if (signalAssigned[sIdx] == false) {
127+
fprintf(stderr, "Accessing a not assigned signal: %d\n", sIdx);
128+
assert(false);
129+
}
130+
#endif
125131
mpz_set(*value, signalValues[sIdx]);
126132
}
127133

128134
void Circom_CalcWit::setSignal(int cIdx, int sIdx, PBigInt value) {
129135
#ifdef SANITY_CHECK
130-
assert(signalAssigned[sIdx] == false);
136+
if (signalAssigned[sIdx] == true) {
137+
fprintf(stderr, "Signal assigned twice: %d\n", sIdx);
138+
assert(false);
139+
}
131140
signalAssigned[sIdx] = true;
132141
#endif
142+
/*
143+
// Log assignement
144+
char *valueStr = mpz_get_str(0, 10, *value);
145+
printf("%d --> %s\n", sIdx, valueStr);
146+
free(valueStr);
147+
*/
133148
mpz_set(signalValues[sIdx], *value);
134149
if ( BITMAP_ISSET(circuit->mapIsInput, sIdx) ) {
135150
inputSignalsToTrigger[cIdx]--;
@@ -147,7 +162,7 @@ void Circom_CalcWit::checkConstraint(PBigInt value1, PBigInt value2, char const
147162
std::string sV2 = std::string(pcV2);
148163
free(pcV1);
149164
free(pcV2);
150-
throw std::runtime_error(std::string("Constraint does not match,") + err + ". " + sV1 + " != " + sV2 );
165+
throw std::runtime_error(std::string("Constraint doesn't match, ") + err + ". " + sV1 + " != " + sV2 );
151166
}
152167
#endif
153168
}
@@ -160,3 +175,10 @@ void Circom_CalcWit::triggerComponent(int newCIdx) {
160175
cIdx = oldCIdx;
161176
}
162177

178+
void Circom_CalcWit::log(PBigInt value) {
179+
char *pcV = mpz_get_str(0, 10, *value);
180+
printf("Log: %s\n", pcV);
181+
free(pcV);
182+
}
183+
184+

c/calcwit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Circom_CalcWit {
4343

4444
void checkConstraint(PBigInt value1, PBigInt value2, char const *err);
4545

46+
void log(PBigInt value);
47+
4648

4749
// Public functions
4850
inline void setInput(int idx, PBigInt val) {

cli.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ if (argv._.length == 0) {
6767

6868
const fullFileName = path.resolve(process.cwd(), inputFile);
6969
const fileName = path.basename(fullFileName, ".circom");
70-
const outName = argv.output ? argv.output : fileName + ".json";
7170
const cSourceName = typeof(argv.csource) === "string" ? argv.csource : fileName + ".cpp";
7271
const r1csName = typeof(argv.r1cs) === "string" ? argv.r1cs : fileName + ".r1cs";
7372
const symName = typeof(argv.sym) === "string" ? argv.sym : fileName + ".sym";
@@ -79,24 +78,15 @@ if (argv.csource) {
7978
options.cSourceWriteStream = fs.createWriteStream(cSourceName);
8079
}
8180
if (argv.r1cs) {
82-
options.r1csWriteStream = fs.createWriteStream(r1csName);
81+
options.r1csFileName = r1csName;
8382
}
8483
if (argv.sym) {
8584
options.symWriteStream = fs.createWriteStream(symName);
8685
}
8786

8887
compiler(fullFileName, options).then( () => {
89-
let r1csDone = false;
9088
let cSourceDone = false;
9189
let symDone = false;
92-
if (options.r1csWriteStream) {
93-
options.r1csWriteStream.end(() => {
94-
r1csDone = true;
95-
finishIfDone();
96-
});
97-
} else {
98-
r1csDone = true;
99-
}
10090
if (options.cSourceWriteStream) {
10191
options.cSourceWriteStream.end(() => {
10292
cSourceDone = true;
@@ -111,11 +101,13 @@ compiler(fullFileName, options).then( () => {
111101
finishIfDone();
112102
});
113103
} else {
114-
cSourceDone = true;
104+
symDone = true;
115105
}
116106
function finishIfDone() {
117-
if ((r1csDone)&&(cSourceDone)&&(symDone)) {
118-
process.exit(0);
107+
if ((cSourceDone)&&(symDone)) {
108+
setTimeout(() => {
109+
process.exit(0);
110+
}, 300);
119111
}
120112
}
121113
}, (err) => {

0 commit comments

Comments
 (0)