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.

Contract state inconsistency in forked networks at historical blocks

See original GitHub issue

I found inconsistent contract states between the forked network and mainnet at block 11129500-11129520.

Environment

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

  1. Creating a forked network at block 11129514 ganache --fork.url https://mainnet.infura.io/v3/* --fork.blockNumber 11129514
  2. Set Web3.py / Web3.js to connect to the forked network
  3. Set contract information (Address, ABI, etc.)
  4. Call depositArbCheck method
  5. Observe the return value false (which should be true at block 11129514 according to the verification steps below)

Verification step

  1. Set Web3.py / Web3.js to connect to the mainnet (https://mainnet.infura.io/v3/*)
  2. Set contract information (Address, ABI, etc.)
  3. Call depositArbCheck method with block_identifier/block_number = 11129514
  4. 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:closed
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
davidmurdochcommented, Nov 19, 2022

Happy to help! Give that other issue a 👍. We use issue engagement as a strong signal for what we work on.

0reactions
yepengdingcommented, Nov 19, 2022

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vetting Smart Contract State-Inconsistency Bugs in Seconds
PDF | This paper presents SAILFISH, a scalable system for automatically finding state-inconsistency bugs in smart contracts.
Read more >
An Overview of Forks and Coordination in Blockchain ... - arXiv
This manuscript is aimed at elaborating the concept of blockchain technology alongside its coordination and implementation with other emerging ...
Read more >
BDP301 Flashcards - Quizlet
Study with Quizlet and memorize flashcards containing terms like Did Bitcoin enable a centralized or a decentralized system for exchange of value?
Read more >
The State of Ethereum Smart Contracts Security - MDPI
Smart contracts are self-executing programs that run on the blockchain and make it possible for peers to enforce agreements without a third-party guarantee....
Read more >
How does ethereum network keep consistent
Consensus about the transactions at a given block height equates to agreement about what the state must be. The heaviest chain rule helps...
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