Skip to content

Commit

Permalink
Change script_signature type to ComSig
Browse files Browse the repository at this point in the history
Fix cucumber test for comsig

update gen block
  • Loading branch information
SWvheerden committed Jun 18, 2021
1 parent 4b4af99 commit fac6be0
Show file tree
Hide file tree
Showing 30 changed files with 195 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion applications/tari_app_grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"
tari_common_types = { version = "^0.8", path = "../../base_layer/common_types"}
tari_core = { path = "../../base_layer/core"}
tari_wallet = { path = "../../base_layer/wallet"}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge #switch back to official after merge
tari_comms = { path = "../../comms"}

chrono = "0.4.6"
Expand Down
10 changes: 9 additions & 1 deletion applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ message TransactionInput {
// The block height that the UTXO was mined
uint64 height = 6;
// A signature with k_s, signing the script, input data, and mined height
Signature script_signature = 7;
ComSignature script_signature = 7;
// The offset pubkey, K_O
bytes script_offset_public_key = 8;
}
Expand Down Expand Up @@ -225,6 +225,14 @@ message Signature {
bytes signature = 2;
}

// Define the explicit ComSignature implementation for the Tari base layer. A different signature scheme can be
// employed by redefining this type.
message ComSignature {
bytes public_nonce_commitment = 1;
bytes signature_u = 2;
bytes signature_v = 3;
}

