package
0.8.3
Repository: https://github.com/livepeer/go-livepeer.git
Documentation: pkg.go.dev

# README

Probabilistic Micropayments (PM) Client

The pm package contains a client implementation of the Livepeer probabilistic micropayment protocol. The main areas of interest are:

  • A Ticket type which defines the ticket format that both senders and recipients accept.
  • A Sender type which is responsible for creating tickets.
  • A Recipient type which is responsible for validating/receiving tickets and redeeming winning tickets using the TicketBroker interface (implemented by an Ethereum smart contract). This type will be able to translate a Ticket type into the correct format expected by the TicketBroker

In practice, the package user will need to define a communication channel (i.e. HTTP connection) and a network message format (i.e. protocol buffer) that peers will use to send and receive tickets. The sending peer will use the Sender type and the receiving peer will use the Recipient type.

High Level Flow

flow diagram

RNG

A Sender and a Recipient execute a collaborative commit-reveal protocol in order to generate the random number used to determine if a ticket won or not. The random number construction is:

keccak256(abi.encodePacked(senderSig, recipientRand))

The abi.encodePacked() Solidity built-in is used to match the behavior of the contract implementing the TicketBroker interface. senderSig is a signature produced by Sender over the hash of the ticket and recipientRand is the pre-image of the recipientRandHash that is included in the ticket.

Before a Sender can start creating and sending tickets, it must first fetch ticket parameters from a Recipient. When generating ticket parameters, a Recipient will generate a random number recipientRand, compute the hash of recipientRand as recipientRandHash and include the hash with the ticket parameters. Once a Sender has a set of ticket parameters with a recipientRandHash, the Sender will use a monontonically increasing senderNonce with each new ticket that it creates.

The following conditions are met in order to ensure that the random number generation for winning ticket selection is fair:

  • Once a Sender has a set of ticket parameters with a recipientRandHash, the Sender will use a montonically increasing senderNonce with each new ticket that it creates. The montonically increasing senderNonce will ensure that senderSig is unpredictable to the Recipient.
  • Whenever a Recipient receives a ticket that uses a particular recipientRandHash, it will update an in-memory map of already received senderNonce values for the recipientRandHash. If the Recipient ever receives a ticket with a senderNonce that is already tracked by the map OR the maximum number of senderNonce values have been received for the recipientRandHash (a Sender is expected to regularly request for a new set of ticket parameters with a new recipientRandHash which means the maximum number of senderNonce values for a recipientRandHash would typically never be reached) it will consider the ticket a replay attack where the Sender is reusing an old senderNonce
  • Whenever a Recipient redeems a winning ticket, it will wait until the ticket parameters expire (based on the ParamsExpirationBlock of the ticket parameters) to redeem the ticket. This behavior allows the Recipient to avoid tracking recipientRandHash values to prevent replays because a Sender that attempts to replay a recipientRandHash value that already is associated with a redeemed winning ticket (and thus the recipientRand pre-image was revealed on-chain) would fail the ticket parameters expiration check

Refer to the spec for more information on the specifics of the random number generation for winning ticket selection.

# Functions

No description provided by the author
NewRecipient creates an instance of a recipient with an automatically generated random secret.
NewRecipientWithSecret creates an instance of a recipient with a user provided secret.
NewSender creates a new Sender instance.
NewSenderMonitor returns a new SenderMonitor.
NewTicket creates a Ticket instance.
NewValidator returns an instance of a validator.
RandAddress returns a random ETH address.
RandBytes returns a slice of random bytes with the size specified by the caller.
RandHash returns a random keccak256 hash.

# Variables

ErrTicketParamsExpired is returned when ticket params have expired.

# Structs

DefaultSigVerifier is client-side-only implementation of sig verification, i.e.
ErrSenderValidation is returned when the sender cannot send tickets.
No description provided by the author
No description provided by the author
No description provided by the author
MockRecipient is useful for testing components that depend on pm.Recipient.
MockSender is useful for testing components that depend on pm.Sender.
ReserveInfo holds information about a sender's reserve.
SenderInfo contains information about a sender tracked by a Broker.
SignedTicket is a wrapper around a Ticket with the sender's signature over the ticket and the recipient recipientRand.
Ticket is lottery ticket payment in a probabilistic micropayment protocol The expected value of the ticket constitutes the payment and can be calculated using the ticket's face value and winning probability.
TicketBatch is a group of tickets that share the same TicketParams, TicketExpirationParams and Sender Each ticket in a batch is identified by a unique TicketSenderParams.
TicketExpirationParams indicates when/how a ticket expires.
TicketParams represents the parameters defined by a receiver that a sender must adhere to when sending tickets to receiver.
TicketParamsConfig contains config information for a recipient to determine the parameters to use for tickets.
TicketSenderParams identifies a unique ticket based on a sender's nonce and signature over a ticket hash.

# Interfaces

Broker is an interface which serves as an abstraction over an on-chain smart contract that handles the administrative tasks in a probabilistic micropayment protocol including processing deposits and pay outs.
GasPriceMonitor defines methods for monitoring gas prices.
Recipient is an interface which describes an object capable of receiving tickets.
RedeemableEmitter is an interface that describes methods for emitting redeemable tickets.
Sender enables starting multiple probabilistic micropayment sessions with multiple recipients and create tickets that adhere to each session's params and unique nonce requirements.
SenderManager defines the methods for fetching sender information.
SenderMonitor is an interface that describes methods used to monitor remote senders.
Signer supports identifying as an Ethereum account owner, by providing the Account and enabling message signing.
SigVerifier is an interface which describes an object capable of verification of ECDSA signatures produced by ETH addresses.
TicketStore is an interface which describes an object capable of persisting tickets.
TimeManager defines the methods for fetching the last initialized round and associated block hash of the Livepeer protocol.
Validator is an interface which describes an object capable of validating tickets.