mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-20 16:11:35 +03:00
31 lines
708 B
Plaintext
31 lines
708 B
Plaintext
|
/*
|
||
|
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;
|
||
|
for i in 0..256 {
|
||
|
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 {
|
||
|
const pedersen = PedersenHash::new(parameters);
|
||
|
return pedersen.hash(hash_input);
|
||
|
}
|
||
|
|