Skip to content
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

Reduce size of serialized share #96

Merged
merged 7 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cggmp21/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "../README.md"

[dependencies]
cggmp21-keygen = { path = "../cggmp21-keygen", version = "0.1" }
key-share = { path = "../key-share", version = "0.2" }
key-share = { path = "../key-share", version = "0.2", features = ["serde"] }

generic-ec = { version = "0.2", features = ["serde", "udigest"] }
generic-ec-zkp = { version = "0.2", features = ["serde", "udigest"] }
Expand Down
2 changes: 1 addition & 1 deletion cggmp21/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ where
pub fn subset<T: Clone, I: Into<usize> + Copy>(indexes: &[I], list: &[T]) -> Option<Vec<T>> {
indexes
.iter()
.map(|&i| list.get(i.into()).map(T::clone))
.map(|&i| list.get(i.into()).cloned())
.collect()
}

Expand Down
5 changes: 5 additions & 0 deletions key-share/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.2.3
* Reduce size of serialized key share [#96]

[#96]: https://github.com/dfns/cggmp21/pull/96

## v0.2.2
* Add `no_std` support [#92]

Expand Down
4 changes: 2 additions & 2 deletions key-share/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "key-share"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Key share of any Threshold Signature Scheme (TSS)"
Expand All @@ -11,7 +11,7 @@ keywords = ["mpc", "threshold-signatures", "tss"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
generic-ec = { version = "0.2", default-features = false, features = ["alloc"] }
generic-ec = { version = "0.2.3", default-features = false, features = ["alloc"] }
generic-ec-zkp = { version = "0.2", default-features = false, features = ["alloc"] }
rand_core = { version = "0.6", optional = true }

Expand Down
12 changes: 12 additions & 0 deletions key-share/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ impl<'de, E: Curve> serde::Deserialize<'de> for DirtyCoreKeyShare<E> {
#[cfg_attr(feature = "serde", serde(bound = ""))]
#[cfg_attr(feature = "udigest", derive(udigest::Digestable))]
pub struct DirtyKeyInfo<E: Curve> {
// NOTE: on changing any of `serde` attributes, remember to change
// `crate::serde_fix` as well!
//
/// Guard that ensures curve consistency for deseraization
#[cfg_attr(feature = "udigest", udigest(with = utils::encoding::curve_name))]
pub curve: CurveName<E>,
Expand All @@ -215,12 +218,17 @@ pub struct DirtyKeyInfo<E: Curve> {
)]
pub public_shares: Vec<NonZero<Point<E>>>,
/// Verifiable secret sharing setup, present if key was generated using VSS scheme
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub vss_setup: Option<VssSetup<E>>,
/// Chain code associated with the key, if HD wallets support was enabled
#[cfg(feature = "hd-wallets")]
#[cfg_attr(
feature = "serde",
serde(default),
serde(skip_serializing_if = "Option::is_none"),
serde(with = "As::<Option<utils::HexOrBin>>")
)]
#[cfg_attr(feature = "udigest", udigest(with = utils::encoding::maybe_bytes))]
Expand All @@ -240,6 +248,10 @@ pub struct VssSetup<E: Curve> {
/// Key shares indexes
///
/// `I[i]` corresponds to key share index of a $\ith$ signer
#[cfg_attr(
feature = "serde",
serde(with = "As::<Vec<generic_ec::serde::PreferCompact>>")
)]
pub I: Vec<NonZero<Scalar<E>>>,
}

Expand Down
10 changes: 5 additions & 5 deletions key-share/src/serde_fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ core_key_share! {
pub shared_public_key: NonZero<Point<E>>,
#[serde(with = "As::<Vec<generic_ec::serde::Compact>>")]
pub public_shares: Vec<NonZero<Point<E>>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub vss_setup: Option<crate::VssSetup<E>>,

#[cfg(feature = "hd-wallets")]
#[cfg_attr(
feature = "serde",
serde(default),
serde(with = "As::<Option<crate::utils::HexOrBin>>")
)]
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(with = "As::<Option<crate::utils::HexOrBin>>")]
pub chain_code: Option<slip_10::ChainCode>,

