From fb60b1d9892fda5b1842fb80b0e4f6f559182e63 Mon Sep 17 00:00:00 2001 From: Swati Rawal Date: Thu, 4 Apr 2024 11:16:43 +0100 Subject: [PATCH] chore: added a fix for a bug --- .../javascript/nodes/boilerplate-generator.ts | 3 ++- .../orchestration/javascript/raw/boilerplate-generator.ts | 7 ++++--- .../orchestration/javascript/raw/toOrchestration.ts | 6 +++--- src/transformers/visitors/toOrchestrationVisitor.ts | 3 +++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/boilerplate/orchestration/javascript/nodes/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/nodes/boilerplate-generator.ts index 0eee30a5b..be6447d86 100644 --- a/src/boilerplate/orchestration/javascript/nodes/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/nodes/boilerplate-generator.ts @@ -52,7 +52,7 @@ export function buildPrivateStateNode(nodeType: string, fields: any = {}): any { }; } case 'WritePreimage': { - const { id, increment, burnedOnly, indicator = {} } = fields; + const { id, increment, burnedOnly, reinitialisedOnly, indicator = {} } = fields return { increment, stateVarId: id, @@ -64,6 +64,7 @@ export function buildPrivateStateNode(nodeType: string, fields: any = {}): any { mappingName: indicator.isMapping ? indicator.node?.name : null, nullifierRequired: indicator.isNullified, burnedOnly, + reinitialisedOnly, isOwned: indicator.isOwned, mappingOwnershipType: indicator.mappingOwnershipType, owner: indicator.isOwned diff --git a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts index 4b4407a2a..20ea44dd9 100644 --- a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts @@ -2,7 +2,7 @@ // Q: how are we merging mapping key and ownerPK in edge case? // Q: should we reduce constraints a mapping's commitment's preimage by not having the extra inner hash? Not at the moment, because it adds complexity to transpilation. -import fs from 'fs'; +import fs, { stat } from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; @@ -474,8 +474,9 @@ sendTransaction = { mappingName, mappingKey, burnedOnly, - structProperties, reinitialisedOnly, + structProperties, + }): string[] { let value; switch (stateType) { @@ -521,7 +522,7 @@ sendTransaction = { default: value = structProperties ? `{ ${structProperties.map(p => `${p}: ${stateName}.${p}`)} }` : `${stateName}`; return [` - \n${reinitialisedOnly? ' ': `if (${stateName}_commitmentExists) await markNullified(${stateName}_currentCommitment, secretKey.hex(32));`} + \n${reinitialisedOnly ? ' ': `if (${stateName}_commitmentExists) await markNullified(${stateName}_currentCommitment, secretKey.hex(32));`} \nawait storeCommitment({ hash: ${stateName}_newCommitment, name: '${mappingName}', diff --git a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts index 58fd08d51..afc62b762 100644 --- a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts +++ b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts @@ -155,7 +155,6 @@ export const generateProofBoilerplate = (node: any) => { }); // then we build boilerplate code per state - console.log(stateNode); switch (stateNode.isWhole) { case true: output.push( @@ -596,7 +595,7 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { : ``, burnedOnly: false, structProperties: stateNode.structProperties, - reinitialisedOnly: stateNode.reinitialisedOnly, + reinitialisedOnly: false, })); break; @@ -631,8 +630,9 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { ? `${stateName}_stateVarId_key.integer` : ``, burnedOnly: stateNode.burnedOnly, - structProperties: stateNode.structProperties, reinitialisedOnly: stateNode.reinitialisedOnly, + structProperties: stateNode.structProperties, + })); } } diff --git a/src/transformers/visitors/toOrchestrationVisitor.ts b/src/transformers/visitors/toOrchestrationVisitor.ts index e13337f3d..abbd02a33 100644 --- a/src/transformers/visitors/toOrchestrationVisitor.ts +++ b/src/transformers/visitors/toOrchestrationVisitor.ts @@ -567,9 +567,12 @@ const visitor = { burnedOnly: stateVarIndicator.isBurned && !stateVarIndicator.newCommitmentsRequired, + reinitialisedOnly: stateVarIndicator.reinitialisable && + !stateVarIndicator.isNullified, }); } } + if (node.kind === 'constructor') { newNodes.writePreimageNode.isConstructor = true;