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.
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)
}
}
}
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.
Example fix commit.