juno
juno copied to clipboard
Contract hash calculator
Add contract hash calculator (not contract address hash) as specified in: https://starknet.io/documentation/contracts/
CONTRACT HASH The contract hash is a hash of its definition. The elements defining a contract are:
API version (the version under which the contract was deployed) Array of external functions entry points Array of L1 handlers entry points1 Array of constructors entry points (currently the compiler allows only one constructor) Array of used builtin names2 (ordered by declaration) Keccak3 of the contract’s program. Here the contract’s program stands for the json obtained by executing starknet-compile with the --ne_debug_info flag. To see the exact computation of this field, see our repo. Bytecode (represented by an array of field elements) The contract’s hash is the chain hash4 of the above, computed as follows:
start with h(0,api_version) for every line in the above (excluding the first), compute: h(h(previous_line), new_line)
the hash of an array a[1],…,a[n] is defined by h(...h(h(0,a[1)),a[2]),...,a[n]),n)
let c denote the cumulative hash resulting from applying the above process, the contract’s hash is then h(c, number_of_lines), where number_of_lines is 7. For more details, see the Cairo implementation here.