arnaucube
arnaucube/sonobe-playgroundPublic Self-hosted repository
sonobe-playground/circuit/utils/row_hasher.circom
circuit/utils/row_hasher.circomRaw
 1pragma circom 2.0.0;
 2include "../node_modules/circomlib/circuits/poseidon.circom";
 3
 4template Hasher(inputSize) {
 5    signal input values[inputSize];
 6    signal output hash;
 7
 8    component hasher = Poseidon(inputSize);
 9    for (var i = 0; i < inputSize; i++) {
10        hasher.inputs[i] <== values[i];
11    }
12    hash <== hasher.out;
13}
14
15
16template RowHasher (width) {
17    signal input img[width];
18    signal output hash;
19
20    component hasher[width-1];
21
22    for(var i=0; i < width-1; i++) {
23        hasher[i] = Hasher(2);
24        hasher[i].values[0] <== i == 0 ? img[0] : hasher[i-1].hash;
25        hasher[i].values[1] <== img[i+1];
26    }
27
28    hash <== hasher[width-2].hash;
29
30}