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

L-1: Add a reset period check to prevent the transaction failing and using all gas #492

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/allowances/contracts/AllowanceModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ contract AllowanceModule is SignatureDecoder {
// solium-disable-next-line security/no-block-members
uint32 currentMin = uint32(block.timestamp / 60);
if (resetBaseMin > 0) {
require(resetBaseMin <= currentMin, "resetBaseMin <= currentMin");
require(resetBaseMin <= currentMin && resetTimeMin > 0, "resetBaseMin <= currentMin && resetTimeMin > 0");
allowance.lastResetMin = currentMin - ((currentMin - resetBaseMin) % resetTimeMin);
} else if (allowance.lastResetMin == 0) {
allowance.lastResetMin = currentMin;
Expand Down
20 changes: 20 additions & 0 deletions modules/allowances/test/allowanceRecurring.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,24 @@ describe('AllowanceModule allowanceRecurring', () => {
expect(expectedLastReset).to.be.equal(resetLast)
expect(4).to.equal(nonce)
})

it('Reverts when trying to set up a recurring allowance with reset period of 0', async () => {
const { safe, allowanceModule, token, owner, alice } = await loadFixture(setup)
const tokenAddress = await token.getAddress()

// add alice as delegate
await execSafeTransaction(safe, await allowanceModule.addDelegate.populateTransaction(alice.address), owner)

// create an allowance for alice
const configResetPeriod = 0
const configResetBase = nowInMinutes()

await expect(
execSafeTransaction(
safe,
await allowanceModule.setAllowance.populateTransaction(alice.address, tokenAddress, 100, configResetPeriod, configResetBase),
owner,
),
).to.be.reverted
})
})
Loading