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
This commit is contained in:
Luke Parker
2022-08-03 03:25:18 -05:00
committed by GitHub
parent a30568ff57
commit 797be71eb3
56 changed files with 698 additions and 425 deletions

View File

@@ -1,4 +1,4 @@
use std::{marker::Send, sync::Arc};
use std::marker::Send;
use async_trait::async_trait;
use thiserror::Error;
@@ -57,7 +57,7 @@ pub trait Coin {
async fn prepare_send(
&self,
keys: Arc<FrostKeys<Self::Curve>>,
keys: FrostKeys<Self::Curve>,
transcript: RecommendedTranscript,
height: usize,
inputs: Vec<Self::Output>,

View File

@@ -1,5 +1,3 @@
use std::sync::Arc;
use async_trait::async_trait;
use curve25519_dalek::scalar::Scalar;
@@ -57,7 +55,7 @@ impl OutputTrait for Output {
#[derive(Debug)]
pub struct SignableTransaction(
Arc<FrostKeys<Ed25519>>,
FrostKeys<Ed25519>,
RecommendedTranscript,
usize,
MSignableTransaction,
@@ -137,14 +135,14 @@ impl Coin for Monero {
async fn get_outputs(&self, block: &Self::Block, key: dfg::EdwardsPoint) -> Vec<Self::Output> {
block
.iter()
.flat_map(|tx| tx.scan(self.view_pair(key), true).not_locked())
.flat_map(|tx| tx.scan(&self.view_pair(key), true).not_locked())
.map(Output::from)
.collect()
}
async fn prepare_send(
&self,
keys: Arc<FrostKeys<Ed25519>>,
keys: FrostKeys<Ed25519>,
transcript: RecommendedTranscript,
height: usize,
mut inputs: Vec<Output>,
@@ -177,7 +175,7 @@ impl Coin for Monero {
.clone()
.multisig(
&self.rpc,
(*transaction.0).clone(),
transaction.0.clone(),
transaction.1.clone(),
transaction.2,
included.to_vec(),
@@ -235,7 +233,7 @@ impl Coin for Monero {
.await
.unwrap()
.swap_remove(0)
.scan(self.empty_view_pair(), false)
.scan(&self.empty_view_pair(), false)
.ignore_timelock();
let amount = outputs[0].commitment.amount;

View File

@@ -71,7 +71,7 @@ async fn test_send<C: Coin + Clone>(coin: C, fee: C::Fee) {
for i in 1 ..= threshold {
let mut wallet = Wallet::new(MemCoinDb::new(), coin.clone());
wallet.acknowledge_height(0, height);
wallet.add_keys(&WalletKeys::new(Arc::try_unwrap(keys.remove(&i).take().unwrap()).unwrap(), 0));
wallet.add_keys(&WalletKeys::new(keys.remove(&i).unwrap(), 0));
wallets.push(wallet);
}

View File

@@ -1,4 +1,4 @@
use std::{sync::Arc, collections::HashMap};
use std::collections::HashMap;
use rand_core::OsRng;
@@ -203,7 +203,7 @@ fn select_inputs_outputs<C: Coin>(
pub struct Wallet<D: CoinDb, C: Coin> {
db: D,
coin: C,
keys: Vec<(Arc<FrostKeys<C::Curve>>, Vec<C::Output>)>,
keys: Vec<(FrostKeys<C::Curve>, Vec<C::Output>)>,
pending: Vec<(usize, FrostKeys<C::Curve>)>,
}
@@ -249,7 +249,7 @@ impl<D: CoinDb, C: Coin> Wallet<D, C> {
//if b < self.pending[k].0 {
//} else if b == self.pending[k].0 {
if b <= self.pending[k].0 {
self.keys.push((Arc::new(self.pending.swap_remove(k).1), vec![]));
self.keys.push((self.pending.swap_remove(k).1, vec![]));
} else {
k += 1;
}