Skip to content

Commit

Permalink
Merge branch 'master' into paul/adr-005-multisig-chainlink-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 14, 2022
2 parents 9eb1093 + 61ace0f commit 78be05b
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: none
pull_request: 717
description: Added IBC AnteHandler
backward_compatible: true
date: 2022-01-10T10:48:44.785928578Z
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Deploy 🚀
if: github.ref == 'refs/heads/master'
uses: JamesIves/github-pages-deploy-action@4.2.0
uses: JamesIves/github-pages-deploy-action@v4.2.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: swagger-pages
Expand Down
54 changes: 54 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
channelkeeper "github.com/cosmos/ibc-go/v2/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/v2/modules/core/ante"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions

IBCChannelkeeper channelkeeper.Keeper
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

var sigGasConsumer = options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(),
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCChannelkeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
}
17 changes: 10 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,16 @@ func NewDesmosApp(
// Initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
anteHandler, err := ante.NewAnteHandler(
ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
IBCChannelkeeper: app.IBCKeeper.ChannelKeeper,
},
)
if err != nil {
Expand Down
72 changes: 72 additions & 0 deletions docs/architecture/adr-004-application-links-expiration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ADR 004: Expiration of application links

## Changelog

- September 20th, 2021: Initial draft;
- September 21th, 2021: Moved from DRAFT to PROPOSED;
- December 22th, 2021: First review;
- January 04th, 2022: Second review;
- January 10th, 2022: Third review;
- January 12th, 2022: Fourth review.

## Status

PROPOSED

## Abstract

Currently when a user links a centralized application with their Desmos profile, the created link contains a timestamp of when it has been created.
Since centralized applications' username can be switched and sold, we SHOULD implement an "expiration date" system on links.
This means that after a certain amount of time passes, the link will be automatically marked deleted and the user has to connect it again in order to keep it valid.

## Context

Desmos `x/profiles` module gives users the possibility to link their Desmos profile with both centralized application and
other blockchains accounts. By doing this, a user can be verified as the owner of those accounts and prove to the system
that they're not impersonating anyone else. This verification however remains valid only if the user
never trades or sells their centralized-app username to someone else. If they do, the link to such username MUST be invalidated.
Unfortunately for us, it's not possible to understand when this happens since it's off-chain.
To prevent this situation, an "expiration time" SHOULD be added to the `ApplicationLink` object.

## Decision

To implement the link expiration we will act as follow:
1. extend the `ApplicationLink` structure by adding an `ExpiratonTime` field that represents the time when the link will expire and will be deleted from the store;
2. save a reference of the expiring link inside the store using a prefix and a `time.Time` value which will make it easy to iterate over the expired links;
3. add a new keeper method that allows to iterate over the expired links;
4. inside the `BeginBlock` method, iterate over all the expired links and delete them from the store.

We will also need to introduce a new `x/profiles` on chain parameter named `AppLinkParams` which contains
the default validity duration of all the app links. The parameter will be later used inside the `StartProfileConnection`
to calculate the estimated expiration time of each `AppLink`.

## Consequences

### Backwards Compatibility

This update will affect the `ApplicationLink` object by adding the new `ExpirationTime`
field and breaking the compatibility with the previous versions of the software. To allow
a smooth update and overcome these compatibility issues, we need to set up a proper migration
from the previous versions to the one that will include the additions contained in this ADR.

### Positive

- Considerably reduce the possibility of impersonation of entities and users of centralized apps;

### Negative

- By adding the extra `ExpirationTime` field we are going to raise the overall `AppLinks` handling complexity. Since we're performing an iteration over all the expired link references inside at the start of each block this can require an amount of time that SHOULD be studied with benchmark tests during the implementation.

### Neutral

(none known)

## Further Discussions

## Test Cases [optional]
- The expired `AppLinks` are deleted correctly when they expire.
-
## References

- Issue [#516](https://github.com/desmos-labs/desmos/issues/516)
- PR [#562](https://github.com/desmos-labs/desmos/pull/562)

0 comments on commit 78be05b

Please sign in to comment.