Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/anchor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ jobs:
return 1
fi

# Sync program IDs (Anchor 1.0+ requires keypair and declare_id! to match)
# Sync program IDs (Anchor requires the keypair and declare_id! to match)
anchor keys sync

# Update IDL address fields to match the synced keys.
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/kani.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ jobs:
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
# Each proof crate declares its own `[workspace]`, so the repository-wide
# `cargo fmt` and `cargo clippy` jobs in rust.yml never see it. Lint here
# instead, or these crates drift.
- name: Enforce formatting
working-directory: finance/${{ matrix.program }}/kani-proofs
run: cargo fmt --check
- name: Linting
working-directory: finance/${{ matrix.program }}/kani-proofs
run: cargo clippy --all-targets -- -D warnings
- name: Run unit tests
working-directory: finance/${{ matrix.program }}/kani-proofs
run: cargo test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ jobs:
with:
components: clippy
- name: Linting
# Allow diverging_sub_expression: false positive from Anchor 1.0's #[program] macro expansion
# Allow diverging_sub_expression: false positive from Anchor v2's #[program] macro expansion
run: cargo clippy -- -D warnings -A clippy::diverging_sub_expression
5 changes: 4 additions & 1 deletion .github/workflows/solana-asm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ jobs:
# ELF, which requires litesvm >= 0.13 (Agave 4.0) to load; the
# workspace pins litesvm 0.13.1. If a future sbpf change breaks
# loading, pin a revision here with --rev.
cargo install --git https://github.com/blueshift-gg/sbpf.git
#
# The package name is required: the repository now also ships an
# `xtask` binary, and cargo refuses to guess between two binaries.
cargo install --git https://github.com/blueshift-gg/sbpf.git sbpf
- name: Setup Solana Stable
uses: heyAyushh/setup-solana@v5.9
with:
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ jobs:
# --ignore-workspace: only install root deps, not all 94 subprojects
- run: pnpm install --frozen-lockfile --ignore-workspace
- run: pnpm run check

