hashgraph / hedera-services

Crypto, token, consensus, file, and smart contract services for the Hedera public ledger
Apache License 2.0
271 stars 121 forks source link

TSS-Block-Signing Proposal: Define the Services / Platform API #13776

Open poulok opened 2 months ago

poulok commented 2 months ago

Scope and content of the TSS Block Signing Proposal:

This ticket is done when the services / platform API for the application to request a message be signed with TSS and the platform to provide the signed message (or an error) is agreed upon and documented. This includes getting approval from services and the architecture team.

edward-swirldslabs commented 1 month ago

Pseudo code for Signing Manager:

#### TSS Signing Manager

The TSS Signing Manager is responsible for computing a node's private shares from the TSS Messages and for
generating ledger signatures by submitting a node's share signature to be gossiped to the rest of the network and
accumulating a threshold number of share signatures to recover the ledger signatures. Each recovered ledger
signature is published to interested parties through the `PlatformPublisher`.

Public API:

1. State API: void sign(byte[] message) throws NotReadyException
2. `PlatformPublisher` provides a consumer for ledger signatures

Internal Elements:

1. Map<RosterHash, Roster> rosters
2. Map<RosterHash, List<TssMessage>> tssMessages
3. Map<RosterHash, Pair<List<Private Share Keys>, List<Public Share Keys>>> shares
4. Map<MessageHash, RosterHash> messageRosterMap
5. Map<MessageHash, List<PairingSignature>> messageSignatures
6. activeRosterHash
7. current round

Inputs:

1. Rosters in state (Constructor)
2. TssMessages in state (Constructor)
3. Active Roster (Constructor)
4. Share Signatures in state (Constructor)
5. TssShareSignature (Wire)
6. message (Wire)
7. EventWindow (Wire)

Input Invariants:

1. TssShareSignature received must be for previous signMessage(byte[] message) calls.

`On Message`:

1. Use the private shares of the active roster to create TssShareSignatures from the node and gossip them out.
2. Construct an empy list of PairingSignatures for the message.

`On TssShareSignature`:

1. get the hash of the message the signature is for.
2. get the roster that signed the message.
3. validate the share signature
4. Add the signature to the collection for the message.
5. If a threshold number have been collected, compute the ledger signature and publish it on the output wire.

`On EventWindow`:

1. Update the current round.
2. cleanup the message signatures for any collections that are older than the configured number of rounds.