NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.15k stars 1.37k forks source link

Unexpected errors interacting with deployed Vyper contracts #1141

Open CodeForcer opened 3 years ago

CodeForcer commented 3 years ago

Hi team, I've encountered a strange error that might be related to HardHat.

If you go to Etherscan and visit the curve registry contract (https://etherscan.io/address/0x7d86446ddb609ed0f5f8684acf30380a356b2b4c#readContract) you can call the get_balances method on any of the individual pools to get the balance.

The Curve contracts are all written in Vyper.

On Etherscan every single Curve pool works when checking balances this way. However, when using the registry ABI and HardHat to call the exact same method, a subsection of the pools fail with 2 different errors depending on the pool, an "out of gas" error (makes no sense for a call), and an "unknown revert" error.

I've created the following repository to demonstrate this error: https://github.com/CodeForcer/curve-error-example

You can see the demonstration with yarn install, putting an archive node address in .env, and then npx hardhat test.

In the test there are 2 lists, which in total contain all the Curve pools. The first list is the pools that work, and the second list the pools that throw errors.

Looking at the code of the pools which error there are no clear differences between the good pools and error pools. However, there are some oddities with the ABI's of the error pools on the coins method (the failing pools mostly specify int128 here but the good pools mostly specify uint256).

Let me know if there's anything I can do to help diagnose the cause of this. I'm guessing the error might also possibly be with Alchemy, or maybe the fact that Curve is in Vyper and HardHat is Solidity focused.

alcuadrado commented 3 years ago

Thanks a lot for the detailed report, @CodeForcer.

I think what's happening is a result of a weird interaction between ethers and vyper. Vyper includes the estimated gas of each function in the ABIs, and ethers uses it. Somehow, that estimation is not enough, so the call fails.

One could argue that Hardhat should ignore that for calls, but that can lead to weird situations too.

I'd recommend removing all the gas fields from the ABI as a workaround. I'll leave this open so that we can dig deeper into it and figure out if there's something we can do on our side.

CodeForcer commented 3 years ago

@alcuadrado thank you, this is indeed the cause of the problem. After removing the gas fields from the ABI everything works as expected.

Clearly the issue here is not the fault of HardHat, but I would suggest adding a very clear message when something like this occurs like "The gas used used for function exceeds the amount amount specified in the ABI".

It's a very confusing situation to diagnose for the developer, and I suspect I wont be the last to encounter this scenario