-
Notifications
You must be signed in to change notification settings - Fork 0
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: authz rules grant specific #3
base: vitwit/v0.50.5
Are you sure you want to change the base?
Changes from 1 commit
3b2a261
07a9f17
7394c19
a03ab3b
0db8ed2
dbdd25c
9f54de7
0f329bf
70be56d
bb94e63
9ae7ce5
eabb609
24b70aa
7c4fab8
62db0e7
d5b0c28
0002d1b
80a08d1
7954140
b8aad25
4c90b55
b4571b8
2601990
5c21c60
5fd01d4
4e27d6a
4422fda
0fc59af
7a4da4c
ffa9b81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||||||
# Description | ||||||||||
|
||||||||||
Problem: | ||||||||||
The existing authorization (authz) module lacks the flexibility to grant permissions (authz grants) for various types of messages along with specific conditions or rules. This limitation constrains users from customizing their transaction behavior based on specific needs or strategies. | ||||||||||
|
||||||||||
## Specific Examples of Limitations: | ||||||||||
Swapping Reward Tokens: | ||||||||||
- Currently, users cannot set a rule to swap their reward tokens or any other tokens for another token with a specified limit. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
Sending Tokens to Selected Addresses: | ||||||||||
- Users are unable to authorize sending tokens to a pre-defined or selected address, restricting the ability to control where tokens are transferred. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
Staking Tokens with Limitations: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace it with gov usecase.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, consider spec format of cosmos-sdk. It describes the problem, but clearly explain about solution, conclusion etc instead of PR diff. |
||||||||||
- The module does not allow users to grant permission to stake tokens with certain limits or to stake only with selected validators. This limits the user's control over staking decisions. | ||||||||||
|
||||||||||
## PR diff: | ||||||||||
This PR adds a feature which an authz can be granted with some rules, | ||||||||||
for example: | ||||||||||
- if a staker wants to stake some portion of rewards he can do that by allowing max stake amount | ||||||||||
- if he wants to stake only to selected validators | ||||||||||
- swap some portion of rewards to another token or liquid staked token | ||||||||||
- also we can add rules to every message before granting. | ||||||||||
|
||||||||||
Changes: | ||||||||||
updated the ante handlers flow to check in the message is executing the authz message and any rules need to be checked before processing the message. if the message is not reaching the rules then it will eventually fail. | ||||||||||
|
||||||||||
added an extra ante handler: | ||||||||||
``` | ||||||||||
// handleCheckSendAuthzRules returns true if the rules are voilated | ||||||||||
func (azd AuthzDecorator) handleSendAuthzRules(ctx sdk.Context, msg *banktypes.MsgSend, grantee []byte) error { | ||||||||||
granter, err := azd.ak.AddressCodec().StringToBytes(msg.FromAddress) | ||||||||||
if err != nil { | ||||||||||
return err | ||||||||||
} | ||||||||||
|
||||||||||
_, rules := azd.azk.GetAuthzWithRules(ctx, grantee, granter, sdk.MsgTypeURL(&banktypes.MsgSend{})) | ||||||||||
for _, rule := range rules { | ||||||||||
if rule.Key == authztypes.AllowedRecipients { | ||||||||||
isAllowed := false | ||||||||||
for _, allowedRecipient := range rule.Values { | ||||||||||
if msg.ToAddress == allowedRecipient { | ||||||||||
isAllowed = true | ||||||||||
break | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
if !isAllowed { | ||||||||||
return errorsmod.Wrap(sdkerrors.ErrTxDecode, "Recipient is not in the allowed list of the grant") | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
if rule.Key == authztypes.MaxAmount { | ||||||||||
limit, err := sdk.ParseCoinsNormalized(strings.Join(rule.Values, ",")) | ||||||||||
if err != nil { | ||||||||||
return err | ||||||||||
} | ||||||||||
if !limit.IsAllGTE(msg.Amount) { | ||||||||||
return errorsmod.Wrap(sdkerrors.ErrTxDecode, "Amount exceeds the max_amount limit set by the granter") | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
return nil | ||||||||||
} | ||||||||||
``` | ||||||||||
the above snippet checks the rules for `MsgSend` likewise we can add checks to every messages. |
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.