2023-07-21 13:10:01 +03:00
|
|
|
const snarkjs = require("@tornado/snarkjs");
|
2018-12-06 19:32:49 +03:00
|
|
|
|
|
|
|
const bigInt = snarkjs.bigInt;
|
|
|
|
|
|
|
|
module.exports = function hexBits(cir, witness, sig, nBits) {
|
|
|
|
let v = bigInt(0);
|
2023-07-21 13:10:01 +03:00
|
|
|
for (let i = nBits - 1; i >= 0; i--) {
|
2018-12-06 19:32:49 +03:00
|
|
|
v = v.shiftLeft(1);
|
2023-07-21 13:10:01 +03:00
|
|
|
const name = sig + "[" + i + "]";
|
2018-12-06 19:32:49 +03:00
|
|
|
const idx = cir.getSignalIdx(name);
|
|
|
|
const vbit = bigInt(witness[idx].toString());
|
|
|
|
if (vbit.equals(bigInt(1))) {
|
|
|
|
v = v.add(bigInt(1));
|
|
|
|
} else if (vbit.equals(bigInt(0))) {
|
|
|
|
v;
|
|
|
|
} else {
|
2023-07-21 13:10:01 +03:00
|
|
|
console.log("Not Binary: " + name);
|
2018-12-06 19:32:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return v.toString(16);
|
|
|
|
};
|