adversary

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: Apache-2.0, MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validated

func Validated(msg *gpbft.GMessage) gpbft.ValidatedMessage

Types

type Absent

type Absent struct {
	// contains filtered or unexported fields
}

func NewAbsent

func NewAbsent(id gpbft.ActorID, host gpbft.Host) *Absent

A participant that never sends anything.

func (*Absent) AllowMessage

func (*Absent) AllowMessage(_ gpbft.ActorID, _ gpbft.ActorID, _ gpbft.GMessage) bool

func (*Absent) ID

func (a *Absent) ID() gpbft.ActorID

func (*Absent) ReceiveAlarm

func (*Absent) ReceiveAlarm() error

func (*Absent) ReceiveMessage

func (*Absent) ReceiveMessage(_ gpbft.ValidatedMessage) error

func (*Absent) StartInstanceAt added in v0.0.3

func (*Absent) StartInstanceAt(uint64, time.Time) error

func (*Absent) ValidateMessage

func (*Absent) ValidateMessage(msg *gpbft.GMessage) (gpbft.ValidatedMessage, error)

type Adversary

type Adversary struct {
	Receiver
	Power gpbft.StoragePower
}

type Deny

type Deny struct {
	// contains filtered or unexported fields
}

Deny adversary denies all messages to/from a given set of participants for a configured duration of time.

For this adversary to take effect global stabilisation time must be configured to be at least as long as the configured deny duration.

See sim.WithGlobalStabilizationTime.

func NewDeny

func NewDeny(id gpbft.ActorID, host Host, denialDuration time.Duration, msgMatcher DenyMessageMatcher, mode DenyTargetMode, targets ...gpbft.ActorID) *Deny

func (*Deny) AllowMessage

func (d *Deny) AllowMessage(from gpbft.ActorID, to gpbft.ActorID, msg gpbft.GMessage) bool

func (*Deny) ID

func (d *Deny) ID() gpbft.ActorID

func (*Deny) ReceiveAlarm

func (*Deny) ReceiveAlarm() error

func (*Deny) ReceiveMessage

func (*Deny) ReceiveMessage(gpbft.ValidatedMessage) error

func (*Deny) StartInstanceAt added in v0.0.3

func (*Deny) StartInstanceAt(uint64, time.Time) error

func (*Deny) ValidateMessage

func (*Deny) ValidateMessage(msg *gpbft.GMessage) (gpbft.ValidatedMessage, error)

type DenyMessageMatcher added in v0.3.0

type DenyMessageMatcher func(*gpbft.GMessage) bool

DenyMessageMatcher checks whether a message should be denied by the Deny adversary or not.

See: DenyAllMessages, DenyPhase.

var (
	DenyAllMessages DenyMessageMatcher = func(*gpbft.GMessage) bool { return true }
)

func DenyPhase added in v0.3.0

func DenyPhase(phase gpbft.Phase) DenyMessageMatcher

DenyPhase denies all messages at the given phase.

type DenyTargetMode added in v0.3.0

type DenyTargetMode int
const (
	// DenyToOrFrom denies message to or from target actor IDs.
	DenyToOrFrom DenyTargetMode = iota
	// DenyTo only denies messages destined to target actor IDs.
	DenyTo
	// DenyFrom only denies messages sent from target actor IDs.
	DenyFrom
)

func (DenyTargetMode) String added in v0.3.0

func (m DenyTargetMode) String() string

type Drop

type Drop struct {
	// contains filtered or unexported fields
}

Drop adversary stochastically drops messages to/from a given set of participants for a configured duration of time, mimicking at-most-once message delivery semantics across a simulation network.

When no participants are set, all exchanged messages will be targeted by this adversary. For this adversary to take effect global stabilisation time must be configured to be at least as long as the configured drop duration.

See sim.WithGlobalStabilizationTime.

func NewDrop

func NewDrop(id gpbft.ActorID, host Host, seed int64, dropProbability float64, dropDuration time.Duration, targets ...gpbft.ActorID) *Drop

func (*Drop) AllowMessage

func (d *Drop) AllowMessage(from gpbft.ActorID, to gpbft.ActorID, _ gpbft.GMessage) bool

func (*Drop) ID

func (d *Drop) ID() gpbft.ActorID

func (*Drop) ReceiveAlarm

func (*Drop) ReceiveAlarm() error

func (*Drop) ReceiveMessage

func (*Drop) ReceiveMessage(gpbft.ValidatedMessage) error

func (*Drop) StartInstanceAt added in v0.0.3

func (*Drop) StartInstanceAt(uint64, time.Time) error

func (*Drop) ValidateMessage

func (*Drop) ValidateMessage(msg *gpbft.GMessage) (gpbft.ValidatedMessage, error)

type Generator

type Generator func(gpbft.ActorID, Host) *Adversary

func NewAbsentGenerator

