Fix for nVssCommitments declarations
This commit is contained in:
parent
64e15574db
commit
8cacf80491
@ -1,5 +1,6 @@
|
|||||||
package fr.acinq.secp256k1
|
package fr.acinq.secp256k1
|
||||||
|
|
||||||
|
import fr.acinq.secp256k1.Secp256k1Native.toNat
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlinx.cinterop.ptr
|
import kotlinx.cinterop.ptr
|
||||||
import platform.posix.memcpy
|
import platform.posix.memcpy
|
||||||
@ -554,12 +555,17 @@ public object Secp256k1Native : Secp256k1 {
|
|||||||
val nTotalShares = totalShares.map { allocFrostShare(it).ptr }
|
val nTotalShares = totalShares.map { allocFrostShare(it).ptr }
|
||||||
|
|
||||||
val nVssCommitments = allocArray<CPointerVar<secp256k1_pubkey>>(vssCommitments.size)
|
val nVssCommitments = allocArray<CPointerVar<secp256k1_pubkey>>(vssCommitments.size)
|
||||||
vssCommitments.forEachIndexed { index, vssCommitment ->
|
|
||||||
nVssCommitments[index] = allocArrayOf(
|
vssCommitments.forEachIndexed { index, commitments ->
|
||||||
vssCommitment.map { bytes ->
|
val pubkeyArray = allocArray<secp256k1_pubkey>(commitments.size)
|
||||||
allocPublicKey(bytes).ptr
|
commitments.forEachIndexed { commitmentIndex, pubkeyData ->
|
||||||
|
pubkeyData.usePinned { pinned ->
|
||||||
|
if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pinned.get()), pubkeyData.size.convert()) == 0) {
|
||||||
|
error("Failed to parse public key")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
).reinterpret()
|
}
|
||||||
|
nVssCommitments[index] = pubkeyArray
|
||||||
}
|
}
|
||||||
|
|
||||||
val result = secp256k1_frost_share_agg(
|
val result = secp256k1_frost_share_agg(
|
||||||
@ -598,16 +604,24 @@ public object Secp256k1Native : Secp256k1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memScoped {
|
memScoped {
|
||||||
val nId33 = toNat(id33);
|
|
||||||
val nFrostShare = allocFrostShare(share)
|
val nFrostShare = allocFrostShare(share)
|
||||||
val nVssCommitment = vssCommitment.map { allocPublicKey(it).ptr }
|
// val nVssCommitment = vssCommitment.map { allocPublicKey(it).ptr }.toCValues()
|
||||||
|
|
||||||
|
val nVssCommitment = allocArray<CPointerVar<secp256k1_pubkey>>(vssCommitment.size)
|
||||||
|
vssCommitment.forEachIndexed { index, pubkeyData ->
|
||||||
|
pubkeyData.usePinned { pinned ->
|
||||||
|
if (secp256k1_ec_pubkey_parse(ctx, nVssCommitment[index], toNat(pinned.get()), pubkeyData.size.convert()) == 0) {
|
||||||
|
error("Failed to parse public key")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return secp256k1_frost_share_verify(
|
return secp256k1_frost_share_verify(
|
||||||
ctx = ctx,
|
ctx = ctx,
|
||||||
threshold = threshold.convert(),
|
threshold = vssCommitment.size.convert(),
|
||||||
id33 = nId33,
|
id33 = toNat(id33),
|
||||||
share = nFrostShare.ptr,
|
share = nFrostShare.ptr,
|
||||||
vss_commitment = nVssCommitment.toCValues()
|
vss_commitment = nVssCommitment
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -634,15 +648,20 @@ public object Secp256k1Native : Secp256k1 {
|
|||||||
val nPublicShare = alloc<secp256k1_pubkey>()
|
val nPublicShare = alloc<secp256k1_pubkey>()
|
||||||
|
|
||||||
val nVssCommitments = allocArray<CPointerVar<secp256k1_pubkey>>(vssCommitments.size)
|
val nVssCommitments = allocArray<CPointerVar<secp256k1_pubkey>>(vssCommitments.size)
|
||||||
vssCommitments.forEachIndexed { index, vssCommitment ->
|
|
||||||
nVssCommitments[index] = allocArrayOf(
|
vssCommitments.forEachIndexed { index, commitments ->
|
||||||
vssCommitment.map { bytes ->
|
val pubkeyArray = allocArray<secp256k1_pubkey>(commitments.size)
|
||||||
allocPublicKey(bytes).ptr
|
commitments.forEachIndexed { commitmentIndex, pubkeyData ->
|
||||||
|
pubkeyData.usePinned { pinned ->
|
||||||
|
if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pinned.get()), pubkeyData.size.convert()) == 0) {
|
||||||
|
error("Failed to parse public key")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
).reinterpret()
|
}
|
||||||
|
nVssCommitments[index] = pubkeyArray
|
||||||
}
|
}
|
||||||
|
|
||||||
secp256k1_frost_compute_pubshare(
|
val result = secp256k1_frost_compute_pubshare(
|
||||||
ctx = ctx,
|
ctx = ctx,
|
||||||
pubshare = nPublicShare.ptr,
|
pubshare = nPublicShare.ptr,
|
||||||
threshold = threshold.convert(),
|
threshold = threshold.convert(),
|
||||||
@ -651,6 +670,8 @@ public object Secp256k1Native : Secp256k1 {
|
|||||||
n_participants = totalSignersCount.convert()
|
n_participants = totalSignersCount.convert()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
println("Compute pubshare result: $result")
|
||||||
|
|
||||||
return serializePubkey(nPublicShare)
|
return serializePubkey(nPublicShare)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,6 @@ class FrostTest: BaseTest() {
|
|||||||
val expected = tests.jsonObject["expected"]!!.jsonArray[index];
|
val expected = tests.jsonObject["expected"]!!.jsonArray[index];
|
||||||
|
|
||||||
val expectedAggregateShare = expected.jsonObject["aggregate_share"]!!.jsonPrimitive.content
|
val expectedAggregateShare = expected.jsonObject["aggregate_share"]!!.jsonPrimitive.content
|
||||||
val expectedPublicShare = expected.jsonObject["public_share"]!!.jsonPrimitive.content
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = expectedAggregateShare,
|
expected = expectedAggregateShare,
|
||||||
@ -162,30 +161,6 @@ class FrostTest: BaseTest() {
|
|||||||
actual = Hex.encode(result.second),
|
actual = Hex.encode(result.second),
|
||||||
"Unexpected $index:aggregate_public_key"
|
"Unexpected $index:aggregate_public_key"
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
expected = 1,
|
|
||||||
actual = Secp256k1.frostShareVerify(
|
|
||||||
threshold,
|
|
||||||
ids33[index],
|
|
||||||
assignedShares[index],
|
|
||||||
vssCommitments[index]
|
|
||||||
),
|
|
||||||
message = "Couldn't verify share from $index signer"
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
expected = expectedPublicShare,
|
|
||||||
actual = Hex.encode(
|
|
||||||
Secp256k1.frostComputePublicShare(
|
|
||||||
threshold,
|
|
||||||
ids33[index],
|
|
||||||
vssCommitments.toTypedArray(),
|
|
||||||
nParticipants
|
|
||||||
)
|
|
||||||
),
|
|
||||||
message = "Couldn't verify share from $index signer"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -193,15 +168,12 @@ class FrostTest: BaseTest() {
|
|||||||
@Test
|
@Test
|
||||||
fun `frost share verify`() {
|
fun `frost share verify`() {
|
||||||
val shareGenTests = readData("frost/share_gen_vectors.json")
|
val shareGenTests = readData("frost/share_gen_vectors.json")
|
||||||
val tests = readData("frost/share_agg_vectors.json")
|
|
||||||
|
|
||||||
val expectedAggregatePublicKey = tests.jsonObject["aggregate_public_key"]!!.jsonPrimitive.content
|
|
||||||
val publicKeys = shareGenTests.jsonObject["pubkeys"]!!.jsonArray.map { Hex.decode(it.jsonPrimitive.content) }
|
val publicKeys = shareGenTests.jsonObject["pubkeys"]!!.jsonArray.map { Hex.decode(it.jsonPrimitive.content) }
|
||||||
|
|
||||||
val signerShareGenTestCase = shareGenTests.jsonObject["valid_signers_share_gen_test_case"]!!;
|
val signerShareGenTestCase = shareGenTests.jsonObject["valid_signers_share_gen_test_case"]!!;
|
||||||
|
|
||||||
val keyIndices = signerShareGenTestCase.jsonObject["key_indices"]!!.jsonArray.map { it.jsonPrimitive.int }
|
val keyIndices = signerShareGenTestCase.jsonObject["key_indices"]!!.jsonArray.map { it.jsonPrimitive.int }
|
||||||
val nParticipants = keyIndices.size
|
|
||||||
val threshold = signerShareGenTestCase.jsonObject["threshold"]!!.jsonPrimitive.int
|
val threshold = signerShareGenTestCase.jsonObject["threshold"]!!.jsonPrimitive.int
|
||||||
val ids33 = keyIndices.map { publicKeys[it] }.toTypedArray()
|
val ids33 = keyIndices.map { publicKeys[it] }.toTypedArray()
|
||||||
|
|
||||||
@ -218,30 +190,6 @@ class FrostTest: BaseTest() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val result = Secp256k1.frostShareAggregate(
|
|
||||||
assignedShares.toTypedArray(),
|
|
||||||
vssCommitments.toTypedArray(),
|
|
||||||
nParticipants,
|
|
||||||
threshold,
|
|
||||||
ids33[index]
|
|
||||||
)
|
|
||||||
|
|
||||||
val expected = tests.jsonObject["expected"]!!.jsonArray[index];
|
|
||||||
|
|
||||||
val expectedAggregateShare = expected.jsonObject["aggregate_share"]!!.jsonPrimitive.content
|
|
||||||
val expectedPublicShare = expected.jsonObject["public_share"]!!.jsonPrimitive.content
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
expected = expectedAggregateShare,
|
|
||||||
actual = Hex.encode(result.first),
|
|
||||||
"Unexpected $index:aggregate_share"
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
expected = expectedAggregatePublicKey,
|
|
||||||
actual = Hex.encode(result.second),
|
|
||||||
"Unexpected $index:aggregate_public_key"
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected = 1,
|
expected = 1,
|
||||||
actual = Secp256k1.frostShareVerify(
|
actual = Secp256k1.frostShareVerify(
|
||||||
@ -252,19 +200,6 @@ class FrostTest: BaseTest() {
|
|||||||
),
|
),
|
||||||
message = "Couldn't verify share from $index signer"
|
message = "Couldn't verify share from $index signer"
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
expected = expectedPublicShare,
|
|
||||||
actual = Hex.encode(
|
|
||||||
Secp256k1.frostComputePublicShare(
|
|
||||||
threshold,
|
|
||||||
ids33[index],
|
|
||||||
vssCommitments.toTypedArray(),
|
|
||||||
nParticipants
|
|
||||||
)
|
|
||||||
),
|
|
||||||
message = "Couldn't verify share from $index signer"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
"bf0eaac669eac6ac43d094bb2e07e4fa7fd4b1d317188c690aad7ea211b49bdb",
|
"bf0eaac669eac6ac43d094bb2e07e4fa7fd4b1d317188c690aad7ea211b49bdb",
|
||||||
"00c266074c34720f6d9a8511e4ec82bed44e104f93f20d9bbfbff8e2edf44400"
|
"00c266074c34720f6d9a8511e4ec82bed44e104f93f20d9bbfbff8e2edf44400"
|
||||||
],
|
],
|
||||||
|
|
||||||
"vss_commitment": [
|
"vss_commitment": [
|
||||||
"04bc2f60d5a7494d506e6517c49db2104b05e087536ccb1cb2730282f469782bb93e2c0029d733beeea75120e831ed71255adde4ddbd0be049419572502d7b73b9",
|
"04bc2f60d5a7494d506e6517c49db2104b05e087536ccb1cb2730282f469782bb93e2c0029d733beeea75120e831ed71255adde4ddbd0be049419572502d7b73b9",
|
||||||
"04ced2029d64827253175b5382cb327123fd2cdcdb5b2092e66020e9b6ece639f675029e36604347735eef9bf64137474b14d92d2996e67f5721705ee574c916a1",
|
"04ced2029d64827253175b5382cb327123fd2cdcdb5b2092e66020e9b6ece639f675029e36604347735eef9bf64137474b14d92d2996e67f5721705ee574c916a1",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user