Skip to content

Commit

Permalink
Fix solo machine handshake verification bug (#120)
Browse files Browse the repository at this point in the history
* modify solo machine verify functions to use a pointer to ensure the sequence is incremented

* update changelog
  • Loading branch information
colin-axner committed Apr 14, 2021
1 parent 0174312 commit 7e673b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Bug Fixes

* (modules/light-clients/06-solomachine) [\#120](https://github.com/cosmos/ibc-go/pull/120) Fix solo machine handshake verification bug.

### API Breaking

* (modules/core) [\#109](https://github.com/cosmos/ibc-go/pull/109) Remove connection and channel handshake CLI commands.
Expand Down
34 changes: 17 additions & 17 deletions modules/light-clients/06-solomachine/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (cs ClientState) VerifyUpgradeAndUpdateState(

// VerifyClientState verifies a proof of the client state of the running chain
// stored on the solo machine.
func (cs ClientState) VerifyClientState(
func (cs *ClientState) VerifyClientState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
Expand Down Expand Up @@ -131,13 +131,13 @@ func (cs ClientState) VerifyClientState(

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(store, cdc, &cs)
setClientState(store, cdc, cs)
return nil
}

// VerifyClientConsensusState verifies a proof of the consensus state of the
// running chain stored on the solo machine.
func (cs ClientState) VerifyClientConsensusState(
func (cs *ClientState) VerifyClientConsensusState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
Expand Down Expand Up @@ -169,13 +169,13 @@ func (cs ClientState) VerifyClientConsensusState(

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(store, cdc, &cs)
setClientState(store, cdc, cs)
return nil
}

// VerifyConnectionState verifies a proof of the connection state of the
// specified connection end stored on the target machine.
func (cs ClientState) VerifyConnectionState(
func (cs *ClientState) VerifyConnectionState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
Expand Down Expand Up @@ -206,13 +206,13 @@ func (cs ClientState) VerifyConnectionState(

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(store, cdc, &cs)
setClientState(store, cdc, cs)
return nil
}

// VerifyChannelState verifies a proof of the channel state of the specified
// channel end, under the specified port, stored on the target machine.
func (cs ClientState) VerifyChannelState(
func (cs *ClientState) VerifyChannelState(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
Expand Down Expand Up @@ -244,13 +244,13 @@ func (cs ClientState) VerifyChannelState(

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(store, cdc, &cs)
setClientState(store, cdc, cs)
return nil
}

// VerifyPacketCommitment verifies a proof of an outgoing packet commitment at
// the specified port, specified channel, and specified sequence.
func (cs ClientState) VerifyPacketCommitment(
func (cs *ClientState) VerifyPacketCommitment(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
Expand Down Expand Up @@ -285,13 +285,13 @@ func (cs ClientState) VerifyPacketCommitment(

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(store, cdc, &cs)
setClientState(store, cdc, cs)
return nil
}

// VerifyPacketAcknowledgement verifies a proof of an incoming packet
// acknowledgement at the specified port, specified channel, and specified sequence.
func (cs ClientState) VerifyPacketAcknowledgement(
func (cs *ClientState) VerifyPacketAcknowledgement(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
Expand Down Expand Up @@ -326,14 +326,14 @@ func (cs ClientState) VerifyPacketAcknowledgement(

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(store, cdc, &cs)
setClientState(store, cdc, cs)
return nil
}

// VerifyPacketReceiptAbsence verifies a proof of the absence of an
// incoming packet receipt at the specified port, specified channel, and
// specified sequence.
func (cs ClientState) VerifyPacketReceiptAbsence(
func (cs *ClientState) VerifyPacketReceiptAbsence(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
Expand Down Expand Up @@ -367,13 +367,13 @@ func (cs ClientState) VerifyPacketReceiptAbsence(

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(store, cdc, &cs)
setClientState(store, cdc, cs)
return nil
}

// VerifyNextSequenceRecv verifies a proof of the next sequence number to be
// received of the specified channel at the specified port.
func (cs ClientState) VerifyNextSequenceRecv(
func (cs *ClientState) VerifyNextSequenceRecv(
store sdk.KVStore,
cdc codec.BinaryMarshaler,
height exported.Height,
Expand Down Expand Up @@ -407,7 +407,7 @@ func (cs ClientState) VerifyNextSequenceRecv(

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(store, cdc, &cs)
setClientState(store, cdc, cs)
return nil
}

Expand All @@ -417,7 +417,7 @@ func (cs ClientState) VerifyNextSequenceRecv(
// along with the solo-machine sequence encoded in the proofHeight.
func produceVerificationArgs(
cdc codec.BinaryMarshaler,
cs ClientState,
cs *ClientState,
height exported.Height,
prefix exported.Prefix,
proof []byte,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientState() {

if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(expSeq, tc.clientState.Sequence)
suite.Require().Equal(expSeq, suite.GetSequenceFromStore(), "sequence not updated in the store (%d) on valid test case %s", suite.GetSequenceFromStore(), tc.name)
} else {
suite.Require().Error(err)
Expand Down Expand Up @@ -375,6 +376,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientConsensusState() {

if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(expSeq, tc.clientState.Sequence)
suite.Require().Equal(expSeq, suite.GetSequenceFromStore(), "sequence not updated in the store (%d) on valid test case %s", suite.GetSequenceFromStore(), tc.name)
} else {
suite.Require().Error(err)
Expand Down Expand Up @@ -465,6 +467,7 @@ func (suite *SoloMachineTestSuite) TestVerifyConnectionState() {

if tc.expPass {
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.name)
suite.Require().Equal(expSeq, tc.clientState.Sequence)
suite.Require().Equal(expSeq, suite.GetSequenceFromStore(), "sequence not updated in the store (%d) on valid test case %d: %s", suite.GetSequenceFromStore(), i, tc.name)
} else {
suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.name)
Expand Down Expand Up @@ -554,6 +557,7 @@ func (suite *SoloMachineTestSuite) TestVerifyChannelState() {

if tc.expPass {
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.name)
suite.Require().Equal(expSeq, tc.clientState.Sequence)
suite.Require().Equal(expSeq, suite.GetSequenceFromStore(), "sequence not updated in the store (%d) on valid test case %d: %s", suite.GetSequenceFromStore(), i, tc.name)
} else {
suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.name)
Expand Down Expand Up @@ -903,6 +907,7 @@ func (suite *SoloMachineTestSuite) TestVerifyNextSeqRecv() {

if tc.expPass {
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.name)
suite.Require().Equal(expSeq, tc.clientState.Sequence)
suite.Require().Equal(expSeq, suite.GetSequenceFromStore(), "sequence not updated in the store (%d) on valid test case %d: %s", suite.GetSequenceFromStore(), i, tc.name)
} else {
suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.name)
Expand Down

0 comments on commit 7e673b9

Please sign in to comment.