Skip to content

Commit d4bba54

Browse files
randombitIDX GitHub Automation
andauthored
feat(crypto): CRP-2589 Add support for Taproot input to Schnorr signatures (#1803)
This updates the internal signature library implementing the threshold Schnorr protocol to also accept an auxiliary input relating to BIP341 (Taproot) --------- Co-authored-by: IDX GitHub Automation <infra+github-automation@dfinity.org>
1 parent 8801558 commit d4bba54

File tree

32 files changed

+357
-23
lines changed

32 files changed

+357
-23
lines changed

Cargo.Bazel.Fuzzing.json.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "7661b2c9fdc930e58622dc8df6307c9e805eb95556ad2b11b93ca0561235524a",
2+
"checksum": "d49c2d6535ae0e33df43f23bf7877c04341c237a0782c81faa1e85ae9a4e8a6b",
33
"crates": {
44
"abnf 0.12.0": {
55
"name": "abnf",
@@ -19214,6 +19214,10 @@
1921419214
"id": "scraper 0.17.1",
1921519215
"target": "scraper"
1921619216
},
19217+
{
19218+
"id": "secp256k1 0.22.2",
19219+
"target": "secp256k1"
19220+
},
1921719221
{
1921819222
"id": "semver 1.0.22",
1921919223
"target": "semver"
@@ -62768,6 +62772,8 @@
6276862772
],
6276962773
"crate_features": {
6277062774
"common": [
62775+
"default",
62776+
"global-context",
6277162777
"rand",
6277262778
"rand-std",
6277362779
"recovery",
@@ -85537,6 +85543,7 @@
8553785543
"scoped_threadpool 0.1.9",
8553885544
"scopeguard 1.2.0",
8553985545
"scraper 0.17.1",
85546+
"secp256k1 0.22.2",
8554085547
"semver 1.0.22",
8554185548
"serde 1.0.203",
8554285549
"serde-bytes-repr 0.1.5",

Cargo.Bazel.Fuzzing.toml.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,6 +3215,7 @@ dependencies = [
32153215
"scoped_threadpool",
32163216
"scopeguard",
32173217
"scraper",
3218+
"secp256k1 0.22.2",
32183219
"semver",
32193220
"serde",
32203221
"serde-bytes-repr",

Cargo.Bazel.json.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "d4b611a5f338012769866b27437875353f5d76dbabb9b135418806599a3b8912",
2+
"checksum": "4002433162202c7300c4f17bf7105e405ab6e3b9f9cd9e3d56c3ebe98e04d509",
33
"crates": {
44
"abnf 0.12.0": {
55
"name": "abnf",
@@ -19037,6 +19037,10 @@
1903719037
"id": "scraper 0.17.1",
1903819038
"target": "scraper"
1903919039
},
19040+
{
19041+
"id": "secp256k1 0.22.2",
19042+
"target": "secp256k1"
19043+
},
1904019044
{
1904119045
"id": "semver 1.0.22",
1904219046
"target": "semver"
@@ -62608,6 +62612,8 @@
6260862612
],
6260962613
"crate_features": {
6261062614
"common": [
62615+
"default",
62616+
"global-context",
6261162617
"rand",
6261262618
"rand-std",
6261362619
"recovery",
@@ -85410,6 +85416,7 @@
8541085416
"scoped_threadpool 0.1.9",
8541185417
"scopeguard 1.2.0",
8541285418
"scraper 0.17.1",
85419+
"secp256k1 0.22.2",
8541385420
"semver 1.0.22",
8541485421
"serde 1.0.203",
8541585422
"serde-bytes-repr 0.1.5",

Cargo.Bazel.toml.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,7 @@ dependencies = [
32043204
"scoped_threadpool",
32053205
"scopeguard",
32063206
"scraper",
3207+
"secp256k1 0.22.2",
32073208
"semver",
32083209
"serde",
32093210
"serde-bytes-repr",

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bazel/external_crates.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,13 @@ def external_crates_repository(name, cargo_lockfile, lockfile, sanitizers_enable
10801080
"scraper": crate.spec(
10811081
version = "^0.17.1",
10821082
),
1083+
"secp256k1": crate.spec(
1084+
version = "^0.22",
1085+
features = [
1086+
"global-context",
1087+
"rand-std",
1088+
],
1089+
),
10831090
"semver": crate.spec(
10841091
version = "^1.0.9",
10851092
features = [

rs/consensus/src/idkg/payload_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,7 @@ mod tests {
19201920
&key_transcript,
19211921
&[1; 64],
19221922
Randomness::from([0; 32]),
1923+
None,
19231924
&derivation_path,
19241925
algorithm,
19251926
&mut rng,

rs/consensus/src/idkg/signer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,7 @@ mod tests {
13611361
&key_transcript,
13621362
&[0; 32],
13631363
Randomness::from([0; 32]),
1364+
None,
13641365
&derivation_path,
13651366
algorithm_for_key_id(&key_id),
13661367
&mut rng,
@@ -2111,6 +2112,7 @@ mod tests {
21112112
&key_transcript,
21122113
&message,
21132114
Randomness::from(context.nonce.unwrap()),
2115+
None,
21142116
&derivation_path,
21152117
algorithm,
21162118
&mut rng,

rs/crypto/benches/tschnorr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fn bench_create_sig_share<M: Measurement, R: RngCore + CryptoRng>(
6464
&key_transcript,
6565
&message,
6666
seed,
67+
None,
6768
&derivation_path,
6869
test_case.alg,
6970
rng,
@@ -103,6 +104,7 @@ fn bench_verify_sig_share<M: Measurement, R: RngCore + CryptoRng>(
103104
&key_transcript,
104105
&message,
105106
seed,
107+
None,
106108
&derivation_path,
107109
test_case.alg,
108110
rng,
@@ -153,6 +155,7 @@ fn bench_combine_sig_shares<M: Measurement, R: RngCore + CryptoRng>(
153155
&key_transcript,
154156
&message,
155157
seed,
158+
None,
156159
&derivation_path,
157160
test_case.alg,
158161
rng,
@@ -194,6 +197,7 @@ fn bench_verify_combined_sig<M: Measurement, R: RngCore + CryptoRng>(
194197
&key_transcript,
195198
&message,
196199
seed,
200+
None,
197201
&derivation_path,
198202
test_case.alg,
199203
rng,

rs/crypto/internal/crypto_lib/threshold_sig/canister_threshold_sig/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,13 @@ impl From<CanisterThresholdError> for ThresholdBip340GenerateSigShareInternalErr
965965
/// The presig_transcript is the transcript of the pre-signature (kappa)
966966
///
967967
/// The message can be of any length
968+
///
969+
/// If taproot_tree_root is Some then this generates a Taproot tweaked
970+
/// signature, using the provided hash to derive a tweak
968971
pub fn create_bip340_signature_share(
969972
derivation_path: &DerivationPath,
970973
message: &[u8],
974+
taproot_tree_root: Option<&[u8]>,
971975
nonce: Randomness,
972976
key_transcript: &IDkgTranscriptInternal,
973977
presig_transcript: &IDkgTranscriptInternal,
@@ -977,6 +981,7 @@ pub fn create_bip340_signature_share(
977981
ThresholdBip340SignatureShareInternal::new(
978982
derivation_path,
979983
message,
984+
taproot_tree_root,
980985
nonce,
981986
key_transcript,
982987
key_opening,
@@ -1012,7 +1017,8 @@ impl From<CanisterThresholdError> for ThresholdBip340VerifySigShareInternalError
10121017
pub fn verify_bip340_signature_share(
10131018
sig_share: &ThresholdBip340SignatureShareInternal,
10141019
derivation_path: &DerivationPath,
1015-
hashed_message: &[u8],
1020+
message: &[u8],
1021+
taproot_tree_root: Option<&[u8]>,
10161022
randomness: Randomness,
10171023
signer_index: NodeIndex,
10181024
key_transcript: &IDkgTranscriptInternal,
@@ -1021,7 +1027,8 @@ pub fn verify_bip340_signature_share(
10211027
sig_share
10221028
.verify(
10231029
derivation_path,
1024-
hashed_message,
1030+
message,
1031+
taproot_tree_root,
10251032
randomness,
10261033
signer_index,
10271034
key_transcript,
@@ -1059,6 +1066,7 @@ impl From<CanisterThresholdError> for ThresholdBip340CombineSigSharesInternalErr
10591066
pub fn combine_bip340_signature_shares(
10601067
derivation_path: &DerivationPath,
10611068
message: &[u8],
1069+
taproot_tree_root: Option<&[u8]>,
10621070
randomness: Randomness,
10631071
key_transcript: &IDkgTranscriptInternal,
10641072
presig_transcript: &IDkgTranscriptInternal,
@@ -1069,6 +1077,7 @@ pub fn combine_bip340_signature_shares(
10691077
ThresholdBip340CombinedSignatureInternal::new(
10701078
derivation_path,
10711079
message,
1080+
taproot_tree_root,
10721081
randomness,
10731082
key_transcript,
10741083
presig_transcript,
@@ -1106,6 +1115,7 @@ pub fn verify_threshold_bip340_signature(
11061115
signature: &ThresholdBip340CombinedSignatureInternal,
11071116
derivation_path: &DerivationPath,
11081117
message: &[u8],
1118+
taproot_tree_root: Option<&[u8]>,
11091119
randomness: Randomness,
11101120
presig_transcript: &IDkgTranscriptInternal,
11111121
key_transcript: &IDkgTranscriptInternal,
@@ -1114,6 +1124,7 @@ pub fn verify_threshold_bip340_signature(
11141124
.verify(
11151125
derivation_path,
11161126
message,
1127+
taproot_tree_root,
11171128
randomness,
11181129
presig_transcript,
11191130
key_transcript,

0 commit comments

Comments
 (0)