Skip to content

Commit

Permalink
Merge pull request #539 from neutron-org/fix/fee_overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pr0n00gler authored May 28, 2024
2 parents 455d33b + f1e5f58 commit 1812213
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions x/dex/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,19 @@ func TestMsgDepositValidate(t *testing.T) {
},
types.ErrTickOutsideRange,
},
{
"invalid fee overflow",
types.MsgDeposit{
Creator: sample.AccAddress(),
Receiver: sample.AccAddress(),
Fees: []uint64{559681},
TickIndexesAToB: []int64{0},
AmountsA: []sdkmath.Int{sdkmath.OneInt()},
AmountsB: []sdkmath.Int{sdkmath.OneInt()},
Options: []*types.DepositOptions{{DisableAutoswap: false}},
},
types.ErrInvalidFee,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -1878,6 +1891,17 @@ func TestMsgWithdrawalValidate(t *testing.T) {
},
types.ErrTickOutsideRange,
},
{
"invalid fee overflow",
types.MsgWithdrawal{
Creator: sample.AccAddress(),
Receiver: sample.AccAddress(),
Fees: []uint64{559681},
TickIndexesAToB: []int64{0},
SharesToRemove: []sdkmath.Int{sdkmath.OneInt()},
},
types.ErrInvalidFee,
},
}

for _, tt := range tests {
Expand Down
4 changes: 4 additions & 0 deletions x/dex/types/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func IsTickOutOfRange(tickIndex int64) bool {
}

func ValidateTickFee(tick int64, fee uint64) error {
// Ensure we do not overflow/wrap Uint
if fee >= MaxTickExp {
return ErrInvalidFee
}
// Ensure |tick| + fee <= MaxTickExp
// NOTE: Ugly arithmetic is to ensure that we don't overflow uint64
if utils.Abs(tick) > MaxTickExp-fee {
Expand Down

0 comments on commit 1812213

Please sign in to comment.