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

PacketFee asserts relayers must be nil causing invalid PacketFee types after json marshaling/unmarshaling #1773

Closed
3 tasks
colin-axner opened this issue Jul 25, 2022 · 0 comments · Fixed by #1774
Assignees
Labels
29-fee type: bug Something isn't working as expected
Milestone

Comments

@colin-axner
Copy link
Contributor

Summary of Bug

ICS29 PacketFee validation asserts that the relayers field must be nil. This causes packet fees with empty slices to fail validation.

Problem

We create PacketFee's with nil relayer fields (uninitialized slice), but JSON marshaling a PacketFee and unmarshaling it causes an empty slice to be created. Adding:

pf := types.NewPacketFees(packetFees)
bz := types.ModuleCdc.MustMarshalJSON(&pf)
newPf := types.PacketFees{}
types.ModuleCdc.MustUnmarshalJSON(bz, &newPf)
suite.Require().Equal(pf, newPf)

to 29-fee/keeper/keeper_test.go#TestFeesInEscrow causes:

--- FAIL: TestKeeperTestSuite (11.55s)
    --- FAIL: TestKeeperTestSuite/TestFeesInEscrow (0.14s)
        keeper_test.go:107: 
            	Error Trace:	keeper_test.go:107
            	Error:      	Not equal: 
            	            	expected: types.PacketFees{PacketFees:[]types.PacketFee{types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dda0)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051ddc0)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dde0)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string(nil)}, types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dda0)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051ddc0)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dde0)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string(nil)}, types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dda0)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051ddc0)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dde0)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string(nil)}, types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dda0)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051ddc0)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dde0)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string(nil)}, types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dda0)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051ddc0)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc00051dde0)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string(nil)}}}
            	            	actual  : types.PacketFees{PacketFees:[]types.PacketFee{types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d729a0)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d729c0)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72a00)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string{}}, types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72a20)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72a60)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72a80)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string{}}, types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72ac0)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72ae0)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72b20)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string{}}, types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72b40)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72b80)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72ba0)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string{}}, types.PacketFee{Fee:types.Fee{RecvFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72be0)}}}, AckFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72c00)}}}, TimeoutFee:types.Coins{types.Coin{Denom:"stake", Amount:types.Int{i:(*big.Int)(0xc001d72c40)}}}}, RefundAddress:"cosmos16dt3rr3757spdyc3q2ctlx5fz03purt0ffn3t8", Relayers:[]string{}}}}

We can see the relayers field differs in each, one is Relayers:[]string(nil)} and the other is Relayers:[]string{}

I found this issue testing exporting/importing as importing failed basic validation since the packet fees exported were no longer considered valid

Solution

Treat empty Relayers slices as valid


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged/assigned
@colin-axner colin-axner added type: bug Something isn't working as expected 29-fee labels Jul 25, 2022
@colin-axner colin-axner changed the title ics29: PacketFee asserts relayers must be nil causing invalid PacketFee types after json marshaling/unmarshaling PacketFee asserts relayers must be nil causing invalid PacketFee types after json marshaling/unmarshaling Jul 25, 2022
@colin-axner colin-axner self-assigned this Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
29-fee type: bug Something isn't working as expected
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants