ExcessivelySafeCall

Git Source

State Variables

LOW_28_MASK

uint256 constant LOW_28_MASK = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

Functions

excessivelySafeCall

Use when you really really really don't trust the called contract. This prevents the called contract from causing reversion of the caller in as many ways as we can.

The main difference between this and a solidity low-level call is that we limit the number of bytes that the callee can cause to be copied to caller memory. This prevents stupid things like malicious contracts returning 10,000,000 bytes causing a local OOG when copying to memory.

function excessivelySafeCall(address _target, uint256 _gas, uint16 _maxCopy, bytes memory _calldata)
    internal
    returns (bool, bytes memory);

Parameters

NameTypeDescription
_targetaddressThe address to call
_gasuint256The amount of gas to forward to the remote contract
_maxCopyuint16The maximum number of bytes of returndata to copy to memory.
_calldatabytesThe data to send to the remote contract

Returns

NameTypeDescription
<none>boolsuccess and returndata, as .call(). Returndata is capped to _maxCopy bytes.
<none>bytes

excessivelySafeStaticCall

Use when you really really really don't trust the called contract. This prevents the called contract from causing reversion of the caller in as many ways as we can.

The main difference between this and a solidity low-level call is that we limit the number of bytes that the callee can cause to be copied to caller memory. This prevents stupid things like malicious contracts returning 10,000,000 bytes causing a local OOG when copying to memory.

function excessivelySafeStaticCall(address _target, uint256 _gas, uint16 _maxCopy, bytes memory _calldata)
    internal
    view
    returns (bool, bytes memory);

Parameters

NameTypeDescription
_targetaddressThe address to call
_gasuint256The amount of gas to forward to the remote contract
_maxCopyuint16The maximum number of bytes of returndata to copy to memory.
_calldatabytesThe data to send to the remote contract

Returns

NameTypeDescription
<none>boolsuccess and returndata, as .call(). Returndata is capped to _maxCopy bytes.
<none>bytes

swapSelector

Swaps function selectors in encoded contract calls

Allows reuse of encoded calldata for functions with identical argument types but different names. It simply swaps out the first 4 bytes for the new selector. This function modifies memory in place, and should only be used with caution.

function swapSelector(bytes4 _newSelector, bytes memory _buf) internal pure;

Parameters

NameTypeDescription
_newSelectorbytes4The new 4-byte selector
_bufbytesThe encoded contract args