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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With