Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CHIP-0041: Streaming Puzzle #142

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions CHIPs/chip-0041.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
CHIP Number | 0041
:-------------|:----
Title | Streaming Puzzle
Description | A puzzle that allows continuous payments to a receiver over a fixed time period. The stream may be stopped early by a clawback puzzle.
Authors | [yakuhito](https://github.com/yakuhito), [Michael Taylor](https://github.com/MichaelTaylor3D)
Editor | [Dan Perry](https://github.com/danieljperry)
Comments-URI | [CHIPs repo, PR #142](https://github.com/Chia-Network/chips/pull/142)
Status | Review
Category | Informational
Sub-Category | Chialisp
Created | 2025-02-03
Requires | -
Replaces | -
Superseded-By | -

## Abstract
This CHIP proposes a new puzzle for continuously streaming XCH or CATs to a receiver over a fixed time period. The sender creates a streaming coin holding the total amount to be transferred. As time passes, the receiver’s claimable portion increases proportionally. The receiver may spend the coin to claim their accrued share at any point, causing the puzzle to create a new streaming coin with the remainder. A designated clawback puzzle may stop the stream at any time. In that case, the receiver still obtains their accrued amount, but a new streaming coin is not generated.

## Motivation
Many blockchain protocols use vesting schedules to distribute tokens to investors. This proposal simplifies that process by leveraging the coinset model for fine-grained, continuous payments without requiring multiple delayed transactions. The included clawback mechanism expands possible use cases, such as enabling DAOs to reward contributors with an option to halt payments early if needed. This arrangement ensures that the recipient retains all accrued funds up to the clawback time.

## Backwards Compatibility
This proposal is fully backwards compatible. The streaming coin pays out to the recipient puzzle hash in a manner that current wallets can recognize. Specifically, it uses a standard payout output condition (i.e., `CREATE_COIN` with the receiver’s puzzle hash as the hint), ensuring that existing wallet software will properly detect incoming CAT or XCH coins.

## Rationale
The receiver and clawback initiator are considered to be custody puzzles (e.g., `p2_delegated_puzzle_or_hidden_puzzle`), and are set when the streaming coin is first created. Usually, the streaming coin creator will use one of their addresses as the clawback puzzle, allowing them to stop streaming funds in the future. Alternatively, the clawback puzzle can be set to `()`, effectively disabling the clawback functionality of the streaming coin and creating a 'permanent commitment' stream. Both puzzles are required to send a message to spend the coin. The claimed/clawed back funds are also created with these puzzle hashes.

When designing the puzzle, our main considerations were:
- **Minimize Required On-Chain Transactions**: The puzzle design requires fewer on-chain transactions than repeated partial payments, allowing payouts in the smallest possible increments without manually creating multiple outputs. This offers greater flexibility and more granularity over the next best option, which requires creating multiple delayed clawback transactions.
- **Controlled Access**: Only the receiver and the clawback puzzle may spend the streaming coin. This restricts potential spam payout transactions triggered by third parties while granting the receiver freedom to choose timing for claims (e.g., for tax considerations).
- **Clawback Option**: Giving the sender the ability to stop the stream increases puzzle complexity but substantially expands the puzzle’s utility in scenarios such as DAO-based contributor grants, where early termination may be necessary. The puzzle ensures that accrued funds are released to the receiver even when the stream is stopped.

## Specification
The streaming puzzle can be found [here](https://github.com/Yakuhito/streaming/blob/master/puzzles/stream.clsp).

The streaming identifier is defined as the coin name of the initial streaming coin. This identifier is a bech32m-encoded string with the prefix `stream` (for mainnet) or `tstream` (for testnet). For example, a valid testnet stream ID might be:

```
tstream1yxruadr5c02n37sn392ejrvczsyfrmjv7m0ynjpgkrhhzym66n5qez4qck
```

During creation of the first streaming coin, the following information must be provided via memos:
- Recipient puzzle hash
- Clawback puzzle hash
- Start timestamp
- End timestamp

Wallets or other software analyzing the chain can parse these memos from the eve streaming coin’s creation and verify that they match the puzzle hash included in the associated `CREATE_COIN` condition. This allows driver code to be able to spend the first streaming coin.


## Test Cases
A series of tests verifying partial claims and clawbacks is provided in the reference implementation.

## Reference Implementation
The reference implementation can be found [here](https://github.com/Yakuhito/streaming/tree/master). It includes:
- Puzzle and driver code
- Tests
- A CLI tool for viewing and interacting with streaming CATs through the Sage RPC

## Security
Aside from puzzle risk, senders and receivers should keep in mind that Chia network fees fluctuate. It might become expensive to interact with the streaming coin. The puzzle has been optimized to reduce transaction size and fees, typically costing less than comparable operations like NFT transfers.

## Copyright
Copyright and rights to this CHIP waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).