Code Monkey home page Code Monkey logo

Comments (4)

ZionDoki avatar ZionDoki commented on June 30, 2024 2

The problem occurs because there is a problem between the Buffer BigInt and the string format conversion required by the commitment.

In case someone encounters the same problem later, my previous solution is:

const ffjavascript = require("ffjavascript");
const stringifyBigInts = ffjavascript.utils.stringifyBigInts;
const F = new ffjavascript.ZqField(
  ffjavascript.Scalar.fromString(
    "21888242871839275222246405745257275088548364400416034343698204186575808495617"
  )
);

function createCommitment(secret) {
  return pedersenHash(secret)
}

let secret = crypto.randomBytes(31);                                         // generate random secret
const createdcommitment = createCommitment(secret);  
cm = stringifyBigInts(F.fromRprLEM(createdcommitment));      // commitment

with good regards, guys :>

from circomlib.

crashpilot avatar crashpilot commented on June 30, 2024 1

Hey, I ran into similar issues.

After quite some debugging I found that the circomlibjs expects an uint8array as input and the circom circuit expects the bit format.

I use this function to format for instance an uint8 buffer to a bit representation:

function buffer2bits(buff) {
    const res = [];
    for (let i = 0; i < buff.length; i++) {
        for (let j = 0; j < 8; j++) {
            if ((buff[i] >> j) & 1) {
                res.push('1');
            } else {
                res.push('0');
            }
        }
    }
    return res;
}

Adapting accordingly fixed it for me.

from circomlib.

StrawberryChocolateFudge avatar StrawberryChocolateFudge commented on June 30, 2024

I'm having similar problems!

from circomlib.

TheBojda avatar TheBojda commented on June 30, 2024

@ZionDoki Is the complete code available anywhere?

I tried it with a super simple circuit:

pragma circom 2.0.0;

include "../node_modules/circomlib/circuits/pedersen.circom";

component main = Pedersen(248);

and a simple js code, but the result is always wrong:

pedersen = await buildPedersenHash();
const b = Buffer.alloc(31);
for (let i = 0; i < 31; i++) {
   b[i] = i + 1;
}
const pedersenHash = pedersen.hash(b)
const points = pedersen.babyJub.unpackPoint(pedersenHash)
console.log(points);

function buffer2bitArray(b) {
    const res = [];
    for (let i = 0; i < b.length; i++) {
        for (let j = 0; j < 8; j++) {
            res.push((b[i] >> (7 - j) & 1));
        }
    }
    return res;
}

const { proof, publicSignals } = await groth16.fullProve({ in: arrIn }, "./build/pedersen_test_js/pedersen_test.wasm", "./build/pedersen_test.zkey")
console.log(publicSignals)

The publicSignals[0] should be equal to points[0], but it is always different.

(btw, sha256 works lika a charm, but it's slow)

from circomlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.