You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
595 B

  1. const snarkjs = require("snarkjs");
  2. const bigInt = snarkjs.bigInt;
  3. module.exports = function hexBits(cir, witness, sig, nBits) {
  4. let v = bigInt(0);
  5. for (let i=nBits-1; i>=0; i--) {
  6. v = v.shiftLeft(1);
  7. const name = sig+"["+i+"]";
  8. const idx = cir.getSignalIdx(name);
  9. const vbit = bigInt(witness[idx].toString());
  10. if (vbit.equals(bigInt(1))) {
  11. v = v.add(bigInt(1));
  12. } else if (vbit.equals(bigInt(0))) {
  13. v;
  14. } else {
  15. console.log("Not Binary: "+name);
  16. }
  17. }
  18. return v.toString(16);
  19. };