Skip to content
Access control Audit finding Intermediate

Stale migration permit reactivation in folks finance staking contract

The staking contract only allows users to change a migration permit if the target address currently holds the migrator role, so users cannot revoke a permit after that role is removed. If the same address later regains the role, the old permit becomes active again and the migrator can migrate the user's staking positions without a new approval.

jo13 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

69263 sc low stale migration permit reactivation in folks finance staking contract

Submitted on Mar 13th 2026 at 20:54:07 UTC by @jo13 for Audit Comp | Folks Finance: Staking Contracts

Description

Brief/Intro

The Staking contract allows users to grant migration permission only to addresses that currently hold MIGRATOR_ROLE, but it applies the same role check when users try to revoke an existing permission. This means that once a migrator loses its role, users can no longer explicitly clear the stored permit for that address. If the same address later receives MIGRATOR_ROLE again, the previously granted permission becomes active again automatically. In production, this can unexpectedly reactivate stale migration approvals and weaken user control over who can migrate their staking positions.

Vulnerability Details

The issue is located in setMigrationPermit():

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

This function uses a current-role existence check before allowing any update to the stored permission mapping. That is reasonable when the user is trying to newly authorize a migrator, but it becomes problematic when the user wants to revoke an already stored permission.

The migrationPermits mapping is keyed by migrator address and user address:

Solidity
mapping(address migrator => mapping(address user => bool isAuthorized)) public migrationPermits;

The stored value is not deleted automatically when admin revokes MIGRATOR_ROLE, and no cleanup is performed on role changes. As a result, the following sequence is possible:

  1. A migrator M is granted MIGRATOR_ROLE.
  2. A user calls setMigrationPermit(M, true).
  3. Admin revokes MIGRATOR_ROLE from M.
  4. The user later tries to revoke the stale permit with setMigrationPermit(M, false).
  5. The call reverts with MigratorNotFound(M) because M no longer has the role.
  6. At some later point, admin grants MIGRATOR_ROLE back to the same address M.
  7. The old migrationPermits[M][user] == true value is still present and becomes usable again.

The migration entry point relies on both role possession and stored user permit:

Solidity
function migratePositionsFrom(address user)
    external
    nonReentrant
    onlyRole(MIGRATOR_ROLE)
    returns (UserStake[] memory)
{
    if (!migrationPermits[msg.sender][user]) revert MigratorNotPermitted(msg.sender, user);
    ...
}

Because the permit is persistent, re-granting the same role to the same address reactivates the old user authorization without any new user action.

This is a real permission-lifecycle flaw. The user is prevented from revoking a permission entry that already exists simply because the role status changed after the permission was created.

Impact Details

  • Users can lose practical control over old migration approvals once the migrator role is revoked.
  • An address that regains MIGRATOR_ROLE later can reuse stale approvals that users were unable to clear.
  • Users may reasonably assume that revoking a role or losing role status fully neutralizes an old migrator relationship, but the stored authorization remains in state.
  • If the reauthorized migrator is malicious or compromised, it can again call migratePositionsFrom(user) for users who had previously approved it.

References

  • Affected code: src/Staking.sol::setMigrationPermit()
  • Role-gated revoke problem: src/Staking.sol:77-81
  • Stored permit mapping: src/Staking.sol:38
  • Migration entry point using stale permit: src/Staking.sol:166-172
  • Related errors: src/interfaces/IStakingV1.sol:79-80

Proof of Concept

Add this function to test/Staking.t.sol and run forge test --match-test test_Migration_StalePermitReactivatesWhenMigratorRoleGrantedAgain -vv

Solidity
function test_Migration_StalePermitReactivatesWhenMigratorRoleGrantedAgain() public {
    deal(address(token), address(staking), 1000 ether);
    deal(address(token), alice, 100 ether);

    uint8 periodIndex = addStakingPeriodByManager(50 ether, 20, 10, 5000, true);
    bytes32 migratorRole = keccak256("MIGRATOR");
    approveAndStake(alice, periodIndex, 10 ether, 20, 10, 5000, address(0));

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

    vm.prank(admin);
    staking.revokeRole(migratorRole, migrator);

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

    assertEq(staking.migrationPermits(migrator, alice), true);

    vm.prank(admin);
    staking.grantRole(migratorRole, migrator);

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

The original report as published on Immunefi, by jo13. 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 setMigrationPermit function checks that the migrator currently has MIGRATOR_ROLE even when the user is trying to revoke an existing permit, and stored permits are not cleared when the role is revoked.

Impact

A migrator that regains its role could reuse stale approvals to migrate positions of users who were unable to revoke them, weakening user control over migration.

What the attacker needed

User previously approved a migrator; migrator role is revoked then re-granted; migrator address is malicious or compromised

The fix

The contract should allow users to revoke a stored permit regardless of whether the migrator currently holds the role, or clear permits when the role is revoked.

How it was found

  1. A migrator address is granted MIGRATOR_ROLE.
  2. A user calls setMigrationPermit to allow that migrator.
  3. The admin revokes MIGRATOR_ROLE from the migrator.
  4. The user tries to revoke the permit but the call reverts because the migrator no longer has the role.
  5. The admin grants MIGRATOR_ROLE back to the same address.
  6. The migrator calls migratePositionsFrom for the user and the old permit is still active.

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 special 'migrator' address permission to move their staked tokens. The contract only lets the user change that permission while the migrator still has an official role. If the role is taken away, the user cannot cancel the old permission, and if the role is given back later, the old permission starts working 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 jo13

View all

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