diff --git a/src/boilerplate/contract/solidity/nodes/ContractBoilerplateGenerator.ts b/src/boilerplate/contract/solidity/nodes/ContractBoilerplateGenerator.ts index 8407807b4..4fcc80a0c 100644 --- a/src/boilerplate/contract/solidity/nodes/ContractBoilerplateGenerator.ts +++ b/src/boilerplate/contract/solidity/nodes/ContractBoilerplateGenerator.ts @@ -118,7 +118,7 @@ class ContractBoilerplateGenerator { let paramtype: string; let params : any[]; let functionName: string; - + for ([functionName, parameterList] of Object.entries(circuitParams)) { for ([paramtype, params] of Object.entries(parameterList)){ const returnpara = {}; diff --git a/src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts b/src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts index abae7a1b3..6535ffbae 100644 --- a/src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts +++ b/src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts @@ -121,7 +121,7 @@ class ContractBoilerplateGenerator { let verifyInput: string[] = []; const verifyInputsMap = (type: string, input: string, counter: any) => { - + if(type === 'parameters'){ switch (input) { case 'nullifierRoot': @@ -149,6 +149,7 @@ class ContractBoilerplateGenerator { } } else if(type === 'returnParameters') { + switch (input) { case 'encryption': verifyInput.push( ` diff --git a/src/transformers/visitors/toContractVisitor.ts b/src/transformers/visitors/toContractVisitor.ts index 9e5c6618f..6a91bdef0 100644 --- a/src/transformers/visitors/toContractVisitor.ts +++ b/src/transformers/visitors/toContractVisitor.ts @@ -29,13 +29,13 @@ const findCustomInputsVisitor = (thisPath: NodePath, thisState: any) => { item.expression.components.forEach(element => { if(element.kind === 'bool'){ thisState.customInputs ??= []; - thisState.customInputs.push({name: '1', typeName: {name: 'bool'}}); + thisState.customInputs.push({name: '1', typeName: {name: 'bool'}, isReturn: true}); } }); } else { if(item.expression.kind === 'bool'){ thisState.customInputs ??= []; - thisState.customInputs.push({name: '1', typeName: {name: 'bool'}}); + thisState.customInputs.push({name: '1', typeName: {name: 'bool'}, isReturn: true}); } } } @@ -44,7 +44,7 @@ const findCustomInputsVisitor = (thisPath: NodePath, thisState: any) => { if(thisPath.getAncestorOfType('Return') && binding instanceof VariableBinding && binding.isSecret){ thisState.customInputs ??= []; if(thisState.variableName.includes(indicator.node.name)) - thisState.customInputs.push({name: 'newCommitments['+(thisState.variableName.indexOf(indicator.node.name))+']', typeName: {name: 'uint256'}}); + thisState.customInputs.push({name: 'newCommitments['+(thisState.variableName.indexOf(indicator.node.name))+']', typeName: {name: 'uint256'}, isReturn: true}); } // for some reason, node.interactsWithSecret has disappeared here but not in toCircuit @@ -61,7 +61,7 @@ const findCustomInputsVisitor = (thisPath: NodePath, thisState: any) => { thisState.customInputs ??= []; const type = binding.node.typeName.nodeType === 'Mapping' ? binding.node.typeName.valueType.name : binding.node.typeName.name; if (!thisState.customInputs.some((input: any) => input.name === indicator?.name)) - thisState.customInputs.push({name: indicator?.name, typeName: {name: type}, isConstantArray: thisPath.isConstantArray() ? thisPath.node.typeName.length.value : false, inCircuit: true }); + thisState.customInputs.push({name: indicator?.name, typeName: {name: type}, isConstantArray: thisPath.isConstantArray() ? thisPath.node.typeName.length.value : false, inCircuit: true, isReturn: false }); } }; @@ -431,7 +431,7 @@ export default { path.traversePathsFast(findCustomInputsVisitor, state); state.returnpara ??= {}; state.returnpara[state.functionName] ??= {}; - state.returnpara[state.functionName].returnParameters = state.customInputs.map(n => n.name); + state.returnpara[state.functionName].returnParameters = state.customInputs.filter(n => n.isReturn).map(n => n.name ); const newNode = buildNode( node.nodeType, { value: node.expression.value }); diff --git a/test/contracts/Return-Bool.zol b/test/contracts/Return-Bool.zol new file mode 100644 index 000000000..8874f6552 --- /dev/null +++ b/test/contracts/Return-Bool.zol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: CC0 +pragma solidity ^0.8.0; +contract Assign { + secret bool private a; + secret bool private c; + bool public d; + bool public g; + + function add( secret uint256 value, secret bool value_bool, bool value_publicbool) public returns (bool){ + secret bool l = true; + bool m = false; + c = a && m && d; + if(value > 10 && !c) { + c=true; + a= value_bool && value_publicbool; + } + if( value < 10) { + a =!c; + c= l || a || m; + } + return a; + } +} \ No newline at end of file