我想表明用户知道 circom 中 sha256 哈希的原像。原像可以是任意长度,但实际上在 100-700 字节之间。我尝试了代码:
template ArbitraryLengthSha256 () {
signal input nBits;
signal input preimage[nBits];
signal output result[256];
var i;
component hashed = Sha256(nBits);
for (i=0; i<nBits; i++) {
hashed.in[i] <== preimage[i];
}
for (i=0; i<256; i++) {
result[i] <== hashed.out[i];
}
}
这会导致错误:
error[T20460]: Typing error found
┌─ "ppp.circom":8:26
│
8 │ signal input preimage[nBits];
│ ^^^^^ The length of every array must known during the constraint generation phase
error[T20461]: Typing error found
┌─ "ppp.circom":14:23
│
14 │ component hashed = Sha256(nBits);
│ ^^^^^^^^^^^^^ Every component instantiation must be resolved during the constraint generation phase
error[T2005]: Typing error found
┌─ "ppp.circom":15:14
│
15 │ for (i=0; i<nBits; i++) {
│ ^^^^^^^ There are constraints depending on the value of the condition and it can be unknown during the constraint generation phase
有什么方法可以对 circom 中的任意长度字符串进行 sha256 哈希吗?