starknet_in_rust
starknet_in_rust copied to clipboard
Improve SierraContractClass ABI handling.
I'm forwarding a message from @kkovaacs :
"starknet_in_rust uses the ContractClass type from cairo-lang-starknet when creating a Declare v2 transaction. Unfortunately the JSON representation for that type isn’t quite the same as the one used on Starknet.
The ABI is defined as a string on Starknet to avoid the issue of the class hash depending on the exact method of JSON-serializing the ABI data structure. However, the ContractClass type contains a parsed representation of the ABI which is then transformed back to string when starknet_in_rust is doing class hash calculation."
This leads to potencial hash mismatches.
Thanks @kkovaacs for the report.
FYI: it seems there are Sierra classes out there where ABI cannot even be parsed:
https://testnet-2.starkscan.co/class/0x04db025178e9b74b9eb51178860acd478362bc9b5a8f3fd63252b1d70b0dc0ad
I get a "missing field kind" error when trying to parse the JSON using serde into ContractClass.
Very easy to reproduce using the class in this comment: https://github.com/eqlabs/pathfinder/issues/1208#issuecomment-1635607016
The starknet_estimateFee call fails with starknet_in_rust because the class hash miscalculation leads to an invalid transaction hash, which then fails signature check...