arch_program/lib.rs
1#![allow(unexpected_cfgs)]
2/*!
3# Arch Program
4A Rust library for building programs that run inside the Arch Virtual Machine. This crate
5provides core functionality for creating instructions, managing accounts, handling program
6errors, and interacting with the Arch runtime environment.
7## Features
8- Bitcoin transaction and UTXO management
9- Account data manipulation and ownership verification
10- System instruction creation and processing
11- Program error handling
12- Logging utilities
13- Cryptographic operations including secp256k1 signature recovery
14- Memory management for on-chain programs
15## Usage
16Add this crate to your `Cargo.toml`:
17```toml
18[dependencies]
19arch_program = "0.4.0"
20```
21Then import the modules you need in your code:
22```rust
23use arch_program::account::AccountInfo;
24use arch_program::pubkey::Pubkey;
25use arch_program::instruction::Instruction;
26// ... other imports as needed
27```
28*/
29
30pub use bitcoin;
31
32// Re-export commonly used functions
33pub use program::{
34 get_bitcoin_block_height, get_clock, get_remaining_compute_units, get_stack_height,
35};
36
37/// Account management and ownership verification
38pub mod account;
39/// Atomic operations for u64 values
40pub mod atomic_u64;
41pub mod bpf_loader;
42/// Time-related functionality for on-chain programs
43pub mod clock;
44pub mod compiled_keys;
45/// Compute budget instruction definitions and processing
46pub mod compute_budget;
47/// Utilities for debugging account data
48pub mod debug_account_data;
49/// Error handling for decoding operations
50pub mod decode_error;
51/// Program entrypoint definitions and processing
52pub mod entrypoint;
53/// Hash type for 32-byte cryptographic hashes
54pub mod hash;
55pub mod hashing_functions;
56/// Helper functions for common operations
57pub mod helper;
58/// Bitcoin transaction input signing utilities
59pub mod input_to_sign;
60/// Instruction definitions and processing
61pub mod instruction;
62pub mod loader_instruction;
63/// Logging functionality for on-chain programs
64pub mod log;
65
66pub mod native_loader;
67/// Program runtime interfaces and state management
68pub mod program;
69/// Error types for program operations
70pub mod program_error;
71/// Memory management for program execution
72pub mod program_memory;
73/// Optional value representation for programs
74pub mod program_option;
75/// Data serialization and deserialization for on-chain storage
76pub mod program_pack;
77/// Stub implementations for program interfaces
78#[cfg(not(target_os = "solana"))]
79pub mod program_stubs;
80pub mod program_utils;
81/// Public key definitions and operations
82pub mod pubkey;
83
84/// Convenience macro to declare a static program ID and helper functions.
85///
86/// Input: a single literal base58 string representation of a program's ID.
87///
88/// This generates:
89/// - A `const ID: Pubkey` — the program ID, decoded at compile time.
90/// - A `fn check_id(id: &Pubkey) -> bool` — returns `true` if the given pubkey matches.
91/// - A `const fn id() -> Pubkey` — returns the program ID.
92///
93/// # Example
94///
95/// ```ignore
96/// use arch_program::declare_id;
97///
98/// declare_id!("MyProgram111111111111111111111111111111111");
99///
100/// assert_eq!(id(), ID);
101/// assert!(check_id(&id()));
102/// ```
103#[macro_export]
104macro_rules! declare_id {
105 ($address:expr) => {
106 /// The const program ID.
107 pub const ID: $crate::pubkey::Pubkey = $crate::pubkey::Pubkey::from_str_const($address);
108
109 /// Returns `true` if given pubkey is the program ID.
110 pub fn check_id(id: &$crate::pubkey::Pubkey) -> bool {
111 id == &ID
112 }
113
114 /// Returns the program ID.
115 pub const fn id() -> $crate::pubkey::Pubkey {
116 ID
117 }
118
119 #[cfg(test)]
120 #[test]
121 fn test_id() {
122 assert!(check_id(&id()));
123 }
124 };
125}
126pub mod rent;
127/// Resharing defines.
128pub mod resharing;
129/// Sanitization trait and error types for validating over-the-wire messages
130pub mod sanitize;
131/// Sanitized transaction processing
132pub mod sanitized;
133/// Secp256k1 signature recovery utilities
134pub mod sol_secp256k1_recover;
135/// Stable memory layout implementations
136pub mod stable_layout;
137pub mod stake;
138/// System call interfaces for interacting with the runtime
139pub mod syscalls;
140/// System instruction definitions and creation
141pub mod system_instruction;
142pub mod system_program;
143/// Bitcoin transaction signing utilities
144pub mod transaction_to_sign;
145/// Bitcoin UTXO (Unspent Transaction Output) management
146pub mod utxo;
147pub mod vote;
148
149pub mod serde_error;
150
151#[macro_use]
152extern crate serde_derive;
153
154/// Rune management
155pub mod rune;
156
157/// Maximum size of a Bitcoin transaction in bytes
158pub const MAX_BTC_TX_SIZE: usize = 3976;
159
160/// Maximum size of a Bitcoin rune output in bytes
161pub const MAX_BTC_RUNE_OUTPUT_SIZE: usize = 2048;
162
163pub const MAX_SIGNERS: usize = 16;
164pub const MAX_SEEDS: usize = 16;
165pub const MAX_SEED_LEN: usize = 32;
166/// Max Taproot inputs to keep tx size ≤ 4096 bytes.
167/// Each input ≈ 161 bytes (base + witness).
168/// 4096 / 161 ≈ 25
169pub const MAX_BTC_TXN_INPUTS: usize = 25;
170
171pub mod builtin {
172 use super::*;
173 use crate::pubkey::Pubkey;
174
175 pub const BUILTIN_PROGRAMS_ID: &[Pubkey] =
176 &[native_loader::ID, system_program::ID, bpf_loader::ID];
177}