Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

safe-ledger

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.

What it defends against

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).

Run it

# See the security checks rejecting attacks live:
cargo run

# Run the test suite (12 tests, including one per security property):
cargo test

cargo run walks through a normal transfer and then four blocked attacks: unauthorized withdrawal, overspend (underflow), overflow on credit, and a zero-value transfer.

How it's structured

  • src/lib.rs — the Ledger type, the LedgerError enum, 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, amount

Scope and honesty

This 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.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages