GenesisClaim.stake() reverts because the approve call is commented out

Severity: Medium

Component: ghost-dao-contracts @ b87dff4c7a6ac34b35698c42b4d1f34b5f930864 (vesting/Genesis.sol lines 56 to 69, Staking.sol lines 76 to 83)

Source review only. No transactions. I verified the revert with a local Foundry test deploying the pinned Genesis, Treasury, FTSO and Staking contracts, 5 of 5 runs identical.

Description

stake() calls _claim(amount), which pulls the reserve asset and mints the FTSO payout to the GenesisClaim contract itself, then calls _STAKING.stake(toStake, to, …). Staking.stake pulls the FTSO from msg.sender, which is the GenesisClaim contract, with safeTransferFrom. The allowance from GenesisClaim to the staking contract is never set, because the only approve call is a commented out line. Users cannot grant that allowance themselves, it must come from the token holder, which is the contract. Every stake() call therefore reverts atomically at ERC20InsufficientAllowance, and only the plain claim() path, which pays FTSO out directly, works.

function stake(
    address to,
    uint256 amount,
    bool isRebasing,
    bool isClaim
) external {
    uint256 toStake = _claim(amount);
    //
    // _FTSO.approve(address(_STAKING), toStake);
    // _STAKING.stake(toStake, msg.sender);
    //
    // if (isFtso) _STAKING.claim(msg.sender);
    _STAKING.stake(toStake, to, isRebasing, isClaim);
}

Proof of concept (a Foundry test deploying the real pinned GenesisClaim, GhostTreasury, FTSO and Staking contracts and calling stake() then claim(); local chain only. 5 of 5 runs byte identical):

// poc/test/TrackB.t.sol
function test_genesisStakeReverts_claimWorks() public {
    // deploy the real pinned contracts; reserve = repo's ERC20Mock (test-only asset,
    // code under test is the real GenesisClaim/Treasury/Staking)
    (GenesisClaim genesis, Staking staking, FatsoERC20 ftso, ...) = _deploySuite();

    reserve.mint(user, 1e18);
    vm.startPrank(user);
    reserve.approve(address(genesis), 1e18);
    // Genesis._claim approves TREASURY and deposits; Treasury mints FTSO to genesis
    vm.expectRevert(abi.encodeWithSelector(
        IERC20Errors.ERC20InsufficientAllowance.selector,
        address(staking), 0, 1e9  // spender=staking, allowance=0, needed=toStake
    ));
    genesis.stake(user, 1e18, false, false);   // the only approve is commented out
    vm.stopPrank();

    // control: the same deposit through claim() pays out fine
    vm.prank(user);
    genesis.claim(1e18);
    assertEq(ftso.balanceOf(user), 1e9);
}

Raw output of the 5 runs (identical):

[PASS] test_genesisStakeReverts_claimWorks() (gas: 384376)
Logs:
  ASSERT stake reverted ERC20InsufficientAllowance spender=staking allowance=0 needed=toStake
  toStake=1000000000
  CONTROL claim transferred FTSO to caller
  claimed=1000000000

stake() reverts with ERC20InsufficientAllowance(staking, 0, 1000000000) because the GenesisClaim contract never approved the staking contract, and the control claim() for the same deposit pays the caller exactly 1000000000 FTSO units, proving the mint path works and only the missing approval blocks staking.

Steps to reproduce

  1. Clone and pin:
git clone https://git.ghostchain.io/ghostchain/ghost-dao-contracts.git && git -C ghost-dao-contracts checkout b87dff4c7a6ac34b35698c42b4d1f34b5f930864
  1. Create the Foundry test above deploying the repo’s real GenesisClaim, GhostTreasury, FatsoERC20 (FTSO) and Staking (use the repo’s ERC20Mock as the reserve asset; the code under test is the real vesting suite).
  2. Run:
forge test --match-test test_genesisStakeReverts_claimWorks -vv
  1. Observe stake() reverts ERC20InsufficientAllowance(staking, 0, 1000000000) because Genesis.sol line 64 still has the _FTSO.approve commented out, and the control claim() for the same deposit pays the caller exactly 1000000000 FTSO.
  2. Run 5 times; byte identical output.

Impact

No fund loss, the revert is atomic and users pay only gas, but the entire genesis staking flow is dead at deploy. Every eligible user who tries the one shot vesting to staking path fails and must fall back to claim() and stake manually. One hundred percent of stake() attempts revert.

Fix

Restore the approval before the staking call, preferably safeIncreaseAllowance or forceApprove, or transfer the minted FTSO to the user and let them stake directly.

Thank you for your report!

As it turns out, src/vesting/Genesis.sol is there only as legacy. It will not be deployed and will never be part of the protocol, because all early-adopter bounties will be included in the genesis file of the chain.

We should consider cleaning up and removing all unnecessary files from the repo.