2022-11-10 22:35:09 -05:00
|
|
|
use core::{ops::Deref, fmt::Debug};
|
2024-04-21 22:50:07 -04:00
|
|
|
use std_shims::{
|
2024-06-14 17:12:46 -04:00
|
|
|
sync::{Arc, Mutex},
|
2024-04-21 22:50:07 -04:00
|
|
|
io::{self, Read, Write},
|
|
|
|
|
collections::HashMap,
|
|
|
|
|
};
|
2022-04-29 22:03:34 -04:00
|
|
|
|
2022-05-06 07:33:08 -04:00
|
|
|
use rand_core::{RngCore, CryptoRng, SeedableRng};
|
2022-08-30 20:01:46 -04:00
|
|
|
use rand_chacha::ChaCha20Rng;
|
2022-04-21 21:36:18 -04:00
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
use zeroize::{Zeroize, Zeroizing};
|
Utilize zeroize (#76)
* Apply Zeroize to nonces used in Bulletproofs
Also makes bit decomposition constant time for a given amount of
outputs.
* Fix nonce reuse for single-signer CLSAG
* Attach Zeroize to most structures in Monero, and ZOnDrop to anything with private data
* Zeroize private keys and nonces
* Merge prepare_outputs and prepare_transactions
* Ensure CLSAG is constant time
* Pass by borrow where needed, bug fixes
The past few commitments have been one in-progress chunk which I've
broken up as best read.
* Add Zeroize to FROST structs
Still needs to zeroize internally, yet next step. Not quite as
aggressive as Monero, partially due to the limitations of HashMaps,
partially due to less concern about metadata, yet does still delete a
few smaller items of metadata (group key, context string...).
* Remove Zeroize from most Monero multisig structs
These structs largely didn't have private data, just fields with private
data, yet those fields implemented ZeroizeOnDrop making them already
covered. While there is still traces of the transaction left in RAM,
fully purging that was never the intent.
* Use Zeroize within dleq
bitvec doesn't offer Zeroize, so a manual zeroing has been implemented.
* Use Zeroize for random_nonce
It isn't perfect, due to the inability to zeroize the digest, and due to
kp256 requiring a few transformations. It does the best it can though.
Does move the per-curve random_nonce to a provided one, which is allowed
as of https://github.com/cfrg/draft-irtf-cfrg-frost/pull/231.
* Use Zeroize on FROST keygen/signing
* Zeroize constant time multiexp.
* Correct when FROST keygen zeroizes
* Move the FROST keys Arc into FrostKeys
Reduces amount of instances in memory.
* Manually implement Debug for FrostCore to not leak the secret share
* Misc bug fixes
* clippy + multiexp test bug fixes
* Correct FROST key gen share summation
It leaked our own share for ourself.
* Fix cross-group DLEq tests
2022-08-03 03:25:18 -05:00
|
|
|
|
2023-09-12 10:02:20 -04:00
|
|
|
use curve25519_dalek::{scalar::Scalar, edwards::EdwardsPoint};
|
2022-04-21 21:36:18 -04:00
|
|
|
|
2024-04-21 22:50:07 -04:00
|
|
|
use group::{
|
|
|
|
|
ff::{Field, PrimeField},
|
|
|
|
|
Group, GroupEncoding,
|
|
|
|
|
};
|
2022-05-03 07:20:24 -04:00
|
|
|
|
2022-06-24 18:58:24 -04:00
|
|
|
use transcript::{Transcript, RecommendedTranscript};
|
2022-05-03 08:49:46 -04:00
|
|
|
use dalek_ff_group as dfg;
|
2022-10-25 23:17:25 -05:00
|
|
|
use frost::{
|
2022-12-08 19:04:35 -05:00
|
|
|
dkg::lagrange,
|
2022-10-25 23:17:25 -05:00
|
|
|
curve::Ed25519,
|
2023-02-23 06:50:45 -05:00
|
|
|
Participant, FrostError, ThresholdKeys, ThresholdView,
|
2022-10-29 03:54:42 -05:00
|
|
|
algorithm::{WriteAddendum, Algorithm},
|
2022-10-25 23:17:25 -05:00
|
|
|
};
|
2022-04-21 21:36:18 -04:00
|
|
|
|
2024-06-13 18:54:18 -04:00
|
|
|
use monero_generators::hash_to_point;
|
|
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
use crate::{ClsagContext, Clsag};
|
2022-04-21 21:36:18 -04:00
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
impl ClsagContext {
|
2022-06-24 18:58:24 -04:00
|
|
|
fn transcript<T: Transcript>(&self, transcript: &mut T) {
|
2022-05-06 07:33:08 -04:00
|
|
|
// Doesn't domain separate as this is considered part of the larger CLSAG proof
|
2022-05-06 01:35:23 -04:00
|
|
|
|
2022-05-03 07:20:24 -04:00
|
|
|
// Ring index
|
2024-06-14 16:17:51 -04:00
|
|
|
transcript.append_message(b"signer_index", [self.decoys.signer_index()]);
|
2022-05-03 07:20:24 -04:00
|
|
|
|
|
|
|
|
// Ring
|
2024-06-14 11:47:57 -04:00
|
|
|
for (i, pair) in self.decoys.ring().iter().enumerate() {
|
2024-06-14 16:17:51 -04:00
|
|
|
// Doesn't include global output indexes as CLSAG doesn't care/won't be affected by it
|
2022-05-06 19:07:37 -04:00
|
|
|
// They're just a unreliable reference to this data which will be included in the message
|
2024-06-14 16:17:51 -04:00
|
|
|
// if somehow relevant
|
2023-01-07 05:18:35 -05:00
|
|
|
transcript.append_message(b"member", [u8::try_from(i).expect("ring size exceeded 255")]);
|
2024-04-21 22:50:07 -04:00
|
|
|
// This also transcripts the key image generator since it's derived from this key
|
2023-01-07 05:18:35 -05:00
|
|
|
transcript.append_message(b"key", pair[0].compress().to_bytes());
|
|
|
|
|
transcript.append_message(b"commitment", pair[1].compress().to_bytes())
|
2022-05-03 07:20:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Doesn't include the commitment's parts as the above ring + index includes the commitment
|
2024-06-14 16:17:51 -04:00
|
|
|
// The only potential malleability would be if the G/H relationship is known, breaking the
|
2022-05-03 07:20:24 -04:00
|
|
|
// discrete log problem, which breaks everything already
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 17:12:46 -04:00
|
|
|
/// A channel to send the mask to use for the pseudo-out (rerandomized commitment) with.
|
|
|
|
|
///
|
|
|
|
|
/// A mask must be sent along this channel before any preprocess addendums are handled. Breaking
|
|
|
|
|
/// this rule will cause a panic.
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub struct ClsagMultisigMaskSender {
|
|
|
|
|
buf: Arc<Mutex<Option<Scalar>>>,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
struct ClsagMultisigMaskReceiver {
|
|
|
|
|
buf: Arc<Mutex<Option<Scalar>>>,
|
|
|
|
|
}
|
|
|
|
|
impl ClsagMultisigMaskSender {
|
|
|
|
|
fn new() -> (ClsagMultisigMaskSender, ClsagMultisigMaskReceiver) {
|
|
|
|
|
let buf = Arc::new(Mutex::new(None));
|
|
|
|
|
(ClsagMultisigMaskSender { buf: buf.clone() }, ClsagMultisigMaskReceiver { buf })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Send a mask to a CLSAG multisig instance.
|
|
|
|
|
pub fn send(self, mask: Scalar) {
|
|
|
|
|
*self.buf.lock() = Some(mask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl ClsagMultisigMaskReceiver {
|
|
|
|
|
fn recv(self) -> Scalar {
|
|
|
|
|
self.buf.lock().unwrap()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
/// Addendum produced during the signing process.
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Zeroize, Debug)]
|
|
|
|
|
pub struct ClsagAddendum {
|
|
|
|
|
key_image_share: dfg::EdwardsPoint,
|
2022-05-06 19:07:37 -04:00
|
|
|
}
|
|
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
impl ClsagAddendum {
|
2024-06-14 17:12:46 -04:00
|
|
|
/// The key image share within this addendum.
|
2024-06-14 16:17:51 -04:00
|
|
|
pub fn key_image_share(&self) -> dfg::EdwardsPoint {
|
|
|
|
|
self.key_image_share
|
2022-05-06 19:07:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-29 03:54:42 -05:00
|
|
|
impl WriteAddendum for ClsagAddendum {
|
2022-10-25 23:17:25 -05:00
|
|
|
fn write<W: Write>(&self, writer: &mut W) -> io::Result<()> {
|
2024-06-14 16:17:51 -04:00
|
|
|
writer.write_all(self.key_image_share.compress().to_bytes().as_ref())
|
2022-10-25 23:17:25 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 21:36:18 -04:00
|
|
|
#[allow(non_snake_case)]
|
2022-07-22 02:34:36 -04:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
2022-05-06 19:07:37 -04:00
|
|
|
struct Interim {
|
2022-05-13 20:26:29 -04:00
|
|
|
p: Scalar,
|
2022-04-21 21:36:18 -04:00
|
|
|
c: Scalar,
|
|
|
|
|
|
|
|
|
|
clsag: Clsag,
|
2022-07-15 01:26:07 -04:00
|
|
|
pseudo_out: EdwardsPoint,
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
/// FROST-inspired algorithm for producing a CLSAG signature.
|
2022-04-21 21:36:18 -04:00
|
|
|
#[allow(non_snake_case)]
|
2022-06-05 07:33:15 -04:00
|
|
|
#[derive(Clone, Debug)]
|
2024-06-13 18:54:18 -04:00
|
|
|
pub struct ClsagMultisig {
|
2022-06-24 18:58:24 -04:00
|
|
|
transcript: RecommendedTranscript,
|
2022-05-06 07:33:08 -04:00
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
key_image_generator: EdwardsPoint,
|
2024-04-21 22:50:07 -04:00
|
|
|
key_image_shares: HashMap<[u8; 32], dfg::EdwardsPoint>,
|
|
|
|
|
image: Option<dfg::EdwardsPoint>,
|
2022-04-21 21:36:18 -04:00
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
context: ClsagContext,
|
|
|
|
|
|
2024-06-14 17:12:46 -04:00
|
|
|
mask_recv: Option<ClsagMultisigMaskReceiver>,
|
2024-06-14 16:17:51 -04:00
|
|
|
mask: Option<Scalar>,
|
2022-04-29 22:03:34 -04:00
|
|
|
|
2022-05-18 00:53:13 -04:00
|
|
|
msg: Option<[u8; 32]>,
|
2022-07-15 01:26:07 -04:00
|
|
|
interim: Option<Interim>,
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
2022-05-21 15:33:35 -04:00
|
|
|
impl ClsagMultisig {
|
2024-06-14 16:17:51 -04:00
|
|
|
/// Construct a new instance of multisignature CLSAG signing.
|
|
|
|
|
///
|
|
|
|
|
/// Before this has its `process_addendum` called, a mask must be set. Else this will panic.
|
2024-06-13 18:54:18 -04:00
|
|
|
pub fn new(
|
2022-06-24 18:58:24 -04:00
|
|
|
transcript: RecommendedTranscript,
|
2024-06-14 16:17:51 -04:00
|
|
|
context: ClsagContext,
|
2024-06-14 17:12:46 -04:00
|
|
|
) -> (ClsagMultisig, ClsagMultisigMaskSender) {
|
|
|
|
|
let (mask_send, mask_recv) = ClsagMultisigMaskSender::new();
|
|
|
|
|
(
|
|
|
|
|
ClsagMultisig {
|
|
|
|
|
transcript,
|
|
|
|
|
|
|
|
|
|
key_image_generator: hash_to_point(context.decoys.signer_ring_members()[0].compress().0),
|
|
|
|
|
key_image_shares: HashMap::new(),
|
|
|
|
|
image: None,
|
|
|
|
|
|
|
|
|
|
context,
|
|
|
|
|
|
|
|
|
|
mask_recv: Some(mask_recv),
|
|
|
|
|
mask: None,
|
|
|
|
|
|
|
|
|
|
msg: None,
|
|
|
|
|
interim: None,
|
|
|
|
|
},
|
|
|
|
|
mask_send,
|
|
|
|
|
)
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
2022-04-30 04:32:19 -04:00
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
/// The key image generator used by the signer.
|
|
|
|
|
pub fn key_image_generator(&self) -> EdwardsPoint {
|
|
|
|
|
self.key_image_generator
|
2022-05-06 19:07:37 -04:00
|
|
|
}
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
2022-05-21 15:33:35 -04:00
|
|
|
impl Algorithm<Ed25519> for ClsagMultisig {
|
2022-06-24 18:58:24 -04:00
|
|
|
type Transcript = RecommendedTranscript;
|
2022-10-25 23:17:25 -05:00
|
|
|
type Addendum = ClsagAddendum;
|
2024-06-14 16:17:51 -04:00
|
|
|
// We output the CLSAG and the key image, which requires an interactive protocol to obtain
|
2022-04-21 21:36:18 -04:00
|
|
|
type Signature = (Clsag, EdwardsPoint);
|
|
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
// We need the nonce represented against both G and the key image generator
|
2022-07-12 01:28:01 -04:00
|
|
|
fn nonces(&self) -> Vec<Vec<dfg::EdwardsPoint>> {
|
2024-06-14 16:17:51 -04:00
|
|
|
vec![vec![dfg::EdwardsPoint::generator(), dfg::EdwardsPoint(self.key_image_generator)]]
|
2022-07-12 01:28:01 -04:00
|
|
|
}
|
|
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
// We also publish our share of the key image
|
2022-04-21 21:36:18 -04:00
|
|
|
fn preprocess_addendum<R: RngCore + CryptoRng>(
|
2022-05-17 19:15:53 -04:00
|
|
|
&mut self,
|
2024-04-21 22:50:07 -04:00
|
|
|
_rng: &mut R,
|
2022-12-08 19:04:35 -05:00
|
|
|
keys: &ThresholdKeys<Ed25519>,
|
2022-10-25 23:17:25 -05:00
|
|
|
) -> ClsagAddendum {
|
2024-06-14 16:17:51 -04:00
|
|
|
ClsagAddendum {
|
|
|
|
|
key_image_share: dfg::EdwardsPoint(self.key_image_generator) * keys.secret_share().deref(),
|
|
|
|
|
}
|
2022-10-25 23:17:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn read_addendum<R: Read>(&self, reader: &mut R) -> io::Result<ClsagAddendum> {
|
|
|
|
|
let mut bytes = [0; 32];
|
|
|
|
|
reader.read_exact(&mut bytes)?;
|
|
|
|
|
// dfg ensures the point is torsion free
|
|
|
|
|
let xH = Option::<dfg::EdwardsPoint>::from(dfg::EdwardsPoint::from_bytes(&bytes))
|
2023-11-19 18:01:13 -05:00
|
|
|
.ok_or_else(|| io::Error::other("invalid key image"))?;
|
2022-10-25 23:17:25 -05:00
|
|
|
// Ensure this is a canonical point
|
|
|
|
|
if xH.to_bytes() != bytes {
|
2023-11-19 18:01:13 -05:00
|
|
|
Err(io::Error::other("non-canonical key image"))?;
|
2022-10-25 23:17:25 -05:00
|
|
|
}
|
|
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
Ok(ClsagAddendum { key_image_share: xH })
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
2022-10-25 23:17:25 -05:00
|
|
|
fn process_addendum(
|
2022-04-21 21:36:18 -04:00
|
|
|
&mut self,
|
2022-10-29 03:54:42 -05:00
|
|
|
view: &ThresholdView<Ed25519>,
|
2023-02-23 06:50:45 -05:00
|
|
|
l: Participant,
|
2022-10-25 23:17:25 -05:00
|
|
|
addendum: ClsagAddendum,
|
2022-04-21 21:36:18 -04:00
|
|
|
) -> Result<(), FrostError> {
|
2024-04-21 22:50:07 -04:00
|
|
|
if self.image.is_none() {
|
2022-05-06 07:33:08 -04:00
|
|
|
self.transcript.domain_separate(b"CLSAG");
|
2024-04-21 22:50:07 -04:00
|
|
|
// Transcript the ring
|
2024-06-14 16:17:51 -04:00
|
|
|
self.context.transcript(&mut self.transcript);
|
|
|
|
|
// Fetch the mask from the Mutex
|
|
|
|
|
// We set it to a variable to ensure our view of it is consistent
|
|
|
|
|
// It was this or a mpsc channel... std doesn't have oneshot :/
|
2024-06-14 17:12:46 -04:00
|
|
|
self.mask = Some(self.mask_recv.take().unwrap().recv());
|
2024-04-21 22:50:07 -04:00
|
|
|
// Transcript the mask
|
2024-06-14 16:17:51 -04:00
|
|
|
self.transcript.append_message(b"mask", self.mask.expect("mask wasn't set").to_bytes());
|
2024-04-21 22:50:07 -04:00
|
|
|
|
|
|
|
|
// Init the image to the offset
|
2024-06-14 16:17:51 -04:00
|
|
|
self.image = Some(dfg::EdwardsPoint(self.key_image_generator) * view.offset());
|
2022-05-06 07:33:08 -04:00
|
|
|
}
|
|
|
|
|
|
2024-04-21 22:50:07 -04:00
|
|
|
// Transcript this participant's contribution
|
2023-02-23 06:50:45 -05:00
|
|
|
self.transcript.append_message(b"participant", l.to_bytes());
|
2024-06-14 16:17:51 -04:00
|
|
|
self
|
|
|
|
|
.transcript
|
|
|
|
|
.append_message(b"key_image_share", addendum.key_image_share.compress().to_bytes());
|
2022-10-25 23:17:25 -05:00
|
|
|
|
2024-04-21 22:50:07 -04:00
|
|
|
// Accumulate the interpolated share
|
|
|
|
|
let interpolated_key_image_share =
|
2024-06-14 16:17:51 -04:00
|
|
|
addendum.key_image_share * lagrange::<dfg::Scalar>(l, view.included());
|
2024-04-21 22:50:07 -04:00
|
|
|
*self.image.as_mut().unwrap() += interpolated_key_image_share;
|
2022-10-25 23:17:25 -05:00
|
|
|
|
2024-04-21 22:50:07 -04:00
|
|
|
self
|
|
|
|
|
.key_image_shares
|
|
|
|
|
.insert(view.verification_share(l).to_bytes(), interpolated_key_image_share);
|
2022-04-21 21:36:18 -04:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 07:33:08 -04:00
|
|
|
fn transcript(&mut self) -> &mut Self::Transcript {
|
|
|
|
|
&mut self.transcript
|
2022-04-29 15:28:04 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-21 21:36:18 -04:00
|
|
|
fn sign_share(
|
|
|
|
|
&mut self,
|
2022-10-29 03:54:42 -05:00
|
|
|
view: &ThresholdView<Ed25519>,
|
2022-07-12 01:28:01 -04:00
|
|
|
nonce_sums: &[Vec<dfg::EdwardsPoint>],
|
2022-11-10 22:35:09 -05:00
|
|
|
nonces: Vec<Zeroizing<dfg::Scalar>>,
|
2022-07-15 01:26:07 -04:00
|
|
|
msg: &[u8],
|
2022-04-21 21:36:18 -04:00
|
|
|
) -> dfg::Scalar {
|
2022-05-03 07:20:24 -04:00
|
|
|
// Use the transcript to get a seeded random number generator
|
2024-06-14 16:17:51 -04:00
|
|
|
//
|
2022-05-03 07:20:24 -04:00
|
|
|
// The transcript contains private data, preventing passive adversaries from recreating this
|
2024-06-14 16:17:51 -04:00
|
|
|
// process even if they have access to the commitments/key image share broadcast so far
|
|
|
|
|
//
|
|
|
|
|
// Specifically, the transcript contains the signer's index within the ring, along with the
|
|
|
|
|
// opening of the commitment being re-randomized (and what it's re-randomized to)
|
2022-08-30 20:01:46 -04:00
|
|
|
let mut rng = ChaCha20Rng::from_seed(self.transcript.rng_seed(b"decoy_responses"));
|
2022-04-28 12:01:20 -04:00
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
// TODO: Accept the message preimage and remove this panic
|
2022-05-18 00:53:13 -04:00
|
|
|
self.msg = Some(msg.try_into().expect("CLSAG message should be 32-bytes"));
|
|
|
|
|
|
2024-04-22 00:25:58 -04:00
|
|
|
let sign_core = Clsag::sign_core(
|
2022-04-28 17:12:54 -04:00
|
|
|
&mut rng,
|
2024-04-21 22:50:07 -04:00
|
|
|
&self.image.expect("verifying a share despite never processing any addendums").0,
|
2024-06-14 16:17:51 -04:00
|
|
|
&self.context,
|
|
|
|
|
self.mask.expect("mask wasn't set"),
|
2022-07-22 02:34:36 -04:00
|
|
|
self.msg.as_ref().unwrap(),
|
2022-07-12 01:28:01 -04:00
|
|
|
nonce_sums[0][0].0,
|
2022-07-15 01:26:07 -04:00
|
|
|
nonce_sums[0][1].0,
|
2022-04-23 03:49:30 -04:00
|
|
|
);
|
2024-04-22 00:25:58 -04:00
|
|
|
self.interim = Some(Interim {
|
|
|
|
|
p: sign_core.key_challenge,
|
|
|
|
|
c: sign_core.challenged_mask,
|
|
|
|
|
clsag: sign_core.incomplete_clsag,
|
|
|
|
|
pseudo_out: sign_core.pseudo_out,
|
|
|
|
|
});
|
2022-04-21 21:36:18 -04:00
|
|
|
|
2024-04-21 22:50:07 -04:00
|
|
|
// r - p x, where p is the challenge for the keys
|
2024-04-22 00:25:58 -04:00
|
|
|
*nonces[0] - dfg::Scalar(sign_core.key_challenge) * view.secret_share().deref()
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-07 14:28:42 -04:00
|
|
|
#[must_use]
|
2022-04-21 21:36:18 -04:00
|
|
|
fn verify(
|
|
|
|
|
&self,
|
|
|
|
|
_: dfg::EdwardsPoint,
|
2022-07-12 01:28:01 -04:00
|
|
|
_: &[Vec<dfg::EdwardsPoint>],
|
2022-07-15 01:26:07 -04:00
|
|
|
sum: dfg::Scalar,
|
2022-04-21 21:36:18 -04:00
|
|
|
) -> Option<Self::Signature> {
|
|
|
|
|
let interim = self.interim.as_ref().unwrap();
|
|
|
|
|
let mut clsag = interim.clsag.clone();
|
2024-06-14 16:17:51 -04:00
|
|
|
// We produced shares as `r - p x`, yet the signature is actually `r - p x - c x`
|
2024-04-21 22:50:07 -04:00
|
|
|
// Substract `c x` (saved as `c`) now
|
2024-06-14 16:17:51 -04:00
|
|
|
clsag.s[usize::from(self.context.decoys.signer_index())] = sum.0 - interim.c;
|
2022-07-15 01:26:07 -04:00
|
|
|
if clsag
|
|
|
|
|
.verify(
|
2024-06-14 16:17:51 -04:00
|
|
|
self.context.decoys.ring(),
|
2024-04-21 22:50:07 -04:00
|
|
|
&self.image.expect("verifying a signature despite never processing any addendums").0,
|
2022-07-15 01:26:07 -04:00
|
|
|
&interim.pseudo_out,
|
2022-07-22 02:34:36 -04:00
|
|
|
self.msg.as_ref().unwrap(),
|
2022-07-15 01:26:07 -04:00
|
|
|
)
|
|
|
|
|
.is_ok()
|
|
|
|
|
{
|
2022-05-13 20:26:29 -04:00
|
|
|
return Some((clsag, interim.pseudo_out));
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
2022-07-22 02:34:36 -04:00
|
|
|
None
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn verify_share(
|
|
|
|
|
&self,
|
|
|
|
|
verification_share: dfg::EdwardsPoint,
|
2022-07-12 01:28:01 -04:00
|
|
|
nonces: &[Vec<dfg::EdwardsPoint>],
|
2022-04-21 21:36:18 -04:00
|
|
|
share: dfg::Scalar,
|
2022-12-13 20:25:32 -05:00
|
|
|
) -> Result<Vec<(dfg::Scalar, dfg::EdwardsPoint)>, ()> {
|
2022-04-21 21:36:18 -04:00
|
|
|
let interim = self.interim.as_ref().unwrap();
|
2024-04-21 22:50:07 -04:00
|
|
|
|
|
|
|
|
// For a share `r - p x`, the following two equalities should hold:
|
|
|
|
|
// - `(r - p x)G == R.0 - pV`, where `V = xG`
|
|
|
|
|
// - `(r - p x)H == R.1 - pK`, where `K = xH` (the key image share)
|
|
|
|
|
//
|
|
|
|
|
// This is effectively a discrete log equality proof for:
|
|
|
|
|
// V, K over G, H
|
|
|
|
|
// with nonces
|
|
|
|
|
// R.0, R.1
|
|
|
|
|
// and solution
|
|
|
|
|
// s
|
|
|
|
|
//
|
|
|
|
|
// Which is a batch-verifiable rewrite of the traditional CP93 proof
|
|
|
|
|
// (and also writable as Generalized Schnorr Protocol)
|
|
|
|
|
//
|
|
|
|
|
// That means that given a proper challenge, this alone can be certainly argued to prove the
|
|
|
|
|
// key image share is well-formed and the provided signature so proves for that.
|
|
|
|
|
|
|
|
|
|
// This is a bit funky as it doesn't prove the nonces are well-formed however. They're part of
|
|
|
|
|
// the prover data/transcript for a CP93/GSP proof, not part of the statement. This practically
|
|
|
|
|
// is fine, for a variety of reasons (given a consistent `x`, a consistent `r` can be
|
|
|
|
|
// extracted, and the nonces as used in CLSAG are also part of its prover data/transcript).
|
|
|
|
|
|
|
|
|
|
let key_image_share = self.key_image_shares[&verification_share.to_bytes()];
|
|
|
|
|
|
2024-06-14 16:17:51 -04:00
|
|
|
// Hash every variable relevant here, using the hash output as the random weight
|
2024-04-21 22:50:07 -04:00
|
|
|
let mut weight_transcript =
|
|
|
|
|
RecommendedTranscript::new(b"monero-serai v0.1 ClsagMultisig::verify_share");
|
|
|
|
|
weight_transcript.append_message(b"G", dfg::EdwardsPoint::generator().to_bytes());
|
2024-06-14 16:17:51 -04:00
|
|
|
weight_transcript.append_message(b"H", self.key_image_generator.to_bytes());
|
2024-04-21 22:50:07 -04:00
|
|
|
weight_transcript.append_message(b"xG", verification_share.to_bytes());
|
|
|
|
|
weight_transcript.append_message(b"xH", key_image_share.to_bytes());
|
|
|
|
|
weight_transcript.append_message(b"rG", nonces[0][0].to_bytes());
|
|
|
|
|
weight_transcript.append_message(b"rH", nonces[0][1].to_bytes());
|
|
|
|
|
weight_transcript.append_message(b"c", dfg::Scalar(interim.p).to_repr());
|
|
|
|
|
weight_transcript.append_message(b"s", share.to_repr());
|
|
|
|
|
let weight = weight_transcript.challenge(b"weight");
|
|
|
|
|
let weight = dfg::Scalar(Scalar::from_bytes_mod_order_wide(&weight.into()));
|
|
|
|
|
|
|
|
|
|
let part_one = vec![
|
2022-12-13 20:25:32 -05:00
|
|
|
(share, dfg::EdwardsPoint::generator()),
|
2024-04-21 22:50:07 -04:00
|
|
|
// -(R.0 - pV) == -R.0 + pV
|
2023-03-28 04:38:01 -04:00
|
|
|
(-dfg::Scalar::ONE, nonces[0][0]),
|
2024-04-21 22:50:07 -04:00
|
|
|
(dfg::Scalar(interim.p), verification_share),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let mut part_two = vec![
|
2024-06-14 16:17:51 -04:00
|
|
|
(weight * share, dfg::EdwardsPoint(self.key_image_generator)),
|
2024-04-21 22:50:07 -04:00
|
|
|
// -(R.1 - pK) == -R.1 + pK
|
|
|
|
|
(-weight, nonces[0][1]),
|
|
|
|
|
(weight * dfg::Scalar(interim.p), key_image_share),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let mut all = part_one;
|
|
|
|
|
all.append(&mut part_two);
|
|
|
|
|
Ok(all)
|
2022-04-21 21:36:18 -04:00
|
|
|
}
|
|
|
|
|
}
|