Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge audit branch #1533

Merged
merged 61 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f129edf
fix: ensure world metadata are handled safely with ACL
glihm Jan 18, 2024
73d7809
fix: remove unused EXECUTE_ENTRYPOINT
glihm Jan 18, 2024
5016cfe
fix: add support for array for feature parity on metadata uri
glihm Jan 18, 2024
8ff011f
fix: ensure the new class hash to upgrade to has world() entrypoint
glihm Jan 19, 2024
787d8c8
wip: metadata rework
glihm Jan 23, 2024
597c436
feat: add expand env var for plugin debug
glihm Jan 25, 2024
f03cce8
feat: add support for multiple segment in the storage
glihm Jan 25, 2024
30e79c8
fix: adjust world entry points based on storage rework
glihm Jan 25, 2024
98ed168
fix: remove unused WhereClause
glihm Jan 25, 2024
bfd952b
fix: ensure deployed contracts addresses don't conflict with model names
glihm Jan 25, 2024
b1e1aa8
fix: remove TODO with expected behavior for packing
glihm Jan 25, 2024
0c0a4ec
fix: ensure fpow is never used with base equal to 0 in our case
glihm Jan 25, 2024
fdebe59
fix: remove old boolean enum usage
glihm Jan 25, 2024
c804b77
fix: ensure executor address is not zero
glihm Jan 25, 2024
29621f5
fix: ensure packing max bits max value
glihm Jan 25, 2024
88ccdde
fix: remove unused file
glihm Jan 25, 2024
ec03721
fix: remove database/utils not used for now
glihm Jan 25, 2024
e95153c
fix: remove index related code
glihm Jan 25, 2024
f548b79
fix: ensure empty data are well retrieved from storage
glihm Jan 26, 2024
4b5c0f8
fix: remove the length from the storage to be backward compatible
glihm Jan 31, 2024
9a94a39
fix: remove unused variable
glihm Jan 31, 2024
0cd0031
fix: adjust gas for test
glihm Jan 31, 2024
1d65123
feat: add function to verify ownership of tx account
glihm Jan 31, 2024
479197e
fix: remove executor and and deploy models instead
glihm Feb 3, 2024
04f7ef7
fix: keep class hash and contract address for models
glihm Feb 5, 2024
cc534af
feat: update toolchain for new model registration
glihm Feb 5, 2024
ef92799
fix: revise world documentation and refacto world errors
glihm Feb 5, 2024
c04ffa5
fix: remove unused storage variable
glihm Feb 6, 2024
202d077
fix: ensure the world address is protected against model registration
glihm Feb 6, 2024
572fdc8
fix: remove unused variable
glihm Feb 6, 2024
0e1ea82
fix: reintroduce missing test
glihm Feb 6, 2024
1a1f348
fix: ensure resource metadata are only controlled by world creator
glihm Feb 6, 2024
909d5a4
wip: on-going merge of audit branch
glihm Feb 12, 2024
bf87c55
fix: ensure resource metadata is well written in the manifest
glihm Feb 12, 2024
94373a0
fix: format + clippy
glihm Feb 12, 2024
1fcb8ad
tests(dojo-core): fix testing
glihm Feb 12, 2024
2f1a9de
Merge branch 'main' into merge-audit
glihm Feb 13, 2024
72586e5
fix: torii initial support for array and introspection
glihm Feb 13, 2024
064119b
wip: torii introspect integration for Array
glihm Feb 13, 2024
97fa30a
fix: add contract address to model's metadata
glihm Feb 13, 2024
c60a3ae
fix: Ty serialization for Array on Torii side
glihm Feb 13, 2024
8f6f2fa
fix: fix torii values index for store_set_record
glihm Feb 14, 2024
40deb70
fix: remove contract address from wrong model
glihm Feb 14, 2024
dbcf65e
feat: add array in testing graphql
glihm Feb 14, 2024
c5f5699
chore: restore main Cargo.lock
glihm Feb 14, 2024
4c58f78
fix: remove Copy trait for Record as now contains Array
glihm Feb 14, 2024
bf099e6
docs: add audit link in README
glihm Feb 14, 2024
b9e385a
docs: fix README audit format
glihm Feb 14, 2024
786e672
chore: use new tag of cainome wasm compatible + remove unused variables
glihm Feb 14, 2024
7a79cf9
fix: fmt
glihm Feb 14, 2024
d9f57b2
fix: add array as supported enum for models children ty
glihm Feb 14, 2024
28a083f
fix(dojo-core): remove print statements not required
glihm Feb 14, 2024
2c91bc7
fix: remove print for database but keep it for base_test address
glihm Feb 14, 2024
0456f4c
fix: add sozo command for class hash back and add contract address co…
glihm Feb 14, 2024
1575b14
ci: avoid rate limitation for protoc
glihm Feb 14, 2024
f2bdd07
fix(torii): ensure model contract address is in a new migration
glihm Feb 14, 2024
6619d6c
fix(torii): remove array indexing support for now
glihm Feb 14, 2024
589c9a4
fix(dojo-core): disable use of capacity derive on model
glihm Feb 14, 2024
c54c7c0
fix: fmt
glihm Feb 14, 2024
bd55004
fix(dojo-lang): run missing CAIRO_FIX tests
glihm Feb 14, 2024
082e369
fix: remove debug print
glihm Feb 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ itertools = "0.10.3"
jsonrpsee = { version = "0.16.2", default-features = false }
lazy_static = "1.4.0"
metrics-process = "1.0.9"
num-traits = { version = "0.2", default-features = false }
once_cell = "1.0"
parking_lot = "0.12.1"
pretty_assertions = "1.2.1"
Expand Down
4 changes: 0 additions & 4 deletions bin/sozo/src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ fn extract_events(manifest: &Manifest) -> HashMap<String, Vec<Event>> {
inner_helper(&mut events_map, abi);
}

