Skip to content
Access control Audit finding Intermediate

Users cannot revoke a migration permit after the migrator loses MIGRATOR_ROLE, allowing stale approval to reactivate if the same address is re-granted the role

The staking contract's setMigrationPermit function requires the target migrator to currently hold MIGRATOR_ROLE for both granting and revoking a permit. If a migrator loses the role, a user cannot clear their earlier approval, so if the same address is later re-granted the role the stale approval lets it migrate the user's position without fresh consent.

iam0x04 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

68903 sc low users cannot revoke a migration permit after the migrator loses migrator role allowing stale approval to reactivate if the same address is re granted the role

Submitted on Mar 11th 2026 at 21:30:32 UTC by @iam0x04 for Audit Comp | Folks Finance: Staking Contracts

Description

Brief/Intro

setMigrationPermit() blocks both granting and revoking permission behind a live MIGRATOR_ROLE check. As a result, if a user previously approved a migrator, and that migrator later loses its role, the user can no longer clear the stored approval. If the same address is granted MIGRATOR_ROLE again in the future, the stale approval becomes active again and the migrator can move the user’s still-open staking position without fresh consent, breaking the intended “user-controlled migration” model.

Vulnerability Details

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);
}

https://github.com/Folks-Finance/folks-staking-contracts/blob/3131a2d46b5afa76f606bf08adfd85452a47e2d8/src/Staking.sol#L77-L82

This function applies the same hasRole(MIGRATOR_ROLE, _migrator) gate to both:

  • enabling a permit with true
  • disabling a permit with false

That creates the following broken state transition:

  1. A user grants migration permission to migrator M by calling setMigrationPermit(M, true).
  2. Later, M loses MIGRATOR_ROLE.
  3. The user attempts to revoke the old approval with setMigrationPermit(M, false).
  4. The call reverts with MigratorNotFound(M) because M no longer has the role.
  5. The old value in migrationPermits[M][user] remains true.
  6. If M is re-granted MIGRATOR_ROLE later, the stale approval is immediately valid again.

The stale approval is then consumed by migratePositionsFrom()

Solidity
if (!migrationPermits[msg.sender][user]) revert MigratorNotPermitted(msg.sender, user);
...
TOKEN.safeTransfer(msg.sender, unclaimedUserAmount + unclaimedUserRewards);

Once the role is re-granted, the old permit is enough for the migrator to pass authorization and receive the user’s remaining principal and rewards from the staking contract.

This is also inconsistent with the documentation in README.md (line 136), which states that migration permission "can be revoked at any time."

https://github.com/Folks-Finance/folks-staking-contracts/blob/3131a2d46b5afa76f606bf08adfd85452a47e2d8/README.md?plain=1#L134-L140

Impact Details

The impact is that a stale migration approval can later be reused to migrate a user’s active position without fresh consent if the same address is re-granted MIGRATOR_ROLE.

Proof of Concept

Put this file under the test folder.

Solidity
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.23;

import "./Staking.t.sol";

contract StaleMigrationPermitRegrantPoC is StakingTest {
    function test_poc_staleMigrationPermitCanBeUsedAfterRoleRegrant() 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));

        vm.prank(alice);
        staking.setMigrationPermit(migrator, true);
        assertTrue(staking.migrationPermits(migrator, alice));

        vm.prank(admin);
        staking.revokeRole(keccak256("MIGRATOR"), migrator);

        vm.expectRevert(abi.encodeWithSelector(IStakingV1.MigratorNotFound.selector, migrator));
        vm.prank(alice);
        staking.setMigrationPermit(migrator, false);

        assertTrue(staking.migrationPermits(migrator, alice));

        vm.prank(admin);
        staking.grantRole(keccak256("MIGRATOR"), migrator);

        uint256 expectedTransferredBalance = 10 ether + calculateReward(10 ether, 20, 5000);

        vm.prank(migrator);
        IStakingV1.UserStake[] memory migratedStakes = staking.migratePositionsFrom(alice);

        assertEq(migratedStakes.length, 1);
        assertEq(migratedStakes[0].amount, 10 ether);
        assertEq(staking.getUserStakes(alice).length, 0);
        assertEq(token.balanceOf(migrator), expectedTransferredBalance);
    }
}
  • Alice stakes 10 ether into the staking contract.
  • Alice explicitly grants migration permission to migrator.
  • Admin revokes MIGRATOR_ROLE from migrator.
  • Alice tries to revoke the old permission, but the call reverts with MigratorNotFound.
  • The stored approval remains true even though the migrator was deauthorized.
  • Admin grants MIGRATOR_ROLE back to the same migrator address.
  • The migrator successfully calls migratePositionsFrom(alice) using the stale approval.
  • The test confirms Alice’s stake is removed and the migrator receives Alice’s principal plus reward.
Bash
forge test --mt test_poc_staleMigrationPermitCanBeUsedAfterRoleRegrant

The original report as published on Immunefi, by iam0x04. 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 permit-setting function applies the same live role check to both granting and revoking, so a revocation is impossible once the migrator no longer holds the role.

Impact

A stale approval could later be reused to migrate a user's active position without fresh consent if the same address is re-granted MIGRATOR_ROLE.

What the attacker needed

User has staked tokens; user previously approved the migrator; migrator loses then regains the role

The fix

The permit-setting function should allow a user to revoke a permit without requiring the migrator to currently hold MIGRATOR_ROLE, for example by only checking the role when setting the permit to true.

How it was found

  1. A user grants migration permission to a migrator address.
  2. The admin revokes MIGRATOR_ROLE from that migrator.
  3. The user tries to revoke the old permission but the call reverts with MigratorNotFound.
  4. The stored approval remains true.
  5. The admin re-grants MIGRATOR_ROLE to the same address.
  6. The migrator calls migratePositionsFrom for the user and receives their principal plus rewards.

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 user can give a helper contract permission to move their staked tokens. The contract only lets that permission be changed while the helper is still officially trusted. If the helper is untrusted and later trusted again, the old permission silently comes back to life, so the user's stake can be moved without asking them again.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by iam0x04

View all

6 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.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.