Skip to content

Commit

Permalink
fix(dojo-core): ensure contract deployment verifies if the selector i…
Browse files Browse the repository at this point in the history
…s unregistered (#2473)

fix: ensure a contract can't be deployed with selector clash
  • Loading branch information
glihm authored Sep 25, 2024
1 parent 8f4bcbb commit 731ff47
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 24 deletions.
4 changes: 4 additions & 0 deletions crates/dojo-core/src/world/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub fn resource_not_registered(resource: felt252) -> ByteArray {
format!("Resource `{}` is not registered", resource)
}

pub fn resource_already_registered(resource: felt252) -> ByteArray {
format!("Resource `{}` is already registered", resource)
}

pub fn not_owner(caller: ContractAddress, resource: felt252) -> ByteArray {
format!("Caller `{:?}` is not the owner of the resource `{}`", caller, resource)
}
Expand Down
6 changes: 6 additions & 0 deletions crates/dojo-core/src/world/world_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,12 @@ pub mod world {
self.assert_caller_namespace_write_access(@namespace, namespace_hash);

let selector = dispatcher.selector();

match self.resources.read(selector) {
Resource::Unregistered => {},
_ => panic_with_byte_array(@errors::resource_already_registered(selector))
};

self.owners.write((selector, caller), true);
self.resources.write(selector, Resource::Contract((class_hash, contract_address)));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e"
original_class_hash = "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e"
class_hash = "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0"
original_class_hash = "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0"
abi = "manifests/dev/base/abis/dojo-world.json"
tag = "dojo-world"
manifest_name = "dojo-world"
2 changes: 1 addition & 1 deletion crates/sozo/ops/src/tests/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn test_model_ops(sequencer: &RunnerCtx) {
)
.await
.unwrap(),
Felt::from_hex("0x68e3a53988f20d84c6652f25d6add070633a5d05f8c4ac68285cacb228afa14")
Felt::from_hex("0x237386e1b35190b45c7d0aa29b3957d84ba2d4d22c2c10f7511b3abf0d7bd73")
.unwrap()
);

Expand Down
2 changes: 1 addition & 1 deletion examples/spawn-and-move/dojo_dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
account_address = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03"
private_key = "0x1800000000300000180000000000030000000000003006001800006600"
world_address = "0x5fedbace16902d9ca4cdc1522f9fe156cd8c69a5d25e1436ee4b7b9933ad997"
world_address = "0x15b584f1132fe386a0aa7a447e7073233a545ac4b84b361ed797edaa8f0f14"
4 changes: 2 additions & 2 deletions examples/spawn-and-move/manifests/dev/base/dojo-world.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e"
original_class_hash = "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e"
class_hash = "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0"
original_class_hash = "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0"
abi = "manifests/dev/base/abis/dojo-world.json"
tag = "dojo-world"
manifest_name = "dojo-world"
16 changes: 8 additions & 8 deletions examples/spawn-and-move/manifests/dev/deployment/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"world": {
"kind": "WorldContract",
"class_hash": "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e",
"original_class_hash": "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e",
"class_hash": "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0",
"original_class_hash": "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0",
"abi": [
{
"type": "impl",
Expand Down Expand Up @@ -1234,8 +1234,8 @@
]
}
],
"address": "0x5fedbace16902d9ca4cdc1522f9fe156cd8c69a5d25e1436ee4b7b9933ad997",
"transaction_hash": "0x4c8e0d28e32c21f29f33ff68e245b65fcc91763abf53f284cce8c2274ff6115",
"address": "0x15b584f1132fe386a0aa7a447e7073233a545ac4b84b361ed797edaa8f0f14",
"transaction_hash": "0x715b5d1bde9766b6db3f8b903a0626343c553a91e199f96d721644d121e676b",
"block_number": 3,
"seed": "dojo_examples",
"metadata": {
Expand All @@ -1255,7 +1255,7 @@
"contracts": [
{
"kind": "DojoContract",
"address": "0x3287947f8080cdf20c0a6e88d50a8d824e04f035bd34550316e6768d87d35de",
"address": "0x54de18a0d4dcd51213c3375061fd5cd5a30dbefdb50c9718ae9a8004162abbd",
"class_hash": "0x67a20ea91a4b9bb9cdb46cefc41dd6ca4c07c22d4d413205720963944fd817d",
"original_class_hash": "0x67a20ea91a4b9bb9cdb46cefc41dd6ca4c07c22d4d413205720963944fd817d",
"base_class_hash": "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2",
Expand Down Expand Up @@ -1686,7 +1686,7 @@
},
{
"kind": "DojoContract",
"address": "0x6ee438f6082f930c1b874cfefa2e380b1bd8eb8d77374bf18e8224c5dd1819",
"address": "0x3af2ea94daa59a22d5b979004019de544dbf92a2e4ff5f4869abb7ded9ca669",
"class_hash": "0x4590a27e4ec7366358ba5f60323777f301435ebbdd113ab02c54b947717530d",
"original_class_hash": "0x4590a27e4ec7366358ba5f60323777f301435ebbdd113ab02c54b947717530d",
"base_class_hash": "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2",
Expand Down Expand Up @@ -1925,7 +1925,7 @@
},
{
"kind": "DojoContract",
"address": "0xd9e080358f8bcb8ca52182623e63b4777dbf54dedd3742bd86fabb3d1991ba",
"address": "0x7ba7852396ce1e20e332e6ad1af1a978c866d61d8ad3d2d58f618dac027c8e1",
"class_hash": "0x67edb33671cd2f5b766d073e3dec53b03400761a20f349ea9628cf4c883b393",
"original_class_hash": "0x67edb33671cd2f5b766d073e3dec53b03400761a20f349ea9628cf4c883b393",
"base_class_hash": "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2",
Expand Down Expand Up @@ -2146,7 +2146,7 @@
},
{
"kind": "DojoContract",
"address": "0x3fec924b42052f14a9c4bb48abae2068d66034e3cc6e063353b87a5659f5040",
"address": "0x3be251ef8450c757a5712e203eef1ce65a49678a3fe711df29012de99d61c8",
"class_hash": "0x40e824b8814bafef18cce2cf68f5765e9c9a1c86f55a8491b0c2a4faebdcc87",
"original_class_hash": "0x40e824b8814bafef18cce2cf68f5765e9c9a1c86f55a8491b0c2a4faebdcc87",
"base_class_hash": "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2",
Expand Down
16 changes: 8 additions & 8 deletions examples/spawn-and-move/manifests/dev/deployment/manifest.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[world]
kind = "WorldContract"
class_hash = "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e"
original_class_hash = "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e"
class_hash = "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0"
original_class_hash = "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0"
abi = "manifests/dev/deployment/abis/dojo-world.json"
address = "0x5fedbace16902d9ca4cdc1522f9fe156cd8c69a5d25e1436ee4b7b9933ad997"
transaction_hash = "0x4c8e0d28e32c21f29f33ff68e245b65fcc91763abf53f284cce8c2274ff6115"
address = "0x15b584f1132fe386a0aa7a447e7073233a545ac4b84b361ed797edaa8f0f14"
transaction_hash = "0x715b5d1bde9766b6db3f8b903a0626343c553a91e199f96d721644d121e676b"
block_number = 3
seed = "dojo_examples"
manifest_name = "dojo-world"
Expand All @@ -23,7 +23,7 @@ manifest_name = "dojo-base"

[[contracts]]
kind = "DojoContract"
address = "0x3287947f8080cdf20c0a6e88d50a8d824e04f035bd34550316e6768d87d35de"
address = "0x54de18a0d4dcd51213c3375061fd5cd5a30dbefdb50c9718ae9a8004162abbd"
class_hash = "0x67a20ea91a4b9bb9cdb46cefc41dd6ca4c07c22d4d413205720963944fd817d"
original_class_hash = "0x67a20ea91a4b9bb9cdb46cefc41dd6ca4c07c22d4d413205720963944fd817d"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
Expand All @@ -47,7 +47,7 @@ manifest_name = "dojo_examples-actions-40b6994c"

[[contracts]]
kind = "DojoContract"
address = "0x6ee438f6082f930c1b874cfefa2e380b1bd8eb8d77374bf18e8224c5dd1819"
address = "0x3af2ea94daa59a22d5b979004019de544dbf92a2e4ff5f4869abb7ded9ca669"
class_hash = "0x4590a27e4ec7366358ba5f60323777f301435ebbdd113ab02c54b947717530d"
original_class_hash = "0x4590a27e4ec7366358ba5f60323777f301435ebbdd113ab02c54b947717530d"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
Expand All @@ -61,7 +61,7 @@ manifest_name = "dojo_examples-dungeon-6620e0e6"

[[contracts]]
kind = "DojoContract"
address = "0xd9e080358f8bcb8ca52182623e63b4777dbf54dedd3742bd86fabb3d1991ba"
address = "0x7ba7852396ce1e20e332e6ad1af1a978c866d61d8ad3d2d58f618dac027c8e1"
class_hash = "0x67edb33671cd2f5b766d073e3dec53b03400761a20f349ea9628cf4c883b393"
original_class_hash = "0x67edb33671cd2f5b766d073e3dec53b03400761a20f349ea9628cf4c883b393"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
Expand All @@ -75,7 +75,7 @@ manifest_name = "dojo_examples-mock_token-31599eb2"

[[contracts]]
kind = "DojoContract"
address = "0x3fec924b42052f14a9c4bb48abae2068d66034e3cc6e063353b87a5659f5040"
address = "0x3be251ef8450c757a5712e203eef1ce65a49678a3fe711df29012de99d61c8"
class_hash = "0x40e824b8814bafef18cce2cf68f5765e9c9a1c86f55a8491b0c2a4faebdcc87"
original_class_hash = "0x40e824b8814bafef18cce2cf68f5765e9c9a1c86f55a8491b0c2a4faebdcc87"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e"
original_class_hash = "0x6f4515274ee23404789c3351a77107d0ec07508530119822046600ca6948d6e"
class_hash = "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0"
original_class_hash = "0x5c4271c8cd454ceb8049d2b0724c99d12c2ef8077fc6ad325b18978f614aab0"
abi = "manifests/release/base/abis/dojo-world.json"
tag = "dojo-world"
manifest_name = "dojo-world"
Binary file modified spawn-and-move-db.tar.gz
Binary file not shown.
Binary file modified types-test-db.tar.gz
Binary file not shown.

0 comments on commit 731ff47

Please sign in to comment.