Nova-Rewards

Optimized Storage Schema

This document describes the storage layout optimizations applied to Nova Rewards smart contracts to stay within Soroban’s WASM size and storage budget limits.

Optimization Strategy

This audit reviewed the nova-rewards, nova_token, vesting, referral, reward_pool, and admin_roles contracts. Existing keys are already mostly consolidated; the new DailyUsage struct in reward_pool further reduces per-wallet storage overhead.

1. Storage Key Consolidation

Where multiple fields are always read/written together, they have been consolidated into single struct values to reduce storage overhead.

2. Fixed-Length Identifiers

Using Bytes or BytesN instead of String for fixed-length identifiers reduces encoding overhead.

3. TTL Management

All persistent storage entries have appropriate TTL extensions to prevent ledger expiry.

Contract Storage Layouts

Nova Rewards Contract (nova-rewards)

Storage Keys:

Optimizations Applied:

WASM Size: Measured with stellar contract inspect --wasm

Nova Token Contract (nova_token)

Storage Keys:

Optimizations Applied:

TTL Extensions:

Vesting Contract (vesting)

Storage Keys:

Optimizations Applied:

TTL Extensions:

Admin Roles Contract (admin_roles)

Storage Keys:

Optimizations Applied:

Referral Contract (referral)

Storage Keys:

Optimizations Applied:

TTL Extensions:

Reward Pool Contract (reward_pool)

Storage Keys:

Optimizations Applied:

TTL Extensions:

Storage Budget Guidelines

Instance Storage

Persistent Storage

Temporary Storage

TTL Extension Pattern

// Example: Extending TTL on persistent storage read
let balance: i128 = env
    .storage()
    .persistent()
    .get(&DataKey::Balance(addr.clone()))
    .unwrap_or(0);

// Extend TTL by 31 days (2,678,400 ledgers at 5s/ledger)
env.storage()
    .persistent()
    .extend_ttl(&DataKey::Balance(addr.clone()), 2_678_400, 2_678_400);

WASM Size Measurements

Run before and after optimization:

cd contracts
stellar contract build
stellar contract inspect --wasm target/wasm32v1-none/release/nova_rewards.wasm
stellar contract inspect --wasm target/wasm32v1-none/release/nova_token.wasm
stellar contract inspect --wasm target/wasm32v1-none/release/vesting.wasm

Size Targets

Future Optimization Opportunities

  1. Pagination: For contracts with unbounded lists, implement pagination to avoid loading entire collections
  2. Lazy Loading: Load struct fields on-demand rather than entire structs
  3. Compression: Use bit-packing for boolean flags and small enums
  4. Archive Old Data: Move historical data to off-chain storage, keep only recent entries on-chain

References