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

Function applyCircuit

ecgo/test/eval.go:95–134  ·  view source on GitHub ↗
(rc *layered.RootCircuit, circuit *layered.Circuit, cur []*big.Int, next []*big.Int, publicInput []*big.Int)

Source from the content-addressed store, hash-verified

93}
94
95func applyCircuit(rc *layered.RootCircuit, circuit *layered.Circuit, cur []*big.Int, next []*big.Int, publicInput []*big.Int) {
96 tmp := big.NewInt(0)
97 for _, m := range circuit.Mul {
98 coef := sampleCoef(m.Coef, m.CoefType, m.PublicInputId, publicInput)
99 tmp.Mul(cur[m.In0], cur[m.In1])
100 next[m.Out].Add(next[m.Out], tmp.Mul(tmp, coef))
101 }
102 for _, a := range circuit.Add {
103 coef := sampleCoef(a.Coef, a.CoefType, a.PublicInputId, publicInput)
104 next[a.Out].Add(next[a.Out], tmp.Mul(cur[a.In], coef))
105 }
106 for _, c := range circuit.Cst {
107 coef := sampleCoef(c.Coef, c.CoefType, c.PublicInputId, publicInput)
108 next[c.Out].Add(next[c.Out], coef)
109 }
110 for _, ct := range circuit.Custom {
111 inB := make([]*big.Int, len(ct.In))
112 outB := []*big.Int{big.NewInt(0)}
113 for i, e := range ct.In {
114 inB[i] = cur[e]
115 }
116 hintFunc := customgates.GetFunc(ct.GateType)
117 err := hintFunc(rc.Field, inB, outB)
118 if err != nil {
119 panic(err)
120 }
121 coef := sampleCoef(ct.Coef, ct.CoefType, ct.PublicInputId, publicInput)
122 next[ct.Out].Add(next[ct.Out], tmp.Mul(outB[0], coef))
123 }
124 for _, sub := range circuit.SubCircuits {
125 sc := rc.Circuits[sub.Id]
126 for _, alloc := range sub.Allocations {
127 applyCircuit(rc, sc,
128 cur[alloc.InputOffset:alloc.InputOffset+sc.InputLen],
129 next[alloc.OutputOffset:alloc.OutputOffset+sc.OutputLen],
130 publicInput,
131 )
132 }
133 }
134}

Callers 1

evalCircuitFunction · 0.85

Calls 4

GetFuncFunction · 0.92
sampleCoefFunction · 0.85
MulMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected