Skip to content

Commit 5f16082

Browse files
committed
hotfix for invalid hash computation due to stupid abi formatting bcs the abi is an arbitrary string
1 parent c873181 commit 5f16082

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

crates/rpc/rpc-types/src/class.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use std::io::{self, Write};
77
use cairo_lang_starknet_classes::contract_class::ContractEntryPoints;
88
use cairo_lang_utils::bigint::BigUintAsHex;
99
use katana_primitives::class::{
10-
compute_sierra_class_hash, ClassHash, ContractClass, LegacyContractClass, SierraContractClass,
10+
compute_legacy_class_hash, compute_sierra_class_hash, ClassHash, ComputeClassHashError,
11+
ContractClass, LegacyContractClass, SierraContractClass,
1112
};
1213
use katana_primitives::{
1314
Felt, {self},
@@ -34,6 +35,15 @@ pub enum Class {
3435
Legacy(RpcLegacyContractClass),
3536
}
3637

38+
impl Class {
39+
pub fn hash(&self) -> ClassHash {
40+
match self {
41+
Class::Sierra(class) => class.hash(),
42+
Class::Legacy(class) => class.hash().unwrap(),
43+
}
44+
}
45+
}
46+
3747
#[derive(Debug, thiserror::Error)]
3848
pub enum ConversionError {
3949
#[error(transparent)]
@@ -119,6 +129,12 @@ pub struct RpcLegacyContractClass {
119129
pub abi: Option<Vec<ContractClassAbiEntry>>,
120130
}
121131

132+
impl RpcLegacyContractClass {
133+
pub fn hash(&self) -> Result<ClassHash, ComputeClassHashError> {
134+
compute_legacy_class_hash(&LegacyContractClass::try_from(self.clone()).unwrap())
135+
}
136+
}
137+
122138
//////////////////////////////////////////////////
123139
// LegacyClass implementations
124140
//////////////////////////////////////////////////

crates/sync/stage/src/classes.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,9 @@ impl<P> Classes<P> {
9393
.zip(class_artifacts.into_par_iter())
9494
.map(|(key, gateway_class)| {
9595
let block = key.block;
96-
let expected_hash = key.class_hash;
97-
98-
let class: ContractClass =
99-
gateway_class.try_into().map_err(Error::Conversion)?;
10096

101-
let computed_hash = class.class_hash().map_err(|source| {
102-
Error::ClassHashComputation { class_hash: expected_hash, source, block }
103-
})?;
97+
let expected_hash = key.class_hash;
98+
let computed_hash = gateway_class.hash();
10499

105100
if computed_hash != expected_hash {
106101
return Err(Error::ClassHashMismatch {
@@ -110,7 +105,7 @@ impl<P> Classes<P> {
110105
});
111106
}
112107

113-
Ok(class)
108+
Ok(ContractClass::try_from(gateway_class).map_err(Error::Conversion)?)
114109
})
115110
.collect::<Result<Vec<_>, Error>>();
116111

0 commit comments

Comments
 (0)