Skip to content

Commit

Permalink
fix: multiple incrementations for decrements in orchestration
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagarms committed Jul 8, 2024
1 parent f2be420 commit 1eda67f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ class BoilerplateGenerator {
${stateVarIds.join('\n')}
\nlet ${stateName}_preimage = await getCommitmentsById(${stateName}_stateVarId);
\n
${structProperties.map(sp => `let ${stateName}_${sp}_newCommitmentValue = generalise(0);\n`).join('')}
`];
return [`
\n\n// read preimage for decremented state
\n${stateName}_newOwnerPublicKey = ${newOwnerStatment}
${stateVarIds.join('\n')}
\nlet ${stateName}_preimage = await getCommitmentsById(${stateName}_stateVarId);
\n` ];
\n
let ${stateName}_newCommitmentValue = generalise(0);` ];
case 'whole':
switch (reinitialisedOnly) {
case true:
Expand Down
8 changes: 8 additions & 0 deletions src/codeGenerators/orchestration/nodejs/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ export default function codeGenerator(node: any, options: any = {}): any {
increments = codeGenerator(node.expression.rightHandSide);
return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) + ${increments});\n`;
}
if (node.expression.operator === '-='){
increments = codeGenerator(node.expression.rightHandSide);
return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) + (${increments}));\n`;
}
if (node.expression.operator === '='){
increments = codeGenerator(node.expression.rightHandSide);
if (node.decrementsSecretState){
increments = increments.replace(new RegExp(`${privateStateName}.integer`, 'g'), `0`);
return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) - (${increments}));\n`;
}
increments = increments.replace(new RegExp(privateStateName, 'g'), `${privateStateName}_newCommitmentValue`);
return `\n${privateStateName}_newCommitmentValue = generalise(${increments});\n`;
}
Expand Down
3 changes: 2 additions & 1 deletion test/contracts/KnownUnknown.zol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ contract Assign {
}

function remove( uint256 value ) public {
unknown b -= value +a;
unknown b = b - value +a;
unknown b = b - (value +a);
unknown x.prop1 -= value + a;
unknown x.prop2 -= value;
unknown b -= value;
Expand Down

0 comments on commit 1eda67f

Please sign in to comment.