#[serde(with = "As::<generic_ec::serde::Compact>")]
pub x: NonZero<SecretScalar<E>>,
}
2 changes: 1 addition & 1 deletion key-share/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ pub fn subset<T: Clone, I: Into<usize> + Copy>(
) -> Option<alloc::vec::Vec<T>> {
indexes
.iter()
.map(|&i| list.get(i.into()).map(T::clone))
.map(|&i| list.get(i.into()).cloned())
.collect()
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"curve": "secp256k1",
"i": 0,
"shared_public_key": "0212366241a60518a4f242adc65758563373bdf2747fd84beb70ea0decbff88293",
"public_shares": [
"0287a4fe3f749593bb3bc86e2afa7b7e13e09da01b68b651c4c4955296319983f0",
"020b4ca37931b21002b4c57f21339ad06e8bb777f5c5e00adf3303409b604ea861",
"03aad497f3d1fb98b81286b8e11bf48878d6dd6de1716b0ba8b9d57d55ca6de825",
"03c8f52a34aada5b5e274d6e931bb490543f308bba61d7fd390ee54edd6090aca9",
"03c5105f63e739c8017c10513c78468e93c24780f8f2fb02663f5f42959a614a5d"
],
"x": "498777e41b6bd35d8af3cf0dd48f4cc99599108f1f3a03e6623f6cfb1804a00a"
}
Binary file not shown.
14 changes: 14 additions & 0 deletions test-data/old-shares/v0.2.3/secp256k1-threshold-false-hd-true.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"curve": "secp256k1",
"i": 0,
"shared_public_key": "024392578eadd0ae369e03e0b30daf4e92d0d569dc0d45dfbc1d27483a10a5eb8e",
"public_shares": [
"03e1dc5555e191d9db3a564ad8024857353ef76786ad7f8ac7eae08a2584c90c42",
"0388d9f29fc8ce4e21110da3df3cd0d598d45044dabee36ba6a440452190a15cde",
"02cc5140d2f23fbcc7224131020b31d068c4b6592170d416358cfe727575b02eb2",
"03ea82ee2af5d2c7df248ba888588504c2e7f246ea198b5bf0c4c4e1e7d73a2df0",
"02949e18056a8fb5702e0ece78890c1e4625179b504e8ee608f855dc6be67690de"
],
"chain_code": "5e1fa411dd4a0004de927fce0c00ea0b87f0b5026f4afd03c38d6dbbba8778fb",
"x": "95cdf3ebb0bcaee661718ae3a396f62c13605998d013a444a2e6c14cf6dad08e"
}
Binary file not shown.
23 changes: 23 additions & 0 deletions test-data/old-shares/v0.2.3/secp256k1-threshold-true-hd-false.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"curve": "secp256k1",
"i": 0,
"shared_public_key": "039079502269cf8fdaabf1bf91a7c363cfca1a3eb5c2e4a84a8bbde38d21c96cd0",
"public_shares": [
"034a24a8884dd564f40c3f8be173b7002088609544318824dc6f5c4b305f3d9ee8",
"02e8e02546d595c58183d54564e27508ebfc3c0c62203717df88c6b7b6b6874f17",
"02aa7f587cc9a3dc52585ddd745dc9edd3c6f1cfcd2b01aa33b5fd861ab5887e05",
"03d4b05cf3838d9a1c6ef443fb38753e1db7e9b10523c3b1913fcbb6421b8079fa",
"0267fbead366d3ac76aaf5c56f3bf18beadb75a576dfb8b07adfb51c3ae6eaf814"
],
"vss_setup": {
"min_signers": 3,
"I": [
"0000000000000000000000000000000000000000000000000000000000000001",
"0000000000000000000000000000000000000000000000000000000000000002",
"0000000000000000000000000000000000000000000000000000000000000003",
"0000000000000000000000000000000000000000000000000000000000000004",
"0000000000000000000000000000000000000000000000000000000000000005"
]
},
"x": "bdbad801cabc750cf765e24a5b2553357f231b07d05bdb4017b148119af2aa59"
}
Binary file not shown.
24 changes: 24 additions & 0 deletions test-data/old-shares/v0.2.3/secp256k1-threshold-true-hd-true.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"curve": "secp256k1",
"i": 0,
"shared_public_key": "0283f2560ec7f0a58398c37ccb386b97736af8ee22f457fb8b75c4639370831be3",
"public_shares": [
"021169919b3a5d2c27a8b0f7b0c061a362dd7dade5985c6fd3a120bd0f349c3ca3",
"03f56a0fcec9f5ec695adbd3f073909cc69085ced62f03689739cdec055a00a8d7",
"02146f2715951159002d710f9d03a936a2ce9ec3ee3b667aa52c15fd5c8150795b",
"0389387de43d1e5ad2e91f21ba86a990450f7acd68c45b30a0c53c30e24d1fb0c6",
"0220c52dd258ff4b8a714ce7752bdcdb4b157480780a7bdb0d4e137f31d5e76b31"
],
"vss_setup": {
"min_signers": 3,
"I": [
"0000000000000000000000000000000000000000000000000000000000000001",
"0000000000000000000000000000000000000000000000000000000000000002",
"0000000000000000000000000000000000000000000000000000000000000003",
"0000000000000000000000000000000000000000000000000000000000000004",
"0000000000000000000000000000000000000000000000000000000000000005"
]
},
"chain_code": "101a1820569466d7836c89d05a89c70257179dbeeb7b3d4aeeedaf6ecf150cb0",
"x": "782087c8eda1007984f5bcec33f3446a339b64fb5fcc81e5a63f1ee8ceaae4de"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"curve": "secp256r1",
"i": 0,
"shared_public_key": "03abf6ccfabe50febbe85845af6f569a80e3126743c50912980c2fb73a14250d25",
"public_shares": [
"029238230038d288f01b2cd40cf4e705ac9a88d391b15b7ce96d45863f6a94619a",
"03ba3b4a7a4c434838caf904a13a7cb3e3438340be6874542646cb84470bf74474",
"03495372b111b135e0aa66439881780cc0403d0b0e5cfa9651084acb57f8e33213",
"02631823fa561f5f935698a3d42b595ad743bdb9590bdba6a3ec44f2716ad85cc7",
"034cdeaeb4bf79646ad5eb7527869952c5af3197e442c66a4a3b02fd5d36cf8cb4"
],
"x": "9d8822ac8ca71fedb9935f9377b30d44ca44c5dedb4c2a6bbc8a5c46107adbeb"
}
Binary file not shown.
14 changes: 14 additions & 0 deletions test-data/old-shares/v0.2.3/secp256r1-threshold-false-hd-true.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"curve": "secp256r1",
"i": 0,
"shared_public_key": "02398fbf40ec45ab0ffa38919c81632dc396cf4d5e11d67601cbd7d49748354fa5",
"public_shares": [
"03b40e3364e254f9ff48d452157d29267da14df31444f6f846c63b14a58e3888da",
"027fecb4fc4aae5df1e0acc27fabfb2ebfdbb10a053863d9b7db041807dedfaa9f",
"0364fd4694302a693a4beb0d5e6b96d3432a83222d3cc8a382dfed6150f1b40ab9",
"02bdfe17933b468a747bb7c43d904160fd2e5987baf49bb115e5bfb410d5420109",
"02ad4b5e78c5aa5261ecf234ab7f1ecf230bc5970ff6589cd9df2b91b20bb44f24"
],
"chain_code": "c1dfa80e86dc63628fe164404b22e5e15a3d2392d714de58c9bc703e102e036b",
"x": "0a44c6aa8e564e0da2d63b040fe5ea8385505cdcf2a042a8f72490c4a107e165"
}
Binary file not shown.
23 changes: 23 additions & 0 deletions test-data/old-shares/v0.2.3/secp256r1-threshold-true-hd-false.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"curve": "secp256r1",
"i": 0,
"shared_public_key": "03ac274ce13551dceadd41c339d911d3b441d35ff378c81d23bc8e3aad137f6c45",
"public_shares": [
"03c99a1d73cd4ea3bc914aa47b6af59b638a7a7ef7e9e61b60a560abd4d9915174",
"022c7f1ec772b37f6e3fda525c7d14f452c047a0b11794f1416f1a326326432705",
"0252682499e0c0680e9e2d082eac72c16cdb4fae6d2d29222b6d5d1cfda5011115",
"03ca8cc749138077117a9e46ef580aaf5862411bf3cc54479e8c1b66f7ecbb35f3",
"031a1fdbf540b718f838e4f419656297ca7abc8b0e0e48b2467ed102be99e990e8"
],
"vss_setup": {
"min_signers": 3,
"I": [
"0000000000000000000000000000000000000000000000000000000000000001",
"0000000000000000000000000000000000000000000000000000000000000002",
"0000000000000000000000000000000000000000000000000000000000000003",
"0000000000000000000000000000000000000000000000000000000000000004",
"0000000000000000000000000000000000000000000000000000000000000005"
]
},
"x": "226521a2a13c10b974d3b8236f3a99e3e2175a5ce99766b75c477afb430f6ffb"
}
Binary file not shown.
24 changes: 24 additions & 0 deletions test-data/old-shares/v0.2.3/secp256r1-threshold-true-hd-true.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"curve": "secp256r1",
"i": 0,
"shared_public_key": "03fc526161144f5dd828db44474ab93910edf9ba59ef5fdb69c39e8582fdae2917",
"public_shares": [
"032ceda239376e2b5608385291f2595cd1f4bc090df364c098c250336a1db6f50f",
"034636015e441de24ea46d651d7b141a3046154cb34ff29c24838b8c7e5c7d6fa6",
"03e29bbbba23a8c41f5d392b47f5e8b48e003fa5ce30fb6c0eaa87413ea164c8e8",
"03121f24fb33b91a567a4bdff7d2a3ebdd388eda9ca91fa4e33a309bd9efdd8eaf",
"032b3b4cfbc240ee3d282faee92f5f37f2fd9a9b80e8744bcb135f475034232f65"
],
"vss_setup": {
"min_signers": 3,
"I": [
"0000000000000000000000000000000000000000000000000000000000000001",
"0000000000000000000000000000000000000000000000000000000000000002",
"0000000000000000000000000000000000000000000000000000000000000003",
"0000000000000000000000000000000000000000000000000000000000000004",
"0000000000000000000000000000000000000000000000000000000000000005"
]
},
"chain_code": "15f710a770c88585cba1fe7d5cf4111e001166a161ef6b806dd4342d64247859",
"x": "005e8676812c11b0e307cda6dede17d8172c99a9c02b405c7052e4c80bf8cd91"
}
Binary file not shown.
13 changes: 13 additions & 0 deletions test-data/old-shares/v0.2.3/stark-threshold-false-hd-false.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"curve": "stark",
"i": 0,
"shared_public_key": "0303df4327623c4d6e28f53bcbe0f9a791d7b1e1f020caf9cdbdd8099320e58d02",
"public_shares": [
"0300e91c19280a7babccbb39d045b64de4c5a3e7df64b3d4c2c7ca7515792cdec5",
"0200eabbf2a147d835c905dd487c7d8fb21dcaa79e779f6eb934d32e770c17fd4c",
"0307ff0e461c8872b1a9e302b71b7caf1fd3b5a390faba969a909fc47cb18ee0f0",
"0201e219c58e5e1623b8213f6bdba04cdc5316bff2806a48c609035000b92dcc87",
"02075928c94617584215255010a5adefd0f6d2eafbc05255328d1f95d8b3e292e1"
],
"x": "046f036a3c61bb7c421a13da92bc949f07b5b2d2bcdd3426a7803cfad95e2dea"
}
Binary file not shown.
14 changes: 14 additions & 0 deletions test-data/old-shares/v0.2.3/stark-threshold-false-hd-true.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"curve": "stark",
"i": 0,
"shared_public_key": "02075ab77595ba1e7f09b1ae16631ec5fc98747fa11f166b6f0de824f06104d234",
"public_shares": [
"02034e797bdbae9e84378cd32baddbfe3e7101b47cc5570db37d915b5c299913ac",
"03003234aa0eda183bb125611e743382d4c710a01d343ceae813eb0b39d90f44a5",
"0205909c84e992898d351082a698f1853a474d93708767dd8db3a6bf945b630910",
"02038e35862b968af30bed3b80bf6056a30a37924e675bcd4aba595e0b8806c32f",
"0306259f8a827ddb8595ff7734aba2bc732a2916f07eab533bd592900753534e97"
],
"chain_code": "f069e0c7de414b63a6ee725b7a66506c5297117124ddf1b52a5243449e23c188",
"x": "06d6bbc624e13f18e77c44579454c3b011ec9732625e5488c9d1d8f052ff22c4"
}
Binary file not shown.
23 changes: 23 additions & 0 deletions test-data/old-shares/v0.2.3/stark-threshold-true-hd-false.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"curve": "stark",
"i": 0,
"shared_public_key": "03019bb68a2e51c55de3eaa76ac5bc24cea554ded12b4965c5d5d6c776c0d9f1a7",
"public_shares": [
"0307eee8eb76aa9fe85e2c999a94199887a9d73d03ab839ab01b60044b049c7371",
"03023096979f5e25b72e31cbcdec6243895b843fd31b12309785669a3883f38f01",
"0201b7d89ac870979b8d5697a38059e00dbc2e14ee7b8a7fabf4db089af00bc22a",
"0205ea761de0d6079021ee207a1d5e31658a4fcec946d85498a40c7e1ef62877ab",
"02061d56b9bf7f95ff1152656632eb22fb69d6c4b5d4b5231f46d760cb1d408ef3"
],
"vss_setup": {
"min_signers": 3,
"I": [
"0000000000000000000000000000000000000000000000000000000000000001",
"0000000000000000000000000000000000000000000000000000000000000002",
"0000000000000000000000000000000000000000000000000000000000000003",
"0000000000000000000000000000000000000000000000000000000000000004",
"0000000000000000000000000000000000000000000000000000000000000005"
]
},
"x": "04daf665503286d858e1b99febb9fbaf454ec4f846e201413870e4c56c57ca43"
}
Binary file not shown.
Loading
Loading