From 408beb5ce1de0a0f708951b00d68a5601d1055e7 Mon Sep 17 00:00:00 2001 From: Noah Prince Date: Wed, 20 Nov 2024 08:26:41 -0800 Subject: [PATCH 1/2] Bugfix relinquishing votes with expired positions, bump cargo for verify --- Cargo.lock | 12 +-- programs/circuit-breaker/Cargo.toml | 2 +- programs/fanout/Cargo.toml | 2 +- programs/lazy-distributor/Cargo.toml | 2 +- programs/rewards-oracle/Cargo.toml | 2 +- programs/treasury-management/Cargo.toml | 2 +- programs/voter-stake-registry/Cargo.toml | 2 +- .../relinquish_expired_vote_v0.rs | 16 ++-- scripts/verify.sh | 81 +++++++++++++++++++ 9 files changed, 101 insertions(+), 20 deletions(-) create mode 100755 scripts/verify.sh diff --git a/Cargo.lock b/Cargo.lock index bea8f31a7..b3529ef9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1011,7 +1011,7 @@ dependencies = [ [[package]] name = "circuit-breaker" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anchor-lang", "anchor-spl", @@ -1644,7 +1644,7 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "fanout" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anchor-lang", "anchor-spl", @@ -2306,7 +2306,7 @@ dependencies = [ [[package]] name = "lazy-distributor" -version = "0.2.0" +version = "0.2.1" dependencies = [ "account-compression-cpi", "anchor-lang", @@ -3422,7 +3422,7 @@ dependencies = [ [[package]] name = "rewards-oracle" -version = "0.2.1" +version = "0.2.2" dependencies = [ "anchor-lang", "default-env", @@ -5494,7 +5494,7 @@ dependencies = [ [[package]] name = "treasury-management" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anchor-lang", "anchor-spl", @@ -5673,7 +5673,7 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "voter-stake-registry" -version = "0.3.3" +version = "0.3.4" dependencies = [ "anchor-lang", "anchor-spl", diff --git a/programs/circuit-breaker/Cargo.toml b/programs/circuit-breaker/Cargo.toml index 35803bc1c..f15880221 100644 --- a/programs/circuit-breaker/Cargo.toml +++ b/programs/circuit-breaker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "circuit-breaker" -version = "0.1.0" +version = "0.1.1" description = "Created with Anchor" edition = "2021" diff --git a/programs/fanout/Cargo.toml b/programs/fanout/Cargo.toml index 033349b8b..3bbf28509 100644 --- a/programs/fanout/Cargo.toml +++ b/programs/fanout/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fanout" -version = "0.1.0" +version = "0.1.1" description = "Created with Anchor" edition = "2021" diff --git a/programs/lazy-distributor/Cargo.toml b/programs/lazy-distributor/Cargo.toml index ac796262f..a969eff16 100644 --- a/programs/lazy-distributor/Cargo.toml +++ b/programs/lazy-distributor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lazy-distributor" -version = "0.2.0" +version = "0.2.1" description = "Created with Anchor" edition = "2021" diff --git a/programs/rewards-oracle/Cargo.toml b/programs/rewards-oracle/Cargo.toml index 0d662119b..ee90de826 100644 --- a/programs/rewards-oracle/Cargo.toml +++ b/programs/rewards-oracle/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rewards-oracle" -version = "0.2.1" +version = "0.2.2" description = "Created with Anchor" edition = "2021" diff --git a/programs/treasury-management/Cargo.toml b/programs/treasury-management/Cargo.toml index 4f246c436..16e0c56d5 100644 --- a/programs/treasury-management/Cargo.toml +++ b/programs/treasury-management/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "treasury-management" -version = "0.2.0" +version = "0.2.1" description = "Created with Anchor" edition = "2021" diff --git a/programs/voter-stake-registry/Cargo.toml b/programs/voter-stake-registry/Cargo.toml index e636579ef..90bd354c7 100644 --- a/programs/voter-stake-registry/Cargo.toml +++ b/programs/voter-stake-registry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "voter-stake-registry" -version = "0.3.3" +version = "0.3.4" description = "Heliums voter weight plugin for spl-governance" license = "GPL-3.0-or-later" homepage = "https://github.com/helium/helium-program-library" diff --git a/programs/voter-stake-registry/src/instructions/relinquish_expired_vote_v0.rs b/programs/voter-stake-registry/src/instructions/relinquish_expired_vote_v0.rs index 0797bdd76..91df44c51 100644 --- a/programs/voter-stake-registry/src/instructions/relinquish_expired_vote_v0.rs +++ b/programs/voter-stake-registry/src/instructions/relinquish_expired_vote_v0.rs @@ -18,11 +18,8 @@ pub struct RelinquishExpiredVoteV0<'info> { close = rent_refund )] pub marker: Box>, - #[account( - mut, - constraint = position.mint == marker.mint - )] - pub position: Box>, + #[account(mut)] + pub position: AccountInfo<'info>, #[account( constraint = !matches!(proposal.state, ProposalState::Voting { .. }) )] @@ -31,9 +28,12 @@ pub struct RelinquishExpiredVoteV0<'info> { } pub fn handler(ctx: Context) -> Result<()> { - // Allow closing old markers that just had the relinquished boolean. - if !ctx.accounts.marker._deprecated_relinquished { - ctx.accounts.position.num_active_votes -= ctx.accounts.marker.choices.len() as u16; + let mut data = ctx.accounts.position.try_borrow_mut_data()?; + if !data.is_empty() && !ctx.accounts.marker._deprecated_relinquished { + let mut position = PositionV0::try_deserialize(&mut data.as_ref())?; + require_eq!(position.mint, ctx.accounts.marker.mint); + position.num_active_votes -= ctx.accounts.marker.choices.len() as u16; + position.try_serialize(&mut *data)?; } Ok(()) diff --git a/scripts/verify.sh b/scripts/verify.sh new file mode 100755 index 000000000..fb4f61c6e --- /dev/null +++ b/scripts/verify.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# Function to get the latest semver tag for a program +get_latest_tag() { + local program_name=$1 + git tag -l "program-$program_name-*" | sort -t. -k1,1n -k2,2n -k3,3n | tail -n 1 +} + +# Function to get commit hash from a tag +get_commit_hash() { + local tag=$1 + git rev-list -n 1 "$tag" +} + +# Function to verify a single program +verify_program() { + local program_dir=$1 + local max_attempts=5 + local attempt=1 + + # Get the base name and convert hyphens to underscores + library_name=$(basename "$program_dir" | tr '-' '_') + + # Get the program ID from Anchor.toml + program_id=$(toml get Anchor.toml programs.localnet.$library_name | tr -d '"') + + # Skip if program ID is empty + [ -z "$program_id" ] && return + + # Get the program name (for tag matching) + program_name=$(basename "$program_dir") + + # Get the latest tag and its commit hash + latest_tag=$(get_latest_tag "$program_name") + + # Check if tag exists + if [ -z "$latest_tag" ]; then + echo "Error: No tags found for $program_name" + return 1 + fi + + commit_hash=$(get_commit_hash "$latest_tag") + + echo "Verifying $library_name with program ID $program_id" + echo "Using tag $latest_tag (commit: $commit_hash)" + + while [ $attempt -le $max_attempts ]; do + if solana-verify verify-from-repo \ + https://github.com/helium/helium-program-library \ + --program-id "$program_id" \ + --remote \ + --commit-hash "$commit_hash" \ + --library-name "$library_name" \ + -b solanafoundation/solana-verifiable-build:1.16.13; then + return 0 + fi + + echo "Attempt $attempt failed. Retrying in 10 seconds..." + sleep 10 + attempt=$((attempt + 1)) + done + + echo "Error: Verification failed after $max_attempts attempts" + return 1 +} + +# Check if a specific program was provided +if [ $# -eq 1 ]; then + program_dir="programs/$1" + if [ -d "$program_dir" ]; then + verify_program "$program_dir" + else + echo "Error: Program directory '$program_dir' not found" + exit 1 + fi +else + # Iterate through each directory in programs/ + for program_dir in programs/*/; do + verify_program "$program_dir" + done +fi From e1fa3d9ec1441b5fdda46635ab797687007aa7ac Mon Sep 17 00:00:00 2001 From: Noah Prince Date: Wed, 20 Nov 2024 08:29:11 -0800 Subject: [PATCH 2/2] Add check --- .../src/instructions/relinquish_expired_vote_v0.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/voter-stake-registry/src/instructions/relinquish_expired_vote_v0.rs b/programs/voter-stake-registry/src/instructions/relinquish_expired_vote_v0.rs index 91df44c51..760280f4b 100644 --- a/programs/voter-stake-registry/src/instructions/relinquish_expired_vote_v0.rs +++ b/programs/voter-stake-registry/src/instructions/relinquish_expired_vote_v0.rs @@ -19,6 +19,7 @@ pub struct RelinquishExpiredVoteV0<'info> { )] pub marker: Box>, #[account(mut)] + /// CHECK: Deserialized later pub position: AccountInfo<'info>, #[account( constraint = !matches!(proposal.state, ProposalState::Voting { .. })