Skip to content

Commit caf47cd

Browse files
committed
feat: IsASafe.isProbablyASafe
1 parent c4f6c6c commit caf47cd

5 files changed

Lines changed: 29 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "lib/forge-std"]
22
path = lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/safe-smart-account"]
5+
path = lib/safe-smart-account
6+
url = https://github.com/safe-fndn/safe-smart-account

foundry.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
"name": "v1.16.2",
55
"rev": "bf647bd6046f2f7da30d0c2bf435e5c76a780c1b"
66
}
7+
},
8+
"lib/safe-smart-account": {
9+
"tag": {
10+
"name": "v1.5.0",
11+
"rev": "dc437e8fba8b4805d76bcbd1c668c9fd3d1e83be"
12+
}
713
}
814
}

foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ bytecode_hash = "none"
1414
# For dependencies
1515
remappings = [
1616
'forge-std/=lib/forge-std/src/',
17+
'@safe/=lib/safe-smart-account/contracts/',
1718
#'@fvm-solidity/=lib/pdp/lib/fvm-solidity/src/',
1819
]
1920

lib/safe-smart-account

Submodule safe-smart-account added at 77901a5

src/lib/IsASafe.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: Apache-2.0 OR MIT
2+
pragma solidity ^0.8.36;
3+
4+
import {IProxy} from "@safe/proxies/SafeProxy.sol";
5+
6+
library IsASafe {
7+
error NotSafeProxy(address account);
8+
error UnusualSafeMasterCopy(address account, address masterCopy);
9+
10+
function isProbablyASafe(address account) internal view {
11+
uint256 codesize = account.code.length;
12+
// observed Safe proxy codesize range is 110 (v1.0.0) to 171 (v1.3.0)
13+
require(codesize > 80 && codesize < 240, NotSafeProxy(account));
14+
address implementation = IProxy(account).masterCopy();
15+
// observed Safe masterCopy size is 20869 (v1.5.0) to 24421 (v1.4.1)
16+
require(implementation.code.length > 8000, UnusualSafeMasterCopy(account, implementation));
17+
}
18+
}

0 commit comments

Comments
 (0)