Skip to content

Commit

Permalink
doc: added a new topic: Compiled class hash (#1294)
Browse files Browse the repository at this point in the history
* doc: compiled class hash

* further improvement to the doc

* fix: Dir structure changes for SEO (#1261)

* Changed /documentation/ to /root/ in antora.yml.

* Changed root to ROOT.

* Change file names for SEO:
* underscores to hyphens
* uppercase to lowercase

* Change file names for SEO to be match content matter

* Added broken links from 3rd party sites

* Update messaging-mechanism.adoc to latest on main.

* Updated xrefs in messaging-mechanism.adoc.

* Updated URL for preview to drop `/documentation/`

* fix: Change "cross-chain" to "cross-layer" in L1-L2 Messaging mechanism (#1289)

* Change "cross-chain" to "cross-layer" in L1-L2 Messaging mechanism

* Apply suggestions from code review

* Removed `seo-optimization` branch from playbook. (#1299)

* docs: add messaging_reference.adoc (#1094)

* create messaging_reference.adoc
* add messaging_reference.adoc to nav
* add the functions implemented in StarknetMessaging.sol but not part of the IStarknetMessaging.sol
* Explain `deployer_address`
* Added links between consumeMessageFromL2 function and ConsumedMessageToL2 event.
* Added links between consumeMessageFromL2 function and ConsumedMessageToL2 event.
* modify event descriptions and add event heading for functions
* fix directory structure
* Comment out events from internal `processMessages` function

* docs: Update Starknet book ToC (#1297)

* Update Starknet book ToC: Update outdated information about Starknet book

---------

Co-authored-by: Steve Goodman <39279277+stoobie@users.noreply.github.com>

* fix typo adding class hashes in tx v3 invoke computation (#1292)

* Update playbook.yml to use main branch for ui-bundle.zip (#1306)

* Fix hash calculation documentation: change 1 to 0 in v1 (deprecated) hash calculation (#1304)

* docs: Update transactions.adoc with txs v3 fee estimation (#1296)

* Update transactions.adoc with txs v3 fee estimation

* Update transactions.adoc

* Update transactions.adoc

* Update transactions.adoc

---------

Co-authored-by: Steve Goodman <39279277+stoobie@users.noreply.github.com>

* Update transaction-life-cycle.adoc with finality status of deploy_account and declare transactions (#1295)

* Update transaction-life-cycle.adoc with finality status of deploy_account and declare transactions

---------

Co-authored-by: Steve Goodman <39279277+stoobie@users.noreply.github.com>

* docs: add validate warnings and refactor the account's functions page (#1302)

* add validate warnings and refactor account functions page

* fix typo

* minor fixes

* Update serialization-of-cairo-types.adoc (#1307)

* docs: Migrate Provers topic from the Starknet Book (#1270)

* Migrating Provers topic from the Starknet Book at https://book.starknet.io/ch03-03-provers.html.

* Import sharp.adoc from the Book in order to bring in a commit with multiple contributors.

* Edits, and removed sharp.adoc
---------

Co-authored-by: Omar U. Espejel <espejelomar@gmail.com>

* Update README.adoc

* docs: add L1HandlerTransaction table and info on caller address (#1275)

* feat: add l1 handler transaction type version

* fix: fix typo

* fix: fix typo

* fix: add a new ref to l1 handler transaction

* fix: reword L1HandlerTransaction to L1 handler transaction in normal text

* fix: reword for consistent format and better readability

* Update components/Starknet/modules/architecture-and-concepts/pages/network-architecture/messaging-mechanism.adoc

* Update components/Starknet/modules/architecture-and-concepts/pages/network-architecture/messaging-mechanism.adoc

* fix: remove old file

* Update components/Starknet/modules/architecture-and-concepts/pages/network-architecture/transactions.adoc

Co-authored-by: Steve Goodman <39279277+stoobie@users.noreply.github.com>

* fix: reword as suggested

---------

Co-authored-by: Steve Goodman <39279277+stoobie@users.noreply.github.com>

* Added a link to info on the L1 handler tx type from the tx versions table. (#1312)

* Update components/Starknet/modules/architecture-and-concepts/nav.adoc

* change file name to use hyphens

* implement reviewed changes

* Update nav.adoc

---------

Co-authored-by: Steve Goodman <39279277+stoobie@users.noreply.github.com>
Co-authored-by: xiaolou86 <20718693+xiaolou86@users.noreply.github.com>
Co-authored-by: Lauri Peltonen <20242241+microbecode@users.noreply.github.com>
Co-authored-by: antiyro <74653697+antiyro@users.noreply.github.com>
Co-authored-by: Nnaji Benjamin <60315147+Benjtalkshow@users.noreply.github.com>
Co-authored-by: odednaor <odednaor@gmail.com>
Co-authored-by: ArielElp <86294909+ArielElp@users.noreply.github.com>
Co-authored-by: jumpman <57270771+kkawula@users.noreply.github.com>
Co-authored-by: Omar U. Espejel <espejelomar@gmail.com>
Co-authored-by: Raz Landau <125185051+LandauRaz@users.noreply.github.com>
Co-authored-by: glihm <dev@glihm.net>
  • Loading branch information
12 people authored Aug 8, 2024
1 parent f10fbdf commit e690b8f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
*** xref:accounts/deploying-new-accounts.adoc[Deploying new accounts]
*** xref:accounts/universal-deployer.adoc[Universal Deployer Contract]
*** xref:accounts/simplified-transaction-flow.adoc[Simplified transaction flow]

** Contracts
*** xref:smart-contracts/contract-classes.adoc[Contract classes and instances]
*** xref:smart-contracts/class-hash.adoc[Class hash]
*** xref:smart-contracts/compiled-class-hash.adoc[Compiled class hash]
*** xref:smart-contracts/contract-address.adoc[Contract address]
*** xref:smart-contracts/contract-storage.adoc[Contract storage]
*** xref:smart-contracts/contract-abi.adoc[Contract ABI]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[id="compiled_class_hash"]
= 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 xref:network-architecture/transactions.adoc#declare_v2[`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 xref:Network_Architecture/transactions.adoc#declare_v2[`DECLARE`] transaction. The xref:Network_Architecture/transactions.adoc#declare_v2[`DECLARE`] transaction is a specific type of transaction in Starknet used to register new contracts.

* Inclusion in State Commitment: Once the xref:Network_Architecture/transactions.adoc#declare_v2[`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.

0 comments on commit e690b8f

Please sign in to comment.