@@ -8,7 +8,17 @@ use crate::{
88 types:: { Transcript , VerificationKey } ,
99} ;
1010
11- lazy_static:: lazy_static! {
11+ #[ cfg( not( feature = "std" ) ) ]
12+ use alloc:: { boxed, format, string:: String } ;
13+
14+ #[ cfg( feature = "std" ) ]
15+ use lazy_static:: lazy_static;
16+
17+ #[ cfg( not( feature = "std" ) ) ]
18+ use once_cell:: race:: OnceBox ;
19+
20+ #[ cfg( feature = "std" ) ]
21+ lazy_static ! {
1222 /// 8-point barycentric coefficients
1323 static ref BARY : [ Fr ; 8 ] = [
1424 "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593efffec51" ,
@@ -22,6 +32,25 @@ lazy_static::lazy_static! {
2232 ] . map( Fr :: from_str) ;
2333}
2434
35+ #[ cfg( not( feature = "std" ) ) ]
36+ static BARY_BOX : OnceBox < [ Fr ; 8 ] > = OnceBox :: new ( ) ;
37+
38+ #[ cfg( not( feature = "std" ) ) ]
39+ fn get_bary ( ) -> & ' static [ Fr ; 8 ] {
40+ BARY_BOX . get_or_init ( || {
41+ alloc:: boxed:: Box :: new ( [
42+ Fr :: from_str ( "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593efffec51" ) ,
43+ Fr :: from_str ( "0x00000000000000000000000000000000000000000000000000000000000002d0" ) ,
44+ Fr :: from_str ( "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593efffff11" ) ,
45+ Fr :: from_str ( "0x0000000000000000000000000000000000000000000000000000000000000090" ) ,
46+ Fr :: from_str ( "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593efffff71" ) ,
47+ Fr :: from_str ( "0x00000000000000000000000000000000000000000000000000000000000000f0" ) ,
48+ Fr :: from_str ( "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effffd31" ) ,
49+ Fr :: from_str ( "0x00000000000000000000000000000000000000000000000000000000000013b0" ) ,
50+ ] )
51+ } )
52+ }
53+
2554/// Check if the sum of two univariates equals the target value
2655#[ inline( always) ]
2756fn check_round_sum ( u : & [ Fr ] , target : Fr ) -> bool {
@@ -40,7 +69,12 @@ fn next_target(u: &[Fr], chi: Fr) -> Fr {
4069 // Σ u_i / (BARY[i] * (χ - i))
4170 let mut acc = Fr :: zero ( ) ;
4271 for i in 0 ..8 {
43- let inv = ( BARY [ i] * ( chi - Fr :: from_u64 ( i as u64 ) ) ) . inverse ( ) ;
72+ #[ cfg( feature = "std" ) ]
73+ let bary_val = BARY [ i] ;
74+ #[ cfg( not( feature = "std" ) ) ]
75+ let bary_val = get_bary ( ) [ i] ;
76+
77+ let inv = ( bary_val * ( chi - Fr :: from_u64 ( i as u64 ) ) ) . inverse ( ) ;
4478 acc = acc + ( u[ i] * inv) ;
4579 }
4680
0 commit comments