BUG: not possible to delete or set storage on forked chain
See original GitHub issueSSTORE 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)
}
}
}
-
Start local ganache instance in debug mode
yarn run ganache-cli --debug(will run on http://localhost:8545) -
Start the truffle console against the local development instance above
yarn run truffle console -
In the console, create a new instance of
ContractEditingviaconst contractEditing = await ContractEditing.new() -
In the console, for the test contract instance, set storage
slot 1tovalue 0x02await contractEditing.setStorageSlot(1, "0x02") -
Ensure the value is set
await web3.eth.getStorageAt(contractEditing.address, 1)you should get back0x0200000000000000000000000000000000000000000000000000000000000000 -
Now fork the above chain in a new instance running on a different port, e.g.
8900yarn run ganache-cli --fork http://localhost:8545 --port 8900 -
Add truffle config for a new local network running on the above port
testFork: {
host: "localhost",
port: 8900,
network_id: "*"
},
-
Start the truffle console against the forked development chain
yarn run truffle console --network testFork -
Initialise the
ContractEditinginstance 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") -
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 back0x0200000000000000000000000000000000000000000000000000000000000000 -
Now try changing that storage slot in the forked chain
await contractEditing.setStorageSlot(1, "0x03") -
Ensure the storage slot has changed:
await web3.eth.getStorageAt(contractEditing.address, 1)you should get back the new value0x03but we still get back0x0200000000000000000000000000000000000000000000000000000000000000
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
- Version used:
Ganache CLI v6.4.3 (ganache-core: 2.5.5) - Operating System and version: OSx
- Link to your project: https://github.com/JoinColony/colonyNetwork
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
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.
Closing as @elenadimitrova can confirm this issue has been fixed in the latest beta! Thanks @elenadimitrova!