Merge pull request #189 from filecoin-project/feat/check-block-sig

check block signatures during sync
This commit is contained in:
Whyrusleeping 2019-09-14 01:49:27 +10:00 committed by GitHub
commit bfd4624712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -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