11use crate:: {
2- address::public_keys_hash::PublicKeysHash , constants::GENERATOR_INDEX__PUBLIC_KEYS_HASH ,
3- hash:: poseidon2_hash_with_separator , point::POINT_LENGTH ,
4- traits ::{Deserialize , Serialize , Empty , is_empty , Hash },
2+ address::public_keys_hash::PublicKeysHash ,
3+ constants ::{
4+ GENERATOR_INDEX__PUBLIC_KEYS_HASH , DEFAULT_NPK_M_X , DEFAULT_NPK_M_Y , DEFAULT_IVPK_M_X ,
5+ DEFAULT_IVPK_M_Y , DEFAULT_OVPK_M_X , DEFAULT_OVPK_M_Y , DEFAULT_TPK_M_X , DEFAULT_TPK_M_Y ,
6+ }, hash:: poseidon2_hash_with_separator , point::POINT_LENGTH ,
7+ traits ::{Deserialize , Serialize , Hash },
58};
69
710use dep::std::embedded_curve_ops::EmbeddedCurvePoint as Point ;
11+ use dep::std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key ;
12+ use std::embedded_curve_ops::EmbeddedCurveScalar ;
13+ use std::default::Default ;
814
915pub global PUBLIC_KEYS_LENGTH : u32 = 12 ;
1016
@@ -96,13 +102,21 @@ impl Serialize<POINT_LENGTH> for TpkM {
96102 }
97103}
98104
99- impl Empty for PublicKeys {
100- fn empty () -> Self {
105+ impl Default for PublicKeys {
106+ fn default () -> Self {
101107 PublicKeys {
102- npk_m : NpkM { inner : Point ::empty () },
103- ivpk_m : IvpkM { inner : Point ::empty () },
104- ovpk_m : OvpkM { inner : Point ::empty () },
105- tpk_m : TpkM { inner : Point ::empty () },
108+ npk_m : NpkM {
109+ inner : Point { x : DEFAULT_NPK_M_X , y : DEFAULT_NPK_M_Y , is_infinite : false },
110+ },
111+ ivpk_m : IvpkM {
112+ inner : Point { x : DEFAULT_IVPK_M_X , y : DEFAULT_IVPK_M_Y , is_infinite : false },
113+ },
114+ ovpk_m : OvpkM {
115+ inner : Point { x : DEFAULT_OVPK_M_X , y : DEFAULT_OVPK_M_Y , is_infinite : false },
116+ },
117+ tpk_m : TpkM {
118+ inner : Point { x : DEFAULT_TPK_M_X , y : DEFAULT_TPK_M_Y , is_infinite : false },
119+ },
106120 }
107121 }
108122}
@@ -118,16 +132,10 @@ impl Eq for PublicKeys {
118132
119133impl PublicKeys {
120134 pub fn hash (self ) -> PublicKeysHash {
121- PublicKeysHash ::from_field (
122- if is_empty (self ) {
123- 0
124- } else {
125- poseidon2_hash_with_separator (
126- self .serialize (),
127- GENERATOR_INDEX__PUBLIC_KEYS_HASH as Field ,
128- )
129- },
130- )
135+ PublicKeysHash ::from_field (poseidon2_hash_with_separator (
136+ self .serialize (),
137+ GENERATOR_INDEX__PUBLIC_KEYS_HASH as Field ,
138+ ))
131139 }
132140}
133141
@@ -202,13 +210,13 @@ unconstrained fn compute_public_keys_hash() {
202210}
203211
204212#[test]
205- unconstrained fn compute_empty_hash () {
206- let keys = PublicKeys ::empty ();
213+ unconstrained fn compute_default_hash () {
214+ let keys = PublicKeys ::default ();
207215
208216 let actual = keys .hash ();
209- let test_data_empty_hash = 0x0000000000000000000000000000000000000000000000000000000000000000 ;
217+ let test_data_default_hash = 0x1d3bf1fb93ae0e9cda83b203dd91c3bfb492a9aecf30ec90e1057eced0f0e62d ;
210218
211- assert (actual .to_field () == test_data_empty_hash );
219+ assert (actual .to_field () == test_data_default_hash );
212220}
213221
214222#[test]
0 commit comments