leo_core/algorithms/
pedersen.rs1use crate::algorithms::CoreFunction;
18use leo_ast::{IntegerType, Type};
19
20pub struct Pedersen64Hash;
21
22impl CoreFunction for Pedersen64Hash {
23 const NUM_ARGS: usize = 1;
24
25 fn first_arg_is_allowed_type(type_: &Type) -> bool {
26 matches!(
27 type_,
28 Type::Boolean
29 | Type::Integer(IntegerType::I8)
30 | Type::Integer(IntegerType::I16)
31 | Type::Integer(IntegerType::I32)
32 | Type::Integer(IntegerType::I64)
33 | Type::Integer(IntegerType::U8)
34 | Type::Integer(IntegerType::U16)
35 | Type::Integer(IntegerType::U32)
36 | Type::Integer(IntegerType::U64)
37 | Type::String
38 )
39 }
40
41 fn return_type() -> Type {
42 Type::Field
43 }
44}
45
46pub struct Pedersen64Commit;
47
48impl CoreFunction for Pedersen64Commit {
49 const NUM_ARGS: usize = 2;
50
51 fn first_arg_is_allowed_type(type_: &Type) -> bool {
52 matches!(
53 type_,
54 Type::Boolean
55 | Type::Integer(IntegerType::I8)
56 | Type::Integer(IntegerType::I16)
57 | Type::Integer(IntegerType::I32)
58 | Type::Integer(IntegerType::I64)
59 | Type::Integer(IntegerType::U8)
60 | Type::Integer(IntegerType::U16)
61 | Type::Integer(IntegerType::U32)
62 | Type::Integer(IntegerType::U64)
63 | Type::String
64 )
65 }
66
67 fn second_arg_is_allowed_type(type_: &Type) -> bool {
68 matches!(type_, Type::Scalar)
69 }
70
71 fn return_type() -> Type {
72 Type::Group
73 }
74}
75
76pub struct Pedersen128Hash;
77
78impl CoreFunction for Pedersen128Hash {
79 const NUM_ARGS: usize = 1;
80
81 fn first_arg_is_allowed_type(type_: &Type) -> bool {
82 matches!(type_, Type::Boolean | Type::Integer(_) | Type::String)
83 }
84
85 fn return_type() -> Type {
86 Type::Field
87 }
88}
89
90pub struct Pedersen128Commit;
91
92impl CoreFunction for Pedersen128Commit {
93 const NUM_ARGS: usize = 2;
94
95 fn first_arg_is_allowed_type(type_: &Type) -> bool {
96 matches!(type_, Type::Boolean | Type::Integer(_) | Type::String)
97 }
98
99 fn second_arg_is_allowed_type(type_: &Type) -> bool {
100 matches!(type_, Type::Scalar)
101 }
102
103 fn return_type() -> Type {
104 Type::Group
105 }
106}