Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update post, poet and merkle-tree to latest #881

Merged
merged 3 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require (
github.com/prometheus/common v0.2.0
github.com/seehuhn/mt19937 v0.0.0-20180715112136-cc7708819361
github.com/spacemeshos/ed25519 v0.0.0-20190316215305-5878e62449c1
github.com/spacemeshos/merkle-tree v0.0.0-20190327145446-3651a544f849
github.com/spacemeshos/poet v0.0.0-20190428110109-b14e3f4011e5
github.com/spacemeshos/post v0.0.0-20190414091440-9e41a560833b
github.com/spacemeshos/merkle-tree v0.0.0-20190508113057-1a71b988924a
github.com/spacemeshos/poet v0.0.0-20190508113556-f56ec5e8f063
github.com/spacemeshos/post v0.0.0-20190508113329-07bdc2589d98
github.com/spacemeshos/sha256-simd v0.0.0-20190111104731-8575aafc88c9
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ github.com/golang-collections/go-datastructures v0.0.0-20150211160725-59788d5eb2
github.com/golang-collections/go-datastructures v0.0.0-20150211160725-59788d5eb259/go.mod h1:9Qcha0gTWLw//0VNka1Cbnjvg3pNKGFdAm7E9sBabxE=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff h1:kOkM9whyQYodu09SJ6W3NCsHG7crFaJILQ22Gozp3lg=
github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
Expand Down Expand Up @@ -132,12 +130,12 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/spacemeshos/ed25519 v0.0.0-20190316215305-5878e62449c1 h1:Fw9KqgcXb8mUFo6dnBWpUR7pc5SPDjKzEPDd+Z4elEk=
github.com/spacemeshos/ed25519 v0.0.0-20190316215305-5878e62449c1/go.mod h1:lyZLUyZXvd7gp6KHwGS5ZgtS2ZvV++lBjdE4MLqmLnU=
github.com/spacemeshos/go-spacemesh v0.0.0-20190218131258-f9290a04382c/go.mod h1:tY7flNGGFec6jgu03jBYCbFmntvpxOS8dG3dt0Eznl8=
github.com/spacemeshos/merkle-tree v0.0.0-20190327145446-3651a544f849 h1:RJw90V/KgsE3dKbcec+aFsgTdYzIwRlYwKRwu9DADPY=
github.com/spacemeshos/merkle-tree v0.0.0-20190327145446-3651a544f849/go.mod h1:mPxjt4RONPxSUhxOq4bhSJyKVGQJ0VMSyRiE51dDLgE=
github.com/spacemeshos/poet v0.0.0-20190428110109-b14e3f4011e5 h1:724MO4Nnr7WmWMSuEzGqqGvpcnBhFprcWjc4ziIF3p8=
github.com/spacemeshos/poet v0.0.0-20190428110109-b14e3f4011e5/go.mod h1:V896lkF+9qcGILIhtESFRCg2VqFfGuno3ieUZTMBNdo=
github.com/spacemeshos/post v0.0.0-20190414091440-9e41a560833b h1:/R/ocumeVdnFDoLMjLiElMx6K+basPVWOENLvxf/nFc=
github.com/spacemeshos/post v0.0.0-20190414091440-9e41a560833b/go.mod h1:2FA26QXziszAuvENyHv6pjld6adNW24q8Ls96yZPX60=
github.com/spacemeshos/merkle-tree v0.0.0-20190508113057-1a71b988924a h1:/CO5P93Jlt/bQIMTmKCVr001J6BteK6KRwoeVu6Zzwk=
github.com/spacemeshos/merkle-tree v0.0.0-20190508113057-1a71b988924a/go.mod h1:mPxjt4RONPxSUhxOq4bhSJyKVGQJ0VMSyRiE51dDLgE=
github.com/spacemeshos/poet v0.0.0-20190508113556-f56ec5e8f063 h1:99PgDpQW/SOSKYGHYe7CfodWt4R/xnTJexSjeJgKHSI=
github.com/spacemeshos/poet v0.0.0-20190508113556-f56ec5e8f063/go.mod h1:Ej7s4IHMZ8FHZ4ElitwuOROvecDELt82gHx0wovvZZY=
github.com/spacemeshos/post v0.0.0-20190508113329-07bdc2589d98 h1:dB9yxkhtbDYGlW7tdp3PSGRXeuOq7kE/3sJqT8Nja+M=
github.com/spacemeshos/post v0.0.0-20190508113329-07bdc2589d98/go.mod h1:n8EGjskKs9gKrxfCWqgrEH5zBiYFLZ70LezPb0CRXPg=
github.com/spacemeshos/sha256-simd v0.0.0-20190111104731-8575aafc88c9 h1:Cc+np6ORem5wrvO+YHQ1sdu71ItiQVRiYB4ugazpgxM=
github.com/spacemeshos/sha256-simd v0.0.0-20190111104731-8575aafc88c9/go.mod h1:Pz5LyRghtiEuSixOVGO0da5AxKBZa6+Yq8ZJfjTAPI0=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
7 changes: 4 additions & 3 deletions nipst/nipst.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,10 @@ func NewNIPSTWithChallenge(challenge *common.Hash) *NIPST {
PoetProof: &PoetProof{
Commitment: []byte(nil),
N: 0,
Proof: &shared.Proof{
Phi: []byte(nil),
L: [150]shared.Labels{},
Proof: &shared.MerkleProof{
Root: []byte(nil),
ProvenLeaves: [][]byte(nil),
ProofNodes: [][]byte(nil),
},
},
PostChallenge: challenge,
Expand Down
2 changes: 1 addition & 1 deletion nipst/nipst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestNIPSTBuilderWithMocks(t *testing.T) {
minerID,
1024,
5,
proving.NumberOfProvenLabels,
proving.NumOfProvenLabels,
600,
postProverMock,
poetProverMock,
Expand Down
26 changes: 9 additions & 17 deletions nipst/poet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"github.com/spacemeshos/go-spacemesh/common"
"github.com/spacemeshos/merkle-tree"
"github.com/spacemeshos/poet/rpc"
"github.com/spacemeshos/poet/hash"
"github.com/spacemeshos/poet/rpc/api"
"github.com/spacemeshos/poet/shared"
"github.com/spacemeshos/poet/verifier"
Expand All @@ -30,7 +30,7 @@ type MembershipProof struct {
type PoetProof struct {
Commitment []byte
N uint
Proof *shared.Proof
Proof *shared.MerkleProof
}

func (p *PoetProof) serialize() []byte {
Expand Down Expand Up @@ -59,17 +59,13 @@ func verifyPoetMembership(member *common.Hash, proof *MembershipProof) (bool, er
var _ verifyPoetFunc = verifyPoet

func verifyPoet(p *PoetProof) (bool, error) {
v, err := verifier.New(p.Commitment, p.N, shared.NewHashFunc(p.Commitment))
if err != nil {
return false, fmt.Errorf("failed to create a new verifier: %v", err)
}

res, err := v.VerifyNIP(*p.Proof)
leafCount := uint64(1) << p.N
err := verifier.Validate(*p.Proof, hash.GenLabelHashFunc(p.Commitment), hash.GenMerkleHashFunc(p.Commitment), leafCount, shared.T)
if err != nil {
return false, fmt.Errorf("failed to verify proof: %v", err)
}

return res, nil
return true, nil
}

var _ verifyPoetMatchesMembershipFunc = verifyPoetMatchesMembership
Expand Down Expand Up @@ -188,17 +184,13 @@ func (c *RPCPoetClient) subscribeProof(r *PoetRound,
return nil, fmt.Errorf("rpc failure: %v", err)
}

labels, err := rpc.WireLabelsToNative(res.Proof.L)
if err != nil {
return nil, fmt.Errorf("failed to deserialize proof: %v", err)
}

p := new(PoetProof)
p.N = uint(res.N)
p.Commitment = res.Commitment
p.Proof = new(shared.Proof)
p.Proof.Phi = res.Proof.Phi
p.Proof.L = *labels
p.Proof = new(shared.MerkleProof)
p.Proof.Root = res.Proof.Phi
p.Proof.ProofNodes = res.Proof.ProofNodes
p.Proof.ProvenLeaves = res.Proof.ProvenLeaves

return p, nil
}
6 changes: 2 additions & 4 deletions nipst/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func verifyPost(proof *PostProof, space uint64, numberOfProvenLabels uint8, diff
if space%merkle.NodeSize != 0 {
return false, fmt.Errorf("space (%d) is not a multiple of merkle.NodeSize (%d)", space, merkle.NodeSize)
}
leafCount := space / merkle.NodeSize
err := validation.Validate(proving.Proof(*proof), leafCount, numberOfProvenLabels, difficulty)
err := validation.Validate(proving.Proof(*proof), proving.Space(space), numberOfProvenLabels, difficulty)
if err != nil {
return false, err
}
Expand All @@ -60,8 +59,7 @@ func (c *PostClient) initialize(id []byte, space uint64, numberOfProvenLabels ui
if space%merkle.NodeSize != 0 {
return nil, fmt.Errorf("space (%d) is not a multiple of merkle.NodeSize (%d)", space, merkle.NodeSize)
}
leafCount := space / merkle.NodeSize
proof, err := initialization.Initialize(id, leafCount, numberOfProvenLabels, difficulty)
proof, err := initialization.Initialize(id, proving.Space(space), numberOfProvenLabels, difficulty)
return (*PostProof)(&proof), err
}

Expand Down
2 changes: 1 addition & 1 deletion nipst/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestPostClient(t *testing.T) {
assert.NoError(err)

space := uint64(1024)
numberOfProvenLabels := uint8(proving.NumberOfProvenLabels)
numberOfProvenLabels := uint8(proving.NumOfProvenLabels)
difficulty := proving.Difficulty(5)

c := NewPostClient()
Expand Down
7 changes: 4 additions & 3 deletions types/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ func BytesAsAtx(b []byte) (*ActivationTx, error) {
PoetProof: &nipst.PoetProof{
Commitment: nil,
N: 0,
Proof: &shared.Proof{
Phi: nil,
L: [150]shared.Labels{},
Proof: &shared.MerkleProof{
Root: nil,
ProvenLeaves: nil,
ProofNodes: nil,
},
},
PostChallenge: nil,
Expand Down