Skip to content

Commit

Permalink
Merge pull request #2865 from irisnet/yuandu/fix-vesting-loophole
Browse files Browse the repository at this point in the history
fix: vesting account loophole
  • Loading branch information
aofengli authored Sep 13, 2023
2 parents 1a98a50 + 08455d5 commit 419abb5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
* (IRISHub) [\#2852](https://github.com/irisnet/irishub/pull/2852) refactor: fix eip712 signature and inject ParseChainID method
* (IRISMod) [irismod \#367](https://github.com/irisnet/irismod/pull/367) Fix rest uri conflict in mt module

### Security

* (IRISHub) [\#2865](https://github.com/irisnet/irishub/pull/2865) Disable the vesting account creation to prevent contract address front-running.

## 2.0.0

### State Machine Breaking
Expand Down
1 change: 1 addition & 0 deletions ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
RejectMessagesDecorator{},
NewRejectVestingDecorator(),
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
Expand Down
31 changes: 31 additions & 0 deletions ante/vesting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

// RejectVestingDecorator is responsible for rejecting the vesting msg
type RejectVestingDecorator struct{}

// NewRejectVestingDecorator returns an instance of ValidateVestingDecorator
func NewRejectVestingDecorator() RejectVestingDecorator {
return RejectVestingDecorator{}
}

// AnteHandle checks the transaction
func (vvd RejectVestingDecorator) AnteHandle(ctx sdk.Context,
tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
for _, msg := range tx.GetMsgs() {
switch msg.(type) {
case *vestingtypes.MsgCreateVestingAccount,
*vestingtypes.MsgCreatePermanentLockedAccount,
*vestingtypes.MsgCreatePeriodicVestingAccount:
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
"currently doesn't support creating vesting account")
}
}
return next(ctx, tx, simulate)
}

0 comments on commit 419abb5

Please sign in to comment.