Confused about what triggers fallback in openzeppelin's proxy abstract contract #313
Unanswered
viktrified
asked this question in
Q&A
Replies: 1 comment 2 replies
-
It is. a proxy contract, and it doesn't contain any implementation logic, so it is designed to always trigger the fallback function to make a delegate call function to the contract address that contains the implementation logic. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Please can someone explain to me why every call made to this contract will trigger its fallback `// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Proxy.sol)
pragma solidity ^0.8.20;
/**
@dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
instruction
delegatecall
. We refer to the second contract as the implementation behind the proxy, and it has tobe specified by overriding the virtual {_implementation} function.
Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
different contract through the {_delegate} function.
The success and return data of the delegated call will be returned back to the caller of the proxy.
/
abstract contract Proxy {
/*
@dev Delegates the current call to
implementation
.This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
}
}
/**
*/
function _implementation() internal view virtual returns (address);
/**
_implementation()
.*/
function _fallback() internal virtual {
_delegate(_implementation());
}
/**
_implementation()
. Will run if no other*/
fallback() external payable virtual {
_fallback();
}
}`
Beta Was this translation helpful? Give feedback.
All reactions