6

Does RSK have a maximum size of a compiled smart contract? If so, what is the max size of the byte code that can be deployed?

bguiz
  • 27,371
  • 47
  • 154
  • 243
7alip
  • 895
  • 6
  • 11

1 Answers1

6

Yes there is, the maximum size is 24567, which is ~24KB.

This is defined in Constants#getMaxContractSize()

    public static int getMaxContractSize() {
        return 0x6000;
    }

The specific logic during a contract deployment uses this value within TransactionExecutor#createContract()

    private void createContract() {
        int createdContractSize = getLength(program.getResult().getHReturn());
        long returnDataGasValue = GasCost.multiply(GasCost.CREATE_DATA, createdContractSize);
        if (mEndGas < returnDataGasValue) {
            program.setRuntimeFailure(
                    Program.ExceptionHelper.notEnoughSpendingGas(
                            program,
                            "No gas to return just created contract",
                            returnDataGasValue));
            result = program.getResult();
            result.setHReturn(EMPTY_BYTE_ARRAY);
        } else if (createdContractSize > Constants.getMaxContractSize()) {
            program.setRuntimeFailure(
                    Program.ExceptionHelper.tooLargeContractSize(
                            program,
                            Constants.getMaxContractSize(),
                            createdContractSize));
            result = program.getResult();
            result.setHReturn(EMPTY_BYTE_ARRAY);
        } else {
            mEndGas = GasCost.subtract(mEndGas,  returnDataGasValue);
            program.spendGas(returnDataGasValue, "CONTRACT DATA COST");
            cacheTrack.saveCode(tx.getContractAddress(), result.getHReturn());
        }
    }

The part of the above function relevant to your question, is that the condition (createdContractSize > Constants.getMaxContractSize()) needs to be satisfied, otherwise an exception is thrown.

bguiz
  • 27,371
  • 47
  • 154
  • 243