HeadlinesBriefing favicon HeadlinesBriefing.com

Solidity C3 Linearization Explained

DEV Community •
×

Solidity uses the C3 linearization algorithm, also called the Method Resolution Order (MRO), to determine the search order for parent contracts in multiple inheritance. This solves the Diamond Problem, where a contract inherits from two parents that share a common grandparent. Without C3, the compiler would face ambiguity when executing a shared function.

The search starts at the most derived contract and moves right-to-left through parent declarations. For the keyword super, Solidity follows a flattened list generated by C3. This ensures a predictable, conflict-free method resolution path, which is critical for maintaining complex, reusable contract architectures on the Ethereum network.

Consider a diamond chain: contract D inherits from B and C, both of which inherit from A. C3 linearization produces the order [D, C, B, A]. A call to `super.foo()` in D executes C's version, then B's, then A's, preventing the base function from running twice. This deterministic order is essential for safe, modular smart contract design.