ether transfer in loop tracked

pull/7/head
app 6 years ago
parent e714aaacb6
commit 355bb70071
  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) { etherTransferInLoop.prototype.visit = function (node) {
if (common.isLoop(node) && common.isTransfer(node)) { if (common.isLoop(node)) {
this.relevantNodes.push(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) 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 // #################### Trivial Node Identification
function isFunctionDefinition (node) { function isFunctionDefinition (node) {
@ -1084,6 +1094,7 @@ module.exports = {
getFunctionOrModifierDefinitionParameterPart: getFunctionOrModifierDefinitionParameterPart, getFunctionOrModifierDefinitionParameterPart: getFunctionOrModifierDefinitionParameterPart,
getFunctionOrModifierDefinitionReturnParameterPart: getFunctionOrModifierDefinitionReturnParameterPart, getFunctionOrModifierDefinitionReturnParameterPart: getFunctionOrModifierDefinitionReturnParameterPart,
getUnAssignedTopLevelBinOps: getUnAssignedTopLevelBinOps, getUnAssignedTopLevelBinOps: getUnAssignedTopLevelBinOps,
getLoopBlockStartIndex: getLoopBlockStartIndex,
// #################### Complex Node Identification // #################### Complex Node Identification
isDeleteOfDynamicArray: isDeleteOfDynamicArray, isDeleteOfDynamicArray: isDeleteOfDynamicArray,

Loading…
Cancel
Save