Skip to content

Revert "fix(scout_access): replace expect("overflow") with ScoutAccessError::Overflow" - #3

Closed
gracious01-tech wants to merge 1 commit into
mainfrom
revert-2-feat/overflow-error-handling
Closed

Revert "fix(scout_access): replace expect("overflow") with ScoutAccessError::Overflow"#3
gracious01-tech wants to merge 1 commit into
mainfrom
revert-2-feat/overflow-error-handling

Conversation

@gracious01-tech

Copy link
Copy Markdown
Owner

Description

Replaced panic-based overflow handling in log_trial_offer with a typed contract error.

Previously, the contract used .expect("overflow") on checked_add, which caused execution to panic instead of returning a predictable contract error.

This update now safely returns ScoutAccessError::Overflow when the counter exceeds the maximum u32 limit.


Related Issue

Closes scout-off#109


Type of Change

  • Bug fix
  • Smart contract reliability improvement
  • Error handling enhancement
  • New feature
  • Refactor
  • Documentation

Changes Included

  • Removed .expect("overflow") from scout_access/src/lib.rs
  • Added graceful overflow handling using ScoutAccessError::Overflow
  • Updated counter increment logic to return typed errors
  • Added overflow boundary unit tests

Security Impact

Improves contract stability and prevents panic-based execution failures.

No authorization or payment logic changed.


Testing

  • Added unit test simulating overflow using u32::MAX
  • Verified ScoutAccessError::Overflow is returned correctly
  • Verified normal counter increments still succeed
  • Existing tests remain green

Manual Testing Steps

  • Set TrialCounter to u32::MAX
  • Called log_trial_offer
  • Verified contract returns ScoutAccessError::Overflow
  • Confirmed no panic occurs
  • Tested standard increment flow successfully

Acceptance Criteria Coverage

  • No .expect("overflow") remains in scout_access/src/lib.rs
  • Unit test simulates overflow using u32::MAX

Breaking Changes

No breaking changes.

This change only replaces panic behavior with typed error handling.


Checklist

  • Code builds successfully
  • Tests pass
  • Follows project conventions
  • No sensitive data exposed
  • Existing functionality preserved

Additional Context

Using typed errors instead of panics improves predictability for integrators and aligns with recommended Soroban smart contract error-handling practices.


Reviewer Notes

Please focus on:

  • Correct overflow detection logic
  • Proper propagation of ScoutAccessError::Overflow
  • Removal of panic-based handling
  • Boundary-condition test coverage

@gracious01-tech
gracious01-tech deleted the revert-2-feat/overflow-error-handling branch May 31, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

log_trial_offer TrialCounter overflow uses expect instead of returning a typed error

1 participant