foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.28k stars 1.75k forks source link

Anvil - debug_traceTransaction - storage enabled - some struct logs missing storage object #6691

Open zemse opened 10 months ago

zemse commented 10 months ago

Component

Anvil

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

What version of Foundry are you on?

forge 0.2.0 (2bcb4a1 2024-01-01T00:24:40.423571000Z)

What command(s) is the bug in?

No response

Operating System

macOS (Apple Silicon)

Describe the bug

When storage values are SLOADed multiple times across multiple callcontext, the first SLOAD contains a storage object that contains the key, however further SLOADs have empty storage objects.

Here is expected geth output, actual anvil output and diff [line 431, 1221 in the pr files changed].

This issue is mainly arising because step tracing utilizes revm StorageChanged journaling which also is fired when storage slot value changes or the slot is first accessed. However, subsequent SLOADs are not detected through revm journaling and hence the storage object remains empty for that struct log.

This can be reproduced by calling the main function on this contract.

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract AnvilBug {
    function main() external returns (uint x) {
        assembly {
            sstore(1, 1)
            x := sload(1)
        }
        this.f1();
    }

    function f1() external returns (uint x) {
        assembly {
            // sload same slot in another call context
            x := sload(1)
        }
    }
}

Example fix commit.

DaniPopes commented 9 months ago

cc @mattsse tracing related

grandizzy commented 2 weeks ago

@zemse would you be able to try latest foundry version and see if issue is still reproducible? thank you!