Merge remote-tracking branch 'origin/master' into next
This commit is contained in:
commit
fabcbb621d
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -7,6 +7,3 @@
|
|||||||
[submodule "extern/test-vectors"]
|
[submodule "extern/test-vectors"]
|
||||||
path = extern/test-vectors
|
path = extern/test-vectors
|
||||||
url = https://github.com/filecoin-project/test-vectors.git
|
url = https://github.com/filecoin-project/test-vectors.git
|
||||||
[submodule "extern/blst"]
|
|
||||||
path = extern/blst
|
|
||||||
url = https://github.com/supranational/blst.git
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -163,7 +164,11 @@ func (ts *testSuite) testVersion(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
require.Equal(t, v.Version, build.BuildVersion)
|
versions := strings.Split(v.Version, "+")
|
||||||
|
if len(versions) <= 0 {
|
||||||
|
t.Fatal("empty version")
|
||||||
|
}
|
||||||
|
require.Equal(t, versions[0], build.BuildVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *testSuite) testSearchMsg(t *testing.T) {
|
func (ts *testSuite) testSearchMsg(t *testing.T) {
|
||||||
|
@ -58,6 +58,8 @@ func init() {
|
|||||||
SetAddressNetwork(address.Testnet)
|
SetAddressNetwork(address.Testnet)
|
||||||
|
|
||||||
Devnet = true
|
Devnet = true
|
||||||
|
|
||||||
|
BuildType = BuildCalibnet
|
||||||
}
|
}
|
||||||
|
|
||||||
const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds)
|
const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds)
|
||||||
|
@ -61,6 +61,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Devnet = false
|
Devnet = false
|
||||||
|
|
||||||
|
BuildType = BuildMainnet
|
||||||
}
|
}
|
||||||
|
|
||||||
const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds)
|
const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds)
|
||||||
|
@ -10,19 +10,25 @@ var CurrentCommit string
|
|||||||
var BuildType int
|
var BuildType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BuildDefault = 0
|
BuildDefault = 0
|
||||||
Build2k = 0x1
|
BuildMainnet = 0x1
|
||||||
BuildDebug = 0x3
|
Build2k = 0x2
|
||||||
|
BuildDebug = 0x3
|
||||||
|
BuildCalibnet = 0x4
|
||||||
)
|
)
|
||||||
|
|
||||||
func buildType() string {
|
func buildType() string {
|
||||||
switch BuildType {
|
switch BuildType {
|
||||||
case BuildDefault:
|
case BuildDefault:
|
||||||
return ""
|
return ""
|
||||||
case BuildDebug:
|
case BuildMainnet:
|
||||||
return "+debug"
|
return "+mainnet"
|
||||||
case Build2k:
|
case Build2k:
|
||||||
return "+2k"
|
return "+2k"
|
||||||
|
case BuildDebug:
|
||||||
|
return "+debug"
|
||||||
|
case BuildCalibnet:
|
||||||
|
return "+calibnet"
|
||||||
default:
|
default:
|
||||||
return "+huh?"
|
return "+huh?"
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,10 @@ import (
|
|||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/lib/sigs/bls"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w api.WalletAPI, bt *api.BlockTemplate) (*types.FullBlock, error) {
|
func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w api.WalletAPI, bt *api.BlockTemplate) (*types.FullBlock, error) {
|
||||||
@ -140,35 +140,29 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w api.WalletA
|
|||||||
}
|
}
|
||||||
|
|
||||||
func aggregateSignatures(sigs []crypto.Signature) (*crypto.Signature, error) {
|
func aggregateSignatures(sigs []crypto.Signature) (*crypto.Signature, error) {
|
||||||
sigsS := make([][]byte, len(sigs))
|
sigsS := make([]ffi.Signature, len(sigs))
|
||||||
for i := 0; i < len(sigs); i++ {
|
for i := 0; i < len(sigs); i++ {
|
||||||
sigsS[i] = sigs[i].Data
|
copy(sigsS[i][:], sigs[i].Data[:ffi.SignatureBytes])
|
||||||
}
|
}
|
||||||
|
|
||||||
aggregator := new(bls.AggregateSignature).AggregateCompressed(sigsS)
|
aggSig := ffi.Aggregate(sigsS)
|
||||||
if aggregator == nil {
|
if aggSig == nil {
|
||||||
if len(sigs) > 0 {
|
if len(sigs) > 0 {
|
||||||
return nil, xerrors.Errorf("bls.Aggregate returned nil with %d signatures", len(sigs))
|
return nil, xerrors.Errorf("bls.Aggregate returned nil with %d signatures", len(sigs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zeroSig := ffi.CreateZeroSignature()
|
||||||
|
|
||||||
// Note: for blst this condition should not happen - nil should not
|
// Note: for blst this condition should not happen - nil should not
|
||||||
// be returned
|
// be returned
|
||||||
return &crypto.Signature{
|
return &crypto.Signature{
|
||||||
Type: crypto.SigTypeBLS,
|
Type: crypto.SigTypeBLS,
|
||||||
Data: new(bls.Signature).Compress(),
|
Data: zeroSig[:],
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
aggSigAff := aggregator.ToAffine()
|
|
||||||
if aggSigAff == nil {
|
|
||||||
return &crypto.Signature{
|
|
||||||
Type: crypto.SigTypeBLS,
|
|
||||||
Data: new(bls.Signature).Compress(),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
aggSig := aggSigAff.Compress()
|
|
||||||
return &crypto.Signature{
|
return &crypto.Signature{
|
||||||
Type: crypto.SigTypeBLS,
|
Type: crypto.SigTypeBLS,
|
||||||
Data: aggSig,
|
Data: aggSig[:],
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
||||||
blst "github.com/supranational/blst/bindings/go"
|
|
||||||
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||||
|
|
||||||
// named msgarray here to make it clear that these are the types used by
|
// named msgarray here to make it clear that these are the types used by
|
||||||
// messages, regardless of specs-actors version.
|
// messages, regardless of specs-actors version.
|
||||||
@ -55,7 +56,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/vm"
|
"github.com/filecoin-project/lotus/chain/vm"
|
||||||
bstore "github.com/filecoin-project/lotus/lib/blockstore"
|
bstore "github.com/filecoin-project/lotus/lib/blockstore"
|
||||||
"github.com/filecoin-project/lotus/lib/sigs"
|
"github.com/filecoin-project/lotus/lib/sigs"
|
||||||
"github.com/filecoin-project/lotus/lib/sigs/bls"
|
|
||||||
"github.com/filecoin-project/lotus/metrics"
|
"github.com/filecoin-project/lotus/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -676,6 +676,10 @@ func blockSanityChecks(h *types.BlockHeader) error {
|
|||||||
return xerrors.Errorf("block had nil bls aggregate signature")
|
return xerrors.Errorf("block had nil bls aggregate signature")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if h.Miner.Protocol() != address.ID {
|
||||||
|
return xerrors.Errorf("block had non-ID miner address")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1178,17 +1182,21 @@ func (syncer *Syncer) verifyBlsAggregate(ctx context.Context, sig *crypto.Signat
|
|||||||
trace.Int64Attribute("msgCount", int64(len(msgs))),
|
trace.Int64Attribute("msgCount", int64(len(msgs))),
|
||||||
)
|
)
|
||||||
|
|
||||||
msgsS := make([]blst.Message, len(msgs))
|
msgsS := make([]ffi.Message, len(msgs))
|
||||||
|
pubksS := make([]ffi.PublicKey, len(msgs))
|
||||||
for i := 0; i < len(msgs); i++ {
|
for i := 0; i < len(msgs); i++ {
|
||||||
msgsS[i] = msgs[i].Bytes()
|
msgsS[i] = msgs[i].Bytes()
|
||||||
|
copy(pubksS[i][:], pubks[i][:ffi.PublicKeyBytes])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sigS := new(ffi.Signature)
|
||||||
|
copy(sigS[:], sig.Data[:ffi.SignatureBytes])
|
||||||
|
|
||||||
if len(msgs) == 0 {
|
if len(msgs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
valid := new(bls.Signature).AggregateVerifyCompressed(sig.Data, pubks,
|
valid := ffi.HashVerify(sigS, msgsS, pubksS)
|
||||||
msgsS, []byte(bls.DST))
|
|
||||||
if !valid {
|
if !valid {
|
||||||
return xerrors.New("bls aggregate signature failed to verify")
|
return xerrors.New("bls aggregate signature failed to verify")
|
||||||
}
|
}
|
||||||
|
1
extern/blst
vendored
1
extern/blst
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 1cbb16ed9580dcd3e9593b71221fcf2a048faaef
|
|
2
extern/filecoin-ffi
vendored
2
extern/filecoin-ffi
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 1d9cb3e8ff53f51f9318fc57e5d00bc79bdc0128
|
Subproject commit 0c50dfbaa64c6187d65e63e19aea751a981ac931
|
12
extern/sector-storage/manager.go
vendored
12
extern/sector-storage/manager.go
vendored
@ -285,9 +285,19 @@ func (m *Manager) ReadPiece(ctx context.Context, sink io.Writer, sector storage.
|
|||||||
if unsealed == cid.Undef {
|
if unsealed == cid.Undef {
|
||||||
return xerrors.Errorf("cannot unseal piece (sector: %d, offset: %d size: %d) - unsealed cid is undefined", sector, offset, size)
|
return xerrors.Errorf("cannot unseal piece (sector: %d, offset: %d size: %d) - unsealed cid is undefined", sector, offset, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize, err := sector.ProofType.SectorSize()
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("getting sector size: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
err = m.sched.Schedule(ctx, sector, sealtasks.TTUnseal, selector, unsealFetch, func(ctx context.Context, w Worker) error {
|
err = m.sched.Schedule(ctx, sector, sealtasks.TTUnseal, selector, unsealFetch, func(ctx context.Context, w Worker) error {
|
||||||
// TODO: make restartable
|
// TODO: make restartable
|
||||||
_, err := m.waitSimpleCall(ctx)(w.UnsealPiece(ctx, sector, offset, size, ticket, unsealed))
|
|
||||||
|
// NOTE: we're unsealing the whole sector here as with SDR we can't really
|
||||||
|
// unseal the sector partially. Requesting the whole sector here can
|
||||||
|
// save us some work in case another piece is requested from here
|
||||||
|
_, err := m.waitSimpleCall(ctx)(w.UnsealPiece(ctx, sector, 0, abi.PaddedPieceSize(ssize).Unpadded(), ticket, unsealed))
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
3
go.mod
3
go.mod
@ -127,7 +127,6 @@ require (
|
|||||||
github.com/raulk/clock v1.1.0
|
github.com/raulk/clock v1.1.0
|
||||||
github.com/raulk/go-watchdog v1.0.1
|
github.com/raulk/go-watchdog v1.0.1
|
||||||
github.com/stretchr/testify v1.6.1
|
github.com/stretchr/testify v1.6.1
|
||||||
github.com/supranational/blst v0.1.1
|
|
||||||
github.com/syndtr/goleveldb v1.0.0
|
github.com/syndtr/goleveldb v1.0.0
|
||||||
github.com/urfave/cli/v2 v2.2.0
|
github.com/urfave/cli/v2 v2.2.0
|
||||||
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
|
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
|
||||||
@ -158,5 +157,3 @@ replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v
|
|||||||
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
|
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
|
||||||
|
|
||||||
replace github.com/filecoin-project/test-vectors => ./extern/test-vectors
|
replace github.com/filecoin-project/test-vectors => ./extern/test-vectors
|
||||||
|
|
||||||
replace github.com/supranational/blst => ./extern/blst
|
|
||||||
|
@ -7,17 +7,17 @@ import (
|
|||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
|
|
||||||
blst "github.com/supranational/blst/bindings/go"
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/lib/sigs"
|
"github.com/filecoin-project/lotus/lib/sigs"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DST = string("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_")
|
const DST = string("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_")
|
||||||
|
|
||||||
type SecretKey = blst.SecretKey
|
type SecretKey = ffi.PrivateKey
|
||||||
type PublicKey = blst.P1Affine
|
type PublicKey = ffi.PublicKey
|
||||||
type Signature = blst.P2Affine
|
type Signature = ffi.Signature
|
||||||
type AggregateSignature = blst.P2Aggregate
|
type AggregateSignature = ffi.Signature
|
||||||
|
|
||||||
type blsSigner struct{}
|
type blsSigner struct{}
|
||||||
|
|
||||||
@ -29,30 +29,55 @@ func (blsSigner) GenPrivate() ([]byte, error) {
|
|||||||
return nil, fmt.Errorf("bls signature error generating random data")
|
return nil, fmt.Errorf("bls signature error generating random data")
|
||||||
}
|
}
|
||||||
// Note private keys seem to be serialized little-endian!
|
// Note private keys seem to be serialized little-endian!
|
||||||
pk := blst.KeyGen(ikm[:]).ToLEndian()
|
sk := ffi.PrivateKeyGenerateWithSeed(ikm)
|
||||||
return pk, nil
|
return sk[:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (blsSigner) ToPublic(priv []byte) ([]byte, error) {
|
func (blsSigner) ToPublic(priv []byte) ([]byte, error) {
|
||||||
pk := new(SecretKey).FromLEndian(priv)
|
if priv == nil || len(priv) != ffi.PrivateKeyBytes {
|
||||||
if pk == nil || !pk.Valid() {
|
|
||||||
return nil, fmt.Errorf("bls signature invalid private key")
|
return nil, fmt.Errorf("bls signature invalid private key")
|
||||||
}
|
}
|
||||||
return new(PublicKey).From(pk).Compress(), nil
|
|
||||||
|
sk := new(SecretKey)
|
||||||
|
copy(sk[:], priv[:ffi.PrivateKeyBytes])
|
||||||
|
|
||||||
|
pubkey := ffi.PrivateKeyPublicKey(*sk)
|
||||||
|
|
||||||
|
return pubkey[:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (blsSigner) Sign(p []byte, msg []byte) ([]byte, error) {
|
func (blsSigner) Sign(p []byte, msg []byte) ([]byte, error) {
|
||||||
pk := new(SecretKey).FromLEndian(p)
|
if p == nil || len(p) != ffi.PrivateKeyBytes {
|
||||||
if pk == nil || !pk.Valid() {
|
|
||||||
return nil, fmt.Errorf("bls signature invalid private key")
|
return nil, fmt.Errorf("bls signature invalid private key")
|
||||||
}
|
}
|
||||||
return new(Signature).Sign(pk, msg, []byte(DST)).Compress(), nil
|
|
||||||
|
sk := new(SecretKey)
|
||||||
|
copy(sk[:], p[:ffi.PrivateKeyBytes])
|
||||||
|
|
||||||
|
sig := ffi.PrivateKeySign(*sk, msg)
|
||||||
|
|
||||||
|
return sig[:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (blsSigner) Verify(sig []byte, a address.Address, msg []byte) error {
|
func (blsSigner) Verify(sig []byte, a address.Address, msg []byte) error {
|
||||||
if !new(Signature).VerifyCompressed(sig, a.Payload()[:], msg, []byte(DST)) {
|
payload := a.Payload()
|
||||||
|
if sig == nil || len(sig) != ffi.SignatureBytes || len(payload) != ffi.PublicKeyBytes {
|
||||||
return fmt.Errorf("bls signature failed to verify")
|
return fmt.Errorf("bls signature failed to verify")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pk := new(PublicKey)
|
||||||
|
copy(pk[:], payload[:ffi.PublicKeyBytes])
|
||||||
|
|
||||||
|
sigS := new(Signature)
|
||||||
|
copy(sigS[:], sig[:ffi.SignatureBytes])
|
||||||
|
|
||||||
|
msgs := [1]ffi.Message{msg}
|
||||||
|
pks := [1]PublicKey{*pk}
|
||||||
|
|
||||||
|
if !ffi.HashVerify(sigS, msgs[:], pks[:]) {
|
||||||
|
return fmt.Errorf("bls signature failed to verify")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,6 +229,9 @@ func gasEstimateGasLimit(
|
|||||||
pending, ts := mpool.PendingFor(fromA)
|
pending, ts := mpool.PendingFor(fromA)
|
||||||
priorMsgs := make([]types.ChainMsg, 0, len(pending))
|
priorMsgs := make([]types.ChainMsg, 0, len(pending))
|
||||||
for _, m := range pending {
|
for _, m := range pending {
|
||||||
|
if m.Message.Nonce == msg.Nonce {
|
||||||
|
break
|
||||||
|
}
|
||||||
priorMsgs = append(priorMsgs, m)
|
priorMsgs = append(priorMsgs, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user