leo/disabled_tests/parser/serialize/pedersen_hash.leo

31 lines
732 B
Plaintext
Raw Normal View History

2022-01-28 21:34:02 +03:00
/*
namespace: Serialize
expectation: Pass
*/
circuit PedersenHash {
parameters: [group; 256];
// Instantiates a Pedersen hash circuit
function new(parameters: [group; 256]) -> Self {
return Self { parameters: parameters };
}
function hash(self, bits: [bool; 256]) -> group {
let digest: group = 0group;
2022-03-08 21:20:05 +03:00
for i: u32 in u32..256u32 {
2022-01-28 21:34:02 +03:00
if bits[i] {
digest += self.parameters[i];
}
}
return digest;
}
}
// The 'pedersen-hash' main function.
function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group {
2022-03-07 19:30:03 +03:00
const pedersen: PerdesenHash = PedersenHash::new(parameters);
2022-01-28 21:34:02 +03:00
return pedersen.hash(hash_input);
}