Compiled class hash
The compiled class hash is a cryptographic hash that results from the compilation process of a Cairo class
from its intermediate representation (Sierra) to Cairo assembly (Casm). This process is managed by the Sierra→Casm compiler.
The compiled class hash is crucial for ensuring the uniqueness and integrity of compiled classes within Starknet. Whether you are a developer deploying contracts or a party interested in the inner workings of Starknet’s state commitment, understanding the compiled class hash is essential.
For developers, the hash is an important part of the contract declaration process, ensuring that each compiled class is uniquely identifiable and verifiable. For those involved in maintaining the network, it contributes to the efficiency and performance of Starknet by optimizing the state commitment process.
The state commitment uses the Sierra code that results when compiling Cairo classes. Sierra acts as an intermediate representation between Cairo and Casm. Provers, however, operate solely with Casm.
In order to avoid recompiling, from Sierra to Casm, each block in which the class is deployed, the state commitment gets the information it needs about the corresponding Casm from the the information contained in the compiled class hash.
When declaring a contract, the party administering the contract endorses the compiled class hash, procured using an SDK, as an integral component of the DECLARE
transaction. Following the inclusion of the transaction in a block, the compiled class hash integrates into the state commitment.
Purpose and Significance
-
Uniqueness: The compiled class hash ensures the uniqueness of each compiled class. It is essentially a fingerprint for the compiled output, allowing the network to verify the integrity and uniqueness of the class.
-
State Commitment: In Starknet, state commitment includes various components, including the Cairo classes. These classes are initially defined using Sierra. However, for the prover to function efficiently, it requires Casm.
-
Efficiency: By including the compiled class hash in the state commitment, Starknet avoids the need to recompile from Sierra to Casm in every block where the class is used. This optimization significantly enhances the network’s efficiency and performance.
Usage
When a new contract is declared on Starknet, the compiled class hash plays a pivotal role. Here’s how:
-
Declaration Process: The party declaring the contract computes the compiled class hash using an SDK provided by Starknet.
-
DECLARE Transaction: This hash is then included as part of the
DECLARE
transaction is a specific type of transaction in Starknet used to register new contracts. -
Inclusion in State Commitment: Once the
DECLARE
transaction is included in a block, the compiled class hash becomes part of the state commitment. This inclusion ensures that the network recognizes and stores the unique compiled output of the contract.
Prospectively, as Sierra-to-Casm compilation integrates into the Starknet OS, the value might undergo updates via proof of the Sierra-to-Casm compiler execution. Such verification demonstrates that compiling the same class with an updated compiler version yields a fresh compiled class hash. The compiled class hash is a basic element in Starknet’s architecture, enabling efficient state commitment and ensuring the integrity and uniqueness of compiled classes.