2019-11-21 00:52:59 +00:00
|
|
|
package sectorbuilder
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
2019-11-30 08:41:52 +00:00
|
|
|
sectorbuilder "github.com/filecoin-project/filecoin-ffi"
|
2019-11-21 00:52:59 +00:00
|
|
|
"go.opencensus.io/trace"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/address"
|
2019-12-09 14:15:25 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-11-21 00:52:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (sb *SectorBuilder) SectorSize() uint64 {
|
|
|
|
return sb.ssize
|
|
|
|
}
|
|
|
|
|
|
|
|
var UserBytesForSectorSize = sectorbuilder.GetMaxUserBytesPerStagedSector
|
|
|
|
|
|
|
|
func VerifySeal(sectorSize uint64, commR, commD []byte, proverID address.Address, ticket []byte, seed []byte, sectorID uint64, proof []byte) (bool, error) {
|
|
|
|
var commRa, commDa, ticketa, seeda [32]byte
|
|
|
|
copy(commRa[:], commR)
|
|
|
|
copy(commDa[:], commD)
|
|
|
|
copy(ticketa[:], ticket)
|
|
|
|
copy(seeda[:], seed)
|
|
|
|
proverIDa := addressToProverID(proverID)
|
|
|
|
|
|
|
|
return sectorbuilder.VerifySeal(sectorSize, commRa, commDa, proverIDa, ticketa, seeda, sectorID, proof)
|
|
|
|
}
|
|
|
|
|
2019-11-30 08:41:52 +00:00
|
|
|
func NewSortedPrivateSectorInfo(sectors []sectorbuilder.PrivateSectorInfo) SortedPrivateSectorInfo {
|
|
|
|
return sectorbuilder.NewSortedPrivateSectorInfo(sectors...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSortedPublicSectorInfo(sectors []sectorbuilder.PublicSectorInfo) SortedPublicSectorInfo {
|
|
|
|
return sectorbuilder.NewSortedPublicSectorInfo(sectors...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func VerifyElectionPost(ctx context.Context, sectorSize uint64, sectorInfo SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []EPostCandidate, proverID address.Address) (bool, error) {
|
2019-12-17 22:23:43 +00:00
|
|
|
challengeCount := types.ElectionPostChallengeCount(uint64(len(sectorInfo.Values())), 0)
|
2019-11-30 08:41:52 +00:00
|
|
|
return verifyPost(ctx, sectorSize, sectorInfo, challengeCount, challengeSeed, proof, candidates, proverID)
|
2019-11-21 00:52:59 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 22:23:43 +00:00
|
|
|
func VerifyFallbackPost(ctx context.Context, sectorSize uint64, sectorInfo SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []EPostCandidate, proverID address.Address, faults int) (bool, error) {
|
|
|
|
challengeCount := fallbackPostChallengeCount(uint64(len(sectorInfo.Values())), faults)
|
2019-11-30 08:41:52 +00:00
|
|
|
return verifyPost(ctx, sectorSize, sectorInfo, challengeCount, challengeSeed, proof, candidates, proverID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyPost(ctx context.Context, sectorSize uint64, sectorInfo SortedPublicSectorInfo, challengeCount uint64, challengeSeed []byte, proof []byte, candidates []EPostCandidate, proverID address.Address) (bool, error) {
|
|
|
|
var challengeSeeda [CommLen]byte
|
|
|
|
copy(challengeSeeda[:], challengeSeed)
|
|
|
|
|
2019-11-21 00:52:59 +00:00
|
|
|
_, span := trace.StartSpan(ctx, "VerifyPoSt")
|
|
|
|
defer span.End()
|
2019-11-30 08:41:52 +00:00
|
|
|
prover := addressToProverID(proverID)
|
|
|
|
return sectorbuilder.VerifyPoSt(sectorSize, sectorInfo, challengeSeeda, challengeCount, proof, candidates, prover)
|
2019-11-21 00:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GeneratePieceCommitment(piece io.Reader, pieceSize uint64) (commP [CommLen]byte, err error) {
|
|
|
|
f, werr, err := toReadableFile(piece, int64(pieceSize))
|
|
|
|
if err != nil {
|
|
|
|
return [32]byte{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
commP, err = sectorbuilder.GeneratePieceCommitmentFromFile(f, pieceSize)
|
|
|
|
if err != nil {
|
|
|
|
return [32]byte{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return commP, werr()
|
|
|
|
}
|
|
|
|
|
2019-11-30 08:41:52 +00:00
|
|
|
func GenerateDataCommitment(ssize uint64, pieces []sectorbuilder.PublicPieceInfo) ([CommLen]byte, error) {
|
2019-11-21 00:52:59 +00:00
|
|
|
return sectorbuilder.GenerateDataCommitment(ssize, pieces)
|
2019-12-04 16:53:32 +00:00
|
|
|
}
|