# The only TypeScript application in the repository. Biome above formats and
# lints it, but nothing was compiling it, so a client that no longer matched
# the program's IDL would have gone unnoticed. `verify` runs the client's
# instruction encoding, account decoding and PDA derivation against the
# committed IDL, offline, with no validator.
vault-strategy-app:
name: Vault strategy app
runs-on: ubuntu-latest
defaults:
run:
working-directory: finance/vault-strategy/anchor/app
steps:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: pnpm install --frozen-lockfile
- run: pnpm run typecheck
- run: pnpm run verify
16 changes: 11 additions & 5 deletions basics/close-account/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ Two [instruction handlers](https://solana.com/docs/terminology#instruction-handl
init,
payer = user,
space = User::DISCRIMINATOR.len() + User::INIT_SPACE,
seeds = [b"USER", user.key().as_ref()],
bump,
seeds = [
b"USER",
user.address().as_ref(),
],
bump
)]
pub user_account: Account<'info, User>,
pub user_account: BorshAccount<User>,
```

See [`programs/close-account/src/instructions/create_user.rs`](programs/close-account/src/instructions/create_user.rs).
Expand All @@ -22,11 +25,14 @@ Two [instruction handlers](https://solana.com/docs/terminology#instruction-handl
```rust
#[account(
mut,
seeds = [b"USER", user.key().as_ref()],
seeds = [
b"USER",
user.address().as_ref(),
],
bump = user_account.bump,
close = user, // close account and return lamports to user
)]
pub user_account: Account<'info, User>,
pub user_account: BorshAccount<User>,
```

See [`programs/close-account/src/instructions/close_user.rs`](programs/close-account/src/instructions/close_user.rs).
Expand Down
2 changes: 1 addition & 1 deletion basics/counter/anchor/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Counter (Anchor)

Increment a global counter stored in a [PDA](https://solana.com/docs/terminology#program-derived-address-pda). [Anchor](https://solana.com/docs/terminology#anchor) adds an explicit `initialize` handler that the native variant handles differently.
Increment a global counter stored in a [PDA](https://solana.com/docs/terminology#program-derived-address-pda). [Anchor](https://solana.com/docs/terminology#anchor) adds an explicit `initialize_counter` handler that the native variant handles differently.

See also: the [repository catalog](../../README.md).

Expand Down
33 changes: 3 additions & 30 deletions basics/cross-program-invocation/anchor/idls/lever.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@
"instructions": [
{
"name": "initialize",
"discriminator": [
175,
175,
109,
31,
13,
152,
155,
237
],
"discriminator": [175, 175, 109, 31, 13, 152, 155, 237],
"accounts": [
{
"name": "power",
Expand All @@ -39,16 +30,7 @@
},
{
"name": "switch_power",
"discriminator": [
226,
238,
56,
172,
191,
45,
122,
87
],
"discriminator": [226, 238, 56, 172, 191, 45, 122, 87],
"accounts": [
{
"name": "power",
Expand All @@ -66,16 +48,7 @@
"accounts": [
{
"name": "PowerStatus",
"discriminator": [
145,
147,
198,
35,
253,
101,
231,
26
]
"discriminator": [145, 147, 198, 35, 253, 101, 231, 26]
}
],
"types": [
Expand Down
2 changes: 1 addition & 1 deletion compression/cnft-burn/anchor/programs/cnft-burn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wincode = { version = "0.5", features = ["derive"] }
# vendored Bubblegum types need; pinocchio re-exports this same type.
solana-address = { version = ">=2.6, <2.7", features = ["borsh"] }
# mpl-bubblegum and spl-account-compression removed: they depend on solana-program 2.x
# which is incompatible with Anchor 1.0's solana 3.x types. CPI calls are built manually
# which is incompatible with Anchor v2's solana 3.x types. CPI calls are built manually
# using raw invoke() with hardcoded program IDs and discriminators.
borsh = { version = "1", features = ["derive"] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wincode = { version = "0.5", features = ["derive"] }
# vendored Bubblegum types need; pinocchio re-exports this same type.
solana-address = { version = ">=2.6, <2.7", features = ["borsh"] }
# mpl-bubblegum and spl-account-compression removed: they depend on solana-program 2.x
# which is incompatible with Anchor 1.0's solana 3.x types. CPI calls are built manually
# which is incompatible with Anchor v2's solana 3.x types. CPI calls are built manually
# using raw invoke_signed() with hardcoded program IDs and discriminators.
borsh = { version = "1", features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion compression/cutils/anchor/programs/cutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wincode = { version = "0.5", features = ["derive"] }
# vendored Bubblegum types need; pinocchio re-exports this same type.
solana-address = { version = ">=2.6, <2.7", features = ["borsh"] }
# mpl-bubblegum and spl-account-compression removed: they depend on solana-program 2.x
# which is incompatible with Anchor 1.0's solana 3.x types. CPI calls are built manually
# which is incompatible with Anchor v2's solana 3.x types. CPI calls are built manually
# using raw invoke() with hardcoded program IDs and discriminators. Bubblegum types
# (MetadataArgs, LeafSchema, etc.) are re-implemented in bubblegum_types.rs.
borsh = { version = "1", features = ["derive"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Re-implementation of mpl-bubblegum types using borsh 1.x and Anchor 1.0's Address.
/// Re-implementation of mpl-bubblegum types using borsh 1.x and Anchor v2's Address.
///
/// mpl-bubblegum 2.1.1 depends on solana-program 2.x which is incompatible with
/// Anchor 1.0's solana 3.x types. These types are borsh-compatible reproductions
/// Anchor v2's solana 3.x types. These types are borsh-compatible reproductions
/// that produce identical binary serialization.
use anchor_lang::prelude::*;
use borsh::BorshSerialize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn handle_verify(
);

// Build verify_leaf instruction manually because spl-account-compression 1.0.0
// depends on solana-program 2.x which is incompatible with Anchor 1.0's solana 3.x
// depends on solana-program 2.x which is incompatible with Anchor v2's solana 3.x
// types. Once a compatible version is available, replace this with the CPI wrapper.
let mut accounts = vec![AccountMeta::new_readonly(
*context.accounts.merkle_tree.address(),
Expand Down
3 changes: 1 addition & 2 deletions finance/betting-market/kani-proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ fn proof_parimutuel_solvency() {

// ...so total payouts (stakes back + winnings) never exceed the vault
// balance after the fee (winning_pool + distributable).
let total_payout =
winning_pool as u128 + total_winnings;
let total_payout = winning_pool as u128 + total_winnings;
assert!(total_payout <= winning_pool as u128 + distributable as u128);
}

Expand Down
42 changes: 35 additions & 7 deletions finance/escrow/kani-proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ pub enum TokenError {
/// only if it holds enough, credits `to` only if the sum fits in `u64`, and the
/// two operations together conserve the total. This models exactly that.
pub fn token_transfer(from: &mut u64, to: &mut u64, amount: u64) -> Result<(), TokenError> {
let new_from = from.checked_sub(amount).ok_or(TokenError::InsufficientFunds)?;
let new_from = from
.checked_sub(amount)
.ok_or(TokenError::InsufficientFunds)?;
let new_to = to.checked_add(amount).ok_or(TokenError::Overflow)?;
*from = new_from;
*to = new_to;
Expand Down Expand Up @@ -236,7 +238,12 @@ fn proof_take_offer_conserves_value() {
let vault_a: u64 = kani::any();
let wanted_b: u64 = kani::any();

let mut b = TakeBalances { taker_a, taker_b, maker_b, vault_a };
let mut b = TakeBalances {
taker_a,
taker_b,
maker_b,
vault_a,
};
let total_a_before = taker_a as u128 + vault_a as u128;
let total_b_before = taker_b as u128 + maker_b as u128;

Expand Down Expand Up @@ -272,8 +279,16 @@ fn proof_take_offer_guard_never_overflows() {
let vault_a: u64 = kani::any();
let wanted_b: u64 = kani::any();

let mut b = TakeBalances { taker_a, taker_b, maker_b, vault_a };
assert_ne!(take_offer(&mut b, wanted_b), Err(TakeError::ConservationOverflow));
let mut b = TakeBalances {
taker_a,
taker_b,
maker_b,
vault_a,
};
assert_ne!(
take_offer(&mut b, wanted_b),
Err(TakeError::ConservationOverflow)
);
}

/// Companion to the finding above: once we assume the SPL invariant that a
Expand All @@ -295,8 +310,16 @@ fn proof_take_offer_guard_dead_under_spl_invariant() {
kani::assume((taker_a as u128 + vault_a as u128) <= u64::MAX as u128);
kani::assume((maker_b as u128 + wanted_b as u128) <= u64::MAX as u128);

let mut b = TakeBalances { taker_a, taker_b, maker_b, vault_a };
assert_ne!(take_offer(&mut b, wanted_b), Err(TakeError::ConservationOverflow));
let mut b = TakeBalances {
taker_a,
taker_b,
maker_b,
vault_a,
};
assert_ne!(
take_offer(&mut b, wanted_b),
Err(TakeError::ConservationOverflow)
);
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -438,7 +461,12 @@ mod tests {

#[test]
fn take_offer_swaps() {
let mut b = TakeBalances { taker_a: 0, taker_b: 50, maker_b: 0, vault_a: 10 };
let mut b = TakeBalances {
taker_a: 0,
taker_b: 50,
maker_b: 0,
vault_a: 10,
};
take_offer(&mut b, 7).unwrap();
assert_eq!(b.vault_a, 0);
assert_eq!(b.taker_a, 10);
Expand Down
2 changes: 1 addition & 1 deletion finance/lending/anchor/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
# Anchor 1.0+ runs Rust + LiteSVM tests via cargo test.
# Anchor runs Rust + LiteSVM tests via cargo test.
test = "cargo test"
15 changes: 12 additions & 3 deletions finance/lending/kani-proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,18 @@ mod tests {
fn rate_curve_endpoints() {
// min 100, optimal 300, max 2000, kink at 8000 bps.
// util 0 -> min; util 8000 -> optimal; util 10000 -> max.
assert_eq!(borrow_rate_bps(0, 100, 300, 2000, 8000, 10000).unwrap(), 100);
assert_eq!(borrow_rate_bps(8000, 100, 300, 2000, 8000, 10000).unwrap(), 300);
assert_eq!(borrow_rate_bps(10000, 100, 300, 2000, 8000, 10000).unwrap(), 2000);
assert_eq!(
borrow_rate_bps(0, 100, 300, 2000, 8000, 10000).unwrap(),
100
);
assert_eq!(
borrow_rate_bps(8000, 100, 300, 2000, 8000, 10000).unwrap(),
300
);
assert_eq!(
borrow_rate_bps(10000, 100, 300, 2000, 8000, 10000).unwrap(),
2000
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion finance/order-book/anchor/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[toolchain]
# Match the repo package manager (pnpm-lock.yaml at root); avoids Anchor's yarn default.
package_manager = "pnpm"
# Pin Solana to the version used across the repo's Anchor 1.0 examples so the
# Pin Solana to the version used across the repo's Anchor examples so the
# bundled test validator and BPF toolchain stay in lock-step.
solana_version = "3.1.8"

Expand Down
Loading
Loading