Skip to content

Commit

Permalink
ATX v2 (for ATX merge) (#5785)
Browse files Browse the repository at this point in the history
## Motivation

Proposal of the new ATX version to support the atx merging.
  • Loading branch information
poszu committed May 9, 2024
1 parent f9119e1 commit 06ec6d0
Show file tree
Hide file tree
Showing 4 changed files with 626 additions and 0 deletions.
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
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)
}

func (c *NIPostChallengeV2) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
if c == nil {
return nil
}
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())
}
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 types.EpochID
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=256"`
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=256"`

// 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.ATXID
Post 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=256"` // support merging up to 256 IDs
}

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=256"` // support merging up to 256 IDs
}
Loading

0 comments on commit 06ec6d0

Please sign in to comment.