ether transfer in loop tracked

pull/5370/head
app 5 years ago
parent 502c1717b9
commit 30d987dd1c
  1. 8
      remix-analyzer/src/solidity-analyzer/modules/etherTransferInLoop.js
  2. 11
      remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.js

@ -8,8 +8,12 @@ function etherTransferInLoop () {
}
etherTransferInLoop.prototype.visit = function (node) {
if (common.isLoop(node) && common.isTransfer(node)) {
this.relevantNodes.push(node)
if (common.isLoop(node)) {
var loopBlockStartIndex = common.getLoopBlockStartIndex()
var transferNodes = node.children[loopBlockStartIndex].children.filter(node => (common.isExpressionStatement(node) && common.isTransfer(node)))
if (transferNodes.length > 0) {
this.relevantNodes.push(...transferNodes)
}
}
}

@ -410,6 +410,16 @@ function getUnAssignedTopLevelBinOps (subScope) {
return subScope.children.filter(isBinaryOpInExpression)
}
function getLoopBlockStartIndex (node) {
if (isLoop(node)) {
if (nodeType(node, exactMatch(nodeTypes.FORSTATEMENT))) {
return 3 // For 'for' loop
} else {
return 1 // For 'while' and 'do-while' loop
}
}
}
// #################### Trivial Node Identification
function isFunctionDefinition (node) {
@ -1084,6 +1094,7 @@ module.exports = {
getFunctionOrModifierDefinitionParameterPart: getFunctionOrModifierDefinitionParameterPart,
getFunctionOrModifierDefinitionReturnParameterPart: getFunctionOrModifierDefinitionReturnParameterPart,
getUnAssignedTopLevelBinOps: getUnAssignedTopLevelBinOps,
getLoopBlockStartIndex: getLoopBlockStartIndex,
// #################### Complex Node Identification
isDeleteOfDynamicArray: isDeleteOfDynamicArray,

Loading…
Cancel
Save