Closed whichqua closed 1 month ago
This issue relates to a bug in our block context where an in correct deprecated_contract_hash
is used.
It affects Deprecated Contracts All blocks involved in this contract fail: https://sepolia.starkscan.co/contract/0x038f56b1cc89f907a5ddd9343b83bd97b85366c86b99f156f5ca28fb6494ba83#account-calls
It occurs in the vm during execution of a hint leading to the conclusion that it is an issue with how we are setting up the state.
After some research, this issue only applies for Cairo0 contracts and we've identified 3 different scenarios
class_hash
and recomputed_class_hash
are equals (block 204936)
[WARN prove_block::state_utils] ------------------------------------
[WARN prove_block::state_utils] Contract address: 0x41a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf
[WARN prove_block::state_utils] ------------------------------------
[WARN prove_block::state_utils] Class hash: 0x7b3e05f48f0c69e4a65ce5e076a66271a527aff2c34ce1083ec6e1526997a69
[WARN prove_block::state_utils] Recomputed Class hash: 0x7b3e05f48f0c69e4a65ce5e076a66271a527aff2c34ce1083ec6e1526997a69
class_hash
and recomputed_class_hash
are different but the last one matches OS (cairo code) recomputed class hash (block 30000)
[WARN prove_block::state_utils] ------------------------------------
[WARN prove_block::state_utils] Contract address: 0x7a3c142b1ef242f093642604c2ac2259da0efa3a0517715c34a722ba2ecd048
[WARN prove_block::state_utils] ------------------------------------
[WARN prove_block::state_utils] Class hash: 0x5c478ee27f2112411f86f207605b2e2c58cdb647bac0df27f660ef2252359c6
[WARN prove_block::state_utils] Recomputed Class hash: 0x7c373e188d0f701559ed725ef6c7bc10fca3441ef3399d5f6aee49bba5e2d4e
[WARN starknet_os::hints::deprecated_compiled_class] Computed_hash: 0x7c373e188d0f701559ed725ef6c7bc10fca3441ef3399d5f6aee49bba5e2d4e
class_hash
and recomputed_class_hash
are different and the last one also doesn't match the OS computed class hash (block 159674)
[WARN prove_block::state_utils] ------------------------------------
[WARN prove_block::state_utils] Contract address: 0x7a3c142b1ef242f093642604c2ac2259da0efa3a0517715c34a722ba2ecd048
[WARN prove_block::state_utils] ------------------------------------
[WARN prove_block::state_utils] Class hash: 0x5c478ee27f2112411f86f207605b2e2c58cdb647bac0df27f660ef2252359c6
[WARN prove_block::state_utils] Recomputed Class hash: 0x7c373e188d0f701559ed725ef6c7bc10fca3441ef3399d5f6aee49bba5e2d4e
[WARN prove_block::state_utils] CAIRO_0
[WARN starknet_os::hints::deprecated_compiled_class] Computed_hash: 0x57ed19d5ae9c505530da5f2ac62f90633a2f3cfd0cda8a94948b11909744024
The recomputed class_hash can be checked here while the comparison with the computed by Cairo code is here
Once we have a clearer view of the issue, we focus on the type conversions between Starknet and Pathfinder types. In order to simplify this process, some tests were added to the project. The first step was to check that the conversion between CompressedLegacyContractClass
and LegacyContractClass
is correct and we can get the correct class_hash
Some fixes were made to getting the right class_hash
in this commit and here
With the latest fix, we are able to recompute the correct class_hash
but the third scenario is still pending since the OS computation is not correct
After making a deeper debugging, we've realized that the information provided to Cairo code was different and that was the root cause of the error on the hash computation. The information that is sent to Cairo code is loaded here
All the fields but hinted_class_hash were correct, so we've compared in pathfinder code how that hash was computed.
This function is the one that computes the class_hash
but if you pay attention, it applies some changes on the input Json object to keep compatibility for old Cairo contracts.
On these blocks 166705, 159746, 159752, 161371, 164180
, the issue was that there was no compiler version on the object and this part was missing.
So the solution was to encapsulate the pre-processing that is done to the Json object in this function
and make it public, so we are able to use it from SNOS.
Once we have this done, the fix is pretty straightforward to apply as you can check here
This issue is encountered during proving blocks for the following blocks:
The error log:
The issue happens in this deprecated hint:
This hint is also executed in the same function and may be related:
Not yet figured out why.