Skip to content

Commit

Permalink
chore: fixed secret call
Browse files Browse the repository at this point in the history
  • Loading branch information
SwatiEY committed Aug 29, 2024
1 parent beb16ca commit 0ae4fc3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/codeGenerators/circuit/zokrates/toCircuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/transformers/visitors/toCircuitVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit 0ae4fc3

Please sign in to comment.