Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hashing function Sha256 in Circom

During the hackathon ETH Global Paris Was attempting to integrate a circom circuit with hashing a birthday date to prove that the user know the date following a well known medium tutorial. Here is its code

pragma circom 2.0.0;
include "./circomlib/circuits/sha256/sha256.circom";

template Birthday(){
  component SHA = Sha256(6);
  signal input date[6];
  SHA.in <== date;

  signal output date_out[256];
  date_out <== SHA.out;
}

component main { public [ date ] } = Birthday();

/* INPUT = {
    "date": [10, 3, 0, 3, 0, 1]
} */

Errors, with Error: Assert Failed.

Error in template BinSum_17 line: 100

Error in template SigmaPlus_18 line: 44

Error in template Sha256compression_97 line: 83

Error in template Sha256_98 line: 73

Error in template Birthday_99 line: 7

like image 417
Pavel Fedotov Avatar asked Oct 31 '25 23:10

Pavel Fedotov


1 Answers

I have asked my friend Kai Jun Eer on whether what I was implementing made any sense. He dived into the code for SHA256 and confirmed my suspicion that its implementation is not the best, to day the least.

Kai, co creator of zrclib, recommended me to use Poseidon which is far more efficient.

So here is the circuit code that helped us win 2023 ETH Global Paris:

pragma circom 2.0.0;

include "./circomlib/circuits/poseidon.circom";

template Location(){
    signal input in[2];
    signal output out;

    component poseidon = Poseidon(2);

    poseidon.inputs[0] <== in[0];
    poseidon.inputs[1] <== in[1];
    out <== poseidon.out;
}

component main { public [ in ] } = Location();

/* INPUT = {
    "in": [100, 100]
} */
like image 91
Pavel Fedotov Avatar answered Nov 04 '25 02:11

Pavel Fedotov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!