MCPcopy Create free account
hub / github.com/PolyhedraZK/ExpanderCompilerCollection / FromInterface

Function FromInterface

ecgo/utils/convert.go:38–89  ·  view source on GitHub ↗

FromInterface converts an interface to a big.Int element input must be primitive (uintXX, intXX, []byte, string) or implement BigInt(res *big.Int) (which is the case for gnark-crypto field elements) if the input is a string, it calls (big.Int).SetString(input, 0). In particular: The number prefix

(input interface{})

Source from the content-addressed store, hash-verified

36//
37// panics if the input is invalid
38func FromInterface(input interface{}) big.Int {
39 var r big.Int
40
41 switch v := input.(type) {
42 case big.Int:
43 r.Set(&v)
44 case *big.Int:
45 r.Set(v)
46 case uint8:
47 r.SetUint64(uint64(v))
48 case uint16:
49 r.SetUint64(uint64(v))
50 case uint32:
51 r.SetUint64(uint64(v))
52 case uint64:
53 r.SetUint64(v)
54 case uint:
55 r.SetUint64(uint64(v))
56 case int8:
57 r.SetInt64(int64(v))
58 case int16:
59 r.SetInt64(int64(v))
60 case int32:
61 r.SetInt64(int64(v))
62 case int64:
63 r.SetInt64(v)
64 case int:
65 r.SetInt64(int64(v))
66 case string:
67 if _, ok := r.SetString(v, 0); !ok {
68 panic("unable to set big.Int from string " + v)
69 }
70 case []byte:
71 r.SetBytes(v)
72 default:
73 if v, ok := input.(toBigIntInterface); ok {
74 v.ToBigIntRegular(&r)
75 return r
76 } else if reflect.ValueOf(input).Kind() == reflect.Pointer {
77 vv := reflect.ValueOf(input)
78 if vv.CanInterface() {
79 if v, ok := vv.Interface().(toBigIntInterface); ok {
80 v.ToBigIntRegular(&r)
81 return r
82 }
83 }
84 }
85 panic(reflect.TypeOf(input).String() + " to big.Int not supported")
86 }
87
88 return r
89}

Callers 3

FromInterfaceMethod · 0.92
FromInterfaceMethod · 0.92
FromInterfaceMethod · 0.92

Calls 3

SetMethod · 0.80
ToBigIntRegularMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected