Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Storage in forked chain still not working correctly in latest beta #494

Closed
area opened this issue Oct 23, 2019 · 3 comments · Fixed by #495
Closed

Storage in forked chain still not working correctly in latest beta #494

area opened this issue Oct 23, 2019 · 3 comments · Fixed by #495

Comments

@area
Copy link
Contributor

area commented Oct 23, 2019

This is clearly related to #436 - there, it was not possible to set storage, but it seems like it's now too easy to delete storage on a forked chain!

Expected Behavior

Emptying a storage slot in a contract on a forked chain should not affect other contracts.

Current Behavior

Emptying a storage slot in a contract on a forked chain seems to empty that storage slot on all other contracts.

Possible Solution

Steps to Reproduce (for bugs)

Once again using:

pragma solidity 0.5.8;
contract ContractEditing {
  function setStorageSlot(uint256 _slot, bytes32 _value) public {
    uint x = _slot;
    bytes32 y = _value;
    assembly {
      sstore(x, y)
    }
  }
}

From a truffle console, connected to a ganache instance forking mainnet

a1="0x5346D0f80e2816FaD329F2c140c870ffc3c3E2Ef" // This is our contract
dai="0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359" // This is the DAI contract

web3.eth.getStorageAt(a1, 7)
> '0x0000000000000000000000000000000000000000000000000000000000000003'
web3.eth.getStorageAt(dai, 7)
> '0x44616920537461626c65636f696e2076312e3000000000000000000000000000'

Looks good so far...

ce = await ContractEditing.new({from: f}) // Get f from web3.eth.getAccounts();
ce.setStorageSlot(7, "0xdeadbeef", {from:f})

web3.eth.getStorageAt(ce.address, 7)
> '0xdeadbeef00000000000000000000000000000000000000000000000000000000'
web3.eth.getStorageAt(a1, 7)
> '0x0000000000000000000000000000000000000000000000000000000000000003'
web3.eth.getStorageAt(dai, 7)
> '0x44616920537461626c65636f696e2076312e3000000000000000000000000000'

Again, looks good. Now let's empty the slot

ce.setStorageSlot(7, "0x00", {from:f})
web3.eth.getStorageAt(ce.address, 7)
> '0x'

Great!

web3.eth.getStorageAt(a1, 7)
> '0x'
web3.eth.getStorageAt(dai, 7)
> '0x'

Oh no...

Context

This obviously makes using a forked network in many meaningful ways impossible!

Your Environment

  • Version used: Ganache CLI v6.8.1-beta.0 (ganache-core: 2.9.1-beta.0)
@area
Copy link
Contributor Author

area commented Oct 23, 2019

Not very familiar with the forking code, but it looks like this is because the database keeping track of which storage slots have been deleted on the fork is the same for all forked storage trees, but only indexes by key which appears to just be the storage slot.

@area
Copy link
Contributor Author

area commented Oct 23, 2019

I've made a fork that demonstrates a possible fix and modifies the forking deletion test to check for it.

@davidmurdoch
Copy link
Member

If you want to go ahead and make a PR I'll pull it in!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants