Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expired allowance miscalculation #289

Open
matiascabello opened this issue Jul 31, 2024 · 0 comments
Open

Expired allowance miscalculation #289

matiascabello opened this issue Jul 31, 2024 · 0 comments

Comments

@matiascabello
Copy link
Collaborator

This issue involves a poor implementation of the allowance function in the Token SEP-041 interface. While the approve function in SEP-041 allows passing an expiration_ledger:

fn approve(e: Env, from: Address, spender: Address, amount: i128, expiration_ledger: u32)

The allowance function only returns the amount:

fn allowance(e: Env, from: Address, spender: Address) -> i128

This can lead to implementations that compile but do not account for expiration_ledger. For example:

fn allowance(e: Env, from: Address, spender: Address) -> i128 {
    let result = storage::get_allowance(&e, &from, &spender);
    result.amount
}

Proposal

If the TokenInterface is implemented (this could be verified by checking if the trait is imported and implemented), ensure that allowance includes something like:

fn allowance(e: Env, from: Address, spender: Address) -> i128 {
    let result = storage::get_allowance(&e, &from, &spender);
    if e.ledger().sequence() > result.expiration_ledger {
        0
    } else {
        result.amount
    }
}
@matiascabello matiascabello assigned jgcrosta and unassigned jgcrosta Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants