Skip to content

Add access control to Pausable trait examples#1764

Merged
leighmcculloch merged 12 commits intomainfrom
pause-example
Mar 17, 2026
Merged

Add access control to Pausable trait examples#1764
leighmcculloch merged 12 commits intomainfrom
pause-example

Conversation

@leighmcculloch
Copy link
Copy Markdown
Member

What

pause() and unpause() default implementations in the v25 contracttrait migration guide now call require_auth on an admin address retrieved from instance storage. A __constructor is added to each example to initialize the admin address. Inline string literals for storage keys are replaced with named constants ADMIN and PAUSED.

Why

The previous examples exported pause() and unpause() as publicly callable contract functions without any authorization check. Developers following the pattern as written would ship contracts with open pause entrypoints. This ensures the examples start from a secure baseline. Closes #1763.

Close #1763

@leighmcculloch leighmcculloch requested a review from mootz12 March 17, 2026 05:46
@leighmcculloch leighmcculloch marked this pull request as ready for review March 17, 2026 06:59
Copilot AI review requested due to automatic review settings March 17, 2026 06:59
@leighmcculloch leighmcculloch requested review from a team and removed request for mootz12 March 17, 2026 07:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the v25 migration note for #[contracttrait] to demonstrate a more realistic “pausable” pattern that includes admin authorization, constructor initialization, and test setup using testutils mock auths.

Changes:

  • Introduces an auxiliary (non-exported) RequireAuthForPause trait and makes Pausable depend on it.
  • Adds an __constructor to initialize an admin value in instance storage and enforces require_auth() in pause/unpause.
  • Expands the doctest examples to show MockAuth/MockAuthInvoke usage for authorized calls.

Comment thread soroban-sdk/src/_migrating/v25_contracttrait.rs
Comment thread soroban-sdk/src/_migrating/v25_contracttrait.rs
Comment thread soroban-sdk/src/_migrating/v25_contracttrait.rs
Comment thread soroban-sdk/src/_migrating/v25_contracttrait.rs
Comment thread soroban-sdk/src/_migrating/v25_contracttrait.rs
Comment thread soroban-sdk/src/_migrating/v25_contracttrait.rs
@leighmcculloch leighmcculloch added this pull request to the merge queue Mar 17, 2026
Merged via the queue into main with commit c8cd59e Mar 17, 2026
182 of 184 checks passed
@leighmcculloch leighmcculloch deleted the pause-example branch March 17, 2026 13:48
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.

Pausable trait example in v25 migration guide should include access control best practice

3 participants