@@ -17,6 +17,9 @@ impl StarkHash for Pedersen {
17
17
18
18
/// Computes the Pedersen hash of an array of Felts, as defined
19
19
/// in <https://docs.starknet.io/documentation/architecture_and_concepts/Hashing/hash-functions/#array_hashing.>
20
+ ///
21
+ /// Warning: there is room for collision as:
22
+ /// pedersen_array([value]) and pedersen(pedersen(0, value), 1) will return the same values
20
23
fn hash_array ( felts : & [ Felt ] ) -> Felt {
21
24
let data_len = Felt :: from ( felts. len ( ) ) ;
22
25
let current_hash: FieldElement < Stark252PrimeField > = felts
@@ -26,16 +29,32 @@ impl StarkHash for Pedersen {
26
29
} ) ;
27
30
Felt ( PedersenStarkCurve :: hash ( & current_hash, & data_len. 0 ) )
28
31
}
29
-
32
+
33
+ /// Computes the Pedersen hash of a single Felt
34
+ ///
35
+ /// Warning: there is room for collision as:
36
+ /// pedersen(value) and pedersen(value, 0) will return the same values
30
37
fn hash_single ( felt : & Felt ) -> Felt {
31
- todo ! ( )
38
+ Felt ( PedersenStarkCurve :: hash ( & felt . 0 , & Felt :: from ( 0 ) . 0 ) )
32
39
}
33
40
}
34
41
35
42
#[ cfg( test) ]
36
43
mod tests {
37
44
use super :: * ;
38
45
46
+ #[ test]
47
+ fn test_pedersen_hash_single ( ) {
48
+ let x =
49
+ Felt :: from_hex ( "0x03d937c035c878245caf64531a5756109c53068da139362728feb561405371cb" )
50
+ . unwrap ( ) ;
51
+ assert_eq ! (
52
+ Pedersen :: hash_single( & x) ,
53
+ Felt :: from_hex( "0x460ded9dacd215bcfc43f1b30b2a02690378e00f82a2283617d47d948c7b7f1" )
54
+ . unwrap( )
55
+ )
56
+ }
57
+
39
58
#[ test]
40
59
fn test_pedersen_hash ( ) {
41
60
let x =
0 commit comments