From 222dc4b2c1b10e1a44c2808a7c7429913302eded Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Wed, 23 Apr 2025 07:48:30 +0000 Subject: [PATCH] program: drop --- .github/workflows/main.yml | 94 +------ Cargo.lock | 369 +--------------------------- Cargo.toml | 3 - package.json | 8 - program/Cargo.toml | 39 --- program/src/entrypoint.rs | 19 -- program/src/lib.rs | 5 - program/src/processor.rs | 208 ---------------- program/tests/allocate.rs | 112 --------- program/tests/allocate_with_seed.rs | 159 ------------ program/tests/assign.rs | 61 ----- program/tests/setup.rs | 8 - scripts/helpers/start-validator.mts | 10 +- scripts/rust.mts | 11 - 14 files changed, 5 insertions(+), 1101 deletions(-) delete mode 100644 program/Cargo.toml delete mode 100644 program/src/entrypoint.rs delete mode 100644 program/src/lib.rs delete mode 100644 program/src/processor.rs delete mode 100644 program/tests/allocate.rs delete mode 100644 program/tests/allocate_with_seed.rs delete mode 100644 program/tests/assign.rs delete mode 100644 program/tests/setup.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 57ab7e2..bbcaa3b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,30 +69,6 @@ jobs: - name: Lint / Features run: pnpm interface:lint:features - - format_and_lint_program: - name: Format & Lint Program - runs-on: ubuntu-latest - steps: - - name: Git Checkout - uses: actions/checkout@v4 - - - name: Setup Environment - uses: ./.github/actions/setup - with: - toolchain: format, lint - - - name: Format - run: pnpm program:format - - - name: Lint / Clippy - run: pnpm program:lint:clippy - - - name: Lint / Docs - run: pnpm program:lint:docs - - - name: Lint / Features - run: pnpm program:lint:features wasm_interface: name: Build Interface in WASM @@ -154,40 +130,10 @@ jobs: git status --porcelain test -z "$(git status --porcelain)" - build_program: - name: Build Program - runs-on: ubuntu-latest - needs: format_and_lint_program - steps: - - name: Git Checkout - uses: actions/checkout@v4 - - - name: Setup Environment - uses: ./.github/actions/setup - with: - cargo-cache-key: cargo-build-program - solana: true - - - name: Build - run: pnpm program:build - - - name: Upload Program Builds - uses: actions/upload-artifact@v4 - with: - name: program-builds - path: ./target/deploy/*.so - if-no-files-found: error - - - name: Save Program Builds For Client Jobs - uses: actions/cache/save@v4 - with: - path: ./**/*.so - key: ${{ runner.os }}-builds-${{ github.sha }} - test_client_js: name: Test Client JS runs-on: ubuntu-latest - needs: [format_and_lint_client_js, build_program] + needs: [format_and_lint_client_js] steps: - name: Git Checkout uses: actions/checkout@v4 @@ -197,19 +143,13 @@ jobs: with: solana: true - - name: Restore Program Builds - uses: actions/cache/restore@v4 - with: - path: ./**/*.so - key: ${{ runner.os }}-builds-${{ github.sha }} - - name: Test Client JS run: pnpm js:test test_client_rust: name: Test Client Rust runs-on: ubuntu-latest - needs: [format_and_lint_client_rust, build_program] + needs: [format_and_lint_client_rust] steps: - name: Git Checkout uses: actions/checkout@v4 @@ -221,35 +161,5 @@ jobs: toolchain: test solana: true - - name: Restore Program Builds - uses: actions/cache/restore@v4 - with: - path: ./**/*.so - key: ${{ runner.os }}-builds-${{ github.sha }} - - name: Test Client Rust run: pnpm rust:test - - test_program: - name: Test Program - runs-on: ubuntu-latest - needs: build_program - steps: - - name: Git Checkout - uses: actions/checkout@v4 - - - name: Setup Environment - uses: ./.github/actions/setup - with: - cargo-cache-key: cargo-program-tests - toolchain: test - solana: true - - - name: Restore Program Builds - uses: actions/cache/restore@v4 - with: - path: ./**/*.so - key: ${{ runner.os }}-builds-${{ github.sha }} - - - name: Test - run: pnpm program:test diff --git a/Cargo.lock b/Cargo.lock index cff2096..bc31d3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -204,12 +204,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" -[[package]] -name = "ascii" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" - [[package]] name = "asn1-rs" version = "0.5.2" @@ -626,19 +620,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "combine" -version = "3.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" -dependencies = [ - "ascii", - "byteorder", - "either", - "memchr", - "unreachable", -] - [[package]] name = "combine" version = "4.6.7" @@ -817,7 +798,6 @@ dependencies = [ "fiat-crypto", "rand_core 0.6.4", "rustc_version", - "serde", "subtle", "zeroize", ] @@ -982,12 +962,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "eager" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abe71d579d1812060163dff96056261deb5bf6729b100fa2e36a68b9649ba3d3" - [[package]] name = "ed25519" version = "1.5.3" @@ -1044,26 +1018,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "enum-iterator" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fd242f399be1da0a5354aa462d57b4ab2b4ee0683cc552f7c007d2d12d36e94" -dependencies = [ - "enum-iterator-derive", -] - -[[package]] -name = "enum-iterator-derive" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ab991c1362ac86c61ab6f556cff143daa22e5a15e4e189df818b2fd19fe65b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.87", -] - [[package]] name = "env_logger" version = "0.9.3" @@ -1363,15 +1317,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "hash32" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" -dependencies = [ - "byteorder", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1796,7 +1741,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" dependencies = [ "cesu8", - "combine 4.6.7", + "combine", "jni-sys", "log", "thiserror 1.0.69", @@ -1922,18 +1867,6 @@ dependencies = [ "libsecp256k1-core", ] -[[package]] -name = "light-poseidon" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c9a85a9752c549ceb7578064b4ed891179d20acd85f27318573b64d2d7ee7ee" -dependencies = [ - "ark-bn254", - "ark-ff", - "num-bigint 0.4.6", - "thiserror 1.0.69", -] - [[package]] name = "litemap" version = "0.7.4" @@ -2022,66 +1955,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "mollusk-svm" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e07877773d8734efadaa9b44a8c817d048033003c467243fb747efe2e641da71" -dependencies = [ - "bincode", - "mollusk-svm-error", - "mollusk-svm-keys", - "solana-account", - "solana-bpf-loader-program", - "solana-clock", - "solana-compute-budget", - "solana-epoch-rewards", - "solana-epoch-schedule", - "solana-feature-set", - "solana-fee-structure", - "solana-hash", - "solana-instruction", - "solana-loader-v3-interface", - "solana-log-collector", - "solana-logger", - "solana-precompiles", - "solana-program-error", - "solana-program-runtime", - "solana-pubkey", - "solana-rent", - "solana-sdk-ids", - "solana-slot-hashes", - "solana-stake-interface", - "solana-system-program 2.2.1", - "solana-sysvar", - "solana-sysvar-id", - "solana-timings", - "solana-transaction-context", -] - -[[package]] -name = "mollusk-svm-error" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5062f87053bf1daf07e578155a850d01d2bb8c9327d5e31924edc7c17b7903f" -dependencies = [ - "solana-pubkey", - "thiserror 1.0.69", -] - -[[package]] -name = "mollusk-svm-keys" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f95fd45db898fde342eeb6c55c4d32033fccdc4cb703f213af848c96d3a82b" -dependencies = [ - "mollusk-svm-error", - "solana-account", - "solana-instruction", - "solana-pubkey", - "solana-transaction-context", -] - [[package]] name = "nix" version = "0.29.0" @@ -2485,17 +2358,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "qualifier_attr" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e2e25ee72f5b24d773cae88422baddefff7714f97aab68d96fe2b6fc4a28fb2" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.87", -] - [[package]] name = "quanta" version = "0.12.5" @@ -3354,55 +3216,6 @@ dependencies = [ "borsh 1.5.5", ] -[[package]] -name = "solana-bpf-loader-program" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cbc2581d0f39cd7698e46baa06fc5e8928b323a85ed3a4fdbdfe0d7ea9fc152" -dependencies = [ - "bincode", - "libsecp256k1", - "qualifier_attr", - "scopeguard", - "solana-account", - "solana-account-info", - "solana-big-mod-exp", - "solana-bincode", - "solana-blake3-hasher", - "solana-bn254", - "solana-clock", - "solana-compute-budget", - "solana-cpi", - "solana-curve25519", - "solana-feature-set", - "solana-hash", - "solana-instruction", - "solana-keccak-hasher", - "solana-loader-v3-interface", - "solana-loader-v4-interface", - "solana-log-collector", - "solana-measure", - "solana-packet", - "solana-poseidon", - "solana-precompiles", - "solana-program-entrypoint", - "solana-program-memory", - "solana-program-runtime", - "solana-pubkey", - "solana-sbpf", - "solana-sdk-ids", - "solana-secp256k1-recover", - "solana-sha256-hasher", - "solana-stable-layout", - "solana-system-interface 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "solana-sysvar", - "solana-sysvar-id", - "solana-timings", - "solana-transaction-context", - "solana-type-overrides", - "thiserror 2.0.11", -] - [[package]] name = "solana-client" version = "2.2.1" @@ -3504,16 +3317,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "solana-compute-budget" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab40b24943ca51f1214fcf7979807640ea82a8387745f864cf3cd93d1337b01" -dependencies = [ - "solana-fee-structure", - "solana-program-entrypoint", -] - [[package]] name = "solana-compute-budget-interface" version = "2.2.1" @@ -3565,20 +3368,6 @@ dependencies = [ "solana-stable-layout", ] -[[package]] -name = "solana-curve25519" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f213e3a853a23814dee39d730cd3a5583b7b1e6b37b2cd4d940bbe62df7acc16" -dependencies = [ - "bytemuck", - "bytemuck_derive", - "curve25519-dalek 4.1.3", - "solana-define-syscall", - "subtle", - "thiserror 2.0.11", -] - [[package]] name = "solana-decode-error" version = "2.2.1" @@ -3977,15 +3766,6 @@ dependencies = [ "solana-system-interface 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "solana-log-collector" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4aa28cd428e0af919d2fafd31c646835622abfd7ed4dba4df68e3c00f461bc66" -dependencies = [ - "log", -] - [[package]] name = "solana-logger" version = "2.3.0" @@ -4181,18 +3961,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "solana-poseidon" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad1ea160d08dc423c35021fa3e437a5783eb256f5ab8bc3024e27db913acf42" -dependencies = [ - "ark-bn254", - "light-poseidon", - "solana-define-syscall", - "thiserror 2.0.11", -] - [[package]] name = "solana-precompile-error" version = "2.2.1" @@ -4364,47 +4132,6 @@ dependencies = [ "solana-program-error", ] -[[package]] -name = "solana-program-runtime" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c3d36fed5548b1a8625eb071df6031a95aa69f884e29bf244821e53c49372bc" -dependencies = [ - "base64 0.22.1", - "bincode", - "enum-iterator", - "itertools 0.12.1", - "log", - "percentage", - "rand 0.8.5", - "serde", - "solana-account", - "solana-clock", - "solana-compute-budget", - "solana-epoch-rewards", - "solana-epoch-schedule", - "solana-feature-set", - "solana-hash", - "solana-instruction", - "solana-last-restart-slot", - "solana-log-collector", - "solana-measure", - "solana-metrics", - "solana-precompiles", - "solana-pubkey", - "solana-rent", - "solana-sbpf", - "solana-sdk-ids", - "solana-slot-hashes", - "solana-stable-layout", - "solana-sysvar", - "solana-sysvar-id", - "solana-timings", - "solana-transaction-context", - "solana-type-overrides", - "thiserror 2.0.11", -] - [[package]] name = "solana-pubkey" version = "2.2.1" @@ -4665,23 +4392,6 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61f1bc1357b8188d9c4a3af3fc55276e56987265eb7ad073ae6f8180ee54cecf" -[[package]] -name = "solana-sbpf" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a3ce7a0f4d6830124ceb2c263c36d1ee39444ec70146eb49b939e557e72b96" -dependencies = [ - "byteorder", - "combine 3.8.1", - "hash32", - "libc", - "log", - "rand 0.8.5", - "rustc-demangle", - "thiserror 1.0.69", - "winapi", -] - [[package]] name = "solana-sdk" version = "2.2.1" @@ -5091,47 +4801,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "solana-system-program" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43c8f684977e4439031b3a27b954ab05a6bdf697d581692aaf8888cf92b73b9e" -dependencies = [ - "bincode", - "log", - "serde", - "serde_derive", - "solana-account", - "solana-bincode", - "solana-instruction", - "solana-log-collector", - "solana-nonce", - "solana-nonce-account", - "solana-packet", - "solana-program-runtime", - "solana-pubkey", - "solana-sdk-ids", - "solana-system-interface 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "solana-sysvar", - "solana-transaction-context", - "solana-type-overrides", -] - -[[package]] -name = "solana-system-program" -version = "3.0.0" -dependencies = [ - "mollusk-svm", - "solana-account", - "solana-account-info", - "solana-bincode", - "solana-msg", - "solana-program-entrypoint", - "solana-program-error", - "solana-pubkey", - "solana-system-interface 1.0.0", -] - [[package]] name = "solana-system-transaction" version = "2.2.1" @@ -5229,17 +4898,6 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6af261afb0e8c39252a04d026e3ea9c405342b08c871a2ad8aa5448e068c784c" -[[package]] -name = "solana-timings" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49d9eabdce318cb07c60a23f1cc367b43e177c79225b5c2a081869ad182172ad" -dependencies = [ - "eager", - "enum-iterator", - "solana-pubkey", -] - [[package]] name = "solana-tls-utils" version = "2.2.1" @@ -5383,16 +5041,6 @@ dependencies = [ "thiserror 2.0.11", ] -[[package]] -name = "solana-type-overrides" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d39dc2e501edfea7ce1cec2fe2a2428aedfea1cc9c31747931e0d90d5c57b020" -dependencies = [ - "lazy_static", - "rand 0.8.5", -] - [[package]] name = "solana-udp-client" version = "2.2.1" @@ -5878,15 +5526,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -dependencies = [ - "void", -] - [[package]] name = "untrusted" version = "0.9.0" @@ -5944,12 +5583,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "walkdir" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index 1e1655a..c1c95a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ resolver = "2" members = [ "clients/rust", "interface", - "program", ] [workspace.package] @@ -14,9 +13,7 @@ license = "Apache-2.0" edition = "2021" [workspace.dependencies] -solana-account = "2.2.1" solana-account-info = "2.2.1" -solana-bincode = "2.2.1" solana-cpi = "2.2.1" solana-decode-error = "2.2.1" solana-example-mocks = "2.2.1" diff --git a/package.json b/package.json index ed138ed..5d8c7ea 100644 --- a/package.json +++ b/package.json @@ -27,14 +27,6 @@ "interface:publish": "tsx ./scripts/rust.mts publish interface", "interface:test": "tsx ./scripts/rust.mts test interface", "interface:wasm": "tsx ./scripts/rust.mts wasm interface", - "program:format": "tsx ./scripts/rust.mts format program", - "program:lint": "tsx ./scripts/rust.mts lint program", - "program:lint:clippy": "tsx ./scripts/rust.mts lint-clippy program", - "program:lint:docs": "tsx ./scripts/rust.mts lint-docs program", - "program:lint:features": "tsx ./scripts/rust.mts lint-features program", - "program:publish": "tsx ./scripts/rust.mts publish program", - "program:build": "tsx ./scripts/rust.mts build-sbf program", - "program:test": "tsx ./scripts/rust.mts test program", "template:upgrade": "tsx ./scripts/helpers/upgrade-template.ts" }, "devDependencies": { diff --git a/program/Cargo.toml b/program/Cargo.toml deleted file mode 100644 index 75c4deb..0000000 --- a/program/Cargo.toml +++ /dev/null @@ -1,39 +0,0 @@ -[package] -name = "solana-system-program" -version = "3.0.0" -description = "Solana System Program" -readme = "README.md" -authors = { workspace = true } -repository = { workspace = true } -homepage = { workspace = true } -license = { workspace = true } -edition = { workspace = true } - -[package.metadata.solana] -program-id = "11111111111111111111111111111111" - -[features] -bpf-entrypoint = [] - -[dependencies] -solana-account-info = { workspace = true } -solana-bincode = { workspace = true } -solana-msg = { workspace = true } -solana-program-entrypoint = { workspace = true } -solana-program-error = { workspace = true } -solana-pubkey = { workspace = true, features = ["sha2"] } -solana-system-interface = { path = "../interface", features = ["serde"] } - -[dev-dependencies] -mollusk-svm = "0.1.0" -solana-account = { workspace = true } -solana-system-interface = { path = "../interface", features = ["bincode"] } - -[lib] -crate-type = ["cdylib"] - -[lints.rust.unexpected_cfgs] -level = "warn" -check-cfg = [ - 'cfg(target_os, values("solana"))', -] diff --git a/program/src/entrypoint.rs b/program/src/entrypoint.rs deleted file mode 100644 index 89c592e..0000000 --- a/program/src/entrypoint.rs +++ /dev/null @@ -1,19 +0,0 @@ -//! Program entrypoint. - -use { - crate::processor, - solana_account_info::AccountInfo, - solana_program_error::{PrintProgramError, ProgramResult}, - solana_pubkey::Pubkey, - solana_system_interface::error::SystemError, -}; - -solana_program_entrypoint::entrypoint!(process_instruction); -fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], - instruction_data: &[u8], -) -> ProgramResult { - processor::process(program_id, accounts, instruction_data) - .inspect_err(PrintProgramError::print::) -} diff --git a/program/src/lib.rs b/program/src/lib.rs deleted file mode 100644 index 9159945..0000000 --- a/program/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -//! Solana System Program. - -#[cfg(all(target_os = "solana", feature = "bpf-entrypoint"))] -pub mod entrypoint; -pub mod processor; diff --git a/program/src/processor.rs b/program/src/processor.rs deleted file mode 100644 index 03b781a..0000000 --- a/program/src/processor.rs +++ /dev/null @@ -1,208 +0,0 @@ -//! Program processor. - -use { - solana_account_info::AccountInfo, - solana_msg::msg, - solana_program_error::{ProgramError, ProgramResult}, - solana_pubkey::Pubkey, - solana_system_interface::{ - error::SystemError, instruction::SystemInstruction, MAX_PERMITTED_DATA_LENGTH, - }, -}; - -// Maximum input buffer length that can be deserialized. -// https://github.com/anza-xyz/solana-sdk/blob/41c663a8ec7269aa1117a2e3b0e24ff9ee1ac4af/packet/src/lib.rs#L32 -const MAX_INPUT_LEN: u64 = 1232; - -macro_rules! accounts { - ( $infos:ident, $( $i:literal => $name:ident ),* $(,)? ) => { - $( - let $name = $infos.get($i).ok_or(ProgramError::NotEnoughAccountKeys)?; - )* - }; -} - -// Represents an address that may or may not have been generated from a seed. -struct AddressInfo<'a, 'b> { - info: &'a AccountInfo<'b>, - base: Option<(&'a Pubkey, &'a AccountInfo<'b>)>, -} - -impl std::fmt::Debug for AddressInfo<'_, '_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("AddressInfo") - .field("address", &self.info.key) - .field("base", &self.base.map(|(key, _)| key)) - .finish() - } -} - -impl<'a, 'b> AddressInfo<'a, 'b> { - fn is_signer(&self) -> bool { - /* - [CORE_BPF]: - This is pretty ugly, but... - - For some reason, the program asks for the base address _and_ the - base account, which are supposed to be the same account. - - In the original builtin, the key is validated against the - account when this method is called, since it would search the - `signers` hash map for the keyed account matching the provided base - address. - - To preserve identical functionality, including the timing at which - errors are thrown, we inject the check here. - */ - if let Some((base_key, base_info)) = self.base { - base_key == base_info.key && base_info.is_signer - } else { - self.info.is_signer - } - } - - fn create( - info: &'a AccountInfo<'b>, - with_seed: Option<(&'a Pubkey, &'a AccountInfo<'b>, &str, &Pubkey)>, - ) -> Result { - let base = if let Some((base_key, base_info, seed, owner)) = with_seed { - // Re-derive the address. It must match the supplied address. - let address_with_seed = Pubkey::create_with_seed(base_key, seed, owner)?; - if *info.key != address_with_seed { - msg!( - "Create: address {} does not match derived address {}", - info.key, - address_with_seed - ); - Err(SystemError::AddressWithSeedMismatch)? - } - Some((base_key, base_info)) - } else { - None - }; - - Ok(Self { info, base }) - } -} - -fn allocate(info: &AccountInfo, address: &AddressInfo, space: u64) -> Result<(), ProgramError> { - if !address.is_signer() { - msg!("Allocate: 'to' account {:?} must sign", address); - Err(ProgramError::MissingRequiredSignature)? - } - - // If it looks like the account is already in use, bail. - if !info.data_is_empty() || !solana_system_interface::program::check_id(info.owner) { - msg!("Allocate: account {:?} already in use", address); - Err(SystemError::AccountAlreadyInUse)? - } - - if space > MAX_PERMITTED_DATA_LENGTH { - msg!( - "Allocate: requested {}, max allowed {}", - space, - MAX_PERMITTED_DATA_LENGTH - ); - Err(SystemError::InvalidAccountDataLength)? - } - - /* - [TODO: CORE_BPF]: - - This is going to behave differently than the builtin program right now, - since reallocations are limited to `MAX_PERMITTED_DATA_INCREASE``, which is - smaller than `MAX_PERMITTED_DATA_LENGTH`. - - * `MAX_PERMITTED_DATA_LENGTH` : 1_024 * 10 * 1_024 - * `MAX_PERMITTED_DATA_INCREASE` : 1_024 * 10 - - https://github.com/solana-program/system/issues/30 - */ - info.realloc(space as usize, true) -} - -fn assign(info: &AccountInfo, address: &AddressInfo, owner: &Pubkey) -> Result<(), ProgramError> { - // No work to do, just return. - if info.owner == owner { - return Ok(()); - } - - if !address.is_signer() { - msg!("Assign: account {:?} must sign", address); - Err(ProgramError::MissingRequiredSignature)? - } - - info.assign(owner); - - Ok(()) -} - -fn process_allocate(accounts: &[AccountInfo], space: u64) -> ProgramResult { - accounts!( - accounts, - 0 => account_info, - ); - allocate( - account_info, - &AddressInfo::create(account_info, None)?, - space, - ) -} - -fn process_allocate_with_seed( - accounts: &[AccountInfo], - base: Pubkey, - seed: String, - space: u64, - owner: Pubkey, -) -> ProgramResult { - accounts!( - accounts, - 0 => account_info, - 1 => base_info, - ); - - let address = AddressInfo::create(account_info, Some((&base, base_info, &seed, &owner)))?; - - // [CORE_BPF]: The original builtin also does both `allocate` & `assign` here. - // See https://github.com/anza-xyz/agave/blob/b31e5f47f9b9190a3c566f6d13c3f37422961071/programs/system/src/system_processor.rs#L518. - allocate(account_info, &address, space)?; - assign(account_info, &address, &owner) -} - -fn process_assign(accounts: &[AccountInfo], owner: Pubkey) -> ProgramResult { - accounts!( - accounts, - 0 => account_info, - ); - - let address = AddressInfo::create(account_info, None)?; - - assign(account_info, &address, &owner) -} - -pub fn process(_program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) -> ProgramResult { - match solana_bincode::limited_deserialize::(input, MAX_INPUT_LEN) - .map_err(|_| ProgramError::InvalidInstructionData)? - { - SystemInstruction::Allocate { space } => { - msg!("Instruction: Allocate"); - process_allocate(accounts, space) - } - SystemInstruction::AllocateWithSeed { - base, - seed, - space, - owner, - } => { - msg!("Instruction: AllocateWithSeed"); - process_allocate_with_seed(accounts, base, seed, space, owner) - } - SystemInstruction::Assign { owner } => { - msg!("Instruction: Assign"); - process_assign(accounts, owner) - } - /* TODO: Remaining instruction implementations... */ - _ => Err(ProgramError::InvalidInstructionData), - } -} diff --git a/program/tests/allocate.rs b/program/tests/allocate.rs deleted file mode 100644 index 7cdd23d..0000000 --- a/program/tests/allocate.rs +++ /dev/null @@ -1,112 +0,0 @@ -mod setup; - -use { - mollusk_svm::result::Check, - solana_account::Account, - solana_account_info::MAX_PERMITTED_DATA_INCREASE, - solana_program_error::ProgramError, - solana_pubkey::Pubkey, - solana_system_interface::{ - error::SystemError, instruction::allocate, MAX_PERMITTED_DATA_LENGTH, - }, -}; - -const SPACE: u64 = 10_000; - -#[test] -fn fail_account_not_signer() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); - - let mut instruction = allocate(&pubkey, SPACE); - instruction.accounts[0].is_signer = false; - - mollusk.process_and_validate_instruction( - &instruction, - &[(pubkey, Account::default())], - &[Check::err(ProgramError::MissingRequiredSignature)], - ); -} - -#[test] -fn fail_account_already_in_use() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); - - let account = Account { - data: vec![4; 32], // Has data - ..Account::default() - }; - - mollusk.process_and_validate_instruction( - &allocate(&pubkey, SPACE), - &[(pubkey, account)], - &[Check::err(ProgramError::Custom( - SystemError::AccountAlreadyInUse as u32, - ))], - ); - - let account = Account { - owner: Pubkey::new_unique(), // Not System - ..Account::default() - }; - - mollusk.process_and_validate_instruction( - &allocate(&pubkey, SPACE), - &[(pubkey, account)], - &[Check::err(ProgramError::Custom( - SystemError::AccountAlreadyInUse as u32, - ))], - ); -} - -#[test] -fn fail_space_too_large() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); - - let space_too_large = MAX_PERMITTED_DATA_LENGTH + 1; - - mollusk.process_and_validate_instruction( - &allocate(&pubkey, space_too_large), - &[(pubkey, Account::default())], - &[Check::err(ProgramError::Custom( - SystemError::InvalidAccountDataLength as u32, - ))], - ); -} - -// [TODO: CORE_BPF]: This verifies the concern for the `realloc` issue. -#[test] -fn fail_space_too_large_for_realloc() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); - - let space_too_large_for_realloc = MAX_PERMITTED_DATA_INCREASE + 1; - - mollusk.process_and_validate_instruction( - &allocate(&pubkey, space_too_large_for_realloc as u64), - &[(pubkey, Account::default())], - &[Check::err(ProgramError::InvalidRealloc)], // See...? - ); -} - -#[test] -fn success() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); - - mollusk.process_and_validate_instruction( - &allocate(&pubkey, SPACE), - &[(pubkey, Account::default())], - &[ - Check::success(), - Check::account(&pubkey).space(SPACE as usize).build(), - ], - ); -} diff --git a/program/tests/allocate_with_seed.rs b/program/tests/allocate_with_seed.rs deleted file mode 100644 index 806e1d0..0000000 --- a/program/tests/allocate_with_seed.rs +++ /dev/null @@ -1,159 +0,0 @@ -mod setup; - -use { - mollusk_svm::result::Check, - solana_account::Account, - solana_account_info::MAX_PERMITTED_DATA_INCREASE, - solana_program_error::ProgramError, - solana_pubkey::Pubkey, - solana_system_interface::{ - error::SystemError, instruction::allocate_with_seed, MAX_PERMITTED_DATA_LENGTH, - }, -}; - -const BASE: Pubkey = Pubkey::new_from_array([6; 32]); -const OWNER: Pubkey = Pubkey::new_from_array([8; 32]); -const SEED: &str = "seed"; -const SPACE: u64 = 10_000; - -#[test] -fn fail_address_with_seed_mismatch() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); // Not derived from base + seed. - - mollusk.process_and_validate_instruction( - &allocate_with_seed(&pubkey, &BASE, SEED, SPACE, &OWNER), - &[(pubkey, Account::default()), (BASE, Account::default())], - &[Check::err(ProgramError::Custom( - SystemError::AddressWithSeedMismatch as u32, - ))], - ); -} - -#[test] -fn fail_base_not_signer() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::create_with_seed(&BASE, &SEED, &OWNER).unwrap(); - - let mut instruction = allocate_with_seed(&pubkey, &BASE, SEED, SPACE, &OWNER); - instruction.accounts[1].is_signer = false; - - mollusk.process_and_validate_instruction( - &instruction, - &[(pubkey, Account::default()), (BASE, Account::default())], - &[Check::err(ProgramError::MissingRequiredSignature)], - ); -} - -#[test] -fn fail_base_key_mismatch() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::create_with_seed(&BASE, &SEED, &OWNER).unwrap(); - let not_the_base = Pubkey::new_unique(); - - let mut instruction = allocate_with_seed(&pubkey, &BASE, SEED, SPACE, &OWNER); - instruction.accounts[1].pubkey = not_the_base; - - mollusk.process_and_validate_instruction( - &instruction, - &[ - (pubkey, Account::default()), - (not_the_base, Account::default()), - ], - &[Check::err(ProgramError::MissingRequiredSignature)], - ); -} - -#[test] -fn fail_account_already_in_use() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::create_with_seed(&BASE, &SEED, &OWNER).unwrap(); - - let account = Account { - data: vec![4; 32], // Has data - ..Account::default() - }; - - mollusk.process_and_validate_instruction( - &allocate_with_seed(&pubkey, &BASE, SEED, SPACE, &OWNER), - &[(pubkey, account), (BASE, Account::default())], - &[Check::err(ProgramError::Custom( - SystemError::AccountAlreadyInUse as u32, - ))], - ); - - let account = Account { - owner: Pubkey::new_unique(), // Not System - ..Account::default() - }; - - mollusk.process_and_validate_instruction( - &allocate_with_seed(&pubkey, &BASE, SEED, SPACE, &OWNER), - &[(pubkey, account), (BASE, Account::default())], - &[Check::err(ProgramError::Custom( - SystemError::AccountAlreadyInUse as u32, - ))], - ); -} - -#[test] -fn fail_space_too_large() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::create_with_seed(&BASE, &SEED, &OWNER).unwrap(); - - let space_too_large = MAX_PERMITTED_DATA_LENGTH + 1; - - mollusk.process_and_validate_instruction( - &allocate_with_seed(&pubkey, &BASE, SEED, space_too_large, &OWNER), - &[(pubkey, Account::default()), (BASE, Account::default())], - &[Check::err(ProgramError::Custom( - SystemError::InvalidAccountDataLength as u32, - ))], - ); -} - -// [TODO: CORE_BPF]: This verifies the concern for the `realloc` issue. -#[test] -fn fail_space_too_large_for_realloc() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::create_with_seed(&BASE, &SEED, &OWNER).unwrap(); - - let space_too_large_for_realloc = MAX_PERMITTED_DATA_INCREASE + 1; - - mollusk.process_and_validate_instruction( - &allocate_with_seed( - &pubkey, - &BASE, - SEED, - space_too_large_for_realloc as u64, - &OWNER, - ), - &[(pubkey, Account::default()), (BASE, Account::default())], - &[Check::err(ProgramError::InvalidRealloc)], // See...? - ); -} - -#[test] -fn success() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::create_with_seed(&BASE, &SEED, &OWNER).unwrap(); - - mollusk.process_and_validate_instruction( - &allocate_with_seed(&pubkey, &BASE, SEED, SPACE, &OWNER), - &[(pubkey, Account::default()), (BASE, Account::default())], - &[ - Check::success(), - Check::account(&pubkey) - .owner(&OWNER) - .space(SPACE as usize) - .build(), - ], - ); -} diff --git a/program/tests/assign.rs b/program/tests/assign.rs deleted file mode 100644 index 5e2e8c7..0000000 --- a/program/tests/assign.rs +++ /dev/null @@ -1,61 +0,0 @@ -mod setup; - -use { - mollusk_svm::result::Check, solana_account::Account, solana_program_error::ProgramError, - solana_pubkey::Pubkey, solana_system_interface::instruction::assign, -}; - -const OWNER: Pubkey = Pubkey::new_from_array([8; 32]); - -#[test] -fn fail_account_not_signer() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); - - let mut instruction = assign(&pubkey, &OWNER); - instruction.accounts[0].is_signer = false; - - mollusk.process_and_validate_instruction( - &instruction, - &[(pubkey, Account::default())], - &[Check::err(ProgramError::MissingRequiredSignature)], - ); -} - -#[test] -fn success() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); - - mollusk.process_and_validate_instruction( - &assign(&pubkey, &OWNER), - &[(pubkey, Account::default())], - &[ - Check::success(), - Check::account(&pubkey).owner(&OWNER).build(), - ], - ); -} - -#[test] -fn success_already_assigned() { - let mollusk = setup::setup(); - - let pubkey = Pubkey::new_unique(); - - let account = Account { - owner: OWNER, // Already assigned - ..Account::default() - }; - - mollusk.process_and_validate_instruction( - &assign(&pubkey, &OWNER), - &[(pubkey, account)], - &[ - Check::success(), - Check::account(&pubkey).owner(&OWNER).build(), - ], - ); -} diff --git a/program/tests/setup.rs b/program/tests/setup.rs deleted file mode 100644 index 9b0e935..0000000 --- a/program/tests/setup.rs +++ /dev/null @@ -1,8 +0,0 @@ -use mollusk_svm::Mollusk; - -pub fn setup() -> Mollusk { - Mollusk::new( - &solana_system_interface::program::id(), - "solana_system_program", - ) -} diff --git a/scripts/helpers/start-validator.mts b/scripts/helpers/start-validator.mts index d9ec0b0..1b7e4ae 100644 --- a/scripts/helpers/start-validator.mts +++ b/scripts/helpers/start-validator.mts @@ -28,10 +28,7 @@ if (!restart && isValidatorRunning) { const verb = isValidatorRunning ? 'Restarting' : 'Starting'; // Get programs and accounts. -// TODO: JOE C: -// Disabled adding the BPF program until BPF implementation is complete. -// Tests expect a valid System program to live at the corresponding address. -const programs = [...getExternalPrograms()]; +const programs = [...getPrograms(), ...getExternalPrograms()]; const programPluralized = programs.length === 1 ? 'program' : 'programs'; const accounts = [...getExternalAccounts()]; const accountsPluralized = accounts.length === 1 ? 'account' : 'accounts'; @@ -100,10 +97,7 @@ try { process.exit(); } -// TODO: JOE C: -// Disabled adding the BPF program until BPF implementation is complete. -// Tests expect a valid System program to live at the corresponding address. -function _getPrograms() { +function getPrograms() { const binaryDir = path.join(workingDirectory, 'target', 'deploy'); return getProgramFolders().map((folder) => { const cargo = getCargo(folder); diff --git a/scripts/rust.mts b/scripts/rust.mts index 5cb0a9d..485bb3f 100644 --- a/scripts/rust.mts +++ b/scripts/rust.mts @@ -13,7 +13,6 @@ import { } from './helpers/utils.mts'; enum Command { - BuildSbf = 'build-sbf', Format = 'format', LintClippy = 'lint-clippy', LintDocs = 'lint-docs', @@ -38,13 +37,6 @@ async function cargo( await $`cargo ${toolchain} ${command} --manifest-path ${manifestPath} ${cargoArgs} -- ${commandArgs}`; } -async function buildSbf() { - return cargo( - 'build-sbf', - ['--features', 'bpf-entrypoint'], - ); -} - async function format() { return cargo( getToolchainArgument('format'), @@ -134,9 +126,6 @@ async function publish() { switch (command) { - case Command.BuildSbf: - await buildSbf(); - break; case Command.Format: await format(); break;