11package block
22
33import (
4+ "io"
5+
46 "github.com/eigerco/strawberry/internal/constants"
57 "github.com/eigerco/strawberry/internal/crypto"
68 "github.com/eigerco/strawberry/internal/crypto/ed25519"
79 "github.com/eigerco/strawberry/internal/jamtime"
10+ "github.com/eigerco/strawberry/pkg/serialization/codec/jam"
811)
912
1013// DisputeExtrinsic represents the structured input for submitting disputes.
@@ -37,13 +40,44 @@ type Verdict struct {
3740 Judgements [constants .ValidatorsSuperMajority ]Judgement // ⟦{{⊺,⊥}, NV, V̄}⟧⌊2/3V⌋+1
3841}
3942
43+ // UnmarshalJAM implements the JAM codec Unmarshaler interface.
44+ func (v * Verdict ) UnmarshalJAM (r io.Reader ) error {
45+ if _ , err := io .ReadFull (r , v .ReportHash [:]); err != nil {
46+ return err
47+ }
48+ buf := make ([]byte , 4 )
49+ if _ , err := io .ReadFull (r , buf ); err != nil {
50+ return err
51+ }
52+ v .EpochIndex = jamtime .Epoch (jam .DecodeUint32 (buf ))
53+ for i := range v .Judgements {
54+ if err := v .Judgements [i ].UnmarshalJAM (r ); err != nil {
55+ return err
56+ }
57+ }
58+ return nil
59+ }
60+
4061// Culprit represents misbehaving guarantor who guaranteed an invalid work-report
4162type Culprit struct {
4263 ReportHash crypto.Hash // H, hash of the work report
4364 ValidatorEd25519PublicKey ed25519.PublicKey // H̄
4465 Signature crypto.Ed25519Signature // V̄
4566}
4667
68+ // UnmarshalJAM implements the JAM codec Unmarshaler interface.
69+ func (c * Culprit ) UnmarshalJAM (r io.Reader ) error {
70+ if _ , err := io .ReadFull (r , c .ReportHash [:]); err != nil {
71+ return err
72+ }
73+ c .ValidatorEd25519PublicKey = make ([]byte , crypto .Ed25519PublicSize )
74+ if _ , err := io .ReadFull (r , c .ValidatorEd25519PublicKey ); err != nil {
75+ return err
76+ }
77+ _ , err := io .ReadFull (r , c .Signature [:])
78+ return err
79+ }
80+
4781// Fault is an Auditor who made incorrect judgment
4882type Fault struct {
4983 ReportHash crypto.Hash // H, hash of the work report
@@ -52,17 +86,60 @@ type Fault struct {
5286 Signature crypto.Ed25519Signature // V̄
5387}
5488
89+ // UnmarshalJAM implements the JAM codec Unmarshaler interface.
90+ func (f * Fault ) UnmarshalJAM (r io.Reader ) error {
91+ if _ , err := io .ReadFull (r , f .ReportHash [:]); err != nil {
92+ return err
93+ }
94+ b := make ([]byte , 1 )
95+ if _ , err := io .ReadFull (r , b ); err != nil {
96+ return err
97+ }
98+ f .IsValid = b [0 ] != 0
99+ f .ValidatorEd25519PublicKey = make ([]byte , crypto .Ed25519PublicSize )
100+ if _ , err := io .ReadFull (r , f .ValidatorEd25519PublicKey ); err != nil {
101+ return err
102+ }
103+ _ , err := io .ReadFull (r , f .Signature [:])
104+ return err
105+ }
106+
55107// Judgement is a statement from an auditor that declares whether a given work-report is valid or invalid
56108type Judgement struct {
57109 IsValid bool // {⊺,⊥}
58110 ValidatorIndex uint16 // NV
59111 Signature crypto.Ed25519Signature // V̄
60112}
61113
114+ // UnmarshalJAM implements the JAM codec Unmarshaler interface.
115+ func (j * Judgement ) UnmarshalJAM (r io.Reader ) error {
116+ buf := make ([]byte , 3 )
117+ if _ , err := io .ReadFull (r , buf ); err != nil {
118+ return err
119+ }
120+ j .IsValid = buf [0 ] != 0
121+ j .ValidatorIndex = jam .DecodeUint16 (buf [1 :3 ])
122+ _ , err := io .ReadFull (r , j .Signature [:])
123+ return err
124+ }
125+
62126// VerdictSummary V is a sequence of (report_hash, vote_count) pairs
63127// where vote_count must be exactly one of: 0, ⌊V/3⌋, or ⌊2V/3⌋+1
64128// V ∈ ⟦⟨H, {0, ⌊1/3V⌋, ⌊2/3V⌋ + 1}⟩⟧ (eq. 10.11 v0.7.0)
65129type VerdictSummary struct {
66130 ReportHash crypto.Hash // H
67131 VoteCount uint16 // Must be 0, V/3, or 2V/3+1
68132}
133+
134+ // UnmarshalJAM implements the JAM codec Unmarshaler interface.
135+ func (vs * VerdictSummary ) UnmarshalJAM (r io.Reader ) error {
136+ if _ , err := io .ReadFull (r , vs .ReportHash [:]); err != nil {
137+ return err
138+ }
139+ buf := make ([]byte , 2 )
140+ if _ , err := io .ReadFull (r , buf ); err != nil {
141+ return err
142+ }
143+ vs .VoteCount = jam .DecodeUint16 (buf )
144+ return nil
145+ }
0 commit comments