From 148ca6f8af367c2b8e7db6453b1d69eafc891a17 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 4 Feb 2025 19:05:40 +0200 Subject: [PATCH 1/3] reverted a previous commit leading to improper epoch usage for header verification --- process/block/interceptedBlocks/common.go | 3 +-- process/headerCheck/headerSignatureVerify.go | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/process/block/interceptedBlocks/common.go b/process/block/interceptedBlocks/common.go index a488e7f1d5..7e80112fea 100644 --- a/process/block/interceptedBlocks/common.go +++ b/process/block/interceptedBlocks/common.go @@ -139,9 +139,8 @@ func checkMetaShardInfo( } isSelfMeta := coordinator.SelfId() == core.MetachainShardId - isHeaderFromMeta := sd.GetShardID() == core.MetachainShardId isHeaderFromSelf := sd.GetShardID() == coordinator.SelfId() - if !(isSelfMeta || isHeaderFromMeta || isHeaderFromSelf) { + if !(isSelfMeta || isHeaderFromSelf) { continue } diff --git a/process/headerCheck/headerSignatureVerify.go b/process/headerCheck/headerSignatureVerify.go index 409d8ab68d..4b9e204c6d 100644 --- a/process/headerCheck/headerSignatureVerify.go +++ b/process/headerCheck/headerSignatureVerify.go @@ -140,8 +140,12 @@ func (hsv *HeaderSigVerifier) getConsensusSignersForEquivalentProofs(proof data. return nil, process.ErrUnexpectedHeaderProof } - // safe to use proof.GetHeaderEpoch, as the transition block will be treated separately + // TODO: remove if start of epochForConsensus block needs to be validated by the new epochForConsensus nodes epochForConsensus := proof.GetHeaderEpoch() + if proof.GetIsStartOfEpoch() && epochForConsensus > 0 { + epochForConsensus = epochForConsensus - 1 + } + consensusPubKeys, err := hsv.nodesCoordinator.GetAllEligibleValidatorsPublicKeysForShard( epochForConsensus, proof.GetHeaderShardId(), From 7b6e822ce8e57dc2dbb32c2260914febd78bf270 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 4 Feb 2025 19:24:53 +0200 Subject: [PATCH 2/3] proper fix --- common/common.go | 6 +++--- process/headerCheck/headerSignatureVerify.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/common.go b/common/common.go index 00b6f92d28..3b44e80fc4 100644 --- a/common/common.go +++ b/common/common.go @@ -40,10 +40,10 @@ func IsEpochChangeBlockForFlagActivation(header data.HeaderHandler, enableEpochs return isStartOfEpochBlock && isBlockInActivationEpoch } -// IsEpochStartProofForFlagActivation returns true if the provided proof is the proof of the epoch start block on the activation epoch of equivalent messages -func IsEpochStartProofForFlagActivation(proof consensus.ProofHandler, enableEpochsHandler EnableEpochsHandler) bool { +// IsEpochStartProofAfterFlagActivation returns true if the provided proof is the proof of the epoch start block after the activation epoch of equivalent messages +func IsEpochStartProofAfterFlagActivation(proof consensus.ProofHandler, enableEpochsHandler EnableEpochsHandler) bool { isStartOfEpochProof := proof.GetIsStartOfEpoch() - isProofInActivationEpoch := proof.GetHeaderEpoch() == enableEpochsHandler.GetActivationEpoch(EquivalentMessagesFlag) + isProofInActivationEpoch := proof.GetHeaderEpoch() >= enableEpochsHandler.GetActivationEpoch(EquivalentMessagesFlag) return isStartOfEpochProof && isProofInActivationEpoch } diff --git a/process/headerCheck/headerSignatureVerify.go b/process/headerCheck/headerSignatureVerify.go index 4b9e204c6d..a2ee09a06d 100644 --- a/process/headerCheck/headerSignatureVerify.go +++ b/process/headerCheck/headerSignatureVerify.go @@ -314,7 +314,7 @@ func (hsv *HeaderSigVerifier) VerifyHeaderWithProof(header data.HeaderHandler) e } prevProof := header.GetPreviousProof() - if common.IsEpochStartProofForFlagActivation(prevProof, hsv.enableEpochsHandler) { + if common.IsEpochStartProofAfterFlagActivation(prevProof, hsv.enableEpochsHandler) { return hsv.verifyHeaderProofAtTransition(prevProof) } @@ -369,7 +369,7 @@ func (hsv *HeaderSigVerifier) VerifyHeaderProof(proofHandler data.HeaderProofHan return fmt.Errorf("%w for flag %s", process.ErrFlagNotActive, common.EquivalentMessagesFlag) } - if common.IsEpochStartProofForFlagActivation(proofHandler, hsv.enableEpochsHandler) { + if common.IsEpochStartProofAfterFlagActivation(proofHandler, hsv.enableEpochsHandler) { return hsv.verifyHeaderProofAtTransition(proofHandler) } From afee01abb7f2634a5a911d8dd7b5a40e44334402 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 6 Feb 2025 10:24:03 +0200 Subject: [PATCH 3/3] fix after review --- common/common.go | 6 +++--- process/headerCheck/headerSignatureVerify.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/common.go b/common/common.go index 3b44e80fc4..00b6f92d28 100644 --- a/common/common.go +++ b/common/common.go @@ -40,10 +40,10 @@ func IsEpochChangeBlockForFlagActivation(header data.HeaderHandler, enableEpochs return isStartOfEpochBlock && isBlockInActivationEpoch } -// IsEpochStartProofAfterFlagActivation returns true if the provided proof is the proof of the epoch start block after the activation epoch of equivalent messages -func IsEpochStartProofAfterFlagActivation(proof consensus.ProofHandler, enableEpochsHandler EnableEpochsHandler) bool { +// IsEpochStartProofForFlagActivation returns true if the provided proof is the proof of the epoch start block on the activation epoch of equivalent messages +func IsEpochStartProofForFlagActivation(proof consensus.ProofHandler, enableEpochsHandler EnableEpochsHandler) bool { isStartOfEpochProof := proof.GetIsStartOfEpoch() - isProofInActivationEpoch := proof.GetHeaderEpoch() >= enableEpochsHandler.GetActivationEpoch(EquivalentMessagesFlag) + isProofInActivationEpoch := proof.GetHeaderEpoch() == enableEpochsHandler.GetActivationEpoch(EquivalentMessagesFlag) return isStartOfEpochProof && isProofInActivationEpoch } diff --git a/process/headerCheck/headerSignatureVerify.go b/process/headerCheck/headerSignatureVerify.go index a2ee09a06d..4b9e204c6d 100644 --- a/process/headerCheck/headerSignatureVerify.go +++ b/process/headerCheck/headerSignatureVerify.go @@ -314,7 +314,7 @@ func (hsv *HeaderSigVerifier) VerifyHeaderWithProof(header data.HeaderHandler) e } prevProof := header.GetPreviousProof() - if common.IsEpochStartProofAfterFlagActivation(prevProof, hsv.enableEpochsHandler) { + if common.IsEpochStartProofForFlagActivation(prevProof, hsv.enableEpochsHandler) { return hsv.verifyHeaderProofAtTransition(prevProof) } @@ -369,7 +369,7 @@ func (hsv *HeaderSigVerifier) VerifyHeaderProof(proofHandler data.HeaderProofHan return fmt.Errorf("%w for flag %s", process.ErrFlagNotActive, common.EquivalentMessagesFlag) } - if common.IsEpochStartProofAfterFlagActivation(proofHandler, hsv.enableEpochsHandler) { + if common.IsEpochStartProofForFlagActivation(proofHandler, hsv.enableEpochsHandler) { return hsv.verifyHeaderProofAtTransition(proofHandler) }