Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
755ee4af
Commit
755ee4af
authored
Mar 24, 2020
by
aniket-engg
Committed by
Aniket
Mar 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
suggested changes done
parent
aee19d30
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
65 deletions
+79
-65
index.ts
remix-analyzer/src/solidity-analyzer/index.ts
+17
-2
abstractAstView.ts
...analyzer/src/solidity-analyzer/modules/abstractAstView.ts
+37
-38
assignAndCompare.ts
...nalyzer/src/solidity-analyzer/modules/assignAndCompare.ts
+1
-1
gasCosts.ts
remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts
+1
-1
similarVariableNames.ts
...zer/src/solidity-analyzer/modules/similarVariableNames.ts
+1
-1
tsconfig.json
remix-analyzer/tsconfig.json
+22
-22
No files found.
remix-analyzer/src/solidity-analyzer/index.ts
View file @
755ee4af
...
...
@@ -10,7 +10,13 @@ type ModuleObj = {
export
default
class
staticAnalysisRunner
{
run
(
compilationResult
:
CompilationResult
,
toRun
:
any
[],
callback
:
((
reports
:
AnalysisReport
[])
=>
void
)):
void
{
/**
* Run analysis (Used by IDE)
* @param compilationResult contract compilation result
* @param toRun module indexes (compiled from remix IDE)
* @param callback callback
*/
run
(
compilationResult
:
CompilationResult
,
toRun
:
number
[],
callback
:
((
reports
:
AnalysisReport
[])
=>
void
)):
void
{
const
modules
:
ModuleObj
[]
=
toRun
.
map
((
i
)
=>
{
const
m
:
AnalyzerModule
=
this
.
modules
()[
i
]
return
{
'name'
:
m
.
name
,
'mod'
:
m
}
...
...
@@ -18,10 +24,16 @@ export default class staticAnalysisRunner {
this
.
runWithModuleList
(
compilationResult
,
modules
,
callback
)
}
/**
* Run analysis passing list of modules to run
* @param compilationResult contract compilation result
* @param modules analysis module
* @param callback callback
*/
runWithModuleList
(
compilationResult
:
CompilationResult
,
modules
:
ModuleObj
[],
callback
:
((
reports
:
AnalysisReport
[])
=>
void
)):
void
{
let
reports
:
AnalysisReport
[]
=
[]
// Also provide convenience analysis via the AST walker.
const
walker
:
AstWalker
=
new
AstWalker
()
const
walker
=
new
AstWalker
()
for
(
let
k
in
compilationResult
.
sources
)
{
walker
.
walkFull
(
compilationResult
.
sources
[
k
].
ast
,
(
node
:
any
)
=>
{
...
...
@@ -55,6 +67,9 @@ export default class staticAnalysisRunner {
callback
(
reports
)
}
/**
* Get list of all analysis modules
*/
modules
():
any
[]
{
return
list
}
...
...
remix-analyzer/src/solidity-analyzer/modules/abstractAstView.ts
View file @
755ee4af
import
{
getStateVariableDeclarationsFromContractNode
,
getInheritsFromName
,
getContractName
,
getFunctionOrModifierDefinitionParameterPart
,
getType
,
getDeclaredVariableName
,
getFunctionDefinitionReturnParameterPart
}
from
'./staticAnalysisCommon'
import
{
AstWalker
}
from
'remix-astwalker'
import
{
FunctionDefinitionAstNode
,
ParameterListAstNode
,
ModifierDefinitionAstNode
,
ContractHLAst
,
VariableDeclarationAstNode
,
FunctionHLAst
,
ContractDefinitionAstNode
,
ReportObj
,
ReportFunction
,
VisitFunction
,
ModifierHLAst
,
CompilationResult
}
from
'types'
import
{
FunctionDefinitionAstNode
,
ParameterListAstNode
,
ModifierDefinitionAstNode
,
ContractHLAst
,
VariableDeclarationAstNode
,
FunctionHLAst
,
ReportObj
,
ReportFunction
,
VisitFunction
,
ModifierHLAst
,
CompilationResult
}
from
'types'
type
WrapFunction
=
((
contracts
:
ContractHLAst
[],
isSameName
:
boolean
)
=>
ReportObj
[])
...
...
@@ -47,10 +48,9 @@ export default class abstractAstView {
* @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.
*/
build_visit
(
relevantNodeFilter
:
((
node
:
any
)
=>
boolean
)):
VisitFunction
{
const
that
:
abstractAstView
=
this
return
function
(
node
:
any
)
{
return
(
node
:
any
)
=>
{
if
(
node
.
nodeType
===
"ContractDefinition"
)
{
th
at
.
setCurrentContract
(
that
,
{
th
is
.
setCurrentContract
(
{
node
:
node
,
functions
:
[],
relevantNodes
:
[],
...
...
@@ -59,40 +59,40 @@ export default class abstractAstView {
stateVariables
:
getStateVariableDeclarationsFromContractNode
(
node
)
})
}
else
if
(
node
.
nodeType
===
"InheritanceSpecifier"
)
{
const
currentContract
:
ContractHLAst
=
th
at
.
getCurrentContract
(
that
)
const
currentContract
:
ContractHLAst
=
th
is
.
getCurrentContract
(
)
const
inheritsFromName
:
string
=
getInheritsFromName
(
node
)
currentContract
.
inheritsFrom
.
push
(
inheritsFromName
)
}
else
if
(
node
.
nodeType
===
"FunctionDefinition"
)
{
th
at
.
setCurrentFunction
(
that
,
{
th
is
.
setCurrentFunction
(
{
node
:
node
,
relevantNodes
:
[],
modifierInvocations
:
[],
localVariables
:
th
at
.
getLocalVariables
(
node
),
parameters
:
th
at
.
getLocalParameters
(
node
),
returns
:
th
at
.
getReturnParameters
(
node
)
localVariables
:
th
is
.
getLocalVariables
(
node
),
parameters
:
th
is
.
getLocalParameters
(
node
),
returns
:
th
is
.
getReturnParameters
(
node
)
})
// push back relevant nodes to their the current fn if any
th
at
.
getCurrentContract
(
that
).
relevantNodes
.
map
((
item
)
=>
{
th
is
.
getCurrentContract
(
).
relevantNodes
.
map
((
item
)
=>
{
if
(
item
.
referencedDeclaration
===
node
.
id
)
{
th
at
.
getCurrentFunction
(
that
).
relevantNodes
.
push
(
item
.
node
)
th
is
.
getCurrentFunction
(
).
relevantNodes
.
push
(
item
.
node
)
}
})
}
else
if
(
node
.
nodeType
===
"ModifierDefinition"
)
{
th
at
.
setCurrentModifier
(
that
,
{
th
is
.
setCurrentModifier
(
{
node
:
node
,
relevantNodes
:
[],
localVariables
:
th
at
.
getLocalVariables
(
node
),
parameters
:
th
at
.
getLocalParameters
(
node
)
localVariables
:
th
is
.
getLocalVariables
(
node
),
parameters
:
th
is
.
getLocalParameters
(
node
)
})
}
else
if
(
node
.
nodeType
===
"ModifierInvocation"
)
{
if
(
!
th
at
.
isFunctionNotModifier
)
throw
new
Error
(
'abstractAstView.js: Found modifier invocation outside of function scope.'
)
th
at
.
getCurrentFunction
(
that
).
modifierInvocations
.
push
(
node
)
if
(
!
th
is
.
isFunctionNotModifier
)
throw
new
Error
(
'abstractAstView.js: Found modifier invocation outside of function scope.'
)
th
is
.
getCurrentFunction
(
).
modifierInvocations
.
push
(
node
)
}
else
if
(
relevantNodeFilter
(
node
))
{
let
scope
:
FunctionHLAst
|
ModifierHLAst
|
ContractHLAst
=
(
th
at
.
isFunctionNotModifier
)
?
that
.
getCurrentFunction
(
that
)
:
that
.
getCurrentModifier
(
that
)
let
scope
:
FunctionHLAst
|
ModifierHLAst
|
ContractHLAst
=
(
th
is
.
isFunctionNotModifier
)
?
this
.
getCurrentFunction
()
:
this
.
getCurrentModifier
(
)
if
(
scope
)
{
scope
.
relevantNodes
.
push
(
node
)
}
else
{
scope
=
th
at
.
getCurrentContract
(
that
)
// if we are not in a function scope, add the node to the contract scope
scope
=
th
is
.
getCurrentContract
(
)
// if we are not in a function scope, add the node to the contract scope
if
(
scope
&&
node
.
referencedDeclaration
)
{
scope
.
relevantNodes
.
push
({
referencedDeclaration
:
node
.
referencedDeclaration
,
node
:
node
})
}
...
...
@@ -102,10 +102,9 @@ export default class abstractAstView {
}
build_report
(
wrap
:
WrapFunction
):
ReportFunction
{
const
that
:
abstractAstView
=
this
return
function
(
compilationResult
:
CompilationResult
)
{
that
.
resolveStateVariablesInHierarchy
(
that
.
contracts
)
return
wrap
(
that
.
contracts
,
that
.
multipleContractsWithSameName
)
return
(
compilationResult
:
CompilationResult
)
=>
{
this
.
resolveStateVariablesInHierarchy
(
this
.
contracts
)
return
wrap
(
this
.
contracts
,
this
.
multipleContractsWithSameName
)
}
}
...
...
@@ -127,35 +126,35 @@ export default class abstractAstView {
})
}
private
setCurrentContract
(
that
:
abstractAstView
,
contract
:
ContractHLAst
):
void
{
private
setCurrentContract
(
contract
:
ContractHLAst
):
void
{
const
name
:
string
=
getContractName
(
contract
.
node
)
if
(
th
at
.
contracts
.
map
((
c
:
ContractHLAst
)
=>
getContractName
(
c
.
node
)).
filter
((
n
)
=>
n
===
name
).
length
>
0
)
{
if
(
th
is
.
contracts
.
map
((
c
:
ContractHLAst
)
=>
getContractName
(
c
.
node
)).
filter
((
n
)
=>
n
===
name
).
length
>
0
)
{
console
.
log
(
'abstractAstView.js: two or more contracts with the same name dectected, import aliases not supported at the moment'
)
th
at
.
multipleContractsWithSameName
=
true
th
is
.
multipleContractsWithSameName
=
true
}
th
at
.
currentContractIndex
=
(
that
.
contracts
.
push
(
contract
)
-
1
)
th
is
.
currentContractIndex
=
(
this
.
contracts
.
push
(
contract
)
-
1
)
}
private
setCurrentFunction
(
that
:
abstractAstView
,
func
:
FunctionHLAst
):
void
{
th
at
.
isFunctionNotModifier
=
true
th
at
.
currentFunctionIndex
=
(
that
.
getCurrentContract
(
that
).
functions
.
push
(
func
)
-
1
)
private
setCurrentFunction
(
func
:
FunctionHLAst
):
void
{
th
is
.
isFunctionNotModifier
=
true
th
is
.
currentFunctionIndex
=
(
this
.
getCurrentContract
(
).
functions
.
push
(
func
)
-
1
)
}
private
setCurrentModifier
(
that
,
modi
):
void
{
th
at
.
isFunctionNotModifier
=
false
th
at
.
currentModifierIndex
=
(
that
.
getCurrentContract
(
that
).
modifiers
.
push
(
modi
)
-
1
)
private
setCurrentModifier
(
modi
):
void
{
th
is
.
isFunctionNotModifier
=
false
th
is
.
currentModifierIndex
=
(
this
.
getCurrentContract
(
).
modifiers
.
push
(
modi
)
-
1
)
}
private
getCurrentContract
(
that
:
abstractAstView
):
ContractHLAst
{
return
th
at
.
contracts
[
that
.
currentContractIndex
]
private
getCurrentContract
():
ContractHLAst
{
return
th
is
.
contracts
[
this
.
currentContractIndex
]
}
private
getCurrentFunction
(
that
:
abstractAstView
):
FunctionHLAst
{
return
th
at
.
getCurrentContract
(
that
).
functions
[
that
.
currentFunctionIndex
]
private
getCurrentFunction
():
FunctionHLAst
{
return
th
is
.
getCurrentContract
().
functions
[
this
.
currentFunctionIndex
]
}
private
getCurrentModifier
(
that
:
abstractAstView
):
ModifierHLAst
{
return
th
at
.
getCurrentContract
(
that
).
modifiers
[
that
.
currentModifierIndex
]
private
getCurrentModifier
():
ModifierHLAst
{
return
th
is
.
getCurrentContract
().
modifiers
[
this
.
currentModifierIndex
]
}
private
getLocalParameters
(
funcNode
:
FunctionDefinitionAstNode
|
ModifierDefinitionAstNode
):
string
[]
{
...
...
remix-analyzer/src/solidity-analyzer/modules/assignAndCompare.ts
View file @
755ee4af
...
...
@@ -12,7 +12,7 @@ export default class assignAndCompare implements AnalyzerModule {
algorithm
:
ModuleAlgorithm
=
algorithm
.
EXACT
visit
(
node
:
BlockAstNode
|
IfStatementAstNode
|
WhileStatementAstNode
|
ForStatementAstNode
):
void
{
if
(
node
&&
node
.
nodeType
&&
isSubScopeWithTopLevelUnAssignedBinOp
(
node
))
getUnAssignedTopLevelBinOps
(
node
).
forEach
((
n
)
=>
this
.
warningNodes
.
push
(
n
))
if
(
node
?
.
nodeType
&&
isSubScopeWithTopLevelUnAssignedBinOp
(
node
))
getUnAssignedTopLevelBinOps
(
node
).
forEach
((
n
)
=>
this
.
warningNodes
.
push
(
n
))
}
report
(
compilationResults
:
CompilationResult
):
ReportObj
[]
{
...
...
remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts
View file @
755ee4af
...
...
@@ -3,7 +3,7 @@ import { default as algorithm } from './algorithmCategories'
import
AbstractAst
from
'./abstractAstView'
import
{
ModuleAlgorithm
,
ModuleCategory
,
ReportObj
,
CompilationResult
,
CompiledContractObj
,
CompiledContract
,
VisitFunction
,
AnalyzerModule
}
from
'./../../types'
type
VisitedContract
=
{
interface
VisitedContract
{
name
:
string
object
:
CompiledContract
file
:
string
...
...
remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts
View file @
755ee4af
...
...
@@ -6,7 +6,7 @@ import { get } from 'fast-levenshtein'
import
{
util
}
from
'remix-lib'
import
{
AnalyzerModule
,
ModuleAlgorithm
,
ModuleCategory
,
ReportObj
,
ContractHLAst
,
FunctionHLAst
,
VariableDeclarationAstNode
,
VisitFunction
,
ReportFunction
}
from
'./../../types'
type
SimilarRecord
=
{
interface
SimilarRecord
{
var1
:
string
var2
:
string
distance
:
number
...
...
remix-analyzer/tsconfig.json
View file @
755ee4af
{
"include"
:
[
"src"
,
"index.ts"
],
"compilerOptions"
:
{
"target"
:
"es6"
,
/*
Specify
ECMAScript
target
version
:
'ES
3
'
(default)
,
'ES
5
'
,
'ES
2015
'
,
'ES
2016
'
,
'ES
2017
'
,
'ES
2018
'
or
'ESNEXT'.
*/
"module"
:
"commonjs"
,
/*
Specify
module
code
generation
:
'none'
,
'commonjs'
,
'amd'
,
'system'
,
'umd'
,
'es
2015
'
,
or
'ESNext'.
*/
"lib"
:
[
"dom"
,
"es2018"
],
/*
Specify
library
files
to
be
included
in
the
compilation.
*/
"declaration"
:
true
,
/*
Generates
corresponding
'.d.ts'
file.
*/
"sourceMap"
:
true
,
/*
Generates
corresponding
'.map'
file.
*/
"outDir"
:
"./dist"
,
/*
Redirect
output
structure
to
the
directory.
*/
/*
Strict
Type-Checking
Options
*/
"strict"
:
true
,
/*
Enable
all
strict
type-checking
options.
*/
"noImplicitAny"
:
false
,
/*
Raise
error
on
expressions
and
declarations
with
an
implied
'any'
type.
*/
/*
Module
Resolution
Options
*/
"baseUrl"
:
"./src"
,
/*
Base
directory
to
resolve
non-absolute
module
names.
*/
"paths"
:
{
"remix-analyzer"
:
[
"./"
]
},
/*
A
series
of
entries
which
re-map
imports
to
lookup
locations
relative
to
the
'baseUrl'.
*/
"typeRoots"
:
[
"./@types"
,
"./node_modules/@types"
],
"esModuleInterop"
:
true
,
/*
Enables
emit
interoperability
between
CommonJS
and
ES
Modules
via
creation
of
namespace
objects
for
all
imports.
Implies
'allowSyntheticDefaultImports'.
*/
/*
Experimental
Options
*/
"experimentalDecorators"
:
false
,
/*
Enables
experimental
support
for
ES
7
decorators.
*/
}
"include"
:
[
"src"
,
"index.ts"
],
"compilerOptions"
:
{
"target"
:
"es6"
,
/*
Specify
ECMAScript
target
version
:
'ES
3
'
(default)
,
'ES
5
'
,
'ES
2015
'
,
'ES
2016
'
,
'ES
2017
'
,
'ES
2018
'
or
'ESNEXT'.
*/
"module"
:
"commonjs"
,
/*
Specify
module
code
generation
:
'none'
,
'commonjs'
,
'amd'
,
'system'
,
'umd'
,
'es
2015
'
,
or
'ESNext'.
*/
"lib"
:
[
"dom"
,
"es2018"
],
/*
Specify
library
files
to
be
included
in
the
compilation.
*/
"declaration"
:
true
,
/*
Generates
corresponding
'.d.ts'
file.
*/
"sourceMap"
:
true
,
/*
Generates
corresponding
'.map'
file.
*/
"outDir"
:
"./dist"
,
/*
Redirect
output
structure
to
the
directory.
*/
/*
Strict
Type-Checking
Options
*/
"strict"
:
true
,
/*
Enable
all
strict
type-checking
options.
*/
"noImplicitAny"
:
false
,
/*
Raise
error
on
expressions
and
declarations
with
an
implied
'any'
type.
*/
/*
Module
Resolution
Options
*/
"baseUrl"
:
"./src"
,
/*
Base
directory
to
resolve
non-absolute
module
names.
*/
"paths"
:
{
"remix-analyzer"
:
[
"./"
]
},
/*
A
series
of
entries
which
re-map
imports
to
lookup
locations
relative
to
the
'baseUrl'.
*/
"typeRoots"
:
[
"./@types"
,
"./node_modules/@types"
],
"esModuleInterop"
:
true
,
/*
Enables
emit
interoperability
between
CommonJS
and
ES
Modules
via
creation
of
namespace
objects
for
all
imports.
Implies
'allowSyntheticDefaultImports'.
*/
/*
Experimental
Options
*/
"experimentalDecorators"
:
false
,
/*
Enables
experimental
support
for
ES
7
decorators.
*/
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment