如何在代理合同中找到实现合同地址?



有一个可升级的代理模式,允许通过将代理合约中的实现地址指向升级合约的新地址来升级智能合约。

是否有办法找到实现合同的地址?当我查看代理代码时,我看到以下内容:

// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x64_bytes_string;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x64_bytes_string;

代码中似乎没有任何内容显示实现契约的地址。

一些块浏览器(如Etherscan)现在提供了一种从代理合约的部署地址直接导航到代理合约实现的方法。

_IMPLEMENTATION_SLOT是代理契约中的内存,其中保存了实现的地址。要检索当前的实现契约地址,您可以读取存储:

let proxyContract = "0x_YOUR_PROXY_CONTRACT";
let storagePosition = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
let address = await web3Client.eth.getStorageAt(proxyContract, storagePosition);

我在https://ethereum.stackexchange.com/questions/103143/how-do-i-get-the-implementation-contract-address-from-the-proxy-contract-address上发现类似的问题如果没有implementation().call()函数,有一个如何从代理契约中获取_IMPLEMENTATION_SLOT常量的指南。

最新更新