Skip to content

Commit

Permalink
fix: multiple incrementations for some variable in circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagarms committed Jul 5, 2024
1 parent 06addb4 commit 32568d8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/boilerplate/circuit/zokrates/nodes/BoilerplateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ const collectIncrements = (bpg: BoilerplateGenerator) => {
if (inc.nodeType === 'MemberAccess') inc.name ??= `${inc.expression.name}.${inc.memberName}`;
if (!inc.name) inc.name = inc.value;
let modName = inc.modName ? inc.modName : inc.name;
if (incrementsArray.some(existingInc => inc.name === existingInc.name))
if (incrementsArray.some(existingInc => inc.name === existingInc.name && inc.id === existingInc.id))
continue;
incrementsArray.push({
name: inc.name,
precedingOperator: inc.precedingOperator,
});

if (counter != inc.counter) {
incrementsString[inc.counter] += `${modName}`;
if (counter !== inc.counter) {
incrementsString[inc.counter] = `${modName}`;
} else {
incrementsString[inc.counter] += ` ${inc.precedingOperator} ${modName}`;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ const collectIncrements = (bpg: BoilerplateGenerator) => {
});

if (counter != dec.counter) {
incrementsString[dec.counter + incCounter] += `${modName}`;
incrementsString[dec.counter + incCounter] = `${modName}`;
} else {
// if we have decrements, this str represents the value we must take away
// => it's a positive value with +'s
Expand Down
3 changes: 1 addition & 2 deletions src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,9 @@ class BoilerplateGenerator {
importStatements(): string[] {
return []; // TODO: we might eventually import some underflow/overflow functions.
},

statements({ name: x, addend, newCommitmentValue, structProperties, memberName}): string[] {
if (structProperties) {
return [`${x}.${memberName} = ${x}.${memberName} + ${newCommitmentValue[memberName]}`]
return [`${x}.${memberName} = ${x}.${memberName} + ${newCommitmentValue}`]
}
return [`${x} = ${x} + ${newCommitmentValue}`];
//return [
Expand Down
7 changes: 7 additions & 0 deletions src/codeGenerators/circuit/zokrates/toCircuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ function codeGenerator(node: any) {
return Circuitbp.generateBoilerplate(node);

case 'BoilerplateStatement': {
let newComValue = '';
if (node.bpType === 'incrementation') newComValue = codeGenerator(node.addend);
if (node.bpType === 'decrementation') newComValue = codeGenerator(node.subtrahend);
console.log(node.newCommitmentValue);
console.log(node.addend);
console.log(newComValue);
node.newCommitmentValue = newComValue;
return Circuitbp.generateBoilerplate(node);
}

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/KnownUnknown.zol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract Assign {
unknown x.prop1 += value + a;
unknown x.prop2 += value;
unknown b += value;
unknown x.prop1 += value ;
unknown x.prop1 += value;
a+= value;
}

Expand Down

0 comments on commit 32568d8

Please sign in to comment.