hyperledger-labs/yui-ibc-solidity

limitation about design of middleware and EVM stack

Closed this issue · 9 comments

Compiler run failed:
Error: Compiler error (/solidity/libyul/backends/evm/AsmCodeGen.cpp:63):Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables. When compiling inline assembly: Variable value1 is 1 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.

I get next.

So could help if IBCAppBase instead of many variables, have fewer, but put into memory objects. Is it okey to do such refactoring?

Alternative have internal methods IBCAppBase for override and other public/external interface to use. So that internal better inlined.

I am super fine to run via-ir too.

What would be acceptable solution?

our team picked to uses via-ir, i guess it better to avoid doing code duplication and making memory stucts as parameters (which can gas cost)

bluele commented

Hi @dzmitry-lahoda, this issue is for yui-ibc-solidity repo, right? If so, can we transfer this issue into the yui-ibc-solidity?

bluele commented

Anyway, which IIBCModule function is the stack too deep error occurred in?

oh, sorry. yeah. wrong repo.

i have sent with ics 30 ibc middlware. it was fine.

on top of that i have sent draft pr to have ibc hooks on middleware. here it failed.

error does not tells exactly with sol file has issue, may be need to run with some verbise flag.

middleware inherits and uses warapped IIBCAppBase and ibcpackethandler

bluele commented

I have transferred this from yui-relayer @dzmitry-lahoda

bluele commented

I see, onChanOpenInit and onChanOpenTry have many parameters, so we get stack too deep error when try to call the middleware as the followings:

    function onChanOpenInit(
        Channel.Order order,
        string[] calldata connectionHops,
        string calldata portId,
        string calldata channelId,
        ChannelCounterparty.Data calldata counterparty,
        string calldata version
    ) external override returns (string memory) {
        return middleware.onChanOpenInit(order, connectionHops, portId, channelId, counterparty, version); // stack too deep
    }

I think ibc-solidity should support such a case without enabling via-ir=true. To mitigate the error, we should use a struct parameter instead. As you say, there is some additional gas cost, but these functions are called once and this is acceptable. I will open a PR later.

used struct params in #220 and it worked