@ -2,25 +2,51 @@ var name = 'Selfdestruct: '
var desc = 'Be aware of caller contracts.'
var desc = 'Be aware of caller contracts.'
var categories = require ( './categories' )
var categories = require ( './categories' )
var common = require ( './staticAnalysisCommon' )
var common = require ( './staticAnalysisCommon' )
var AbstractAst = require ( './abstractAstView' )
function selfdestruct ( ) {
function selfdestruct ( ) {
this . relevantNodes = [ ]
this . abstractAst = new AbstractAst ( )
}
selfdestruct . prototype . visit = function ( node ) {
this . visit = this . abstractAst . build _visit (
if ( common . isSelfdestructCall ( node ) ) {
( node ) => common . isStatement ( node ) ||
this . relevantNodes . push ( node )
common . isSelfdestructCall ( node )
}
)
this . report = this . abstractAst . build _report ( report )
}
}
selfdestruct . prototype . report = function ( ) {
selfdestruct . prototype . visit = function ( ) { throw new Error ( 'constantFunctions.js no visit function set upon construction' ) }
return this . relevantNodes . map ( function ( item , i ) {
return {
selfdestruct . prototype . report = function ( ) { throw new Error ( 'constantFunctions.js no report function set upon construction' ) }
function report ( contracts , multipleContractsWithSameName ) {
var warnings = [ ]
contracts . forEach ( ( contract ) => {
contract . functions . forEach ( ( func ) => {
let hasSelf = false
func . relevantNodes . forEach ( ( node ) => {
if ( common . isSelfdestructCall ( node ) ) {
warnings . push ( {
warning : 'Use of selfdestruct: can block calling contracts unexpectedly. Be especially careful if this contract is planned to be used by other contracts (i.e. library contracts, interactions). Selfdestruction of the callee contract can leave callers in an inoperable state.' ,
warning : 'Use of selfdestruct: can block calling contracts unexpectedly. Be especially careful if this contract is planned to be used by other contracts (i.e. library contracts, interactions). Selfdestruction of the callee contract can leave callers in an inoperable state.' ,
location : item . src ,
location : node . src ,
more : 'https://paritytech.io/blog/security-alert.html'
more : 'https://paritytech.io/blog/security-alert.html'
} )
hasSelf = true
}
if ( common . isStatement ( node ) && hasSelf ) {
warnings . push ( {
warning : 'Use of selfdestruct: No code after selfdestruct is executed. Selfdestruct is a terminal.' ,
location : node . src ,
more : 'http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html#self-destruct'
} )
hasSelf = false
}
}
} )
} )
} )
} )
return warnings
}
}
module . exports = {
module . exports = {