From 33a8cf422443eee93eb9a1e053d2bebe7180cc9c Mon Sep 17 00:00:00 2001 From: Josselin Date: Mon, 7 Jan 2019 10:01:23 +0000 Subject: [PATCH] Add support for subdenomination --- .../expressions/expression_parsing.py | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py index 53e3111d0..c0ac0a1e2 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -237,6 +237,34 @@ def filter_name(value): value = value[:idx+1] return value +def convert_subdenomination(value, sub): + if sub is None: + return value + value = int(value) + if sub == 'wei': + return value + if sub == 'szabo': + return value * int(1e12) + if sub == 'finney': + return value * int(1e15) + if sub == 'ether': + return value * int(1e18) + if sub == 'seconds': + return value + if sub == 'minutes': + return value * 60 + if sub == 'hours': + return value * 60 * 60 + if sub == 'days': + return value * 60 * 60 * 24 + if sub == 'weeks': + return value * 60 * 60 * 24 * 7 + if sub == 'years': + return value * 60 * 60 * 24 * 7 * 365 + + logger.error('Subdemoniation not found {}'.format(sub)) + return value + def parse_expression(expression, caller_context): """ @@ -380,11 +408,17 @@ def parse_expression(expression, caller_context): if is_compact_ast: value = expression['value'] - if not value and value != "": + if value: + if 'subdenomination' in expression and expression['subdenomination']: + value = str(convert_subdenomination(value, expression['subdenomination'])) + elif not value and value != "": value = '0x'+expression['hexValue'] else: value = expression['attributes']['value'] - if value is None: + if value: + if 'subdenomination' in expression['attributes'] and expression['attributes']['subdenomination']: + value = str(convert_subdenomination(value, expression['attributes']['subdenomination'])) + elif value is None: # for literal declared as hex # see https://solidity.readthedocs.io/en/v0.4.25/types.html?highlight=hex#hexadecimal-literals assert 'hexvalue' in expression['attributes']