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
1ef62d1d
Commit
1ef62d1d
authored
May 19, 2020
by
aniket-engg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tuple handling
parent
95f68f04
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
6 deletions
+48
-6
gasCosts.ts
remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts
+44
-4
staticAnalysisIntegration-test-0.5.0.ts
...zer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts
+2
-2
ballot.sol
...zer/test/analysis/test-contracts/solidity-v0.5/ballot.sol
+2
-0
No files found.
remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts
View file @
1ef62d1d
...
...
@@ -2,7 +2,7 @@ import { default as category } from './categories'
import
{
default
as
algorithm
}
from
'./algorithmCategories'
import
{
getFunctionDefinitionName
,
helpers
,
isVariableTurnedIntoGetter
}
from
'./staticAnalysisCommon'
import
{
ModuleAlgorithm
,
ModuleCategory
,
ReportObj
,
CompilationResult
,
CompiledContract
,
AnalyzerModule
,
FunctionDefinitionAstNode
,
VariableDeclarationAstNode
}
from
'./../../types'
FunctionDefinitionAstNode
,
VariableDeclarationAstNode
,
CompiledContractObj
}
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
,
node
.
parameters
.
parameters
.
map
(
this
.
getSplittedTypeDesc
))
signature
=
helpers
.
buildAbiSignature
(
functionName
,
this
.
getSplittedTypeDesc
(
node
,
compilationResults
.
contracts
))
}
else
signature
=
node
.
name
+
'()'
...
...
@@ -64,8 +64,48 @@ export default class gasCosts implements AnalyzerModule {
// To create the method signature similar to contract.evm.gasEstimates.external object
// For address payable, return address
private
getSplittedTypeDesc
(
node
:
VariableDeclarationAstNode
):
string
{
return
node
.
typeDescriptions
.
typeString
.
split
(
' '
)[
0
]
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
}
...
...
remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts
View file @
1ef62d1d
...
...
@@ -125,7 +125,7 @@ test('Integration test constantFunctions module', function (t: test.Test) {
const
lengthCheck
:
Record
<
string
,
number
>
=
{
'KingOfTheEtherThrone.sol'
:
0
,
'assembly.sol'
:
0
,
'ballot.sol'
:
0
,
'ballot.sol'
:
1
,
'ballot_reentrant.sol'
:
0
,
'ballot_withoutWarnings.sol'
:
0
,
'cross_contract.sol'
:
0
,
...
...
@@ -233,7 +233,7 @@ test('Integration test gasCosts module', function (t: test.Test) {
const
lengthCheck
:
Record
<
string
,
number
>
=
{
'KingOfTheEtherThrone.sol'
:
2
,
'assembly.sol'
:
2
,
'ballot.sol'
:
3
,
'ballot.sol'
:
4
,
'ballot_reentrant.sol'
:
2
,
'ballot_withoutWarnings.sol'
:
0
,
'cross_contract.sol'
:
1
,
...
...
remix-analyzer/test/analysis/test-contracts/solidity-v0.5/ballot.sol
View file @
1ef62d1d
...
...
@@ -141,5 +141,7 @@ contract Ballot {
{
winnerName = proposals[winningProposal()].name;
}
function testWithArray (bytes32[] memory param) public {}
}
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