From 0ae4fc3eefb0e911d3097f78046de75724b36745 Mon Sep 17 00:00:00 2001 From: Swati Rawal Date: Thu, 29 Aug 2024 08:06:13 +0100 Subject: [PATCH] chore: fixed secret call --- src/codeGenerators/circuit/zokrates/toCircuit.ts | 5 ++++- .../visitors/orchestrationInternalFunctionCallVisitor.ts | 6 ++++-- src/transformers/visitors/toCircuitVisitor.ts | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/codeGenerators/circuit/zokrates/toCircuit.ts b/src/codeGenerators/circuit/zokrates/toCircuit.ts index 39f9ab33..e100c9bb 100644 --- a/src/codeGenerators/circuit/zokrates/toCircuit.ts +++ b/src/codeGenerators/circuit/zokrates/toCircuit.ts @@ -160,7 +160,10 @@ function codeGenerator(node: any) { case 'VariableDeclarationStatement': { const declarations = node.declarations.map(codeGenerator).join(', '); if (!node.initialValue) return `${declarations} = ${node.declarations.map(n => n.typeName.name === 'bool' ? 'false' : 0)}`; - if(node.initialValue.nodeType === 'InternalFunctionCall') return `${declarations} = ${node.initialValue.name}`; + if(node.initialValue.nodeType === 'InternalFunctionCall'){ + if(!declarations) return ; + return `${declarations} = ${node.initialValue.name}`; + } const initialValue = codeGenerator(node.initialValue); return `${declarations} = ${initialValue}`; diff --git a/src/transformers/visitors/orchestrationInternalFunctionCallVisitor.ts b/src/transformers/visitors/orchestrationInternalFunctionCallVisitor.ts index 006af636..c7cf9288 100644 --- a/src/transformers/visitors/orchestrationInternalFunctionCallVisitor.ts +++ b/src/transformers/visitors/orchestrationInternalFunctionCallVisitor.ts @@ -432,7 +432,7 @@ const internalCallVisitor = { }); }); node.privateStates = Object.assign(node.privateStates,generateProofNode.privateStates); - node.parameters = [...new Set([...node.parameters ,...generateProofNode.parameters])]; + node.parameters = [...new Set([...node.parameters ,...generateProofNode.parameters, ...state.returnPara])]; break; } case 'SendTransaction': { @@ -527,11 +527,13 @@ FunctionCall: { decNode.declarations[0].isAccessed = true; decNode.declarations[0].interactsWithSecret = true; callingfnDefPath.node._newASTPointer.body.preStatements.splice(1,0,decNode); - const returnPara = functionReferncedNode.node.returnParameters.parameters[0].name; + const returnPara = functionReferncedNode.node.returnParameters.parameters[0].name; newNode = buildNode('InternalFunctionCall', { name: returnPara, internalFunctionInteractsWithSecret: internalFunctionInteractsWithSecret, }); + console.log(parent) + parent.interactsWithSecret ? state.returnPara = returnPara : ' '; const functionParams = callingfnDefPath.node._newASTPointer.body.preStatements; // console.log(functionParams); diff --git a/src/transformers/visitors/toCircuitVisitor.ts b/src/transformers/visitors/toCircuitVisitor.ts index 84c5e4d0..fe0e9df5 100644 --- a/src/transformers/visitors/toCircuitVisitor.ts +++ b/src/transformers/visitors/toCircuitVisitor.ts @@ -1587,12 +1587,13 @@ if(parent.nodeType === 'VariableDeclarationStatement') { name: returnPara, internalFunctionInteractsWithSecret: internalFunctionInteractsWithSecret, // return }); + if(parent._newASTPointer.declarations.length > 0){ const functionParams = callingfnDefPath.node._newASTPointer.parameters.parameters.map(param => param.name); if(!functionParams.includes(returnPara)){ callingfnDefPath.node._newASTPointer.parameters.parameters.push(functionReferncedNode.node.returnParameters.parameters[0]._newASTPointer); callingfnDefPath.node._newASTPointer.parameters.parameters[functionParams.length].declarationType = 'parameter'; callingfnDefPath.node._newASTPointer.parameters.parameters[functionParams.length].interactsWithSecret = true; - } + }} } else { newNode = buildNode('InternalFunctionCall', {