Skip to content

Commit

Permalink
fix(Proxy): remove unneeded fallback function
Browse files Browse the repository at this point in the history
https://forum.openzeppelin.com/t/proxy-sol-fallback/36951/8


The fallback alone would indeed be enough.

 Fallback is not limited to` msg.value == 0` (if its marked `payable`). Both functions can support value.

The difference between receive and fallback is in the msg.data. If the calldata is empty and if there is a receive function, it fill be used. Otherwise, fallback is used. This means that regardless of the value, fallback will be called if there is some data. `fallback` is also the one that is called if there is no data, but receive is not defined.

So why do we have a receive function that is not really needed? To silent solidity warnings that sometimes happen when you have a fallback function but no receive function.
- @Amxx 

see <OpenZeppelin/openzeppelin-contracts#4434 (comment)>
  • Loading branch information
sambacha committed Sep 27, 2023
1 parent 4ec77af commit a16f20b
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)

pragma solidity 0.8.19;
pragma solidity ^0.8.19;

/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
Expand Down Expand Up @@ -68,14 +68,6 @@ abstract contract Proxy {
_fallback();
}

/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}

/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
Expand Down

0 comments on commit a16f20b

Please sign in to comment.