Skip to content

Correct method for calculating Pedersen hash #20

@TheBojda

Description

@TheBojda

I tried to calculate Pedersen hash with circom and circomjs, but the results are different.

This is my circuit:

template PedersenHasher() {
    signal input source;
    signal output hash;
    signal output hash2;

    component hasher = Pedersen(248);
    component sourceBits = Num2Bits(248);
    sourceBits.in <== source;

    for (var i = 0; i < 248; i++) {
        hasher.in[i] <== sourceBits.out[i];
    }

    hash <== hasher.out[0];
    hash2 <== hasher.out[1];
}

component main = PedersenHasher();

And this is my circomjs code:

const pedersen = await buildPedersenHash();
const source = crypto.randomBytes(31);

const pedersenHash = pedersen.hash(source)
const points = pedersen.babyJub.unpackPoint(pedersenHash)

const { proof, publicSignals } = await groth16.fullProve({ source: ethers.BigNumber.from(source).toString() },
    "./build/pedersenHasherTest_js/pedersenHasherTest.wasm", "./build/pedersenHasher_0001.zkey")

If am I right publicSignals[0] should be equal to points[0] and publicSignals[1] should be equal to points[1], but the hashes are different.

Am I doing something wrong, or is it a bug in circomjs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions