Skip to content

Commit

Permalink
Merge pull request #343 from neutron-org/fix_deposit_validation
Browse files Browse the repository at this point in the history
Audit Fix: deposit msg validation
  • Loading branch information
pr0n00gler authored Nov 13, 2023
2 parents e4f3ea5 + e94daf1 commit 69462f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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 @@ func TestMsgDeposit_ValidateBasic(t *testing.T) {
TickIndexesAToB: []int64{0},
AmountsA: []math.Int{math.OneInt()},
AmountsB: []math.Int{math.OneInt()},
Options: []*DepositOptions{{false}},
},
err: ErrInvalidAddress,
},
Expand All @@ -36,6 +37,7 @@ func TestMsgDeposit_ValidateBasic(t *testing.T) {
TickIndexesAToB: []int64{0},
AmountsA: []math.Int{math.OneInt()},
AmountsB: []math.Int{math.OneInt()},
Options: []*DepositOptions{{false}},
},
err: ErrInvalidAddress,
},
Expand All @@ -48,6 +50,7 @@ func TestMsgDeposit_ValidateBasic(t *testing.T) {
TickIndexesAToB: []int64{},
AmountsA: []math.Int{},
AmountsB: []math.Int{},
Options: []*DepositOptions{{false}},
},
err: ErrUnbalancedTxArray,
},
Expand Down Expand Up @@ -99,6 +102,19 @@ func TestMsgDeposit_ValidateBasic(t *testing.T) {
},
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
},
{
name: "invalid no deposit",
msg: MsgDeposit{
Expand All @@ -108,6 +124,7 @@ func TestMsgDeposit_ValidateBasic(t *testing.T) {
TickIndexesAToB: []int64{0},
AmountsA: []math.Int{math.ZeroInt()},
AmountsB: []math.Int{math.ZeroInt()},
Options: []*DepositOptions{{false}},
},
err: ErrZeroDeposit,
},
Expand All @@ -120,6 +137,7 @@ func TestMsgDeposit_ValidateBasic(t *testing.T) {
TickIndexesAToB: []int64{0},
AmountsA: []math.Int{math.OneInt()},
AmountsB: []math.Int{math.OneInt()},
Options: []*DepositOptions{{false}},
},
},
}
Expand Down

0 comments on commit 69462f8

Please sign in to comment.