Skip to content

Instantly share code, notes, and snippets.

@RobinLinus
Last active April 15, 2023 12:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobinLinus/2ef150e0fa660ac5f8617a1db9701750 to your computer and use it in GitHub Desktop.
Save RobinLinus/2ef150e0fa660ac5f8617a1db9701750 to your computer and use it in GitHub Desktop.
Decentralized File Hosting on Lightning

Sats4Files [Simplified]

The client wants to buy from the server the file corresponding to a particular file_id. The following is a very basic scheme solving the problem in a naive way.

  • The file gets chunked into 32-byte chunks. They are hashed into a Merkle root, which is the file_id.
  • The client buys from the server one Merkle branch after another via Lightning payments. The payment's preimage is the Merkle leaf.

Limitations and Optimizations

  • Sending 32 MB requires 1 million Lightning transactions. That means equally many signatures.
  • All hops have to store all preimages. Lighting upgrades using sighash_anyprevout like Eltoo or Daric can reduce the storage complexity from O(n) to O(1). On today's Bitcoin, Decker-Wattenhofer payment channels would allow to reduce the storage complexity by resetting it periodically (but only a limited number of times).
  • In Lighting, a preimage can be used only once safely. So a server can send a file only once. This can be solved by using PTLCs and reblinding instead of HTLCs. So the leaves of the file_id become curve points instead of hashes. Here's the advantage that the intermediate hops learn nothing about the file.

See also this solution and this optimized solution.

@ColbySerpa
Copy link

PayPub —> ZKCP —> ZKCSP —> Sats4Files⛈️ Simplified.

I do wonder what services the “s” in ZKCSP can provide beyond trading coins for files. Maybe some useful applications to explore later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment