This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
debug_storageRangeAt
fails to find storage when the slot was created earlier in the same block
#3338
Labels
Issue
In some cases, when the transaction index is greater than 0 (i.e. you're not looking at the first transaction in a block),
debug_storageRangeAt
will fail to find storage that was there at the start of the transaction.This doesn't happen in all cases. If there was storage at that slot at the start of the block, it seems like it works fine; it will correctly report the storage for that index. If however there was no storage at that slot at the start of the block, but storage was set in transaction 0, then doing
debug_storageRangeAt
with index 1 will fail to find the storage that was set there in transaction 0.(At least, that's how the problem looks to me.)
Reproduction steps
I found this using the
solc8-magic-square
project in thesolidity-test-cases
repo, but I'll admit that this would probably be more easily reproduced with aSimpleStorage
contract. So, modify as appropriate. The relevant fact here is that doinggenerateMagicSquare(n)
will set storage slot 0 to the numbern
, at least whenn
is small and odd (you might want to useSimpleStorage
instead if you don't like being restricted to small odd numbers :P ).I compiled the project. I ran
ganache -p 7545 -b 5
. I then didtruffle migrate
to migrate the project, thentruffle console
. I then did the following:No storage was returned for index 1, despite the slot having been set in index 0. If you do an
eth_getStorageAt
for the block, you'll be able to see that the slot is correctly set to 3 at the end of the block.I also tested this with three transactions in the block instead of two; the result was that no storage was returned for any of the three indices.
Non-reproduction steps
I also did the same thing, but with an extra step of doing
it.generateMagicSquare(5)
in a separate block before doing the two transactions above. In this case, the problem does not occur; the firstdebug_storageRangeAt
shows the correct value of 5, and the seconddebug_storageRangeAt
shows the correct value of 1. The problem only seems to occur when there was no storage present at that slot at the beginning of the block.(Of course, it's possible I have the exact conditions of the bug incorrect, but I thought this was worth pointing out all the same.)
Environment
Version: This problem probably exists in all released versions of Ganache 7, since it exists on both 7.0.0 and on 7.3.2.
The text was updated successfully, but these errors were encountered: