github.com/consensys/gnark@v0.11.0/test/end_to_end.go (about) 1 package test 2 3 import ( 4 "reflect" 5 "strings" 6 7 "github.com/consensys/gnark/frontend" 8 ) 9 10 // hollow takes a gnark circuit and removes all the witness data. The resulting circuit can be used for compilation purposes 11 // Its purpose is to make testing more convenient. For example, as opposed to SolvingSucceeded(circuit, assignment), 12 // one can write SolvingSucceeded(hollow(assignment), assignment), obviating the creation of a separate circuit object. 13 func hollow(c frontend.Circuit) frontend.Circuit { 14 cV := reflect.ValueOf(c).Elem() 15 t := reflect.TypeOf(c).Elem() 16 res := reflect.New(t) // a new object of the same type as c 17 resE := res.Elem() 18 resC := res.Interface().(frontend.Circuit) 19 20 frontendVar := reflect.TypeOf((*frontend.Variable)(nil)).Elem() 21 22 for i := 0; i < t.NumField(); i++ { 23 fieldT := t.Field(i).Type 24 if fieldT.Kind() == reflect.Slice && fieldT.Elem().Implements(frontendVar) { // create empty slices for witness slices 25 resE.Field(i).Set(reflect.ValueOf(make([]frontend.Variable, cV.Field(i).Len()))) 26 } else if fieldT != frontendVar { // copy non-witness variables 27 resE.Field(i).Set(cV.Field(i)) 28 } 29 } 30 31 return resC 32 } 33 34 func removePackageName(s string) string { 35 return s[strings.LastIndex(s, ".")+1:] 36 }