Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add salt to weights commit-reveal #478

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ reveal_weights {
let version_key: u64 = 0;
let uids: Vec<u16> = vec![0];
let weight_values: Vec<u16> = vec![10];
let salt: Vec<u8> = vec![8];
let hotkey: T::AccountId = account("hot", 0, 1);
let coldkey: T::AccountId = account("cold", 1, 2);

Expand Down Expand Up @@ -421,9 +422,10 @@ reveal_weights {
netuid,
uids.clone(),
weight_values.clone(),
salt.clone(),
version_key,
));
let _ = Subtensor::<T>::commit_weights(<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), netuid, commit_hash);

}: reveal_weights(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, version_key)
}: reveal_weights(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, salt, version_key)
}
6 changes: 5 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,9 @@ pub mod pallet {
/// * `values` (`Vec<u16>`):
/// - The values of the weights being revealed.
///
/// * `salt` (`Vec<u8>`):
/// - The random salt to protect from brute-force guessing attack in case of small weight changes bit-wise.
///
/// * `version_key` (`u64`):
/// - The network version key.
///
Expand All @@ -1436,9 +1439,10 @@ pub mod pallet {
netuid: u16,
uids: Vec<u16>,
values: Vec<u16>,
salt: Vec<u8>,
version_key: u64,
) -> DispatchResult {
Self::do_reveal_weights(origin, netuid, uids, values, version_key)
Self::do_reveal_weights(origin, netuid, uids, values, salt, version_key)
}

/// # Args:
Expand Down
5 changes: 5 additions & 0 deletions pallets/subtensor/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ impl<T: Config> Pallet<T> {
/// * `values` (`Vec<u16>`):
/// - The values of the weights being revealed.
///
/// * `salt` (`Vec<u8>`):
/// - The values of the weights being revealed.
///
/// * `version_key` (`u64`):
/// - The network version key.
///
Expand All @@ -78,6 +81,7 @@ impl<T: Config> Pallet<T> {
netuid: u16,
uids: Vec<u16>,
values: Vec<u16>,
salt: Vec<u8>,
version_key: u64,
) -> DispatchResult {
let who = ensure_signed(origin.clone())?;
Expand All @@ -103,6 +107,7 @@ impl<T: Config> Pallet<T> {
netuid,
uids.clone(),
values.clone(),
salt.clone(),
version_key,
));
ensure!(provided_hash == *commit_hash, Error::<T>::InvalidReveal);
Expand Down
Loading