mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 20:59:23 +00:00
Simplify Monero key image handling
This commit is contained in:
@@ -7,7 +7,7 @@ use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar};
|
||||
|
||||
use monero::VarInt;
|
||||
|
||||
use monero_serai::{random_scalar, Commitment, transaction::decoys::Decoys, key_image, clsag};
|
||||
use monero_serai::{Commitment, random_scalar, generate_key_image, transaction::decoys::Decoys, clsag};
|
||||
#[cfg(feature = "multisig")]
|
||||
use monero_serai::frost::{MultisigError, Transcript};
|
||||
|
||||
@@ -42,7 +42,7 @@ fn clsag() {
|
||||
ring.push([&dest * &ED25519_BASEPOINT_TABLE, Commitment::new(mask, amount).calculate()]);
|
||||
}
|
||||
|
||||
let image = key_image::generate(&secrets[0]);
|
||||
let image = generate_key_image(&secrets[0]);
|
||||
let (clsag, pseudo_out) = clsag::sign(
|
||||
&mut OsRng,
|
||||
&vec![(
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
#![cfg(feature = "multisig")]
|
||||
|
||||
use rand::{RngCore, rngs::OsRng};
|
||||
|
||||
use curve25519_dalek::{traits::Identity, edwards::EdwardsPoint};
|
||||
|
||||
use monero_serai::key_image;
|
||||
|
||||
mod frost;
|
||||
use crate::frost::{THRESHOLD, PARTICIPANTS, generate_keys};
|
||||
|
||||
#[test]
|
||||
fn key_image() {
|
||||
let (keys, group_private) = generate_keys();
|
||||
let image = key_image::generate(&group_private);
|
||||
|
||||
let mut included = (1 ..= PARTICIPANTS).into_iter().collect::<Vec<usize>>();
|
||||
while included.len() > THRESHOLD {
|
||||
included.swap_remove((OsRng.next_u64() as usize) % included.len());
|
||||
}
|
||||
included.sort();
|
||||
|
||||
let mut views = vec![];
|
||||
let mut shares = vec![];
|
||||
for i in 1 ..= PARTICIPANTS {
|
||||
if included.contains(&i) {
|
||||
// If they were included, include their view
|
||||
views.push(keys[i - 1].view(&included).unwrap());
|
||||
let share = key_image::generate_share(&mut OsRng, &views[i - 1]);
|
||||
let mut serialized = share.0.compress().to_bytes().to_vec();
|
||||
serialized.extend(b"abc");
|
||||
serialized.extend(&share.1);
|
||||
shares.push(serialized);
|
||||
} else {
|
||||
// If they weren't included, include dummy data to fill the Vec
|
||||
// Uses the view of someone actually included as Params::new verifies inclusion
|
||||
views.push(keys[included[0] - 1].view(&included).unwrap());
|
||||
shares.push(vec![]);
|
||||
}
|
||||
}
|
||||
|
||||
for i in &included {
|
||||
let mut multi_image = EdwardsPoint::identity();
|
||||
for l in &included {
|
||||
let share = key_image::verify_share(&views[i - 1], *l, &shares[l - 1]).unwrap();
|
||||
assert_eq!(share.1, b"abc");
|
||||
multi_image += share.0;
|
||||
}
|
||||
assert_eq!(image, multi_image);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user