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(runtime): Add delegate keys #342

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions neps/nep-0342.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
NEP: 297
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to NEP: 342

Title: Delegate Keys
Author: Illia Polosukhin <illia@near.org>
DiscussionsTo: https://gov.near.org/t/proposal-extending-nears-account-with-aliases-and-delegated-keys/9450
Status: Draft
Type:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to Type: Standards Track

Category: Runtime
Created: 28-Mar-2022
---

## Summary

Delegate keys allow to assign permissions to another account instead of a key.
This allows to delegate ownership of an account by giving set of permissions that are usually restricted only to FullAccessKey.

## Motivation

Issue that became evident trying to develop upgradability patterns for contracts is complexity of going from full access key on the contract to a contract managed by multisig or a DAO.

Right now it is required to implement a complex logic of upgrading contract and managing assets/control inside the contract in the first version to allow “owner” account to call these methods.

## Rationale and alternatives
[rationale-and-alternatives]: #rationale-and-alternatives

## Specification

See updates to AccessKey.md and Actions.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are looking to have these NEP spec artifacts as stand-alone as possible. It feels superfluous, but could you please copy the content of AccessKey.md and Actions.md into this section. In future new specs I am going to recommend only creating the docusaurus sections during the Last Call phase.


## Reference Implementation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to be an optional section for non-Contract categories of standards like this one. Please feel free to omit.


TBD

## Drawbacks

This adds complexity to the account model.

## Copyright
[copyright]: #copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
34 changes: 32 additions & 2 deletions specs/DataStructures/AccessKey.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Access Keys

Access key provides an access for a particular account. Each access key belongs to some account and
Access key provides access for a particular account. Each access key belongs to some account and
is identified by a unique (within the account) public key. Access keys are stored as `account_id,public_key` in a trie state. Account can have from [zero](#account-without-access-keys) to multiple access keys.

```rust
Expand All @@ -21,6 +21,7 @@ There are 2 types of `AccessKeyPermission` in Near currently: `FullAccess` and `
pub enum AccessKeyPermission {
FunctionCall(FunctionCallPermission),
FullAccess,
DelegateCall(DelegateCallPermission),
}
```

Expand Down Expand Up @@ -48,6 +49,35 @@ pub struct FunctionCallPermission {
}
```

## AccountKeyPermission::DelegateCall

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the following warning section:

:::caution
This is part of proposed spec [NEP-342](https://github.com/near/NEPs/blob/master/neps/nep-0342.md) and subject to change.
:::

Grants limited permission to make some type of actions from a specified `sender_id`.

```rust
/// Permission per each type of `Action`.
pub enum ActionPermission {
CreateAccount,
DeployContract,
FunctionCall,
Transfer,
Stake,
AddKey,
DeleteKey,
DeleteAccount,
DelegateAction,
}

pub struct DelegateCallPermission {
/// The access key only allows actions from the given set from given sender account id.
pub sender_id: AccountId,

/// Set of allowed actions by given `sender_id`.
pub allowed: Set<ActionPermission>,
}
```

## Account without access keys

If account has no access keys attached it means that it has no owner who can run transactions from its behalf. However, if such accounts has code it can be invoked by other accounts and contracts.
If account has no access keys attached it means that it has no external party who can run transactions from its behalf.
However, if such account has code, it can be invoked by other accounts and contracts.
Contract code can also add and remove keys or call actions on the account it's deployed.
27 changes: 27 additions & 0 deletions specs/RuntimeSpec/Actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum Action {
AddKey(AddKeyAction),
DeleteKey(DeleteKeyAction),
DeleteAccount(DeleteAccountAction),
DelegateAction(DelegateAction),
}
```

Expand Down Expand Up @@ -276,3 +277,29 @@ DeleteAccountStaking { account_id: AccountId }

**Execution Error**:
- If state or storage is corrupted, a `StorageError` is returned.

## DelegateAction

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the following warning section:

:::caution
This is part of proposed spec [NEP-342](https://github.com/near/NEPs/blob/master/neps/nep-0342.md) and subject to change.
:::

Delegate action allows to execute an action on antoher account.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*another


```rust
pub struct DelegateAction {
/// Which account to delegate given action.
pub delegatee_id: AccountId,
/// Specific action to call on the delegatee account.
pub action: Action,
}
```

**Outcomes**:
- A new receipt is created toward `delegatee_id` with `action`. Receiver will consider permissions (delegated keys) when receipt arrives which will result in execution of such action or failure.

### Errors

**Validation Error**
- If `delegatee_id` is not a valid account id, the following error will be returned
```rust
/// Invalid account ID.
InvalidAccountId { account_id: AccountId },
```