From f4679dba212870242e0ff1ba7eaaeaf5fff44912 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Fri, 21 Aug 2020 10:17:11 +0200 Subject: [PATCH] go/roothash: Make the parent block check earlier --- .changelog/3206.bugfix.md | 1 + go/roothash/api/commitment/pool.go | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 .changelog/3206.bugfix.md diff --git a/.changelog/3206.bugfix.md b/.changelog/3206.bugfix.md new file mode 100644 index 00000000000..106ae9827b2 --- /dev/null +++ b/.changelog/3206.bugfix.md @@ -0,0 +1 @@ +go/roothash: Make the parent block check earlier diff --git a/go/roothash/api/commitment/pool.go b/go/roothash/api/commitment/pool.go index d5fc3e1a204..e12d42edcfd 100644 --- a/go/roothash/api/commitment/pool.go +++ b/go/roothash/api/commitment/pool.go @@ -149,8 +149,6 @@ func (p *Pool) addOpenExecutorCommitment( return ErrNotInCommittee } - // TODO: Check for signs of double signing (#1804). - // Ensure the node did not already submit a commitment. if _, ok := p.ExecuteCommitments[id]; ok { return ErrAlreadyCommitted @@ -169,6 +167,16 @@ func (p *Pool) addOpenExecutorCommitment( return ErrInvalidMessages } + // Check if the block is based on the previous block. + if !header.IsParentOf(&blk.Header) { + logger.Debug("executor commitment is not based on correct block", + "node_id", id, + "expected_previous_hash", blk.Header.EncodedHash(), + "previous_hash", header.PreviousHash, + ) + return ErrNotBasedOnCorrectBlock + } + // Verify RAK-attestation. if p.Runtime.TEEHardware != node.TEEHardwareInvalid { n, err := nl.Node(ctx, id) @@ -198,16 +206,6 @@ func (p *Pool) addOpenExecutorCommitment( } } - // Check if the block is based on the previous block. - if !header.IsParentOf(&blk.Header) { - logger.Debug("executor commitment is not based on correct block", - "node_id", id, - "expected_previous_hash", blk.Header.EncodedHash(), - "previous_hash", header.PreviousHash, - ) - return ErrNotBasedOnCorrectBlock - } - if err := sv.VerifyTxnSchedulerSignature(body.TxnSchedSig, blk.Header.Round); err != nil { logger.Debug("executor commitment has bad transaction scheduler signer", "node_id", id,