Circcom 中的哈希函数 Sha256

问题描述 投票:0回答:1

在黑客马拉松期间,ETH Global Paris 试图将循环电路与生日日期哈希相结合,以证明用户按照众所周知的媒体教程知道该日期。这是它的代码

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

cryptography ethereum pragma circom zk-snark
1个回答
2
投票

我问过我的朋友凯俊·额尔,我所实施的做法是否有意义。他深入研究了 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]
} */
© www.soinside.com 2019 - 2024. All rights reserved.