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
|
|
|
use std::marker::Send;
|
2022-06-24 19:53:41 -04:00
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
|
|
use transcript::RecommendedTranscript;
|
2022-06-28 00:06:12 -04:00
|
|
|
use frost::{curve::Curve, FrostKeys, sign::PreprocessMachine};
|
2022-06-24 19:53:41 -04:00
|
|
|
|
|
|
|
|
pub mod monero;
|
|
|
|
|
pub use self::monero::Monero;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Error, Debug)]
|
|
|
|
|
pub enum CoinError {
|
|
|
|
|
#[error("failed to connect to coin daemon")]
|
2022-07-15 01:26:07 -04:00
|
|
|
ConnectionError,
|
2022-06-24 19:53:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait Output: Sized + Clone {
|
|
|
|
|
type Id: AsRef<[u8]>;
|
|
|
|
|
|
|
|
|
|
fn id(&self) -> Self::Id;
|
|
|
|
|
fn amount(&self) -> u64;
|
|
|
|
|
|
|
|
|
|
fn serialize(&self) -> Vec<u8>;
|
|
|
|
|
fn deserialize<R: std::io::Read>(reader: &mut R) -> std::io::Result<Self>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
|
pub trait Coin {
|
|
|
|
|
type Curve: Curve;
|
|
|
|
|
|
|
|
|
|
type Fee: Copy;
|
|
|
|
|
type Transaction;
|
|
|
|
|
type Block;
|
|
|
|
|
|
|
|
|
|
type Output: Output;
|
|
|
|
|
type SignableTransaction;
|
|
|
|
|
type TransactionMachine: PreprocessMachine<Signature = Self::Transaction>;
|
|
|
|
|
|
|
|
|
|
type Address: Send;
|
|
|
|
|
|
|
|
|
|
const ID: &'static [u8];
|
|
|
|
|
const CONFIRMATIONS: usize;
|
|
|
|
|
const MAX_INPUTS: usize;
|
|
|
|
|
const MAX_OUTPUTS: usize; // TODO: Decide if this includes change or not
|
|
|
|
|
|
|
|
|
|
// Doesn't have to take self, enables some level of caching which is pleasant
|
|
|
|
|
fn address(&self, key: <Self::Curve as Curve>::G) -> Self::Address;
|
|
|
|
|
|
2022-10-15 21:39:06 -04:00
|
|
|
async fn get_latest_block_number(&self) -> Result<usize, CoinError>;
|
|
|
|
|
async fn get_block(&self, number: usize) -> Result<Self::Block, CoinError>;
|
2022-06-24 19:53:41 -04:00
|
|
|
async fn get_outputs(
|
|
|
|
|
&self,
|
|
|
|
|
block: &Self::Block,
|
2022-07-15 01:26:07 -04:00
|
|
|
key: <Self::Curve as Curve>::G,
|
2022-08-22 12:15:14 -04:00
|
|
|
) -> Result<Vec<Self::Output>, CoinError>;
|
2022-06-24 19:53:41 -04:00
|
|
|
|
2022-10-15 19:51:59 -04:00
|
|
|
// TODO: Remove
|
2022-10-15 21:39:06 -04:00
|
|
|
async fn is_confirmed(&self, tx: &[u8]) -> Result<bool, CoinError>;
|
2022-10-15 19:51:59 -04:00
|
|
|
|
2022-06-24 19:53:41 -04:00
|
|
|
async fn prepare_send(
|
|
|
|
|
&self,
|
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
|
|
|
keys: FrostKeys<Self::Curve>,
|
2022-06-24 19:53:41 -04:00
|
|
|
transcript: RecommendedTranscript,
|
2022-10-15 21:39:06 -04:00
|
|
|
block_number: usize,
|
2022-06-24 19:53:41 -04:00
|
|
|
inputs: Vec<Self::Output>,
|
|
|
|
|
payments: &[(Self::Address, u64)],
|
2022-07-15 01:26:07 -04:00
|
|
|
fee: Self::Fee,
|
2022-06-24 19:53:41 -04:00
|
|
|
) -> Result<Self::SignableTransaction, CoinError>;
|
|
|
|
|
|
|
|
|
|
async fn attempt_send(
|
|
|
|
|
&self,
|
|
|
|
|
transaction: Self::SignableTransaction,
|
2022-07-15 01:26:07 -04:00
|
|
|
included: &[u16],
|
2022-06-24 19:53:41 -04:00
|
|
|
) -> Result<Self::TransactionMachine, CoinError>;
|
|
|
|
|
|
|
|
|
|
async fn publish_transaction(
|
|
|
|
|
&self,
|
2022-07-15 01:26:07 -04:00
|
|
|
tx: &Self::Transaction,
|
2022-06-24 19:53:41 -04:00
|
|
|
) -> Result<(Vec<u8>, Vec<<Self::Output as Output>::Id>), CoinError>;
|
|
|
|
|
|
2022-10-16 13:11:32 -04:00
|
|
|
#[cfg(test)]
|
2022-10-15 23:21:43 -04:00
|
|
|
async fn get_fee(&self) -> Self::Fee;
|
|
|
|
|
|
2022-10-16 13:11:32 -04:00
|
|
|
#[cfg(test)]
|
2022-06-28 00:01:20 -04:00
|
|
|
async fn mine_block(&self);
|
2022-06-24 19:53:41 -04:00
|
|
|
|
2022-10-16 13:11:32 -04:00
|
|
|
#[cfg(test)]
|
2022-06-24 19:53:41 -04:00
|
|
|
async fn test_send(&self, key: Self::Address);
|
|
|
|
|
}
|