Skip to content

Commit 169c628

Browse files
committed
add endpoints to vsss
1 parent cc51345 commit 169c628

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/circuit/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,14 @@ impl StoredGates {
137137
pub fn save_to_json<P: AsRef<std::path::Path>>(&self, path: P) -> std::io::Result<()> {
138138
let file = std::fs::File::create(path)?;
139139
let writer = std::io::BufWriter::new(file);
140-
serde_json::to_writer(writer, self)
141-
.map_err(std::io::Error::other)
140+
serde_json::to_writer(writer, self).map_err(std::io::Error::other)
142141
}
143142

144143
/// Loads and deserializes stored gates from a JSON file.
145144
pub fn load_from_json<P: AsRef<std::path::Path>>(path: P) -> std::io::Result<Self> {
146145
let file = std::fs::File::open(path)?;
147146
let reader = std::io::BufReader::new(file);
148-
serde_json::from_reader(reader)
149-
.map_err(std::io::Error::other)
147+
serde_json::from_reader(reader).map_err(std::io::Error::other)
150148
}
151149
}
152150

src/cut_and_choose/vsss/core.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ where
236236
}
237237
result
238238
}
239+
240+
/// Construct a polynomial from a list of point values evaluated at the
241+
/// consecutive integer indices `0, 1, ..., degree`. The length of `points`
242+
/// determines the degree (`degree = points.len() - 1`).
243+
pub fn new(points: Vec<T>) -> Self {
244+
Self(points)
245+
}
239246
}
240247

241248
impl Polynomial<Fr> {
@@ -323,6 +330,19 @@ impl ShareCommits<Projective> {
323330
Ok(())
324331
}
325332

333+
/// Verify that this [`ShareCommits`] is internally self-consistent, given
334+
/// the degree of the underlying polynomial.
335+
///
336+
/// The first `degree + 1` committed points are treated as the polynomial
337+
/// coefficient commitments (`G * coeff[i]` for `i in 0..=degree`). A
338+
/// [`PolynomialCommits`] is constructed from them and used to verify that
339+
/// the remaining committed points are consistent via Lagrange interpolation.
340+
pub fn verify_self_consistence(&self, degree: usize) -> Result<(), String> {
341+
let poly = Polynomial::new(self.0[..=degree].to_vec());
342+
let poly_commits = PolynomialCommits(poly);
343+
self.verify(&poly_commits)
344+
}
345+
326346
pub fn verify_shares(&self, secp: &Secp256k1, shares: &[(usize, Fr)]) -> Result<(), String> {
327347
let mut indices = shares.iter().map(|(i, _)| *i).collect::<Vec<_>>();
328348
indices.sort_unstable();

0 commit comments

Comments
 (0)