-
Notifications
You must be signed in to change notification settings - Fork 195
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: initial execution context implementation #392
feat: initial execution context implementation #392
Conversation
crates/dojo-lang/src/system.rs
Outdated
@@ -122,8 +123,7 @@ impl System { | |||
rewrite_nodes.push(RewriteNode::interpolate_patched( | |||
" | |||
#[external] | |||
fn execute($parameters$$separator$world_address: starknet::ContractAddress) \ | |||
$ret_clause$ { | |||
fn execute($parameters$$separator$ctx: Context) $ret_clause$ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the context instead of world_address
}.execute(dojo_core::string::ShortStringTrait::new('$system$'), $calldata$); | ||
"let $var_name$ = \ | ||
ctx.world.execute(dojo_core::string::ShortStringTrait::new('$system$'), \ | ||
$role_id$, $calldata$); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add role_id to execute command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks really good so far!
struct Context { | ||
world: IWorldDispatcher, // Dispatcher to the world contract | ||
caller_account: ContractAddress, // Address of the origin | ||
caller_system: ClassHash, // Class hash of the calling system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we probably want a system name here as well, since the class can be changed
caller_system: ClassHash, // Class hash of the calling system | |
caller_system: ShortString, // Name of the calling system | |
caller_system_class_hash: ClassHash, // Class hash of the calling system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah good catch, will change this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback and review @tarrencev !
struct Context { | ||
world: IWorldDispatcher, // Dispatcher to the world contract | ||
caller_account: ContractAddress, // Address of the origin | ||
caller_system: ClassHash, // Class hash of the calling system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah good catch, will change this!
0d5395c
to
e072fbc
Compare
e072fbc
to
ab82d12
Compare
crates/dojo-core/src/world.cairo
Outdated
if role_id == 'Admin'.into() { | ||
assert(is_account_admin(), 'only admin can set Admin role'); | ||
} | ||
execution_role::write(system, role_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm do we need the system
here?
i think every system execute call could be proceeded by a assume_role
call and i think we want to validate that the caller has permission to assume the role here?
that way, if there are multiple executions in a multicall, the caller can, for example, assume a role once that can be used across all the execute calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right good catch, I'm removing the system here and we just check if the caller has this permission to assume the role 👍 also this way, the role can be used across multiple system calls
ab82d12
to
510fa69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback and review @tarrencev !
crates/dojo-core/src/world.cairo
Outdated
if role_id == 'Admin'.into() { | ||
assert(is_account_admin(), 'only admin can set Admin role'); | ||
} | ||
execution_role::write(system, role_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right good catch, I'm removing the system here and we just check if the caller has this permission to assume the role 👍 also this way, the role can be used across multiple system calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another banger
great job
- Remove passing of role from world interface - Move calling system from storage to context - Implement interface for setting of execution role - Update authorization check - use default role if not set
835ac01
to
1908bec
Compare
if role_id == 'Admin'.into() { | ||
assert(is_account_admin(), 'only admin can set Admin role'); | ||
} | ||
let caller = get_tx_info().unbox().account_contract_address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to validate the user can assume this role here still right?
This pr does the following:
Context
struct to system execution to provide the dojo execution contextworld_address
system.rs
andcommands
are updated to inject the contextNote:
this pr doesn't implement authorization checking yet using the contextcaller system is still stored in the world contract, will have to be refactored once context is used for auth