question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: not possible to delete or set storage on forked chain

See original GitHub issue

SSTORE operations fail to have effect although transactions are reported successful. This is only present on a forked chain.

Expected Behavior

SSTORE(X, Y) should set storage slot X to value Y on a forked chain.

Current Behavior

SSTORE(X, Y) has no effect on storage, irrespective of whether this is setting a slot from zero to non-zero value, or the other way around. Found when testing a possibly related issue https://github.com/trufflesuite/ganache-cli/issues/653

Steps to Reproduce (for bugs)

Use the following contract for testing

pragma solidity 0.5.8;
contract ContractEditing {
  function setStorageSlot(uint256 _slot, bytes32 _value) public {
    uint x = _slot;
    bytes32 y = _value;
    assembly {
      sstore(x, y)
    }
  }
}
  1. Start local ganache instance in debug mode yarn run ganache-cli --debug (will run on http://localhost:8545)

  2. Start the truffle console against the local development instance above yarn run truffle console

  3. In the console, create a new instance of ContractEditing via const contractEditing = await ContractEditing.new()

  4. In the console, for the test contract instance, set storage slot 1 to value 0x02 await contractEditing.setStorageSlot(1, "0x02")

  5. Ensure the value is set await web3.eth.getStorageAt(contractEditing.address, 1) you should get back 0x0200000000000000000000000000000000000000000000000000000000000000

  6. Now fork the above chain in a new instance running on a different port, e.g. 8900 yarn run ganache-cli --fork http://localhost:8545 --port 8900

  7. Add truffle config for a new local network running on the above port

testFork: {
      host: "localhost",
      port: 8900,
      network_id: "*"
    },
  1. Start the truffle console against the forked development chain yarn run truffle console --network testFork

  2. Initialise the ContractEditing instance from the original dev chain (you’ll need the address of the contract off development chain, e.g. 0x4D6f43bbA56AE29BD5a69C0FE08f034Bb318BeaE) const contractEditing = await ContractEditing.at("0x4D6f43bbA56AE29BD5a69C0FE08f034Bb318BeaE")

  3. Ensure the storage slot is what we set it to in step 4 via rerunning await web3.eth.getStorageAt(contractEditing.address, 1) you should still get back 0x0200000000000000000000000000000000000000000000000000000000000000

  4. Now try changing that storage slot in the forked chain await contractEditing.setStorageSlot(1, "0x03")

  5. Ensure the storage slot has changed: await web3.eth.getStorageAt(contractEditing.address, 1) you should get back the new value 0x03 but we still get back 0x0200000000000000000000000000000000000000000000000000000000000000

You can try different combinations of the storage slot changes. I haven’t been able to get anything to stick on the forked chain.

Context

This was found during testing of https://github.com/trufflesuite/ganache-cli/issues/652 which might be one of the symptoms of this issue. The above tests also fail with the dirty hack proposed here https://github.com/trufflesuite/ganache-cli/issues/653#issuecomment-502054495

Your Environment

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
elenadimitrovacommented, Jul 11, 2019

I tested the fix works as of Ganache CLI v6.4.6-beta.0 (ganache-core: 2.5.8-beta.0) 🎉

EDIT: I tested https://github.com/trufflesuite/ganache-cli/issues/652 as well but that issue still persists.

1reaction
nicholasjpaternocommented, Jul 11, 2019

Closing as @elenadimitrova can confirm this issue has been fixed in the latest beta! Thanks @elenadimitrova!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Message "Fork Error - The project is still being deleted" still ...
Summary I forked a repo, did some changes, merged the forked changes back to origin and deleted my fork.
Read more >
Ethereum Merge FAQ - Ledger Support
This FAQ answers the most common questions about the Ethereum Merge and how it will impact Ledger users. You can learn more about...
Read more >
fcntl(2) - Linux manual page - man7.org
On Linux, this command can change only the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags. It is not possible to change the O_DSYNC...
Read more >
Forking other networks | Ethereum development ... - Hardhat
Pinning a block​​ Hardhat Network will by default fork from a recent mainnet block. While this might be practical depending on the context,...
Read more >
Why You Should Delete Coinbase (and How to Do It)
Let's get into it! QUICK TIP: The best place to store coins after you buy is not on an exchange. You need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found