10

Suppose that you have an upgradeable proxy "Foo" that calls an implementation contract "Bar" via DELEGATECALL.

In "Bar", there is a function that uses the Solidity syntax address(this) to retrieve the address of the current contract.

What is the "current" contract when the call is made via the upgradeable proxy "Foo"?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143

1 Answers1

9

Remember how DELEGATECALL works:

DELEGATECALL basically says that I'm a contract and I'm allowing (delegating) you to do whatever you want to my storage. DELEGATECALL is a security risk for the sending contract which needs to trust that the receiving contract will treat the storage well.

So the answer is that address(this) will return the address of the "Foo" proxy, not of the "Bar" implementation. This wouldn't be a "delegation" if the answer was otherwise, would it?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143