func NewAbsentGenerator(power gpbft.StoragePower) Generator

func NewDenyGenerator

func NewDenyGenerator(power gpbft.StoragePower, denialDuration time.Duration, msgMatcher DenyMessageMatcher, mode DenyTargetMode, targets ...gpbft.ActorID) Generator

func NewDropGenerator

func NewDropGenerator(power gpbft.StoragePower, seed int64, dropProbability float64, dropDuration time.Duration, targets ...gpbft.ActorID) Generator

func NewImmediateDecideGenerator

func NewImmediateDecideGenerator(value *gpbft.ECChain, power gpbft.StoragePower, opts ...ImmediateDecideOption) Generator

func NewRepeatGenerator

func NewRepeatGenerator(power gpbft.StoragePower, sampler RepetitionSampler) Generator

func NewSpamGenerator

func NewSpamGenerator(power gpbft.StoragePower, roundsAhead uint64) Generator

func NewWitholdCommitGenerator

func NewWitholdCommitGenerator(power gpbft.StoragePower, victims []gpbft.ActorID, victimValue *gpbft.ECChain) Generator

type Host

type Host interface {
	gpbft.Host
	gpbft.Signer
	// Sends a message to all other participants, immediately.
	// Note that the adversary can subsequently delay delivery to some participants,
	// before messages are actually received.
	RequestSynchronousBroadcast(mb *gpbft.MessageBuilder) error
}

Endpoint with which the adversary can control the network

type ImmediateDecide

type ImmediateDecide struct {
	// contains filtered or unexported fields
}

/ An "adversary" that immediately sends a DECIDE message, justified by its own COMMIT.

func NewImmediateDecide

func NewImmediateDecide(id gpbft.ActorID, host Host, value *gpbft.ECChain, opts ...ImmediateDecideOption) *ImmediateDecide

func (*ImmediateDecide) AllowMessage

func (*ImmediateDecide) AllowMessage(_ gpbft.ActorID, _ gpbft.ActorID, _ gpbft.GMessage) bool

func (*ImmediateDecide) ID

func (i *ImmediateDecide) ID() gpbft.ActorID

func (*ImmediateDecide) ReceiveAlarm

func (*ImmediateDecide) ReceiveAlarm() error

func (*ImmediateDecide) ReceiveMessage

func (*ImmediateDecide) ReceiveMessage(_ gpbft.ValidatedMessage) error

func (*ImmediateDecide) StartInstanceAt added in v0.0.3

func (i *ImmediateDecide) StartInstanceAt(instance uint64, _when time.Time) error

func (*ImmediateDecide) ValidateMessage

func (*ImmediateDecide) ValidateMessage(msg *gpbft.GMessage) (gpbft.ValidatedMessage, error)

type ImmediateDecideOption added in v0.0.3

type ImmediateDecideOption func(*ImmediateDecide)

func ImmediateDecideWithJustifiedSupplementalData added in v0.0.4

func ImmediateDecideWithJustifiedSupplementalData(data gpbft.SupplementalData) ImmediateDecideOption

Immediately decide with a value that may or may not match the justification.

func ImmediateDecideWithJustifiedValue added in v0.0.4

func ImmediateDecideWithJustifiedValue(value *gpbft.ECChain) ImmediateDecideOption

Immediately decide with a value that may or may not match the justification.

func ImmediateDecideWithNthParticipant added in v0.0.3

func ImmediateDecideWithNthParticipant(n uint64) ImmediateDecideOption

type Receiver

type Receiver interface {
	gpbft.Receiver
	ID() gpbft.ActorID
	AllowMessage(from gpbft.ActorID, to gpbft.ActorID, msg gpbft.GMessage) bool
}

type Repeat

type Repeat struct {
	// contains filtered or unexported fields
}

Repeat is a type of adversary in the gpbft consensus protocol that intercepts and rebroadcasts messages. It is designed to test the resilience of the consensus mechanism against Byzantine faults, specifically through message repetition attacks.

The number of times each message is repeated can be configured using RepetitionSampler. This allows simulating fixed or varying degrees of repetition throughout a simulation. The repeated messages are resigned by the adversary with other fields left unmodified. This results in a mimicking behaviour, where the adversary broadcasts any message it receives as its own.

By repeating messages, this adversary can simulate a variety of fault conditions, including the creation of equivocations. Equivocations occur when a node (or in this case, an adversary) sends conflicting information to different parts of the network, which can potentially mislead other nodes about the state of consensus. This behavior effectively amplifies the likelihood of network partitions in cases where there are diverging base chains across the participants. More importantly, this adversary may momentarily appear to be part of one or other network partitions.

See RepetitionSampler.

func NewRepeat

func NewRepeat(id gpbft.ActorID, host Host, sampler RepetitionSampler) *Repeat

