1
$\begingroup$

I want to create a SHA256 hasher in Circom so I can validate that a person knows the pre-image of a SHA256 hash without revealing the pre-image. This is my current code but it doesn't work:

include "/node_modules/circomlib/circuits/sha256/sha256.circom"

template SHAHasher(nBits) {
  signal input bits[nBits];
  signal output newHash[256];

  component shaHash = Sha256(nBits);

  for (var i=0; i<nBits; i++) {
    shaHash.in[i] <== bits[i];
  }

  for (var i=0; i<256; i++) {
    newHash[i] <== shaHash.out[i];
  }
}

Thank you in advance, any help would be greatly appreciated.

$\endgroup$
5
  • 1
    $\begingroup$ I don't know Circom at all, but this wrapper class seems to provide zero functionality over the wrapped Sha256 class. How exactly does it fail? $\endgroup$
    – Maarten Bodewes
    Jul 29, 2022 at 1:30
  • $\begingroup$ I think you need to know circom in order to solve the problem, but it's not returning an error this is why I'm confused. stderr: "" $\endgroup$ Jul 29, 2022 at 2:33
  • $\begingroup$ I have made a meta question to discuss if this kind of question is on-topic, despite being a programming question. On the technical side: assuming we accept this kind of questions, the present one is not answerable without a description of how the code was compiled (version of compiler, option on the command line), same for any later tool invoked. I would suggest to perform the "getting started" procedure before trying something so much more difficult. $\endgroup$
    – fgrieu
    Jul 29, 2022 at 5:05
  • $\begingroup$ @LostatCplusplus OK, clear, no error in the error stream, but in that case how does it fail? Does it return the wrong value? How have you come up with the "right" value? Doesn't it return any value? $\endgroup$
    – Maarten Bodewes
    Jul 29, 2022 at 12:27
  • $\begingroup$ This is the error: 'Error: Error: Assert Failed. Error in template BinSum_17 line: 100\n' $\endgroup$ Jul 29, 2022 at 14:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.