Skip to content

Commit 0a95c8b

Browse files
authored
Merge pull request #861 from ethereum/libsLinting
libs linting fix
2 parents 2e6d289 + 14b4157 commit 0a95c8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1740
-1772
lines changed

libs/remix-analyzer/.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"extends": "../../.eslintrc",
33
"rules": {
44
"@typescript-eslint/no-explicit-any": "off",
5-
"@typescript-eslint/no-unused-vars": "off"
5+
"@typescript-eslint/no-unused-vars": "off",
6+
"no-unused-vars": "off",
7+
"dot-notation": "off"
68
},
79
"ignorePatterns": ["!**/*"]
810
}

libs/remix-analyzer/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default as CodeAnalysis} from './solidity-analyzer'
1+
export { default as CodeAnalysis } from './solidity-analyzer'

libs/remix-analyzer/src/solidity-analyzer/index.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type ModuleObj = {
99
}
1010

1111
export default class staticAnalysisRunner {
12-
1312
/**
1413
* Run analysis (Used by IDE)
1514
* @param compilationResult contract compilation result
@@ -18,9 +17,9 @@ export default class staticAnalysisRunner {
1817
*/
1918
run (compilationResult: CompilationResult, toRun: number[], callback: ((reports: AnalysisReport[]) => void)): void {
2019
const modules: ModuleObj[] = toRun.map((i) => {
21-
const module = this.modules()[i]
22-
const m = new module()
23-
return { 'name': m.name, 'mod': m }
20+
const Module = this.modules()[i]
21+
const m = new Module()
22+
return { name: m.name, mod: m }
2423
})
2524
this.runWithModuleList(compilationResult, modules, callback)
2625
}
@@ -36,21 +35,21 @@ export default class staticAnalysisRunner {
3635
// Also provide convenience analysis via the AST walker.
3736
const walker = new AstWalker()
3837
for (const k in compilationResult.sources) {
39-
walker.walkFull(compilationResult.sources[k].ast,
38+
walker.walkFull(compilationResult.sources[k].ast,
4039
(node: any) => {
41-
modules.map((item: ModuleObj) => {
42-
if (item.mod.visit !== undefined) {
43-
try {
44-
item.mod.visit(node)
45-
} catch (e) {
46-
reports.push({
47-
name: item.name, report: [{ warning: 'INTERNAL ERROR in module ' + item.name + ' ' + e.message, error: e.stack }]
48-
})
40+
modules.map((item: ModuleObj) => {
41+
if (item.mod.visit !== undefined) {
42+
try {
43+
item.mod.visit(node)
44+
} catch (e) {
45+
reports.push({
46+
name: item.name, report: [{ warning: 'INTERNAL ERROR in module ' + item.name + ' ' + e.message, error: e.stack }]
47+
})
48+
}
4949
}
50-
}
51-
})
52-
return true
53-
}
50+
})
51+
return true
52+
}
5453
)
5554
}
5655

libs/remix-analyzer/src/solidity-analyzer/modules/abstractAstView.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { getStateVariableDeclarationsFromContractNode, getInheritsFromName, getContractName,
2-
getFunctionOrModifierDefinitionParameterPart, getType, getDeclaredVariableName,
3-
getFunctionDefinitionReturnParameterPart, getCompilerVersion } from './staticAnalysisCommon'
1+
import {
2+
getStateVariableDeclarationsFromContractNode, getInheritsFromName, getContractName,
3+
getFunctionOrModifierDefinitionParameterPart, getType, getDeclaredVariableName,
4+
getFunctionDefinitionReturnParameterPart, getCompilerVersion
5+
} from './staticAnalysisCommon'
46
import { AstWalker } from '@remix-project/remix-astwalker'
5-
import { FunctionDefinitionAstNode, ParameterListAstNode, ModifierDefinitionAstNode, ContractHLAst, VariableDeclarationAstNode,
6-
FunctionHLAst, ReportObj, ReportFunction, VisitFunction, ModifierHLAst, CompilationResult } from '../../types'
7+
import {
8+
FunctionDefinitionAstNode, ParameterListAstNode, ModifierDefinitionAstNode, ContractHLAst, VariableDeclarationAstNode,
9+
FunctionHLAst, ReportObj, ReportFunction, VisitFunction, ModifierHLAst, CompilationResult
10+
} from '../../types'
711

812
type WrapFunction = ((contracts: ContractHLAst[], isSameName: boolean, version: string) => ReportObj[])
913

@@ -23,7 +27,7 @@ export default class abstractAstView {
2327
*/
2428
multipleContractsWithSameName = false
2529

26-
/**
30+
/**
2731
* Builds a higher level AST view. I creates a list with each contract as an object in it.
2832
* Example contractsOut:
2933
*
@@ -48,9 +52,10 @@ export default class abstractAstView {
4852
* @contractsOut {list} return list for high level AST view
4953
* @return {ASTNode -> void} returns a function that can be used as visit function for static analysis modules, to build up a higher level AST view for further analysis.
5054
*/
55+
// eslint-disable-next-line camelcase
5156
build_visit (relevantNodeFilter: ((node:any) => boolean)): VisitFunction {
5257
return (node: any) => {
53-
if (node.nodeType === "ContractDefinition") {
58+
if (node.nodeType === 'ContractDefinition') {
5459
this.setCurrentContract({
5560
node: node,
5661
functions: [],
@@ -59,11 +64,11 @@ export default class abstractAstView {
5964
inheritsFrom: [],
6065
stateVariables: getStateVariableDeclarationsFromContractNode(node)
6166
})
62-
} else if (node.nodeType === "InheritanceSpecifier") {
67+
} else if (node.nodeType === 'InheritanceSpecifier') {
6368
const currentContract: ContractHLAst = this.getCurrentContract()
6469
const inheritsFromName: string = getInheritsFromName(node)
6570
currentContract.inheritsFrom.push(inheritsFromName)
66-
} else if (node.nodeType === "FunctionDefinition") {
71+
} else if (node.nodeType === 'FunctionDefinition') {
6772
this.setCurrentFunction({
6873
node: node,
6974
relevantNodes: [],
@@ -78,14 +83,14 @@ export default class abstractAstView {
7883
this.getCurrentFunction().relevantNodes.push(item.node)
7984
}
8085
})
81-
} else if (node.nodeType === "ModifierDefinition") {
86+
} else if (node.nodeType === 'ModifierDefinition') {
8287
this.setCurrentModifier({
8388
node: node,
8489
relevantNodes: [],
8590
localVariables: this.getLocalVariables(node),
8691
parameters: this.getLocalParameters(node)
8792
})
88-
} else if (node.nodeType === "ModifierInvocation") {
93+
} else if (node.nodeType === 'ModifierInvocation') {
8994
if (!this.isFunctionNotModifier) throw new Error('abstractAstView.js: Found modifier invocation outside of function scope.')
9095
this.getCurrentFunction().modifierInvocations.push(node)
9196
} else if (relevantNodeFilter(node)) {
@@ -102,6 +107,7 @@ export default class abstractAstView {
102107
}
103108
}
104109

110+
// eslint-disable-next-line camelcase
105111
build_report (wrap: WrapFunction): ReportFunction {
106112
// eslint-disable-next-line @typescript-eslint/no-unused-vars
107113
return (compilationResult: CompilationResult) => {
@@ -176,7 +182,7 @@ export default class abstractAstView {
176182
private getLocalVariables (funcNode: ParameterListAstNode): VariableDeclarationAstNode[] {
177183
const locals: VariableDeclarationAstNode[] = []
178184
new AstWalker().walkFull(funcNode, (node: any) => {
179-
if (node.nodeType === "VariableDeclaration") locals.push(node)
185+
if (node.nodeType === 'VariableDeclaration') locals.push(node)
180186
return true
181187
})
182188
return locals

libs/remix-analyzer/src/solidity-analyzer/modules/assignAndCompare.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { default as category } from './categories'
1+
import category from './categories'
22
import { isSubScopeWithTopLevelUnAssignedBinOp, getUnAssignedTopLevelBinOps } from './staticAnalysisCommon'
3-
import { default as algorithm } from './algorithmCategories'
4-
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, BlockAstNode, IfStatementAstNode,
5-
WhileStatementAstNode, ForStatementAstNode, CompilationResult, ExpressionStatementAstNode, SupportedVersion} from './../../types'
3+
import algorithm from './algorithmCategories'
4+
import {
5+
AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, BlockAstNode, IfStatementAstNode,
6+
WhileStatementAstNode, ForStatementAstNode, CompilationResult, ExpressionStatementAstNode, SupportedVersion
7+
} from './../../types'
68

79
export default class assignAndCompare implements AnalyzerModule {
810
warningNodes: ExpressionStatementAstNode[] = []
9-
name = `Result not used: `
10-
description = `The result of an operation not used`
11+
name = 'Result not used: '
12+
description = 'The result of an operation not used'
1113
category: ModuleCategory = category.MISC
1214
algorithm: ModuleAlgorithm = algorithm.EXACT
1315
version: SupportedVersion = {

libs/remix-analyzer/src/solidity-analyzer/modules/blockBlockhash.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { default as category } from './categories'
1+
import category from './categories'
22
import { isBlockBlockHashAccess } from './staticAnalysisCommon'
3-
import { default as algorithm } from './algorithmCategories'
4-
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, FunctionCallAstNode, SupportedVersion} from './../../types'
3+
import algorithm from './algorithmCategories'
4+
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, FunctionCallAstNode, SupportedVersion } from './../../types'
55

66
export default class blockBlockhash implements AnalyzerModule {
77
warningNodes: FunctionCallAstNode[] = []
8-
name = `Block hash: `
9-
description = `Can be influenced by miners`
8+
name = 'Block hash: '
9+
description = 'Can be influenced by miners'
1010
category: ModuleCategory = category.SECURITY
1111
algorithm: ModuleAlgorithm = algorithm.EXACT
1212
version: SupportedVersion = {
@@ -30,4 +30,3 @@ export default class blockBlockhash implements AnalyzerModule {
3030
})
3131
}
3232
}
33-

libs/remix-analyzer/src/solidity-analyzer/modules/blockTimestamp.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
import { default as category } from './categories'
1+
import category from './categories'
22
import { isNowAccess, isBlockTimestampAccess, getCompilerVersion } from './staticAnalysisCommon'
3-
import { default as algorithm } from './algorithmCategories'
4-
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, IdentifierAstNode,
5-
MemberAccessAstNode, SupportedVersion} from './../../types'
3+
import algorithm from './algorithmCategories'
4+
import {
5+
AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, IdentifierAstNode,
6+
MemberAccessAstNode, SupportedVersion
7+
} from './../../types'
68

79
export default class blockTimestamp implements AnalyzerModule {
810
warningNowNodes: IdentifierAstNode[] = []
911
warningblockTimestampNodes: MemberAccessAstNode[] = []
10-
name = `Block timestamp: `
11-
description = `Can be influenced by miners`
12+
name = 'Block timestamp: '
13+
description = 'Can be influenced by miners'
1214
category: ModuleCategory = category.SECURITY
1315
algorithm: ModuleAlgorithm = algorithm.EXACT
1416
version: SupportedVersion = {
1517
start: '0.4.12'
1618
}
1719

18-
visit (node: IdentifierAstNode | MemberAccessAstNode ): void {
19-
if (node.nodeType === "Identifier" && isNowAccess(node)) this.warningNowNodes.push(node)
20-
else if (node.nodeType === "MemberAccess" && isBlockTimestampAccess(node)) this.warningblockTimestampNodes.push(node)
20+
visit (node: IdentifierAstNode | MemberAccessAstNode): void {
21+
if (node.nodeType === 'Identifier' && isNowAccess(node)) this.warningNowNodes.push(node)
22+
else if (node.nodeType === 'MemberAccess' && isBlockTimestampAccess(node)) this.warningblockTimestampNodes.push(node)
2123
}
2224

2325
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
2-
SECURITY: {displayName: 'Security', id: 'SEC'},
3-
GAS: {displayName: 'Gas & Economy', id: 'GAS'},
4-
MISC: {displayName: 'Miscellaneous', id: 'MISC'},
5-
ERC: {displayName: 'ERC', id: 'ERC'}
2+
SECURITY: { displayName: 'Security', id: 'SEC' },
3+
GAS: { displayName: 'Gas & Economy', id: 'GAS' },
4+
MISC: { displayName: 'Miscellaneous', id: 'MISC' },
5+
ERC: { displayName: 'ERC', id: 'ERC' }
66
}

libs/remix-analyzer/src/solidity-analyzer/modules/checksEffectsInteraction.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import { default as category } from './categories'
2-
import { isInteraction, isEffect, isLocalCallGraphRelevantNode, getFullQuallyfiedFuncDefinitionIdent,
3-
isWriteOnStateVariable, isStorageVariableDeclaration, getFullQualifiedFunctionCallIdent, getCompilerVersion } from './staticAnalysisCommon'
4-
import { default as algorithm } from './algorithmCategories'
1+
import category from './categories'
2+
import {
3+
isInteraction, isEffect, isLocalCallGraphRelevantNode, getFullQuallyfiedFuncDefinitionIdent,
4+
isWriteOnStateVariable, isStorageVariableDeclaration, getFullQualifiedFunctionCallIdent, getCompilerVersion
5+
} from './staticAnalysisCommon'
6+
import algorithm from './algorithmCategories'
57
import { buildGlobalFuncCallGraph, resolveCallGraphSymbol, analyseCallGraph } from './functionCallGraph'
6-
import AbstractAst from './abstractAstView'
7-
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, ContractHLAst, VariableDeclarationAstNode,
8-
FunctionHLAst, ContractCallGraph, Context, FunctionCallAstNode, AssignmentAstNode, UnaryOperationAstNode,
9-
InlineAssemblyAstNode, ReportFunction, VisitFunction, FunctionCallGraph, SupportedVersion } from './../../types'
8+
import AbstractAst from './abstractAstView'
9+
import {
10+
AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, ContractHLAst, VariableDeclarationAstNode,
11+
FunctionHLAst, ContractCallGraph, Context, FunctionCallAstNode, AssignmentAstNode, UnaryOperationAstNode,
12+
InlineAssemblyAstNode, ReportFunction, VisitFunction, FunctionCallGraph, SupportedVersion
13+
} from './../../types'
1014

1115
export default class checksEffectsInteraction implements AnalyzerModule {
12-
name = `Check-effects-interaction: `
13-
description = `Potential reentrancy bugs`
16+
name = 'Check-effects-interaction: '
17+
description = 'Potential reentrancy bugs'
1418
category: ModuleCategory = category.SECURITY
1519
algorithm: ModuleAlgorithm = algorithm.HEURISTIC
1620
version: SupportedVersion = {
@@ -20,28 +24,28 @@ export default class checksEffectsInteraction implements AnalyzerModule {
2024
abstractAst: AbstractAst = new AbstractAst()
2125

2226
visit: VisitFunction = this.abstractAst.build_visit((node: FunctionCallAstNode | AssignmentAstNode | UnaryOperationAstNode | InlineAssemblyAstNode) => (
23-
node.nodeType === 'FunctionCall' && (isInteraction(node) || isLocalCallGraphRelevantNode(node))) ||
27+
node.nodeType === 'FunctionCall' && (isInteraction(node) || isLocalCallGraphRelevantNode(node))) ||
2428
((node.nodeType === 'Assignment' || node.nodeType === 'UnaryOperation' || node.nodeType === 'InlineAssembly') && isEffect(node)))
2529

2630
report: ReportFunction = this.abstractAst.build_report(this._report.bind(this))
27-
31+
2832
private _report (contracts: ContractHLAst[], multipleContractsWithSameName: boolean, version: string): ReportObj[] {
2933
const warnings: ReportObj[] = []
3034
const hasModifiers: boolean = contracts.some((item) => item.modifiers.length > 0)
3135
const callGraph: Record<string, ContractCallGraph> = buildGlobalFuncCallGraph(contracts)
3236
contracts.forEach((contract) => {
3337
contract.functions.forEach((func) => {
3438
func['changesState'] = this.checkIfChangesState(
35-
getFullQuallyfiedFuncDefinitionIdent(
36-
contract.node,
37-
func.node,
38-
func.parameters
39-
),
40-
this.getContext(
41-
callGraph,
42-
contract,
43-
func)
44-
)
39+
getFullQuallyfiedFuncDefinitionIdent(
40+
contract.node,
41+
func.node,
42+
func.parameters
43+
),
44+
this.getContext(
45+
callGraph,
46+
contract,
47+
func)
48+
)
4549
})
4650
contract.functions.forEach((func: FunctionHLAst) => {
4751
if (this.isPotentialVulnerableFunction(func, this.getContext(callGraph, contract, func))) {
@@ -50,7 +54,7 @@ export default class checksEffectsInteraction implements AnalyzerModule {
5054
comments += (multipleContractsWithSameName) ? 'Note: Import aliases are currently not supported by this static analysis.' : ''
5155
warnings.push({
5256
warning: `Potential violation of Checks-Effects-Interaction pattern in ${funcName}: Could potentially lead to re-entrancy vulnerability. ${comments}`,
53-
location: func.node['src'],
57+
location: func.node.src,
5458
more: `https://solidity.readthedocs.io/en/${version}/security-considerations.html#re-entrancy`
5559
})
5660
}
@@ -92,4 +96,3 @@ export default class checksEffectsInteraction implements AnalyzerModule {
9296
return analyseCallGraph(context.callGraph, startFuncName, context, (node: any, context: Context) => isWriteOnStateVariable(node, context.stateVariables))
9397
}
9498
}
95-

0 commit comments

Comments
 (0)