Commit 3a0969bc authored by 董子豪's avatar 董子豪

add test

parent 7bcaa30c
......@@ -6,18 +6,20 @@ import(
)
type SectorInfo struct {
SealProof abi.RegisteredSealProof // RegisteredProof used when sealing - needs to be mapped to PoSt registered proof when used to verify a PoSt
SealType abi.RegisteredSealProof // RegisteredProof used when sealing - needs to be mapped to PoSt registered proof when used to verify a PoSt
SectorNumber abi.SectorNumber
SealedCID cid.Cid // CommR
}
type Proof []byte
type SealVerifyInfo struct {
SealProof abi.RegisteredSealProof
SealType abi.RegisteredSealProof
SectorID abi.SectorID
DealIDs []abi.DealID
Randomness abi.SealRandomness
InteractiveRandomness abi.InteractiveSealRandomness
Proof []byte
SealProof Proof
// Safe because we get those from the miner actor
SealedCID cid.Cid `checked:"true"` // CommR
......@@ -36,15 +38,15 @@ type AggregateSealVerifyInfo struct {
type AggregateSealVerifyProofAndInfos struct {
Miner abi.ActorID
SealProof abi.RegisteredSealProof
AggregateProof abi.RegisteredAggregationProof
Proof []byte
SealType abi.RegisteredSealProof
AggregateType abi.RegisteredAggregationProof
AggregateProof Proof
Infos []AggregateSealVerifyInfo
}
type PoStProof struct {
PoStProof abi.RegisteredPoStProof
ProofBytes []byte
ProofBytes Proof
}
type WinningPoStVerifyInfo struct {
......@@ -64,9 +66,9 @@ type WindowPoStVerifyInfo struct {
type AggregateWindowPostInfos struct{
PoStType abi.RegisteredPoStProof
AggregateType abi.RegisteredAggregationProof
Miner abi.ActorID
AggregationProof []byte
AggregateProof Proof
ChallengedSectors []SectorInfo
SectorCount []uint
Randomnesses []abi.PoStRandomness
Prover abi.ActorID
}
\ No newline at end of file
......@@ -27,8 +27,6 @@ type PreCommit1Out []byte
type Commit1Out []byte
type Proof []byte
type SectorCids struct {
Unsealed cid.Cid
Sealed cid.Cid
......
......@@ -25,6 +25,7 @@ func main() {
Version: "1.0.1",
Commands: []*cli.Command{
test,
testSealAndWindowPoSt,
testSealCmd,
testAggregationCmd,
testSplitDataCmd,
......@@ -46,9 +47,39 @@ var test = &cli.Command{
},
}
var testSealAndWindowPoSt = &cli.Command{
Name: "test-all",
Usage: "Test Seal the sectors and generate window post",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "sector-size",
Value: "8MiB",
Usage: "size of the sectors in bytes",
},
&cli.IntFlag{
Name: "num-agg",
Value: 4,
Usage: "How many window-post proofs used to aggregate",
},
},
Action: func(c *cli.Context) error {
sectorSizeInt, err := units.RAMInBytes(c.String("sector-size"))
if err != nil {
return err
}
sectorSize := abi.SectorSize(sectorSizeInt)
numAggregate := c.Int("num-agg")
err = seal.TestSealAndWindowPoSt(sectorSize, numAggregate)
if err != nil {
return err
}
return nil
},
}
var testSealCmd = &cli.Command{
Name: "test-seal",
Usage: "Test interface",
Usage: "Test sealing the sectors",
Action: func(c *cli.Context) error {
// Test 8MiB sector
err := seal.TestSealAndUnseal()
......@@ -61,7 +92,7 @@ var testSealCmd = &cli.Command{
var testSplitDataCmd = &cli.Command{
Name: "test-split",
Usage: "Test interface",
Usage: "Test encode data into pieces",
Action: func(c *cli.Context) error {
// Test 8MiB sector
err := seal.TestSplitDataInToPieces()
......@@ -74,7 +105,7 @@ var testSplitDataCmd = &cli.Command{
var testAggregationCmd = &cli.Command{
Name: "test-aggregation",
Usage: "Test interface",
Usage: "Test aggregate some window-post proofs",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "sector-size",
......
......@@ -27,7 +27,7 @@ import (
// VerifySeal returns true if the sealing operation from which its inputs were
// derived was valid, and false if not.
func VerifySeal(info spproof.SealVerifyInfo) (bool, error) {
sp, err := toFilRegisteredSealProof(info.SealProof)
sp, err := toFilRegisteredSealProof(info.SealType)
if err != nil {
return false, err
}
......@@ -47,7 +47,7 @@ func VerifySeal(info spproof.SealVerifyInfo) (bool, error) {
return false, err
}
resp := generated.FilVerifySeal(sp, commR, commD, proverID, to32ByteArray(info.Randomness), to32ByteArray(info.InteractiveRandomness), uint64(info.SectorID.Number), info.Proof, uint(len(info.Proof)))
resp := generated.FilVerifySeal(sp, commR, commD, proverID, to32ByteArray(info.Randomness), to32ByteArray(info.InteractiveRandomness), uint64(info.SectorID.Number), info.SealProof, uint(len(info.SealProof)))
resp.Deref()
defer generated.FilDestroyVerifySealResponse(resp)
......@@ -64,7 +64,7 @@ func VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (b
return false, xerrors.New("no seal verify infos")
}
spt := aggregate.SealProof // todo assuming this needs to be the same for all sectors, potentially makes sense to put in AggregateSealVerifyProofAndInfos
spt := aggregate.SealType // todo assuming this needs to be the same for all sectors, potentially makes sense to put in AggregateSealVerifyProofAndInfos
inputs := make([]generated.FilAggregationInputs, len(aggregate.Infos))
for i, info := range aggregate.Infos {
......@@ -97,12 +97,12 @@ func VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (b
return false, err
}
rap, err := toFilRegisteredAggregationProof(aggregate.AggregateProof)
rap, err := toFilRegisteredAggregationProof(aggregate.AggregateType)
if err != nil {
return false, err
}
resp := generated.FilVerifyAggregateSealProof(sp, rap, proverID, aggregate.Proof, uint(len(aggregate.Proof)), inputs, uint(len(inputs)))
resp := generated.FilVerifyAggregateSealProof(sp, rap, proverID, aggregate.AggregateProof, uint(len(aggregate.AggregateProof)), inputs, uint(len(inputs)))
resp.Deref()
defer generated.FilDestroyVerifyAggregateSealResponse(resp)
......@@ -205,7 +205,7 @@ func VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostIn
return false, err
}
proverID, err := toProverID(aggregateInfo.Miner)
proverID, err := toProverID(aggregateInfo.Prover)
if err != nil {
return false, err
}
......@@ -225,8 +225,8 @@ func VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostIn
sp,
rap,
proverID,
aggregateInfo.AggregationProof,
uint(len(aggregateInfo.AggregationProof)),
aggregateInfo.AggregateProof,
uint(len(aggregateInfo.AggregateProof)),
randomnesses,
uint(len(randomnesses)),
filPublicReplicaInfos,
......@@ -549,8 +549,8 @@ func SealCommitPhase2(
// infos [commRs, seeds],
// }
// TODO AggregateSealProofs it only needs InteractiveRandomness out of the aggregateInfo.Infos
func AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs [][]byte) (out []byte, err error) {
sp, err := toFilRegisteredSealProof(aggregateInfo.SealProof)
func AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs []spproof.Proof) (out []byte, err error) {
sp, err := toFilRegisteredSealProof(aggregateInfo.SealType)
if err != nil {
return nil, err
}
......@@ -573,7 +573,7 @@ func AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos,
}
}
rap, err := toFilRegisteredAggregationProof(aggregateInfo.AggregateProof)
rap, err := toFilRegisteredAggregationProof(aggregateInfo.AggregateType)
if err != nil {
return nil, err
}
......@@ -959,7 +959,7 @@ func toFilPublicReplicaInfos(src []spproof.SectorInfo, typ string) ([]generated.
switch typ {
case "window":
p, err := src[idx].SealProof.RegisteredWindowPoStProof()
p, err := src[idx].SealType.RegisteredWindowPoStProof()
if err != nil {
return nil, 0, err
}
......@@ -969,7 +969,7 @@ func toFilPublicReplicaInfos(src []spproof.SectorInfo, typ string) ([]generated.
return nil, 0, err
}
case "winning":
p, err := src[idx].SealProof.RegisteredWinningPoStProof()
p, err := src[idx].SealType.RegisteredWinningPoStProof()
if err != nil {
return nil, 0, err
}
......
......@@ -10,18 +10,6 @@ import (
spproof "fil_integrate/build/proof"
)
type AggregateWindowPostInfos struct{
PoStType abi.RegisteredPoStProof
AggregateType abi.RegisteredAggregationProof
Miner abi.ActorID
AggregationProof []byte
ChallengedSectors []spproof.SectorInfo
Arr []uint
Proofs []spproof.PoStProof
Randomnesses []abi.PoStRandomness
SectorCount uint
}
// BLS
// SignatureBytes is the length of a BLS signature
......
......@@ -144,8 +144,8 @@ func WorkflowProofsLifecycle(t TestHelper) {
Number: sectorNum,
},
SealedCID: sealedCID,
SealProof: sealProofType,
Proof: proof,
SealType: sealProofType,
SealProof: proof,
DealIDs: []abi.DealID{},
Randomness: ticket,
InteractiveRandomness: seed,
......@@ -228,7 +228,7 @@ func WorkflowProofsLifecycle(t TestHelper) {
})
provingSet := []spproof.SectorInfo{{
SealProof: sealProofType,
SealType: sealProofType,
SectorNumber: sectorNum,
SealedCID: sealedCID,
}}
......
This diff is collapsed.
package seal
import(
"context"
"os"
"fmt"
"io/ioutil"
"path/filepath"
"golang.org/x/xerrors"
"github.com/mitchellh/go-homedir"
"github.com/filecoin-project/go-state-types/abi"
spproof "fil_integrate/build/proof"
"fil_integrate/build/storage"
"fil_integrate/seal/basicfs"
)
const minerID = 1000
func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
sdir, err := homedir.Expand("~/tmp/bench")
if err != nil {
return err
}
tsdir, err := ioutil.TempDir(sdir, "bench")
if err != nil {
return err
}
// defer func() {
// if err := os.RemoveAll(tsdir); err != nil {
// log.Warn("remove all: ", err)
// }
// }()
// TODO: pretty sure this isnt even needed?
if err := os.MkdirAll(tsdir, 0775); err != nil {
return err
}
sbfs := &basicfs.Provider{
Root: tsdir,
}
sb ,err := New(sbfs)
if err != nil{
return err
}
sp := &Provider{
Root: tsdir,
}
// sectorSize := abi.SectorSize(8*1024*1024)
ctx := context.TODO()
b := []byte(string("random data"))
seed := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 255}
var sectorsInfo [][]storage.SectorRef
var postProofs []spproof.PoStProof
var randomnesses []abi.PoStRandomness
var sectorCount []uint
var index = 0
for i := 0; i < numAggregate; i++ {
filename := filepath.Join(tsdir, "input.dat")
b, err = generateRandomData(filename, b)
if err != nil {
return err
}
in, err := os.Open(filename)
if err != nil {
return err
}
defer in.Close()
_, piecesHash, err := sp.EncodeDataToPieces(ctx, sectorSize, in)
if err != nil{
return err
}
var infos []spproof.AggregateSealVerifyInfo
var sealedSectors []spproof.SectorInfo
var sectors []storage.SectorRef
var proofs []spproof.Proof
for _, pieceHash := range piecesHash {
filename = filepath.Join(tsdir, "pieces", fmt.Sprintf("%x.dat", pieceHash[:]))
f, err := os.Open(filename)
if err != nil {
return err
}
sid := storage.SectorRef{
ID: abi.SectorID{
Miner: minerID,
Number: abi.SectorNumber(index),
},
ProofType: spt(sectorSize),
}
pieceInfo, err := sb.AddPiece(ctx, sid, nil, abi.PaddedPieceSize(sectorSize).Unpadded(), f)
if err != nil {
return err
}
var pieces []abi.PieceInfo
pieces = append(pieces, pieceInfo)
cids, err := sb.Sealed(ctx, sid, pieces)
if err != nil {
return err
}
proof, err := sb.GenerateCommitProof(ctx, sid, seed, pieces, cids)
if err != nil {
return err
}
infos = append(infos, spproof.AggregateSealVerifyInfo{
Number: sid.ID.Number,
InteractiveRandomness: seed,
SealedCID: cids.Sealed,
UnsealedCID: cids.Unsealed,
})
sealedSectors = append(sealedSectors, spproof.SectorInfo{
SealType: sid.ProofType,
SectorNumber: sid.ID.Number,
SealedCID: cids.Sealed,
})
sectors = append(sectors, sid)
proofs = append(proofs, proof)
index++
}
//
aggregateInfo := spproof.AggregateSealVerifyProofAndInfos{
Miner: minerID,
SealType: spt(sectorSize),
AggregateType: DefaultAggregationType(),
Infos: infos,
}
proof, err := sb.AggregateSealProofs(aggregateInfo, proofs)
if err != nil {
return err
}
aggregateInfo.AggregateProof = proof
ok, err := ProofVerifier.VerifyAggregateSeals(aggregateInfo)
if err != nil {
return err
}
if !ok {
return xerrors.Errorf("Verify Seal Aggregation proof failed")
}
postProof, _, err := sb.GenerateWindowPoStProofs(ctx, minerID, sealedSectors, seed)
if err != nil {
return err
}
randomnesses = append(randomnesses, seed)
sectorCount = append(sectorCount, uint(len(sealedSectors)))
sectorsInfo = append(sectorsInfo, sectors)
postProofs = append(postProofs, postProof...)
}
proof, err := sb.AggregateWindowPoStProofs(spproof.AggregateWindowPostInfos{
AggregateType: DefaultAggregationType(),
Randomnesses: randomnesses,
SectorCount: sectorCount,
}, postProofs)
if err != nil {
return err
}
ok, err := ProofVerifier.VerifyAggregateWindowPostProofs(sectorsInfo, proof, randomnesses, minerID)
if err != nil {
return err
}
if ok {
fmt.Println("verify success")
} else {
fmt.Println("verify failed")
}
return nil
}
\ No newline at end of file
This diff is collapsed.
......@@ -4,6 +4,7 @@ import(
"context"
"io"
"github.com/minio/blake2b-simd"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
......@@ -13,28 +14,40 @@ import(
"fil_integrate/seal/basicfs"
)
//interface
type SectorSealer interface{
AddPiece(ctx context.Context, sector storage.SectorRef, existingPieceSizes []abi.UnpaddedPieceSize, pieceSize abi.UnpaddedPieceSize, file storage.Data) (abi.PieceInfo, error)
var b = blake2b.Sum256([]byte("randomness"))
var Ticket abi.SealRandomness = abi.SealRandomness(b[:])
CheckPieceAndDataRoot(sid storage.SectorRef, commd cid.Cid, pieces []abi.PieceInfo) (bool, error)
Sealed(ctx context.Context, sid storage.SectorRef, seed abi.InteractiveSealRandomness, ticket abi.SealRandomness, pieces []abi.PieceInfo) (storage.SectorCids, []byte, error)
type PieceProvider interface {
// Split and encode data into pieces
// Pieces structure is [ Tag | MetaData | HashData ] or [ Tag | PreHash | HashData]
EncodeDataToPieces(ctx context.Context, sectorSize abi.SectorSize, file storage.Data) (storage.Hash, []storage.Hash, error)
DecodePiece(ctx context.Context, sectorSize abi.SectorSize, in io.Reader, start storiface.UnpaddedByteIndex, end storiface.UnpaddedByteIndex) (storage.DecodedData, error)
GenerateCommit2Proof( ctx context.Context, sid storage.SectorRef, seed abi.InteractiveSealRandomness, ticket abi.SealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (storage.Proof, error)
}
//interface
type SectorSealer interface{
AddPiece(ctx context.Context, sector storage.SectorRef, existingPieceSizes []abi.UnpaddedPieceSize, pieceSize abi.UnpaddedPieceSize, file storage.Data) (abi.PieceInfo, error)
// run pre-commit1 and pre-commit2 phase
// generate the sealed sector and sector commitment(commd, commr)
Sealed(ctx context.Context, sid storage.SectorRef, pieces []abi.PieceInfo) (storage.SectorCids, error)
// run commit1 and commit2 phase
// generate the zk-proof of sealing
GenerateCommitProof( ctx context.Context, sid storage.SectorRef, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (spproof.Proof, error)
AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs []spproof.Proof) (spproof.Proof, error)
UnsealedRange(ctx context.Context, sid storage.SectorRef, sectorSize abi.SectorSize, commd cid.Cid, out io.Writer, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) error
GenerateWindowPoStProofs(ctx context.Context, minerID abi.ActorID, sectorInfo []spproof.SectorInfo, randomness abi.PoStRandomness) ([]spproof.PoStProof, []abi.SectorID, error)
UnsealedRange(ctx context.Context, sid storage.SectorRef, sectorSize abi.SectorSize, ticket abi.SealRandomness, commd cid.Cid, out io.Writer, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) error
AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error)
AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) ([]byte, error)
AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) (spproof.Proof, error)
}
type SectorVerifier interface{
VerifySeal(info spproof.SealVerifyInfo) (bool, error)
VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (bool, error)
VerifyWindowPoSt(info spproof.WindowPoStVerifyInfo) (bool, error)
VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostInfos, sealedSectors [][]spproof.SectorInfo) (bool, error)
VerifyWindowPoSt(sectors []storage.SectorRef, randomness abi.PoStRandomness, proofs []spproof.PoStProof, proverID abi.ActorID) (bool, error)
VerifyAggregateWindowPostProofs(sectors [][]storage.SectorRef, proof spproof.Proof, randomnesses []abi.PoStRandomness, proverID abi.ActorID) (bool, error)
}
type SectorProvider interface {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment