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

Logic Contract

1 min read
Pronunciation
[loj-ik kon-trakt]
Analogy
In our P.O. Box analogy, the P.O. Box is the proxy. The 'logic contract' is the actual office building with all the departments, employees, and rules that perform the work. If the company wants to change how it operates, it builds a new office building (a new logic contract) and tells the P.O. Box to forward mail there instead.
Definition
In an upgradeable smart contract system (typically using a proxy pattern), the logic contract (also known as an implementation contract) contains the actual executable code and business logic for the application. The proxy contract delegates calls to this logic contract.
Key Points Intro
The logic contract holds the executable business rules in an upgradeable contract setup.
Key Points

Contains the active smart contract code and functions.

Is called by a proxy contract via `delegatecall`.

Can be replaced with a new version to upgrade the smart contract's functionality.

Typically does not hold state itself; state is stored in the proxy contract.

Multiple proxy contracts can potentially point to the same logic contract if they share identical logic.

Example
A developer team creates version 1.0 of their application's business logic in `LogicContractV1`. A proxy contract is deployed and points to it. Later, they develop `LogicContractV2` with bug fixes and new features. The proxy is then updated to point to `LogicContractV2`.
Technical Deep Dive
Logic contracts must be written carefully to be compatible with the proxy pattern. For instance, they should not have constructors that initialize state variables, as their code runs in the context of the proxy's storage; initialization logic is usually handled by a special `initialize` function called through the proxy after deployment. Storage layout compatibility between different versions of logic contracts is also a critical consideration to avoid corrupting the proxy's state during an upgrade.

Logic Contract - Related Articles

No related articles for this term.