-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #461 This PR adds a rule which verifies that the signature length check is ensured using the `_checkSignaturesLength(...)` in the `Safe4337Module`. The rule ensures that a signature that the bundler could manipulate, which could clear the check in Safe using `checkSignatures(...)` will still get caught using the `_checkSignaturesLength(...)`. For this, we use a `canonicalSignatureHash(...)` which generates the same hash for valid signatures, with and without the excess data. An example is added to show this case before the function is written. Also have added the workflow for checking the same in CI (Currently, it uses a script, which will be modified in a later PR to be consistent with our other repos).
- Loading branch information
Showing
6 changed files
with
94 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"files": [ | ||
"certora/harnesses/Safe4337ModuleHarness.sol", | ||
"certora/harnesses/Account.sol", | ||
], | ||
"loop_iter": "3", | ||
"optimistic_loop": true, | ||
"msg": "Safe4337Module: Signatures Length Check", | ||
"rule_sanity": "basic", | ||
"solc": "solc8.23", | ||
"verify": "Safe4337ModuleHarness:certora/specs/SignatureLengthCheck.spec", | ||
"packages": [ | ||
"@account-abstraction=../../node_modules/.pnpm/@account-abstraction+contracts@0.7.0/node_modules/@account-abstraction", | ||
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.13.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global" | ||
] | ||
} |
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 "./../../contracts/Safe4337Module.sol"; | ||
|
||
contract Safe4337ModuleHarness is Safe4337Module { | ||
constructor(address entryPoint) Safe4337Module(entryPoint) {} | ||
|
||
function checkSignaturesLength(bytes calldata signatures, uint256 threshold) external pure returns (bool) { | ||
return _checkSignaturesLength(signatures, threshold); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
modules/4337/certora/scripts/verifySignatureLengthCheck.sh
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,12 @@ | ||
#!/bin/bash | ||
|
||
params=() | ||
|
||
if [[ -n "$CI" ]]; then | ||
params=("--wait_for_results") | ||
fi | ||
|
||
certoraRun certora/conf/SignatureLengthCheck.conf \ | ||
"${params[@]}" \ | ||
"$@" | ||
|
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,15 @@ | ||
using Account as safeContract; | ||
|
||
methods { | ||
function checkSignaturesLength(bytes, uint256) external returns(bool) envfree; | ||
|
||
// Safe Contract functions | ||
function safeContract.canonicalSignature(bytes, uint256) external returns(bytes) envfree; | ||
} | ||
|
||
// This rule verifies that if excess data is added to the signature, though it could pass in the safe contract's `checkSignatures(...)`, | ||
// it will be caught within the `_checkSignaturesLength(...)` call, as the dynamic length is checked. | ||
rule signatureCannotBeLongerThanCanonicalEncoding(bytes signatures, uint256 threshold) { | ||
bytes canonical = safeContract.canonicalSignature(signatures, threshold); | ||
assert checkSignaturesLength(signatures, threshold) => signatures.length <= canonical.length; | ||
} |