2019-12-06 14:06:42 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
2020-01-13 20:47:27 +00:00
|
|
|
"context"
|
2020-02-12 17:41:35 +00:00
|
|
|
|
|
|
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
2020-01-13 20:47:27 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-sectorbuilder"
|
2019-12-06 14:06:42 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2020-01-13 20:47:27 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
2019-12-06 14:06:42 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-01-13 20:47:27 +00:00
|
|
|
"go.opencensus.io/trace"
|
2019-12-06 14:06:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Actual type is defined in chain/types/vmcontext.go because the VMContext interface is there
|
|
|
|
|
2020-01-13 20:47:27 +00:00
|
|
|
func Syscalls(verifier sectorbuilder.Verifier) *types.VMSyscalls {
|
2019-12-06 14:06:42 +00:00
|
|
|
return &types.VMSyscalls{
|
2020-01-13 20:47:27 +00:00
|
|
|
ValidatePoRep: func(ctx context.Context, maddr address.Address, ssize uint64, commD, commR, ticket, proof, seed []byte, sectorID uint64) (bool, actors.ActorError) {
|
|
|
|
_, span := trace.StartSpan(ctx, "ValidatePoRep")
|
|
|
|
defer span.End()
|
|
|
|
ok, err := verifier.VerifySeal(ssize, commR, commD, maddr, ticket, seed, sectorID, proof)
|
|
|
|
if err != nil {
|
|
|
|
return false, aerrors.Absorb(err, 25, "verify seal failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok, nil
|
|
|
|
},
|
2020-02-12 17:41:35 +00:00
|
|
|
VerifyFallbackPost: func(ctx context.Context,
|
|
|
|
sectorSize uint64,
|
|
|
|
sectorInfo []types.PublicSectorInfo,
|
|
|
|
challengeSeed []byte,
|
|
|
|
proof []byte,
|
|
|
|
candidates []types.Candidate,
|
|
|
|
proverID address.Address,
|
|
|
|
faults uint64) (bool, error) {
|
|
|
|
|
|
|
|
sI := make([]ffi.PublicSectorInfo, len(sectorInfo))
|
|
|
|
for i, v := range sectorInfo {
|
|
|
|
sI[i] = ffi.PublicSectorInfo{
|
|
|
|
SectorID: v.SectorID,
|
|
|
|
CommR: v.CommR,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cand := make([]sectorbuilder.EPostCandidate, len(candidates))
|
|
|
|
for i, v := range candidates {
|
|
|
|
cand[i] = sectorbuilder.EPostCandidate{
|
|
|
|
SectorID: v.SectorID,
|
|
|
|
PartialTicket: v.PartialTicket,
|
|
|
|
Ticket: v.Ticket,
|
|
|
|
SectorChallengeIndex: v.SectorChallengeIndex,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return verifier.VerifyFallbackPost(
|
|
|
|
ctx,
|
|
|
|
sectorSize,
|
|
|
|
sectorbuilder.NewSortedPublicSectorInfo(sI),
|
|
|
|
challengeSeed,
|
|
|
|
proof,
|
|
|
|
cand,
|
|
|
|
proverID,
|
|
|
|
faults,
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
2019-12-06 14:06:42 +00:00
|
|
|
}
|
|
|
|
}
|