9

Got a few questions regarding storage limitations of smart contract.

  1. What is the maximum number of bytes of data that I can send for a single transaction?
  2. Is there a size limit to the storage of a smart contract?

1 Answer 1

14

1. Maximum parameter size per transaction

The maximum number of bytes per transaction for a single transaction is limited several constants, in particular an upper size of for operations max_operation_data_length and the hard gas limits for operations and blocks (a block contains a set of operations):

  "max_operation_data_length": 16384,
  "hard_gas_limit_per_operation": "800000",
  "hard_gas_limit_per_block": "8000000",
  "cost_per_byte": "1000",
  "hard_storage_limit_per_operation": "60000",

These constants can be obtained by a RPC call if you have a running node:

tezos-client rpc get /chains/main/blocks/head/context/constants | jq

Presumably max_operation_data_length is in bytes, meaning that you have a an upper limit of of ~16kB for the parameter per transaction. You would also have to remove the size needed other data in transaction, such as sender, recipient, etc.

The gas limits hard_gas_limit_per_block and hard_gas_limit_per_operation indirectly limit both maximum storage and transaction size. Each time a smart contract is invoked, the node passes through the following phases:

  1. Read binary representation of smart contract code + contract state from disk
  2. Decode code, storage and input to untyped representation
  3. Typecheck code, storage and input
  4. Run code
  5. Encode storage to untyped repr.
  6. (write encoded storage to disk – batched & async)

Each of these phases consumes gas. Larger parameter increases the gas consumption in phase 2-4. Larger storage increases gas consumption in phases 1-5. It follows that storage and parameter size are limited by the hard gas limits. However, I do not have any hard numbers, but you could simulate using tezos-client to obtain estimates.

2. Maximum storage size per contract

Finally, for your second question, which is already partially answered by 1. AFAIK, there is no explicit fixed limit on the storage of a smart contract. However, after a certain size, the storage of contract can no longer be decoded, because doing so would exceed the hard gas limits. Another limiting factor is funds. The costs_per_byte is currently at 1000 mutez. This means that each additional kB costs ~1tz (currently ~= 3usd) to store, payed by the sender of transaction that increase storage.

We also have to consider the constant hard_storage_limit_per_operation. Whenever a transaction is injected on the network, it is associated with a storage limit. Typically, it is set by the user, to ensure that their transaction does not provoke an unintended amount of storage burn. If the size of the storage size diff resulting from applying the transaction exceeds the storage limit, then the transaction is rejected. The constant hard_storage_limit_per_operation gives the highest storage limit that can be set, and thus also limits the maximum storage size increase per transaction. It follows that the storage of a contract cannot increase with more than 60000 bytes per transaction. Note that such a transaction would cost ~180 usd today.

2
  • When you say "such a txn would cost", are you referring to transaction fees? Gas does not have monetary meaning. Does the amount of txn fee also increase with needed storage amount?
    – utdrmac
    Feb 20, 2020 at 15:17
  • Indeed, gas does not have a fixed cost. But storage burn has a fixed cost per byte. See here for instance: tezos.stackexchange.com/a/2165/1773 and here tezos.gitlab.io/introduction/howtouse.html for a full explanation.
    – arvidj
    Feb 20, 2020 at 15:28

Your Answer

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

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