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

remix vm cancun abi.decode revert #4800

Closed
alexanderhawl opened this issue May 16, 2024 · 11 comments
Closed

remix vm cancun abi.decode revert #4800

alexanderhawl opened this issue May 16, 2024 · 11 comments

Comments

@alexanderhawl
Copy link

I deploy the contract in remix vm cancun

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

contract private_swap_test {
    mapping(address => uint256) private balance;
    uint256 public bestBet;
    address payable public winner;
    address payable private owner = payable(msg.sender);
    address public token = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; //USDT

    function Bet() public payable {
        if (msg.value > bestBet) {
            bestBet = msg.value;
            winner = payable(msg.sender);
        }
        balance[msg.sender] += msg.value;
    }

    function withdrawToken() external payable {
        (bool success, bytes memory res) = token.call{value: 0}(abi.encodeWithSignature("balanceOf(address)", address(this)));
        uint256 tokenBalance = abi.decode(res, (uint256));
        // require(success);
        //uint tokenBalance=address(this).balance;
        if (msg.sender == winner && tokenBalance > 0) {
            (success, ) = token.call(abi.encodeWithSignature("transfer(address,uint256)", msg.sender, tokenBalance));
            require(success);
            winner = payable(0x0000000000000000000000000000000000000000); 
        }
        balance[msg.sender] = 0;
        (success, ) = address(msg.sender).call{value: balance[msg.sender]}("");
        require(success);
        
    }

    receive() external payable {
        Bet();
    }
}

when I call the withdrawToken function, it revert, the debug information says the error is in the abi.decode. So I comment it, and use

uint tokenBalance=address(this).balance;

It works well. I report this issue to solidity team, they say the compilation doesn't report error, the deploying environment is not fact cncun.
https://github.com/ethereum/solidity/issues/15099

@alexanderhawl
Copy link
Author

deploy environment: remix vm cancun
solidity version : 0.8.25
optimization: no

@Aniket-Engg
Copy link
Collaborator

Hello @alexanderhawl , do you see any errors in browser console too?

@alexanderhawl
Copy link
Author

just only revert. But I replay it in blocksec phalcon exploer, it says invalid opcode MCOPY.

@Aniket-Engg
Copy link
Collaborator

just only revert. But I replay it in blocksec phalcon exploer, it says invalid opcode MCOPY.

Can you share error screenshot?

This might not be related to cancun VM as if I compile using Shanghai EVM version and deploy to Remix VM(Shanghai) method call still fails

@Aniket-Engg
Copy link
Collaborator

Also, address(this).balance returns the ETH balance of contract not the token balance

@alexanderhawl
Copy link
Author

I tried the code in foundry, the evm_version is shanghai, it also reverts.

@alexanderhawl
Copy link
Author

I used blocksec phalcon to fork a eth mainnet, transaction always went well no matter the compiler is cancun or shanghai. But if I selected remix vm cancun or shanghai, it reverted.
the revert picture in remix vm
the successful transaction in phalcon fork
https://app.blocksec.com/explorer/tx/eth/0xe3dd3123b5960961e8fd9c7acf84325afc08703662594e2c3335ad016fcac7cf?event=fork&forkId=fork_57869ed1534f4c6c926a5924ebbae1cd

@alexanderhawl
Copy link
Author

Uploading Screenshot_20240516_224253.png…

@Aniket-Engg
Copy link
Collaborator

Difficult to deduce what's wrong

@alexanderhawl
Copy link
Author

I found the error reason, in the remix vm , the token address is not a contract, so the balanceOf function is error. the res variable is 0x. So the abi.decode revert. Thanks your response.

@Aniket-Engg
Copy link
Collaborator

okay. That's great. Hope you can fix it now. Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants