Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hedera Token Service return EvmError: InvalidEFOpcode while running forking tests with foundry #863

Open
sqrlfirst opened this issue Jul 17, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@sqrlfirst
Copy link

Description

I'm trying to run I'm trying to run mainnet fork test in foundry, however I'm getting following error while I try to execute vm.deal cheat code to mint erc20:

Ran 1 test for test/foundry/testforissue.t.sol:DealCheatCodeIssue
[FAIL. Reason: setup failed: EvmError: Revert] setUp() (gas: 0)
Traces:
  [1040430288] DealCheatCodeIssue::setUp()
    ├─ [0] VM::addr(<pk>) [staticcall]
    │   └─ ← [Return] user_one: [0x10717341b635a148A81A6e6e8c0EDe50E59490B2]
    ├─ [0] VM::label(user_one: [0x10717341b635a148A81A6e6e8c0EDe50E59490B2], "user_one")
    │   └─ ← [Return] 
    ├─ [0] VM::deal(user_one: [0x10717341b635a148A81A6e6e8c0EDe50E59490B2], 100000000000 [1e11])
    │   └─ ← [Return] 
    ├─ [1040398513] 0x000000000000000000000000000000000006f89a::balanceOf(user_one: [0x10717341b635a148A81A6e6e8c0EDe50E59490B2]) [staticcall]
    │   ├─ [0] 0x0000000000000000000000000000000000000167::redirectForToken() [delegatecall]
    │   │   └─ ← [InvalidEFOpcode] EvmError: InvalidEFOpcode
    │   └─ ← [Revert] EvmError: Revert
    └─ ← [Revert] EvmError: Revert

Steps to reproduce

  1. Run the test with following command:
forge test --fork-url "https://mainnet.hashio.io/api" --match-contract "DealCheatCodeIssue"  -vvvv 

Example of test:

// SPDX-License-Identifier: unlicensed
pragma solidity ^0.8.17;

import {Test, Vm, console} from "forge-std/Test.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract DealCheatCodeIssue is Test {
    address USDC_mainnet = 0x000000000000000000000000000000000006f89a;
    address user1;

    function setUp() public {
        user1 = makeAddr("user_one");

        deal(user1, 100 * 10e8);
        deal(USDC_mainnet, user1, 1000 * 10e8);
    }

    function test_UserBalance() public {
        uint256 userBalance = IERC20(USDC_mainnet).balanceOf(user1);
        assertEq(userBalance, 1000 * 10e8);
    }
}

Additional context

No response

Hedera network

mainnet

Version

v0.1.0

Operating system

macOS

@sqrlfirst sqrlfirst added the bug Something isn't working label Jul 17, 2024
@konstantinabl konstantinabl self-assigned this Jul 26, 2024
@acuarica acuarica assigned acuarica and unassigned konstantinabl Jul 29, 2024
@acuarica
Copy link
Contributor

Hi @sqrlfirst, thanks for reporting this. We are aware of this situation. This happens when trying to use network forking with some of the Hedera native services, _e.g., Hedera Token Service. In this specific case, the issue arises because USDC at 0x000000000000000000000000000000000006f89a is a Hedera Native Token. Hedera Native Tokens implement HIP-719, which in turns calls the HTS at 0x0000000000000000000000000000000000000167. However, the eth_getCode for 0x0000000000000000000000000000000000000167 returns 0xfe, hence the EvmError: InvalidEFOpcode.

We are working on a solution, which in a nutshell involves emulating the HTS at a Solidity level. We estimate to have some results in the next weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Sprint Backlog
Development

No branches or pull requests

3 participants