diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 35c65d2..1d322fe 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,6 @@
-
-
@@ -18,8 +16,8 @@
-
-
+
+
@@ -27,8 +25,8 @@
-
-
+
+
@@ -45,29 +43,30 @@
-
+
-
+
-
-
+
+
-
+
+
-
+
-
-
+
+
@@ -75,8 +74,8 @@
-
-
+
+
@@ -85,10 +84,10 @@
-
+
-
-
+
+
@@ -131,6 +130,12 @@
new
newpro
clone
+ newProg
+ func
+ global
+ globalin
+ newcir
+ newprogr
mottla
@@ -152,7 +157,6 @@
-
@@ -160,12 +164,13 @@
-
-
+
-
+
+
+
@@ -192,6 +197,11 @@
+
+
+
+
+
@@ -279,60 +289,70 @@
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -342,22 +362,23 @@
-
+
+
-
+
-
-
+
+
-
-
+
+
@@ -401,7 +422,10 @@
-
+
+
+
+
@@ -453,78 +477,34 @@
file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 204
-
-
-
- file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 421
-
+ 514
+
file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 425
-
+ 218
+
file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 406
-
+ 298
+
file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 410
-
-
-
- file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 275
-
-
-
- file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 276
-
-
-
-
- file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 299
-
-
-
-
- file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 292
-
-
-
-
- file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 370
-
-
-
-
- file://$PROJECT_DIR$/circuitcompiler/Programm.go
- 380
-
-
+ 325
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
@@ -669,13 +649,6 @@
-
-
-
-
-
-
-
@@ -725,10 +698,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -739,20 +740,27 @@
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
@@ -776,34 +784,21 @@
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
diff --git a/circuitcompiler/Programm.go b/circuitcompiler/Programm.go
index 2fa8c41..ccd6e13 100644
--- a/circuitcompiler/Programm.go
+++ b/circuitcompiler/Programm.go
@@ -17,7 +17,7 @@ type utils struct {
type Program struct {
functions map[string]*Circuit
- globalInputs []Constraint
+ globalInputs []string
arithmeticEnvironment utils //find a better name
R1CS struct {
@@ -45,6 +45,10 @@ func (p *Program) BuildConstraintTrees() {
p.getMainCircuit().gateMap[mainRoot.value.Out] = mainRoot
}
+ for _, in := range p.getMainCircuit().Inputs {
+ p.globalInputs = append(p.globalInputs, composeNewFunction(in, p.getMainCircuit().Inputs))
+ }
+
var wg = sync.WaitGroup{}
for _, circuit := range p.functions {
@@ -103,39 +107,35 @@ func (p *Program) ReduceCombinedTree() (orderedmGates []gate) {
return orderedmGates
}
-func (p *Program) r1CSRecursiveBuild(currentCircuit *Circuit, root *gate, mGatesUsed map[string]bool, orderedmGates *[]gate, negate bool, inverse bool) (isConstant bool) {
+func (p *Program) r1CSRecursiveBuild(currentCircuit *Circuit, root *gate, mGatesUsed map[string]bool, orderedmGates *[]gate, negate bool, inverse bool) (variableEnd bool) {
if root.OperationType() == IN {
- return false
- }
-
- if root.OperationType() == CONST {
return true
}
- if _, alreadyComputed := mGatesUsed[root.value.Out]; alreadyComputed {
+ if root.OperationType() == CONST {
return false
}
if root.OperationType() == FUNC {
nextContext := p.extendedFunctionRenamer(currentCircuit, root.value)
- isConstant = p.r1CSRecursiveBuild(nextContext, nextContext.root, mGatesUsed, orderedmGates, negate, inverse)
- return isConstant
+ currentCircuit = nextContext
+ root = nextContext.root
}
- if _, alreadyComputed := mGatesUsed[root.value.V1]; !alreadyComputed {
- isConstant = p.r1CSRecursiveBuild(currentCircuit, root.left, mGatesUsed, orderedmGates, negate, inverse)
+ originOfVariable := p.functions[getContextFromVariable(root.value.Out)]
+ if _, alreadyComputed := mGatesUsed[composeNewFunction(root.value.Out, originOfVariable.currentOutputs())]; alreadyComputed {
+ return true
}
- if _, alreadyComputed := mGatesUsed[root.value.V2]; !alreadyComputed {
- cons := p.r1CSRecursiveBuild(currentCircuit, root.right, mGatesUsed, orderedmGates, Xor(negate, root.value.negate), Xor(inverse, root.value.invert))
- isConstant = isConstant || cons
- }
+ variableEnd = p.r1CSRecursiveBuild(currentCircuit, root.left, mGatesUsed, orderedmGates, negate, inverse)
+
+ cons := p.r1CSRecursiveBuild(currentCircuit, root.right, mGatesUsed, orderedmGates, Xor(negate, root.value.negate), Xor(inverse, root.value.invert))
if root.OperationType() == MULTIPLY {
- if isConstant && !root.value.invert && root != p.getMainCircuit().root {
- return false
+ if !(variableEnd && cons) && !root.value.invert && root != p.getMainCircuit().root {
+ return variableEnd || cons
}
root.leftIns = p.collectFactors(currentCircuit, root.left, mGatesUsed, false, false)
//if root.left.value.Out== root.right.value.Out{
@@ -147,19 +147,21 @@ func (p *Program) r1CSRecursiveBuild(currentCircuit *Circuit, root *gate, mGates
//root.rightIns = collectAtomsInSubtree3(root.right, mGatesUsed, Xor(negate, root.value.negate), Xor(inverse, root.value.invert))
root.rightIns = p.collectFactors(currentCircuit, root.right, mGatesUsed, false, false)
root.index = len(mGatesUsed)
- var nn = root.value.Out
- //if _, ex := p.functions[nn]; ex {
- // nn = composeNewFunction(root.value.Out, currentCircuit.Inputs)
+ var nn = composeNewFunction(root.value.Out, originOfVariable.currentOutputs())
+ //var nn = root.value.Out
+ //if _, ex := p.functions[root.value.Out]; ex {
+ // nn = currentCircuit.currentOutputName()
//}
-
+ if _, ex := mGatesUsed[nn]; ex {
+ panic(fmt.Sprintf("told ya so %v", nn))
+ }
mGatesUsed[nn] = true
rootGate := cloneGate(root)
rootGate.value.Out = nn
*orderedmGates = append(*orderedmGates, *rootGate)
-
}
- return isConstant
+ return variableEnd || cons
//TODO optimize if output is not a multipication gate
}
@@ -211,11 +213,18 @@ func mulFactors(leftFactors, rightFactors []factor) (result []factor) {
//this one should only be reached, after a true mgate had its left and right braches computed. here we
//a factor can appear at most in quadratic form. we reduce terms a*a^-1 here.
if facRight.typ&facLeft.typ == IN {
- //if facRight.n
+ if facLeft.name == facRight.name {
+ if facRight.invert != facLeft.invert {
+ rightFactors[i] = factor{typ: CONST, negate: Xor(facRight.negate, facLeft.negate), multiplicative: mul2DVector(facRight.multiplicative, facLeft.multiplicative)}
+ continue
+ }
+ }
+
//rightFactors[i] = factor{typ: CONST, negate: Xor(facRight.negate, facLeft.negate), multiplicative: mul2DVector(facRight.multiplicative, facLeft.multiplicative)}
//continue
}
+ fmt.Println("dsf")
panic("unexpected")
}
@@ -289,22 +298,10 @@ func addFactors(leftFactors, rightFactors []factor) []factor {
return res
}
-func (p *Program) collectFactors(contextCircut *Circuit, g *gate, mGatesUsed map[string]bool, negate bool, invert bool) []factor {
-
- if _, ex := mGatesUsed[g.value.Out]; ex {
- return []factor{{typ: IN, name: g.value.Out, invert: invert, negate: negate, multiplicative: [2]int{1, 1}}}
- }
+func (p *Program) collectFactors(contextCircut *Circuit, node *gate, mGatesUsed map[string]bool, negate bool, invert bool) []factor {
- if g.OperationType() == IN {
- return []factor{{typ: IN, name: g.value.Out, invert: invert, negate: negate, multiplicative: [2]int{1, 1}}}
- }
- if g.OperationType() == FUNC {
- nextContext := p.extendedFunctionRenamer(contextCircut, g.value)
- return p.collectFactors(nextContext, nextContext.root, mGatesUsed, negate, invert)
- }
-
- if g.OperationType() == CONST {
- b1, v1 := isValue(g.value.Out)
+ if node.OperationType() == CONST {
+ b1, v1 := isValue(node.value.Out)
if !b1 {
panic("not a constant")
}
@@ -314,22 +311,38 @@ func (p *Program) collectFactors(contextCircut *Circuit, g *gate, mGatesUsed map
return []factor{{typ: CONST, negate: negate, multiplicative: [2]int{v1, 1}}}
}
- var leftFactors, rightFactors []factor
- if g.left.OperationType() == FUNC {
- nextContext := p.extendedFunctionRenamer(contextCircut, g.left.value)
- leftFactors = p.collectFactors(nextContext, nextContext.root, mGatesUsed, negate, invert)
- } else {
- leftFactors = p.collectFactors(contextCircut, g.left, mGatesUsed, negate, invert)
+ if node.OperationType() == FUNC {
+ nextContext := p.extendedFunctionRenamer(contextCircut, node.value)
+
+ //if _, ex := mGatesUsed[nextContext.currentOutputName()]; ex {
+ // return []factor{{typ: IN, name: nextContext.currentOutputName(), invert: invert, negate: negate, multiplicative: [2]int{1, 1}}}
+ //}
+ contextCircut = nextContext
+ node = nextContext.root
}
- if g.right.OperationType() == FUNC {
- nextContext := p.extendedFunctionRenamer(contextCircut, g.right.value)
- rightFactors = p.collectFactors(nextContext, nextContext.root, mGatesUsed, Xor(negate, g.value.negate), Xor(invert, g.value.invert))
- } else {
- rightFactors = p.collectFactors(contextCircut, g.right, mGatesUsed, Xor(negate, g.value.negate), Xor(invert, g.value.invert))
+ originOfVariable := p.functions[getContextFromVariable(node.value.Out)]
+ if originOfVariable == nil {
+ fmt.Println("asdf")
+ }
+ lookingFOr := composeNewFunction(node.value.Out, originOfVariable.currentOutputs())
+
+ //if _, ex := mGatesUsed[node.value.Out]; ex {
+ // return []factor{{typ: IN, name: node.value.Out, invert: invert, negate: negate, multiplicative: [2]int{1, 1}}}
+ //}
+
+ if node.OperationType() == IN {
+ return []factor{{typ: IN, name: lookingFOr, invert: invert, negate: negate, multiplicative: [2]int{1, 1}}}
}
- switch g.OperationType() {
+ if _, alreadyComputed := mGatesUsed[lookingFOr]; alreadyComputed {
+ return []factor{{typ: IN, name: lookingFOr, invert: invert, negate: negate, multiplicative: [2]int{1, 1}}}
+ }
+
+ leftFactors := p.collectFactors(contextCircut, node.left, mGatesUsed, negate, invert)
+ rightFactors := p.collectFactors(contextCircut, node.right, mGatesUsed, Xor(negate, node.value.negate), Xor(invert, node.value.invert))
+
+ switch node.OperationType() {
case MULTIPLY:
return mulFactors(leftFactors, rightFactors)
case PLUS:
@@ -358,10 +371,10 @@ func (p *Program) getMainCircuit() *Circuit {
return p.functions["main"]
}
-func (p *Program) addGlobalInput(c Constraint) {
- c.Out = "main@" + c.Out
- p.globalInputs = append(p.globalInputs, c)
-}
+//func (p *Program) addGlobalInput(c Constraint) {
+// c.Out = "main@" + c.Out
+// p.globalInputs = append(p.globalInputs, c)
+//}
func prepareUtils() utils {
bn, err := bn128.NewBn128()
@@ -388,46 +401,51 @@ func (p *Program) extendedFunctionRenamer(contextCircuit *Circuit, constraint *C
//if _, ex := contextCircuit.gateMap[constraint.Out]; !ex {
// panic("constraint must be within the contextCircuit circuit")
//}
- if b, n, _ := isFunction(constraint.Out); b {
- if newContext, v := p.functions[n]; v {
- //am i certain that constraint.inputs is alwazs equal to n??? me dont like it
- for i, argument := range constraint.Inputs {
- isConst, _ := isValue(argument)
- if isConst {
- continue
- }
- isFunc, _, _ := isFunction(argument)
- if isFunc {
- panic("functions as arguments no supported yet")
- //p.extendedFunctionRenamer(contextCircuit,)
- }
- //at this point I assert that argument is a variable. This can become troublesome later
- inputOriginCircuit := p.functions[getContextFromVariable(argument)]
- if gate, ex := inputOriginCircuit.gateMap[argument]; ex {
- oldGate := newContext.gateMap[newContext.Inputs[i]]
- //we take the old gate which was nothing but a input
- //and link this input to its constituents comming from the calling contextCircuit.
- //i think this is pretty neat
- oldGate.value = gate.value
- oldGate.right = gate.right
- oldGate.left = gate.left
-
- } else {
- panic("not expected")
- }
+ b, n, _ := isFunction(constraint.Out)
+ if !b {
+ panic("not expected")
+ }
+ if newContext, v := p.functions[n]; v {
+ //am i certain that constraint.inputs is alwazs equal to n??? me dont like it
+ for i, argument := range constraint.Inputs {
+
+ isConst, _ := isValue(argument)
+ if isConst {
+ continue
+ }
+ isFunc, _, _ := isFunction(argument)
+ if isFunc {
+ panic("functions as arguments no supported yet")
+ //p.extendedFunctionRenamer(contextCircuit,)
+ }
+ //at this point I assert that argument is a variable. This can become troublesome later
+ //first we get the circuit in which the argument was created
+ inputOriginCircuit := p.functions[getContextFromVariable(argument)]
+
+ //we pick the gate that has the argument as output
+ if gate, ex := inputOriginCircuit.gateMap[argument]; ex {
+ //we pick the old circuit inputs and let them now reference the same as the argument gate did,
+ oldGate := newContext.gateMap[newContext.Inputs[i]]
+ //we take the old gate which was nothing but a input
+ //and link this input to its constituents coming from the calling contextCircuit.
+ //i think this is pretty neat
+ oldGate.value = gate.value
+ oldGate.right = gate.right
+ oldGate.left = gate.left
+
+ } else {
+ panic("not expected")
}
- newContext.renameInputs(constraint.Inputs)
- return newContext
}
- } else {
- panic("not expected")
+ //newContext.renameInputs(constraint.Inputs)
+ return newContext
}
return nil
}
func NewProgram() (p *Program) {
- p = &Program{functions: map[string]*Circuit{}, globalInputs: []Constraint{{Op: IN, Out: "one"}}, arithmeticEnvironment: prepareUtils()}
+ p = &Program{functions: map[string]*Circuit{}, globalInputs: []string{"one"}, arithmeticEnvironment: prepareUtils()}
return
}
@@ -441,7 +459,7 @@ func (p *Program) GenerateReducedR1CS(mGates []gate) (a, b, c [][]*big.Int) {
indexMap := make(map[string]int)
for i, v := range p.globalInputs {
- indexMap[v.Out] = i
+ indexMap[v] = i
}
for i, v := range mGates {
@@ -456,10 +474,21 @@ func (p *Program) GenerateReducedR1CS(mGates []gate) (a, b, c [][]*big.Int) {
cConstraint := r1csqap.ArrayOfBigZeros(size)
for _, val := range gate.leftIns {
+ if val.typ != CONST {
+ if _, ex := indexMap[val.name]; !ex {
+ panic(fmt.Sprintf("%v index not found!!!", val.name))
+ }
+ }
convertAndInsertFactorAt(aConstraint, val, indexMap[val.name])
}
for _, val := range gate.rightIns {
+ if val.typ != CONST {
+ if _, ex := indexMap[val.name]; !ex {
+ panic(fmt.Sprintf("%v index not found!!!", val.name))
+ }
+ }
+
convertAndInsertFactorAt(bConstraint, val, indexMap[val.name])
}
@@ -498,11 +527,8 @@ func convertAndInsertFactorAt(arr []*big.Int, val factor, index int) {
value.Neg(value)
}
- if val.typ == CONST {
- arr[0] = value
- } else {
- arr[index] = value
- }
+ //not that index is 0 if its a constant, since 0 is the map default if no entry was found
+ arr[index] = value
}
diff --git a/circuitcompiler/Programm_test.go b/circuitcompiler/Programm_test.go
index 54cda80..4e8c43c 100644
--- a/circuitcompiler/Programm_test.go
+++ b/circuitcompiler/Programm_test.go
@@ -14,37 +14,48 @@ func TestProgramm_BuildConstraintTree(t *testing.T) {
}
func TestNewProgramm(t *testing.T) {
-
//flat := `
- //func do(x):
- // e = x * 5
- // b = e * 6
- // c = b * 7
- // f = c * 1
- // d = c * f
- // out = d * mul(d,e)
//
- //func add(x ,k):
+ //def add(x ,k):
// z = k * x
- // out = do(x) + mul(x,z)
+ // out = 6 + mul(x,z)
//
- //func main(x,z):
- // out = do(z) + add(x,x)
+ //def main(x,z):
+ // out = mul(x,z) - add(x,x)
//
- //func mul(a,b):
+ //def mul(a,b):
// out = a * b
//`
flat := `
- func mul(a,b):
- out = a * b
+ def do(x):
+ e = x * 5
+ b = e * 6
+ c = b * 7
+ f = c * 1
+ d = c * f
+ out = d * mul(d,e)
- func main(a):
- b = a * a
- c = 4 - b
- d = 5 * c
- out = mul(d,b) / mul(b,b)
+ def add(x ,k):
+ z = k * x
+ out = do(x) + mul(x,z)
+
+ def main(x,z):
+ out = do(z) + add(x,x)
+
+ def mul(a,b):
+ out = a * b
`
//flat := `
+ //func mul(a,b):
+ // out = a * b
+ //
+ //func main(a,aa):
+ // b = a * a
+ // c = 4 - b
+ // d = 5 * c
+ // out = mul(d,c) / mul(b,b)
+ //`
+ //flat := `
//func main(a,b):
// c = a + b
// e = c - a
@@ -52,6 +63,7 @@ func TestNewProgramm(t *testing.T) {
// g = f + 2
// out = g * a
//`
+
parser := NewParser(strings.NewReader(flat))
program, err := parser.Parse()
@@ -79,9 +91,9 @@ func TestNewProgramm(t *testing.T) {
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
- a1 := big.NewInt(int64(6))
- //a2 := big.NewInt(int64(5))
- inputs := []*big.Int{a1}
+ a1 := big.NewInt(int64(7))
+ a2 := big.NewInt(int64(11))
+ inputs := []*big.Int{a1, a2}
w := program.CalculateWitness(inputs)
fmt.Println("witness")
fmt.Println(w)
diff --git a/circuitcompiler/circuit.go b/circuitcompiler/circuit.go
index 93ef717..bb0d267 100644
--- a/circuitcompiler/circuit.go
+++ b/circuitcompiler/circuit.go
@@ -26,7 +26,6 @@ type gate struct {
left *gate
right *gate
funcInputs []*gate
- Op Token
value *Constraint //is a pointer a good thing here??
leftIns []factor //leftIns and RightIns after addition gates have been reduced. only multiplication gates remain
rightIns []factor
@@ -95,9 +94,9 @@ func (p *Program) addFunction(constraint *Constraint) (c *Circuit) {
Op: IN,
Out: in,
}
- if name == "main" {
- p.addGlobalInput(*newConstr)
- }
+ //if name == "main" {
+ // p.addGlobalInput(*newConstr)
+ //}
c.addConstraint(newConstr)
renamedInputs[i] = newConstr.Out
}
@@ -125,7 +124,7 @@ func (circ *Circuit) addConstraint(constraint *Constraint) {
//todo this is dangerous.. if someone would use out as variable name, things would be fucked
if constraint.Out == "out" {
- constraint.Out = composeNewFunction(circ.Name, circ.Inputs)
+ constraint.Out = circ.Name //composeNewFunction(circ.Name, circ.Inputs)
circ.root = gateToAdd
} else {
constraint.Out = circ.renamer(constraint.Out)
@@ -137,6 +136,25 @@ func (circ *Circuit) addConstraint(constraint *Constraint) {
circ.gateMap[constraint.Out] = gateToAdd
}
+func (circ *Circuit) currentOutputName() string {
+
+ return composeNewFunction(circ.Name, circ.currentOutputs())
+}
+
+func (circ *Circuit) currentOutputs() []string {
+
+ renamedInputs := make([]string, len(circ.Inputs))
+ for i, in := range circ.Inputs {
+ if _, ex := circ.gateMap[in]; !ex {
+ panic("not existing input")
+ }
+ renamedInputs[i] = circ.gateMap[in].value.Out
+ }
+
+ return renamedInputs
+
+}
+
func (circ *Circuit) renamer(constraint string) string {
if constraint == "" {
@@ -162,72 +180,73 @@ func (circ *Circuit) renamer(constraint string) string {
}
-func (circ *Circuit) renameInputs(inputs []string) {
- if len(inputs) != len(circ.Inputs) {
- panic("given inputs != circuit.Inputs")
- }
- mapping := make(map[string]string)
- for i := 0; i < len(inputs); i++ {
- if _, ex := circ.gateMap[inputs[i]]; ex {
-
- //this is a tricky part. So we replace former inputs with the new ones, thereby
- //it might be, that the new input name has already been used for some output inside the function
- //currently I dont know an elegant way how to handle this renaming issue
- if circ.gateMap[inputs[i]].value.Op != IN {
- panic(fmt.Sprintf("renaming collsion with %s", inputs[i]))
- }
-
- }
- mapping[circ.Inputs[i]] = inputs[i]
- }
- //fmt.Println(mapping)
- //circ.Inputs = inputs
- permute := func(in string) string {
- if out, ex := mapping[in]; ex {
- return out
- }
- return in
- }
-
- permuteListe := func(in []string) []string {
- for i := 0; i < len(in); i++ {
- in[i] = permute(in[i])
- }
- return in
- }
-
- for _, constraint := range circ.gateMap {
-
- if constraint.value.Op == IN {
- constraint.value.Out = permute(constraint.value.Out)
- continue
- }
-
- if b, n, in := isFunction(constraint.value.Out); b {
- constraint.value.Out = composeNewFunction(n, permuteListe(in))
- constraint.value.Inputs = permuteListe(in)
- }
- if b, n, in := isFunction(constraint.value.V1); b {
- constraint.value.V1 = composeNewFunction(n, permuteListe(in))
- constraint.value.Inputs = permuteListe(in)
- }
- if b, n, in := isFunction(constraint.value.V2); b {
- constraint.value.V2 = composeNewFunction(n, permuteListe(in))
- constraint.value.Inputs = permuteListe(in)
- }
-
- constraint.value.V1 = permute(constraint.value.V1)
- constraint.value.V2 = permute(constraint.value.V2)
-
- }
- return
-}
+//func (circ *Circuit) renameInputs(inputs []string) {
+// if len(inputs) != len(circ.Inputs) {
+// panic("given inputs != circuit.Inputs")
+// }
+// mapping := make(map[string]string)
+// for i := 0; i < len(inputs); i++ {
+// if _, ex := circ.gateMap[inputs[i]]; ex {
+//
+// //this is a tricky part. So we replace former inputs with the new ones, thereby
+// //it might be, that the new input name has already been used for some output inside the function
+// //currently I dont know an elegant way how to handle this renaming issue
+// if circ.gateMap[inputs[i]].value.Op != IN {
+// panic(fmt.Sprintf("renaming collsion with %s", inputs[i]))
+// }
+//
+// }
+// mapping[circ.Inputs[i]] = inputs[i]
+// }
+// //fmt.Println(mapping)
+// //circ.Inputs = inputs
+// permute := func(in string) string {
+// if out, ex := mapping[in]; ex {
+// return out
+// }
+// return in
+// }
+//
+// permuteListe := func(in []string) []string {
+// for i := 0; i < len(in); i++ {
+// in[i] = permute(in[i])
+// }
+// return in
+// }
+//
+// for _, constraint := range circ.gateMap {
+//
+// if constraint.value.Op == IN {
+// constraint.value.Out = permute(constraint.value.Out)
+// continue
+// }
+//
+// if b, n, in := isFunction(constraint.value.Out); b {
+// constraint.value.Out = composeNewFunction(n, permuteListe(in))
+// constraint.value.Inputs = permuteListe(in)
+// }
+// if b, n, in := isFunction(constraint.value.V1); b {
+// constraint.value.V1 = composeNewFunction(n, permuteListe(in))
+// constraint.value.Inputs = permuteListe(in)
+// }
+// if b, n, in := isFunction(constraint.value.V2); b {
+// constraint.value.V2 = composeNewFunction(n, permuteListe(in))
+// constraint.value.Inputs = permuteListe(in)
+// }
+//
+// constraint.value.V1 = permute(constraint.value.V1)
+// constraint.value.V2 = permute(constraint.value.V2)
+//
+// }
+// return
+//}
func getContextFromVariable(in string) string {
- if strings.Contains(in, variableIndicationSign) {
- return strings.Split(in, variableIndicationSign)[0]
- }
- return ""
+ //if strings.Contains(in, variableIndicationSign) {
+ // return strings.Split(in, variableIndicationSign)[0]
+ //}
+ //return ""
+ return strings.Split(in, variableIndicationSign)[0]
}
func composeNewFunction(fname string, inputs []string) string {
diff --git a/circuitcompiler/lexer.go b/circuitcompiler/lexer.go
index 94abd92..5852fb5 100644
--- a/circuitcompiler/lexer.go
+++ b/circuitcompiler/lexer.go
@@ -42,7 +42,7 @@ func (ch Token) String() string {
case EXP:
return "^"
case FUNC:
- return "func"
+ return "def"
case IN:
return "In"
case CONST:
diff --git a/circuitcompiler/parser.go b/circuitcompiler/parser.go
index 3905684..4fb434b 100644
--- a/circuitcompiler/parser.go
+++ b/circuitcompiler/parser.go
@@ -58,7 +58,7 @@ func (p *Parser) parseLine() (*Constraint, error) {
c := &Constraint{}
tok, lit := p.scanIgnoreWhitespace()
switch lit {
- case "func":
+ case "def":
c.Op = FUNC
// format: `func name(in):`
//todo this is all a bit hacky and unsafe