Class hash
The class hash is a hash chain of the definition of the class.
Definition of a (Cairo 0) class
Cairo 0 classes are deprecated, and will no longer be supported after regenesis |
The elements that define a class are:
API version |
The version of the class, currently always 0. |
||
Array of external functions entry points |
An entry point is a pair
|
||
Array of L1 handlers entry points |
- |
||
Array of constructors entry points |
Currently, the compiler allows only one constructor. |
||
Array of used builtin names |
An ASCII-encode array, ordered by declaration. |
||
Program hash |
The starknet_keccak of the class’s program. The class’s program is the abi and program part of the
The compiler outputs abi, entrypoint selectors and the program. For program hash, |
||
Bytecode |
Represented by an array of field elements. |
Computing the (Cairo 0) class hash
Where
-
\(h\) is the Pedersen hash function
-
the Pedersen hash of an array is defined here
-
the hash of an entry point array \((\text{selector},\text{offset})_{i=1}^n\) is given by \(h(\text{selector}_1,\text{offset}_1,...,\text{selector}_n,\text{offset}_n)\)
-
the
program_hash
is thestarknet_keccak
of the json described above -
the
bytecode_hash
is simply the hash of the bytecode array
Definition of a (Cairo 1) class
Classes that were written in Cairo 1 are defined by their Sierra code ( resulting from the compilation of the Cairo code into Sierra, see here for more details).
The elements that define a class are:
contract_class_version |
The version of the contract class object. Currently, the Starknet OS supports version 0.1.0 |
||
Array of external functions entry points |
An entry point is a pair
|
||
Array of L1 handlers entry points |
- |
||
Array of constructors entry points |
Currently, the compiler allows only one constructor. |
||
ABI |
A string representing the ABI of the class. The ABI hash (which affects the class hash) is given by:
|
||
Sierra program |
An array of field elements representing the Sierra instructions. |
Computing the (Cairo 1) class hash
The hash of the class is the chain hash of its components, computed as follows:
Where
The Starknet OS currently supports contract class version 0.1.0, which is represented in the above hash computation as the ASCII encoding of the string |
For more details, see the Cairo implementation.