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
30fb3d54
Commit
30fb3d54
authored
May 20, 2020
by
aniket-engg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils
parent
1ef62d1d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
51 deletions
+51
-51
gasCosts.ts
remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts
+3
-50
staticAnalysisCommon.ts
...zer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
+48
-1
No files found.
remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts
View file @
30fb3d54
import
{
default
as
category
}
from
'./categories'
import
{
default
as
algorithm
}
from
'./algorithmCategories'
import
{
getFunctionDefinitionName
,
helpers
,
isVariableTurnedIntoGetter
}
from
'./staticAnalysisCommon'
import
{
getFunctionDefinitionName
,
helpers
,
isVariableTurnedIntoGetter
,
getSplittedTypeDesc
}
from
'./staticAnalysisCommon'
import
{
ModuleAlgorithm
,
ModuleCategory
,
ReportObj
,
CompilationResult
,
CompiledContract
,
AnalyzerModule
,
FunctionDefinitionAstNode
,
VariableDeclarationAstNode
,
CompiledContractObj
}
from
'./../../types'
FunctionDefinitionAstNode
,
VariableDeclarationAstNode
}
from
'./../../types'
export
default
class
gasCosts
implements
AnalyzerModule
{
name
:
string
=
`Gas costs: `
...
...
@@ -23,7 +23,7 @@ export default class gasCosts implements AnalyzerModule {
let
signature
:
string
;
if
(
node
.
nodeType
===
'FunctionDefinition'
){
const
functionName
:
string
=
getFunctionDefinitionName
(
node
)
signature
=
helpers
.
buildAbiSignature
(
functionName
,
this
.
getSplittedTypeDesc
(
node
,
compilationResults
.
contracts
))
signature
=
helpers
.
buildAbiSignature
(
functionName
,
getSplittedTypeDesc
(
node
,
compilationResults
.
contracts
))
}
else
signature
=
node
.
name
+
'()'
...
...
@@ -62,53 +62,6 @@ export default class gasCosts implements AnalyzerModule {
return
report
}
// To create the method signature similar to contract.evm.gasEstimates.external object
// For address payable, return address
private
getSplittedTypeDesc
(
node
:
FunctionDefinitionAstNode
,
contracts
:
CompiledContractObj
):
string
[]
{
return
node
.
parameters
.
parameters
.
map
((
varNode
,
varIndex
)
=>
{
let
finalTypeString
;
const
typeString
=
varNode
.
typeDescriptions
.
typeString
if
(
typeString
.
includes
(
'struct'
))
{
const
paramsCount
=
node
.
parameters
.
parameters
.
length
const
fnName
=
node
.
name
for
(
const
filename
in
contracts
)
{
for
(
const
contractName
in
contracts
[
filename
])
{
const
methodABI
=
contracts
[
filename
][
contractName
].
abi
.
find
(
e
=>
e
.
name
===
fnName
&&
e
.
inputs
?.
length
&&
e
.
inputs
[
varIndex
][
'type'
].
includes
(
'tuple'
)
&&
e
.
inputs
[
varIndex
][
'internalType'
]
===
typeString
)
if
(
methodABI
&&
methodABI
.
inputs
)
{
const
inputs
=
methodABI
.
inputs
[
varIndex
]
let
typeStr
=
this
.
getTypeStringFromComponents
(
inputs
[
'components'
])
finalTypeString
=
typeStr
+
inputs
[
'type'
].
replace
(
'tuple'
,
''
)
}
}
}
}
else
finalTypeString
=
typeString
.
split
(
' '
)[
0
]
return
finalTypeString
})
}
private
getTypeStringFromComponents
(
components
:
any
[])
{
let
typeString
=
'('
for
(
var
i
=
0
;
i
<
components
.
length
;
i
++
)
{
const
param
=
components
[
i
]
if
(
param
.
type
.
includes
(
'tuple'
)
&&
param
.
components
&&
param
.
components
.
length
>
0
){
typeString
=
typeString
+
this
.
getTypeStringFromComponents
(
param
.
components
)
typeString
=
typeString
+
param
.
type
.
replace
(
'tuple'
,
''
)
}
else
typeString
=
typeString
+
param
.
type
if
(
i
!==
components
.
length
-
1
)
typeString
=
typeString
+
','
}
typeString
=
typeString
+
')'
return
typeString
}
private
checkMethodGas
(
contract
:
CompiledContract
,
methodSignature
:
string
):
Record
<
string
,
any
>
|
undefined
{
if
(
contract
.
evm
&&
contract
.
evm
.
gasEstimates
&&
contract
.
evm
.
gasEstimates
.
external
)
{
if
(
methodSignature
===
'()'
)
{
...
...
remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts
View file @
30fb3d54
...
...
@@ -3,7 +3,7 @@
import
{
FunctionDefinitionAstNode
,
ModifierDefinitionAstNode
,
ParameterListAstNode
,
ForStatementAstNode
,
WhileStatementAstNode
,
VariableDeclarationAstNode
,
ContractDefinitionAstNode
,
InheritanceSpecifierAstNode
,
MemberAccessAstNode
,
BinaryOperationAstNode
,
FunctionCallAstNode
,
ExpressionStatementAstNode
,
UnaryOperationAstNode
,
IdentifierAstNode
,
IndexAccessAstNode
,
BlockAstNode
,
AssignmentAstNode
,
InlineAssemblyAstNode
,
IfStatementAstNode
}
from
"types"
IdentifierAstNode
,
IndexAccessAstNode
,
BlockAstNode
,
AssignmentAstNode
,
InlineAssemblyAstNode
,
IfStatementAstNode
,
CompiledContractObj
}
from
"types"
import
{
util
}
from
'remix-lib'
type
SpecialObjDetail
=
{
...
...
@@ -1077,6 +1077,52 @@ function buildAbiSignature (funName: string, paramTypes: any[]): string {
return
funName
+
'('
+
util
.
concatWithSeperator
(
paramTypes
,
','
)
+
')'
}
// To create the method signature similar to contract.evm.gasEstimates.external object
// For address payable, return address
function
getSplittedTypeDesc
(
node
:
FunctionDefinitionAstNode
,
contracts
:
CompiledContractObj
):
string
[]
{
return
node
.
parameters
.
parameters
.
map
((
varNode
,
varIndex
)
=>
{
let
finalTypeString
;
const
typeString
=
varNode
.
typeDescriptions
.
typeString
if
(
typeString
.
includes
(
'struct'
))
{
const
paramsCount
=
node
.
parameters
.
parameters
.
length
const
fnName
=
node
.
name
for
(
const
filename
in
contracts
)
{
for
(
const
contractName
in
contracts
[
filename
])
{
const
methodABI
=
contracts
[
filename
][
contractName
].
abi
.
find
(
e
=>
e
.
name
===
fnName
&&
e
.
inputs
?.
length
&&
e
.
inputs
[
varIndex
][
'type'
].
includes
(
'tuple'
)
&&
e
.
inputs
[
varIndex
][
'internalType'
]
===
typeString
)
if
(
methodABI
&&
methodABI
.
inputs
)
{
const
inputs
=
methodABI
.
inputs
[
varIndex
]
let
typeStr
=
getTypeStringFromComponents
(
inputs
[
'components'
])
finalTypeString
=
typeStr
+
inputs
[
'type'
].
replace
(
'tuple'
,
''
)
}
}
}
}
else
finalTypeString
=
typeString
.
split
(
' '
)[
0
]
return
finalTypeString
})
}
function
getTypeStringFromComponents
(
components
:
any
[])
{
let
typeString
=
'('
for
(
var
i
=
0
;
i
<
components
.
length
;
i
++
)
{
const
param
=
components
[
i
]
if
(
param
.
type
.
includes
(
'tuple'
)
&&
param
.
components
&&
param
.
components
.
length
>
0
){
typeString
=
typeString
+
getTypeStringFromComponents
(
param
.
components
)
typeString
=
typeString
+
param
.
type
.
replace
(
'tuple'
,
''
)
}
else
typeString
=
typeString
+
param
.
type
if
(
i
!==
components
.
length
-
1
)
typeString
=
typeString
+
','
}
typeString
=
typeString
+
')'
return
typeString
}
const
helpers
=
{
expressionTypeDescription
,
nodeType
,
...
...
@@ -1112,6 +1158,7 @@ export {
getFunctionOrModifierDefinitionParameterPart
,
getFunctionDefinitionReturnParameterPart
,
getUnAssignedTopLevelBinOps
,
getSplittedTypeDesc
,
// #################### Complex Node Identification
isDeleteOfDynamicArray
,
...
...
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