Skip to content
Business logic Audit finding Beginner

Incorrect guard in setMigrationPermit prevents revocation after role removal, breaking documented user control

The setMigrationPermit function checks the migrator role even when a user is revoking a permit, so once an admin removes that role the user's revocation call reverts. A user who had granted a permit can then no longer withdraw it, contradicting the documented ability to revoke at any time.

Orhuk1 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

69376 sc low incorrect guard in setmigrationpermit prevents revocation after role removal breaking documented user control

Submitted on Mar 14th 2026 at 14:33:33 UTC by @Orhuk1 for Audit Comp | Folks Finance: Staking Contracts

Description

The setMigrationPermit function applies the MIGRATOR_ROLE check unconditionally regardless of whether the caller is granting or revoking a permit:

Solidity
function setMigrationPermit(address _migrator, bool _isMigrationPermitted) external {
    if (!hasRole(MIGRATOR_ROLE, _migrator)) revert MigratorNotFound(_migrator);
    migrationPermits[_migrator][msg.sender] = _isMigrationPermitted;
    emit MigrationPermitUpdated(_migrator, msg.sender, _isMigrationPermitted);
}

When a migrator's role is revoked by the admin, any user who had previously granted that migrator a permit can no longer revoke it. The call reverts with MigratorNotFound even though the user is only attempting to modify their own state.

This directly contradicts the documented behavior in the README:

"The permission can be revoked at any time by calling setMigrationPermit(migratorAddress, false)."

The fix is to apply the role guard only when granting, not when revoking:

Solidity
function setMigrationPermit(address _migrator, bool _isMigrationPermitted) external {
    if (_isMigrationPermitted && !hasRole(MIGRATOR_ROLE, _migrator)) {
        revert MigratorNotFound(_migrator);
    }
    migrationPermits[_migrator][msg.sender] = _isMigrationPermitted;
    emit MigrationPermitUpdated(_migrator, msg.sender, _isMigrationPermitted);
}

This preserves the behaviour that users cannot grant permits to non-migrators, while allowing unconditional revocation regardless of the migrator's current role status.

Proof of Concept

Steps:

  1. Alice grants a migration permit to migrator while the role is active
  2. Admin revokes MIGRATOR_ROLE from migrator
  3. Alice calls setMigrationPermit(migrator, false) to revoke her permit
  4. The call reverts with MigratorNotFound — Alice has no on-chain remedy
Solidity
function test_revocationBlockedAfterRoleRemoved() public {
    deal(address(token), address(staking), 1000 ether);
    deal(address(token), alice, 100 ether);

    uint8 periodIndex = addStakingPeriodByManager(50 ether, 20, 10, 5000, true);
    approveAndStake(alice, periodIndex, 10 ether, 20, 10, 5000, address(0));

    // Step 1: Alice grants permit to migrator
    vm.prank(alice);
    staking.setMigrationPermit(migrator, true);
    assertTrue(staking.migrationPermits(migrator, alice));

    // Cache role before pranking to prevent prank being consumed by argument evaluation
    bytes32 migratorRole = staking.MIGRATOR_ROLE();

    // Step 2: Admin revokes migrator role
    vm.prank(admin);
    staking.revokeRole(migratorRole, migrator);
    assertFalse(staking.hasRole(migratorRole, migrator));

    // Step 3 & 4: Alice attempts to revoke her permit — reverts
    vm.expectRevert(
        abi.encodeWithSelector(IStakingV1.MigratorNotFound.selector, migrator)
    );
    vm.prank(alice);
    staking.setMigrationPermit(migrator, false);

    // Permit remains true with no on-chain remedy for Alice
    assertTrue(staking.migrationPermits(migrator, alice));
}
Bash
forge test --match-test test_revocationBlockedAfterRoleRemoved -vvv

The original report as published on Immunefi, by Orhuk1. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The role check is applied unconditionally, including on revocation, instead of only when granting a permit.

Impact

A user cannot revoke a previously granted migration permit after the migrator's role is removed, leaving the permission active with no on-chain remedy; the report rates this as low severity with no loss of value.

What the attacker needed

User previously granted a permit; admin revokes the migrator role

The fix

The role check should apply only when granting a permit, so revocation always succeeds; the report proposes this change but does not say it was applied.

How it was found

  1. Alice grants a migration permit to the migrator while the role is active.
  2. The admin revokes the migrator role from that migrator.
  3. Alice calls setMigrationPermit with false to revoke her permit.
  4. The call reverts with MigratorNotFound and the permit stays true.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A permit here is a user's permission letting a migrator move their staked funds. The contract only lets you change that permission if the migrator still holds a special role, and that check also runs when you try to switch the permission off. So if an admin removes the role, your own permission stays switched on and you cannot turn it off yourself.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Orhuk1

View all

3 more disclosed reports, best first.

More from Folks Finance: Staking Contracts

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.