2020-10-14 14:08:13 +03:00
|
|
|
circuit PedersenHash {
|
|
|
|
parameters: [group; 256],
|
|
|
|
|
|
|
|
// Instantiates a Pedersen hash circuit
|
2021-02-04 20:30:38 +03:00
|
|
|
function new(self, parameters: [group; 256]) -> Self {
|
2020-10-14 14:08:13 +03:00
|
|
|
return Self { parameters: parameters }
|
|
|
|
}
|
|
|
|
|
|
|
|
function hash(bits: [bool; 256]) -> group {
|
|
|
|
let mut digest: group = 0;
|
|
|
|
for i in 0..256 {
|
|
|
|
if bits[i] {
|
|
|
|
digest += self.parameters[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return digest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The 'pedersen-hash' main function.
|
|
|
|
function main() -> group {
|
2021-02-16 22:19:20 +03:00
|
|
|
let parameters = [1group; 256];
|
|
|
|
let pedersen = PedersenHash::new(parameters);
|
2020-10-14 14:08:13 +03:00
|
|
|
let hash_input: [bool; 256] = [true; 256];
|
|
|
|
return pedersen.hash(hash_input)
|
2020-08-03 06:33:05 +03:00
|
|
|
}
|