Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit Fix: deposit msg validation #343

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion x/dex/types/message_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (msg *MsgDeposit) ValidateBasic() error {
numDeposits := len(msg.AmountsA)
if numDeposits != len(msg.Fees) ||
numDeposits != len(msg.TickIndexesAToB) ||
numDeposits != len(msg.AmountsB) {
numDeposits != len(msg.AmountsB) ||
numDeposits != len(msg.Options) {
return ErrUnbalancedTxArray
}
if numDeposits == 0 {
Expand Down
18 changes: 18 additions & 0 deletions x/dex/types/message_deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
TickIndexesAToB: []int64{0},
AmountsA: []math.Int{math.OneInt()},
AmountsB: []math.Int{math.OneInt()},
Options: []*DepositOptions{{false}},
},
err: ErrInvalidAddress,
},
Expand All @@ -36,6 +37,7 @@
TickIndexesAToB: []int64{0},
AmountsA: []math.Int{math.OneInt()},
AmountsB: []math.Int{math.OneInt()},
Options: []*DepositOptions{{false}},
},
err: ErrInvalidAddress,
},
Expand All @@ -48,6 +50,7 @@
TickIndexesAToB: []int64{},
AmountsA: []math.Int{},
AmountsB: []math.Int{},
Options: []*DepositOptions{{false}},
},
err: ErrUnbalancedTxArray,
},
Expand Down Expand Up @@ -99,6 +102,19 @@
},
err: ErrZeroDeposit,
},
{
name: "invalid duplicate deposit",
msg: MsgDeposit{
Creator: sample.AccAddress(),
Receiver: sample.AccAddress(),
Fees: []uint64{1, 2, 1},
TickIndexesAToB: []int64{0, 0, 0},
AmountsA: []math.Int{math.OneInt(), math.OneInt(), math.OneInt()},
AmountsB: []math.Int{math.OneInt(), math.OneInt(), math.OneInt()},
Options: []*DepositOptions{{false}, {false}, {false}},
},
err: ErrDuplicatePoolDeposit,

Check failure on line 116 in x/dex/types/message_deposit_test.go

View workflow job for this annotation

GitHub Actions / Test

undefined: ErrDuplicatePoolDeposit

Check failure on line 116 in x/dex/types/message_deposit_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ErrDuplicatePoolDeposit

Check failure on line 116 in x/dex/types/message_deposit_test.go

View workflow job for this annotation

GitHub Actions / Test

undefined: ErrDuplicatePoolDeposit
},
{
name: "invalid no deposit",
msg: MsgDeposit{
Expand All @@ -108,6 +124,7 @@
TickIndexesAToB: []int64{0},
AmountsA: []math.Int{math.ZeroInt()},
AmountsB: []math.Int{math.ZeroInt()},
Options: []*DepositOptions{{false}},
},
err: ErrZeroDeposit,
},
Expand All @@ -120,6 +137,7 @@
TickIndexesAToB: []int64{0},
AmountsA: []math.Int{math.OneInt()},
AmountsB: []math.Int{math.OneInt()},
Options: []*DepositOptions{{false}},
},
},
}
Expand Down
Loading