2020-05-20 22:45:40 +03:00
|
|
|
circuit PedersenHash {
|
2020-06-20 09:02:58 +03:00
|
|
|
parameters: u32[512]
|
2020-07-03 23:35:46 +03:00
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
static function new(parameters: u32[512]) -> Self {
|
2020-05-20 22:45:40 +03:00
|
|
|
return Self { parameters: parameters }
|
|
|
|
}
|
2020-07-03 23:35:46 +03:00
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
function hash(bits: bool[512]) -> u32 {
|
|
|
|
let mut digest: u32 = 0;
|
2020-05-20 22:45:40 +03:00
|
|
|
for i in 0..512 {
|
2020-07-03 23:35:46 +03:00
|
|
|
let base = if bits[i] ? self.parameters[i] : 0u32;
|
2020-05-20 22:45:40 +03:00
|
|
|
digest += base;
|
|
|
|
}
|
|
|
|
return digest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-20 09:02:58 +03:00
|
|
|
// The 'pedersen_hash' main function.
|
|
|
|
function main() -> u32 {
|
|
|
|
let parameters = [0u32; 512];
|
2020-05-20 22:45:40 +03:00
|
|
|
let pedersen = PedersenHash::new(parameters);
|
2020-06-20 09:02:58 +03:00
|
|
|
let input: bool[512] = [true; 512];
|
|
|
|
return pedersen.hash(input)
|
|
|
|
}
|