Skip to content

Commit

Permalink
fix: allow for multiple increments for structs
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagarms committed Jul 8, 2024
1 parent 1f65c4c commit f2be420
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class BoilerplateGenerator {
${stateName}_newOwnerPublicKey = ${newOwnerStatment}
${stateVarIds.join('\n')}
\n
${structProperties.map(sp => `let ${stateName}_${sp}_newCommitmentValue = generalise(0);\n`).join('')}
`];
return [`
\n\n// read preimage for incremented state
Expand Down
18 changes: 10 additions & 8 deletions src/codeGenerators/orchestration/nodejs/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ export default function codeGenerator(node: any, options: any = {}): any {

if (node.incrementsSecretState && (node.interactsWithSecret || node.expression?.internalFunctionInteractsWithSecret)){
let privateStateName = node.privateStateName.replace(/\./g, '_');
let increments = codeGenerator(node.expression.rightHandSide);
if (typeof node.increments === 'object' && node.increments !== null) {
if (node.expression.leftHandSide.nodeType === 'MemberAccess'){
let propName = node.expression.leftHandSide.memberName;
return `\n${privateStateName}_newCommitmentValue = generalise(${node.increments[propName]});\n`;
}
};
return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) + ${increments});\n`;
let increments;
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);
increments = increments.replace(new RegExp(privateStateName, 'g'), `${privateStateName}_newCommitmentValue`);
return `\n${privateStateName}_newCommitmentValue = generalise(${increments});\n`;
}
}

if (!node.interactsWithSecret)
Expand Down
4 changes: 2 additions & 2 deletions test/contracts/KnownUnknown.zol
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ contract Assign {


function add( uint256 value ) public {
unknown b += value +a;
unknown b = b + value +a;
unknown x.prop1 += value + a;
unknown x.prop2 += value;
unknown b += value;
unknown x.prop1 += value;
unknown x.prop1 += a;
a+= value;
}

Expand Down

0 comments on commit f2be420

Please sign in to comment.