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

Executing code from bytes array makes the debugger crash #7801

Closed
2 tasks done
peyha opened this issue Apr 27, 2024 · 0 comments · Fixed by #7991
Closed
2 tasks done

Executing code from bytes array makes the debugger crash #7801

peyha opened this issue Apr 27, 2024 · 0 comments · Fixed by #7991
Labels
T-bug Type: bug

Comments

@peyha
Copy link

peyha commented Apr 27, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (d431f74 2024-04-27T00:16:52.929844000Z)

What command(s) is the bug in?

forge test --debug "_()" --match-contract PublicTest9

Operating System

macOS (Apple Silicon)

Describe the bug

Tried to use the debugger with the following code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract Challenge {
    bytes internal constant bytecode = (
        hex"5b608060806080608060806080608060806080"
        hex"60806080608060806080608060806080608060"
        hex"60806080608060806080608060806080608060"
    );
    uint256 internal constant bytecode_start = 0x145;

    /**
     * @dev Remove duplicates from an array of uint8
     */
    function dispelDuplicates(
        uint8[] calldata input
    ) public pure returns (uint8[] memory output) {
        function() internal pure bytecode_func;
        assembly {
            bytecode_func := bytecode_start
        }
        bytecode_func();

        bytes memory r = bytecode;
        assembly {
            output := r
        }
    }
}

turns out the debugger crashes once it gets to the line bytecode_func(), here is the corresponding log

The application panicked (crashed).
Message:  swap_remove index (is 241) should be < len (is 240)
Location: /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/alloc/src/vec/mod.rs:1463

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 9 frames hidden ⋮                               
  10: alloc::vec::Vec<T,A>::swap_remove::assert_failed::h5c3445a08183cfb1
      at <unknown source file>:<unknown line>
  11: foundry_debugger::tui::draw::<impl foundry_debugger::tui::context::DebuggerContext>::draw_src::h513d58bd179bc875
      at <unknown source file>:<unknown line>
  12: foundry_debugger::tui::Debugger::try_run_real::{{closure}}::h3a79640c3b313821
      at <unknown source file>:<unknown line>
  13: foundry_debugger::tui::Debugger::try_run::hd03d67fab6d66e5d
      at <unknown source file>:<unknown line>
  14: forge::cmd::test::TestArgs::execute_tests::{{closure}}::h517417722672d6c0
      at <unknown source file>:<unknown line>
  15: forge::cmd::test::TestArgs::run::{{closure}}::h8c22520d60eb572f
      at <unknown source file>:<unknown line>
  16: forge::main::hf3c5a2ed3e2f95d7
      at <unknown source file>:<unknown line>
  17: std::sys_common::backtrace::__rust_begin_short_backtrace::hbc8ec14722bb3757
      at <unknown source file>:<unknown line>
  18: _main<unknown>
      at <unknown source file>:<unknown line>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant