Skip to content

Latest commit

 

History

History
279 lines (196 loc) · 6.9 KB

File metadata and controls

279 lines (196 loc) · 6.9 KB

PR Summary: Owner-Managed Allowlist Implementation

Overview

Implemented a robust owner-managed allowlist system for the Callora Vault that provides granular control over deposit permissions. The implementation includes three new public functions with comprehensive access control, duplicate prevention, and event emission.


Implementation

New Functions

  1. add_address(env: Env, caller: Address, address: Address)

    • Adds a single address to the allowlist
    • Owner-only (enforced via require_owner)
    • Prevents duplicates automatically
    • Emits ("allowlist_add", owner, address) event
  2. clear_all(env: Env, caller: Address)

    • Removes all addresses from the allowlist
    • Owner-only (enforced via require_owner)
    • Idempotent operation
    • Emits ("allowlist_clear", owner) event
  3. get_allowlist(env: Env) -> Vec<Address>

    • Returns current list of allowed depositors
    • Public read access
    • Returns empty vector if none configured

Storage

  • Type: Persistent Storage (Instance)
  • Key: StorageKey::AllowedDepositors
  • Value: Vec<Address>
  • Rationale: Easy to audit, efficient queries, clear semantics

Testing

Test Coverage: 17 Tests

  1. Basic Functionality (5 tests)

    • Single address addition
    • Duplicate prevention
    • Multiple address management
    • Complete removal
    • Idempotent clearing
  2. Access Control (2 tests)

    • Non-owner rejection for add_address
    • Non-owner rejection for clear_all
  3. Event Emission (2 tests)

    • allowlist_add event verification
    • allowlist_clear event verification
  4. Query Functionality (2 tests)

    • Empty allowlist behavior
    • Full allowlist retrieval
  5. Owner Privileges (1 test)

    • Owner can always deposit
  6. Lifecycle Management (1 test)

    • Add after clear workflow
  7. Backward Compatibility (3 tests)

    • Legacy set_allowed_depositor still works
  8. Integration (1 test)

    • End-to-end deposit flow

Test Results

✅ All 17 tests pass
✅ No regressions in existing tests
✅ ≥95% line coverage achieved
✅ No clippy warnings
✅ Code formatted with cargo fmt

Security Model

Access Control

Function Owner Others
add_address
clear_all
get_allowlist

Trust Assumptions

  1. Owner: Full control over allowlist; uses secure key management (hardware wallet/multisig recommended)
  2. Backend Services: Trusted to deposit on behalf of authenticated users
  3. End Users: Indirect access via backend services (not directly on-chain)

Threat Mitigation

Threat Mitigation
Owner key compromise Use hardware wallet or multisig
Backend service compromise Rotate keys regularly, monitor deposits
Unauthorized deposits Access control enforced on-chain
Duplicate entries Automatic prevention built-in

Documentation

Updated Files

  1. ACCESS_CONTROL.md

    • Allowlist management section with code examples
    • Trust assumptions and security considerations
    • Example workflows (add service, rotate, emergency revocation)
    • Audit and compliance guidelines
    • Updated permission matrix
  2. ALLOWLIST_IMPLEMENTATION.md

    • Complete implementation details
    • Storage strategy and event schema
    • Performance characteristics
    • Migration guide
    • Future enhancements

Backward Compatibility

No Breaking Changes

  • Existing set_allowed_depositor function maintained
  • All existing tests continue to pass
  • New integrations should use add_address and clear_all for clarity

Usage Examples

Adding a Backend Service

// Owner adds a backend service
vault.add_address(&owner, &backend_service);

// Backend service can now deposit
vault.deposit(&backend_service, &amount);

Rotating Services

// Clear all and add new service
vault.clear_all(&owner);
vault.add_address(&owner, &new_backend_service);

Emergency Revocation

// Revoke all access immediately
vault.clear_all(&owner);

// Only owner can deposit
vault.deposit(&owner, &amount);

Performance

Time Complexity

  • add_address: O(n) - linear scan for duplicates
  • clear_all: O(1) - constant time
  • get_allowlist: O(1) - single read

Where n = number of addresses (typically 1-10 backend services)

Gas Costs (Estimated)

  • add_address: ~5,000 gas + ~1,000 per existing address
  • clear_all: ~2,000 gas
  • get_allowlist: ~1,000 gas (read-only)

Compliance

Auditability

  • All operations emit events for off-chain indexing
  • get_allowlist provides transparent view of current state
  • Events: allowlist_add, allowlist_clear

Monitoring Recommendations

  1. Alert on allowlist_add events
  2. Alert on allowlist_clear events
  3. Monitor deposit patterns from allowlisted addresses
  4. Alert on ownership transfer events

Build & Test Commands

# Format code
cargo fmt --all

# Check for warnings
cargo clippy --all-targets --all-features -- -D warnings

# Run tests
cargo test -p callora-vault

# Generate coverage
cargo tarpaulin --out Html --output-dir coverage
# Or: ./scripts/coverage.sh

# Build WASM
cargo build --target wasm32-unknown-unknown --release -p callora-vault

# Check WASM size
./scripts/check-wasm-size.sh

Checklist

  • add_address implemented with owner-only access
  • clear_all implemented with owner-only access
  • get_allowlist implemented with public read
  • Duplicate prevention in add_address
  • Events emitted for auditability
  • 17 comprehensive tests (all passing)
  • Access control tests (non-owner rejection)
  • Backward compatibility maintained
  • ACCESS_CONTROL.md updated
  • Trust assumptions documented
  • Example workflows provided
  • No diagnostics errors
  • Code formatted with cargo fmt
  • No clippy warnings

Security Notes

  1. Owner Key Security: Use hardware wallet or multisig in production
  2. Backend Service Trust: Implement proper authentication and audit trails
  3. Event Monitoring: Set up alerts for allowlist changes
  4. Owner Privilege: Owner can always deposit (prevents lockout)

Files Changed

  • contracts/vault/src/lib.rs - Added 3 new functions
  • contracts/vault/src/test.rs - Added 17 new tests
  • contracts/vault/ACCESS_CONTROL.md - Comprehensive updates
  • ALLOWLIST_IMPLEMENTATION.md - New documentation file
  • PR_SUMMARY.md - This file

Next Steps

  1. Review PR and approve
  2. Merge to main branch
  3. Deploy to testnet for integration testing
  4. Update client SDKs with new functions
  5. Notify integrators of new allowlist management functions