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

Panics while parsing yul eq #66

Closed
Inphi opened this issue Jun 28, 2023 · 1 comment · Fixed by #71
Closed

Panics while parsing yul eq #66

Inphi opened this issue Jun 28, 2023 · 1 comment · Fixed by #71

Comments

@Inphi
Copy link
Contributor

Inphi commented Jun 28, 2023

Version

pyrometer @ ed07912ff617ccdfb1255f23349d3ff0548da9de

Problem

Parsing a yul eq expression, where one of its operands is an identifer panics with a No lhs range error.
This occurs when simply running pyrometer Foo.sol, where Foo.sol:

pragma solidity ^0.8.19;

contract Foo {
    struct Struct {
        uint32 a;
    }

    function foo() public {
        Struct memory data;
        assembly {
            let x := eq(data, 0xFF)
        }
    }
}

Here's the stack trace emitted:

thread 'main' panicked at 'No lhs range', src/context/exprs/cmp.rs:183:26
stack backtrace:
   0: rust_begin_unwind
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/panicking.rs:67:14
   2: core::panicking::panic_display
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/panicking.rs:150:5
   3: core::panicking::panic_str
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/panicking.rs:134:5
   4: core::option::expect_failed
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/option.rs:1932:5
   5: pyrometer::context::exprs::cmp::Cmp::cmp_inner
   6: pyrometer::context::exprs::cmp::Cmp::cmp_inner
             at /home/inphi/src/pyrometer/src/context/exprs/cmp.rs:160:17
   7: pyrometer::context::yul::yul_funcs::YulFuncCaller::yul_func_call::{{closure}}::{{closure}}
             at /home/inphi/src/pyrometer/src/context/yul/yul_funcs.rs:227:25
   8: pyrometer::context::ContextBuilder::apply_to_edges
             at /home/inphi/src/pyrometer/src/context/mod.rs:1504:17
   9: pyrometer::context::yul::yul_funcs::YulFuncCaller::yul_func_call::{{closure}}
             at /home/inphi/src/pyrometer/src/context/yul/yul_funcs.rs:218:21
  10: pyrometer::context::ContextBuilder::apply_to_edges
             at /home/inphi/src/pyrometer/src/context/mod.rs:1504:17
  11: pyrometer::context::yul::yul_funcs::YulFuncCaller::yul_func_call
             at /home/inphi/src/pyrometer/src/context/yul/yul_funcs.rs:207:17
  12: pyrometer::context::yul::YulBuilder::parse_ctx_yul_expr_inner
             at /home/inphi/src/pyrometer/src/context/yul/mod.rs:274:44
  13: pyrometer::context::yul::YulBuilder::parse_ctx_yul_expr
             at /home/inphi/src/pyrometer/src/context/yul/mod.rs:250:13
  14: pyrometer::context::yul::YulBuilder::parse_ctx_yul_stmt_inner::{{closure}}
             at /home/inphi/src/pyrometer/src/context/yul/mod.rs:134:25
  15: pyrometer::context::ContextBuilder::apply_to_edges
             at /home/inphi/src/pyrometer/src/context/mod.rs:1504:17
  16: pyrometer::context::yul::YulBuilder::parse_ctx_yul_stmt_inner
             at /home/inphi/src/pyrometer/src/context/yul/mod.rs:70:19
  17: pyrometer::context::yul::YulBuilder::parse_ctx_yul_stmt_inner::{{closure}}::{{closure}}
             at /home/inphi/src/pyrometer/src/context/yul/mod.rs:223:42
  18: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::for_each
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/slice/iter/macros.rs:204:21
  19: pyrometer::context::yul::YulBuilder::parse_ctx_yul_stmt_inner::{{closure}}
             at /home/inphi/src/pyrometer/src/context/yul/mod.rs:220:21
  20: pyrometer::context::ContextBuilder::apply_to_edges
             at /home/inphi/src/pyrometer/src/context/mod.rs:1504:17
  21: pyrometer::context::yul::YulBuilder::parse_ctx_yul_stmt_inner
             at /home/inphi/src/pyrometer/src/context/yul/mod.rs:70:19
  22: pyrometer::context::yul::YulBuilder::parse_ctx_yul_statement
             at /home/inphi/src/pyrometer/src/context/yul/mod.rs:45:17
  23: pyrometer::context::ContextBuilder::parse_ctx_stmt_inner::{{closure}}
             at /home/inphi/src/pyrometer/src/context/mod.rs:430:21
  24: pyrometer::context::ContextBuilder::apply_to_edges
             at /home/inphi/src/pyrometer/src/context/mod.rs:1504:17
  25: pyrometer::context::ContextBuilder::parse_ctx_stmt_inner
             at /home/inphi/src/pyrometer/src/context/mod.rs:429:27
  26: pyrometer::context::ContextBuilder::parse_ctx_statement
             at /home/inphi/src/pyrometer/src/context/mod.rs:62:33
  27: pyrometer::context::ContextBuilder::parse_ctx_stmt_inner::{{closure}}::{{closure}}
             at /home/inphi/src/pyrometer/src/context/mod.rs:260:42
  28: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::for_each
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/slice/iter/macros.rs:204:21
  29: pyrometer::context::ContextBuilder::parse_ctx_stmt_inner::{{closure}}
             at /home/inphi/src/pyrometer/src/context/mod.rs:258:21
  30: pyrometer::context::ContextBuilder::apply_to_edges
             at /home/inphi/src/pyrometer/src/context/mod.rs:1504:17
  31: pyrometer::context::ContextBuilder::parse_ctx_stmt_inner
             at /home/inphi/src/pyrometer/src/context/mod.rs:257:27
  32: pyrometer::context::ContextBuilder::parse_ctx_statement
             at /home/inphi/src/pyrometer/src/context/mod.rs:62:33
  33: pyrometer::context::func_call::FuncCaller::execute_call_inner
             at /home/inphi/src/pyrometer/src/context/func_call/mod.rs:556:13
  34: pyrometer::context::func_call::FuncCaller::func_call_inner::{{closure}}
  35: pyrometer::context::ContextBuilder::apply_to_edges
             at /home/inphi/src/pyrometer/src/context/mod.rs:1504:17
  36: pyrometer::context::func_call::FuncCaller::func_call_inner
             at /home/inphi/src/pyrometer/src/context/func_call/mod.rs:490:9
  37: pyrometer::context::ContextBuilder::parse_ctx_stmt_inner
             at /home/inphi/src/pyrometer/src/context/mod.rs:222:31
  38: pyrometer::context::ContextBuilder::parse_ctx_statement
             at /home/inphi/src/pyrometer/src/context/mod.rs:71:22
  39: pyrometer::Analyzer::final_pass::{{closure}}::{{closure}}
             at /home/inphi/src/pyrometer/src/lib.rs:487:21
  40: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/iter/traits/iterator.rs:853:29
  41: core::iter::traits::iterator::Iterator::fold
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/iter/traits/iterator.rs:2481:21
  42: core::iter::traits::iterator::Iterator::for_each
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/iter/traits/iterator.rs:856:9
  43: pyrometer::Analyzer::final_pass::{{closure}}
             at /home/inphi/src/pyrometer/src/lib.rs:485:13
  44: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/iter/traits/iterator.rs:853:29
  45: core::iter::traits::iterator::Iterator::fold
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/iter/traits/iterator.rs:2481:21
  46: core::iter::traits::iterator::Iterator::for_each
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/iter/traits/iterator.rs:856:9
  47: pyrometer::Analyzer::final_pass
             at /home/inphi/src/pyrometer/src/lib.rs:484:9
  48: pyrometer::Analyzer::parse
             at /home/inphi/src/pyrometer/src/lib.rs:445:21
  49: pyrometer::main
             at /home/inphi/src/pyrometer/cli/src/main.rs:218:9
  50: core::ops::function::FnOnce::call_once
             at /rustc/1a5f8bce74ee432f7cc3aa131bc3d6920e06de10/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

In the above example, I expect typical solidity behavior, where the data identifier in the eq expression is parsed as a memory offset.

@brockelmore
Copy link
Contributor

fixed in #71

@brockelmore brockelmore linked a pull request Dec 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants