Contract state inconsistency in forked networks at historical blocks
See original GitHub issueI found inconsistent contract states between the forked network and mainnet at block 11129500-11129520.
Environment
- Mac M1
- ganache v7.5.0 (@ganache/cli: 0.6.0, @ganache/core: 0.6.0)
- node v16.18.1
Fork
URL: https://mainnet.infura.io/v3/ Block number: 11129514 (11129500-11129520)
Contract
Address: 0x1C47343eA7135c2bA3B2d24202AD960aDaFAa81c Name: CRVStrategyStableMainnet Method: depositArbCheck
Expected Behavior
Call depositArbCheck
method and obtain true
that is the correct value at block 11129500-11129520.
Current Behavior
Call depositArbCheck
method and obtain false
that is the value at the latest block.
Step to Reproduce
- Creating a forked network at block 11129514 ganache --fork.url https://mainnet.infura.io/v3/* --fork.blockNumber 11129514
- Set Web3.py / Web3.js to connect to the forked network
- Set contract information (Address, ABI, etc.)
- Call
depositArbCheck
method - Observe the return value
false
(which should betrue
at block 11129514 according to the verification steps below)
Verification step
- Set Web3.py / Web3.js to connect to the mainnet (https://mainnet.infura.io/v3/*)
- Set contract information (Address, ABI, etc.)
- Call
depositArbCheck
method with block_identifier/block_number = 11129514 - Observe the return value
true
Context
This contract state inconsistency makes it impossible to use Ganache to reproduce typical DeFi attacks for deeper security study. CRVStrategyStableMainnet
, especially depositArbCheck
is used as the reference of the method deposit
of the contract Harvest.Finance: USDT Vault
that was exploited on Oct 26, 2020.
Potential Solution
I think if Ganache always fetches data from Ethereum clients with parameters containing blockNumber
assigned in the beginning, the return value should be correct. I am not sure about what the currently implemented mechanism is, but disabling and deleting cache is not working.
Any help and suggestions would be greatly appreciated. Thanks in advance.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Happy to help! Give that other issue a 👍. We use issue engagement as a strong signal for what we work on.
Thanks for the detailed answer. Manually setting the chain time works. I am glad to hear the updates in the next major release and looking forward to it.
Also, thank you so much for the friendly tips.
miner
option is very helpful. I use the private Infura ID for statistic reasons. The Ganache default is surely enough for common use.Lastly, may I also suggest a similar enhancement mentioned in #3653? It would be convenient to test if Ganache allows modifying ERC20 contract states. Currently, my test relies on DEX contracts to swap ETH for tokens like stablecoins, which leads to the (significant sometimes) state change that hinders complicated and highly coupled analysis.
Thanks again for your help!