7alip
7alip

Reputation: 905

What is the max size of a smart contract on the RSK network?

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?

Upvotes: 6

Views: 114

Answers (1)

bguiz
bguiz

Reputation: 28627

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.

Upvotes: 6

Related Questions