Skip to content

Commit

Permalink
fix: issue where gnosis-safe proxy sometimes was not detected (#2400)
Browse files Browse the repository at this point in the history
Co-authored-by: antazoey <[email protected]>
  • Loading branch information
0xthedance and antazoey authored Dec 11, 2024
1 parent a3f17aa commit 6ca9d38
Show file tree
Hide file tree
Showing 15 changed files with 1,978 additions and 37 deletions.
22 changes: 10 additions & 12 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,16 @@ def str_to_slot(text):
return ProxyInfo(type=_type, target=target)

# safe >=1.1.0 provides `masterCopy()`, which is also stored in slot 0
# detect safe-specific bytecode of push32 keccak256("masterCopy()")
safe_pattern = b"\x7f" + keccak(text="masterCopy()")[:4] + bytes(28)
if to_hex(safe_pattern) in code:
try:
singleton = ContractCall(MASTER_COPY_ABI, address)(skip_trace=True)
slot_0 = self.provider.get_storage(address, 0)
target = self.conversion_manager.convert(slot_0[-20:], AddressType)
# NOTE: `target` is set in initialized proxies
if target != ZERO_ADDRESS and target == singleton:
return ProxyInfo(type=ProxyType.GnosisSafe, target=target)
except ApeException:
pass
# call it and check that target matches
try:
singleton = ContractCall(MASTER_COPY_ABI, address)(skip_trace=True)
slot_0 = self.provider.get_storage(address, 0)
target = self.conversion_manager.convert(slot_0[-20:], AddressType)
# NOTE: `target` is set in initialized proxies
if target != ZERO_ADDRESS and target == singleton:
return ProxyInfo(type=ProxyType.GnosisSafe, target=target)
except ApeException:
pass

# eip-897 delegate proxy, read `proxyType()` and `implementation()`
# perf: only make a call when a proxyType() selector is mentioned in the code
Expand Down
138 changes: 137 additions & 1 deletion tests/functional/data/contracts/ethereum/local/BeaconProxy.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions tests/functional/data/contracts/ethereum/local/ERCProxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"abi": [
{
"inputs": [],
"name": "proxyType",
"outputs": [
{
"name": "proxyTypeId",
"type": "uint256"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "implementation",
"outputs": [
{
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_target",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
}
],
"contractName": "ERCProxy",
"deploymentBytecode": {
"bytecode": "0x608060405234801561001057600080fd5b5060405160208061014a833981016040525160008054600160a060020a03909216600160a060020a031990921691909117905560f9806100516000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634555d5c98114604d5780635c60da1b146071575b600080fd5b348015605857600080fd5b50605f60ac565b60408051918252519081900360200190f35b348015607c57600080fd5b50608360b1565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b600190565b60005473ffffffffffffffffffffffffffffffffffffffff16905600a165627a7a72305820ae971f5c593cbaf95a4ff9c244af7a9afd16cda9faff299ef9f50e1953626a340029"
},
"devdoc": {
"methods": {}
},
"methodIdentifiers": {
"implementation()": "0x5c60da1b",
"proxyType()": "0x4555d5c9"
},
"runtimeBytecode": {
"bytecode": "0x60806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634555d5c98114604d5780635c60da1b146071575b600080fd5b348015605857600080fd5b50605f60ac565b60408051918252519081900360200190f35b348015607c57600080fd5b50608360b1565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b600190565b60005473ffffffffffffffffffffffffffffffffffffffff16905600a165627a7a72305820ae971f5c593cbaf95a4ff9c244af7a9afd16cda9faff299ef9f50e1953626a340029"
},
"sourceId": "tests/functional/data/sources/DelegateProxy.sol",
"sourcemap": "27:278:0:-;;;77:56;8:9:-1;5:2;;;30:1;27;20:12;5:2;77:56:0;;;;;;;;;;;;;112:6;:16;;-1:-1:-1;;;;;112:16:0;;;-1:-1:-1;;;;;;112:16:0;;;;;;;;;27:278;;;;;;",
"userdoc": {
"methods": {}
}
}
Loading

0 comments on commit 6ca9d38

Please sign in to comment.