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

Revert messages are not bubbled in proxy constructors #2425

Closed
ppoliani opened this issue Dec 3, 2020 · 3 comments
Closed

Revert messages are not bubbled in proxy constructors #2425

ppoliani opened this issue Dec 3, 2020 · 3 comments

Comments

@ppoliani
Copy link

ppoliani commented Dec 3, 2020

I'm trying to write some tests to check if some of the user inputs are correct. More specifically I've got the following code in my smart contract function. The code is part of the initialize function.

contract ContractA is Initializable {
  function initialize(IERC20 token) public initializer {
      require(
      address(token) != address(0), 
      "Invalid erc20 address provided"
    );
  }
} 

I have written a test that checks if the correct message is thrown when a 0x address is passed. I used the helper


const deployContract = async  () => {
  const token = await ERC20.new('TokenA', 'TokenA')
  const opts = {
    unsafeAllowLinkedLibraries: true
   }

return await deployProxy(
    ContractA, 
    [token],
    opts
  )
}

const {constants, expectRevert} = require('@openzeppelin/test-helpers');

it('should revert', async () => {
    await expectRevert(
      deployContract(constants.ZERO_ADDRESS, validatorRegistry.address),
      'Invalid erc20 address provided',
    );
}) 

Now when I run this it revert, however the error I get doesn't include the message defined in the require() section. Instead I get the default message -revert

     Wrong kind of exception received
      + expected - actual

      -revert
      +Invalid erc20 address provided

Now if I deploy the contract user .new function and manually invoking the initialize function then I get the correct message.

const deployContract = async  () => {
  const token = await ERC20.new('TokenA', 'TokenA')
  const contract =  await ContractA.new()
  await contract.initialize(token)
}

I'm using:

  • @openzeppelin/truffle-upgrades: 1.3.0
  • @openzeppelin/test-helpers": "^0.5.9"
  • "ganache-cli": "^6.12.1"
  • "truffle": "^5.1.55"
@ppoliani
Copy link
Author

ppoliani commented Dec 3, 2020

Looking into the source code I stumdled across this

contract UpgradeabilityProxy is Proxy {
  constructor(address _logic, bytes memory _data) public payable {
     assert(IMPLEMENTATION_SLOT == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1));
     _setImplementation(_logic);
      if(_data.length > 0) {
        (bool success,) = _logic.delegatecall(_data);
        require(success);
      }
  }  
...
}

Is it because of the (bool success,) = _logic.delegatecall(_data); which presumably doesn't bubble up exceptions?

@frangio
Copy link
Contributor

frangio commented Dec 4, 2020

Thanks for reporting! Yes, it seems that we're not bubbling the revert reason in the constructor! (It is bubbled in the fallback function.) Unfortunately I don't think there's a workaround for you to be able to write the tests you want.

I'm going to move this issue to our OpenZeppelin Contracts repo where proxies are hosted. We should fix it over there. We have to update the Upgrades Plugins to use those (see OpenZeppelin/openzeppelin-upgrades#164).

@frangio frangio transferred this issue from OpenZeppelin/openzeppelin-upgrades Dec 4, 2020
@frangio frangio changed the title Revert messages are not displayed when using deployProxy Revert messages are not bubbled in proxy constructors Dec 4, 2020
@ppoliani ppoliani closed this as completed Dec 4, 2020
@ppoliani ppoliani reopened this Dec 4, 2020
Amxx added a commit to Amxx/openzeppelin-contracts that referenced this issue Jan 5, 2021
@frangio
Copy link
Contributor

frangio commented Jan 7, 2021

Fixed by #2454.

@frangio frangio closed this as completed Jan 7, 2021
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