Updated flusher.sol to fallback function

This commit is contained in:
Thrilok Kumar 2020-09-24 16:23:42 +05:30
parent 6600facbfb
commit 2ed1eacc4d

View File

@ -1,42 +1,35 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.6.8; pragma solidity ^0.6.8;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
interface DeployerInterface { import "@openzeppelin/contracts/proxy/Proxy.sol";
function signer(address) external view returns (bool);
function isConnector(address[] calldata) external view returns (bool);
}
contract Flusher { contract Flusher is Proxy {
event LogCast(address indexed sender, uint value); /**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1
*/
bytes32 private constant _IMPLEMENTATION_SLOT = bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1); // 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
string constant public name = "Flusher-v1"; /**
* @dev Returns the current implementation address.
DeployerInterface public constant deployer = DeployerInterface(address(0)); // TODO - Change while deploying */
function _implementation() internal override view returns (address impl) {
function spell(address _target, bytes memory _data) internal { bytes32 slot = _IMPLEMENTATION_SLOT;
require(_target != address(0), "target-invalid"); // solhint-disable-next-line no-inline-assembly
assembly { assembly {
let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0) impl := sload(slot)
switch iszero(succeeded)
case 1 {
let size := returndatasize()
returndatacopy(0x00, 0x00, size)
revert(0x00, size)
}
} }
} }
function cast(address[] calldata _targets, bytes[] calldata _datas) external payable { function setBasic(address newImplementation) public {
require(deployer.signer(msg.sender), "not-signer"); require(_implementation() == address(0), "_implementation-logic-already-set");
require(_targets.length == _datas.length , "invalid-array-length"); require(newImplementation == address(0), "newImplementation-not-vaild");
require(deployer.isConnector(_targets), "not-connector"); bytes32 slot = _IMPLEMENTATION_SLOT;
for (uint i = 0; i < _targets.length; i++) {
spell(_targets[i], _datas[i]);
}
emit LogCast(msg.sender, msg.value);
}
receive() external payable {} // solhint-disable-next-line no-inline-assembly
assembly {
sstore(slot, newImplementation)
}
}
} }