0glabs / 0g-chain

The First Modular AI Chain
Apache License 2.0
28 stars 37 forks source link

RPC returns 500 error when during deplouying contract with AccessControl #40

Closed xluckydegen closed 2 months ago

xluckydegen commented 2 months ago

Hello, I'm playing with your chain and trying to deploy some of my contracts. but it seems there is some bug in the deployment process.

This is my minimal test case. As soon as TestCoin derive from AccessControl, the RPC is returning the errors:

pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";

contract TestCoin is ERC20,Ownable,AccessControl {

    constructor(string memory name) ERC20(name, name) {
        _mint(msg.sender, 1_000_000 * 10**18);
    }

    function mint(address acc, uint256 amount) public {
    }

    function addMinter(address minter) public onlyOwner {
    }
}

This is the error message:

deploying "TestCoin"HH110: Invalid JSON-RPC response received: <html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx/1.24.0 (Ubuntu)</center>
</body>
</html>
 {"name":"HardhatError","_stack":"HardhatError: HH110: Invalid JSON-RPC response received: <html>\r\n<head><title>500 Internal Server Error</title></head>\r\n<body>\r\n<center><h1>500 Internal Server Error</h1></center>\r\n<hr><center>nginx/1.24.0 (Ubuntu)</center>\r\n</body>\r\n</html>
ethanz0g commented 2 months ago

Hello @xluckydegen,

I've tried to compile this TestCoin contract and it failed. Do you have a way for me to download the whole TestCoin project, so I can reproduce the deployment issue?

xluckydegen commented 2 months ago

Hello @ethanz0g ,

you can easily fix it by adding Ownable(address(this)) param. It seems there were some changes in openzepelling or compiler. it is working in my hardhat without that but it is required in remix now.

Feel free to use this code. Anyway, this was not the original issue. The issue is that as soon as you will add AccessControl your RPCs are failing.

pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";

contract TestCoin is ERC20,Ownable,AccessControl {

    constructor(string memory name) ERC20(name, name) Ownable(address(this)) {
        _mint(msg.sender, 1_000_000 * 10**18);
    }

    function mint(address acc, uint256 amount) public {
    }

    function addMinter(address minter) public onlyOwner {
    }
}
xluckydegen commented 2 months ago

PS:

Yes, I'm checking it now and version 4.9.0 was without constructor and now latest 5.0.0 requires constructor param

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol

ethanz0g commented 2 months ago

Hello @xluckydegen ,

Now the compilation and deployment both succeeded without any complaints. The contract is here:

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";

contract TestCoin is ERC20,Ownable,AccessControl {

    constructor(string memory name) ERC20(name, name) Ownable(address(this)) {
        _mint(msg.sender, 1_000_000 * 10**18);
    }

    function mint(address acc, uint256 amount) public {
    }

    function addMinter(address minter) public onlyOwner {
    }
}

The code is exactly yours except the first line, which is a comment needed in some environments. If you still encounter issues when deploying, you might want to share your deployment script here.

xluckydegen commented 2 months ago

Just checked it and upgrading solidity compiler to 0.8.20 and openzepellin to 5.0.2 fixed it on my side too.