Skip to content

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

@zemse

Description

@zemse

Component

Anvil

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

  • Foundry
  • Foundryup

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Next Up

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions