Update DLC Oracle Signing Algo (#2465)

This commit is contained in:
benthecarman 2021-01-05 08:19:53 -06:00 committed by GitHub
parent b436f6cd2f
commit be06fb13ab
4 changed files with 40 additions and 7 deletions

View file

@ -72,9 +72,39 @@ object SigningVersion extends StringFactory[SigningVersion] {
} }
} }
val latest: SigningVersion = BasicSHA256SigningVersion /** V0 DLC Oracle singing algo, specified in https://github.com/discreetlogcontracts/dlcspecs/pull/113 */
final case object DLCOracleV0SigningVersion extends SigningVersion {
val all: Vector[SigningVersion] = Vector(Mock, BasicSHA256SigningVersion) override def calcNonceTweak(
nonce: SchnorrNonce,
eventName: String): ByteVector = {
val bytes = nonce.bytes ++ CryptoUtil.serializeForHash(eventName)
CryptoUtil.taggedSha256(bytes, "DLC/oracle/nonce/v0").bytes
}
override def calcAnnouncementHash(eventTLV: OracleEventTLV): ByteVector =
CryptoUtil
.taggedSha256(eventTLV.bytes, "DLC/oracle/announcement/v0")
.bytes
override def calcOutcomeHash(
descriptor: EventDescriptorTLV,
byteVector: ByteVector): ByteVector = {
descriptor match {
case _: EnumEventDescriptorV0TLV | _: RangeEventDescriptorV0TLV |
_: DigitDecompositionEventDescriptorV0TLV =>
CryptoUtil
.taggedSha256(byteVector, "DLC/oracle/attestation/v0")
.bytes
}
}
}
val latest: SigningVersion = DLCOracleV0SigningVersion
val all: Vector[SigningVersion] =
Vector(Mock, BasicSHA256SigningVersion, DLCOracleV0SigningVersion)
override def fromStringOpt(str: String): Option[SigningVersion] = { override def fromStringOpt(str: String): Option[SigningVersion] = {
all.find(state => str.toLowerCase() == state.toString.toLowerCase) all.find(state => str.toLowerCase() == state.toString.toLowerCase)

View file

@ -777,8 +777,11 @@ case class OracleAnnouncementV0TLV(
announcementSignature.bytes ++ publicKey.bytes ++ eventTLV.bytes announcementSignature.bytes ++ publicKey.bytes ++ eventTLV.bytes
override def validateSignature: Boolean = { override def validateSignature: Boolean = {
publicKey.verify(CryptoUtil.sha256(eventTLV.bytes).bytes, publicKey.verify(
announcementSignature) CryptoUtil
.taggedSha256(eventTLV.bytes, "DLC/oracle/announcement/v0")
.bytes,
announcementSignature)
} }
} }

View file

@ -9,7 +9,7 @@ class AttestationVerificationTest extends BitcoinSUnitTest {
behavior of "AttestationVerification" behavior of "AttestationVerification"
val signingVersion = SigningVersion.latest val signingVersion = SigningVersion.BasicSHA256SigningVersion
val enumTlv = OracleAnnouncementV0TLV.fromHex( val enumTlv = OracleAnnouncementV0TLV.fromHex(
"""fdd824a350a5f6214e14574bc925a9d5d211961a8e4e9ed8d3cb8dbc7c65d8da767152759e7d8d7646ded432717c8a4616a8fac714 """fdd824a350a5f6214e14574bc925a9d5d211961a8e4e9ed8d3cb8dbc7c65d8da767152759e7d8d7646ded432717c8a4616a8fac714

View file

@ -4,7 +4,7 @@ import com.typesafe.config.Config
import org.bitcoins.core.config.NetworkParameters import org.bitcoins.core.config.NetworkParameters
import org.bitcoins.core.crypto.ExtKeyVersion.SegWitMainNetPriv import org.bitcoins.core.crypto.ExtKeyVersion.SegWitMainNetPriv
import org.bitcoins.core.hd.HDPurpose import org.bitcoins.core.hd.HDPurpose
import org.bitcoins.core.protocol.tlv.EventDescriptorTLV import org.bitcoins.core.protocol.tlv.EnumEventDescriptorV0TLV
import org.bitcoins.core.util.FutureUtil import org.bitcoins.core.util.FutureUtil
import org.bitcoins.core.wallet.keymanagement.KeyManagerParams import org.bitcoins.core.wallet.keymanagement.KeyManagerParams
import org.bitcoins.crypto.AesPassword import org.bitcoins.crypto.AesPassword
@ -65,7 +65,7 @@ case class DLCOracleAppConfig(
if (migrations == 2 || migrations == 3) { // For V2/V3 migrations if (migrations == 2 || migrations == 3) { // For V2/V3 migrations
logger.debug(s"Doing V2/V3 Migration") logger.debug(s"Doing V2/V3 Migration")
val dummyMigrationTLV = EventDescriptorTLV("fdd8060800010564756d6d79") val dummyMigrationTLV = EnumEventDescriptorV0TLV.dummy
val eventDAO = EventDAO()(ec, appConfig) val eventDAO = EventDAO()(ec, appConfig)
for { for {