diff --git a/slither/detectors/reentrancy/reentrancy_benign.py b/slither/detectors/reentrancy/reentrancy_benign.py index eb4c28220..10b60318e 100644 --- a/slither/detectors/reentrancy/reentrancy_benign.py +++ b/slither/detectors/reentrancy/reentrancy_benign.py @@ -82,8 +82,8 @@ Only report reentrancy that acts as a double call (see `reentrancy-eth`, `reentr result_sorted = sorted(list(reentrancies.items()), key=lambda x:x[0][0].name) for (func, calls, send_eth), varsWritten in result_sorted: - calls = list(set(calls)) - send_eth = list(set(send_eth)) + calls = sorted(list(set(calls)), key=lambda x: x.node_id) + send_eth = sorted(list(set(send_eth)), key=lambda x: x.node_id) info = 'Reentrancy in {}.{} ({}):\n' info = info.format(func.contract.name, func.name, func.source_mapping_str) info += '\tExternal calls:\n' @@ -94,7 +94,7 @@ Only report reentrancy that acts as a double call (see `reentrancy-eth`, `reentr for call_info in send_eth: info += '\t- {} ({})\n'.format(call_info.expression, call_info.source_mapping_str) info += '\tState variables written after the call(s):\n' - for (v, node) in varsWritten: + for (v, node) in sorted(varsWritten, key=lambda x: (x[0].name, x[1].node_id)): info += '\t- {} ({})\n'.format(v, node.source_mapping_str) sending_eth_json = [] diff --git a/slither/detectors/reentrancy/reentrancy_eth.py b/slither/detectors/reentrancy/reentrancy_eth.py index 9e56937a5..b0dec5925 100644 --- a/slither/detectors/reentrancy/reentrancy_eth.py +++ b/slither/detectors/reentrancy/reentrancy_eth.py @@ -84,12 +84,9 @@ Bob uses the re-entrancy bug to call `withdrawBalance` two times, and withdraw m result_sorted = sorted(list(reentrancies.items()), key=lambda x:x[0][0].name) for (func, calls, send_eth), varsWritten in result_sorted: - calls = list(set(calls)) - send_eth = list(set(send_eth)) -# if calls == send_eth: -# calls_info = 'Call: {},'.format(calls_str) -# else: -# calls_info = 'Call: {}, Ether sent: {},'.format(calls_str, send_eth_str) + calls = sorted(list(set(calls)), key=lambda x: x.node_id) + send_eth = sorted(list(set(send_eth)), key=lambda x: x.node_id) + info = 'Reentrancy in {}.{} ({}):\n' info = info.format(func.contract.name, func.name, func.source_mapping_str) info += '\tExternal calls:\n' @@ -100,7 +97,7 @@ Bob uses the re-entrancy bug to call `withdrawBalance` two times, and withdraw m for call_info in send_eth: info += '\t- {} ({})\n'.format(call_info.expression, call_info.source_mapping_str) info += '\tState variables written after the call(s):\n' - for (v, node) in varsWritten: + for (v, node) in sorted(varsWritten, key=lambda x: (x[0].name, x[1].node_id)): info += '\t- {} ({})\n'.format(v, node.source_mapping_str) sending_eth_json = [] diff --git a/slither/detectors/reentrancy/reentrancy_read_before_write.py b/slither/detectors/reentrancy/reentrancy_read_before_write.py index cffff172a..f79d67035 100644 --- a/slither/detectors/reentrancy/reentrancy_read_before_write.py +++ b/slither/detectors/reentrancy/reentrancy_read_before_write.py @@ -81,14 +81,14 @@ Do not report reentrancies that involve ethers (see `reentrancy-eth`)''' result_sorted = sorted(list(reentrancies.items()), key=lambda x:x[0][0].name) for (func, calls), varsWritten in result_sorted: - calls = list(set(calls)) + calls = sorted(list(set(calls)), key=lambda x: x.node_id) info = 'Reentrancy in {}.{} ({}):\n' info = info.format(func.contract.name, func.name, func.source_mapping_str) info += '\tExternal calls:\n' for call_info in calls: info += '\t- {} ({})\n'.format(call_info.expression, call_info.source_mapping_str) info += '\tState variables written after the call(s):\n' - for (v, node) in varsWritten: + for (v, node) in sorted(varsWritten, key=lambda x: (x[0].name, x[1].node_id)): info += '\t- {} ({})\n'.format(v, node.source_mapping_str) sending_eth_json = []