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
32a68276
Commit
32a68276
authored
Dec 13, 2017
by
soad003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Static Analysis: require / assert
parent
eae29196
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
7 deletions
+93
-7
package.json
remix-solidity/package.json
+1
-1
guardConditions.js
remix-solidity/src/analysis/modules/guardConditions.js
+29
-0
list.js
remix-solidity/src/analysis/modules/list.js
+2
-1
staticAnalysisCommon.js
remix-solidity/src/analysis/modules/staticAnalysisCommon.js
+23
-1
staticAnalysisIntegration-test.js
...-solidity/test/analysis/staticAnalysisIntegration-test.js
+31
-0
assembly.sol
remix-solidity/test/analysis/test-contracts/assembly.sol
+3
-2
globals.sol
remix-solidity/test/analysis/test-contracts/globals.sol
+4
-2
No files found.
remix-solidity/package.json
View file @
32a68276
...
...
@@ -31,7 +31,7 @@
"scripts"
:
{
"postinstall"
:
"npm-link-local ../remix-lib && npm-link-local ../remix-core"
,
"test"
:
"standard && npm run downloadsolc && tape ./test/tests.js"
,
"downloadsolc"
:
"wget https://ethereum.github.io/solc-bin/soljson.js"
"downloadsolc"
:
"
test -e soljson.js ||
wget https://ethereum.github.io/solc-bin/soljson.js"
},
"standard"
:
{
"ignore"
:
[
...
...
remix-solidity/src/analysis/modules/guardConditions.js
0 → 100644
View file @
32a68276
var
name
=
'Guard Conditions: '
var
desc
=
'Use require and appropriately'
var
categories
=
require
(
'./categories'
)
var
common
=
require
(
'./staticAnalysisCommon'
)
function
guardConditions
()
{
this
.
guards
=
[]
}
guardConditions
.
prototype
.
visit
=
function
(
node
)
{
if
(
common
.
isRequireCall
(
node
)
||
common
.
isAssertCall
(
node
))
this
.
guards
.
push
(
node
)
}
guardConditions
.
prototype
.
report
=
function
(
compilationResults
)
{
if
(
this
.
guards
.
length
>
0
)
{
return
[{
warning
:
'Use <i>assert(x)</i> if you never ever want <i>x</i> to be false, not in any circumstance (apart from a bug in your code). Use <i>require(x)</i> if <i>x</i> can be false, due to e.g. invalid input or a failing external component.'
,
more
:
'http://solidity.readthedocs.io/en/develop/control-structures.html#error-handling-assert-require-revert-and-exceptions'
}]
}
return
[]
}
module
.
exports
=
{
name
:
name
,
description
:
desc
,
category
:
categories
.
MISC
,
Module
:
guardConditions
}
remix-solidity/src/analysis/modules/list.js
View file @
32a68276
...
...
@@ -10,5 +10,6 @@ module.exports = [
require
(
'./lowLevelCalls'
),
require
(
'./blockBlockhash'
),
require
(
'./noReturn'
),
require
(
'./selfdestruct'
)
require
(
'./selfdestruct'
),
require
(
'./guardConditions'
)
]
remix-solidity/src/analysis/modules/staticAnalysisCommon.js
View file @
32a68276
...
...
@@ -20,7 +20,9 @@ var nodeTypes = {
INLINEASSEMBLY
:
'InlineAssembly'
,
BLOCK
:
'Block'
,
NEWEXPRESSION
:
'NewExpression'
,
RETURN
:
'Return'
RETURN
:
'Return'
,
ASSERT
:
'assert'
,
REQUIRE
:
'require'
}
var
basicTypes
=
{
...
...
@@ -417,6 +419,24 @@ function isSelfdestructCall (node) {
}
/**
* True if node is a call to assert
* @node {ASTNode} some AstNode
* @return {bool}
*/
function
isAssertCall
(
node
)
{
return
isBuiltinFunctionCall
(
node
)
&&
getLocalCallName
(
node
)
===
'assert'
}
/**
* True if node is a call to assert
* @node {ASTNode} some AstNode
* @return {bool}
*/
function
isRequireCall
(
node
)
{
return
isBuiltinFunctionCall
(
node
)
&&
getLocalCallName
(
node
)
===
'require'
}
/**
* True if is storage variable declaration
* @node {ASTNode} some AstNode
* @return {bool}
...
...
@@ -810,6 +830,8 @@ module.exports = {
isMinusMinusUnaryOperation
:
isMinusMinusUnaryOperation
,
isBuiltinFunctionCall
:
isBuiltinFunctionCall
,
isSelfdestructCall
:
isSelfdestructCall
,
isAssertCall
:
isAssertCall
,
isRequireCall
:
isRequireCall
,
// #################### Trivial Node Identification
isFunctionDefinition
:
isFunctionDefinition
,
...
...
remix-solidity/test/analysis/staticAnalysisIntegration-test.js
View file @
32a68276
...
...
@@ -441,6 +441,37 @@ test('Integration test selfdestruct.js', function (t) {
})
})
test
(
'Integration test guardConditions.js'
,
function
(
t
)
{
t
.
plan
(
testFiles
.
length
)
var
module
=
require
(
'../../src/analysis/modules/guardConditions'
)
var
lengthCheck
=
{
'KingOfTheEtherThrone.sol'
:
0
,
'assembly.sol'
:
1
,
'ballot.sol'
:
0
,
'ballot_reentrant.sol'
:
0
,
'ballot_withoutWarnings.sol'
:
0
,
'cross_contract.sol'
:
0
,
'inheritance.sol'
:
0
,
'modifier1.sol'
:
0
,
'modifier2.sol'
:
0
,
'notReentrant.sol'
:
0
,
'structReentrant.sol'
:
0
,
'thisLocal.sol'
:
0
,
'globals.sol'
:
1
,
'library.sol'
:
0
,
'transfer.sol'
:
0
,
'ctor.sol'
:
0
,
'forgottenReturn.sol'
:
0
,
'selfdestruct.sol'
:
0
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
t
.
equal
(
report
.
length
,
lengthCheck
[
file
],
`
${
file
}
has right amount of guardCondition warnings`
)
})
})
// #################### Helpers
function
runModuleOnFiles
(
module
,
t
,
cb
)
{
var
statRunner
=
new
StatRunner
()
...
...
remix-solidity/test/analysis/test-contracts/assembly.sol
View file @
32a68276
...
...
@@ -4,6 +4,7 @@
address owner;
function at(address _addr) returns (bytes o_code) {
assert(_addr != 0x0);
assembly {
// retrieve the size of the code, this needs assembly
let size := extcodesize(_addr)
...
...
@@ -20,8 +21,8 @@
}
function bla() {
if(tx.origin == owner)
msg.sender.send(19);
require(tx.origin == owner);
msg.sender.send(19);
assembly {
}
...
...
remix-solidity/test/analysis/test-contracts/globals.sol
View file @
32a68276
...
...
@@ -32,8 +32,8 @@ contract a is bla {
now;
tx.gasprice;
tx.origin;
//
assert(now == block.timestamp
);
//
require(now == block.timestamp
);
//
assert(1 == 2
);
//
require(1 == 1
);
keccak256(a);
sha3(a);
sha256(a);
...
...
@@ -52,6 +52,7 @@ contract a is bla {
//a.transfer(a.balance);
selfdestruct(a);
//revert();
assert(a.balance == 0);
}
}
\ No newline at end of file
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