NewRepeat creates a new instance of the Repeat adversary using the provided id, host, and repetitionSampler. The RepetitionSampler is used to determine the number of times each message received by this adversary should be repeated and retransmitted to other nodes in the network. This repetition could potentially disrupt or manipulate the consensus process depending on how the repetitionSampler is configured (e.g., fixed or probabilistic repetitions), and can lead to equivocating messages across the network.

The primary role of the Repeat adversary is to intercept messages and then broadcast them multiple times. The number of repetitions for each message is determined by the RepetitionSampler. Each echoed message is signed and optionally includes a new ticket if the original message had one. Note, this adversary does not modify the received messages. Instead, it resigns them as its own and broadcasts them effectively mimicking the behavior of other participants in the network.

func (*Repeat) AllowMessage

func (r *Repeat) AllowMessage(gpbft.ActorID, gpbft.ActorID, gpbft.GMessage) bool

func (*Repeat) ID

func (r *Repeat) ID() gpbft.ActorID

func (*Repeat) ReceiveAlarm

func (r *Repeat) ReceiveAlarm() error

func (*Repeat) ReceiveMessage

func (r *Repeat) ReceiveMessage(vmsg gpbft.ValidatedMessage) error

func (*Repeat) StartInstanceAt added in v0.0.3

func (r *Repeat) StartInstanceAt(uint64, time.Time) error

func (*Repeat) ValidateMessage

func (*Repeat) ValidateMessage(msg *gpbft.GMessage) (gpbft.ValidatedMessage, error)

type RepetitionSampler

type RepetitionSampler func(*gpbft.GMessage) int

RepetitionSampler returns the number of times each message is repeated by Repeat adversary. The sampler may implement a fixed or random sampling, and can return different values over time. This allows an implementer to program scenarios where messages are repeated probabilistically or at certain stage through the experiment.

The number of times a message s repeated is dynamically configurable based on the original message itself. For example, an implementer may choose to only repeat messages in a certain phase or from a certain participants. A repetition count of less than or equal to zero signals that the adversary should not rebroadcast the message at all.

type Spam

type Spam struct {
	// contains filtered or unexported fields
}

Spam is an adversary that propagates COMMIT messages for bottom for a configured number of future rounds.

func NewSpam

func NewSpam(id gpbft.ActorID, host Host, roundsAhead uint64) *Spam

NewSpam instantiates a new Spam adversary that spams the network with spammable messages (i.e. COMMIT for bottom) for the configured number of roundsAhead via either synchronous or regular broadcast. This adversary resigns the spammable messages as its own to mimic messages with valid signature but for future rounds.

func (*Spam) AllowMessage

func (s *Spam) AllowMessage(gpbft.ActorID, gpbft.ActorID, gpbft.GMessage) bool

func (*Spam) ID

func (s *Spam) ID() gpbft.ActorID

func (*Spam) ReceiveAlarm

func (s *Spam) ReceiveAlarm() error

func (*Spam) ReceiveMessage

func (s *Spam) ReceiveMessage(vmsg gpbft.ValidatedMessage) error

func (*Spam) StartInstanceAt added in v0.0.3

func (s *Spam) StartInstanceAt(instance uint64, _when time.Time) error

func (*Spam) ValidateMessage

func (*Spam) ValidateMessage(msg *gpbft.GMessage) (gpbft.ValidatedMessage, error)

type WithholdCommit

type WithholdCommit struct {
	// contains filtered or unexported fields
}

This adversary send its COMMIT message to only a single victim, withholding it from others. Against a naive algorithm, when set up with 30% of power, and a victim set with 40%, it can cause one victim to decide, while others revert to the base.

func NewWitholdCommit

func NewWitholdCommit(id gpbft.ActorID, host Host) *WithholdCommit

A participant that never sends anything.

func (*WithholdCommit) AllowMessage

func (w *WithholdCommit) AllowMessage(_ gpbft.ActorID, to gpbft.ActorID, msg gpbft.GMessage) bool

func (*WithholdCommit) ID

func (w *WithholdCommit) ID() gpbft.ActorID

func (*WithholdCommit) ReceiveAlarm

func (*WithholdCommit) ReceiveAlarm() error

func (*WithholdCommit) ReceiveMessage

func (*WithholdCommit) ReceiveMessage(gpbft.ValidatedMessage) error

func (*WithholdCommit) SetVictim

func (w *WithholdCommit) SetVictim(victims []gpbft.ActorID, victimValue *gpbft.ECChain)

func (*WithholdCommit) StartInstanceAt added in v0.0.3

func (w *WithholdCommit) StartInstanceAt(instance uint64, _when time.Time) error

func (*WithholdCommit) ValidateMessage

func (*WithholdCommit) ValidateMessage(msg *gpbft.GMessage) (gpbft.ValidatedMessage, error)

Jump to

Keyboard shortcuts

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