Skip to content

Commit a08fafe

Browse files
committed
cargo fmt
1 parent 324fe26 commit a08fafe

File tree

4 files changed

+60
-20
lines changed

4 files changed

+60
-20
lines changed

tuxedo-core/src/executive.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ where
8080
for input in transaction.inputs.iter() {
8181
if let Some(input_utxo) = TransparentUtxoSet::<V>::peek_utxo(&input.output_ref) {
8282
ensure!(
83-
input_utxo
84-
.verifier
85-
.verify(&stripped_encoded, Self::block_height(), &input.redeemer),
83+
input_utxo.verifier.verify(
84+
&stripped_encoded,
85+
Self::block_height(),
86+
&input.redeemer
87+
),
8688
UtxoError::VerifierError
8789
);
8890
input_utxos.push(input_utxo);

tuxedo-core/src/verifier/htlc.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This module contains `Verifier` implementations related to Hash Time Lock Contracts.
22
//! It contains a simple hash lock, a simple time lock, and a hash time lock.
3-
//!
3+
//!
44
//! These could be used as the base of an atomic swap protocol with a similarly expressive
55
//! utxo chain like Bitcoin. For atomic swaps with less expressive counter party chains,
66
//! such as Monero, see the Farcaster protocol.
@@ -72,19 +72,25 @@ mod test {
7272

7373
#[test]
7474
fn time_lock_too_soon() {
75-
let time_lock = TimeLock { unlock_block_height: 100 };
75+
let time_lock = TimeLock {
76+
unlock_block_height: 100,
77+
};
7678
assert!(!time_lock.verify(&[], 10, &[]));
7779
}
7880

7981
#[test]
8082
fn time_lock_exactly_on_time() {
81-
let time_lock = TimeLock { unlock_block_height: 100 };
83+
let time_lock = TimeLock {
84+
unlock_block_height: 100,
85+
};
8286
assert!(time_lock.verify(&[], 100, &[]));
8387
}
8488

8589
#[test]
8690
fn time_lock_past_threshold() {
87-
let time_lock = TimeLock { unlock_block_height: 100 };
91+
let time_lock = TimeLock {
92+
unlock_block_height: 100,
93+
};
8894
assert!(time_lock.verify(&[], 200, &[]));
8995
}
9096

@@ -104,5 +110,4 @@ mod test {
104110
let hash_lock = BlakeTwoHashLock::new_from_secret(secret);
105111
assert!(!hash_lock.verify(&[], 0, &incorrect.encode()));
106112
}
107-
108-
}
113+
}

tuxedo-core/src/verifier/multi_signature.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
/// guarded by this verifier. A valid redeemer must supply valid signatures by at least
66
/// `threshold` of the signatories. If the threshold is greater than the number of signatories
77
/// the input can never be consumed.
8-
98
use super::Verifier;
109
use parity_scale_codec::{Decode, Encode};
1110
use scale_info::TypeInfo;
1211
use serde::{Deserialize, Serialize};
13-
use sp_core::{H256, sr25519::{Public, Signature}};
12+
use sp_core::{
13+
sr25519::{Public, Signature},
14+
H256,
15+
};
1416
use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
1517

1618
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
@@ -255,4 +257,4 @@ mod test {
255257
bogus.encode().as_slice()
256258
))
257259
}
258-
}
260+
}

tuxedo-core/src/verifier/simple_signature.rs

+39-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
//! This module contains `Verifier` implementations for simple signature checking.
22
//! This is the most common way to implement private ownership in a UTXO chain and will
33
//! likely be used by most chains.
4-
//!
5-
//! Currently there is only an implementation for SR25519 signatures that makes use of
4+
//!
5+
//! Directly locking a UTXO to a public key is supported as well as locking behind a
6+
//! public key hash like bitcoin's P2PKH. For the merits of each approach see:
7+
//! https://bitcoin.stackexchange.com/q/72184
8+
//!
9+
//! Currently there are only implementations for SR25519 signatures that makes use of
610
//! Substrate's host functions to do the actual cryptography. Other signature schemes or
711
//! pure wasm implementations are also welcome here.
812
913
/// A very commonly used verifier that checks an sr25519 signature.
10-
///
14+
///
1115
/// This verifier relies on Substrate's host functions to perform the signature checking
1216
/// natively and gain performance.
13-
1417
use super::Verifier;
1518
use parity_scale_codec::{Decode, Encode};
1619
use scale_info::TypeInfo;
1720
use serde::{Deserialize, Serialize};
18-
use sp_core::{H256, sr25519::{Public, Signature}};
21+
use sp_core::{
22+
sr25519::{Public, Signature},
23+
H256,
24+
};
1925

26+
/// Require a signature from the private key corresponding to the given public key.
27+
/// This is the simplest way to require a signature. If you prefer not to expose the
28+
/// public key until spend time, use P2PKH instead.
29+
///
30+
/// Uses the Sr25519 signature scheme and Substrate's host functions.
2031
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
2132
pub struct Sr25519Signature {
2233
pub owner_pubkey: H256,
@@ -42,6 +53,28 @@ impl Verifier for Sr25519Signature {
4253
}
4354
}
4455

56+
/// Pay To Public Key Hash (P2PKH)
57+
///
58+
/// Require a signature from the private key corresponding to the public key whose _hash_ is given.
59+
/// This is the most common way to represent private ownership in UTXO networks like Bitcoin.
60+
/// It is more complex than providing the public key directly but does not reveal the public key until spend time.
61+
///
62+
/// Uses the Sr25519 signature scheme and Substrate's host functions.
63+
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
64+
pub struct Sr25519P2PKH {
65+
pub owner_pubkey_hash: H256,
66+
}
67+
68+
impl Verifier for Sr25519P2PKH {
69+
fn verify(&self, simplified_tx: &[u8], _: u32, redeemer: &[u8]) -> bool {
70+
//TODO verifier trait should have associated type for decoding the redeemer. Otherwise each and every redeemer impl has to do it.
71+
// Decode the redeemer and expect to find both a pubkey and a signature.
72+
// Check that the hash stored matches the pubkey given.
73+
// Check that the signature given is valid over the tx from the pubkey given.
74+
todo!()
75+
}
76+
}
77+
4578
#[cfg(test)]
4679
mod test {
4780
use super::*;
@@ -61,7 +94,6 @@ mod test {
6194
assert!(sr25519_signature.verify(simplified_tx, 0, redeemer));
6295
}
6396

64-
6597
#[test]
6698
fn sr25519_signature_with_bad_sig() {
6799
let simplified_tx = b"hello world".as_slice();
@@ -73,5 +105,4 @@ mod test {
73105

74106
assert!(!sr25519_signature.verify(simplified_tx, 0, redeemer));
75107
}
76-
77-
}
108+
}

0 commit comments

Comments
 (0)