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

Can set expired allowances #163

Open
tinchoabbate opened this issue Dec 13, 2022 · 2 comments
Open

Can set expired allowances #163

tinchoabbate opened this issue Dec 13, 2022 · 2 comments
Labels
p2 Nice to have

Comments

@tinchoabbate
Copy link

In the library Allowance, neither updateAll nor updateAmountAndExpiration check that the expiration passed is not in the past.

That means it's possible to set an approval expiration timestamp that ends up being lower than block.timestamp (and greater than 0, which is the special case), and have the call succeed.

Seems like a minor oversight - I don't think it has worrying consequences. As long as user sets a reasonable expiration for the allowance, things should be fine. Worst case scenario the expired allowance is stored, the user notices the problem, and submits another tx to update the allowance.

Here's a simple test case to reproduce:

function testApproveExpired() public {
    vm.warp(block.timestamp + 1000);
    uint48 expiredTimestamp = uint48(block.timestamp - 1);
    vm.prank(from);
    vm.expectEmit(true, true, true, true);
    emit Approval(from, address(token0), address(this), defaultAmount, expiredTimestamp);
    permit2.approve(address(token0), address(this), defaultAmount, expiredTimestamp);

    (uint160 amount, uint48 expiration, uint48 nonce) = permit2.allowance(from, address(token0), address(this));
    assertEq(amount, defaultAmount);
    assertEq(expiration, expiredTimestamp);
    assertEq(nonce, 0);
}
@marktoda
Copy link
Collaborator

Interesting point - thanks for raising!

My initial take is that the behavior is exactly the same whether we revert on already-expired allowance or succeed and store it anyways.
Reverting saves a little gas for the user who made the mistake, and is a little more clear that the approval is not going to be usable. But I'm not sure it's even worth the added (admittedly tiny) gas to every other permit/approval to check+revert in this rare case. Esp given its a check that can/will be easily caught in interfaces/sdk integrations

@marktoda
Copy link
Collaborator

@snreynolds want to double check my thoughts here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2 Nice to have
Projects
None yet
Development

No branches or pull requests

2 participants