Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Remix-analyzer: LegacyAST to AST #1427

Merged
merged 24 commits into from
Mar 24, 2020
Merged

Conversation

Aniket-Engg
Copy link
Collaborator

@Aniket-Engg Aniket-Engg commented Feb 20, 2020

  • Analysis is now performed on latest AST introduced in solidity 0.4.12
  • All modules are updated to work according to latest AST
  • Specific types of AST nodes are defined
  • Tests are also updated to support module & AST updates

@Aniket-Engg Aniket-Engg added the WIP Work In Progress label Feb 20, 2020
@Aniket-Engg Aniket-Engg removed the WIP Work In Progress label Mar 17, 2020
remix-analyzer/src/solidity-analyzer/index.ts Show resolved Hide resolved
remix-analyzer/src/solidity-analyzer/index.ts Outdated Show resolved Hide resolved
runWithModuleList (compilationResult, modules, callback) {
let reports: any[] = []
runWithModuleList (compilationResult: CompilationResult, modules: ModuleObj[], callback: ((reports: AnalysisReport[]) => void)): void {
let reports: AnalysisReport[] = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem like you're reassigning the value later (just mutate it). You can use const

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentContractIndex: number = -1
currentFunctionIndex: number = -1
currentModifierIndex: number = -1
isFunctionNotModifier: boolean = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For "number", "string" & "boolean" you don't need to hardtype the property, it's going to be guessed by typescript

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

const inheritsFromName = getInheritsFromName(node)
} else if (node.nodeType === "InheritanceSpecifier") {
const currentContract: ContractHLAst = that.getCurrentContract(that)
const inheritsFromName: string = getInheritsFromName(node)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method getInheritsFromName shld be defined to return a string so you don't have to hardtype it.

private resolveStateVariablesInHierarchy (contracts) {
contracts.map((c) => {
private resolveStateVariablesInHierarchy (contracts: ContractHLAst[]): void {
contracts.map((c: ContractHLAst) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to hardtype this neither, .map() is smart enough

Copy link
Collaborator

@GrandSchtroumpf GrandSchtroumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if (this.isPotentialVulnerableFunction(func, this.getContext(callGraph, contract, func))) {
const funcName = getFullQuallyfiedFuncDefinitionIdent(contract.node, func.node, func.parameters)
let comments = (hasModifiers) ? 'Note: Modifiers are currently not considered by this static analysis.' : ''
const funcName: string = getFullQuallyfiedFuncDefinitionIdent(contract.node, func.node, func.parameters)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as abov about typing the return of getFullQuallyfiedFuncDefinitionIdent to string instead of hardtyping it here

const warnings: ReportObj[] = []
const hasModifiers = contracts.some((item) => item.modifiers.length > 0)
const hasModifiers: boolean = contracts.some((item) => item.modifiers.length > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't ned to hardtype it here. ".some" always returns a boolean

remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts Outdated Show resolved Hide resolved
* stop visiting when cb return true
* @param {Function} cb - callback
*/
// @TODO has been copied from remix-ide repo ! should fix that soon !
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create an issue for it & reference the id of the issue here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this TODO is there before this PR. not sure what to be fixed :|

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XD @yann300 any idea about that ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this message refers to the double loop for ( for (
but the Blame github function does'nt really help finding the reason..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw looks like this stop visiting when a report is returned. Is that right? cause that way it seems some other contracts will not be checked at all...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in the devdoc, it is written like that is an expected behaviour. Not sure if we need to create an issue to know what is the issue 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah probably not in this PR, but we need to understand why it's being done like that...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aniket-Engg
Copy link
Collaborator Author

I have run remix-ide nightwatch_local_staticAnalysis tests locally by integrating this PR. It run fine.

@Aniket-Engg Aniket-Engg merged commit 755ee4a into master Mar 24, 2020
@Aniket-Engg Aniket-Engg deleted the analyzer-legacyAST-to-AST branch March 24, 2020 11:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants