Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

Storage Contract

1 min read
Pronunciation
[stawr-ij kon-trakt]
Analogy
Imagine a company where one building is just a highly secure, organized warehouse (the storage contract) that holds all the company's records and inventory. Other buildings (logic contracts) contain the offices and machinery that perform the actual work, and they request or update data from this central warehouse as needed. If an office building is renovated (logic updated), the warehouse of records remains untouched and consistent.
Definition
In some smart contract architectures, particularly those emphasizing separation of concerns or certain upgrade patterns, a storage contract is a dedicated contract whose primary purpose is to hold and manage the state (data) for one or more other contracts (often logic contracts). This separates data persistence from business logic.
Key Points Intro
Storage contracts centralize data management, potentially simplifying upgrades and data access for associated logic contracts.
Key Points

Primarily designed to store and manage data on the blockchain.

Logic contracts interact with the storage contract to read or write state.

Can help in upgrade patterns by allowing logic contracts to be replaced without affecting the data, as the data resides in a stable storage contract.

Access to modify data in the storage contract is typically restricted to authorized logic contracts or admin functions.

Example
A complex DeFi application might use a separate storage contract to hold all user balances and loan parameters. Different logic contracts (e.g., for lending, borrowing, governance) would then interact with this storage contract to perform their functions. If the lending logic needs an upgrade, a new lending logic contract can be deployed and authorized to use the existing storage contract.
Technical Deep Dive
Using a dedicated storage contract means that data layout is defined in one place. Logic contracts call functions on the storage contract (e.g., `setData(key, value)`, `getData(key)`) to manipulate state. This adds an extra layer of contract calls, which can increase gas costs. The interface of the storage contract needs to be stable or designed for extensibility. Authorization mechanisms (e.g., `onlyOwner` or specific access control for logic contract addresses) are critical to ensure only permitted contracts can modify the state.
Caveat
While separating storage can aid upgradability, it also introduces extra gas costs due to inter-contract calls and can add complexity to the overall system design. The storage contract itself also needs to be carefully designed, as bugs in it could be critical. This pattern is less common than proxy patterns for simple upgrades but can be useful in complex modular systems.

Storage Contract - Related Articles

No related articles for this term.