diff --git a/src/boilerplate/contract/solidity/nodes/FunctionBoilerplateGenerator.ts b/src/boilerplate/contract/solidity/nodes/FunctionBoilerplateGenerator.ts index 3b95cb4a..abd6d1ea 100644 --- a/src/boilerplate/contract/solidity/nodes/FunctionBoilerplateGenerator.ts +++ b/src/boilerplate/contract/solidity/nodes/FunctionBoilerplateGenerator.ts @@ -98,7 +98,7 @@ class FunctionBoilerplateGenerator { }); return { structName: structDef.name, properties: names, isParam: path.isFunctionParameter(node), isConstantArray: path.isConstantArray(node) ? node.typeName.length.value : false, inCircuit: node.interactsWithSecret }; } - return { name: node.name, type: node.typeName.name || node.typeName.baseType?.name || node.typeName.pathNode?.name, isParam: path.isFunctionParameter(node), isConstantArray: path.isConstantArray(node) ? node.typeName.length.value : false, inCircuit: node.interactsWithSecret || scope.getReferencedIndicator(node).interactsWithSecret }; + return { name: node.name, type: node.typeName.name || node.typeName.baseType?.name || node.typeName.pathNode?.name, isParam: path.isFunctionParameter(node), isConstantArray: path.isConstantArray(node) ? node.typeName.length.value : false, inCircuit: node.interactsWithSecret || scope.getReferencedIndicator(node)?.interactsWithSecret }; } const params = path.getFunctionParameters(); diff --git a/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts b/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts index 1eb2e925..39c54d20 100644 --- a/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts +++ b/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts @@ -86,7 +86,6 @@ class FunctionBoilerplateGenerator { } if (input.structName) customInputs[i] = input.properties; }); - console.log('cutomInputs in contract', customInputs); let msgSigCheck = ([...(isConstructor ? [] : [`bytes4 sig = bytes4(keccak256("${functionName}(${parameter})")) ; \n \t \t \t if (sig == msg.sig)`])]); customInputs = customInputs?.flat(Infinity).filter(p => (p.inCircuit || p.isReturn)); diff --git a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts index a843dd7a..03a9fd6d 100644 --- a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts +++ b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts @@ -160,7 +160,6 @@ export const generateProofBoilerplate = (node: any) => { ? [`\n\t\t\t\t\t\t\t\t${stateName}_stateVarId_key.integer,`] : []; // we add any extra params the circuit needs - console.log('Node Parameters Before Filtering:', node.parameters); node.parameters .filter( @@ -181,7 +180,6 @@ export const generateProofBoilerplate = (node: any) => { else { parameters.push(`\t${param}.integer,`); } - console.log('Rania@@@@@@@@@@@@@@@@@@@@@@',param) }); diff --git a/src/transformers/visitors/toOrchestrationVisitor.ts b/src/transformers/visitors/toOrchestrationVisitor.ts index 18fce989..aed1d936 100644 --- a/src/transformers/visitors/toOrchestrationVisitor.ts +++ b/src/transformers/visitors/toOrchestrationVisitor.ts @@ -214,7 +214,6 @@ if (name.endsWith('_')) { if (path.containerName !== 'indexExpression') { num_modifiers++; } - //console.log('expNode!!!!!!!!!!!!!!!!!',expNode); if (expNode) { // if the public input is modified before here, it won't show up in the mjs file // we have to go back and mark any editing statements as interactsWithSecret so they show up @@ -342,7 +341,6 @@ if (name.endsWith('_')) { } else { IDnode.name = `${node.name}_${num_modifiers}`; } - console.log('aaaaaaaaaabbbbbbbbbbbbb', IDnode); } } @@ -368,8 +366,7 @@ if (name.endsWith('_')) { state.publicInputs ??= []; if (!(path.containerName === 'indexExpression' && !(path.parentPath.isSecret|| path.parent.containsSecret))) state.publicInputs.push(node); } - //console.log('Public Inputs After Addition aaaaaaaaaaaaaaaaaaaaaaaaaaaa:', state.publicInputs); - + if (['Identifier', 'IndexAccess'].includes(node.indexExpression?.nodeType)) addPublicInput(NodePath.getPath(node.indexExpression), state, null); } /** @@ -990,12 +987,16 @@ 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) { + if ( para?.name === param?.name ) + oldParam = para ; + break; + } - scope.getReferencedIndicator(param); - console.log('KKKKKKKKKKKKKK param', scope.getReferencedIndicator(param).interactsWithSecret); - - if (param.isPrivate || param.isSecret || param.interactsWithSecret || scope.getReferencedIndicator(param).interactsWithSecret) { + if (param.isPrivate || param.isSecret || param.interactsWithSecret || scope.getReferencedIndicator(oldParam)?.interactsWithSecret) { if (param.typeName.isStruct) { param.typeName.properties.forEach((prop: any) => { newNodes.generateProofNode.parameters.push(`${param.name}.${prop.name}${param.typeName.isConstantArray ? '.all' : ''}`); diff --git a/src/traverse/NodePath.ts b/src/traverse/NodePath.ts index d6965f83..2b87ee8d 100644 --- a/src/traverse/NodePath.ts +++ b/src/traverse/NodePath.ts @@ -984,10 +984,21 @@ export default class NodePath { isConstantArray(node: any = this.node): boolean { if (!this.isArray(node)) return false; let arrLen; + console.log('vvvvvvvvvvvvvvvvvNodenode', node); switch (node.nodeType) { case 'IndexAccess': arrLen = node.baseExpression.typeDescriptions.typeString.match(/(?<=\[)(\d+)(?=\])/); break; + + // case 'VariableDeclaration': + + // if (node.typeDescriptions && node.typeDescriptions.typeString) { + // arrLen = node.typeDescriptions.typeString.match(/(?<=\[)(\d+)(?=\])/); + // } else if (node.typeName && typeof node.typeName.name === 'string' && !isNaN(node.typeName.name)) { + // return false; + // } + // break; + case 'Identifier': default: arrLen = node.typeDescriptions.typeString.match(/(?<=\[)(\d+)(?=\])/); diff --git a/src/traverse/Scope.ts b/src/traverse/Scope.ts index 52b8e176..bac6b5ac 100644 --- a/src/traverse/Scope.ts +++ b/src/traverse/Scope.ts @@ -393,11 +393,17 @@ export class Scope { */ getReferencedIndicator(referencingNode: any, mappingKeyIndicatorOnly: boolean = false): StateVariableIndicator | MappingKey | null { const { path } = this; - if (!referencingNode) return null; + if (!referencingNode) + return null; + + //if (referencingNode.nodeType === 'VariableDeclaration') return null ; + + const indicator = this.getIndicatorById( - path.getReferencedDeclarationId(referencingNode) || referencingNode.id + path.getReferencedDeclarationId(referencingNode) || referencingNode?.id ); + if (!path.isMapping(referencingNode) && !path.isArray(referencingNode) && !path.isStruct(referencingNode)) return indicator; if (path.isStruct(referencingNode) && NodePath.getPath(referencingNode).getAncestorOfType('MemberAccess') && path.isMapping(referencingNode)) { @@ -407,39 +413,42 @@ export class Scope { .node; const indexAccessNode = - memberAccessNode.expression.nodeType === 'IndexAccess' + memberAccessNode.expression?.nodeType === 'IndexAccess' ? memberAccessNode.expression : NodePath.getPath(memberAccessNode).getAncestorOfType('IndexAccess') - .node; + ?.node; return mappingKeyIndicatorOnly ? indicator.mappingKeys[this.getMappingKeyName(indexAccessNode)] : indicator; } - if (path.isStruct(referencingNode) && NodePath.getPath(referencingNode).getAncestorOfType('MemberAccess')) { + if (path.isStruct(referencingNode) && NodePath.getPath(referencingNode)?.getAncestorOfType('MemberAccess')) { const memberAccessNode = referencingNode.nodeType === 'MemberAccess' ? referencingNode - : NodePath.getPath(referencingNode).getAncestorOfType('MemberAccess') + : NodePath.getPath(referencingNode)?.getAncestorOfType('MemberAccess') .node; return mappingKeyIndicatorOnly ? indicator.structProperties[memberAccessNode.memberName] : 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 const indexAccessNode = referencingNode.nodeType === 'IndexAccess' ? referencingNode - : NodePath.getPath(referencingNode).getAncestorOfType('IndexAccess') - .node; + : NodePath.getPath(referencingNode)?.getAncestorOfType('IndexAccess') + ?.node; return mappingKeyIndicatorOnly - ? indicator.mappingKeys[this.getMappingKeyName(indexAccessNode)] + ? indicator?.mappingKeys[this.getMappingKeyName(indexAccessNode)] : 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 4e4c9d15..3efb290c 100644 --- a/test/contracts/Arrays-input.zol +++ b/test/contracts/Arrays-input.zol @@ -10,7 +10,7 @@ contract Assign { function add(secret uint256[5] calldata value, uint256[5] calldata publicValue) public { b = publicValue; - for (uint256 index = 0; index < 6; index++) { + for (uint256 index = 0; index < 2; index++) { known a += value[index]; } }