Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type conversion failure when assigning YUL variable to string literal #584

Closed
Xenomega opened this issue Aug 19, 2020 · 2 comments
Closed
Assignees
Labels
bug Something isn't working High Priority

Comments

@Xenomega
Copy link
Member

The following contract causes an exception:

contract YULAssignStringLiteral {
    function f() public {
        assembly 
        { 
            let x := "oh_god_solidity" 
        }
    }
}

Output:

ERROR:root:Traceback (most recent call last):
  File "c:\users\x\documents\github\slither\slither\__main__.py", line 610, in main_impl
    (slither_instances, results_detectors, results_printers, number_contracts) = process_all(filename, args,
  File "c:\users\x\documents\github\slither\slither\__main__.py", line 67, in process_all
    (slither, current_results_detectors, current_results_printers, current_analyzed_count) = process_single(
  File "c:\users\x\documents\github\slither\slither\__main__.py", line 53, in process_single
    slither = Slither(target,
  File "c:\users\x\documents\github\slither\slither\slither.py", line 86, in __init__
    self._parser.analyze_contracts()
  File "c:\users\x\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 345, in analyze_contracts
    self._convert_to_slithir()
  File "c:\users\x\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 489, in _convert_to_slithir
    func.generate_slithir_and_analyze()
  File "c:\users\x\documents\github\slither\slither\core\declarations\function.py", line 1652, in generate_slithir_and_analyze
    node.slithir_generation()
  File "c:\users\x\documents\github\slither\slither\core\cfg\node.py", line 702, in slithir_generation
    self._irs = convert_expression(expression, self)
  File "c:\users\x\documents\github\slither\slither\slithir\convert.py", line 64, in convert_expression
    visitor = ExpressionToSlithIR(expression, node)
  File "c:\users\x\documents\github\slither\slither\visitors\slithir\expression_to_slithir.py", line 103, in __init__
    self._visit_expression(self.expression)
  File "c:\users\x\documents\github\slither\slither\visitors\expression\expression.py", line 45, in _visit_expression
    self._visit_assignement_operation(expression)
  File "c:\users\x\documents\github\slither\slither\visitors\expression\expression.py", line 101, in _visit_assignement_operation
    self._visit_expression(expression.expression_right)
  File "c:\users\x\documents\github\slither\slither\visitors\expression\expression.py", line 95, in _visit_expression
    self._post_visit(expression)
  File "c:\users\x\documents\github\slither\slither\visitors\expression\expression.py", line 286, in _post_visit
    self._post_literal(expression)
  File "c:\users\x\documents\github\slither\slither\visitors\slithir\expression_to_slithir.py", line 312, in _post_literal
    cst = Constant(expression.value, expression.type, expression.subdenomination)
  File "c:\users\x\documents\github\slither\slither\slithir\variables\constant.py", line 35, in __init__
    self._val = int(Decimal(val))
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
@Xenomega Xenomega added the bug Something isn't working label Aug 19, 2020
@Xenomega
Copy link
Member Author

Xenomega commented Aug 19, 2020

Slightly different exception if it's a return value, something to keep in mind when refactoring:

contract YULReturnStringLiteral  {
    function f() public returns (bytes32 x) {
        assembly {
            x := "abcdef"
        }
    }
}

Output:

ERROR:root:Error in .\yul_return_string_literal.sol
ERROR:root:Traceback (most recent call last):
  File "c:\users\x\documents\github\slither\slither\__main__.py", line 610, in main_impl
    (slither_instances, results_detectors, results_printers, number_contracts) = process_all(filename, args,
  File "c:\users\x\documents\github\slither\slither\__main__.py", line 67, in process_all
    (slither, current_results_detectors, current_results_printers, current_analyzed_count) = process_single(
  File "c:\users\x\documents\github\slither\slither\__main__.py", line 53, in process_single
    slither = Slither(target,
  File "c:\users\x\documents\github\slither\slither\slither.py", line 86, in __init__
    self._parser.analyze_contracts()
  File "c:\users\x\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 345, in analyze_contracts
    self._convert_to_slithir()
  File "c:\users\x\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 489, in _convert_to_slithir
    func.generate_slithir_and_analyze()
  File "c:\users\x\documents\github\slither\slither\core\declarations\function.py", line 1652, in generate_slithir_and_analyze
    node.slithir_generation()
  File "c:\users\x\documents\github\slither\slither\core\cfg\node.py", line 702, in slithir_generation
    self._irs = convert_expression(expression, self)
  File "c:\users\x\documents\github\slither\slither\slithir\convert.py", line 64, in convert_expression
    visitor = ExpressionToSlithIR(expression, node)
  File "c:\users\x\documents\github\slither\slither\visitors\slithir\expression_to_slithir.py", line 103, in __init__
    self._visit_expression(self.expression)
  File "c:\users\x\documents\github\slither\slither\visitors\expression\expression.py", line 45, in _visit_expression
    self._visit_assignement_operation(expression)
  File "c:\users\x\documents\github\slither\slither\visitors\expression\expression.py", line 101, in _visit_assignement_operation
    self._visit_expression(expression.expression_right)
  File "c:\users\x\documents\github\slither\slither\visitors\expression\expression.py", line 95, in _visit_expression
    self._post_visit(expression)
  File "c:\users\x\documents\github\slither\slither\visitors\expression\expression.py", line 286, in _post_visit
    self._post_literal(expression)
  File "c:\users\x\documents\github\slither\slither\visitors\slithir\expression_to_slithir.py", line 312, in _post_literal
    cst = Constant(expression.value, expression.type, expression.subdenomination)
  File "c:\users\x\documents\github\slither\slither\slithir\variables\constant.py", line 30, in __init__
    self._val = int(Decimal(base) * (10 ** int(expo)))
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]

@montyly
Copy link
Member

montyly commented Sep 4, 2020

Fixed with #617

@montyly montyly closed this as completed Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working High Priority
Projects
None yet
Development

No branches or pull requests

3 participants