Hi, based on this answer, I am using the minimal proxy pattern with create2. This part is working just fine. I’d really like to be able to extract out the logic address of that minimal proxy, using Solidity, and I’m not sure how to go about it.
Using hardhat, and solidity 0.6.12
Using create2 + minimal proxy, we have a setup that allows us to create many instances of a given contract. Then elsewhere, a separate contract of ours re-creates the create2 address and verifies it against msg.sender, to ensure that the caller is a genuine contract that we created in our factories (and it saves us from having to store all the addresses we created). That part all works well.
The thing is, we may later upgrade the original contract, which would change the “reference implementation” that the minimal proxy uses, and therefore change it’s contract code, and hence the generated create2 address. So instead of using our config to get the reference implementation, we wanted to pull out the address from the minimal proxy itself. But I think this would require calling some assembly such as
mload on the minimal proxy address. This leads me to have two questions…
- Can I call assembly on another random contract? Or how can I access arbitrary storage slots on another contract?
- If I could do this, where is the logic address stored exactly on the minimal proxy?
I was looking at this, which gave me a decent idea of where it is within the bytecode, and then I think I could turn the bytes back into an address from there. But I’m more stuck on the first part, of how do I even try to reach into a minimal proxy from within Solidity?
Any help would be appreciated. Thanks!
PS: If this isn’t possible, a potentially workable alternative is to store all the reference implementations we ever use, and cycle through them when checking validity, though that seems lame. The other solution is to simply store all the addresses we create, but that could mean a lot of extra storage, and would kind of defeat the purpose of why we went with create2.