Skip to content

stake function violates CEI: transfer before state persistence #217

Description

@ritaifeoluwa

Description

The FarmingPool's stake function pulls tokens from the user after updating state, but the state update uses set_user_stake which happens after the token transfer in the code flow. However, looking at the actual code, the token transfer happens before set_user_stake.

Current behavior (reversed CEI)

// Pull tokens from caller into the contract.
let stake_token = get_stake_token(&env)?;
token::TokenClient::new(&env, &stake_token).transfer(
    &from,
    env.current_contract_address(),
    &amount,
);

set_user_stake(&env, &from, &new_stake);  // State after transfer

Expected behavior

Follow checks-effects-interactions: persist state before external calls.

Why this matters

If the token transfer succeeds but set_user_stake panics, tokens are locked with no record.

Labels

correctness, farming-pool, hard

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programcorrectnessLogic correctness and invariant enforcementfarming-poolFarmingPool contracthardRequires deep domain knowledge and careful design — not a quick fix

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions