3

I'm writing some rather substantial Solidity smart-contracts, and believe I'm hitting the EIP170 24k bytecode size limit. I've already

(a) factored my code into libraries

(b) today split my contract into two parts.

Nothing seems to be helping to get under the limit. Heck, splitting into two contracts -increased- -severely- the code of one of the two resulting contracts -- much bigger than the original all-in-one contract.

Are there tools to help figure out where the code-bloat is coming from? Other methods for splitting-up in order to reduce size?

  • 2
    Most probably from the new statements. They're often the trouble maker because they include the code of the contract to be instantiated. – ivicaa Mar 2 '18 at 23:44
  • Oh wow. Where did you learn this (or was it by experimentation)? You're absolutely right -- and maybe this will get me unstuck! Thank you so much! Is there someplace you've found that documents to semantics of how Solidity gets compiled? I mean, at a detailed level suitable for this sort of debugging? – Chet Mar 3 '18 at 1:38
  • Experimentation, Documentation, Research here and in internet in general. It's not being teached at school. :-) I've added and answer with an example for the factory pattern. – ivicaa Mar 3 '18 at 6:05
2

Most probably the bytecode bloat comes from the new statements in your code. They're often the trouble maker because they include the code of the contract to be instantiated. You can create contract factories which you can deploy in front. This way you can reduce the bytecode size of your main contract.

E.g.

contract X {}

contract XFactory {
    function createX() returns (X) {
        return new X();
    }
}

contract Main {
    XFactory xFactory;
    ...
    Main(XFactory _xFactory) {
        xFactory = _xFactory;
    }
    ...
    function someMethod() {
        X x = xFactory.create();
    }
    ...
}
  • Oh, sigh. Your pattern won't work for me. I need two contracts, A & B, both of which have persistent data storage, with B having a pointer to A. So unlike your example, I need for Main to have a persistent copy of X. If I'm going to pass in a pointer to XFactory, I might as well just pass in a pointer to X. Ah, well. – Chet Mar 10 '18 at 0:30
0

It is possible to get around the max contract size limitation by implementing the Transparent Contract Standard: https://github.com/ethereum/EIPs/issues/1538

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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