Closed weijiekoh closed 5 years ago
To answer my own question:
The SHA256 circuit accepts a 54-byte input, split up into two variables a
and b
.
To encode the number 0x00000001:
Set the buffer in JS as such: b[53] = 1;
Set the circom witness as such: {a: 0, b: 1}
To encode the number 256:
Set the buffer in JS as such: b[52] = 1;
Set the circom witness as such: {a: 0, b: 256}
256 in binary is 100000000
, so b[53] == 0
and b[52] == 1
I really appreciate your work on the
Sha256_2
circuit implementation. It's very useful, especially because it enables useful ZKPs, such as those which use commit-reveal schemes.I was wondering how exactly to format the input to the
Sha256_2
circuit. It acceptsa
andb
, and the corresponding input to the JS sha256 function uses aBuffer
of length 54.In
test/sha256.js
:Circuit input:
{ "a": "1", "b": "0" }
JS hash of the same data:However, what if I have data of a different format? Let's say I want to compute the sha256 hash of a unicode string
Hello, world
or the number1234
. How should I format the circuit'sa
, andb
inputs, as well as the JSBuffer
?Thank you!