3

I was trying to deploy my smart contract to Kovan test network using Remix IDE,although it compiles successfully but when I try to deploy it I get this error message

"false Transaction mined but the execution failed"

My transactions hash is "0x1e15c237c4329c63d74f7a3e63e3c9a2b3921d4eaf4bce304baf734a6c35df68"

The smart contract code is a flattened version of several contracts. see it here on a pastebin.

1 Answer 1

2

It is a transaction that creates a contract so since it fails the problem is in the constructor.

constructor(
    address[] memory _components,
    int256[] memory _units,
    address[] memory _modules,
    IController _controller,
    address _manager,
    string memory _name,
    string memory _symbol
)
    public
    ERC20(_name, _symbol)
{
    controller = _controller;
    manager = _manager;
    positionMultiplier = PreciseUnitMath.preciseUnitInt();
    components = _components;

    // Modules are put in PENDING state, as they need to be individually initialized by the Module
    for (uint256 i = 0; i < _modules.length; i++) {
        moduleStates[_modules[i]] = ISetToken.ModuleState.PENDING;
    }

    // Positions are put in default state initially
    for (uint256 j = 0; j < _components.length; j++) {
        componentPositions[_components[j]].virtualUnit = _units[j];
    }
}

The transaction consumes all 10,000,000 gas available. This type of errors is mainly caused by an assert() or accessing an array out of bounds.

The constructors are quite simple and there's no assert nor require that might fail (ERC20's constructor is also invoked but it is also quite simple).

The access to arrays _modules and _components is correct, but access to _units never checks against its length. Implicitly the code requires _units.length == _components.length.

Parsing the constructor arguments we can see that the last requirements fails. There's one unit and three components.

So this line fails when j = 1

componentPositions[_components[j]].virtualUnit = _units[j]
3
  • Thanks for the reply, why in my code should I make the modification?
    – calibre24
    Dec 9, 2020 at 8:19
  • You can add require(_components.length == _units.length, "Lengths should match"), but it is not necesary. If both array parameters have the same length it will work.
    – Ismael
    Dec 9, 2020 at 14:05
  • Hi Ismael, Your answer was right. it was because I did not pass enough units to match the components of the constructor argument.
    – calibre24
    Dec 9, 2020 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.