trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.62k stars 676 forks source link

Double msg.value amount on payable call (possibly) #362

Closed OFRBG closed 5 years ago

OFRBG commented 5 years ago

Expected Behavior

When calling a payable fallback, the msg.value is equal to the wei attached as value.

Current Behavior

When calling a payable fallback, the msg.value is equal to twice the wei attached as value.

(Running npx ganache-cli --fork https://mainnet.infura.io/metamask with version Ganache CLI v6.3.0 (ganache-core: 2.4.0), the msg.value seems to double.)

Possible Solution

I can't find the issue.

Steps to Reproduce (for bugs)

  1. Run npx ganache-cli --fork https://mainnet.infura.io/metamask
  2. Deploy the bugged contract https://gist.github.com/OFRBG/5930687e7e1da856ef604f9a00f3cc27
  3. Call the fallback with 1 ether value.
  4. Call balanceOf for the address that deposited. The balance is 2000000000000000000 wei.

Context

The error isn't present when connecting to Kovan or Mainnet.

Your Environment

davidmurdoch commented 5 years ago

Thanks @OFRBG for filing this issue! I've confirmed that this is an issue when forking on v6.3.0 and v6.2.5.

davidmurdoch commented 5 years ago

Just jotting down some of the research i've done on this one... This issue is caused by ForkedBlockchain.js's storageTrieCache object being shared between eth_sendTransaction and eth_estimateGas calls. eth_estimateGas essentially poison's the live cache instead of cloning and using it's own.

davidmurdoch commented 5 years ago

This should now be fixed in our latest beta https://github.com/trufflesuite/ganache-core/releases/tag/v2.5.5-beta.0 Let me know if you have any more issues or if the fix doesn't work for you!