2020-05-20 17:10:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"fmt"
|
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-05-20 17:10:35 +00:00
|
|
|
|
|
|
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-06-14 15:00:51 +00:00
|
|
|
prooftypes "github.com/filecoin-project/go-state-types/proof"
|
2023-11-14 00:06:11 +00:00
|
|
|
|
2022-09-14 19:38:15 +00:00
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2020-05-20 17:10:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var proofsCmd = &cli.Command{
|
|
|
|
Name: "proofs",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
verifySealProofCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var verifySealProofCmd = &cli.Command{
|
|
|
|
Name: "verify-seal",
|
2020-05-20 22:28:19 +00:00
|
|
|
ArgsUsage: "<commr> <commd> <proof>",
|
2020-05-20 17:10:35 +00:00
|
|
|
Description: "Verify a seal proof with manual inputs",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ticket",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "proof-rand",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "miner",
|
|
|
|
},
|
|
|
|
&cli.Uint64Flag{
|
|
|
|
Name: "sector-id",
|
|
|
|
},
|
|
|
|
&cli.Int64Flag{
|
|
|
|
Name: "proof-type",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2022-09-14 18:33:29 +00:00
|
|
|
if cctx.NArg() != 3 {
|
2022-09-14 19:38:15 +00:00
|
|
|
return lcli.IncorrectNumArgs(cctx)
|
2020-05-20 17:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
commr, err := cid.Decode(cctx.Args().Get(0))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
commd, err := cid.Decode(cctx.Args().Get(1))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
proof, err := hex.DecodeString(cctx.Args().Get(2))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to decode hex proof input: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := address.NewFromString(cctx.String("miner"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
mid, err := address.IDFromAddress(maddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-21 15:26:32 +00:00
|
|
|
ticket, err := hex.DecodeString(cctx.String("ticket"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
proofRand, err := hex.DecodeString(cctx.String("proof-rand"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:10:35 +00:00
|
|
|
snum := abi.SectorNumber(cctx.Uint64("sector-id"))
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
ok, err := ffi.VerifySeal(prooftypes.SealVerifyInfo{
|
2020-05-20 17:10:35 +00:00
|
|
|
SectorID: abi.SectorID{
|
|
|
|
Miner: abi.ActorID(mid),
|
|
|
|
Number: snum,
|
|
|
|
},
|
2020-05-22 16:26:14 +00:00
|
|
|
SealedCID: commr,
|
2020-06-15 16:30:49 +00:00
|
|
|
SealProof: abi.RegisteredSealProof(cctx.Int64("proof-type")),
|
2020-05-22 16:26:14 +00:00
|
|
|
Proof: proof,
|
|
|
|
DealIDs: nil,
|
2022-04-20 21:34:28 +00:00
|
|
|
Randomness: ticket,
|
|
|
|
InteractiveRandomness: proofRand,
|
2020-05-20 17:10:35 +00:00
|
|
|
UnsealedCID: commd,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid proof")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("proof valid!")
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|