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
Add basic DLC Oracle #2094
Add basic DLC Oracle #2094
Conversation
62d1528
to
84b0528
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think @nkohen should review this as it's very sensitive code.
label: String, | ||
outcomes: Vector[String]): Future[EventDb] = { | ||
for { | ||
indexOpt <- rValueDAO.maxKeyIndex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I do worry about the usage of maxKeyIndex
. There is nothing that protects against two separate threads calling createNewEvent()
at the same time. If I understand correctly, this would lead to an r value being re-used?
I think it would be wiser to have rValueDAO
be responsible for retrieving and incrementing the maxKeyIndex
. We should then write test cases to make sure we can't get rValueDAO
to return the same index on separte calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not very vulnerable to that. The db has a primary key for the nonce so it should fail if you try to make a second with the same, also the r value is tweaked based on the label so it's extra safe there.
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
|
||
hash = | ||
CryptoUtil.sha256(nonce.bytes ++ CryptoUtil.serializeForHash(label)) | ||
commitmentSig = signingKey.schnorrSign(hash.bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly is commitmentSig
? I was under the assumption it was the final signature published, but it seems that it is just affirming that you actually own the private key? This seems like something that can be replaced if we put signatures on oracle addresses? discreetlogcontracts/dlcspecs#99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commitmentSig
is the oracle signing their R value to prove that the oracle is infact going to sign for this event / R value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more clear they aren't signing the R value but instead
CryptoUtil.sha256(nonce.bytes ++ CryptoUtil.serializeForHash(label))
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
val dummyNonce = SchnorrNonce(ECPublicKey.freshPublicKey.bytes.tail) | ||
recoverToSucceededIf[RuntimeException]( | ||
dlcOracle.signEvent(dummyNonce, "testOutcomes")) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I would like to see a test case that calls createEvent()
twice in parallel a verify that the same nonce
is NEVER returned. In general, we should always make sure the database configuration for the DLC oracle project has numThreads=1
to make sure that there is no concurrent database accesses. We should use a require()
inside of DLCOracleAppConfig
to enforce this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue filed for the latter half of this issue: #2107
dlc-oracle-test/src/test/scala/org/bitcoins/dlc/oracle/DLCOracleTest.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracleAppConfig.scala
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/DLCOracle.scala
Outdated
Show resolved
Hide resolved
* Add basic DLC Oracle * Respond to review * Respond to more review * Add maturation time * Add to testkit, tag hashes, better val names * More clear vals, version tagged hashes * Signing key clean up * Add pubkey to db
Closes #2096
Closes #2099