leo/asg/tests/pass/circuits/pedersen_mock.leo

28 lines
669 B
Plaintext
Raw Normal View History

2021-01-25 18:17:42 +03:00
circuit PedersenHash {
parameters: [u32; 512]
function new(parameters: [u32; 512]) -> Self {
2021-04-14 20:51:17 +03:00
return Self { parameters: parameters };
2021-01-25 18:17:42 +03:00
}
function hash(self, bits: [bool; 512]) -> u32 {
let digest: u32 = 0;
2021-01-25 18:17:42 +03:00
for i in 0..512 {
const base = bits[i] ? self.parameters[i] : 0u32;
2021-01-25 18:17:42 +03:00
digest += base;
}
2021-04-14 20:51:17 +03:00
return digest;
2021-01-25 18:17:42 +03:00
}
}
// The 'pedersen_hash' main function.
function main() {
const parameters = [0u32; 512];
const pedersen = PedersenHash::new(parameters);
const hash_input: [bool; 512] = [true; 512];
2021-01-25 18:17:42 +03:00
const res = pedersen.hash(hash_input);
2021-01-25 18:17:42 +03:00
console.assert(res == 0u32);
}