Skip to content
This repository has been archived by the owner on Feb 9, 2025. It is now read-only.

Repo Cleanup #99

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion .cargo/audit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
# RUSTSEC-2020-0071 as dependency in RUSTSEC-2020-0159

[advisories]
ignore = ["RUSTSEC-2020-0159", "RUSTSEC-2020-0071"] # advisory IDs to ignore e.g. ["RUSTSEC-2019-0001", ...]
ignore = [
"RUSTSEC-2020-0159",
"RUSTSEC-2020-0071", # Potential segfault in the time crate
"RUSTSEC-2022-0093",
"RUSTSEC-2024-0344" # curve25519-dalek
]
informational_warnings = ["unmaintained"] # warn for categories of informational advisories
severity_threshold = "medium" # CVSS severity ("none", "low", "medium", "high", "critical")

Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/audit-sec3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Sec3 Pro Audit

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
audit:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check-out the repository
uses: actions/checkout@v2
- name: Sec3 Pro Audit
continue-on-error: false # set to true if you don't want to fail jobs
uses: sec3dev/pro-action@v1
with:
sec3-token: ${{ secrets.SEC3_TOKEN }}
path: programs
- name: Upload Sarif Report
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: sec3-report.sarif
59 changes: 0 additions & 59 deletions .github/workflows/audit.yml

This file was deleted.

14 changes: 7 additions & 7 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: cargo fmt -- --check

- name: Run clippy
run: cargo clippy -- --deny=warnings
run: cargo clippy -- -A clippy::pedantic --deny=warnings

test:
name: Run Tests
Expand Down Expand Up @@ -71,13 +71,13 @@ jobs:
echo Generating keypair...
solana-keygen new -o "$HOME/.config/solana/id.json" --no-passphrase --silent

- name: Install BPF tools
# Note: as a workaround for cargo build-bpf issue run it and ignore errors to install the BPF tools
- name: Install SBF tools
# Note: as a workaround for cargo build-sbf issue run it and ignore errors to install the sbf tools
# https://github.com/solana-labs/solana/issues/26583
run: cargo build-bpf || true
run: cargo build-sbf || true

- name: Build dependencies
run: cargo +bpf build-bpf
run: cargo build-sbf

- name: Run bpf tests
run: cargo +bpf test-bpf
- name: Run sbf tests
run: cargo test-sbf
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# governance-program-library

# governance-program-library
3 changes: 2 additions & 1 deletion programs/gateway/src/instructions/configure_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct ConfigureRegistrar<'info> {
/// Realm is validated in the instruction:
/// - Realm is owned by the governance_program_id
/// - realm_authority is realm.authority
///
/// CHECK: Owned by spl-governance instance specified in governance_program_id
#[account(
address = registrar.realm @ GatewayError::InvalidRealmForRegistrar,
Expand Down Expand Up @@ -50,7 +51,7 @@ pub fn configure_registrar(
registrar.previous_voter_weight_plugin_program_id = use_previous_voter_weight_plugin
.then(|| {
remaining_accounts
.get(0)
.first()
.ok_or(GatewayError::MissingPreviousVoterWeightPlugin)
.map(|account| account.key)
})
Expand Down
3 changes: 2 additions & 1 deletion programs/gateway/src/instructions/create_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct CreateRegistrar<'info> {
/// - Realm is owned by the governance_program_id
/// - governing_token_mint must be the community or council mint
/// - realm_authority is realm.authority
///
/// CHECK: Owned by spl-governance instance specified in governance_program_id
#[account(owner = governance_program_id.key())]
pub realm: UncheckedAccount<'info>,
Expand Down Expand Up @@ -76,7 +77,7 @@ pub fn create_registrar(
registrar.previous_voter_weight_plugin_program_id = use_previous_voter_weight_plugin
.then(|| {
remaining_accounts
.get(0)
.first()
.ok_or(GatewayError::MissingPreviousVoterWeightPlugin)
.map(|account| account.key)
})
Expand Down
1 change: 0 additions & 1 deletion programs/gateway/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ pub mod voter_weight_record;
pub use generic_voter_weight::*;
pub mod generic_voter_weight;

pub use token_owner_record::*;
pub mod token_owner_record;
Binary file modified programs/gateway/tests/fixtures/solana_gateway_program.so
Binary file not shown.
6 changes: 3 additions & 3 deletions programs/nft-voter/src/instructions/cast_nft_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ pub struct CastNftVote<'info> {
}

/// Casts vote with the NFT
pub fn cast_nft_vote<'a, 'b, 'c, 'info>(
ctx: Context<'a, 'b, 'c, 'info, CastNftVote<'info>>,
pub fn cast_nft_vote<'info>(
ctx: Context<'_, '_, '_, 'info, CastNftVote<'info>>,
proposal: Pubkey,
) -> Result<()> {
let registrar = &ctx.accounts.registrar;
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn cast_nft_vote<'a, 'b, 'c, 'info>(
&mut unique_nft_mints,
)?;

voter_weight = voter_weight.checked_add(nft_vote_weight as u64).unwrap();
voter_weight = voter_weight.checked_add(nft_vote_weight).unwrap();

// Create NFT vote record to ensure the same NFT hasn't been already used for voting
// Note: The correct PDA of the NftVoteRecord is validated in create_and_serialize_account_signed
Expand Down
1 change: 1 addition & 0 deletions programs/nft-voter/src/instructions/create_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct CreateRegistrar<'info> {
/// - Realm is owned by the governance_program_id
/// - governing_token_mint must be the community or council mint
/// - realm_authority is realm.authority
///
/// CHECK: Owned by spl-governance instance specified in governance_program_id
#[account(owner = governance_program_id.key())]
pub realm: UncheckedAccount<'info>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn update_voter_weight_record(
&mut unique_nft_mints,
)?;

voter_weight = voter_weight.checked_add(nft_vote_weight as u64).unwrap();
voter_weight = voter_weight.checked_add(nft_vote_weight).unwrap();
}

