Comments (4)
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.
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.
@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.
I'm having similar problems!
from circomlib.
Related Issues (20)
- poseidon hash not equal
- Webassembly LinkError when running tests HOT 1
- error[P1014]: The file circomlib/circuits/poseidon.circom to be included has not been found
- Why is there no template in montgomery.circom for checking a point for belonging to a curve? HOT 1
- Question: smtprocessor new1 state & fnc[1]
- Question: is the circomlib2 branch safe to use?
- How to send strings or array characters as input HOT 1
- How can I modify the parameter p in circom?
- NOT template in Gate.circom
- A detailed Circomlib Readme HOT 2
- Poseidon constants not reproduced HOT 1
- wrong LR bit order when transversing leaf to root?
- Question about Num2Bits HOT 2
- Tests fail on fresh setup HOT 4
- Exception caused by invalid access HOT 2
- Adding Elgamal Encryption/Decryption circuits
- Question about BabyPbk babyjub.circom HOT 3
- Possible Optimisation to IsZero HOT 1
- What is recommended Circuit template for Identity proofs and also for blockchains HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from circomlib.