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

Numeric Outcome DLCs #110

Merged
merged 19 commits into from Feb 5, 2021
Merged

Conversation

nkohen
Copy link
Contributor

@nkohen nkohen commented Oct 28, 2020

This introduces a new document which specifies how to construct and execute DLCs based on (multi-nonce) numeric outcomes.

This includes CET compression optimizations as well as an implementation of general payout curve support, which are combined to describe a (nearly) deterministic CET computation algorithm which is approximately minimal. (I am open to splitting this up into many files if people want).

Remaining TODOs:

  • Add support for signed numeric outcomes (I'm currently leaning towards just running the algorithm on positive and negative numbers separately).
  • Add integration with other spec files (specifically introducing a new contract info version and integrating precision ranges into the accept message somehow).
  • Pretty explanatory diagrams and pictures
  • Add explicit numbers around how much better base 2 is than any other base (specifically 10) in every way and make a recommendation in the spec that oracles support base 2 signing

And lastly I intend to create test vectors as I have almost all of this implemented in a branch on bitcoin-s but these tests shouldn't block this PR being discussed and merged as they will be added in a subsequent PR.

Fixes #65

@nkohen nkohen added this to the v0.1 milestone Oct 28, 2020
@nkohen nkohen added this to In progress in v0.1 Oct 28, 2020
Copy link
Contributor

@benthecarman benthecarman left a comment

Choose a reason for hiding this comment

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

Some initial review

NumericOutcome.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
Lastly, if both grouping optimizations can be made, `w = 0` and `W = B-1` then a **total optimization** can be made and the
whole range can be represented using only a single CET corresponding to `(prefix)____`.

### Algorithms
Copy link
Contributor

Choose a reason for hiding this comment

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

The functions in these should probably be written in a more universal language like python or just psdueo code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Curious to see what people who code in non-scala think about the readability, please leave comments here!

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @benthecarman. Tbh it's fine by me since I got a little bit used to read Scala by now, but it definitely adds to the complexity of something that is already not that easy. I think Python would probably be better. I'm not sure for pseudo code, personally I often find it harder to read than actual code. Also still good to link to your implementation.

Copy link

Choose a reason for hiding this comment

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

As C# guy I can understand the code, we have very similar constructs.
But I think if Scala is chosen, at the very least it should not use fancy constructions.

NumericOutcome.md Outdated Show resolved Hide resolved
@NicolasDorier
Copy link

NicolasDorier commented Oct 29, 2020

I must say I have a hard time understanding it from the Example part, but this is probably not your fault, I am bad at understanding when things are too abstract.

I would suggest, instead of using abstraction, just assuming B=10 and take a real, concrete example of range.
Or maybe as a more "concrete example" new part.

generated in both the front and back groupings of length at most `B-1 ` which corresponds to the coefficient in the order bound.
This counting shows us that base 2 is the optimal base to be using in general cases as it will outperform all larger bases
in both large and small ranges in general.

Copy link
Contributor

Choose a reason for hiding this comment

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

The number of CETs can be further reduced by selecting (B^ n-1) or (B ^ n) for start and end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So while this is true, I'm not sure that it is particularly practical?

Copy link
Contributor

@Ichiro0219 Ichiro0219 Nov 4, 2020

Choose a reason for hiding this comment

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

This idea is valid in both decimal and binary numbers, so I think it is practical. As a more practical description, it may be better to add the description like below to the #optimizations chapter.

Choosing a value closer to (B ^ n) for start and end will reduce the number of CETs.

@nkohen
Copy link
Contributor Author

nkohen commented Oct 29, 2020

I would suggest, instead of using abstraction, just assuming B=10 and take a real, concrete example of range.
Or maybe as a more "concrete example" new part.

Great idea, I've added a concrete example before the general abstract one

Copy link
Member

@Tibo-lg Tibo-lg left a comment

Choose a reason for hiding this comment

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

Overall looks great! Maybe just need to be made a bit easier to read.

Comment on lines 10 to 17
When an outcome can be any of a large range of numbers, then using a simple enumeration of
all possible numbers in this range is unwieldy.
We optimize by using numeric decomposition in which the oracle signs each digit of the outcome
individually so that many possible outcomes can be compressed into a single CET by ignoring certain signatures.
There will be as many nonces as there are possible digits required and CETs are claimed using
some number of these signatures, not necessarily all of them.
If not all signatures are used, then this CET corresponds to all events which agree on the digits for which
signatures are used and may have any value at all other digits for which signatures are ignored.
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this paragraph is very hard to read and the concept is already explained in the oracle spec that is under PR (and for which @Christewart is even adding more detailed example), so I would just remove that and reference the oracle spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be completely honest I think that it doesn't make much sense for these kinds of concerns to be included in the oracle spec for anything other than motivation whereas here they are necessary so I think it should be the other way around.

That said, I am more than happy to re-do the paragraph to make it more readable!

NumericOutcome.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
Lastly, if both grouping optimizations can be made, `w = 0` and `W = B-1` then a **total optimization** can be made and the
whole range can be represented using only a single CET corresponding to `(prefix)____`.

### Algorithms
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @benthecarman. Tbh it's fine by me since I got a little bit used to read Scala by now, but it definitely adds to the complexity of something that is already not that easy. I think Python would probably be better. I'm not sure for pseudo code, personally I often find it harder to read than actual code. Also still good to link to your implementation.

NumericOutcome.md Outdated Show resolved Hide resolved
}
```

## General Payout Curves
Copy link
Member

Choose a reason for hiding this comment

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

If you want to have something merge in the not so distant future, I would take that in a different PR. It's going to be difficult to give you feedback on that without actually trying to implement it myself I feel.

@NicolasDorier
Copy link

NicolasDorier commented Oct 29, 2020

Removed my comments.
I think I figured out how to compute all the CET, but I fail to understand the three optimization, it would be helpful to have a concrete example.

@nkohen
Copy link
Contributor Author

nkohen commented Oct 29, 2020

Removed my comments.
I think I figured out how to compute all the CET, but I fail to understand the three optimization, it would be helpful to have a concrete example.

Just pushed an attempt to make the optimizations more clear.

@nkohen
Copy link
Contributor Author

nkohen commented Oct 29, 2020

Ugh, and as I did that I realized that there are actually some optimizations I missed and that all of the optimizations including the ones I've missed can be stated cleverly as a single optimization, I will be pushing this change up shortly

NumericOutcome.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
Note that this `payout_function` is from the offerer's point of view.
To evaluate the accepter's `payout_function`, you must evaluate the offerer's `payout_function` at a given
`event_outcome` and subtract the resulting payout from `total_collateral`.
It is important that you do NOT construct the accepter's `payout_function` by replacing all `outcome_payout`s in the
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably worth bolding this text and maybe making it it's own paragraph.

NumericOutcome.md Outdated Show resolved Hide resolved
@nkohen nkohen mentioned this pull request Dec 30, 2020
8 tasks
Comment on lines +19 to +22
This is accomplished through the use of digit decomposition where oracles attesting to
numeric outcomes sign each digit of the outcome individually.
There are as many nonces as there are possible digits required and CETs are claimed using
only some of these signatures, not necessarily all of them.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe mention primairly using base 2 here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure this is the best place for this

CETCompression.md Outdated Show resolved Hide resolved
CETCompression.md Outdated Show resolved Hide resolved
NumericOutcome.md Outdated Show resolved Hide resolved
PayoutCurve.md Outdated Show resolved Hide resolved

We will first need a function to decompose any number into its digits in a given base.

```scala
Copy link
Contributor

Choose a reason for hiding this comment

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

These still should be written in something like python

Copy link
Member

@Tibo-lg Tibo-lg left a comment

Choose a reason for hiding this comment

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

LGTM we can iterate over that

@nkohen nkohen merged commit b9ac02c into discreetlogcontracts:master Feb 5, 2021
@nkohen nkohen moved this from In progress to Done in v0.1 Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
v0.1
  
Done
Development

Successfully merging this pull request may close these issues.

Decomposing quantities into multiple signatures
7 participants