let voter_weight_record = &mut ctx.accounts.voter_weight_record;
Expand Down
4 changes: 2 additions & 2 deletions programs/nft-voter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub mod nft_voter {
instructions::configure_collection(ctx, weight, size)
}

pub fn cast_nft_vote<'a, 'b, 'c, 'info>(
ctx: Context<'a, 'b, 'c, 'info, CastNftVote<'info>>,
pub fn cast_nft_vote<'info>(
ctx: Context<'_, '_, '_, 'info, CastNftVote<'info>>,
proposal: Pubkey,
) -> Result<()> {
log_version();
Expand Down
2 changes: 1 addition & 1 deletion programs/nft-voter/src/tools/token_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn get_token_metadata(account_info: &AccountInfo) -> Result<Metadata> {
if *account_info.owner != mpl_token_metadata::ID {
return Err(NftVoterError::InvalidAccountOwner.into());
}

let metadata = Metadata::try_from(account_info)?;

// I'm not sure if this is needed but try_from_slice_checked in from_account_info
Expand Down
72 changes: 38 additions & 34 deletions programs/nft-voter/tests/program_test/token_metadata_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ impl TokenMetadataTest {
};

// instruction accounts
let create_coll_metadata_ix_accounts = mpl_token_metadata::instructions::CreateMetadataAccountV3 {
metadata: coll_metadata_key,
mint: coll_mint_cookie.address,
mint_authority: coll_mint_cookie.mint_authority.pubkey(),
payer: payer,
update_authority: (payer, true),
system_program: system_program::ID,
rent: None,
};
let create_coll_metadata_ix_accounts =
mpl_token_metadata::instructions::CreateMetadataAccountV3 {
metadata: coll_metadata_key,
mint: coll_mint_cookie.address,
mint_authority: coll_mint_cookie.mint_authority.pubkey(),
payer: payer,
update_authority: (payer, true),
system_program: system_program::ID,
rent: None,
};

// creates the instruction
let create_coll_metadata_ix = create_coll_metadata_ix_accounts.instruction(args);
Expand All @@ -124,26 +125,28 @@ impl TokenMetadataTest {
let (master_edition_key, _) =
Pubkey::find_program_address(master_edition_seeds, &self.program_id);


// instruction args
let args_master_edition_v3 = mpl_token_metadata::instructions::CreateMasterEditionV3InstructionArgs {
max_supply: Some(0),
};
let args_master_edition_v3 =
mpl_token_metadata::instructions::CreateMasterEditionV3InstructionArgs {
max_supply: Some(0),
};

// instruction accounts
let create_master_edition_v3_ix_accounts = mpl_token_metadata::instructions::CreateMasterEditionV3 {
edition: master_edition_key,
metadata: coll_metadata_key,
mint: coll_mint_cookie.address,
mint_authority: coll_mint_cookie.mint_authority.pubkey(),
payer: payer,
update_authority: payer,
system_program: system_program::ID,
token_program: spl_token::id(),
rent: None,
};
let create_master_edition_v3_ix_accounts =
mpl_token_metadata::instructions::CreateMasterEditionV3 {
edition: master_edition_key,
metadata: coll_metadata_key,
mint: coll_mint_cookie.address,
mint_authority: coll_mint_cookie.mint_authority.pubkey(),
payer: payer,
update_authority: payer,
system_program: system_program::ID,
token_program: spl_token::id(),
rent: None,
};

let create_master_edition_ix = create_master_edition_v3_ix_accounts.instruction(args_master_edition_v3);
let create_master_edition_ix =
create_master_edition_v3_ix_accounts.instruction(args_master_edition_v3);

self.bench
.process_transaction(
Expand Down Expand Up @@ -210,15 +213,16 @@ impl TokenMetadataTest {
};

// instruction accounts
let create_metadata_ix_accounts = mpl_token_metadata::instructions::CreateMetadataAccountV3 {
metadata: metadata_key,
mint: mint_cookie.address,
mint_authority: mint_cookie.mint_authority.pubkey(),
payer: self.bench.payer.pubkey(),
update_authority: (self.bench.payer.pubkey(), true),
system_program: system_program::ID,
rent: None,
};
let create_metadata_ix_accounts =
mpl_token_metadata::instructions::CreateMetadataAccountV3 {
metadata: metadata_key,
mint: mint_cookie.address,
mint_authority: mint_cookie.mint_authority.pubkey(),
payer: self.bench.payer.pubkey(),
update_authority: (self.bench.payer.pubkey(), true),
system_program: system_program::ID,
rent: None,
};

// creates the instruction
let create_metadata_ix = create_metadata_ix_accounts.instruction(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anchor_lang::prelude::*;
use spl_governance::state::realm;

use crate::error::RealmVoterError;
use crate::state::{GovernanceProgramConfig, Registrar, CollectionItemChangeType};
use crate::state::{CollectionItemChangeType, GovernanceProgramConfig, Registrar};

/// Creates or updates configuration for spl-governance program instances to define which spl-governance instances can be used to grant governance power
#[derive(Accounts)]
Expand Down
1 change: 1 addition & 0 deletions programs/realm-voter/src/instructions/create_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct CreateRegistrar<'info> {
/// - Realm is owned by the governance_program_id
/// - governing_token_mint must be the community or council mint
/// - realm_authority is realm.authority
///
/// CHECK: Owned by spl-governance instance specified in governance_program_id
#[account(owner = governance_program_id.key())]
pub realm: UncheckedAccount<'info>,
Expand Down
1 change: 0 additions & 1 deletion programs/realm-voter/src/state/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub enum CollectionItemChangeType {
Remove,
}


/// Registrar which stores spl-governance configurations for the given Realm
#[account]
#[derive(Debug, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions programs/token-haver/src/instructions/create_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct CreateRegistrar<'info> {
/// - Realm is owned by the governance_program_id
/// - governing_token_mint must be the community or council mint
/// - realm_authority is realm.authority
///
/// CHECK: Owned by spl-governance instance specified in governance_program_id
#[account(owner = governance_program_id.key())]
pub realm: UncheckedAccount<'info>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn update_voter_weight_record<'info>(
voter_weight_record.governing_token_owner,
TokenHaverError::TokenAccountWrongOwner
);

// Throw an error if a token account's mint is not unique amount the accounts
require!(
nonzero_token_accounts
Expand Down
3 changes: 2 additions & 1 deletion programs/token-haver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub mod token_haver {
instructions::create_voter_weight_record(ctx, governing_token_owner)
}
pub fn update_voter_weight_record<'info>(
ctx: Context<'_, '_, 'info, 'info, UpdateVoterWeightRecord<'info>>,) -> Result<()> {
ctx: Context<'_, '_, 'info, 'info, UpdateVoterWeightRecord<'info>>,
) -> Result<()> {
log_version();
instructions::update_voter_weight_record(ctx)
}
Expand Down
2 changes: 1 addition & 1 deletion programs/token-haver/src/state/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Registrar {

impl Registrar {
pub fn get_space(max_mints: u8) -> usize {
DISCRIMINATOR_SIZE + PUBKEY_BYTES * 3 + max_mints as usize * (PUBKEY_BYTES + 8)
DISCRIMINATOR_SIZE + PUBKEY_BYTES * 3 + 4 + max_mints as usize * PUBKEY_BYTES
}
}

Expand Down
Loading