Implement recommendations from 5.0 audit Phase 1B (#4502)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Francisco Giordano <fg@frang.io>
This commit is contained in:
Ernesto García
2023-08-04 14:23:38 -06:00
committed by GitHub
parent 21716722ad
commit f715365ec4
25 changed files with 286 additions and 283 deletions

View File

@ -1,50 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Address} from "../utils/Address.sol";
/**
* @dev A mock to expose `Address`'s functions with function pointers.
*/
contract AddressFnPointerMock {
error CustomRevert();
function functionCall(address target, bytes memory data) external returns (bytes memory) {
return Address.functionCall(target, data, _customRevert);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) external returns (bytes memory) {
return Address.functionCallWithValue(target, data, value, _customRevert);
}
function functionStaticCall(address target, bytes memory data) external view returns (bytes memory) {
return Address.functionStaticCall(target, data, _customRevert);
}
function functionDelegateCall(address target, bytes memory data) external returns (bytes memory) {
return Address.functionDelegateCall(target, data, _customRevert);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) external view returns (bytes memory) {
return Address.verifyCallResultFromTarget(target, success, returndata, _customRevert);
}
function verifyCallResult(bool success, bytes memory returndata) external view returns (bytes memory) {
return Address.verifyCallResult(success, returndata, _customRevert);
}
function verifyCallResultVoid(bool success, bytes memory returndata) external view returns (bytes memory) {
return Address.verifyCallResult(success, returndata, _customRevertVoid);
}
function _customRevert() internal pure {
revert CustomRevert();
}
function _customRevertVoid() internal pure {}
}

View File

@ -59,3 +59,15 @@ contract CallReceiverMock {
return "0x1234";
}
}
contract CallReceiverMockTrustingForwarder is CallReceiverMock {
address private _trustedForwarder;
constructor(address trustedForwarder_) {
_trustedForwarder = trustedForwarder_;
}
function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
return forwarder == _trustedForwarder;
}
}

View File

@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IBeacon} from "../proxy/beacon/IBeacon.sol";
contract UpgradeableBeaconMock is IBeacon {
address public implementation;
constructor(address impl) {
implementation = impl;
}
}
interface IProxyExposed {
// solhint-disable-next-line func-name-mixedcase
function $getBeacon() external view returns (address);
}
contract UpgradeableBeaconReentrantMock is IBeacon {
error BeaconProxyBeaconSlotAddress(address beacon);
function implementation() external view override returns (address) {
// Revert with the beacon seen in the proxy at the moment of calling to check if it's
// set before the call.
revert BeaconProxyBeaconSlotAddress(IProxyExposed(msg.sender).$getBeacon());
}
}

View File

@ -1,12 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IBeacon} from "../proxy/beacon/IBeacon.sol";
contract UpgradeableBeaconMock is IBeacon {
address public implementation;
constructor(address impl) {
implementation = impl;
}
}