Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

solidity

rsk

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?

like image 795
7alip Avatar asked Jul 09 '21 09:07

7alip


People also ask

What is the maximum size of a smart contract?

A smart contract can be a maximum of 24KB or it will run out of gas. This can be circumnavigated by using The Diamond Pattern. OpenZeppelin Contracts - Library for secure smart contract development.

How do smart contracts work?

This means they have a balance and they can send transactions over the network. However they're not controlled by a user, instead they are deployed to the network and run as programmed. User accounts can then interact with a smart contract by submitting transactions that execute a function defined on the smart contract.

What are the eip-170 smart contract size limits?

Small impact Avoid passing structs to functions Declare correct visibility for functions and variables Remove modifiers The future for the contract size limits Why is there a limit? On November 22, 2016the Spurious Dragon hard-fork introduced EIP-170which added a smart contract size limit of 24.576 kb.

What does a smmart contract mean?

A "smart contract" is simply a program that runs on the Ethereum blockchain. It's a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain.


1 Answers

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.

like image 53
bguiz Avatar answered Oct 11 '22 03:10

bguiz