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

Function serializeInstruction

ecgo/irsource/serialize.go:8–63  ·  view source on GitHub ↗
(o *utils.OutputBuf, i *Instruction, field field.Field)

Source from the content-addressed store, hash-verified

6)
7
8func serializeInstruction(o *utils.OutputBuf, i *Instruction, field field.Field) {
9 o.AppendUint8(uint8(i.Type))
10 switch i.Type {
11 case LinComb:
12 if len(i.Inputs) != len(i.LinCombCoef) {
13 panic("gg")
14 }
15 o.AppendUint64(uint64(len(i.Inputs)))
16 for _, x := range i.Inputs {
17 o.AppendUint64(uint64(x))
18 }
19 for _, x := range i.LinCombCoef {
20 o.AppendFieldElement(field, x)
21 }
22 o.AppendFieldElement(field, i.Const)
23 case Mul:
24 o.AppendIntSlice(i.Inputs)
25 case Div:
26 o.AppendUint64(uint64(i.X))
27 o.AppendUint64(uint64(i.Y))
28 o.AppendUint8(uint8(i.ExtraId))
29 case BoolBinOp:
30 o.AppendUint64(uint64(i.X))
31 o.AppendUint64(uint64(i.Y))
32 o.AppendUint8(uint8(i.ExtraId))
33 case IsZero:
34 o.AppendUint64(uint64(i.X))
35 case Commit:
36 o.AppendIntSlice(i.Inputs)
37 case Hint:
38 o.AppendUint64(uint64(i.ExtraId))
39 o.AppendIntSlice(i.Inputs)
40 o.AppendUint64(uint64(i.NumOutputs))
41 case ConstantLike:
42 if i.ExtraId == 0 {
43 o.AppendUint8(1)
44 o.AppendFieldElement(field, i.Const)
45 } else if i.ExtraId == 1 {
46 o.AppendUint8(2)
47 } else {
48 o.AppendUint8(3)
49 o.AppendUint64(uint64(i.ExtraId) - 2)
50 }
51 case SubCircuitCall:
52 o.AppendUint64(uint64(i.ExtraId))
53 o.AppendIntSlice(i.Inputs)
54 o.AppendUint64(uint64(i.NumOutputs))
55 case UnconstrainedBinOp:
56 panic("no unconstrained binop in gnark")
57 case UnconstrainedSelect:
58 panic("no unconstrained select in gnark")
59 case CustomGate:
60 o.AppendUint64(uint64(i.ExtraId))
61 o.AppendIntSlice(i.Inputs)
62 }
63}
64
65func serializeCircuit(o *utils.OutputBuf, c *Circuit, field field.Field) {

Callers 1

serializeCircuitFunction · 0.70

Calls 4

AppendUint8Method · 0.80
AppendUint64Method · 0.80
AppendFieldElementMethod · 0.80
AppendIntSliceMethod · 0.80

Tested by

no test coverage detected