-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#754] Add signature length checks in Safe4337Module
- Loading branch information
Showing
9 changed files
with
255 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity >=0.8.0; | ||
import {Safe4337Module} from "../Safe4337Module.sol"; | ||
|
||
contract TestSafe4337Module is Safe4337Module { | ||
constructor(address entryPoint) Safe4337Module(entryPoint) {} | ||
|
||
function checkSignatureLength(bytes calldata signature, uint256 threshold) external pure returns (bool) { | ||
return _checkSignatureLength(signature, threshold); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { expect } from 'chai' | ||
import { deployments, ethers } from 'hardhat' | ||
import { buildSignatureBytes, signHash } from '../../src/utils/execution' | ||
|
||
describe('TestSafe4337Module', () => { | ||
const setupTests = deployments.createFixture(async () => { | ||
const module = await ethers.deployContract('TestSafe4337Module', [ethers.hexlify(ethers.randomBytes(20))]) | ||
return { module } | ||
}) | ||
|
||
it('Safe with 1 EOA owner', async () => { | ||
const { module } = await setupTests() | ||
const [user] = await ethers.getSigners() | ||
|
||
const safeOpHash = ethers.hexlify(ethers.randomBytes(32)) | ||
|
||
const signature = buildSignatureBytes([await signHash(user, safeOpHash)]) | ||
|
||
const threshold = 1 | ||
expect(await module.checkSignatureLength(signature, threshold)).to.be.true | ||
}) | ||
|
||
it('Safe with 1 Safe as owner', async () => { | ||
const { module } = await setupTests() | ||
|
||
const signature = buildSignatureBytes([ | ||
{ | ||
signer: ethers.ZeroAddress, | ||
data: ethers.hexlify(ethers.randomBytes(65)), | ||
dynamic: true, | ||
}, | ||
]) | ||
|
||
const threshold = 1 | ||
expect(await module.checkSignatureLength(signature, threshold)).to.be.true | ||
}) | ||
|
||
it('Safe with 1 EOA and 1 Safe as owners', async () => { | ||
const { module } = await setupTests() | ||
const [user] = await ethers.getSigners() | ||
|
||
const safeOpHash = ethers.hexlify(ethers.randomBytes(32)) | ||
|
||
const signature = buildSignatureBytes([ | ||
await signHash(user, safeOpHash), | ||
{ | ||
signer: ethers.ZeroAddress, | ||
data: ethers.hexlify(ethers.randomBytes(65)), | ||
dynamic: true, | ||
}, | ||
]) | ||
|
||
const threshold = 2 | ||
expect(await module.checkSignatureLength(signature, threshold)).to.be.true | ||
}) | ||
|
||
it('Safe with 2 EOA and 1 Safe as owners', async () => { | ||
const { module } = await setupTests() | ||
const [user] = await ethers.getSigners() | ||
|
||
let safeOpHash = ethers.hexlify(ethers.randomBytes(32)) | ||
|
||
const signature = buildSignatureBytes([ | ||
await signHash(user, safeOpHash), | ||
await signHash(user, safeOpHash), | ||
{ | ||
signer: ethers.ZeroAddress, | ||
data: ethers.hexlify(ethers.randomBytes(65)), | ||
dynamic: true, | ||
}, | ||
]) | ||
|
||
const threshold = 3 | ||
expect(await module.checkSignatureLength(signature, threshold)).to.be.true | ||
}) | ||
|
||
it('Safe with 1 EOA and 2 Safe as owners', async () => { | ||
const { module } = await setupTests() | ||
const [user] = await ethers.getSigners() | ||
|
||
let safeOpHash = ethers.hexlify(ethers.randomBytes(32)) | ||
|
||
const signature = buildSignatureBytes([ | ||
await signHash(user, safeOpHash), | ||
{ | ||
signer: ethers.ZeroAddress, | ||
data: ethers.hexlify(ethers.randomBytes(65)), | ||
dynamic: true, | ||
}, | ||
{ | ||
signer: ethers.ZeroAddress, | ||
data: ethers.hexlify(ethers.randomBytes(65)), | ||
dynamic: true, | ||
}, | ||
]) | ||
|
||
const threshold = 3 | ||
expect(await module.checkSignatureLength(signature, threshold)).to.be.true | ||
}) | ||
|
||
it('Should revert when signature contains additional bytes', async () => { | ||
const { module } = await setupTests() | ||
const [user] = await ethers.getSigners() | ||
|
||
let safeOpHash = ethers.hexlify(ethers.randomBytes(32)) | ||
|
||
const signature = buildSignatureBytes([ | ||
await signHash(user, safeOpHash), | ||
{ | ||
signer: ethers.ZeroAddress, | ||
data: ethers.hexlify(ethers.randomBytes(65)), | ||
dynamic: true, | ||
}, | ||
{ | ||
signer: ethers.ZeroAddress, | ||
data: ethers.hexlify(ethers.randomBytes(65)), | ||
dynamic: true, | ||
}, | ||
]).concat('00') | ||
|
||
const threshold = 3 | ||
expect(await module.checkSignatureLength(signature, threshold)).to.be.false | ||
}) | ||
}) |
Oops, something went wrong.