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;
|
|
|
|
*/
|
|
|
|
|
2020-05-20 22:45:40 +03:00
|
|
|
circuit PedersenHash {
|
2021-04-29 22:22:17 +03:00
|
|
|
parameters: [u32; 512];
|
2020-07-03 23:35:46 +03:00
|
|
|
|
2020-12-01 23:37:44 +03:00
|
|
|
function new(parameters: [u32; 512]) -> Self {
|
2021-04-14 23:59:07 +03:00
|
|
|
return Self { parameters: parameters };
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
2020-07-03 23:35:46 +03:00
|
|
|
|
2021-05-06 14:27:42 +03:00
|
|
|
function hash(const self, bits: [bool; 512]) -> u32 {
|
2021-03-18 22:19:07 +03:00
|
|
|
let digest: u32 = 0;
|
2020-05-20 22:45:40 +03:00
|
|
|
for i in 0..512 {
|
2021-05-06 14:27:42 +03:00
|
|
|
let base = bits[i] ? self.parameters[i] : 0u32;
|
2020-05-20 22:45:40 +03:00
|
|
|
digest += base;
|
|
|
|
}
|
2021-04-14 23:59:07 +03:00
|
|
|
return digest;
|
2020-05-20 22:45:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
// The 'pedersen_hash' main function.
|
2021-05-05 11:37:51 +03:00
|
|
|
function main(hash_input: [bool; 512]) -> bool {
|
2021-03-18 22:19:07 +03:00
|
|
|
const parameters = [0u32; 512];
|
|
|
|
const pedersen = PedersenHash::new(parameters);
|
2021-05-06 14:27:42 +03:00
|
|
|
let res = pedersen.hash(hash_input);
|
2020-08-17 05:14:26 +03:00
|
|
|
|
2021-05-05 11:37:51 +03:00
|
|
|
return res == 0u32;
|
2020-06-20 09:02:58 +03:00
|
|
|
}
|