Skip to content

Conversation

louisinger
Copy link
Collaborator

This PR adds sharedtaproot.go file into sdk package, greatly inspired by https://github.com/louisinger/shared-utxo

SharedTaprootScript struct lets to create a shared output script thanks to introspection opcodes OP_INSPECTOUTPUTSCRIPTPUBKEY & OP_INSPECTOUTPUTVALUE enforcing a "remaining" output to be set while exiting the shared output.

The struct has two exported functions:

  • Requirements is useful to spend the shared output: describe the expected change.
  • NextSharedTaprootScript lets to compute the new SharedTaprootScript struct from a spent one.

@tiero @altafan please review this

@tiero
Copy link
Member

tiero commented Nov 2, 2023

no need to have an SDK now imho, best to have a common package

@louisinger louisinger self-assigned this Nov 4, 2023
@louisinger
Copy link
Collaborator Author

louisinger commented Nov 4, 2023

here is a table comparing the two methods. It may miss some points cc/ @tiero @altafan

shared taproot tree  psbt binary tree
unilateral exit 1 tx to redeem. a "dynamic" taproot tree branch: must be recomputed each time an user is exiting the pool a constant branch of the binary tree, a set of psbt to broadcast. CPFP for fees
forfeit transaction Must be a message signed by both user and ASP using CSFS because the redeem tx is unknown spend the constant redeem tx, signed by ASP and the user
send VTXO / collaborative exit CSFS + introspections lets to sign 1 unique message  sign x forfeit transactions where x is the number of VTXO created by the pool
number of leaves due to the algorithm complexity without any optimizations (n!) it may limit the number of VTXOs in the pool (~30 ?) the number of psbt to broadcast may limit the number of VTXOs due to the amount of fees to pay to broadcast a big branch

@louisinger louisinger removed their assignment Nov 4, 2023
@altafan
Copy link
Collaborator

altafan commented Nov 6, 2023

no need to have an SDK now imho, best to have a common package

@tiero we will change the name of the package.

Based on louis' table, can you share your opinion on whether we should use this kind of shared utxo? If you have other suggestions on how to "mock" this specific component of the Ark protocol please share them here.

This is my resume on what we can/can't see by using this kind of shared outuput instead of the "binary tree" one defined in the spec:

  • we can see the same kind of interactivity between user and ASP when the former wants to spend his coins
  • we can see how the registration/finalization of the inputs and outputs works (there are no differences between the 2 versions)
  • we can't see the real computation effort made by the ASP when creating the shared output. The job of the ASP would be simplified in louis' proposed version (no binary tree of pre-signed txs created but just a single covenant)
  • the unilateral exit path is completely different, but we shouldn't really care since we're not interested in this feature of the protocol for the PoC

In conclusion, I think that using this kind of shared utxo would allow us to explore most of the aspects of the ASP's real duty but the effort it makes to compute and sign the binary tree of pre-signed txs.

IMO it could be a decent trade off for the PoC, I'd like to know yours.

@tiero
Copy link
Member

tiero commented Nov 6, 2023

1 tx to redeem. a "dynamic" taproot tree branch: must be recomputed each time an user is exiting the pool

How can this process be trustless then? also it requires a signature from everybody everytime there is an exit. Seem same issue CoinPool and other proposals have compared to Ark

@tiero
Copy link
Member

tiero commented Nov 6, 2023

allow us to explore most of the aspects

But not the PSBT binary tree construction, management tho?

@louisinger
Copy link
Collaborator Author

1 tx to redeem. a "dynamic" taproot tree branch: must be recomputed each time an user is exiting the pool

How can this process be trustless then?

It is trustless, the user has to "remove" the spent leaf to recompute the new tree, so it can be derived from the initial taproot tree. However, he needs to know the amounts of the pool VTXOS to compute the right "new" change output. Those data (leaf hashes + stakeholders amounts) would be shared while the VTXO is created.

also it requires a signature from everybody everytime there is an exit. Seem same issue CoinPool and other proposals have compared to Ark

Only the user exiting has to sign the leaf he owns, other pool guys are not involved here.

@altafan
Copy link
Collaborator

altafan commented Nov 6, 2023

Instead of trying to find a way to implement the shared output and make offchain payments effective, let's completely fake it by still doing the job that a real ASP is supposed to do:

Since we're not interested in providing the unilateral exit feature, the onchain outcome of a round can be a simple pool tx with ASP inputs, and 2 outputs mocking the shared and the connector output. They would be simple singlesig outputs owned by the ASP.
Under the hood, the ASP still does the job of creating the tree of txs so they still receive their vTXOs that they can spend. Internally, the ASP makes an association between a mocked shared output and a tree of txs.
The outputs of the txs of the tree don't need to be locked by any complex covenant like the "real version", we could use simple singlesig for the outputs of the intermediate txs, and (A+ASP) || (ASP in 4 weeks) for the outputs of the leaves txs (vTXOs) .

Basically we would simplify all implementational details, but sill have the same operations done by the ASP and also the users.

@altafan altafan closed this Nov 7, 2023
@altafan altafan deleted the covenant branch December 4, 2023 16:02
@altafan altafan restored the covenant branch December 4, 2023 16:02
@altafan altafan deleted the covenant branch December 4, 2023 16:02
altafan referenced this pull request in altafan/ark Jun 19, 2024
Fix sqlite repo config & Payment<>Round relation
altafan referenced this pull request in altafan/ark Jul 17, 2024
Fix returning forfeit txs in round event
altafan added a commit that referenced this pull request Oct 4, 2024
* RPC GetPaymentsStream

This introduces a new feature to the ArkService API that allows clients to subscribe to payment events. Here's a breakdown of the changes:

1. **OpenAPI Specification (`service.swagger.json`):**
   - A new endpoint `/v1/payments` is added to the API, supporting a `GET` operation for streaming payment events.
   - New definitions `v1GetPaymentsStreamResponse`, `v1RoundPayment`, and `v1AsyncPayment` are added to describe the structure of the streaming responses.

2. **Protobuf Definition (`service.proto`):**
   - Added a new RPC method `GetPaymentsStream` that streams `GetPaymentsStreamResponse` messages.
   - Defined new message types: `GetPaymentsStreamRequest`, `GetPaymentsStreamResponse`, `RoundPayment`, and `AsyncPayment`.

3. **Generated Protobuf Code (`service.pb.go`, `service.pb.gw.go`, `service_grpc.pb.go`):**
   - The generated code is updated to include the new RPC method and message types.
   - The gateway code includes functions to handle HTTP requests and responses for the new streaming endpoint.

4. **Application Logic (`covenant.go`, `covenantless.go`):**
   - New payment events channels are introduced (`paymentEventsCh`).
   - Payment events are propagated to these channels when a round is finalized or an async payment is completed.
   - New event types `RoundPaymentEvent` and `AsyncPaymentEvent` are defined, implementing a `PaymentEvent` interface.

5. **gRPC Handlers (`arkservice.go`):**
   - Added logic to handle `GetPaymentsStream` requests and manage payment listeners.
   - A new goroutine is started to listen to payment events and forward them to active listeners.

Overall, this patch extends the ArkService to support real-time streaming of payment events, allowing clients to receive updates on both round payments and async payments as they occur.

* Move emit events in updateVtxoSet & Use generics and parsers (#1)

* Move sending event to updateVtxoSet

* Use generics and parsers

* pr review refactor

* pr review refactor

* fix

---------

Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
altafan added a commit that referenced this pull request Mar 27, 2025
* SDK - refresh tx db

* pr review

* pr review

* pr review

* Fixes (#1)

* Polish refresh db logic

* Tidy up

---------

Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants