Don't usePinned where not necessary

This commit is contained in:
kngako 2024-08-22 23:13:11 +02:00
parent 8cacf80491
commit 9541124a4a

View File

@ -559,12 +559,10 @@ public object Secp256k1Native : Secp256k1 {
vssCommitments.forEachIndexed { index, commitments -> vssCommitments.forEachIndexed { index, commitments ->
val pubkeyArray = allocArray<secp256k1_pubkey>(commitments.size) val pubkeyArray = allocArray<secp256k1_pubkey>(commitments.size)
commitments.forEachIndexed { commitmentIndex, pubkeyData -> commitments.forEachIndexed { commitmentIndex, pubkeyData ->
pubkeyData.usePinned { pinned -> if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pubkeyData), pubkeyData.size.convert()) == 0) {
if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pinned.get()), pubkeyData.size.convert()) == 0) {
error("Failed to parse public key") error("Failed to parse public key")
} }
} }
}
nVssCommitments[index] = pubkeyArray nVssCommitments[index] = pubkeyArray
} }
@ -605,20 +603,24 @@ public object Secp256k1Native : Secp256k1 {
memScoped { memScoped {
val nFrostShare = allocFrostShare(share) val nFrostShare = allocFrostShare(share)
// val nVssCommitment = vssCommitment.map { allocPublicKey(it).ptr }.toCValues() // val nVssCommitment = vssCommitment.map { allocPublicKey(it).ptr }
val nVssCommitment = allocArray<CPointerVar<secp256k1_pubkey>>(vssCommitment.size) val nVssCommitment = allocArray<CPointerVar<secp256k1_pubkey>>(vssCommitment.size)
vssCommitment.forEachIndexed { index, pubkeyData -> vssCommitment.forEachIndexed { index, bytes ->
pubkeyData.usePinned { pinned -> memcpy(nVssCommitment[index], bytes.refTo(0).getPointer(memScope), bytes.size.convert())
if (secp256k1_ec_pubkey_parse(ctx, nVssCommitment[index], toNat(pinned.get()), pubkeyData.size.convert()) == 0) {
error("Failed to parse public key")
}
}
} }
// 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 = vssCommitment.size.convert(), threshold = threshold.convert(),
id33 = toNat(id33), id33 = toNat(id33),
share = nFrostShare.ptr, share = nFrostShare.ptr,
vss_commitment = nVssCommitment vss_commitment = nVssCommitment
@ -652,12 +654,10 @@ public object Secp256k1Native : Secp256k1 {
vssCommitments.forEachIndexed { index, commitments -> vssCommitments.forEachIndexed { index, commitments ->
val pubkeyArray = allocArray<secp256k1_pubkey>(commitments.size) val pubkeyArray = allocArray<secp256k1_pubkey>(commitments.size)
commitments.forEachIndexed { commitmentIndex, pubkeyData -> commitments.forEachIndexed { commitmentIndex, pubkeyData ->
pubkeyData.usePinned { pinned -> if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pubkeyData), pubkeyData.size.convert()) == 0) {
if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pinned.get()), pubkeyData.size.convert()) == 0) {
error("Failed to parse public key") error("Failed to parse public key")
} }
} }
}
nVssCommitments[index] = pubkeyArray nVssCommitments[index] = pubkeyArray
} }