From 67cf948f261d392546f813290cad94479c97fcd2 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 14 Feb 2017 01:34:24 -0500 Subject: [PATCH] ibc: check commit against blockID --- plugins/ibc/ibc.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index d1bd8d53b..53913b438 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -431,23 +431,22 @@ func verifyCommit(chainState BlockchainState, header *tm.Header, commit *tm.Comm return errors.New(cmn.Fmt("Commit has no signatures")) } chainID := chainState.ChainID - vote0 := commit.Precommits[0] vals := chainState.Validators valSet := tm.NewValidatorSet(vals) - // Ensure the commit is for the header - if !bytes.Equal(header.Hash(), vote0.BlockID.Hash) { - return errors.New(cmn.Fmt("Commit.BlockID.Hash (%X) does not match header.Hash (%X)", vote0.BlockID.Hash, header.Hash())) - } - // NOTE: Currently this only works with the exact same validator set. // Not this, but perhaps "ValidatorSet.VerifyCommitAny" should expose // the functionality to verify commits even after validator changes. - err := valSet.VerifyCommit(chainID, vote0.BlockID, vote0.Height, commit) + blockID, err := valSet.VerifyCommitReturnBlockID(chainID, header.Height, commit) if err != nil { return err } + // Ensure the committed blockID matches the header + if !bytes.Equal(header.Hash(), blockID.Hash) { + return errors.New(cmn.Fmt("blockID.Hash (%X) does not match header.Hash (%X)", blockID.Hash, header.Hash())) + } + // All ok! return nil }