diff --git a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts index 03a9fd6d..c6e1e14e 100644 --- a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts +++ b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts @@ -168,8 +168,6 @@ export const generateProofBoilerplate = (node: any) => { !output.join().includes(`${para}.integer`) && !output.join().includes('msgValue')), ) - - ?.forEach((param: string) => { if (param == 'msgSender') { parameters.unshift(`\t${param}.integer,`); diff --git a/src/codeGenerators/orchestration/nodejs/toOrchestration.ts b/src/codeGenerators/orchestration/nodejs/toOrchestration.ts index aef4b9c3..ea3fe5f4 100644 --- a/src/codeGenerators/orchestration/nodejs/toOrchestration.ts +++ b/src/codeGenerators/orchestration/nodejs/toOrchestration.ts @@ -128,7 +128,6 @@ export default function codeGenerator(node: any, options: any = {}): any { if (!node.incrementsSecretState && (node.interactsWithSecret || node.expression?.internalFunctionInteractsWithSecret)){ return `\n${codeGenerator(node.expression)};`; } - if (node.incrementsSecretState && (node.interactsWithSecret ||node.containsPublic || node.expression?.internalFunctionInteractsWithSecret)){ let privateStateName = node.privateStateName.replace(/\./g, '_'); let increments; @@ -174,17 +173,13 @@ export default function codeGenerator(node: any, options: any = {}): any { if (!node.isInitializationAssignment && node.rightHandSide.subType !== 'generalNumber'){ if (['+=', '-=', '*='].includes(node.operator)) { - return `${codeGenerator(node.leftHandSide, { lhs: true, })} = generalise(${codeGenerator(node.leftHandSide)} ${node.operator.charAt( 0, )} ${codeGenerator(node.rightHandSide)})`; - } - - - return `${codeGenerator(node.leftHandSide, { lhs: true })} ${ + return `${codeGenerator(node.leftHandSide, { lhs: true })} ${ node.operator } generalise(${codeGenerator(node.rightHandSide)})`; diff --git a/src/transformers/visitors/checks/interactsWithSecretVisitor.ts b/src/transformers/visitors/checks/interactsWithSecretVisitor.ts index 118b4b14..68e42518 100644 --- a/src/transformers/visitors/checks/interactsWithSecretVisitor.ts +++ b/src/transformers/visitors/checks/interactsWithSecretVisitor.ts @@ -44,7 +44,7 @@ const markIndicatorSubtreeInteractsWithSecret = (thisPath: any, thisState: any) indicator.addSecretInteractingPath(thisState.secretPath); }; -const interactwithPublicSecret = (thisPath: any, thisState: any) => { +const interactwithInferSecret = (thisPath: any, thisState: any) => { const { node, scope } = thisPath; if (node.nodeType === 'ExpressionStatement') { const leftHandSideIndicator = scope.getReferencedIndicator(node.expression.leftHandSide, true); @@ -76,7 +76,7 @@ export default { FunctionDefinition: { exit(path: NodePath) { - path.traversePathsFast(interactwithPublicSecret, { + path.traversePathsFast(interactwithInferSecret, { publicPath: path, }); }, diff --git a/src/transformers/visitors/toContractVisitor.ts b/src/transformers/visitors/toContractVisitor.ts index c43fc69e..6e740950 100644 --- a/src/transformers/visitors/toContractVisitor.ts +++ b/src/transformers/visitors/toContractVisitor.ts @@ -59,7 +59,6 @@ const findCustomInputsVisitor = (thisPath: NodePath, thisState: any) => { ) { thisState.customInputs ??= []; const type = binding.node.typeName.nodeType === 'Mapping' ? binding.node.typeName.valueType.name : binding.node.typeName.name; - const isConstantArray = thisPath.isConstantArray(); const arrayLength = isConstantArray && thisPath.node.typeName?.length ? thisPath.node.typeName.length.value : false; diff --git a/src/transformers/visitors/toOrchestrationVisitor.ts b/src/transformers/visitors/toOrchestrationVisitor.ts index b5d134ea..9f9dee3a 100644 --- a/src/transformers/visitors/toOrchestrationVisitor.ts +++ b/src/transformers/visitors/toOrchestrationVisitor.ts @@ -117,10 +117,8 @@ const addPublicInput = (path: NodePath, state: any, IDnode: any) => { const { node } = path; let { name } = path.scope.getReferencedIndicator(node, true) || path.node; -// if (name.includes('[') && name.includes(']')) { -// name = name.replace(/\[|\]/g, '_'); -// } -name = name.replace(/\[([^\]]+)\]/g, '_$1'); + + name = name.replace(/\[([^\]]+)\]/g, '_$1'); // Ensure there is no trailing underscore if (name.endsWith('_')) { @@ -172,9 +170,7 @@ if (name.endsWith('_')) { isAccessed: true, isSecret: false, }) - } - - else { + } else { innerNode = buildNode('VariableDeclaration', { name, isAccessed: true, @@ -331,7 +327,6 @@ if (name.endsWith('_')) { } }); - //We ensure here that the public variable used has the correct name, e.g index_2 instead of index. if(IDnode) { if (num_modifiers != 0) { @@ -343,8 +338,6 @@ if (name.endsWith('_')) { } } - - // After the non-secret variables have been modified we need to reset the original variable name to its initial value. // e.g. index = index_init. @@ -987,7 +980,6 @@ const visitor = { } // this adds other values we need in the circuit - for (const param of node._newASTPointer.parameters.parameters) { let oldParam : any ; for(const para of node.parameters.parameters) { @@ -995,7 +987,6 @@ const visitor = { oldParam = para ; break; } - if (param.isPrivate || param.isSecret || param.interactsWithSecret || scope.getReferencedIndicator(oldParam)?.interactsWithSecret) { if (param.typeName.isStruct) { param.typeName.properties.forEach((prop: any) => { @@ -1003,7 +994,6 @@ const visitor = { }); } else newNodes.generateProofNode.parameters.push(`${param.name}${param.typeName.isConstantArray ? '.all' : ''}`); } - } if (state.publicInputs) { state.publicInputs.forEach((input: any) => { diff --git a/src/traverse/Scope.ts b/src/traverse/Scope.ts index 92a7d9c7..dbc98ef0 100644 --- a/src/traverse/Scope.ts +++ b/src/traverse/Scope.ts @@ -429,8 +429,6 @@ export class Scope { : indicator; } - - //if (path.isConstantArray(referencingNode) && referencingNode.nodeType === 'variableDeclaration') return null; if ((path.isConstantArray(referencingNode) || referencingNode.memberName === 'length') && !NodePath.getPath(referencingNode).getAncestorOfType('IndexAccess')) return indicator; // getMappingKeyName requires an indexAccessNode - referencingNode may be a baseExpression or indexExpression contained Identifier @@ -445,7 +443,6 @@ export class Scope { : indicator; } - /** * @returns {Node || null} - the node (VariableDeclaration) being referred-to by the input referencingNode. */ diff --git a/test/contracts/Arrays-input.zol b/test/contracts/Arrays-input.zol index 3a4d4209..0bf6f7fe 100644 --- a/test/contracts/Arrays-input.zol +++ b/test/contracts/Arrays-input.zol @@ -5,7 +5,7 @@ pragma solidity ^0.8.0; contract Assign { secret uint256 private a; - uint256[6] public b; + uint256[5] public b; function add(secret uint256[5] calldata value, uint256[5] calldata publicValue) public { diff --git a/test/contracts/Boolean-public.zol b/test/contracts/Boolean-public.zol deleted file mode 100644 index 7348e9a7..00000000 --- a/test/contracts/Boolean-public.zol +++ /dev/null @@ -1,39 +0,0 @@ -// 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 { - 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; - } - } - - function addPublic(uint256 value, bool value_publicbool) public { - if (value > 10) { - d = true; - g = value_publicbool; - } - if (value < 10) { - d = false; - g = !value_publicbool; - } - } - - -} diff --git a/test/contracts/Non-Secret-Array.zol b/test/contracts/Non-Secret-Array.zol index 0bf83af6..2df97865 100644 --- a/test/contracts/Non-Secret-Array.zol +++ b/test/contracts/Non-Secret-Array.zol @@ -8,10 +8,18 @@ uint256 public index; uint256[3] public c; +function add( uint256 value) public { +c[index] += value; +} function add1( uint256 value) public { c[index] += value; known a += c[index]; } +function add2( uint256 value) public { +c[index] += value; +known a += value; +} + } \ No newline at end of file