-
Notifications
You must be signed in to change notification settings - Fork 205
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
Changes from 3 commits
1235b89
d4243bc
681f506
a1cf4c8
3db5c03
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package interceptedBlocks | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/core/check" | ||
"github.com/multiversx/mx-chain-core-go/data" | ||
"github.com/multiversx/mx-chain-core-go/data/block" | ||
"github.com/multiversx/mx-chain-core-go/marshal" | ||
"github.com/multiversx/mx-chain-go/common" | ||
"github.com/multiversx/mx-chain-go/consensus" | ||
"github.com/multiversx/mx-chain-go/dataRetriever" | ||
proofscache "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/proofsCache" | ||
|
@@ -25,13 +27,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 +55,7 @@ func NewInterceptedEquivalentProof(args ArgInterceptedEquivalentProof) (*interce | |
isForCurrentShard: extractIsForCurrentShard(args.ShardCoordinator, equivalentProof), | ||
headerSigVerifier: args.HeaderSigVerifier, | ||
proofsPool: args.Proofs, | ||
headersPool: args.Headers, | ||
}, nil | ||
} | ||
|
||
|
@@ -70,6 +75,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 +123,23 @@ 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())) | ||
} | ||
|
||
return common.VerifyProofAgainstHeader(iep.proof, header) | ||
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. I think we need to add a method (it there is none already) to get the header by hash from pool and if not found from storer (cache and if not found from storage) 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. pushed |
||
} | ||
|
||
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.
👍