Class hash

The class hash is a hash chain of the definition of the class.

Definition of a class

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 (selector, offset), where offset is the offset of the instruction that should be called inside the class’s bytecode.

The selector is an identifier through which the function is callable in transactions or in other classes. The selector is the starknet_keccak hash of the function name, encoded in ASCII.

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 .json file that the StarkNet compiler outputs when you run the following command:

$ starknet-compile --no_debug_info

To see the exact computation of this field, see contract_hash.py.

Bytecode

Represented by an array of field elements.

How the class hash is computed

The hash of the class is the chain hash, that is, the Pedersen hash, of the above, computed as follows:

  1. Start with \(h(0,\text{api_version})\).

  2. For every line in the above, excluding the first, compute \(h(h(previous\_line), new\_line)\), where the hash of an array is defined as starknet_keccak.

  3. Let \(c\) denote the cumulative hash that results from applying the above process; the class’s hash is then \(h(c, \textrm{number_of_lines})\), where \(\text{number_of_lines}\) is 7.

For more details, see the Cairo implementation.