1

This error comes after adding the Tree Static variable :-

use {
    borsh::{BorshDeserialize, BorshSerialize},
    merkletreers::{tree::MerkleTree, utils::hash_it},
    solana_program::{entrypoint::ProgramResult, msg, program_error::ProgramError},
};

#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct WhitelistArgs {
    pub accounts: Vec<String>,
}

const ADMIN_ACCOUNT: &str = "Cv66dQwcSJDdXNVHybchYqp73d75Y8XWj6pKcjN3ffAy";

static mut WHITELIST_TREE: Option<MerkleTree> = None;

pub fn whitelist_account(args: WhitelistArgs, admin_account: String) -> ProgramResult {
    if admin_account != ADMIN_ACCOUNT {
        return Err(ProgramError::IllegalOwner);
    }

    let leaves: Vec<[u8; 32]> = args
        .accounts
        .iter()
        .map(|account_str| {
            let account_bytes = account_str.as_bytes();
            let mut buffer = [0u8; 32];
            hash_it(account_bytes, &mut buffer);
            buffer
        })
        .collect();

        unsafe {
            WHITELIST_TREE = Some(MerkleTree::new(leaves));
        }

        let root = unsafe {
            if let Some(ref tree) = WHITELIST_TREE {
                tree.root
            } else {
                return Err(ProgramError::InvalidAccountData);
            }
        };

    msg!("Accounts have been added to the whitelist");
    msg!("{:?}", root);

    Ok(())
}

1 Answer 1

1

Unlike EVM, a Solana on-chain program is stateless, which means that the program cannot modify any of its own executable data. Your program can only modify other accounts that it owns.

Your program contains a mutable static variable, which is invalid. Mutable statics are typically stored in the .bss section of the ELF, which is why you're getting an error about an entry in the .bss section.

You can find more information at https://solana.com/docs/programs/limitations#static-writable-data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.