Browse Source

Add zero initialization

febo 5 months ago
parent
commit
6f7fb5621a

+ 40 - 5
interface/src/state/account.rs

@@ -68,12 +68,26 @@ impl Account {
 
     #[inline(always)]
     pub fn clear_delegate(&mut self) {
-        self.delegate.0[0] = 0;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.delegate.0[0] = 0;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.delegate.0 = [0, 0, 0, 0];
+        }
     }
 
     #[inline(always)]
     pub fn set_delegate(&mut self, delegate: &Pubkey) {
-        self.delegate.0[0] = 1;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.delegate.0[0] = 1;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.delegate.0 = [1, 0, 0, 0];
+        }
         self.delegate.1 = *delegate;
     }
 
@@ -88,7 +102,14 @@ impl Account {
 
     #[inline(always)]
     pub fn set_native(&mut self, value: bool) {
-        self.is_native[0] = value as u8;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.is_native[0] = value as u8;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.is_native = [value as u8, 0, 0, 0];
+        }
     }
 
     #[inline(always)]
@@ -122,12 +143,26 @@ impl Account {
 
     #[inline(always)]
     pub fn clear_close_authority(&mut self) {
-        self.close_authority.0[0] = 0;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.close_authority.0[0] = 0;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.close_authority.0 = [0, 0, 0, 0];
+        }
     }
 
     #[inline(always)]
     pub fn set_close_authority(&mut self, value: &Pubkey) {
-        self.close_authority.0[0] = 1;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.close_authority.0[0] = 1;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.close_authority.0 = [1, 0, 0, 0];
+        }
         self.close_authority.1 = *value;
     }
 

+ 32 - 4
interface/src/state/mint.rs

@@ -45,12 +45,26 @@ impl Mint {
 
     #[inline(always)]
     pub fn clear_mint_authority(&mut self) {
-        self.mint_authority.0[0] = 0;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.mint_authority.0[0] = 0;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.mint_authority.0 = [0, 0, 0, 0];
+        }
     }
 
     #[inline(always)]
     pub fn set_mint_authority(&mut self, mint_authority: &Pubkey) {
-        self.mint_authority.0[0] = 1;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.mint_authority.0[0] = 1;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.mint_authority.0 = [1, 0, 0, 0];
+        }
         self.mint_authority.1 = *mint_authority;
     }
 
@@ -65,12 +79,26 @@ impl Mint {
 
     #[inline(always)]
     pub fn clear_freeze_authority(&mut self) {
-        self.freeze_authority.0[0] = 0;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.freeze_authority.0[0] = 0;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.freeze_authority.0 = [0, 0, 0, 0];
+        }
     }
 
     #[inline(always)]
     pub fn set_freeze_authority(&mut self, freeze_authority: &Pubkey) {
-        self.freeze_authority.0[0] = 1;
+        #[cfg(not(feature = "fuzzing"))]
+        {
+            self.freeze_authority.0[0] = 1;
+        }
+        #[cfg(feature = "fuzzing")]
+        {
+            self.freeze_authority.0 = [1, 0, 0, 0];
+        }
         self.freeze_authority.1 = *freeze_authority;
     }
 

+ 9 - 0
p-token/src/processor/shared/initialize_account.rs

@@ -83,6 +83,15 @@ pub fn process_initialize_account(
     account.set_account_state(AccountState::Initialized);
     account.mint = *mint_info.key();
     account.owner = *owner;
+    #[cfg(feature = "fuzzing")]
+    {
+        account.set_amount(0);
+        account.set_delegated_amount(0);
+
+        account.clear_close_authority();
+        account.clear_delegate();
+        account.set_native(false);
+    }
 
     if is_native_mint {
         account.set_native(true);

+ 3 - 0
p-token/src/processor/shared/initialize_mint.rs

@@ -86,6 +86,9 @@ pub fn process_initialize_mint(
 
     if let Some(freeze_authority) = freeze_authority {
         mint.set_freeze_authority(freeze_authority);
+    } else {
+        #[cfg(feature = "fuzzing")]
+        mint.clear_freeze_authority();
     }
 
     Ok(())