From 1f65c4c847cc8928279751b3ec53d18e5879f39e Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Mon, 8 Jul 2024 11:57:27 +0100 Subject: [PATCH] fix: _ instead of . in circuit causing compilation error for SimpleStruct2 and for incremented non-structs alllow for multiple incrementations --- src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts | 2 +- .../orchestration/javascript/raw/boilerplate-generator.ts | 4 +++- src/codeGenerators/orchestration/nodejs/toOrchestration.ts | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts b/src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts index d4da9a91..a47ff293 100644 --- a/src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts +++ b/src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts @@ -376,7 +376,7 @@ class BoilerplateGenerator { } else { - lines.push(`${typeName} ${x}_newCommitment_value = ${typeName} { ${structProperties.map(p => ` ${p}: ${isWhole ? `${y}.${p}` : `${y}_${p}`}`)} }\n`); + lines.push(`${typeName} ${x}_newCommitment_value = ${typeName} { ${structProperties.map(p => ` ${p}: ${y}.${p}`)} }\n`); if (structPropertiesTypes) { structPropertiesTypes.forEach(property => { if (property.typeName === 'bool'){ diff --git a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts index 66c25cad..52b28fb5 100644 --- a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts @@ -119,7 +119,9 @@ class BoilerplateGenerator { \n\n// read preimage for incremented state ${stateName}_newOwnerPublicKey = ${newOwnerStatment} ${stateVarIds.join('\n')} - \n`]; + \n + let ${stateName}_newCommitmentValue = generalise(0); + `]; case 'decrement': if (structProperties) return [` diff --git a/src/codeGenerators/orchestration/nodejs/toOrchestration.ts b/src/codeGenerators/orchestration/nodejs/toOrchestration.ts index 78dadfc3..39f83510 100644 --- a/src/codeGenerators/orchestration/nodejs/toOrchestration.ts +++ b/src/codeGenerators/orchestration/nodejs/toOrchestration.ts @@ -126,13 +126,14 @@ 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 `\nconst ${privateStateName}_newCommitmentValue = generalise(${node.increments[propName]});\n`; + return `\n${privateStateName}_newCommitmentValue = generalise(${node.increments[propName]});\n`; } }; - return `\nconst ${privateStateName}_newCommitmentValue = generalise(${node.increments});\n`; + return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) + ${increments});\n`; } if (!node.interactsWithSecret)