Skip to content

Commit

Permalink
Merge pull request #274 from EYBlockchain/swati/returnBug
Browse files Browse the repository at this point in the history
Return bug fix
  • Loading branch information
SwatiEY authored Jun 6, 2024
2 parents 65783e4 + 583d8c5 commit 17f8e50
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ContractBoilerplateGenerator {
let verifyInput: string[] = [];

const verifyInputsMap = (type: string, input: string, counter: any) => {

if(type === 'parameters'){
switch (input) {
case 'nullifierRoot':
Expand Down Expand Up @@ -149,6 +149,7 @@ class ContractBoilerplateGenerator {
}
}
else if(type === 'returnParameters') {

switch (input) {
case 'encryption':
verifyInput.push( `
Expand Down
10 changes: 5 additions & 5 deletions src/transformers/visitors/toContractVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}
}
Expand All @@ -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
Expand All @@ -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 });
}
};

Expand Down Expand Up @@ -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 });
Expand Down
23 changes: 23 additions & 0 deletions test/contracts/Return-Bool.zol
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 17f8e50

Please sign in to comment.