/// Consensus Constants response
message ConsensusConstants {
/// The min height maturity a coinbase utxo must have
Expand Down
42 changes: 42 additions & 0 deletions applications/tari_app_grpc/src/conversions/com_signature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2020. The Tari Project
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
// following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
// disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::convert::TryFrom;
use tari_crypto::tari_utilities::ByteArray;

use crate::tari_rpc as grpc;
use tari_core::transactions::types::{ComSignature, Commitment, PrivateKey};

impl TryFrom<grpc::ComSignature> for ComSignature {
type Error = String;

fn try_from(sig: grpc::ComSignature) -> Result<Self, Self::Error> {
let public_nonce = Commitment::from_bytes(&sig.public_nonce_commitment)
.map_err(|_| "Could not get public nonce commitment".to_string())?;
let signature_u =
PrivateKey::from_bytes(&sig.signature_u).map_err(|_| "Could not get partial signature u".to_string())?;
let signature_v =
PrivateKey::from_bytes(&sig.signature_v).map_err(|_| "Could not get partial signature v".to_string())?;

Ok(Self::new(public_nonce, signature_u, signature_v))
}
}
2 changes: 2 additions & 0 deletions applications/tari_app_grpc/src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod aggregate_body;
mod block;
mod block_header;
mod chain_metadata;
mod com_signature;
mod consensus_constants;
mod historical_block;
mod new_block_template;
Expand All @@ -42,6 +43,7 @@ pub use self::{
block::*,
block_header::*,
chain_metadata::*,
com_signature::*,
consensus_constants::*,
historical_block::*,
new_block_template::*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ impl From<TransactionInput> for grpc::TransactionInput {
script: input.script.as_bytes(),
input_data: input.input_data.as_bytes(),
height: input.height,
script_signature: Some(grpc::Signature {
public_nonce: Vec::from(input.script_signature.get_public_nonce().as_bytes()),
signature: Vec::from(input.script_signature.get_signature().as_bytes()),
script_signature: Some(grpc::ComSignature {
public_nonce_commitment: Vec::from(input.script_signature.public_nonce().as_bytes()),
signature_u: Vec::from(input.script_signature.u().as_bytes()),
signature_v: Vec::from(input.script_signature.v().as_bytes()),
}),
script_offset_public_key: input.script_offset_public_key.as_bytes().to_vec(),
}
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_app_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
tari_comms = { path = "../../comms"}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge
tari_common = { path = "../../common" }
tari_p2p = { path = "../../base_layer/p2p" }
tari_wallet = { path = "../../base_layer/wallet" }
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_base_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tari_common = { path = "../../common" }
tari_comms = { path = "../../comms", features = ["rpc"]}
tari_comms_dht = { path = "../../comms/dht"}
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"]}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge
tari_mmr = { path = "../../base_layer/mmr" }
tari_p2p = { path = "../../base_layer/p2p" }
tari_service_framework = { path = "../../base_layer/service_framework"}
Expand Down
3 changes: 1 addition & 2 deletions applications/tari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
tari_wallet = { path = "../../base_layer/wallet" }
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge
tari_common = { path = "../../common" }
tari_app_utilities = { path = "../tari_app_utilities"}
tari_comms = { path = "../../comms"}
Expand Down Expand Up @@ -43,4 +43,3 @@ features = ["transactions", "mempool_proto", "base_node_proto"]
version = "^0.12"
default-features = false
features = ["crossterm"]

2 changes: 1 addition & 1 deletion applications/tari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tari_app_grpc = { path = "../tari_app_grpc" }
tari_common = { path = "../../common" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"]}
tari_app_utilities = { path = "../tari_app_utilities"}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge
tari_utilities = "^0.3"

anyhow = "1.0.40"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_mining_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ thiserror = "1.0"


[dev-dependencies]
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge
prost-types = "0.6.1"
chrono = "0.4"
2 changes: 1 addition & 1 deletion applications/test_faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tari_utilities = "^0.3"
serde = { version = "1.0.97", features = ["derive"] }
serde_json = "1.0"
rand = "0.7.2"
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge

[dependencies.tari_core]
version = "^0.8"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ edition = "2018"
[dependencies]
futures = {version = "^0.3.1", features = ["async-await"] }
rand = "0.7.2"
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge
serde = { version = "1.0.106", features = ["derive"] }
tokio = { version="^0.2", features = ["blocking", "time", "sync"] }
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tari_common_types = { version = "^0.8", path = "../../base_layer/common_types"}
tari_comms = { version = "^0.8", path = "../../comms"}
tari_comms_dht = { version = "^0.8", path = "../../comms/dht"}
tari_comms_rpc_macros = { version = "^0.8", path = "../../comms/rpc_macros"}
tari_crypto = { git = "ssh://git@github.com/tari-project/tari-crypto.git", branch = "main" }
tari_crypto = { git = "https://github.com/SWvheerden/tari-crypto.git", rev = "3e8817" } #switch back to official after merge
tari_mmr = { version = "^0.8", path = "../../base_layer/mmr", optional = true }
tari_p2p = { version = "^0.8", path = "../../base_layer/p2p" }
tari_service_framework = { version = "^0.8", path = "../service_framework"}
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub fn get_weatherwax_genesis_block_raw() -> Block {
prev_hash: vec![
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
],
timestamp: 1_623_151_562.into(), // Tue Jun 08 2021 11:26:02 GMT+0000
timestamp: 1_623_914_695_000.into(), // Thursday, June 17, 2021 7:24:55 AM GMT
output_mr: from_hex("dcc44f39b65e5e1e526887e7d56f7b85e2ea44bd29bc5bc195e6e015d19e1c06").unwrap(),
range_proof_mr: from_hex("e4d7dab49a66358379a901b9a36c10f070aa9d7bdc8ae752947b6fc4e55d255f").unwrap(),
output_mmr_size: 1,
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ message TransactionInput {
// The block height that the UTXO was mined
uint64 height = 5;
// A signature with k_s, signing the script, input data, and mined height
Signature script_signature = 6;
ComSignature script_signature = 6;
// The offset pubkey, K_O
bytes script_offset_public_key = 7;
}
Expand Down
8 changes: 8 additions & 0 deletions base_layer/core/src/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ message Signature {
bytes signature = 2;
}

// Define the explicit ComSignature implementation for the Tari base layer. A different signature scheme can be
// employed by redefining this type.
message ComSignature {
bytes public_nonce_commitment = 1;
bytes signature_u = 2;
bytes signature_v = 3;
}

// BlindingFactor wrapper
message BlindingFactor {
bytes data = 1;
Expand Down
34 changes: 33 additions & 1 deletion base_layer/core/src/proto/types_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use super::types as proto;
use crate::transactions::types::{BlindingFactor, Commitment, HashOutput, PrivateKey, PublicKey, Signature};
use crate::transactions::types::{
BlindingFactor,
ComSignature,
Commitment,
HashOutput,
PrivateKey,
PublicKey,
Signature,
};
use std::convert::TryFrom;
use tari_crypto::tari_utilities::{ByteArray, ByteArrayError};

Expand Down Expand Up @@ -65,6 +73,30 @@ impl From<Signature> for proto::Signature {
}
}

//---------------------------------- ComSignature --------------------------------------------//

impl TryFrom<proto::ComSignature> for ComSignature {
type Error = ByteArrayError;

fn try_from(sig: proto::ComSignature) -> Result<Self, Self::Error> {
let public_nonce = Commitment::from_bytes(&sig.public_nonce_commitment)?;
let signature_u = PrivateKey::from_bytes(&sig.signature_u)?;
let signature_v = PrivateKey::from_bytes(&sig.signature_v)?;

Ok(Self::new(public_nonce, signature_u, signature_v))
}
}

impl From<ComSignature> for proto::ComSignature {
fn from(sig: ComSignature) -> Self {
Self {
public_nonce_commitment: sig.public_nonce().to_vec(),
signature_u: sig.u().to_vec(),
signature_v: sig.v().to_vec(),
}
}
}

//---------------------------------- HashOutput --------------------------------------------//

impl From<proto::HashOutput> for HashOutput {
Expand Down
10 changes: 7 additions & 3 deletions base_layer/core/src/transactions/aggregated_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl AggregateBody {
self.validate_kernel_sum(total_offset, &factories.commitment)?;

self.validate_range_proofs(&factories.range_proof)?;
self.validate_script_offset(script_offset_g)
self.validate_script_offset(script_offset_g, &factories.commitment)
}

pub fn dissolve(self) -> (Vec<TransactionInput>, Vec<TransactionOutput>, Vec<TransactionKernel>) {
Expand Down Expand Up @@ -377,12 +377,16 @@ impl AggregateBody {
}

/// this will validate the script offset of the aggregate body.
fn validate_script_offset(&self, script_offset: PublicKey) -> Result<(), TransactionError> {
fn validate_script_offset(
&self,
script_offset: PublicKey,
factory: &CommitmentFactory,
) -> Result<(), TransactionError> {
trace!(target: LOG_TARGET, "Checking script offset");
// lets count up the input script public keys
let mut input_keys = PublicKey::default();
for input in &self.inputs {
input_keys = input_keys + input.run_and_verify_script()?;
input_keys = input_keys + input.run_and_verify_script(factory)?;
}

// Now lets gather the output public keys and hashes.
Expand Down
Loading

0 comments on commit fac6be0

Please sign in to comment.