leo/compiler/tests/circuits/pedersen_mock.leo

28 lines
655 B
Plaintext
Raw Normal View History

circuit PedersenHash {
2020-09-02 21:25:49 +03:00
parameters: [u32; 512]
2020-09-02 21:25:49 +03:00
static function new(parameters: [u32; 512]) -> Self {
return Self { parameters: parameters }
}
2020-09-02 21:25:49 +03:00
function hash(bits: [bool; 512]) -> u32 {
let mut digest: u32 = 0;
for i in 0..512 {
let base = if bits[i] ? self.parameters[i] : 0u32;
digest += base;
}
return digest
}
}
// The 'pedersen_hash' main function.
2020-07-30 21:11:54 +03:00
function main() {
let parameters = [0u32; 512];
let pedersen = PedersenHash::new(parameters);
2020-09-02 21:25:49 +03:00
let input: [bool; 512] = [true; 512];
2020-07-30 21:11:54 +03:00
2020-08-17 05:14:26 +03:00
let res = pedersen.hash(input);
console.assert(res == 0u32);
}