DEV Community

Cover image for Smart Events (Contracts) Over Nostr: A Consensus-Based Approach
Melvin Carvalho
Melvin Carvalho

Posted on

Smart Events (Contracts) Over Nostr: A Consensus-Based Approach

Smart Events

Introduction:

In this blog post, we'll explore the concept of smart events (contracts) over Nostr, a decentralized network protocol for content sharing. We'll detail the consensus mechanism that ensures secure and reliable transaction processing and provide insights into the contracting layer of the network.


Nostr Consensus Mechanism:

The Nostr protocol employs a four-phase consensus mechanism, ensuring that only valid transactions are committed to the event chain. These phases are as follows:

  1. Proposal Phase: A validator is chosen as the proposer for the current round based on a deterministic algorithm. This algorithm considers the validator's voting power and previous round information. The proposer creates an event proposal containing transactions and broadcasts it to other validators.

  2. Prevote Phase: Validators verify the correctness of the proposed event, checking transactions and ensuring compliance with network rules. If valid, validators broadcast a signed "prevote" message for that event. If invalid or not received within a specified time limit, validators broadcast a "nil" prevote.

  3. Precommit Phase: After receiving prevotes from more than two-thirds of validators (by voting power), a validator enters the precommit phase. Validators check if the majority of prevotes are for the same event proposal. If so, they broadcast a signed "precommit" message for that event. If there is no majority or the event is not received within the time limit, validators broadcast a "nil" precommit.

  4. Commit Phase: Once a validator receives precommits for the same event proposal from more than two-thirds of validators (by voting power), it enters the commit phase. The validator commits the event to its local event chain, finalizing the consensus process for that event. The validator then moves to the next round or height and begins the process again with the proposal phase.


Contracting Layer:

Digital signatures provide a partial solution, with validators guaranteeing the proper sequencing of contractual states. As long as the dishonest validators do not exceed one-third of the total, the state shall maintain its correct order.

The state machine is capable of monitoring any contract or ledger state. It is crucial to select a federation of esteemed Nostr users, ensuring they are not Sybil attackers. A DynaFed approach could be employed, allowing a supermajority to vote out malicious nodes or those with low uptime, and replacing them with nodes of higher reputation.

Initially, the system is expected to operate in a testnet mode, wherein tokens should not be regarded as possessing tangible value. This allows for thorough evaluation and refinement of the network before transitioning to a mainnet environment, ensuring the stability and security of the system.


Conclusion:

Smart events (contracts) over Nostr provide a promising approach to decentralized content sharing and transaction processing. By utilizing a consensus-based mechanism and carefully designed contracting layer, the Nostr protocol can create a secure, reliable, and efficient platform for a variety of applications.

Top comments (0)