@@ -7,8 +7,8 @@ use super::{
7
7
8
8
#[ derive( Debug ) ]
9
9
pub struct Witness < F : FieldWitness > {
10
- pub primary : Vec < F > ,
11
- pub ( super ) aux : Vec < F > ,
10
+ pub ( super ) primary : Vec < F > ,
11
+ aux : Vec < F > ,
12
12
// Following fields are used to compare our witness with OCaml
13
13
pub ocaml_aux : Vec < F > ,
14
14
ocaml_aux_index : usize ,
@@ -33,86 +33,57 @@ impl<F: FieldWitness> Witness<F> {
33
33
}
34
34
}
35
35
36
- pub fn push < I : Into < F > > ( & mut self , field : I ) {
37
- let field = {
38
- let field: F = field. into ( ) ;
39
- // dbg!(field)
40
- field
41
- } ;
42
- self . assert_ocaml_aux ( & [ field] ) ;
43
- self . aux . push ( field) ;
44
- }
45
-
46
- pub fn extend < I : Into < F > , V : Iterator < Item = I > > ( & mut self , field : V ) {
47
- let fields = {
48
- let fields: Vec < F > = field. map ( Into :: into) . collect ( ) ;
49
- self . assert_ocaml_aux ( & fields) ;
50
- // eprintln!("extend[{}]={:#?}", fields.len(), fields);
51
- fields
52
- } ;
53
- self . aux . extend ( fields)
36
+ pub ( super ) fn aux ( & self ) -> & [ F ] {
37
+ & self . aux
54
38
}
55
39
56
40
pub fn exists < T > ( & mut self , data : T ) -> T
57
41
where
58
42
T : ToFieldElements < F > + Check < F > ,
59
43
{
60
- // data.to_field_elements(&mut self.aux);
61
- let mut fields = data. to_field_elements_owned ( ) ;
62
- self . assert_ocaml_aux ( & fields) ;
63
-
64
- // eprintln!("index={:?} w{:?}", self.aux.len() + 67, &fields);
65
- if self . ocaml_aux . len ( ) > 0 {
66
- eprintln ! (
67
- "index={:?} w{:?}" ,
68
- self . aux. len( ) + self . primary. capacity( ) ,
69
- & fields
70
- ) ;
71
- }
72
- self . aux . append ( & mut fields) ;
73
-
44
+ let data = self . exists_no_check ( data) ;
74
45
data. check ( self ) ;
75
46
data
76
47
}
77
48
49
+ /// Same as `Self::exists`, but do not call `Check::check` on `data`
50
+ /// We use this wherever `seal` is used in OCaml, or on `if_` conditions
78
51
pub fn exists_no_check < T > ( & mut self , data : T ) -> T
79
52
where
80
53
T : ToFieldElements < F > ,
81
54
{
82
- // data.to_field_elements(&mut self.aux);
83
- let mut fields = data. to_field_elements_owned ( ) ;
84
- self . assert_ocaml_aux ( & fields) ;
85
-
86
- // eprintln!("index={:?} w{:?}", self.aux.len() + 67, &fields);
87
- if self . ocaml_aux . len ( ) > 0 {
88
- eprintln ! (
89
- "index={:?} w{:?}" ,
90
- self . aux. len( ) + self . primary. capacity( ) ,
91
- & fields
92
- ) ;
93
- }
94
- self . aux . append ( & mut fields) ;
55
+ #[ cfg( test) ]
56
+ let start = self . aux . len ( ) ;
57
+
58
+ data. to_field_elements ( & mut self . aux ) ;
59
+
60
+ #[ cfg( test) ]
61
+ self . assert_ocaml_aux ( start) ;
95
62
96
63
data
97
64
}
98
65
99
66
/// Compare our witness with OCaml
100
- fn assert_ocaml_aux ( & mut self , new_fields : & [ F ] ) {
67
+ #[ cfg( test) ]
68
+ fn assert_ocaml_aux ( & mut self , start_offset : usize ) {
101
69
if self . ocaml_aux . is_empty ( ) {
102
70
return ;
103
71
}
104
72
105
- // let len = new_fields.len();
106
- // let before = self.aux.len();
107
- // let ocaml = &self.ocaml_aux[before..before + len];
108
- // eprintln!("w{:?} ocaml{:?} {:?}", new_fields, ocaml, new_fields == ocaml);
109
-
73
+ let new_fields = & self . aux [ start_offset..] ;
110
74
let len = new_fields. len ( ) ;
111
- let before = self . aux . len ( ) ;
112
- assert_eq ! ( before, self . ocaml_aux_index) ;
113
- assert_eq ! ( new_fields, & self . ocaml_aux[ before..before + len] ) ;
75
+ let ocaml_fields = & self . ocaml_aux [ start_offset..start_offset + len] ;
76
+
77
+ assert_eq ! ( start_offset, self . ocaml_aux_index) ;
78
+ assert_eq ! ( new_fields, ocaml_fields) ;
114
79
115
80
self . ocaml_aux_index += len;
81
+
82
+ eprintln ! (
83
+ "index={:?} w{:?}" ,
84
+ self . aux. len( ) + self . primary. capacity( ) ,
85
+ & self . aux[ start_offset..]
86
+ ) ;
116
87
}
117
88
118
89
/// Helper
0 commit comments