if let Some(abi) = manifest.executor.abi.clone() {
inner_helper(&mut events_map, abi);
}

for contract in &manifest.contracts {
if let Some(abi) = contract.abi.clone() {
inner_helper(&mut events_map, abi);
Expand Down
4 changes: 2 additions & 2 deletions bin/sozo/src/commands/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub struct ModelArgs {

#[derive(Debug, Subcommand)]
pub enum ModelCommands {
#[command(about = "Retrieve the class hash of a model")]
ClassHash {
#[command(about = "Retrieve the contract address of a model")]
glihm marked this conversation as resolved.
Show resolved Hide resolved
ContractAddress {
#[arg(help = "The name of the model")]
name: String,

Expand Down
1 change: 0 additions & 1 deletion bin/sozo/src/ops/migration/migration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,5 @@ async fn migration_from_remote() {
sequencer.stop().unwrap();

assert_eq!(local_manifest.world.class_hash, remote_manifest.world.class_hash);
assert_eq!(local_manifest.executor.class_hash, remote_manifest.executor.class_hash);
assert_eq!(local_manifest.models.len(), remote_manifest.models.len());
}
54 changes: 20 additions & 34 deletions bin/sozo/src/ops/migration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::Path;

use anyhow::{anyhow, bail, Context, Result};
use dojo_world::contracts::abi::world::ResourceMetadata;
use dojo_world::contracts::cairo_utils;
use dojo_world::contracts::world::WorldContract;
use dojo_world::manifest::{Manifest, ManifestError};
Expand Down Expand Up @@ -286,34 +287,6 @@ where
{
let ui = ws.config().ui();

match &strategy.executor {
Some(executor) => {
ui.print_header("# Executor");
deploy_contract(executor, "executor", vec![], migrator, &ui, &txn_config).await?;

// There is no world migration, so it exists already.
if strategy.world.is_none() {
let addr = strategy.world_address()?;
let InvokeTransactionResult { transaction_hash } =
WorldContract::new(addr, &migrator)
.set_executor(&executor.contract_address.into())
.send()
.await
.map_err(|e| {
ui.verbose(format!("{e:?}"));
e
})?;

TransactionWaiter::new(transaction_hash, migrator.provider()).await?;

ui.print_hidden_sub(format!("Updated at: {transaction_hash:#x}"));
}

ui.print_sub(format!("Contract address: {:#x}", executor.contract_address));
}
None => {}
};

match &strategy.base {
Some(base) => {
ui.print_header("# Base Contract");
Expand Down Expand Up @@ -341,10 +314,7 @@ where
Some(world) => {
ui.print_header("# World");

let calldata = vec![
strategy.executor.as_ref().unwrap().contract_address,
strategy.base.as_ref().unwrap().diff.local,
];
let calldata = vec![strategy.base.as_ref().unwrap().diff.local];
deploy_contract(world, "world", calldata.clone(), migrator, &ui, &txn_config)
.await
.map_err(|e| {
Expand All @@ -358,11 +328,21 @@ where
if let Some(meta) = metadata.as_ref().and_then(|inner| inner.world()) {
match meta.upload().await {
Ok(hash) => {
let encoded_uri = cairo_utils::encode_uri(&format!("ipfs://{hash}"))?;
let mut encoded_uri = cairo_utils::encode_uri(&format!("ipfs://{hash}"))?;

// Metadata is expecting an array of capacity 3.
glihm marked this conversation as resolved.
Show resolved Hide resolved
if encoded_uri.len() < 3 {
encoded_uri.extend(vec![FieldElement::ZERO; 3 - encoded_uri.len()]);
}

let world_metadata = ResourceMetadata {
resource_id: FieldElement::ZERO,
metadata_uri: encoded_uri,
};

let InvokeTransactionResult { transaction_hash } =
WorldContract::new(world.contract_address, migrator)
.set_metadata_uri(&FieldElement::ZERO, &encoded_uri)
.set_metadata(&world_metadata)
.send()
.await
.map_err(|e| {
Expand All @@ -382,6 +362,12 @@ where
None => {}
};

// We don't declare and register the model for Resource Metadata for two reasons:
// 1. Having the ModelRegistered event is occupying space for data that are redundant with
// `MetadataUpdate` event.
// 2. This model is never used from outside world queries, only to set metadata. It should then
glihm marked this conversation as resolved.
Show resolved Hide resolved
// remain internal.

register_models(strategy, migrator, &ui, txn_config.clone()).await?;
deploy_contracts(strategy, migrator, &ui, txn_config).await?;

Expand Down
4 changes: 2 additions & 2 deletions bin/sozo/src/ops/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::commands::model::ModelCommands;

pub async fn execute(command: ModelCommands, env_metadata: Option<Environment>) -> Result<()> {
match command {
ModelCommands::ClassHash { name, world, starknet } => {
ModelCommands::ContractAddress { name, world, starknet } => {
let world_address = world.address(env_metadata.as_ref())?;
let provider = starknet.provider(env_metadata.as_ref())?;

Expand All @@ -17,7 +17,7 @@ pub async fn execute(command: ModelCommands, env_metadata: Option<Environment>)

let model = world.model_reader(&name).await?;

println!("{:#x}", model.class_hash());
println!("{:#x}", model.contract_address());
}

ModelCommands::Schema { name, world, starknet, to_json } => {
Expand Down
11 changes: 10 additions & 1 deletion bin/sozo/tests/test_data/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,15 @@
"writes": [],
"computed": []
},
"resource_metadata": {
"name": "",
"address": null,
"class_hash": "0x0",
"abi": null,
"reads": [],
"writes": [],
"computed": []
},
"base": {
"name": "dojo::base::base",
"class_hash": "0x6c458453d35753703ad25632deec20a29faf8531942ec109e6eb0650316a2bc",
Expand Down Expand Up @@ -1569,4 +1578,4 @@
]
}
]
}
}
83 changes: 83 additions & 0 deletions crates/dojo-core/src/base_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};

#[starknet::contract]
mod contract_upgrade {
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait, IWorldProvider};

#[storage]
struct Storage {}

Expand All @@ -27,6 +29,19 @@ mod contract_upgrade {
'daddy'
}
}

#[abi(embed_v0)]
impl WorldProviderImpl of IWorldProvider<ContractState> {
fn world(self: @ContractState) -> IWorldDispatcher {
IWorldDispatcher { contract_address: starknet::contract_address_const::<'world'>() }
}
}
}

#[starknet::contract]
mod contract_invalid_upgrade {
#[storage]
struct Storage {}
}

use contract_upgrade::{IQuantumLeapDispatcher, IQuantumLeapDispatcherTrait};
Expand All @@ -50,6 +65,18 @@ fn test_upgrade_from_world() {
assert(quantum_dispatcher.plz_more_tps() == 'daddy', 'quantum leap failed');
}

#[test]
#[available_gas(6000000)]
#[should_panic(expected: ('class_hash not world provider', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))]
fn test_upgrade_from_world_not_world_provider() {
let world = deploy_world();

let base_address = world.deploy_contract('salt', base::TEST_CLASS_HASH.try_into().unwrap());
let new_class_hash: ClassHash = contract_invalid_upgrade::TEST_CLASS_HASH.try_into().unwrap();

world.upgrade_contract(base_address, new_class_hash);
}

#[test]
#[available_gas(6000000)]
#[should_panic(expected: ('must be called by world', 'ENTRYPOINT_FAILED'))]
Expand All @@ -62,3 +89,59 @@ fn test_upgrade_direct() {
let upgradeable_dispatcher = IUpgradeableDispatcher { contract_address: base_address };
upgradeable_dispatcher.upgrade(new_class_hash);
}

use debug::PrintTrait;
glihm marked this conversation as resolved.
Show resolved Hide resolved

#[starknet::interface]
trait INameOnly<T> {
fn name(self: @T) -> felt252;
}

#[starknet::contract]
mod invalid_model {
#[storage]
struct Storage {}

#[abi(embed_v0)]
impl InvalidModelName of super::INameOnly<ContractState> {
fn name(self: @ContractState) -> felt252 {
// Pre-computed address of a contract deployed through the world.
0x34534b116332dd9459bfde65280822d84c130e3f1faeb63af8455f83e733f4f
}
}
}

#[starknet::contract]
mod invalid_model_world {
#[storage]
struct Storage {}

#[abi(embed_v0)]
impl InvalidModelName of super::INameOnly<ContractState> {
fn name(self: @ContractState) -> felt252 {
// World address is 0, and not registered as deployed through the world
// as it's itself.
0
}
}
}

#[test]
#[available_gas(6000000)]
#[should_panic(expected: ('invalid model name', 'ENTRYPOINT_FAILED',))]
fn test_deploy_from_world_invalid_model() {
let world = deploy_world();

let base_address = world.deploy_contract(0, base::TEST_CLASS_HASH.try_into().unwrap());
base_address.print();
glihm marked this conversation as resolved.
Show resolved Hide resolved

world.register_model(invalid_model::TEST_CLASS_HASH.try_into().unwrap());
}

#[test]
#[available_gas(6000000)]
#[should_panic(expected: ('invalid model name', 'ENTRYPOINT_FAILED',))]
fn test_deploy_from_world_invalid_model_world() {
let world = deploy_world();
world.register_model(invalid_model_world::TEST_CLASS_HASH.try_into().unwrap());
}
Loading
Loading