1

I am developing a storage contract using mapping to save data. At first the contract exceeds the contract size limit so I seperate my contract to fit it. After seperation, the main storage contract is named Engine.sol which contains the original mapping used to save data.

Though Engine now is below the contract size limit, I'm wondering whether Engine will exceed the limit as users store more and more data into it. That's my first question.

So my idea is if Engine has reached the limit I can create a new Engine and attach it to the old one like a linkded list so users interacting with the old Engine can be redirected to the new Engine to store data.

Here is my second question, like we can use .length to check an array's length, do we have a way to check a contract size like Engine.size? I have tested extcodesize but it returns the same value no matter how much data I have stored.

I'm using remix to code and solidity 0.8.19 to compile.

Thanks a lot for replying!

1 Answer 1

1

It's important to note that the contract size limit and the contract storage limit are two separate limits that serve different purposes. The contract size limit is a restriction on the amount of bytecode that can be deployed on the network, whereas the contract storage limit is a restriction on the amount of data that can be stored within the contract.

In Solidity, the smart contract size limit refers to the maximum size of the contract bytecode, which includes the compiled code of the contract functions and variables. The contract size limit is a fixed value: 24576 bytes. If you're using Hardhat, you can use the hardhat-contract-sizer plugin to check the contract size of any smart contract.

On the other hand, the smart contract storage limit refers to the maximum amount of data that can be stored within the contract's storage space. This storage space is used to store the contract's state variables, which hold the current state of the contract. The storage limit is determined by the amount of gas that has been used to store data in the contract's storage. I recommend you reading the following answer to learn more.

Regarding your second question, there is no built-in way to check the size of a contract. One way to estimate the contract size is to use the extcodesize opcode to get the size of the contract's bytecode. However, as you have mentioned, this may not accurately reflect the actual contract size, as it does not take into account the size of the contract's state variables or the amount of data being stored.

1
  • Enlightening! Thanks again.
    – 庞小博
    Apr 8, 2023 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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