Object.ByzantineFaultTolerance (object v0.1.2)

Byzantine fault tolerance mechanisms for the Object P2P network.

Implements various algorithms and strategies to handle malicious nodes including Sybil attack resistance, consensus protocols, reputation systems, and proof-of-work challenges.

Features

  • PBFT-inspired consensus for critical operations
  • Reputation-based trust system
  • Proof-of-work for Sybil resistance
  • Merkle tree verification for data integrity
  • Threshold signatures for group decisions
  • Audit trails and accountability

Summary

Functions

Issues a proof-of-work challenge to a node.

Returns a specification to start this module under a supervisor.

Gets the current reputation of a node.

Checks if a node is trustworthy based on reputation.

Submits a challenge response.

Initiates Byzantine consensus for a value.

Starts the Byzantine fault tolerance service.

Updates reputation based on interaction outcome.

Verifies data integrity using Merkle proofs.

Votes in a consensus round.

Types

audit_entry()

@type audit_entry() :: %{
  id: binary(),
  operation: atom(),
  participants: [binary()],
  result: term(),
  signatures: %{required(binary()) => binary()},
  timestamp: DateTime.t(),
  merkle_root: binary()
}

challenge()

@type challenge() :: %{
  challenger: binary(),
  challenged: binary(),
  type: :proof_of_work | :data_availability | :computation,
  challenge_data: term(),
  issued_at: DateTime.t(),
  expires_at: DateTime.t()
}

consensus_round()

@type consensus_round() :: %{
  id: binary(),
  proposer: binary(),
  value: term(),
  phase: :prepare | :commit | :complete | :aborted,
  votes: %{prepare: MapSet.t(), commit: MapSet.t()},
  participants: MapSet.t(),
  started_at: DateTime.t(),
  timeout_at: DateTime.t()
}

merkle_tree()

@type merkle_tree() :: %{
  root: binary(),
  height: non_neg_integer(),
  nodes: %{required(non_neg_integer()) => [binary()]}
}

node_reputation()

@type node_reputation() :: %{
  node_id: binary(),
  reputation: float(),
  interactions: non_neg_integer(),
  successful: non_neg_integer(),
  failed: non_neg_integer(),
  last_updated: DateTime.t(),
  proof_of_work: binary() | nil,
  violations: [violation()]
}

state()

@type state() :: %{
  node_id: binary(),
  reputations: %{required(binary()) => node_reputation()},
  consensus_rounds: %{required(binary()) => consensus_round()},
  pending_challenges: %{required(binary()) => challenge()},
  audit_log: [audit_entry()],
  merkle_tree: merkle_tree(),
  config: map()
}

violation()

@type violation() :: %{
  type: :double_spend | :invalid_signature | :protocol_violation | :dos_attack,
  timestamp: DateTime.t(),
  evidence: term()
}

Functions

challenge_node(node_id, challenge_type)

@spec challenge_node(binary(), :proof_of_work | :data_availability) ::
  {:ok, binary()} | {:error, term()}

Issues a proof-of-work challenge to a node.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_reputation(node_id)

@spec get_reputation(binary()) :: float()

Gets the current reputation of a node.

is_trustworthy?(node_id)

@spec is_trustworthy?(binary()) :: boolean()

Checks if a node is trustworthy based on reputation.

respond_to_challenge(challenge_id, response)

@spec respond_to_challenge(binary(), term()) :: :ok | {:error, term()}

Submits a challenge response.

start_consensus(value, participants)

@spec start_consensus(term(), [binary()]) :: {:ok, binary()} | {:error, term()}

Initiates Byzantine consensus for a value.

start_link(opts \\ [])

Starts the Byzantine fault tolerance service.

update_reputation(node_id, outcome)

@spec update_reputation(binary(), :success | :failure | violation()) :: :ok

Updates reputation based on interaction outcome.

verify_merkle_proof(data, proof, root)

@spec verify_merkle_proof(binary(), [binary()], binary()) :: boolean()

Verifies data integrity using Merkle proofs.

vote_consensus(round_id, phase, vote)

@spec vote_consensus(binary(), :prepare | :commit, boolean()) :: :ok

Votes in a consensus round.