nutshell icon indicating copy to clipboard operation
nutshell copied to clipboard

Discreet Log Contracts

Open cloudsupper opened this issue 1 year ago • 17 comments

Implementing @conduition 's awesome proposal (https://github.com/cashubtc/nuts/pull/128) for discrete log contract execution on chaumian ecash mints.

cloudsupper avatar Jul 10 '24 12:07 cloudsupper

Codecov Report

Attention: Patch coverage is 83.28691% with 120 lines in your changes missing coverage. Please review.

Project coverage is 59.31%. Comparing base (8675745) to head (d561dbe). Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
cashu/mint/verification.py 69.46% 40 Missing :warning:
cashu/mint/router.py 0.00% 21 Missing :warning:
cashu/mint/db/write.py 84.88% 13 Missing :warning:
cashu/mint/conditions.py 78.72% 10 Missing :warning:
cashu/core/errors.py 81.81% 6 Missing :warning:
cashu/mint/ledger.py 90.62% 6 Missing :warning:
cashu/wallet/cli/cli.py 73.68% 5 Missing :warning:
cashu/core/base.py 94.52% 4 Missing :warning:
cashu/core/crypto/dlc.py 93.61% 3 Missing :warning:
cashu/mint/crud.py 85.71% 3 Missing :warning:
... and 5 more

:exclamation: There is a different number of reports uploaded between BASE (8675745) and HEAD (d561dbe). Click for more details.

HEAD has 5 uploads less than BASE
Flag BASE (8675745) HEAD (d561dbe)
9 4
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #576      +/-   ##
==========================================
- Coverage   69.02%   59.31%   -9.71%     
==========================================
  Files          92      101       +9     
  Lines        8674    11082    +2408     
==========================================
+ Hits         5987     6573     +586     
- Misses       2687     4509    +1822     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 10 '24 20:07 codecov[bot]

So now basically i wanted to add to the wallet the possibility of minting/swapping-for DLC locked proofs. It would basically work like this:

cashu invoice <amount> --dlc-lock <dlc_root_hash> <-- mints dlc-locked proofs cashu selfpay <amount> --dlc-lock <dlc_root_hash> <-- swap current proofs for dlc-locked proofs cashu selfpay <amount> --dlc-unlock <dlc_root_hash> <-- swaps dlc-locked proofs for normal ones (using the backup secret) cashu fund <dlc_root_hash> <-- generates a token with the proofs locked to dlc_root_hash.

Naturally this would imply a slight change in the DB table that holds the Proofs in order to accomodate dlc_root_hash and backup_secret where present

cloudsupper avatar Jul 11 '24 16:07 cloudsupper

And of course I am going to add tests for all of this.

cloudsupper avatar Jul 11 '24 16:07 cloudsupper

Is there any discussion which needs to happen to validate the spec itself before we push ahead with this implementation?

I suppose so. But I thought I would get started in the meantime. I believe in order to get it merged you'll have to give specific names the new type of requests/responses you're introducing (e.g. PostDlcRegistrationRequest, PostDlcPayoutRequest)

cloudsupper avatar Jul 11 '24 18:07 cloudsupper

By the way congrats on the proposal, it's very well written.

cloudsupper avatar Jul 11 '24 18:07 cloudsupper

So now one should be able to use:

  • cashu send --dlc-root <root_hash> --threshold <funding_threshold> to get a token with dlc locked proofs
  • cashu selfpay --dlc-unlock and cashu selfpay --dlc-unlock --dlc-root <root_hash> to swap out exposed dlc locked proofs (supposedly because the registration is taking too long)

cloudsupper avatar Jul 17 '24 17:07 cloudsupper

@lollerfirst Thank you massively for putting so much effort into this. I can see this PR is still in draft state, and you're on a roll, so i'll try not to interrupt. I'm passively reviewing and will throw in the occasional high-level suggestion where the spec is concerned but I'm not doing any detailed auditing yet. Once you feel ready for a full review, i'll be glad to help :smile: I'm also decent with Python if you need backup :wink:

conduition avatar Jul 19 '24 06:07 conduition

If you want to help with the code you're more than welcome to.

cloudsupper avatar Jul 19 '24 07:07 cloudsupper

I just submitted a small refactor request here: https://github.com/lollerfirst/nutshell/pull/1

conduition avatar Jul 29 '24 18:07 conduition

Registration working. More specific tests needed. (Mixed proofs, p2pk proofs, try invalid registration amongst a valid batch, try invalid proofs, try threshold not respected)

cloudsupper avatar Jul 31 '24 11:07 cloudsupper

@lollerfirst I updated https://github.com/cashubtc/nuts/pull/128: https://github.com/cashubtc/nuts/pull/128#issuecomment-2267627657

conduition avatar Aug 04 '24 18:08 conduition

I pushed a few PRs up with some suggested fixes:

  • https://github.com/lollerfirst/nutshell/pull/2
  • https://github.com/lollerfirst/nutshell/pull/3
  • https://github.com/lollerfirst/nutshell/pull/4

conduition avatar Aug 23 '24 06:08 conduition

working on a wallet implementation. the router was a bit broken, opened a PR to fix it

  • #https://github.com/lollerfirst/nutshell/pull/5

gudnuf avatar Sep 13 '24 17:09 gudnuf

@gudnuf Thank you! I haven't tested the router well. The tests I wrote check the functionality but do not go through the router.

Right now the only thing missing from the mint side is POST /v1/dlc/payout.

It's great you're working on a wallet implementation! Since the beginning I thought that the DLC orchestration between clients should be a separate thing from this.

cloudsupper avatar Sep 13 '24 19:09 cloudsupper

Right now the only thing missing from the mint side is POST /v1/dlc/payout.

Looks like that's already implemented, no?

Since the beginning I thought that the DLC orchestration between clients should be a separate thing from this.

I'm working on this to help me learn rust, so forking it into cdk-cli. It will use NIP88 for the DLC orchestration between wallets

gudnuf avatar Sep 15 '24 05:09 gudnuf

Right now the only thing missing from the mint side is POST /v1/dlc/payout.

Looks like that's already implemented, no?

Since the beginning I thought that the DLC orchestration between clients should be a separate thing from this.

I'm working on this to help me learn rust, so forking it into cdk-cli. It will use NIP88 for the DLC orchestration between wallets

Yea I implemented it yesterday.

Nice! Will read about NIP-88.

Not everything here is properly commented and named, so if you have any issue let me know.

cloudsupper avatar Sep 15 '24 06:09 cloudsupper

Test failing randomly I don't think it's related to this PR.

cloudsupper avatar Oct 30 '24 16:10 cloudsupper