-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: implement validator node registration as per RFC-0313 (#4928)
* fix: updates for SafePassword API change (#4927) Description --- Minor updates for a corresponding [change](tari-project/tari_utilities#52) to the `SafePassword` API. Motivation and Context --- A pending change in `tari_utilities` to the handling of sensitive data includes a new implementation of `SafePassword`. One change removes derived traits for equality testing in favor of equality testing on references to the underlying passphrase data. This work makes the minor but necessary changes to address this API change. How Has This Been Tested? --- Tests pass after applying the linked `tari_utilities` PR. Note that tests will pass using the current `SafePassword` API as well, as the dependency change PR restricts the API. * chore: remove unused methods (#4922) Delete some unused methods * v0.40.0 * fix: set wallet start scan height to birthday and not 0 (see issue #4807) (#4911) Description --- When wallet starts new UTXO scanning service it should start at the birthday. Currently, it starts at height 0. This PR addresses this issue Motivation and Context --- Addresses #4807. How Has This Been Tested? --- * chore: fix naming of ffi functions and comments (#4930) Description --- Fixing the comments of one function in the wallet FFI. Fixes the names of 4 functions in the wallet FFI. * chore: fix depreciated timestamp clippy (#4929) Description --- Fixes depreciated timestamp warnings * feat: implement validator node lmdb store * feat: add stateless vn reg utxo validation rules and merkle root * rename vn validaty period consensus constant * use commitment instead of block hash so that lmdb uses canonical ordering * DRY up vn_mmr calculation, add vn reg utxo validations * fix clippies * wallet: use amount from consensus constants for VN reg * adds validator node signature to common types This is to allow the validator node to use the same signature * remove commitment from signature for now * Remove unneeded validator node kernel feature * ad epoch_length to grpc consensus constants * fix epoch interval check and add test * reduce target time for igor * clippy * change shard key hash label Co-authored-by: Aaron Feickert <66188213+AaronFeickert@users.noreply.github.com> Co-authored-by: stringhandler <mikethetike@tari.com> Co-authored-by: jorgeantonio21 <matroid@outlook.com> Co-authored-by: SW van Heerden <swvheerden@gmail.com>
- Loading branch information
1 parent
26aacc7
commit 8569f7c
Showing
64 changed files
with
1,781 additions
and
655 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022. 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 newtype_ops::newtype_ops; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default)] | ||
pub struct VnEpoch(pub u64); | ||
|
||
impl VnEpoch { | ||
pub fn as_u64(&self) -> u64 { | ||
self.0 | ||
} | ||
|
||
pub fn to_be_bytes(&self) -> [u8; 8] { | ||
self.0.to_be_bytes() | ||
} | ||
|
||
pub fn saturating_sub(self, other: VnEpoch) -> VnEpoch { | ||
VnEpoch(self.0.saturating_sub(other.0)) | ||
} | ||
} | ||
|
||
newtype_ops! { [VnEpoch] {add sub mul div} {:=} Self Self } | ||
newtype_ops! { [VnEpoch] {add sub mul div} {:=} &Self &Self } | ||
newtype_ops! { [VnEpoch] {add sub mul div} {:=} Self &Self } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2022. 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 rand::rngs::OsRng; | ||
use serde::{Deserialize, Serialize}; | ||
use tari_crypto::{hash::blake2::Blake256, hash_domain, hashing::DomainSeparatedHasher, keys::PublicKey as PublicKeyT}; | ||
use tari_utilities::ByteArray; | ||
|
||
use crate::types::{FixedHash, PrivateKey, PublicKey, Signature}; | ||
|
||
hash_domain!(ValidatorNodeHashDomain, "com.tari.dan_layer.validator_node", 0); | ||
|
||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)] | ||
pub struct ValidatorNodeSignature { | ||
public_key: PublicKey, | ||
signature: Signature, | ||
} | ||
|
||
impl ValidatorNodeSignature { | ||
pub fn new(public_key: PublicKey, signature: Signature) -> Self { | ||
Self { public_key, signature } | ||
} | ||
|
||
// TODO: pass in commitment instead of arbitrary message | ||
pub fn sign(private_key: &PrivateKey, msg: &[u8]) -> Self { | ||
let (secret_nonce, public_nonce) = PublicKey::random_keypair(&mut OsRng); | ||
let public_key = PublicKey::from_secret_key(private_key); | ||
let challenge = Self::construct_challenge(&public_key, &public_nonce, msg); | ||
let signature = Signature::sign(private_key.clone(), secret_nonce, &*challenge) | ||
.expect("Sign cannot fail with 32-byte challenge and a RistrettoPublicKey"); | ||
Self { public_key, signature } | ||
} | ||
|
||
fn construct_challenge(public_key: &PublicKey, public_nonce: &PublicKey, msg: &[u8]) -> FixedHash { | ||
let hasher = DomainSeparatedHasher::<Blake256, ValidatorNodeHashDomain>::new_with_label("registration") | ||
.chain(public_key.as_bytes()) | ||
.chain(public_nonce.as_bytes()) | ||
.chain(msg); | ||
digest::Digest::finalize(hasher).into() | ||
} | ||
|
||
pub fn is_valid_signature_for(&self, msg: &[u8]) -> bool { | ||
let challenge = Self::construct_challenge(&self.public_key, self.signature.get_public_nonce(), msg); | ||
self.signature.verify_challenge(&self.public_key, &*challenge) | ||
} | ||
|
||
pub fn public_key(&self) -> &PublicKey { | ||
&self.public_key | ||
} | ||
|
||
pub fn signature(&self) -> &Signature { | ||
&self.signature | ||
} | ||
} |
Oops, something went wrong.