Skip to content

Commit

Permalink
introduce validation for timeout timestamp for eth ibc bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
RustNinja committed Mar 19, 2024
1 parent d662505 commit f4ff771
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
14 changes: 12 additions & 2 deletions custom/ibc-transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
Expand Down Expand Up @@ -30,8 +31,17 @@ func (k msgServer) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*typ
if params.ChannelFees != nil && len(params.ChannelFees) > 0 {
channelFee := findChannelParams(params.ChannelFees, msg.SourceChannel)
if channelFee != nil {
if channelFee.MinTimeoutTimestamp > 0 && msg.TimeoutTimestamp < channelFee.MinTimeoutTimestamp {
return nil, fmt.Errorf("incorrect timeout timestamp found during ibc transfer")
if channelFee.MinTimeoutTimestamp > 0 {

goCtx := sdk.UnwrapSDKContext(goCtx)
blockTime := goCtx.BlockTime()

timeoutTimeInFuture := time.Unix(0, int64(msg.TimeoutTimestamp))
difference := timeoutTimeInFuture.Sub(blockTime).Nanoseconds()

if difference < channelFee.MinTimeoutTimestamp {
return nil, fmt.Errorf("incorrect timeout timestamp found during ibc transfer")
}
}
coin := findCoinByDenom(channelFee.AllowedTokens, msg.Token.Denom)
if coin != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ message ChannelFee{
string channel = 1;
repeated CoinItem allowed_tokens = 2;
string fee_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
uint64 min_timeout_timestamp = 4;
int64 min_timeout_timestamp = 4;
}

message CoinItem{
Expand Down
64 changes: 32 additions & 32 deletions x/ibctransfermiddleware/types/ibctransfermiddleware.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f4ff771

Please sign in to comment.