A minimal in-memory token ledger written in Rust, built while preparing for the Rektoff Solana Rust Security Bootcamp.
The feature set is intentionally tiny — open accounts, mint, transfer, read balances. The point is not what it does but how carefully it does it. Every state-changing operation is written to defend against a vulnerability class that shows up in real Solana audits.
| Vulnerability class | How safe-ledger handles it |
|---|---|
| Integer overflow / underflow | Every balance change uses checked_add / checked_sub, which return None instead of wrapping. Overflow checks are also left on in release builds (overflow-checks = true). |
| Missing authorization | transfer takes an explicit signer. Funds only move if the signer owns the source account — mirroring Solana's signer/account model, where a forgotten ownership check is a top exploit. |
| Unchecked inputs | Zero amounts, self-transfers, and unknown accounts are rejected up front with typed errors instead of silently succeeding. |
| Partial state mutation | All arithmetic is computed before any balance is written, so an error never leaves the ledger half-updated (no tokens created or destroyed on the error path). |
# See the security checks rejecting attacks live:
cargo run
# Run the test suite (12 tests, including one per security property):
cargo testcargo run walks through a normal transfer and then four blocked attacks:
unauthorized withdrawal, overspend (underflow), overflow on credit, and a
zero-value transfer.
src/lib.rs— theLedgertype, theLedgerErrorenum, and the unit tests.src/main.rs— a scripted demo that exercises the library.
The library exposes a small, Result-based API so a caller can never ignore a
failure path:
let mut ledger = Ledger::new();
ledger.open_account("alice")?;
ledger.mint("alice", 1_000)?;
ledger.transfer("alice", "alice", "bob", 250)?; // signer, from, to, amountThis is a learning project, not a production system. It is single-threaded,
in-memory, and uses String account ids for readability rather than real
public keys. What it demonstrates is the security mindset — treating every
arithmetic operation and every authority check as a place a bug could hide — not
a finished ledger. See STUDY_GUIDE.md for the reasoning
behind each decision.
MIT