-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added checks on proofs parameters like epoch, nonce and shard #6698
base: equivalent-proofs-feat-stabilization
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,35 @@ func (bp *baseProcessor) checkBlockValidity( | |
return process.ErrEpochDoesNotMatch | ||
} | ||
|
||
return bp.checkPrevProofValidity(headerHandler) | ||
} | ||
|
||
func (bp *baseProcessor) checkPrevProofValidity(headerHandler data.HeaderHandler) error { | ||
if !bp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, headerHandler.GetEpoch()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you check with this instead: if !common.ShouldBlockHavePrevProof(headerHandler, enableEpochsHandler, common.EquivalentMessagesFlag) {
return nil
} the above check takes into consideration also the first block which should not have a previous proof. |
||
return nil | ||
} | ||
|
||
prevProof := headerHandler.GetPreviousProof() | ||
if check.IfNilReflect(prevProof) { | ||
return process.ErrMissingHeaderProof | ||
} | ||
|
||
headersPool := bp.dataPool.Headers() | ||
prevHeader, err := headersPool.GetHeaderByHash(prevProof.GetHeaderHash()) | ||
if err != nil { | ||
return fmt.Errorf("%w while getting header for proof hash %s", err, hex.EncodeToString(prevProof.GetHeaderHash())) | ||
} | ||
|
||
if prevProof.GetHeaderNonce() != prevHeader.GetNonce() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have now also round in header proof, so we can also add a check for round |
||
return fmt.Errorf("%w, nonce mismatch", process.ErrInvalidHeaderProof) | ||
} | ||
if prevProof.GetHeaderShardId() != prevHeader.GetShardID() { | ||
return fmt.Errorf("%w, shard id mismatch", process.ErrInvalidHeaderProof) | ||
} | ||
if prevProof.GetHeaderEpoch() != prevHeader.GetEpoch() { | ||
return fmt.Errorf("%w, epoch mismatch", process.ErrInvalidHeaderProof) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package interceptedBlocks | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
|
@@ -25,13 +26,15 @@ type ArgInterceptedEquivalentProof struct { | |
ShardCoordinator sharding.Coordinator | ||
HeaderSigVerifier consensus.HeaderSigVerifier | ||
Proofs dataRetriever.ProofsPool | ||
Headers dataRetriever.HeadersPool | ||
} | ||
|
||
type interceptedEquivalentProof struct { | ||
proof *block.HeaderProof | ||
isForCurrentShard bool | ||
headerSigVerifier consensus.HeaderSigVerifier | ||
proofsPool dataRetriever.ProofsPool | ||
headersPool dataRetriever.HeadersPool | ||
} | ||
|
||
// NewInterceptedEquivalentProof returns a new instance of interceptedEquivalentProof | ||
|
@@ -51,6 +54,7 @@ func NewInterceptedEquivalentProof(args ArgInterceptedEquivalentProof) (*interce | |
isForCurrentShard: extractIsForCurrentShard(args.ShardCoordinator, equivalentProof), | ||
headerSigVerifier: args.HeaderSigVerifier, | ||
proofsPool: args.Proofs, | ||
headersPool: args.Headers, | ||
}, nil | ||
} | ||
|
||
|
@@ -70,6 +74,9 @@ func checkArgInterceptedEquivalentProof(args ArgInterceptedEquivalentProof) erro | |
if check.IfNil(args.Proofs) { | ||
return process.ErrNilProofsPool | ||
} | ||
if check.IfNil(args.Headers) { | ||
return process.ErrNilHeadersDataPool | ||
} | ||
|
||
return nil | ||
} | ||
|
@@ -115,9 +122,33 @@ func (iep *interceptedEquivalentProof) CheckValidity() error { | |
return proofscache.ErrAlreadyExistingEquivalentProof | ||
} | ||
|
||
err = iep.checkHeaderParamsFromProof() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return iep.headerSigVerifier.VerifyHeaderProof(iep.proof) | ||
} | ||
|
||
func (iep *interceptedEquivalentProof) checkHeaderParamsFromProof() error { | ||
header, err := iep.headersPool.GetHeaderByHash(iep.proof.GetHeaderHash()) | ||
if err != nil { | ||
return fmt.Errorf("%w while getting header for proof hash %s", err, hex.EncodeToString(iep.proof.GetHeaderHash())) | ||
} | ||
|
||
if iep.proof.GetHeaderNonce() != header.GetNonce() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check for round here also |
||
return fmt.Errorf("%w, nonce mismatch", ErrInvalidProof) | ||
} | ||
if iep.proof.GetHeaderShardId() != header.GetShardID() { | ||
return fmt.Errorf("%w, shard id mismatch", ErrInvalidProof) | ||
} | ||
if iep.proof.GetHeaderEpoch() != header.GetEpoch() { | ||
return fmt.Errorf("%w, epoch mismatch", ErrInvalidProof) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (iep *interceptedEquivalentProof) integrity() error { | ||
isProofValid := len(iep.proof.AggregatedSignature) > 0 && | ||
len(iep.proof.PubKeysBitmap) > 0 && | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the checks can be done against the currentBlockHeader fields which is already loaded, like in the checkBlockValidity method.
currentBlockHeader can be passed as prevHeader
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, do we have this kind of check as well for the proofs in the shard data included in a metablock?
e.g the prevProof from a shardData needs to be verified that it has the correct data (epoch, round, nonce) compared to the prevBlock of that shardData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extended the checks over the prevProof as suggested