Skip to content

Commit

Permalink
Sentinel Root Fix (#234)
Browse files Browse the repository at this point in the history
* fix sentinel value

* add godoc and test

* fix grammar

* add changelog

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
AdityaSripal and colin-axner committed Jul 6, 2021
1 parent 383a3e8 commit 449847b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (07-tendermint) [\#234](https://github.com/cosmos/ibc-go/pull/234) Use sentinel value for the consensus state root set during a client upgrade. This prevents genesis validation from failing.
* (modules) [\#223](https://github.com/cosmos/ibc-go/pull/223) Use correct Prometheus format for metric labels.
* (06-solomachine) [\#214](https://github.com/cosmos/ibc-go/pull/214) Disable defensive timestamp check in SendPacket for solo machine clients.
* (07-tendermint) [\#210](https://github.com/cosmos/ibc-go/pull/210) Export all consensus metadata on genesis restarts for tendermint clients.
Expand Down
3 changes: 3 additions & 0 deletions modules/light-clients/07-tendermint/types/consensus_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"github.com/cosmos/ibc-go/modules/core/exported"
)

// SentinelRoot is used as a stand-in root value for the consensus state set at the upgrade height
const SentinelRoot = "sentinel_root"

// NewConsensusState creates a new ConsensusState instance.
func NewConsensusState(
timestamp time.Time, root commitmenttypes.MerkleRoot, nextValsHash tmbytes.HexBytes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
NextValidatorsHash: suite.valsHash,
},
true},
{"success with sentinel",
&types.ConsensusState{
Timestamp: suite.now,
Root: commitmenttypes.NewMerkleRoot([]byte(types.SentinelRoot)),
NextValidatorsHash: suite.valsHash,
},
true},
{"root is nil",
&types.ConsensusState{
Timestamp: suite.now,
Expand Down
4 changes: 2 additions & 2 deletions modules/light-clients/07-tendermint/types/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ func (cs ClientState) VerifyUpgradeAndUpdateState(
}

// The new consensus state is merely used as a trusted kernel against which headers on the new
// chain can be verified. The root is empty as it cannot be known in advance, thus no proof verification will pass.
// chain can be verified. The root is just a stand-in sentinel value as it cannot be known in advance, thus no proof verification will pass.
// The timestamp and the NextValidatorsHash of the consensus state is the blocktime and NextValidatorsHash
// of the last block committed by the old chain. This will allow the first block of the new chain to be verified against
// the last validators of the old chain so long as it is submitted within the TrustingPeriod of this client.
// NOTE: We do not set processed time for this consensus state since this consensus state should not be used for packet verification
// as the root is empty. The next consensus state submitted using update will be usable for packet-verification.
newConsState := NewConsensusState(
tmUpgradeConsState.Timestamp, commitmenttypes.MerkleRoot{}, tmUpgradeConsState.NextValidatorsHash,
tmUpgradeConsState.Timestamp, commitmenttypes.NewMerkleRoot([]byte(SentinelRoot)), tmUpgradeConsState.NextValidatorsHash,
)

// set metadata for this consensus state
Expand Down

0 comments on commit 449847b

Please sign in to comment.