Skip to content
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

Milestone 1 #1

Merged
merged 2 commits into from
Nov 22, 2021
Merged

Milestone 1 #1

merged 2 commits into from
Nov 22, 2021

Conversation

scilio
Copy link
Collaborator

@scilio scilio commented Nov 13, 2021

Contains all changes for milestone 1 of https://forum.grin.mw/t/request-for-funding-scilio-coinswap-implementation/9149?u=scilio

Fee will be included in payload as part of milestone 2.

Copy link
Member

@yeastplume yeastplume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caveat: I haven't spent tons of time considering the coinswap proposal and its development.

From an engineering perspective, this all looks like a good start to me and appears to cover phase 1 of the development plan as proposed in the original thread. It appears to present the API as derived in the thread and everything thus far demonstrates a solid understanding of the requirements and how to go about developing them (and we don't need to remind you to write tests covering everything) so glad to have you around @scilio!

This project is in its infancy here, and I'm an advocate of not putting up a load of premature hurdles to early development, based on what I've seen so far I'd be comfortable providing scilio with write access to this repo and letting him run with it for the time being (while trying to keep everything in PRs for review purposes). It will be easier to keep up with changes that way than trying to do a mega-review on all of the proposed phase 2 work, and I wouldn't want progress slowed down waiting for formal reviews on every single change just yet.

I just have one comment for now about some apparently redundant code (there may have been a reason for it,) and I'll let @tromp evaluate the API for the time being, but I'll get into more detailed reviews as we progress. It looks as if the real meat is going to come in the next phase, and I look forward to starting to test-run a few instance of this as the project progresses!

src/ser.rs Show resolved Hide resolved
Copy link
Member

@phyro phyro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great start. I've only left a few small notes rather than requests for a change.
I'm a bit weak on the cryptographic side, but I'll try to grasp the implementation concepts better as the projects goes to the next milestones. Thanks for bringing this to life!

src/server.rs Show resolved Hide resolved
Ok(())
}

// milestone 2 - add tests to cover invalid comsig's & inputs not in utxo set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another one we'll eventually want to add is to check that we accept only 1 swap for a given input - this way we close the attack vector when someone creates two swaps for the same input commitment. Similarly, the last node will want to check that no two swaps create the same output commitment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple occurrences of the same input or output indicates either malice, a malfunctioning wallet, or multiple wallets sharing the same seed (which can be considered a form of malfunctioning too). In this case we can either drop all but one of the spends, or drop all of them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for dropping all of them. This way we can see the malfunctioning frequency faster because honest users will complain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wallets sharing the same seed is probably too common for us to just drop all duplicate inputs. We should decide between the earliest submission or the most recent one.

Duplicate outputs does seem more like a form of maliciousness or wallet malfunction. For that, it may be better to drop both. node n wouldn't know which one was submitted first anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you keep one of two inputs sent from two seed-sharing wallets, then the wallet whose input you dropped will malfunction anyway when its input moves in a way it doesn't understand. So I'm inclined to agree with phyro, that it's better to drop all.

Copy link
Member

@yeastplume yeastplume Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When wallets restore from a seed they have no way of knowing what the last used derivation index was (they can guess from the last output belonging to it, but it's obviously not 100%), so non-malicious duplicate outputs can occur with non-zero frequency. The wallet stores an output's MMR position (once the output is found on-chain) to disambiguate it internally in this instance. It might be possible to make MMR position an optional field here, so duplicate outputs can be dropped if they're the same and neither has an MMR position, of if they both have the same MMR position. If only one provides an MMR pos it is preferred and other dropped. (note, I need to check whether wallet stores mmr position or insertion index, I think it's position)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what scenario do you envision in which a user is hampered by duplicate invalidation?
does it involve a user mixing within one day both before and after restore?
btw, i'd rather not complicate the protocol with optional fields.

Copy link
Member

@phyro phyro Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose we have n wallets sharing the same seed w1..wn. Only one wallet will create the output, so perhaps we could say that if the output was created with wi, then it's up to wi to create the coinswap. A wallet can know whether it created an output or not unless there has been a restore, but if a restore was done, you can just create a coinswap after 25 hours or so.

}
}

/// Serializes a ComSignature to and from hex
Copy link
Member

@phyro phyro Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if really needed, but when the comsig is implemented, we could write a simple test that asserts the validity of the signature is preserved e.g. is_valid(deser(ser(sig)), pubkey, msg) still holds.

**jsonrpc:** `2.0`
**method:** `swap`
**params:**
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do these params relate to the data provisioning below? I don't understand why there is a proof of ownership but no rangeproof. And what is data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data refers to the array of encrypted payloads Pi...Pn. Maybe payloads would be a better name.

Copy link
Collaborator

@tromp tromp Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had concluded that data was too short (at a mere 34 bytes) to contain a rangeproof:-(
The other fields seem to have realistic lengths.
But I agree, payloads is more descriptive.
What is the role of msg?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I should've included a rangeproof in the payload. I will change to payloads and replace this example with a real one for 3 nodes. We'll see 2 of these small payloads followed by a larger one with the rangeproof included.

I wasn't sure what message should be signed for the ComSig, so I just added a msg field. I guess the Onion field could be signed instead. Thoughts?

Copy link
Collaborator

@tromp tromp Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with signing with the onion field as message.

/// When asked to read too much data
#[fail(display = "TooLargeReadErr")]
TooLargeReadErr,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should perhaps be something like a DuplicateInput and DuplicateOutput error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll include those errors when I write the duplicate checking logic in milestone 2

Copy link
Collaborator

@tromp tromp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far; I've made some minor comments regarding swap API params, duplicate inputs/outputs, and representing mixnode indices.

Copy link
Member

@j01tz j01tz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems to implement the basics as described in the first milestone. Beyond that, I don't have much to add that hasn't already been brought up in these comments.

I do have some comments about the specification itself but will keep them in the forum thread.

It's nice to have you here @scilio, looking forward to seeing your next work.

@phyro phyro merged commit 0ac1886 into mimblewimble:main Nov 22, 2021
@phyro
Copy link
Member

phyro commented Nov 22, 2021

I've opened an issue #2 to track the minor leftovers from this discussion so we don't forget them in milestone 2.

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.

5 participants