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: initial execution context implementation #392

Merged

Conversation

ftupas
Copy link
Contributor

@ftupas ftupas commented May 31, 2023

This pr does the following:

  • introduce the Context struct to system execution to provide the dojo execution context
  • update executor so it passes the context instead of the world_address
  • generation logic in system.rs and commands are updated to inject the context
  • use the execution context in auth checking
  • store execution role in world
  • resolve Introduce execution context #345

Note:

  • this pr doesn't implement authorization checking yet using the context
  • caller system is still stored in the world contract, will have to be refactored once context is used for auth

@@ -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$ {
Copy link
Contributor Author

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$);
Copy link
Contributor Author

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

Copy link
Contributor

@tarrencev tarrencev left a 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
Copy link
Contributor

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

Suggested change
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

Copy link
Contributor Author

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!

Copy link
Contributor Author

@ftupas ftupas left a 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
Copy link
Contributor Author

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!

@ftupas ftupas force-pushed the feat/initial-execution-context-implementation branch from 0d5395c to e072fbc Compare June 1, 2023 23:38
@ftupas ftupas requested a review from tarrencev June 1, 2023 23:41
@ftupas ftupas force-pushed the feat/initial-execution-context-implementation branch from e072fbc to ab82d12 Compare June 2, 2023 00:34
if role_id == 'Admin'.into() {
assert(is_account_admin(), 'only admin can set Admin role');
}
execution_role::write(system, role_id);
Copy link
Contributor

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

Copy link
Contributor Author

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

@ftupas ftupas force-pushed the feat/initial-execution-context-implementation branch from ab82d12 to 510fa69 Compare June 2, 2023 22:44
Copy link
Contributor Author

@ftupas ftupas left a 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 !

if role_id == 'Admin'.into() {
assert(is_account_admin(), 'only admin can set Admin role');
}
execution_role::write(system, role_id);
Copy link
Contributor Author

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

Copy link
Contributor

@tarrencev tarrencev left a 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

@tarrencev tarrencev force-pushed the feat/initial-execution-context-implementation branch from 835ac01 to 1908bec Compare June 5, 2023 21:10
if role_id == 'Admin'.into() {
assert(is_account_admin(), 'only admin can set Admin role');
}
let caller = get_tx_info().unbox().account_contract_address;
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce execution context
2 participants