Skip to content

Commit

Permalink
Merge branch 'main' into perf/exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Dec 11, 2024
2 parents c0f7a65 + 01cabb0 commit ef46683
Show file tree
Hide file tree
Showing 18 changed files with 1,988 additions and 48 deletions.
6 changes: 5 additions & 1 deletion src/ape/managers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from ape.utils.misc import log_instead_of_fail
from ape.utils.os import create_tempdir, in_tempdir
from ape.utils.rpc import RPCHeaders
from ape.utils.rpc import USER_AGENT, RPCHeaders

if TYPE_CHECKING:
from ethpm_types import PackageManifest
Expand All @@ -39,6 +39,10 @@ def __init__(self, data_folder: Optional[Path] = None, request_header: Optional[
else:
self.DATA_FOLDER = data_folder or Path.home() / ".ape"

request_header = request_header or {
"User-Agent": USER_AGENT,
"Content-Type": "application/json",
}
self.REQUEST_HEADER = request_header or {}

def __ape_extra_attributes__(self):
Expand Down
5 changes: 1 addition & 4 deletions src/ape/utils/basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from ape.exceptions import ApeAttributeError, ApeIndexError, ProviderNotConnectedError
from ape.logging import logger
from ape.utils.misc import log_instead_of_fail, raises_not_implemented
from ape.utils.rpc import USER_AGENT

if TYPE_CHECKING:
from pydantic.main import Model
Expand Down Expand Up @@ -173,9 +172,7 @@ def config_manager(cls) -> "ConfigManager":
The :class:`~ape.managers.config.ConfigManager`.
"""
config = import_module("ape.managers.config")
return config.ConfigManager(
request_header={"User-Agent": USER_AGENT, "Content-Type": "application/json"},
)
return config.ConfigManager()

@manager_access
def conversion_manager(cls) -> "ConversionManager":
Expand Down
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 ef46683

Please sign in to comment.