quicksilver-zone/quicksilver

x/interchainstaking/types: CalculateAllocationDeltas should check the value for targetAllocations.GetForValoper against nil Weight

Closed this issue · 0 comments

Summary of Bug

This might be more of a fuzzing oddity but nonetheless we should defensively guard against it.

Found while fuzzing, that if target.Weight.IsNil() that we get a panic

--- FAIL: FuzzDetermineAllocationsForUndelegation (0.00s)
    --- FAIL: FuzzDetermineAllocationsForUndelegation/333ee1fc6512f2f6 (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x107c98184]

goroutine 11 [running]:
testing.tRunner.func1.2({0x1093c9d20, 0x10a6c8fa0})
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/testing/testing.go:1631 +0x230
testing.tRunner.func1()
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/testing/testing.go:1634 +0x35e
panic({0x1093c9d20?, 0x10a6c8fa0?})
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/runtime/panic.go:759 +0x132
math/big.(*Int).Set(...)
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/math/big/int.go:98
github.com/cosmos/cosmos-sdk/types.Dec.Clone(...)
	/Users/emmanuelodeke/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.16/types/decimal.go:222
github.com/cosmos/cosmos-sdk/types.Dec.ImmutOpInt({0x10969d928?}, 0x1096939a8, {0x1088ed28d?})
	/Users/emmanuelodeke/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.16/types/decimal.go:239 +0x44
github.com/cosmos/cosmos-sdk/types.Dec.MulInt(...)
	/Users/emmanuelodeke/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.16/types/decimal.go:320
github.com/quicksilver-zone/quicksilver/x/interchainstaking/types.CalculateAllocationDeltas(0x0, 0xc0011c97f0, {0x1?}, {0xc0000a2a80, 0x1, 0x197?}, 0xc0011c9568)
	/Users/emmanuelodeke/go/src/github.com/quicksilver-zone/quicksilver/x/interchainstaking/types/rebalance.go:54 +0x5d9
github.com/quicksilver-zone/quicksilver/x/interchainstaking/types.DetermineAllocationsForUndelegation(0x0, 0xc0011c97f0, {0x0?}, {0xc0000a2a80, 0x1, 0x1}, 0x0, {0xc000013758, 0x1, 0x1})
	/Users/emmanuelodeke/go/src/github.com/quicksilver-zone/quicksilver/x/interchainstaking/types/redemptions.go:38 +0x1ec
github.com/quicksilver-zone/quicksilver/x/interchainstaking/types_test.FuzzDetermineAllocationsForUndelegation.func1(0x0?, {0xc00118ff20, 0x2e, 0x30})
	/Users/emmanuelodeke/go/src/github.com/quicksilver-zone/quicksilver/x/interchainstaking/types/fuzz_test.go:70 +0x131
reflect.Value.call({0x109341f00?, 0x1096939f8?, 0x13?}, {0x1088c1966, 0x4}, {0xc0011ca990, 0x2, 0x2?})
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/reflect/value.go:581 +0xca6
reflect.Value.Call({0x109341f00?, 0x1096939f8?, 0x107482b6d?}, {0xc0011ca990?, 0x109690380?, 0xf?})
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/reflect/value.go:365 +0xb9
testing.(*F).Fuzz.func1.1(0xc000585860?)
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/testing/fuzz.go:335 +0x305
testing.tRunner(0xc000585860, 0xc000724480)
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/testing/testing.go:1689 +0xf4
created by testing.(*F).Fuzz.func1 in goroutine 10
	/Users/emmanuelodeke/go/src/go.googlesource.com/go/src/testing/fuzz.go:322 +0x577
exit status 2
FAIL	github.com/quicksilver-zone/quicksilver/x/interchainstaking/types	1.347s

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged/assigned