broadcast

Echo Broadcast Protocol Implementation

Implements Bracha’s reliable broadcast protocol for Byzantine fault tolerance. Ensures all honest parties receive the same message from each sender.

Based on: Bracha’s Reliable Broadcast (1987)
Reference: “Asynchronous Byzantine Agreement Protocols” - Gabriel Bracha

Used in: DKLS23 Threshold ECDSA DKG for broadcast consistency verification
Authors:

Elton de Souza

Date:

01/2026

class broadcast.EchoBroadcast(num_parties: int, fault_threshold: int | None = None)[source]

Bases: object

Echo broadcast protocol for Byzantine fault tolerant message delivery.

Ensures that if any honest party accepts a message from a sender, all honest parties accept the same message (consistency).

This implements echo broadcast verification as used in distributed key generation (DKG) protocols to prevent equivocation attacks where a malicious sender sends different messages to different recipients.

Attributes:

n: Number of parties in the protocol f: Byzantine fault threshold (default: (n-1)//3)

Example:
>>> broadcast = EchoBroadcast(num_parties=5)
>>> msg = broadcast.create_broadcast_message(1, {'value': 42})
>>> 'sender_id' in msg and 'hash' in msg
True
compute_message_hash(message: Any) bytes[source]

Compute hash of a message for echo comparison.

Parameters

messageAny

The message to hash. Can be bytes, dict, or any serializable type.

Returns

bytes

SHA-256 hash of the message

create_broadcast_message(party_id: int, message: Any) Dict[str, Any][source]

Create a broadcast message with its hash for echo verification.

Parameters

party_idint

The sender’s party identifier

messageAny

The message content to broadcast

Returns

dict

Broadcast message containing: - sender_id: The sender’s party ID - message: The original message content - hash: SHA-256 hash of the message

process_echo(verifier_id: int, sender_id: int, msg_hash: bytes, echo_state: Dict[int, Dict[int, bytes]] | None = None) Dict[int, Dict[int, bytes]][source]

Process an echo from another party.

Records what message hash a verifier claims to have received from a sender.

Parameters

verifier_idint

ID of the party reporting what they received

sender_idint

ID of the original sender

msg_hashbytes

Hash of the message the verifier claims to have received

echo_statedict, optional

Current echo state to update. If None, creates new state.

Returns

dict

Updated echo state: {verifier_id: {sender_id: msg_hash}}

verify_consistency(echo_msgs: Dict[int, Dict[int, bytes]]) bool[source]

Verify all parties received consistent messages from each sender.

Checks that for each sender, all verifiers report the same message hash. If any sender sent different messages to different recipients (equivocation), raises ValueError with details about the inconsistency.

Parameters

echo_msgsdict

Echo state mapping {verifier_id: {sender_id: msg_hash}}

Returns

bool

True if all messages are consistent

Raises

ValueError

If broadcast inconsistency is detected, with details about which sender sent different messages to different recipients

Example:
>>> broadcast = EchoBroadcast(num_parties=3)
>>> # All parties received same hash from sender 1
>>> echo_msgs = {1: {1: b'hash1'}, 2: {1: b'hash1'}, 3: {1: b'hash1'}}
>>> broadcast.verify_consistency(echo_msgs)
True