Low-level delegate call failed. EIP1967

I am trying to deploy an ERC1967 contract using a deployer rather than a plugin ( since eventually, I need to deploy it using solidity contracts ). But contract is not getting created in my test suite.

:1234: Code to reproduce

pragma solidity ^0.8.2;

import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract UnERC20Proxy is ERC1967Proxy {
    constructor(address _logic, bytes memory _data)
        ERC1967Proxy(_logic, _data)
    {}

    function getImplementation() public view returns (address) {
        return _implementation();
    }

    function upgradeTo(address newImplementation) external {
        _upgradeTo(newImplementation);
    }
}

Truffle test line:

 unERC20ProxyContract = await unERC20Proxy.new(
        dai.address,
        web3.utils.asciiToHex(""),
        {
          from: accounts[0],
        }
      );

Output

:computer: Environment

  • Truffle
  • Ubuntu 20.4
  • Web3
  • Ganache

Can you check what this evaluates to? web3.utils.asciiToHex("")

Yes. I executed:

      console.log(web3.utils.asciiToHex(""));
      console.log(web3.utils.asciiToHex("rachit"));

The output was:

0x00
0x726163686974

Both the cases are throughing the same error in the contract deployment.

The problem is that web3.utils.asciiToHex("") is giving you 0x00, and you should be sending in an empty byte array. 0x00 is an array of 1 byte, and the proxy is using it to execute it as if it was an initialization function call.

This looks like a bug in the web3.utils. Try:

 unERC20ProxyContract = await unERC20Proxy.new(
        dai.address,
        "",
        {
          from: accounts[0],
        }
      );

I already tried that.
The above approach gives the following:
Error: invalid arrayify value (argument="value", value="", code=INVALID_ARGUMENT, version=bytes/5.0.5)

I also tried:
web3.utils.padLeft(web3.utils.asciiToHex(""))

Same delegate call failed error.

Try with "0x" representing an empty byte array.

3 Likes

That worked !!!
Will also create an issue on web3 for a fix.
Thank you so much.

1 Like

await deployer.deploy(upgradeableProxy, logicContractAddr, adminAddr, "0x");
Fantastic! Thank you @frangio But could explain why and what does it mean?

1 Like

Byte arrays are represented as hex strings. Hex strings are normally prefixed by 0x such as 0xab12, where ab12 are the hexadecimal bytes. The prefix on its own 0x is representing an empty byte array.