@@ -70,7 +70,8 @@ pub struct SRS<G> {
7070 lagrange_bases : HashMapCache < usize , Vec < PolyComm < G > > > ,
7171 #[ cfg( not( feature = "std" ) ) ]
7272 #[ serde( skip) ]
73- lagrange_bases : alloc:: rc:: Rc < core:: cell:: RefCell < HashMap < usize , Vec < PolyComm < G > > > > > ,
73+ lagrange_bases :
74+ alloc:: rc:: Rc < core:: cell:: RefCell < HashMap < usize , alloc:: rc:: Rc < Vec < PolyComm < G > > > > > > ,
7475}
7576
7677#[ cfg( not( feature = "std" ) ) ]
@@ -79,28 +80,23 @@ trait GetOrGenExt<G> {
7980 & self ,
8081 key : usize ,
8182 generator : F ,
82- ) -> & Vec < PolyComm < G > > ;
83+ ) -> alloc :: rc :: Rc < Vec < PolyComm < G > > > ;
8384}
8485
8586#[ cfg( not( feature = "std" ) ) ]
86- #[ allow( unsafe_code) ]
87- impl < G > GetOrGenExt < G > for alloc:: rc:: Rc < core:: cell:: RefCell < HashMap < usize , Vec < PolyComm < G > > > > > {
87+ impl < G > GetOrGenExt < G >
88+ for alloc:: rc:: Rc < core:: cell:: RefCell < HashMap < usize , alloc:: rc:: Rc < Vec < PolyComm < G > > > > > >
89+ {
8890 fn get_or_generate < F : FnOnce ( ) -> Vec < PolyComm < G > > > (
8991 & self ,
9092 key : usize ,
9193 generator : F ,
92- ) -> & Vec < PolyComm < G > > {
94+ ) -> alloc :: rc :: Rc < Vec < PolyComm < G > > > {
9395 let mut map = self . borrow_mut ( ) ;
94- if !map. contains_key ( & key) {
95- map. insert ( key, generator ( ) ) ;
96- }
97- drop ( map) ;
98-
99- // SAFETY: We never remove entries from the map, and the Rc<RefCell<HashMap>>
100- // lives as long as the SRS. The reference is valid as long as the entry exists.
101- let map = self . borrow ( ) ;
102- let ptr = map. get ( & key) . unwrap ( ) as * const Vec < PolyComm < G > > ;
103- unsafe { & * ptr }
96+ let entry = map
97+ . entry ( key)
98+ . or_insert_with ( || alloc:: rc:: Rc :: new ( generator ( ) ) ) ;
99+ alloc:: rc:: Rc :: clone ( entry)
104100 }
105101}
106102
@@ -158,7 +154,7 @@ impl<G> SRS<G> {
158154 #[ cfg( not( feature = "std" ) ) ]
159155 pub const fn lagrange_bases (
160156 & self ,
161- ) -> & alloc:: rc:: Rc < core:: cell:: RefCell < HashMap < usize , Vec < PolyComm < G > > > > > {
157+ ) -> & alloc:: rc:: Rc < core:: cell:: RefCell < HashMap < usize , alloc :: rc :: Rc < Vec < PolyComm < G > > > > > > {
162158 & self . lagrange_bases
163159 }
164160}
@@ -597,6 +593,7 @@ impl<G> SRSTrait<G> for SRS<G>
597593where
598594 G : CommitmentCurve ,
599595{
596+ /// The maximum polynomial degree that can be committed to
600597 fn max_poly_size ( & self ) -> usize {
601598 self . g . len ( )
602599 }
@@ -624,6 +621,9 @@ where
624621 } )
625622 }
626623
624+ /// Turns a non-hiding polynomial commitment into a hiding polynomial
625+ /// commitment. Transforms each given `<a, G>` into `(<a, G> + wH, w)` with
626+ /// a random `w` per commitment.
627627 #[ cfg( feature = "std" ) ]
628628 fn mask (
629629 & self ,
0 commit comments