> For the complete documentation index, see [llms.txt](https://docs.yolkfi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yolkfi.com/02.-technical-architecture/security-and-storage.md).

# Security Model & Storage Optimization

### Comprehensive Threat Model

* **Host-Enforced Reentrancy Protection:** Soroban’s host environment prohibits recursive contract reentrancy by default. If Contract A calls Contract B, and Contract B attempts to re-enter Contract A while active on the call stack, the host immediately aborts the call.
* **Integer Overflow & Arithmetic Safety:** All contracts compile with `overflow-checks = true` in the Cargo release profile. Any overflow/underflow automatically panics and reverts the transaction. Financial accounting functions utilize checked arithmetic (`checked_add`, `checked_mul`).
* **Front-Running Immunity:** Yield distributions are derived directly from signed Oracle submissions, eliminating MEV and front-running vulnerabilities.
* **Replay Attack Defense:** Every production report carries a distinct `cycle_id` that is permanently committed to persistent storage. Duplicate submission attempts are atomically rejected.
* **Multisig Governance & Key Rotation:** Treasury administrative functions require multi-signature authorization. Oracle keys can be rotated dynamically via admin controls on `YieldDistributor.rs` without contract redeployment.

***

### Contract Upgradeability & Protocol 28 Evolution

YolkFi implements a transparent, auditable upgrade pattern adhering to Stellar community standard **SEP-0049**:

1. **Protocol 28 Preparedness:** The contract architecture is structured to leverage upcoming **Protocol 28** features, specifically **CAP-85 (Atomic Upgrades for Contract Fleets)** and **CAP-86 (Data Migrations)** for zero-downtime state upgrades.
2. **Multisig Upgrade Gates:** Upgrades are executed via `env.deployer().update_current_contract_wasm()` and require M-of-N threshold signatures from the protocol multisig account.
3. **Decentralization Roadmap:** As the protocol expands to multiple farm partners, upgrade authorities transition toward timelocked governance and eventual contract immutability for core accounting logic.

***

### Storage Optimization & Proactive TTL Extension

Soroban utilizes a state archival system with Time-To-Live (TTL) ledgers. YolkFi implements a proactive strategy to eliminate archival risk:

```rust
// 1. Instance Storage Extension (performed during contract calls)
env.storage().instance().extend_ttl(500_000, 1_000_000);

// 2. Persistent Storage Extension (per key during NFT transfer or yield claim)
env.storage().persistent().extend_ttl(&key, 500_000, 1_000_000);
```

* **Instance Storage:** Admin addresses, authorized Oracle signer sets, and contract configuration.
* **Persistent Storage:** Investor eligibility records, Hen NFT ownership maps, and distribution history.
* **External Cron Bumps:** A background relayer broadcasts `ExtendFootprintTTLOp` transactions to ensure inactive records never lapse.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.yolkfi.com/02.-technical-architecture/security-and-storage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
