round

package
v0.6.0-alpha-2021-09-21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilFields      = errors.New("message contained empty fields")
	ErrInvalidContent = errors.New("content is not the right type")
	ErrOutChanFull    = errors.New("content is not the right type")
)

Functions

This section is empty.

Types

type Abort

type Abort struct {
	*Helper
	Culprits []party.ID
	Err      error
}

Abort is an empty round containing a list of parties who misbehaved.

func (*Abort) Finalize

func (r *Abort) Finalize(chan<- *Message) (Session, error)

func (Abort) MessageContent

func (Abort) MessageContent() Content

func (Abort) Number

func (Abort) Number() Number

func (Abort) StoreMessage

func (Abort) StoreMessage(Message) error

func (Abort) VerifyMessage

func (Abort) VerifyMessage(Message) error

type BroadcastContent

type BroadcastContent interface {
	Content
	Reliable() bool
}

BroadcastContent wraps a Content, but also indicates whether this content requires reliable broadcast.

type BroadcastRound

type BroadcastRound interface {
	// StoreBroadcastMessage must be run before Round.VerifyMessage and Round.StoreMessage,
	// since those may depend on the content from the broadcast.
	// It changes the round's state to store the message after performing basic validation.
	StoreBroadcastMessage(msg Message) error

	// BroadcastContent returns an uninitialized message.Content for this round's broadcast message.
	//
	// The first round of a protocol, and rounds which do not expect a broadcast message should return nil.
	BroadcastContent() BroadcastContent

	// Round must be implemented by an inherited round which would otherwise function the same way.
	Round
}

BroadcastRound extends Round in that it expects a broadcast message before the p2p message. Due to the way Go struct inheritance works, it is necessary to implement both methods in a separate struct which itself only inherits the base Round. This way, we do not inherit the broadcast methods, and we can identify a broadcast round by type assertion.

type Content

type Content interface {
	RoundNumber() Number
}

Content represents the message, either broadcast or P2P returned by a round during finalization.

type Helper

type Helper struct {

	// Pool allows us to parallelize certain operations
	Pool *pool.Pool
	// contains filtered or unexported fields
}

Helper implements Session without Round, and can therefore be embedded in the first round of a protocol in order to satisfy the Session interface.

func NewSession

func NewSession(info Info, sessionID []byte, pl *pool.Pool, auxInfo ...hash.WriterToWithDomain) (*Helper, error)

NewSession creates a new *Helper which can be embedded in the first Round, so that the full struct implements Session. `sessionID` is an optional byte slice that can be provided by the user. When used, it should be unique for each execution of the protocol. It could be a simple counter which is incremented after execution, or a common random string. `auxInfo` is a variable list of objects which should be included in the session's hash state.

func (*Helper) AbortRound

func (h *Helper) AbortRound(err error, culprits ...party.ID) Session

AbortRound returns a round that contains only the culprits that were able to be identified during a faulty execution of the protocol. The error returned by Round.Finalize() in this case should still be nil.

func (*Helper) BroadcastMessage

func (h *Helper) BroadcastMessage(out chan<- *Message, broadcastContent Content) error

BroadcastMessage constructs a Message from the broadcast Content, and sets the header correctly. An error is returned if the message cannot be sent to the out channel.

func (*Helper) FinalRoundNumber

func (h *Helper) FinalRoundNumber() Number

FinalRoundNumber is the number of rounds before the output round.

func (*Helper) Group

func (h *Helper) Group() curve.Curve

Group returns the curve used for this protocol.

func (*Helper) Hash

func (h *Helper) Hash() *hash.Hash

Hash returns copy of the hash function of this protocol execution.

func (*Helper) HashForID

func (h *Helper) HashForID(id party.ID) *hash.Hash

HashForID returns a clone of the hash.Hash for this session, initialized with the given id.

func (*Helper) N

func (h *Helper) N() int

N returns the number of participants.

func (*Helper) OtherPartyIDs

func (h *Helper) OtherPartyIDs() party.IDSlice

OtherPartyIDs returns a sorted list of parties that does not contain SelfID.

func (*Helper) PartyIDs

func (h *Helper) PartyIDs() party.IDSlice

PartyIDs is a sorted slice of participating parties in this protocol.

func (*Helper) ProtocolID

func (h *Helper) ProtocolID() string

ProtocolID is an identifier for this protocol.

func (*Helper) ResultRound

func (h *Helper) ResultRound(result interface{}) Session

ResultRound returns a round that contains only the result of the protocol. This indicates to the used that the protocol is finished.

func (*Helper) SSID

func (h *Helper) SSID() []byte

SSID the unique identifier for this protocol execution.

func (*Helper) SelfID

func (h *Helper) SelfID() party.ID

SelfID is this party's ID.

func (*Helper) SendMessage

func (h *Helper) SendMessage(out chan<- *Message, content Content, to party.ID) error

SendMessage is a convenience method for safely sending content to some party. If the message is intended for all participants (but does not require reliable broadcast), the `to` field may be empty (""). Returns an error if the message failed to send over out channel. `out` is expected to be a buffered channel with enough capacity to store all messages.

func (*Helper) Threshold

func (h *Helper) Threshold() int

Threshold is the maximum number of parties that are assumed to be corrupted during the execution of this protocol.

func (*Helper) UpdateHashState

func (h *Helper) UpdateHashState(value hash.WriterToWithDomain)

UpdateHashState writes additional data to the hash state.

type Info

type Info struct {
	// ProtocolID is an identifier for this protocol
	ProtocolID string
	// FinalRoundNumber is the number of rounds before the output round.
	FinalRoundNumber Number
	// SelfID is this party's ID.
	SelfID party.ID
	// PartyIDs is a sorted slice of participating parties in this protocol.
	PartyIDs []party.ID
	// Threshold is the maximum number of parties that are assumed to be corrupted during the execution of this protocol.
	Threshold int
	// Group returns the group used for this protocol execution.
	Group curve.Curve
}

type Message

type Message struct {
	From, To  party.ID
	Broadcast bool
	Content   Content
}

type NormalBroadcastContent

type NormalBroadcastContent struct{}

These structs can be embedded in a broadcast message as a way of 1. implementing BroadcastContent 2. indicate to the handler whether the content should be reliably broadcast When non-unanimous halting is acceptable, we can use the echo broadcast.

func (NormalBroadcastContent) Reliable

func (NormalBroadcastContent) Reliable() bool

type Number

type Number uint16

Number is the index of the current round. 0 indicates the output round, 1 is the first round.

func (Number) Domain

func (Number) Domain() string

Domain implements hash.WriterToWithDomain.

func (Number) WriteTo

func (i Number) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo interface.

type Output

type Output struct {
	*Helper
	Result interface{}
}

Output is an empty round containing the output of the protocol.

func (*Output) Finalize

func (r *Output) Finalize(chan<- *Message) (Session, error)

func (Output) MessageContent

func (Output) MessageContent() Content

func (Output) Number

func (Output) Number() Number

func (Output) StoreMessage

func (Output) StoreMessage(Message) error

func (Output) VerifyMessage

func (Output) VerifyMessage(Message) error

type ReliableBroadcastContent

type ReliableBroadcastContent struct{}

These structs can be embedded in a broadcast message as a way of 1. implementing BroadcastContent 2. indicate to the handler whether the content should be reliably broadcast When non-unanimous halting is acceptable, we can use the echo broadcast.

func (ReliableBroadcastContent) Reliable

func (ReliableBroadcastContent) Reliable() bool

type Round

type Round interface {
	// VerifyMessage handles an incoming Message and validates its content with regard to the protocol specification.
	// The content argument can be cast to the appropriate type for this round without error check.
	// In the first round, this function returns nil.
	// This function should not modify any saved state as it may be be running concurrently.
	VerifyMessage(msg Message) error

	// StoreMessage should be called after VerifyMessage and should only store the appropriate fields from the
	// content.
	StoreMessage(msg Message) error

	// Finalize is called after all messages from the parties have been processed in the current round.
	// Messages for the next round are sent out through the out channel.
	// If a non-critical error occurs (like a failure to sample, hash, or send a message), the current round can be
	// returned so that the caller may try to finalize again.
	//
	// If an abort occurs, the expected behavior is to return
	//   r.AbortRound(err, culprits), nil.
	// This indicates to the caller that the protocol has aborted due to a "math" error.
	//
	// In the last round, Finalize should return
	//   r.ResultRound(result), nil
	// where result is the output of the protocol.
	Finalize(out chan<- *Message) (Session, error)

	// MessageContent returns an uninitialized message.Content for this round.
	//
	// The first round of a protocol should return nil.
	MessageContent() Content

	// Number returns the current round number.
	Number() Number
}

type Session

type Session interface {
	// Round is the current round being executed.
	Round
	// Group returns the group used for this protocol execution.
	Group() curve.Curve
	// Hash returns a cloned hash function with the current hash state.
	Hash() *hash.Hash
	// ProtocolID is an identifier for this protocol.
	ProtocolID() string
	// FinalRoundNumber is the number of rounds before the output round.
	FinalRoundNumber() Number
	// SSID the unique identifier for this protocol execution.
	SSID() []byte
	// SelfID is this party's ID.
	SelfID() party.ID
	// PartyIDs is a sorted slice of participating parties in this protocol.
	PartyIDs() party.IDSlice
	// OtherPartyIDs returns a sorted list of parties that does not contain SelfID.
	OtherPartyIDs() party.IDSlice
	// Threshold is the maximum number of parties that are assumed to be corrupted during the execution of this protocol.
	Threshold() int
	// N returns the total number of parties participating in the protocol.
	N() int
}

Session represents the current execution of a round-based protocol. It embeds the current round, and provides additional

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL