Circom 中的哈希函数 Sha256

Hashing function Sha256 in Circom

提问人:Pavel Fedotov 提问时间:7/25/2023 最后编辑:Pavel Fedotov 更新时间:9/11/2023 访问量:195

问:

在黑客马拉松期间,ETH Global Paris 试图将 circom 电路与散列生日日期进行哈希处理集成,以证明用户在遵循一个众所周知的 medium 教程后知道日期。这是它的代码

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]
} */

错误,错误:断言失败。

模板BinSum_17行中的错误:100

模板SigmaPlus_18行中的错误:44

模板Sha256compression_97行中的错误:83

模板Sha256_98行中的错误:73

模板Birthday_99行中的错误:7

密码学 以太坊 pragma circom zk-snark

评论


答:

3赞 Pavel Fedotov 7/25/2023 #1

我问过我的朋友 Kai Jun Eer,我正在实施的东西是否有任何意义。他深入研究了 SHA256 的代码,并证实了我的怀疑,即它的实现并不是最好的,至少是迄今为止最好的。

zrclib 的共同创建者 Kai 建议我使用效率更高的 Poseidon。

因此,以下是帮助我们赢得 2023 年 ETH 全球巴黎的电路代码:

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]
} */