ethereum / remix-project

Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions.
https://remix-ide.readthedocs.io
MIT License
2.4k stars 910 forks source link

Event name conflicts and data out-of-bounds error in Remix #1242

Open taiyangc opened 3 years ago

taiyangc commented 3 years ago

I have been getting a weird errored: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.1.2) error when testing contract functions in Remix, even though it goes through without revert. After debugging and stripping most of the logic, I found a minimal example to reproduce this problem:

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

import "@openzeppelin/contracts@4.1.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.1.0/token/ERC20/ERC20.sol";

contract Test is ERC721 {
    constructor() ERC721("TEST", "TEST") { }

    function test() public {
        emit Transfer(address(0), address(0), 100);
    }
}

The test() call would produce an error

transact to Test.test pending ...
transact to Test.test errored: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.1.2)

Looking closer, I can see that both OpenZeppelin's ERC20 and ERC721 contracts provide a Transfer Event. To verify this assumption, I commented out //import "@openzeppelin/contracts@4.1.0/token/ERC20/ERC20.sol"; and the event emit works as expected. Because my contract uses ERC20 to instantiate an instance of a token so I need to import the definitions, but I am confused if this is a bug in Remix or by design a Solidity contract should not import two files with the same Event names? Is there any way to organize imports to get rid of this problem?

0xandyeth commented 3 years ago

import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

Can you try to import again ?

taiyangc commented 3 years ago

@ReactTop Same result.

0xandyeth commented 3 years ago

What is openzeppelin/contracts version in package.json?

taiyangc commented 3 years ago

There is no package.json in Remix (should there be?)

Under .deps/npm/@openzeppelin/contracts@4.1.0 is as imported.

0xandyeth commented 3 years ago

Hmm ,Can you try to build your contract with truffle-framework instead of Remix ? or Please add ERC20 ,ERC721 contracts manually in remix without module install. I think remix is not working well with openzeppelin. So the editor should be VS code editor.

taiyangc commented 3 years ago

Yes, I am aware that other frameworks have no issues (I am using hardhat without problems). Sometimes it's much easier to debug functions in Remix, so I hope Remix could address this bug.

0xandyeth commented 3 years ago

Maybe , then Please add them manually .

On Wed, Jun 2, 2021 at 8:58 AM Eric Chen @.***> wrote:

Yes, I am aware that other frameworks have no issues (I am using hardhat without problems). Sometimes it's much easier to debug functions in Remix, so I hope Remix could address this bug.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ethereum/remix-project/issues/1242#issuecomment-852624566, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHPAQPQ7N7R7PVI5VKNLWNTTQV63FANCNFSM452XL7GA .

MargaGabard commented 2 years ago

Hi! I have the same error with Remix

I have in the same contract ERC20 y ERC721 contracts of OpenZeppelin, but if I comment out import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol"; then the event emit works as expected.

Have you been able to solve the problem?

Thnks

GolfredoPerezFernandez commented 2 years ago

same here