我在玩圆珠笔和圆球。
我正在使用一个简单的模拟海绵散列电路,看看我是否可以通过javascript前端创建一个正确的输入。
我正在运行的电路
template sponge_test() {
signal input l;
signal input r;
signal input o;
// instantiate - 2 inputs 220 rounds of hashing and 1 output
component hasher = MiMCSponge(2, 220, 1);
// signals in hasher
hasher.ins[0] <== l;
hasher.ins[1] <== r;
// addition constant
hasher.k <== 0;
o === hasher.outs[0];
}
component main = sponge_test();在我的javascript前端,我正在导入circomlib。
import { buildMimcSponge } from 'circomlibjs';
function toHexString(byteArray) {
return Array.from(byteArray, function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('')
}
export async function getProof(message) {
var hasher = await buildMimcSponge();
var h = hasher.multiHash([BigInt("0x3"), BigInt("0x4")]);
// returns byte array
console.log(h);
// back to hexstring
console.log(toHexString(h));
}然后,我创建了一个input.json,如下所示:
{
"l": "0x3",
"r": "0x4",
"o": "0x690f48aba976f2786371b7fa3e941df623e96329e0570dc610f59b7fcfa94723"
},其中包括用于哈希输入的值和打印十六进制值的输出,然后运行以下脚本
# Compile the circuit
circom ${CIRCUIT}.circom --r1cs --wasm --sym --c
# Generate the witness.wtns
node ${CIRCUIT}_js/generate_witness.js ${CIRCUIT}_js/${CIRCUIT}.wasm input.json ${CIRCUIT}_js/witness.wtns我得到断言(o===hasher.outs[0])失败的错误。
现在,我知道,通过查看节点库( node ),在圆环库的javascript实现中,模拟海绵电路也使用了220轮,否则,在散列中,我还能达到不一致的结果呢?
发布于 2022-09-05 18:39:04
因此,我发现阅读已使用以下方法完成。我认为这是因为它是特定于所使用的椭圆曲线。
hasher.F.toString(h, 16);这就产生了电路所接受的预期结果。
如果有人有更深入的见解,我很乐意进一步了解。
https://stackoverflow.com/questions/73604014
复制相似问题