Skip to content

Commit

Permalink
fix(katana-core): replace compiled class hash with class hash (#1404)
Browse files Browse the repository at this point in the history
* replace compiled class hash with class hash

* replace old address
  • Loading branch information
kariy authored Jan 10, 2024
1 parent 042d46b commit 3bb35a6
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 40 deletions.
2 changes: 1 addition & 1 deletion crates/katana/core/contracts/messaging/cairo/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ACCOUNT_L2=./account_l2.json
ACCOUNT_L2_ADDR=0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624
ACCOUNT_L2_ADDR=0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03
L2_PRIVATE_KEY=0x1800000000300000180000000000030000000000003006001800006600

# Build files helpers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"deployment": {
"status": "deployed",
"class_hash": "0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f",
"address": "0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624"
"address": "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
}
}
2 changes: 1 addition & 1 deletion crates/katana/core/contracts/messaging/solidity/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export $(shell sed 's/=.*//' .env)

# Addresses fixed here for easy testing.
C_MSG_L2_ADDR=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
L2_ACCOUNT=0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624
L2_ACCOUNT=0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03
L2_CONTRACT_ADDR=0x0429a64d97c1422a37a09fc7406f35c264be59b744aaff5a79d59393eb1bc7e1

deploy_messaging_contracts:
Expand Down
32 changes: 5 additions & 27 deletions crates/katana/core/src/accounts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fmt::Display;
use std::sync::Arc;

use anyhow::Result;
use blockifier::execution::contract_class::ContractClass;
use katana_primitives::contract::ContractAddress;
use katana_primitives::FieldElement;
use katana_provider::traits::state::StateWriter;
Expand All @@ -14,9 +12,7 @@ use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet::core::utils::{get_contract_address, get_storage_var_address};
use starknet::signers::SigningKey;

use crate::constants::{
FEE_TOKEN_ADDRESS, OZ_V1_ACCOUNT_CONTRACT_COMPILED, OZ_V1_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH,
};
use crate::constants::{FEE_TOKEN_ADDRESS, OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH};

#[serde_as]
#[derive(Debug, Clone, Serialize)]
Expand All @@ -31,18 +27,11 @@ pub struct Account {
pub address: FieldElement,
#[serde_as(as = "UfeHex")]
pub class_hash: FieldElement,
#[serde(skip_serializing)]
pub contract_class: Arc<ContractClass>,
}

impl Account {
#[must_use]
pub fn new(
private_key: FieldElement,
balance: FieldElement,
class_hash: FieldElement,
contract_class: Arc<ContractClass>,
) -> Self {
pub fn new(private_key: FieldElement, balance: FieldElement, class_hash: FieldElement) -> Self {
let public_key = public_key_from_private_key(private_key);
let address = get_contract_address(
FieldElement::from(666u32),
Expand All @@ -51,7 +40,7 @@ impl Account {
FieldElement::ZERO,
);

Self { address, public_key, balance, class_hash, private_key, contract_class }
Self { address, public_key, balance, class_hash, private_key }
}

// TODO: separate fund logic from this struct - implement FeeToken type
Expand Down Expand Up @@ -104,7 +93,6 @@ pub struct DevAccountGenerator {
pub seed: [u8; 32],
pub balance: FieldElement,
pub class_hash: FieldElement,
pub contract_class: Arc<ContractClass>,
}

impl DevAccountGenerator {
Expand All @@ -114,8 +102,7 @@ impl DevAccountGenerator {
total,
seed: [0u8; 32],
balance: FieldElement::ZERO,
class_hash: (*OZ_V1_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH),
contract_class: Arc::new((*OZ_V1_ACCOUNT_CONTRACT_COMPILED).clone()),
class_hash: (*OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH),
}
}

Expand All @@ -127,10 +114,6 @@ impl DevAccountGenerator {
Self { balance, ..self }
}

pub fn with_class(self, class_hash: FieldElement, contract_class: Arc<ContractClass>) -> Self {
Self { class_hash, contract_class, ..self }
}

/// Generate `total` number of accounts based on the `seed`.
#[must_use]
pub fn generate(&self) -> Vec<Account> {
Expand All @@ -147,12 +130,7 @@ impl DevAccountGenerator {
let private_key = FieldElement::from_bytes_be(&private_key_bytes)
.expect("able to create FieldElement from bytes");

Account::new(
private_key,
self.balance,
self.class_hash,
self.contract_class.clone(),
)
Account::new(private_key, self.balance, self.class_hash)
})
.collect()
}
Expand Down
8 changes: 4 additions & 4 deletions crates/katana/core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ pub(super) fn get_genesis_states_for_testing() -> StateUpdatesWithDeclaredClasse
]);

let declared_sierra_classes = HashMap::from([(
*OZ_V1_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH,
*OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH,
OZ_V1_ACCOUNT_CONTRACT.clone().flatten().unwrap(),
)]);

let declared_compiled_classes = HashMap::from([
(*UDC_COMPILED_CLASS_HASH, (*UDC_CONTRACT).clone()),
(*ERC20_CONTRACT_COMPILED_CLASS_HASH, (*ERC20_CONTRACT).clone()),
(*OZ_V1_ACCOUNT_CONTRACT_COMPILED_CLASS_HASH, (*OZ_V1_ACCOUNT_CONTRACT_COMPILED).clone()),
(*UDC_CLASS_HASH, (*UDC_CONTRACT).clone()),
(*ERC20_CONTRACT_CLASS_HASH, (*ERC20_CONTRACT).clone()),
(*OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH, (*OZ_V1_ACCOUNT_CONTRACT_COMPILED).clone()),
]);

StateUpdatesWithDeclaredClasses {
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/types-test/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ build-external-contracts = [ ]
# socials.x = "https://twitter.com/dojostarknet"

[tool.dojo.env]
account_address = "0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624"
account_address = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
private_key = "0x1800000000300000180000000000030000000000003006001800006600"
rpc_url = "http://localhost:5050/"
2 changes: 1 addition & 1 deletion examples/rpc/starknet/starknet_getClass.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Content-Type: application/json
"method": "starknet_getClass",
"params": [
"latest",
"0x016c6081eb34ad1e0c5513234ed0c025b3c7f305902d291bad534cd6474c85bc"
"0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c"
],
"id":1
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rpc/starknet/starknet_getClassAt.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Content-Type: application/json
"method": "starknet_getClassAt",
"params": [
"latest",
"0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624"
"0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
],
"id":1
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rpc/starknet/starknet_getClassHashAt.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Content-Type: application/json
"method": "starknet_getClassHashAt",
"params": [
"pending",
"0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624"
"0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
],
"id": 1
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rpc/starknet/starknet_getNonce.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Content-Type: application/json
"method": "starknet_getNonce",
"params": [
"latest",
"0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624"
"0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
],
"id":1
}
Expand Down
2 changes: 1 addition & 1 deletion examples/spawn-and-move/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ name = "example"
rpc_url = "http://localhost:5050/"

# Default account for katana with seed = 0
account_address = "0x9238c8ca6b3c6ab45a793593b13d98797ccd3bda179d313553e51fee114624"
account_address = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
private_key = "0x1800000000300000180000000000030000000000003006001800006600"
world_address = "0x5010c31f127114c6198df8a5239e2b7a5151e1156fb43791e37e7385faa8138"

0 comments on commit 3bb35a6

Please sign in to comment.