Skip to content

Instantly share code, notes, and snippets.

@ylv-io
Created August 19, 2022 18:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ylv-io/6f8ec43226f124a822b0aab451190de7 to your computer and use it in GitHub Desktop.
Save ylv-io/6f8ec43226f124a822b0aab451190de7 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.1;
/**
* @title NoMevProxy
* @dev Invokes a staticcall to an address from OFAC list to block MEV
*/
contract NoMevProxy {
address immutable implementation;
constructor(address _target) {
implementation = _target;
}
/**
* This function does not return to its internal call site, it will return directly to the external caller.
*
* @dev Delegates the current call.
*/
function _fallback() internal {
address impl = implementation;
assembly {
// make staticcall to OFAC address to prevent MEV
let success := staticcall(21000, 0x3CBdeD43EFdAf0FC77b9C55F6fC9988fCC9b757d, 0, 0, 0, 0)
// 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())
// Call the _implementation. out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
// return call result
return(0, returndatasize())
}
}
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment