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

feat: making code more robust, fixing incentives #44

Merged
merged 6 commits into from
Apr 2, 2024
Merged

Conversation

functor-flow
Copy link

Changes

  • local subnet burn + migration
  • ensuring name safety regarding subnet naming
  • fixing exploit-ability after reaching global maximum of modules

I honestly think that we should change the subneset to subnetchangeset and also add the update for it, what do you think @saiintbrisson ?

Copy link

@saiintbrisson saiintbrisson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good practice to unify all validations in a single place. This makes searching for bugs a LOT easier in the future. Avoid writing security-crucial code more than once in the same codebase, prefer reusing functions

@@ -10,15 +10,71 @@ use sp_std::vec::Vec;
use substrate_fixed::types::I64F64;
extern crate alloc;

#[derive(Debug)]
pub struct SubnetSet<T: Config> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub struct SubnetSet<T: Config> {
pub struct SubnetChangeset<T: Config> {


impl<T: Config> SubnetSet<T> {
#[must_use]
pub fn new(name: &Vec<u8>, founder_key: &T::AccountId, params: SubnetParams<T>) -> Self {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn new(name: &Vec<u8>, founder_key: &T::AccountId, params: SubnetParams<T>) -> Self {
pub fn new(name: &[u8], founder_key: &T::AccountId, params: SubnetParams<T>) -> Self {

// check for name validity
if let Some(name) = self.name {
ensure!(
!Pallet::<T>::if_subnet_name_exists(&name),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the module, this must only be checked if the subnet name is different from its current name. Check ModuleChangeset::new to see how it's done.

Comment on lines 57 to 60
ensure!(
Pallet::<T>::if_subnet_netuid_exists(netuid),
Error::<T>::NetuidDoesNotExist
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this will make this changeset only work when updating a subnet, and not registering one, meaning the same validations will have to be re-done elsewhere, which fragments validation logic.

registrations_this_interval,
target_registrations_per_interval,
));
Self::set_burn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split on a variable just to make easier to read

@functor-flow functor-flow marked this pull request as ready for review April 1, 2024 09:40
@functor-flow
Copy link
Author

d03761b
@saiintbrisson @aripiprazole
Applying the changes you requested, is everything ok ?

@functor-flow functor-flow requested a review from atomoxetine April 1, 2024 15:01
@saiintbrisson saiintbrisson merged commit ec4e631 into main Apr 2, 2024
1 check passed
@saiintbrisson saiintbrisson deleted the march-29 branch April 2, 2024 11:35
functor-flow added a commit that referenced this pull request Jan 16, 2025
* feat: local subnet burn ! missing migrations

* fixing potential problems after reaching global module limit

* fix: ensuring subnet naming safety

* feat: adding migrations + fixing subnet burn

* applying PR suggestions

* fix: clippy errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants