leo/tests/compiler/circuits/pedersen_mock.leo

39 lines
837 B
Plaintext
Raw Normal View History

2021-05-05 11:37:51 +03:00
/*
namespace: Compile
expectation: Pass
inputs:
- pedersen.in: |
[main]
hash_input: [bool; 512] = [true; 512];
[registers]
r0: bool = false;
*/
circuit PedersenHash {
2020-09-02 21:25:49 +03:00
parameters: [u32; 512]
2020-12-01 23:37:44 +03:00
function new(parameters: [u32; 512]) -> Self {
return Self { parameters: parameters };
}
2020-12-01 23:37:44 +03:00
function hash(self, bits: [bool; 512]) -> u32 {
let digest: u32 = 0;
for i in 0..512 {
const base = bits[i] ? self.parameters[i] : 0u32;
digest += base;
}
return digest;
}
}
// The 'pedersen_hash' main function.
2021-05-05 11:37:51 +03:00
function main(hash_input: [bool; 512]) -> bool {
const parameters = [0u32; 512];
const pedersen = PedersenHash::new(parameters);
const res = pedersen.hash(hash_input);
2020-08-17 05:14:26 +03:00
console.assert(res == 0u32);
2021-05-05 11:37:51 +03:00
return res == 0u32;
}