Skip to content

bug: Uint conversion error on memory offset or size > usize::MAX #6472

Description

@greged93

Component

Other (please describe)

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

cast 0.2.0 (27956b3 2023-11-30T00:24:55.614692000Z)

What command(s) is the bug in?

cast run tx_hash --debug

Operating System

macOS (Apple Silicon)

Describe the bug

The debugger object won't handle a memory read/ write offset for which the size is bigger than usize::MAX. The bug can be reproduced with the following:
Sets the code to PUSH1 0x01 PUSH32 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6 PUSH2 0x0100 LOG1

cast rpc anvil_setCode 0x00000000000000000000000000000000deadbeef 60017ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6610100a1

Set the block gas limit

cast rpc evm_setBlockGasLimit 0x05f5e100

Call 0x00000000000000000000000000000000deadbeef

cast send 0x00000000000000000000000000000000deadbeef --value 1 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --gas-limit 80000000

Once done, run cast run tx_hash --debug. Click on MAJ-G to jump to the latest instruction. You should get panicked at crates/debugger/src/lib.rs:897:65: Uint conversion error: Overflow(256, 18446744073709551606, 18446744073709551615).

This comes from this line shown below:

1.. => Some(stack[stack_len - stack_index as usize].to()),

Which tries to convert Uint256 into a usize. We should convert it safely and display on the debugger that this instruction caused an out of gas due to dynamic gas costs if bigger than usize::MAX.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions