diff --git a/src/transformers/visitors/circuitInternalFunctionCallVisitor.ts b/src/transformers/visitors/circuitInternalFunctionCallVisitor.ts index 44f5fb59..11cf48e9 100644 --- a/src/transformers/visitors/circuitInternalFunctionCallVisitor.ts +++ b/src/transformers/visitors/circuitInternalFunctionCallVisitor.ts @@ -114,6 +114,8 @@ const internalCallVisitor = { if(state.newStateArray[name][id].memberName) state.newParameterList.splice(nodeIndex,1); } + const params = state.newParameterList.map(node => node.name); + (state.paramNode && !(params.includes(state.paramNode.name))) ? state.newParameterList.push(state.paramNode) : state.newParameterList; } }) state.newReturnParameterList.forEach((node,nodeIndex) => { diff --git a/src/transformers/visitors/orchestrationInternalFunctionCallVisitor.ts b/src/transformers/visitors/orchestrationInternalFunctionCallVisitor.ts index 2b2a6118..4a4d0019 100644 --- a/src/transformers/visitors/orchestrationInternalFunctionCallVisitor.ts +++ b/src/transformers/visitors/orchestrationInternalFunctionCallVisitor.ts @@ -213,6 +213,9 @@ const internalCallVisitor = { file.nodes.forEach(childNode => { if(childNode.nodeType === 'FunctionDefinition') { childNode.parameters.modifiedStateVariables = joinWithoutDupes(childNode.parameters.modifiedStateVariables, state.newParametersList); + const modifiedNodes = childNode.parameters.modifiedStateVariables.map(node => node.name); + if(state.decNode && !(modifiedNodes.includes(state.decNode.declarations[0].name))) + childNode.body.preStatements.splice(1, 0, state.decNode); if(childNode.decrementedSecretStates) childNode.decrementedSecretStates = [...new Set([...childNode.decrementedSecretStates, ...newdecrementedSecretStates])]; childNode.body.preStatements.forEach(node => { @@ -527,7 +530,7 @@ FunctionCall: { decNode.declarations[0].declarationType = 'state'; decNode.declarations[0].isAccessed = true; decNode.declarations[0].interactsWithSecret = true; - callingfnDefPath.node._newASTPointer.body.preStatements.splice(1,0,decNode); + state.decNode = decNode; const returnPara = functionReferncedNode.node.returnParameters.parameters[0].name; newNode = buildNode('InternalFunctionCall', { name: returnPara, diff --git a/src/transformers/visitors/toCircuitVisitor.ts b/src/transformers/visitors/toCircuitVisitor.ts index fe0e9df5..be27dc0c 100644 --- a/src/transformers/visitors/toCircuitVisitor.ts +++ b/src/transformers/visitors/toCircuitVisitor.ts @@ -1588,12 +1588,12 @@ if(parent.nodeType === 'VariableDeclarationStatement') { 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; - }} + // saving the return parameter to add in the circuits if it doesn't exist + state.paramNode = functionReferncedNode.node.returnParameters.parameters[0]._newASTPointer; + state.paramNode.declarationType = 'parameter'; + state.paramNode.interactsWithSecret = true; + +} } else { newNode = buildNode('InternalFunctionCall', {