Merge pull request #189 from filecoin-project/feat/check-block-sig
check block signatures during sync
This commit is contained in:
commit
bfd4624712
@ -137,9 +137,9 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
|
||||
|
||||
// TODO: set timestamp
|
||||
|
||||
nosigbytes, err := next.Serialize()
|
||||
nosigbytes, err := next.SigningBytes()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to serialize block header with no signature: %w", err)
|
||||
return nil, xerrors.Errorf("failed to get signing bytes for block: %w", err)
|
||||
}
|
||||
|
||||
waddr, err := vm.ResolveToKeyAddr(vmi.StateTree(), cst, worker)
|
||||
|
@ -373,6 +373,15 @@ func (syncer *Syncer) validateTickets(ctx context.Context, mworker address.Addre
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkBlockSignature(blk *types.BlockHeader, worker address.Address) error {
|
||||
sigb, err := blk.SigningBytes()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get block signing bytes: %w", err)
|
||||
}
|
||||
|
||||
return blk.BlockSig.Verify(worker, sigb)
|
||||
}
|
||||
|
||||
// Should match up with 'Semantical Validation' in validation.md in the spec
|
||||
func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) error {
|
||||
h := b.Header
|
||||
@ -404,6 +413,10 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
|
||||
return xerrors.Errorf("GetMinerWorker failed: %w", err)
|
||||
}
|
||||
|
||||
if err := checkBlockSignature(h, waddr); err != nil {
|
||||
return xerrors.Errorf("check block signature failed: %w", err)
|
||||
}
|
||||
|
||||
if err := syncer.validateTickets(ctx, waddr, h.Tickets, baseTs); err != nil {
|
||||
return xerrors.Errorf("validating block tickets failed: %w", err)
|
||||
}
|
||||
|
@ -93,6 +93,13 @@ func (blk *BlockHeader) LastTicket() *Ticket {
|
||||
return blk.Tickets[len(blk.Tickets)-1]
|
||||
}
|
||||
|
||||
func (blk *BlockHeader) SigningBytes() ([]byte, error) {
|
||||
blkcopy := *blk
|
||||
blkcopy.BlockSig = Signature{}
|
||||
|
||||
return blkcopy.Serialize()
|
||||
}
|
||||
|
||||
type MsgMeta struct {
|
||||
BlsMessages cid.Cid
|
||||
SecpkMessages cid.Cid
|
||||
|
Loading…
Reference in New Issue
Block a user