Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Add cleos helper command to add eosio.code to permission #6072

Closed
arhag opened this issue Oct 19, 2018 · 3 comments
Closed

Add cleos helper command to add eosio.code to permission #6072

arhag opened this issue Oct 19, 2018 · 3 comments

Comments

@arhag
Copy link
Contributor

arhag commented Oct 19, 2018

Contracts will almost always need to satisfy some authorization of _self to do things like sending inline actions. This requires adding the _self@eosio.code permission level to the authority (in a way that allows it to unilaterally satisfy the authority) of the permission(s) that the contract wishes to satisfy the authorization for.

The process of adding the eosio.code permission is cumbersome and error-prone if done manually. A new sub-command added to the cleos could automate this process by fetching the current authority of a specified permission, modifying it (if possible and not already done) to add the the eosio.code permission to the authority in a way that unilaterally satisfies the authority, and then push an eosio::updateauth action to change the permission authority to the newly computed authority.

@conr2d
Copy link
Contributor

conr2d commented Oct 20, 2018

Should this new command have ability to add only eosio.code level permission of _self? What about arbitrary account which isn't _self? Someone having multiple accounts could try writing a contract managing his all accounts.

@arhag
Copy link
Contributor Author

arhag commented Oct 22, 2018

@conr2d:

This issue is about providing an easy way for contract developers to setup their account permissions so that their deployed contract can function properly. So I see it as a quick convenience command that doesn't require the developer to manually write any part of the authority structure and merely requires them to provide the permission they want to "upgrade".

Part of that permission upgrade process requires fetching the existing authority and figuring out what the appropriate weight of the account@eosio.code permission level should be so that it all works properly. I don't want to complicate this command by requiring the user to figure out what the weight of the new permission level should be. However, I don't see a problem with generalizing the command to support adding a permission level contract_account@eosio.code for any arbitrary account contract_account, as long as it is clear that the weight will automatically be determined so that the contract_account's contract can unilaterally satisfy that permission.

So here is how I envision such a generalized cleos command:

  • The user needs to specify the account and permission to identify the specific permission they want to upgrade, similar to how they would have to provide such information for the cleos set account permission sub-command.
  • The user also specifies the account contract_account that will be added to the authority as contract_account@eosio.code with the appropriate weight calculated.
  • No other information needs to be provided by the cleos user.
  • The command will fetch the existing authority of the specified permission and do the following:
    • If contract_account@eosio.code already exists in the accounts section of the authority with a weight greater than equal to threshold, do nothing other than printing out a warning to the user that nothing needs to be done.
    • If threshold is greater than or equal to 2^16, then return an error to the user that it is not possible to fulfill the request because the threshold value is too high.
    • Otherwise, add contract_account@eosio.code to the accounts section of the retrieved authority with a weight equal to threshold, and then push an eosio::updateauth action to modify the authority of the specified permission to the newly constructed authority.
  • The way a contract developer with typically use the cleos sub-command is to call it with permission set to active and contract_account set to the value of account which would be the account hosting their contract.

@arhag
Copy link
Contributor Author

arhag commented Oct 24, 2018

Resolved by #6116.

@arhag arhag closed this as completed Oct 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants