Skip to content

[Contracts][Bug] panic!()/unwrap() in production contract code paths #473

Description

@Penielka

Overview

Several production (non-test) contract files panic or unwrap on data that may legitimately be absent:

  • contracts/src/access_control.rs:79-82panic!("Caller does not have Admin role") etc. instead of returning an error (reverts burn all gas for the caller)
  • contracts/src/access_control.rs:34,53,68roles.get(i).unwrap()
  • contracts/src/analyticsStorage.rs:71,107,134,148,187-188,203unwrap() on vector indexing

In Soroban, panics revert the transaction and waste the entire submission fee; a panic in an admin-check path also bricks governance operations for everyone. Unwraps on Vec::get should be require!(...) or ok_or(...)? with clear error codes.

Evidence

  • contracts/src/access_control.rs — panics in require_role-style logic
  • contracts/src/analyticsStorage.rs — multiple .unwrap()

Acceptance Criteria

  • Replace panics in role checks with require!/error returns (or #[contracterror] variants)
  • Replace .unwrap() on vector lookups with checked access and contract errors
  • Add tests asserting error paths return proper Err instead of panicking

Files to Modify

  • contracts/src/access_control.rs
  • contracts/src/analyticsStorage.rs

Priority: High

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcontractsSmart contract issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions