Skip to content

Commit

Permalink
Merge pull request #467 from ComposableFi/rustninja/eth-bridge-ibc-mi…
Browse files Browse the repository at this point in the history
…n-timestamp

introduce validation for timeout timestamp for eth ibc bridge
  • Loading branch information
kkast authored Mar 20, 2024
2 parents 67e2529 + a4a7c29 commit f0497a8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 35 deletions.
18 changes: 16 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,21 @@ 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))
if timeoutTimeInFuture.Before(blockTime) {
return nil, fmt.Errorf("incorrect timeout timestamp found during ibc transfer. timeout timestamp is in the past")
}

difference := timeoutTimeInFuture.Sub(blockTime).Nanoseconds()

if difference < channelFee.MinTimeoutTimestamp {
return nil, fmt.Errorf("incorrect timeout timestamp found during ibc transfer. too soon")
}
}
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 f0497a8

Please sign in to comment.