Skip to content

Commit

Permalink
Merge branch 'main' of github.com:safe-global/safe-modules into deps/…
Browse files Browse the repository at this point in the history
…bump
  • Loading branch information
mmv08 committed Sep 26, 2024
2 parents 6dfab23 + a5aaf8e commit 2f0a306
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 20 deletions.
31 changes: 31 additions & 0 deletions modules/allowances/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

This changelog only contains changes starting from version 0.1.1

# Version 0.1.1

## Compiler settings

Solidity compiler: [0.7.6](https://github.com/ethereum/solidity/releases/tag/v0.7.6)

Solidity optimizer: disabled

## Expected addresses

- `AllowanceModule` at `0xAA46724893dedD72658219405185Fb0Fc91e091C`

## Changes

### General

#### Fix the EIP-712 transfer typehash

Issue: [#70](https://github.com/safe-global/safe-modules/issues/70)

The typehash for the transfer was incorrect, making it impossible to use the module with EIP-712 signatures.

#### Add a check for `resetTimeMin`

For recurring allowances, the `resetTimeMin` must be greater than 0. However, the check was missing, making it possible to specify a `resetTimeMin` of 0, resulting in a divide by zero error and the transaction consuming all gas.

The change was suggested by the [Ackee blockchain](https://ackee.xyz/) during the audit of the module.
24 changes: 23 additions & 1 deletion modules/allowances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,26 @@ pnpm test
```bash
pnpm i
pnpm build
```
```

## Deploying and verifying contracts

Specify all the necessary environment variables in `.env`, following the `.env.sample` file.

```bash
pnpm i
pnpm run deploy <network_name>
```

1. `network_name` is the name of the network you want to deploy to. It must be added to the hardhat config under `networks` beforehand.
2. If the hardhat plugin cannot figure out the etherscan API url for the network, you can add it manually to `tasks/deploy_verify.ts`.
Example:
```ts
await hre.run('etherscan-verify', {
forceLicense: true,
license: 'LGPL-3.0',
apiUrl: "https://api.gnosiscan.io"
})
```


4 changes: 2 additions & 2 deletions modules/allowances/contracts/AllowanceModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface ISafe {

contract AllowanceModule is SignatureDecoder {
string public constant NAME = "Allowance Module";
string public constant VERSION = "0.1.0";
string public constant VERSION = "0.1.1";

bytes32 public constant DOMAIN_SEPARATOR_TYPEHASH = 0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218;
// keccak256(
Expand Down 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
Binary file not shown.
16 changes: 0 additions & 16 deletions modules/allowances/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,10 @@ const config: HardhatUserConfig = {
...sharedNetworkConfig,
url: 'https://rpc.gnosischain.com',
},
ewc: {
...sharedNetworkConfig,
url: `https://rpc.energyweb.org`,
},
goerli: {
...sharedNetworkConfig,
url: `https://goerli.infura.io/v3/${INFURA_KEY}`,
},
mumbai: {
...sharedNetworkConfig,
url: `https://polygon-mumbai.infura.io/v3/${INFURA_KEY}`,
},
polygon: {
...sharedNetworkConfig,
url: `https://polygon-mainnet.infura.io/v3/${INFURA_KEY}`,
},
volta: {
...sharedNetworkConfig,
url: `https://volta-rpc.energyweb.org`,
},
bsc: {
...sharedNetworkConfig,
url: `https://bsc-dataseed.binance.org/`,
Expand Down
2 changes: 1 addition & 1 deletion modules/allowances/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/safe-allowance-module",
"version": "1.0.0",
"version": "0.1.1",
"description": "Allowance module for the gnosis safe",
"keywords": [
"Ethereum",
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
})
})

0 comments on commit 2f0a306

Please sign in to comment.