From 241ec1d194485f76c23cdedfba6e348055961ac0 Mon Sep 17 00:00:00 2001 From: Emanuel Pargov Date: Fri, 26 Jul 2024 12:02:19 +0300 Subject: [PATCH 1/2] Add ticket structs (#18) --- internal/block/block.go | 8 ++++++++ internal/block/ticket.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 internal/block/ticket.go diff --git a/internal/block/block.go b/internal/block/block.go index 9520e22..a7eb69a 100644 --- a/internal/block/block.go +++ b/internal/block/block.go @@ -1,4 +1,12 @@ package block +// Block represents the main block structure type Block struct { + Header *Header + Extrinsic *Extrinsic +} + +// Extrinsic represents the block extrinsic data +type Extrinsic struct { + ET []*TicketProof } diff --git a/internal/block/ticket.go b/internal/block/ticket.go new file mode 100644 index 0000000..5a94531 --- /dev/null +++ b/internal/block/ticket.go @@ -0,0 +1,20 @@ +package block + +import "github.com/eigerco/strawberry/internal/crypto" + +const ( + maxTicketsPerBlock = 16 // `K` in the paper. The maximum number of tickets which may be submitted in a single extrinsic. + ticketProofSize = 784 // Size of F̄[]γz⟨XT ⌢ η′2 r⟩ +) + +// Ticket represents a single ticket (C in equation 50) +type Ticket struct { + Identifier crypto.Hash // y ∈ H 32bytes hash + EntryIndex uint8 // r ∈ Nn (0, 1) +} + +// TicketProof represents a proof of a valid ticket +type TicketProof struct { + EntryIndex uint8 // r ∈ Nn (0, 1) + Proof [ticketProofSize]byte // RingVRF proof +} From 11856c3d9a28052b1de73683efc2bdd9002cf207 Mon Sep 17 00:00:00 2001 From: Daniel Vladco Date: Mon, 29 Jul 2024 12:57:46 +0300 Subject: [PATCH 2/2] Add header fields (#16) feat: add header fields --- internal/block/header.go | 25 +++++++++++++++++++++++++ internal/crypto/bandersnatch.go | 4 ++++ 2 files changed, 29 insertions(+) create mode 100644 internal/crypto/bandersnatch.go diff --git a/internal/block/header.go b/internal/block/header.go index 50bb32b..aa14fe8 100644 --- a/internal/block/header.go +++ b/internal/block/header.go @@ -1,4 +1,29 @@ package block +import ( + "github.com/eigerco/strawberry/internal/crypto" + "github.com/eigerco/strawberry/internal/time" +) + +const NumberOfValidators uint16 = 1023 + +// Header as defined in the section 5 in the paper type Header struct { + ParentHash crypto.Hash // Hp + PriorStateRoot crypto.Hash // Hr + ExtrinsicHash crypto.Hash // Hx + TimeSlotIndex time.Timeslot // Ht + EpochMarker *EpochMarker // He + WinningTicketsMarker [time.TimeslotsPerEpoch]*Ticket // Hw + JudgementsMarkers []crypto.Hash // Hj + PublicKeyIndex uint16 // Hk + VRFSignature crypto.BandersnatchSignature // Hv + BlockSealSignature crypto.BandersnatchSignature // Hs +} + +// EpochMarker consists of epoch randomness and a sequence of +// Bandersnatch keys defining the Bandersnatch validator keys (kb) beginning in the next epoch. +type EpochMarker struct { + Keys [NumberOfValidators]crypto.BandersnatchPublicKey + Entropy crypto.Hash } diff --git a/internal/crypto/bandersnatch.go b/internal/crypto/bandersnatch.go new file mode 100644 index 0000000..b70e5db --- /dev/null +++ b/internal/crypto/bandersnatch.go @@ -0,0 +1,4 @@ +package crypto + +type BandersnatchPublicKey [BandersnatchSize]byte +type BandersnatchSignature [96]byte