Skip to content

Commit

Permalink
fix: fix small issues related to #3020 (#3026)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Jul 1, 2021
2 parents ef94134 + ec5390f commit da1d757
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 25 deletions.
2 changes: 1 addition & 1 deletion base_layer/core/src/transactions/aggregated_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl AggregateBody {
fn validate_sender_signatures(&self) -> Result<(), TransactionError> {
trace!(target: LOG_TARGET, "Checking sender signatures");
for o in &self.outputs {
let _ = o.verify_sender_signature()?;
o.verify_sender_signature()?;
}
Ok(())
}
Expand Down
11 changes: 6 additions & 5 deletions base_layer/core/src/transactions/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ pub enum TransactionError {

/// An unblinded output is one where the value and spending key (blinding factor) are known. This can be used to
/// build both inputs and outputs (every input comes from an output)
// TODO: Try to get rid of 'Serialize' and 'Deserialize' traits here; see related comment at 'struct RawTransactionInfo'
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnblindedOutput {
pub value: MicroTari,
Expand Down Expand Up @@ -422,7 +423,7 @@ impl TransactionInput {
}

/// This will check if the input and the output is the same commitment by looking at the commitment and features.
/// This will ignore the output rangeproof
/// This will ignore the output range proof
pub fn is_equal_to(&self, output: &TransactionOutput) -> bool {
self.commitment == output.commitment && self.features == output.features
}
Expand Down Expand Up @@ -632,7 +633,7 @@ impl TransactionOutput {
}

/// This will check if the input and the output is the same commitment by looking at the commitment and features.
/// This will ignore the output rangeproof
/// This will ignore the output range proof
#[inline]
pub fn is_equal_to(&self, output: &TransactionInput) -> bool {
self.commitment == output.commitment && self.features == output.features
Expand All @@ -659,7 +660,7 @@ impl TransactionOutput {
.to_vec()
}

/// Create sender signature fore the output meta data
/// Create sender signature for the output meta data
pub fn create_sender_signature(
script: &TariScript,
output_features: &OutputFeatures,
Expand Down Expand Up @@ -1050,7 +1051,7 @@ impl Transaction {
.fold(0, |max_maturity, input| max(max_maturity, input.features.maturity))
}

/// Returns the maximum timelock of the kernels inside of the transaction
/// Returns the maximum time lock of the kernels inside of the transaction
pub fn max_kernel_timelock(&self) -> u64 {
self.body
.kernels()
Expand Down Expand Up @@ -1381,7 +1382,7 @@ mod test {
let mut kernel = create_test_kernel(0.into(), 0);
let mut tx = Transaction::new(Vec::new(), Vec::new(), Vec::new(), 0.into(), 0.into());

// lets add timelocks
// lets add time locks
input.features.maturity = 5;
kernel.lock_height = 2;
tx.body.add_input(input.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ use tari_crypto::{

/// This struct contains all the information that a transaction initiator (the sender) will manage throughout the
/// Transaction construction process.
// TODO: Investigate necessity to use the 'Serialize' and 'Deserialize' traits here; this could potentially leak
// TODO: information when least expected.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub(super) struct RawTransactionInfo {
pub num_recipients: usize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl SingleReceiverTransactionProtocol {
sender_info.script_offset_public_key.clone(),
sender_info.sender_metadata_signature.clone(),
);
let _ = output.verify_sender_signature()?;
output.verify_sender_signature()?;
Ok(output)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ CREATE TABLE outputs (
height INTEGER NOT NULL,
script_private_key BLOB NOT NULL,
script_offset_public_key BLOB NOT NULL,
sender_metadata_signature TEXT NOT NULL,
sender_metadata_signature_key BLOB NOT NULL,
sender_metadata_signature_nonce BLOB NOT NULL,
CONSTRAINT unique_commitment UNIQUE (commitment)
);
PRAGMA foreign_keys=on;
44 changes: 34 additions & 10 deletions base_layer/wallet/src/output_manager_service/storage/sqlite_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use tari_core::{
transactions::{
tari_amount::MicroTari,
transaction::{OutputFeatures, OutputFlags, UnblindedOutput},
types::{Commitment, CryptoFactories, PrivateKey, PublicKey},
types::{Commitment, CryptoFactories, PrivateKey, PublicKey, Signature},
},
};
use tari_crypto::{
Expand Down Expand Up @@ -883,7 +883,8 @@ struct NewOutputSql {
height: i64,
script_private_key: Vec<u8>,
script_offset_public_key: Vec<u8>,
sender_metadata_signature: String,
sender_metadata_signature_key: Vec<u8>,
sender_metadata_signature_nonce: Vec<u8>,
}

impl NewOutputSql {
Expand All @@ -892,8 +893,6 @@ impl NewOutputSql {
status: OutputStatus,
tx_id: Option<TxId>,
) -> Result<Self, OutputManagerStorageError> {
let sender_metadata_signature = serde_json::to_string(&output.unblinded_output.sender_metadata_signature)
.map_err(|e| OutputManagerStorageError::UnexpectedResult(e.to_string()))?;
Ok(Self {
commitment: Some(output.commitment.to_vec()),
spending_key: output.unblinded_output.spending_key.to_vec(),
Expand All @@ -908,7 +907,16 @@ impl NewOutputSql {
height: output.unblinded_output.height as i64,
script_private_key: output.unblinded_output.script_private_key.to_vec(),
script_offset_public_key: output.unblinded_output.script_offset_public_key.to_vec(),
sender_metadata_signature,
sender_metadata_signature_key: output
.unblinded_output
.sender_metadata_signature
.get_signature()
.to_vec(),
sender_metadata_signature_nonce: output
.unblinded_output
.sender_metadata_signature
.get_public_nonce()
.to_vec(),
})
}

Expand Down Expand Up @@ -950,7 +958,8 @@ struct OutputSql {
height: i64,
script_private_key: Vec<u8>,
script_offset_public_key: Vec<u8>,
sender_metadata_signature: String,
sender_metadata_signature_key: Vec<u8>,
sender_metadata_signature_nonce: Vec<u8>,
}

impl OutputSql {
Expand Down Expand Up @@ -1133,12 +1142,26 @@ impl TryFrom<OutputSql> for DbUnblindedOutput {
PublicKey::from_vec(&o.script_offset_public_key).map_err(|_| {
error!(
target: LOG_TARGET,
"Could not create PrivateKey from stored bytes, They might be encrypted"
"Could not create PublicKey from stored bytes, They might be encrypted"
);
OutputManagerStorageError::ConversionError
})?,
serde_json::from_str(&o.sender_metadata_signature)
.map_err(|e| OutputManagerStorageError::UnexpectedResult(e.to_string()))?,
Signature::new(
PublicKey::from_vec(&o.sender_metadata_signature_nonce).map_err(|_| {
error!(
target: LOG_TARGET,
"Could not create PublicKey from stored bytes, They might be encrypted"
);
OutputManagerStorageError::ConversionError
})?,
PrivateKey::from_vec(&o.sender_metadata_signature_key).map_err(|_| {
error!(
target: LOG_TARGET,
"Could not create PrivateKey from stored bytes, They might be encrypted"
);
OutputManagerStorageError::ConversionError
})?,
),
);

let hash = match o.hash {
Expand Down Expand Up @@ -1196,7 +1219,8 @@ impl From<OutputSql> for NewOutputSql {
height: o.height,
script_private_key: o.script_private_key,
script_offset_public_key: o.script_offset_public_key,
sender_metadata_signature: o.sender_metadata_signature,
sender_metadata_signature_key: o.sender_metadata_signature_key,
sender_metadata_signature_nonce: o.sender_metadata_signature_nonce,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion base_layer/wallet/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ table! {
height -> BigInt,
script_private_key -> Binary,
script_offset_public_key -> Binary,
sender_metadata_signature -> Text,
sender_metadata_signature_key -> Binary,
sender_metadata_signature_nonce -> Binary,
}
}

Expand Down
9 changes: 5 additions & 4 deletions base_layer/wallet/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

// Note: For help in getting started with diesel as well as how to update the tables look here:
// http://diesel.rs/guides/getting-started/
// - You also need to ensure that you installed diesel with the sqlite feature flag cargo install diesel_cli
// --no-default-features --features sqlite
// - If you updated the tables the following needs to be run from the base_layer/wallet/ folder: diesel setup
// --database-url test.sqlite3 diesel migration run --database-url test.sqlite3
// - You also need to ensure that you installed diesel with the sqlite feature flag:
// - 'cargo install diesel_cli --no-default-features --features sqlite'
// - If you updated the tables the following needs to be run from the base_layer/wallet/ folder:
// - 'diesel setup --database-url test.sqlite3'
// - 'diesel migration run --database-url test.sqlite3'
// - After running this, make sure that the diesel update did not change BigInt to Integer in 'schema.rs' (check for
// any unwanted changes)

Expand Down
4 changes: 2 additions & 2 deletions base_layer/wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ where
source_public_key: &CommsPublicKey,
features: OutputFeatures,
message: String,
sender_signature: Signature,
sender_metadata_signature: Signature,
script_private_key: &PrivateKey,
script_offset_public_key: &PublicKey,
) -> Result<TxId, WalletError> {
Expand All @@ -329,7 +329,7 @@ where
0,
script_private_key.clone(),
script_offset_public_key.clone(),
sender_signature,
sender_metadata_signature,
);

let tx_id = self
Expand Down

0 comments on commit da1d757

Please sign in to comment.