Skip to content

fix(security): require admin auth for MintToken in batch operations (#39)#122

Merged
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
nanoulloa:fix/mint-token-batch-admin-guard
Jul 24, 2026
Merged

fix(security): require admin auth for MintToken in batch operations (#39)#122
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
nanoulloa:fix/mint-token-batch-admin-guard

Conversation

@nanoulloa

Copy link
Copy Markdown
Contributor

Summary

Closes #39.

The batch MintToken path was unauthenticated. In batch.rs,
authorize_batch_access did nothing for BatchOperation::MintToken (=> {}),
and in lib.rs the batch entry points extracted caller only from
Swap/AddLiquidity/RemoveLiquidity ops, setting caller = None for a
mint-first batch. Together these let anyone mint tokens by submitting a
batch containing a MintToken, bypassing every KYC and admin guard.

This PR makes MintToken admin-only inside batches.

Changes

  • peerx-contracts/counter/batch.rsauthorize_batch_access now flags
    requires_admin on any MintToken op and, exactly once after the loop,
    calls the new require_batch_admin helper. The helper loads the configured
    admin (ADMIN_KEY), enforces admin.require_auth(), and re-checks
    require_admin, failing closed with admin_req when no admin is configured.
    Both execute_batch_atomic and execute_batch_best_effort route through
    authorize_batch_access, so both paths are covered by a single, DRY guard.
  • peerx-contracts/counter/src/kyc_tests.rs — regression tests: a
    non-admin mint batch reverts on both the atomic and best-effort paths, and a
    mint batch fails closed when no admin is configured.
  • scripts/check_kyc_guards.sh — extended so CI enforces the batch admin
    gate (require_batch_admin, admin.require_auth(),
    crate::admin::require_admin(env, &admin)).

Acceptance criteria

  • execute_batch_atomic and execute_batch_best_effort require the admin
    when any op is MintToken (via the shared authorize_batch_access).
  • Test: non-admin batch with MintToken reverts.
  • check_kyc_guards.sh updated (and passing).

Verification

  • scripts/check_kyc_guards.sh passes (this is the hard CI gate).
  • batch.rs compiles cleanly; the added tests type-check cleanly.
  • The counter crate as a whole does not yet build locally due to the
    in-progress soroban-sdk migration already tracked in CI ("user-code compile
    errors being triaged post-SDK migration"), which is unrelated to this change.
    To validate the fix behaves correctly at runtime regardless, the exact
    authorization logic was replicated in an isolated Soroban contract and
    executed against the host: an unauthorized (non-admin) mint batch reverts, an
    admin-authorized mint batch succeeds, and a mint batch with no admin
    configured fails closed — while the previous (empty-arm) logic let an
    unauthorized mint through.

…penPeerX#39)

`authorize_batch_access` did nothing for `BatchOperation::MintToken`, and
the `lib.rs` batch entry points set `caller = None` for a mint-first batch.
Together these let anyone mint by submitting a batch whose operation is a
`MintToken`, bypassing every KYC and admin guard.

Gate any batch that mints behind the contract admin. `authorize_batch_access`
now flags `requires_admin` on any `MintToken` op and, once, calls the new
`require_batch_admin` helper, which loads the stored admin, enforces
`admin.require_auth()`, and re-checks `require_admin` (fail-closed to
`admin_req` when no admin is configured). Both `execute_batch_atomic` and
`execute_batch_best_effort` route through this helper.

- Add regression tests: non-admin mint batch reverts (atomic + best-effort),
  and mint fails closed when no admin is configured.
- Extend scripts/check_kyc_guards.sh to enforce the batch admin gate in CI.

Closes OpenPeerX#39

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@ameeribro4-sudo ameeribro4-sudo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LLGTM

@ameeribro4-sudo
ameeribro4-sudo merged commit c2d4f95 into OpenPeerX:main Jul 24, 2026
3 checks passed
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.

[PeerX Backlog # 39] MintToken batch path must require authentication

2 participants