diff --git a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts index c6e1e14e..0c68387c 100644 --- a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts +++ b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts @@ -109,7 +109,6 @@ export const sendTransactionBoilerplate = (node: any) => { output[5].push(`${privateStateName}_cipherText`); output[6].push(`${privateStateName}_encKey`); } - break; } } @@ -139,7 +138,6 @@ export const generateProofBoilerplate = (node: any) => { // we include the state variable key (mapping key) if its not a param (we include params separately) const msgSenderParamAndMappingKey = stateNode.isMapping && (node.parameters.includes('msgSender') || output.join().includes('_msg_stateVarId_key.integer')) && stateNode.stateVarId[1] === 'msg'; const msgValueParamAndMappingKey = stateNode.isMapping && (node.parameters.includes('msgValue') || output.join().includes('_msg_stateVarId_key.integer')) && stateNode.stateVarId[1] === 'msg'; - const constantMappingKey = stateNode.isMapping && (+stateNode.stateVarId[1] || stateNode.stateVarId[1] === '0'); // We are keeping this code in comments, for future if have any issue with extra mapping keys getting added for a zapp we can come to this @@ -161,13 +159,11 @@ export const generateProofBoilerplate = (node: any) => { : []; // we add any extra params the circuit needs node.parameters - .filter( (para: string) => !privateStateNames.includes(para) && ( !output.join().includes(`${para}.integer`) && !output.join().includes('msgValue')), ) - ?.forEach((param: string) => { if (param == 'msgSender') { parameters.unshift(`\t${param}.integer,`); @@ -178,7 +174,6 @@ export const generateProofBoilerplate = (node: any) => { else { parameters.push(`\t${param}.integer,`); } - }); // then we build boilerplate code per state @@ -241,7 +236,6 @@ export const generateProofBoilerplate = (node: any) => { isSharedSecret: stateNode.isSharedSecret, parameters, }) - ); containsNullifierRoot = true; containsNewNullifierRoot = true; @@ -325,7 +319,6 @@ export const preimageBoilerPlate = (node: any) => { accessedOnly: true, stateVarIds, })); - continue; } @@ -507,21 +500,18 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { lines.push(`\nconst ${param} = generalise(_${param});`); params.push(`_${param}`); }); - node.parameters.modifiedStateVariables.forEach((param: any) => { states.push(`_${param.name}_newOwnerPublicKey = 0`); lines.push( `\nlet ${param.name}_newOwnerPublicKey = generalise(_${param.name}_newOwnerPublicKey);`, ); }); - if (node.decrementsSecretState) { node.decrementedSecretStates.forEach((decrementedState: string) => { states.push(` _${decrementedState}_0_oldCommitment = 0`); states.push(` _${decrementedState}_1_oldCommitment = 0`); }); } - node.returnParameters.forEach( (param, index) => { if(param === 'true') rtnparams?.push('bool: bool'); @@ -529,7 +519,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { rtnparams?.push( ` ${param.replace('_change', '')}_newCommitmentValue : ${param}.integer `); }); if (params) params[params.length - 1] += `,`; - if (node.name === 'cnstrctr') return { signature: [ @@ -551,7 +540,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { statements: lines, }; } - if(rtnparams.includes('bool: bool')) { return { signature: [ @@ -564,7 +552,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { statements: lines, }; } - return { signature: [ ` ${functionSig} @@ -607,7 +594,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { mappingName: stateNode.mappingName || stateName, structProperties: stateNode.structProperties })); - } return { statements: lines, @@ -753,7 +739,7 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { statements: [`\n// Extract set membership witness: \n\n`, ...lines], }; - case 'CalculateNullifier': + case 'CalculateNullifier': for ([stateName, stateNode] of Object.entries(node.privateStates)) { if (stateNode.isPartitioned) { lines.push( @@ -763,7 +749,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { accessedOnly: stateNode.accessedOnly, stateType: 'partitioned', })); - } else { lines.push( Orchestrationbp.calculateNullifier.postStatements({ @@ -774,7 +759,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { })); } } - for ([stateName, stateNode] of Object.entries(node.privateStates)) { if (stateNode.isPartitioned) { lines.push( @@ -783,7 +767,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { accessedOnly: stateNode.accessedOnly, stateType: 'partitioned', })); - } else { lines.push( Orchestrationbp.temporaryUpdatedNullifier.postStatements({ @@ -793,7 +776,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { })); } } - for ([stateName, stateNode] of Object.entries(node.privateStates)) { if (stateNode.isPartitioned) { lines.push( @@ -812,7 +794,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { })); } } - return { statements: [`\n// Calculate nullifier(s): \n`, ...lines], }; @@ -829,7 +810,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { isSharedSecret: stateNode.isSharedSecret, structProperties: stateNode.structProperties, })); - break; case true: default: @@ -843,7 +823,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { isSharedSecret: stateNode.isSharedSecret, structProperties: stateNode.structProperties, })); - break; case false: default: @@ -855,7 +834,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { isSharedSecret: stateNode.isSharedSecret, structProperties: stateNode.structProperties, })); - } } } @@ -878,7 +856,7 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { ], }; - case 'EncryptBackupPreimage': + case 'EncryptBackupPreimage': lines.push(`let BackupData = [];\n`) for ([stateName, stateNode] of Object.entries(node.privateStates)) { let stateType; @@ -953,8 +931,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { ] } - - return { statements: [ `\n\n// Send transaction to the blockchain: @@ -997,8 +973,7 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { ], }; - - case 'SendPublicTransaction': + case 'SendPublicTransaction': if (node.publicInputs[0]) { node.publicInputs.forEach((input: any) => { if (input.properties) { diff --git a/src/codeGenerators/orchestration/nodejs/toOrchestration.ts b/src/codeGenerators/orchestration/nodejs/toOrchestration.ts index ea3fe5f4..b0dce722 100644 --- a/src/codeGenerators/orchestration/nodejs/toOrchestration.ts +++ b/src/codeGenerators/orchestration/nodejs/toOrchestration.ts @@ -63,7 +63,6 @@ export default function codeGenerator(node: any, options: any = {}): any { const fn = OrchestrationCodeBoilerPlate(node); const statements = codeGenerator(node.body); fn.statements.push(statements); - return `${fn.signature[0]}\n\t${fn.statements.join('')}\n${ fn.signature[1] }`; @@ -96,7 +95,6 @@ export default function codeGenerator(node: any, options: any = {}): any { } else if (node.declarations[0].isAccessed) { return `${getAccessedValue(node.declarations[0].name)}`; } - if (!node.initialValue && !node.declarations[0].isAccessed) return `\nlet ${codeGenerator(node.declarations[0])};`; if (node.initialValue && node.initialValue.operator && @@ -111,17 +109,17 @@ export default function codeGenerator(node: any, options: any = {}): any { if (node.initialValue.nodeType === 'Literal' && node.isInitializationExpression) return `\nlet ${codeGenerator(node.declarations[0])} = ${codeGenerator(node.initialValue)};`; return `\nlet ${codeGenerator(node.declarations[0])} = generalise(${codeGenerator(node.initialValue)});`; } - return `\nlet ${codeGenerator(node.initialValue)};`; + return `\nlet ${codeGenerator(node.initialValue)};`; } case 'ElementaryTypeName': return; - case 'Block': { - const preStatements: string = (node.preStatements.flatMap(codeGenerator)); - const statements:string = (node.statements.flatMap(codeGenerator)); - const postStatements: string = (node.postStatements.flatMap(codeGenerator)); - return [...preStatements, ...statements, ...postStatements].join('\n\n'); + case 'Block': { + const preStatements: string = (node.preStatements.flatMap(codeGenerator)); + const statements:string = (node.statements.flatMap(codeGenerator)); + const postStatements: string = (node.postStatements.flatMap(codeGenerator)); + return [...preStatements, ...statements, ...postStatements].join('\n\n'); } case 'ExpressionStatement': @@ -131,15 +129,12 @@ export default function codeGenerator(node: any, options: any = {}): any { if (node.incrementsSecretState && (node.interactsWithSecret ||node.containsPublic || node.expression?.internalFunctionInteractsWithSecret)){ let privateStateName = node.privateStateName.replace(/\./g, '_'); let increments; - if (node.expression.operator === '+='){ increments = codeGenerator(node.expression.rightHandSide); - // Although we have += in the case that the indicator is decremented elsewhere in the function, we need to subtract the increments. if (!node.indicatorDecremented) return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) + ${increments});\n`; if (node.indicatorDecremented) return `\n${privateStateName}_newCommitmentValue_inc = generalise(parseInt(${privateStateName}_newCommitmentValue_inc.integer, 10) + ${increments});\n`; } - if (node.expression.operator === '-='){ increments = codeGenerator(node.expression.rightHandSide); return `\n${privateStateName}_newCommitmentValue = generalise(parseInt(${privateStateName}_newCommitmentValue.integer, 10) + (${increments}));\n`; @@ -160,17 +155,15 @@ export default function codeGenerator(node: any, options: any = {}): any { } } } - if (!node.interactsWithSecret) - return `\n// non-secret line would go here but has been filtered out`; - return `\n// increment would go here but has been filtered out`; + return `\n// non-secret line would go here but has been filtered out`; + return `\n// increment would go here but has been filtered out`; case 'InternalFunctionCall': return " "; case 'Assignment': // To ensure the left hand side is always a general number, we generalise it here (excluding the initialisation in a for loop). - if (!node.isInitializationAssignment && node.rightHandSide.subType !== 'generalNumber'){ if (['+=', '-=', '*='].includes(node.operator)) { return `${codeGenerator(node.leftHandSide, { @@ -182,7 +175,6 @@ export default function codeGenerator(node: any, options: any = {}): any { return `${codeGenerator(node.leftHandSide, { lhs: true })} ${ node.operator } generalise(${codeGenerator(node.rightHandSide)})`; - } else { if (['+=', '-=', '*='].includes(node.operator)) { return `${codeGenerator(node.leftHandSide, { @@ -194,10 +186,8 @@ export default function codeGenerator(node: any, options: any = {}): any { return `${codeGenerator(node.leftHandSide, { lhs: true })} ${ node.operator } ${codeGenerator(node.rightHandSide)}`; - } - case 'BinaryOperation': return `${codeGenerator(node.leftExpression, { lhs: options.condition })} ${ node.operator @@ -208,9 +198,8 @@ export default function codeGenerator(node: any, options: any = {}): any { return `(${node.components.map(codeGenerator).join(` `)})`; return ` `; - case 'IfStatement': { + case 'IfStatement': { let comment = (node.inPreStatements) ? "// some public statements of this if statement have been moved to pre-statements here, any other statements appear later" : ''; - // We need to declare some variables before the if statement begins (because they are used outside the if statement). let preIfStatements = node.trueBody.filter((node: any) => node.outsideIf).concat(node.falseBody.filter((node: any) => node.outsideIf)); let newPreIfStatements = []; @@ -219,7 +208,6 @@ export default function codeGenerator(node: any, options: any = {}): any { newPreIfStatements[newPreIfStatements.length - 1].outsideIf = false; }); let preIfStatementsString = newPreIfStatements.flatMap(codeGenerator).join('\n'); - if(node.falseBody.length) return `${comment} ${preIfStatementsString} @@ -236,12 +224,12 @@ export default function codeGenerator(node: any, options: any = {}): any { }` } - case 'Conditional': { - return ` ${codeGenerator(node.condition)} ? - ${node.trueExpression.flatMap(codeGenerator).join('\n')} : ${node.falseExpression.flatMap(codeGenerator).join('\n')}` + case 'Conditional': { + return ` ${codeGenerator(node.condition)} ? + ${node.trueExpression.flatMap(codeGenerator).join('\n')} : ${node.falseExpression.flatMap(codeGenerator).join('\n')}` } - case 'ForStatement': { + case 'ForStatement': { if(node.interactsWithSecret) { let initializationExpression = `${codeGenerator(node.initializationExpression).trim()}`; let condition = `${codeGenerator(node.condition, { condition: true })};`; @@ -249,9 +237,8 @@ export default function codeGenerator(node: any, options: any = {}): any { return `for( ${node.initializationExpression.nodeType === 'VariableDeclarationStatement' ? `` : `let`} ${initializationExpression} ${condition} ${loopExpression}) { ${codeGenerator(node.body)} }` - } - else - return ''; + } else + return ''; } case 'MsgSender': diff --git a/src/transformers/visitors/checks/interactsWithSecretVisitor.ts b/src/transformers/visitors/checks/interactsWithSecretVisitor.ts index 68e42518..d223686b 100644 --- a/src/transformers/visitors/checks/interactsWithSecretVisitor.ts +++ b/src/transformers/visitors/checks/interactsWithSecretVisitor.ts @@ -44,11 +44,10 @@ const markIndicatorSubtreeInteractsWithSecret = (thisPath: any, thisState: any) indicator.addSecretInteractingPath(thisState.secretPath); }; -const interactwithInferSecret = (thisPath: any, thisState: any) => { +const inferInteractsWithSecret = (thisPath: any, thisState: any) => { const { node, scope } = thisPath; if (node.nodeType === 'ExpressionStatement') { const leftHandSideIndicator = scope.getReferencedIndicator(node.expression.leftHandSide, true); - if (leftHandSideIndicator?.interactsWithSecret) { thisPath.traversePathsFast(markIndicatorSubtreeInteractsWithSecret, { secretPath: thisPath, @@ -66,7 +65,6 @@ export default { path.getAncestorOfType('ExpressionStatement') || path.parentPath; if (path.isExternalFunctionCall()) { path.markContainsPublic(); - // below ensures that the return value and args are marked as interactsWithPublic expressionPath.traversePathsFast(markSubtreeInteractsWithPublic, { publicPath: path, }); @@ -76,7 +74,7 @@ export default { FunctionDefinition: { exit(path: NodePath) { - path.traversePathsFast(interactwithInferSecret, { + path.traversePathsFast(inferInteractsWithSecret, { publicPath: path, }); }, diff --git a/src/transformers/visitors/toOrchestrationVisitor.ts b/src/transformers/visitors/toOrchestrationVisitor.ts index 9f9dee3a..76deb3d4 100644 --- a/src/transformers/visitors/toOrchestrationVisitor.ts +++ b/src/transformers/visitors/toOrchestrationVisitor.ts @@ -340,9 +340,7 @@ 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. - fnDefNode.node._newASTPointer.body.preStatements = fnDefNode.node._newASTPointer.body.preStatements.filter(p => p.expression?.rightHandSide?.name !== `${node.name}_init`); - const endNodeInit = buildNode('Assignment', { leftHandSide: buildNode('Identifier', { name: `${node.name}`, subType: 'generalNumber' }), operator: '=', @@ -352,14 +350,12 @@ if (name.endsWith('_')) { expression: endNodeInit, interactsWithSecret: true, }); - fnDefNode.node._newASTPointer.body.preStatements.push(endNode); // if the node is the indexExpression, we dont need its value in the circuit state.publicInputs ??= []; if (!(path.containerName === 'indexExpression' && !(path.parentPath.isSecret|| path.parent.containsSecret))) state.publicInputs.push(node); } - if (['Identifier', 'IndexAccess'].includes(node.indexExpression?.nodeType)) addPublicInput(NodePath.getPath(node.indexExpression), state, null); } /** @@ -375,7 +371,6 @@ const visitor = { enter(path: NodePath, state: any) { const { node, parent, scope } = path; node._newASTPointer = parent._newASTPointer; - const contractName = `${node.name}Shield`; if (scope.indicators.zkSnarkVerificationRequired) { const newNode = buildNode('File', { @@ -390,7 +385,6 @@ const visitor = { }); node._newASTPointer.push(newNode); } - let newNode = buildNode('SetupCommonFilesBoilerplate', { contractName, contractImports: state.contractImports, @@ -441,8 +435,6 @@ const visitor = { }); node._newASTPointer.push(newNode); } - - if (scope.indicators.newCommitmentsRequired) { const newNode = buildNode('EditableCommitmentCommonFilesBoilerplate'); node._newASTPointer.push(newNode); @@ -460,7 +452,6 @@ const visitor = { file.functionNames.push('joinCommitments'); file.functionNames.push('splitCommitments'); } - } if (file.nodes?.[0].nodeType === 'IntegrationTestBoilerplate') { file.nodes[0].constructorParams = state.constructorParams; @@ -471,6 +462,7 @@ const visitor = { path.traverse(explode(internalCallVisitor), state); }, }, + ImportDirective: { enter(path: NodePath, state: any) { const { node } = path; @@ -481,11 +473,9 @@ const visitor = { }); // we assume all import statements come before all functions }, - }, FunctionDefinition: { - enter(path: NodePath, state: any) { const { node, parent, scope } = path; if (scope.modifiesSecretState()) { @@ -494,7 +484,6 @@ const visitor = { node.fileName = fnName; // After getting an appropriate Name , we build the node - const newNode = buildNode('File', { fileName: fnName, // the name of this function fileExtension: '.mjs', @@ -503,8 +492,6 @@ const visitor = { buildNode('FunctionDefinition', { name: node.name, contractName }), ], }); - - node._newASTPointer = newNode.nodes[1]; // eslint-disable-line prefer-destructuring parent._newASTPointer.push(newNode); for (const file of parent._newASTPointer) { @@ -539,7 +526,6 @@ const visitor = { state.skipSubNodes = true; return; } - const contractName = `${parent.name}Shield`; const fnName = path.getUniqueFunctionName(); node.fileName = fnName; @@ -602,8 +588,6 @@ const visitor = { node._newASTPointer.msgSenderParam ??= state.msgSenderParam; node._newASTPointer.msgValueParam ??= state.msgValueParam; - - if(node.containsPublic && !scope.modifiesSecretState()){ interface PublicParam { name: string; @@ -612,14 +596,10 @@ const visitor = { isBool?: boolean; isAddress?: boolean; } - const sendPublicTransactionNode = buildNode('SendPublicTransaction', { functionName: node.fileName, publicInputs: [], }); - - - node.parameters.parameters.forEach((para: { isSecret: any; typeName: { name: string; }; name: any; _newASTPointer: { typeName: { properties: any[]; }; }; }) => { if (!para.isSecret) { if (path.isStructDeclaration(para) || path.isConstantArray(para) || (para.typeName && para.typeName.name === 'bool') || (para.typeName && para.typeName.name === 'address')) { @@ -643,18 +623,14 @@ const visitor = { } }); - // Add publics parametres to sendTransactionNode node._newASTPointer.body.postStatements.push(sendPublicTransactionNode); - node.parameters.parameters.forEach(para => { node._newASTPointer.publicInputs ??= []; node._newASTPointer.publicInputs.push(para.name); }); - } - - + // By this point, we've added a corresponding FunctionDefinition node to the newAST, with the same nodes as the original Solidity function, with some renaming here and there, and stripping out unused data from the oldAST. const functionIndicator: FunctionDefinitionIndicator = scope.indicators; for(const [, indicators ] of Object.entries(functionIndicator)){ @@ -685,7 +661,6 @@ const visitor = { } } } - let thisIntegrationTestFunction: any = {}; let thisIntegrationApiServiceFunction: any = {}; for (const file of parent._newASTPointer) { @@ -704,10 +679,8 @@ const visitor = { if(scope.modifiesSecretState()){ file.functionNames.push(node.fileName); } - } } - thisIntegrationTestFunction.parameters = node._newASTPointer.parameters; thisIntegrationTestFunction.newCommitmentsRequired = functionIndicator.newCommitmentsRequired; @@ -739,7 +712,6 @@ const visitor = { newNodes.generateProofNode.parameters.push(`msgValue`); delete state.msgValueParam; // reset } - const allIndicators: (StateVariableIndicator | MappingKey)[] = []; let stateVarIndicator: StateVariableIndicator | MappingKey; for ([, stateVarIndicator] of Object.entries( @@ -891,7 +863,6 @@ const visitor = { } if (secretModified || accessedOnly) { - newNodes.sendTransactionNode.privateStates[ name ] = buildPrivateStateNode('SendTransaction', { @@ -938,13 +909,10 @@ const visitor = { }); } } - - if (node.kind === 'constructor') { newNodes.writePreimageNode.isConstructor = true; newNodes.membershipWitnessNode.isConstructor = true; } - const newFunctionDefinitionNode = node._newASTPointer; // In If Statements we might have non-secret statements editing variables that later interact with a secret variable. @@ -1020,7 +988,6 @@ const visitor = { // this adds the return parameters which are marked as secret in the tx let returnPara = node._newASTPointer.returnParameters.parameters.filter((paramnode: any) => (paramnode.isSecret || paramnode.typeName.name === 'bool')).map(paramnode => (paramnode.name)) || []; - let returnIsSecret: string[] = []; const decStates = node._newASTPointer.decrementedSecretStates; if( node._newASTPointer.returnParameters.parameters) { @@ -1329,7 +1296,6 @@ const visitor = { node._newASTPointer = newNode.statements; parent._newASTPointer.body = newNode; }, - }, VariableDeclarationStatement: { @@ -1340,7 +1306,6 @@ const visitor = { node._newASTPointer = newNode; path.inList ? parent._newASTPointer.push(newNode) : parent._newASTPointer[path.containerName] = newNode; }, - }, BinaryOperation: { @@ -1350,7 +1315,6 @@ const visitor = { node._newASTPointer = newNode; path.inList ? parent._newASTPointer.push(newNode) : parent._newASTPointer[path.containerName] = newNode; }, - }, Assignment: { @@ -1405,7 +1369,6 @@ const visitor = { parent._newASTPointer.expression = newNode; } } - if (path.getAncestorContainedWithin('initializationExpression') && parent._newASTPointer.nodeType === 'VariableDeclarationStatement' ){ parent._newASTPointer.initialValue.isInitializationAssignment = true; } else if (path.getAncestorContainedWithin('initializationExpression')) { @@ -1426,7 +1389,6 @@ const visitor = { node._newASTPointer = newNode.components; parent._newASTPointer[path.containerName] = newNode; } - }, }, @@ -1553,7 +1515,6 @@ const visitor = { const accessedBeforeModification = indicator.isAccessed && indicator.accessedPaths[0].node.id < lhs.id && !indicator.accessedPaths[0].isModification(); if (accessedBeforeModification || path.isInSubScope()) accessed = true; - const newNode = buildNode('VariableDeclarationStatement', { oldASTId: node.id, declarations: [ @@ -1621,7 +1582,6 @@ const visitor = { exit(path: NodePath, state: any) { const { node, scope } = path; - const { leftHandSide: lhs } = node.expression; const indicator = scope.getReferencedIndicator(lhs, true); let name = indicator?.isMapping @@ -1699,7 +1659,6 @@ const visitor = { // we now have a param or a local var dec let interactsWithSecret = false; - scope.bindings[node.id].referencingPaths.forEach(refPath => { interactsWithSecret ||= refPath.node.interactsWithSecret; // check for internal function call if the parameter passed in the function call interacts with secret or not @@ -1768,7 +1727,6 @@ const visitor = { }); const dec = path.getAncestorOfType('VariableDeclaration').node; if (node.length.value && (path.isLocalStackVariable(dec) || path.isFunctionParameter(dec))) newNode.isConstantArray = true; - node._newASTPointer = newNode; if (Array.isArray(parent._newASTPointer)) { parent._newASTPointer.push(newNode); @@ -1785,10 +1743,8 @@ const visitor = { if(!!path.getAncestorOfType('EventDefinition')) return; if(!!path.getAncestorOfType('EmitStatement')) return; const newNode = buildNode(node.nodeType, { name: node.name }); - parent._newASTPointer[path.containerName] = newNode; }, - }, UserDefinedTypeName: { @@ -1855,8 +1811,6 @@ const visitor = { name, subType: node.typeDescriptions.typeString, }); - - // if this is a public state variable, this fn will add a public input addPublicInput(path, state, newNode); state.skipSubNodes = true; // the subnodes are baseExpression and indexExpression - we skip them diff --git a/src/traverse/Scope.ts b/src/traverse/Scope.ts index dbc98ef0..03486be5 100644 --- a/src/traverse/Scope.ts +++ b/src/traverse/Scope.ts @@ -341,7 +341,6 @@ export class Scope { if (scope.scopeType === scopeType) return true; scope = scope.parentScope; } - return false; } @@ -361,7 +360,6 @@ export class Scope { const id = this.path.getReferencedDeclarationId(node); if (!id) return null; // if the node doesn't refer to another variable return this.queryAncestors((s: Scope) => { - const binding = s.bindings[id] if (!mappingKeyIndicatorOnly) return binding; if (binding instanceof VariableBinding) return binding.mappingKeys[this.getMappingKeyName(referencingNode)]; @@ -395,30 +393,24 @@ export class Scope { const { path } = this; if (!referencingNode) return null; - const indicator = this.getIndicatorById( 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)) { const memberAccessNode = referencingNode.nodeType === 'MemberAccess' ? referencingNode : NodePath.getPath(referencingNode).getAncestorOfType('MemberAccess') .node; - const indexAccessNode = memberAccessNode.expression?.nodeType === 'IndexAccess' ? memberAccessNode.expression : NodePath.getPath(memberAccessNode).getAncestorOfType('IndexAccess') ?.node; - return mappingKeyIndicatorOnly ? indicator.mappingKeys[this.getMappingKeyName(indexAccessNode)] : indicator; } - if (path.isStruct(referencingNode) && NodePath.getPath(referencingNode)?.getAncestorOfType('MemberAccess')) { const memberAccessNode = referencingNode.nodeType === 'MemberAccess' ? referencingNode @@ -428,16 +420,13 @@ export class Scope { ? indicator.structProperties[memberAccessNode.memberName] : indicator; } - 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; - return mappingKeyIndicatorOnly ? indicator?.mappingKeys[this.getMappingKeyName(indexAccessNode)] : indicator;