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

[Merged by Bors] - ATX v2 (for ATX merge) #5785

Closed
wants to merge 12 commits into from
43 changes: 43 additions & 0 deletions activation/wire/challenge_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package wire

import (
"go.uber.org/zap/zapcore"

"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/hash"
)

//go:generate scalegen

// NIPostChallengeV2 collects information needed to generate a PoET challenge.
// It's hash is the challenge registered in the PoET.
type NIPostChallengeV2 struct {
PublishEpoch types.EpochID
PrevATXID types.ATXID
PositioningATXID types.ATXID
CommitmentATXID *types.ATXID
poszu marked this conversation as resolved.
Show resolved Hide resolved
InitialPost *PostV1
}

// Hash serializes the NIPostChallenge and returns its hash.
// The serialized challenge is first prepended with a byte 0x00, and then hashed
// for second preimage resistance of poet membership merkle tree.
func (c *NIPostChallengeV2) Hash() types.Hash32 {
ncBytes := codec.MustEncode(c)
return hash.Sum([]byte{0x00}, ncBytes)

Check warning on line 28 in activation/wire/challenge_v2.go

View check run for this annotation

Codecov / codecov/patch

activation/wire/challenge_v2.go#L26-L28

Added lines #L26 - L28 were not covered by tests
}
Comment on lines +23 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably also be changed to be the root of a merkle tree formed by the NiPostChallengeV2, to ensure we can proof any field to be a specific value in a malfeasance proof without having to attach the full ATX. We just need to make sure that the NiPostChallengeV2 is attached via its root to the tree to be able to extract each field individually.

Regarding pre-image resistance: we need to check if this is still needed with the new signature scheme.


func (c *NIPostChallengeV2) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
if c == nil {
return nil

Check warning on line 33 in activation/wire/challenge_v2.go

View check run for this annotation

Codecov / codecov/patch

activation/wire/challenge_v2.go#L31-L33

Added lines #L31 - L33 were not covered by tests
}
encoder.AddUint32("PublishEpoch", c.PublishEpoch.Uint32())
encoder.AddString("PrevATXID", c.PrevATXID.String())
encoder.AddString("PositioningATX", c.PositioningATXID.String())
if c.CommitmentATXID != nil {
encoder.AddString("CommitmentATX", c.CommitmentATXID.String())

Check warning on line 39 in activation/wire/challenge_v2.go

View check run for this annotation

Codecov / codecov/patch

activation/wire/challenge_v2.go#L35-L39

Added lines #L35 - L39 were not covered by tests
}
encoder.AddObject("InitialPost", c.InitialPost)
return nil
}
90 changes: 90 additions & 0 deletions activation/wire/challenge_v2_scale.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions activation/wire/wire_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package wire

import "github.com/spacemeshos/go-spacemesh/common/types"

//go:generate scalegen

type ActivationTxV2 struct {
PublishEpoch uint32
PositioningATX types.ATXID

// Must be present in the initial ATX.
// Nil in subsequent ATXs unless smesher wants to change it.
// If Nil, the value is inferred from the previous ATX of this smesher.
// It's not allowed to pass the same coinbase as already used by the previous ATX
// to avoid spamming the network with redundant information.
Coinbase *types.Address

// only present in initial ATX
Initial *InitialAtxPartsV2
PreviousATXs []types.ATXID `scale:"max=100"`
NiPosts []NiPostsV2 `scale:"max=2"`

// The VRF nonce must be valid for the collected space of all included IDs.
// only present when:
// - the nonce changed (included more/heavier IDs)
// - it's an initial ATX
VRFNonce *uint64

// The list of marriages with other IDs.
// A marriage is permanent and cannot be revoked or repeated.
// All new IDs that are married to this ID are added to the equivocation set
// that this ID belongs to.
Marriages []MarriageCertificate `scale:"max=100"`
poszu marked this conversation as resolved.
Show resolved Hide resolved

// The ID of the ATX containing marriage for the included IDs.
// Only required when the ATX includes married IDs.
MarriageATX *types.ATXID

Signature types.EdSignature
}

// The first PoST is always for the ATX owner.
func (atx *ActivationTxV2) SmesherID() types.NodeID {
return atx.NiPosts[0].Posts[0].ID
}

type InitialAtxPartsV2 struct {
CommitmentATX types.Hash32
InitialPost PostV1
// needed make hash of the first InnerActivationTxV2 unique
// if the InitialPost happens to be the same for different IDs.
NodeID types.NodeID
}

// MarriageCertificate proves the will of ID to be married with the ID that includes this certificate.
// A marriage allows for publishing a merged ATX, which can contain PoST for all married IDs.
// Any ID from the marriage can publish a merged ATX on behalf of all married IDs.
type MarriageCertificate struct {
ID types.NodeID
// Signature over the other ID that this ID marries with
// If Alice marries Bob, then Alice signs Bob's ID
// and Bob includes this certificate in his ATX.
Signature types.EdSignature
}

// MerkleProofV2 proves membership of multiple challenges in a PoET membership merkle tree.
type MerkleProofV2 struct {
// Nodes on path from leaf to root (not including leaf)
Nodes []types.Hash32 `scale:"max=32"`
LeafIndices []uint64 `scale:"max=100"` // support merging up to 100 IDs
poszu marked this conversation as resolved.
Show resolved Hide resolved
}

type SubPostV2 struct {
ID types.NodeID // The ID that this PoST is for.
PrevATXIndex uint32 // Index of the previous ATX in the `InnerActivationTxV2.PreviousATXs` slice
Post PostV1
NumUnits uint32
}

type NiPostsV2 struct {
// Single membership proof for all IDs in `Posts`.
// The index of ID in `Posts` is the index of the challenge in the proof (`LeafIndices`).
Membership MerkleProofV2
// The root of the PoET proof, that serves as the challenge for PoSTs.
Challenge types.Hash32
Posts []SubPostV2 `scale:"max=100"` // support merging up to 100 IDs
}
Loading