Skip to content

Add BIP0322 Proof of Funds to RegisterInputsForNextRoundRequest #485

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: next-version
Choose a base branch
from

Conversation

louisinger
Copy link
Collaborator

@louisinger louisinger commented Feb 26, 2025

update: #485 (comment)

This PR deletes the nostr notifications system and replace it by a simple GetNote API. OwnershipProof is also replaced by BIP0322 "Proof of Funds".

GetNote

GetNote RPC expects bip322_signature and the associated message. If the signature is valid, the server returns a note where amount = sum of bip322_signature outpoints. The server also mark the VTXOs as spent in DB to prevent cheating.

BIP0322 Proof of funds

common.bip322 package is standalone and follows the BIP0322 specifications ⚠️ except that it doesn't verify the inputs sequence in order to allow the proof to be used for offchain outpoints.

The message must be the current Unix timestamp. It is considered valid by the server if and only if it is close to current timestamp.

CLI and SDK

sdk.RecoverSweptVtxos or ark recover CLI command automatically fetch swept and unspent VTXOs, create a BIP0322 signature, fetch the associated note and redeem it.

it closes #484
it closes #483

@altafan @Kukks please review

@louisinger louisinger requested a review from altafan February 26, 2025 14:01
@louisinger louisinger changed the title Swept vtxos recovering: replace nostr notifications by GetNote RPC Swept vtxos recovery : replace nostr notifications by GetNote RPC Feb 26, 2025
@Kukks
Copy link
Contributor

Kukks commented Feb 27, 2025

Couldn't one simply use the VTXO ownership proof in itself as a note? The api to exchange a proof for a vtxo is redundant:

This flow:

  • VTXO expires/gets swept
  • Wallet goes online, detected expired vtxo
  • Wallet creates proof, send to GetNote
  • Server returns note
  • Wallet redeems note for new VTXO

Proposed flow:

  • VTXO expires/gets swept
  • Wallet goes online, detected expired vtxo
  • Wallet creates proof and registers it as input for next batch

@louisinger
Copy link
Collaborator Author

louisinger commented Feb 27, 2025

Proposed flow:

  • VTXO expires/gets swept
  • Wallet goes online, detected expired vtxo
  • Wallet creates proof and registers it as input for next batch

I agree, but if we do that, we should be able to register also the not expired VTXOs in the same proof no ? If I have 1 VTXO not swept + 1 expired VTXO, I create a proof containing both outpoints and use it as input ?

something like:

message RegisterInputsForNextRoundRequest {
  repeated TaprootTree revealed_taproot_tree = 1; // reveal tapscripts of unspent & not expired vtxos
  repeated string notes = 2;
  string bip322_signature = 3; // proof of funds for "inputs" array + swept vtxos you want to recover
}

@louisinger
Copy link
Collaborator Author

louisinger commented Feb 28, 2025

According to the latest discussion, I've removed the GetNote RPC and reworked the inputs' registration flow:

message RegisterInputsForNextRoundRequest {
  map<string, Tapscripts> tapscripts = 1; 
  Bip322Signature bip322_signature = 2;
  repeated string notes = 3;
}

To register inputs, users must provide a valid BIP322 signature signing a timestamp message. The server accepts the signature if now - timestamp < 15 seconds.

The BIP322 proof of funds tx may include:

  • boarding UTXOs
  • unspent VTXOs
  • recoverable VTXOs (expired but unspent)

map<string, Tapscripts> tapscripts = 1; field should contain the revealed tapscripts for boarding and unspent VTXOs.

@louisinger louisinger changed the title Swept vtxos recovery : replace nostr notifications by GetNote RPC Add BIP0322 Proof of Funds to RegisterInputsForNextRoundRequest Feb 28, 2025
@louisinger louisinger requested a review from altafan February 28, 2025 15:38
@altafan altafan changed the base branch from master to next-version April 8, 2025 09:45
@bordalix
Copy link
Collaborator

To register inputs, users must provide a valid BIP322 signature signing a timestamp message. The server accepts the signature if now - timestamp < 15 seconds.

Fragile:

  1. It should be abs(now - timestamp) < 15 seconds
  2. What are the limitations for this period?
  3. Why only 15 seconds?

@louisinger
Copy link
Collaborator Author

louisinger commented Apr 17, 2025

  1. It should be abs(now - timestamp) < 15 seconds

not clear why ? timestamp should always be smaller than "now". I mean timestamp in the future should always be rejected by the server.

  1. What are the limitations for this period?
  2. Why only 15 seconds?

It can be anything, the idea was to set a small enough delta so the proof can't be reused if intercepted. In fact maybe this delta should be the signer's choice / cc @Kukks ?

@louisinger louisinger marked this pull request as draft April 18, 2025 07:51
@louisinger
Copy link
Collaborator Author

Converted to draft, I need to update the BIP322 proof with :

  • allow outputs to be specified in the proof tx
  • convert to PSBT
  • specify taprootTree in the proof
  • specify onchain output in the proof

@Kukks
Copy link
Contributor

Kukks commented Apr 18, 2025

Converted to draft, I need to update the BIP322 proof with :

  • allow outputs to be specified in the proof tx
  • convert to PSBT
  • specify taprootTree in the proof
  • specify onchain output in the proof

After chat, we will not use psbt after all and stay compatible with BIP322. We will insert the data as a json inside the challenge message, something like

{
 "onchainOutputs": [0, 3...], (indexes)
 "inputTapTrees": [hex_encoded_tree, ...]
 (optional) "createdAt": timestamp
 (optional) "expiry": timestamp

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.

Notes simplification BIP322 as ownership proof
4 participants