Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to call implementation contract from a proxy contract #964

Closed
ericleponner opened this issue Apr 8, 2024 · 13 comments · Fixed by #978
Closed

Enable to call implementation contract from a proxy contract #964

ericleponner opened this issue Apr 8, 2024 · 13 comments · Fixed by #978
Assignees
Labels
enhancement New feature or request smart contracts Features that involve smart contracts

Comments

@ericleponner
Copy link
Collaborator

Problem

This is a follow-up of this request.

Solution

There are some ways to:

  1. detect that a contract is a proxy
  2. fetch id / address of the implementation contract from proxy bytecode
    but these are both heuristic and need to be investigated.

May be a first approach could be to rely on user's knowledge:
user could be asked to provide id/address of the implementation contract before calling implementation methods from the proxy. Feedback is welcome.

Alternatives

No response

@ericleponner ericleponner added the enhancement New feature or request label Apr 8, 2024
@svienot svienot added the smart contracts Features that involve smart contracts label Apr 8, 2024
@mshakeg
Copy link

mshakeg commented Apr 8, 2024

For proxies that respect EIP-1967 the storage slot at which the implementation contract address(or Logic contract as referred to in the EIP doc) is stored at 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc.

For example the proxy contract 0xb177cf10f4382f671e5923c6c06f7b601d5a04e2 has an implementation contract 0x0e44f5cdabefe34d5b729acfa0a79971ffbc0e7e as returned in the following request's response:

curl https://mainnet.hashio.io/api \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_getStorageAt","params":["0xb177cf10f4382f671e5923c6c06f7b601d5a04e2", "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc", "latest"],"id":1,"jsonrpc":"2.0"}'
{
    "result": "0x0000000000000000000000000e44f5cdabefe34d5b729acfa0a79971ffbc0e7e",
    "jsonrpc": "2.0",
    "id": 1
}

Also, the proxy admin contract address storage slot is 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103 as outlined in EIP-1967. Using the same proxy above the proxy admin is 0x51803f621c5e90011de58b57fd5b7a92e0e39b08 as returned in the following request's response:

curl https://mainnet.hashio.io/api \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_getStorageAt","params":["0xb177cf10f4382f671e5923c6c06f7b601d5a04e2", "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103", "latest"],"id":1,"jsonrpc":"2.0"}'
{
    "result": "0x00000000000000000000000051803f621c5e90011de58b57fd5b7a92e0e39b08",
    "jsonrpc": "2.0",
    "id": 1
}

IMU the mirror node explorer is stateless so this might be a feature to implement on sourcify(or hedera's fork of it), i.e. expose an endpoint to determine and register an EIP-1967 compliant proxy and its logic, beacon and admin contracts.

@mshakeg
Copy link

mshakeg commented Apr 8, 2024

created an issue on sourcify

@ericleponner
Copy link
Collaborator Author

@mshakeg thanks for the technical insight 👍

@ericleponner ericleponner self-assigned this Apr 9, 2024
@ericleponner
Copy link
Collaborator Author

@mshakeg

IMU the mirror node explorer is stateless so this might be a feature to implement on sourcify(or hedera's fork of it), i.e. expose an endpoint to determine and register an EIP-1967 compliant proxy and its logic, beacon and admin contracts.

Note that mirror node provides api/v1/contracts/{contractId}/state REST call.
Explorer can easily fetch value at slot 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc and check if it matches address of an existing contract.
Backend service may not be needed in fact…

@mshakeg
Copy link

mshakeg commented Apr 9, 2024

@ericleponner yes, but you'll have to make a mirror node call for every contract to check if it is an ERC-1967 proxy contract which isn't the case for almost all contracts which is a bit wasteful. A cleaner solution imo would be for a backend service(say sourcify) to add some contract metadata for proxy information, then when the mirror node explorer makes a request to sourcify to get a contract that proxy metadata if present is returned, similar to what was described in my sourcify issue, this will probably take a while for the sourcify team to implement, so your approach will work for a quick resolution.

@ericleponner
Copy link
Collaborator Author

@mshakeg
is the admin contract supposed to be invoked through the proxy (like the implementation/logic contract) ?

@mshakeg
Copy link

mshakeg commented Apr 11, 2024

@ericleponner no it does not, the admin contract updates the implementation address in the proxy contract.

@mshakeg
Copy link

mshakeg commented Nov 5, 2024

Hi @ericleponner and @svienot can you also please add auto-verification(and view&write calls) support for minimal clone proxies(provided the implementation is verified)?

The implementation contract for a minimal clone proxy can be extracted as follows:

curl -X POST -H "Content-Type: application/json" --data '{
    "jsonrpc":"2.0",
    "method":"eth_getCode",
    "params":["0xc0f4d92437d6549ac5ac6544b21dee9903fd4c74", "latest"],
    "id":1
}' https://mainnet.hashio.io/api

response:

{
    "result": "0x363d3d373d3d3d363d731c3eb3c090607b6b1e598b1722b4c91847ee80825af43d82803e903d91602b57fd5bf3",
    "jsonrpc": "2.0",
    "id": 1
}

The address can be extracted from the result as follows:

0x363d3d373d3d3d363d73-bebebebebebebebebebebebebebebebebebebebe-5af43d82803e903d91602b57fd5bf3
0x363d3d373d3d3d363d73-1c3eb3c090607b6b1e598b1722b4c91847ee8082-5af43d82803e903d91602b57fd5bf3

i.e. 0x1c3eb3c090607b6b1e598b1722b4c91847ee8082 is the implementation address(which I have verified).

https://eips.ethereum.org/EIPS/eip-1167

@mshakeg
Copy link

mshakeg commented Nov 12, 2024

@ericleponner @svienot just a friendly nudge on my last reply regarding clone proxies

@ericleponner
Copy link
Collaborator Author

Hi @mshakeg
Would you be able to share some minimal clone proxy address for us to experiment ?

@mshakeg
Copy link

mshakeg commented Nov 12, 2024

@ericleponner I already did over here

The proxy is:

0xc0f4d92437d6549ac5ac6544b21dee9903fd4c74

The implementation(extracted from the above proxy) is:

0x1c3eb3c090607b6b1e598b1722b4c91847ee8082

@ericleponner
Copy link
Collaborator Author

@mshakeg
I apologize for the duplicate request :/
Thanks again

@ericleponner
Copy link
Collaborator Author

@mshakeg
I created #1504 enhancement. Let's follow discussion over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request smart contracts Features that involve smart contracts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants